#include <stdio.h> int main() { int r = 0; int buf = 0; for( int c; c=getchar(), c!=EOF; ) { if( c != '\n' ) { r = (r*10+buf)%7; buf = c-'0'; } else { printf( " --- %s\n", r==buf?"valid":"invalid" ); } } return 0; }