akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N >> M;
	vector< int > x(N), y(M);
	rep(i, N) cin >> x[i];
	rep(i, M) cin >> y[i];
	int X = 0, Y = 0;
	rep(i, N) {
		int tmp = x[i] * (N - i - 1);
		tmp %= MOD;
		X += tmp;
		X %= MOD;
		tmp = -x[i] * i;
		tmp %= MOD;
		X += tmp;
		X %= MOD;
	}
	rep(i, M) {
		int tmp = y[i] * (M - i - 1);
		tmp %= MOD;
		Y += tmp;
		Y %= MOD;
		tmp = -y[i] * i;
		tmp %= MOD;
		Y += tmp;
		Y %= MOD;
	}
	int ans = X * Y;
	ans %= MOD;
	ans += MOD;
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, t;
    cin >> x >> t;
    cout << max(0, x - t) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
using namespace std;
typedef long int li;
typedef long long int lli;

const int INF = 0xfffffff;
int grid[100005] = { 0 }, load[100005] = { 0 };
int n, x;

int main() {
	int last = 0, ma = 0;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> load[i];
	}
	load[n] = x;
	sort(load, load + n + 1);
	for (int i = 1; i <= n; i++) grid[i - 1] = load[i] - load[i - 1];
	int ans = grid[0];
	for (int i = 1; i < n; i++) {
		if (grid[i] % ans != 0) {
			bool flag = false;
			for (int j = 2; j <= ans/2; j++) {
				int k = ans / j;
				if (ans%j != 0) continue;
				if (grid[i] % k == 0) {
					ans = k;
					flag = true;
					break;
				}
			}
			if (!flag) {
				cout << 1 << endl;
				return 0;
			}
			
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
H = list(map(int, input().split()))

ap = [False]*(N+1)

for m in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]: 
        ap[b] = True
    elif H[a-1] < H[b-1]:
        ap[a] = True
    elif H[a-1] == H[b-1]:
        ap[a] = True
        ap[b] = True

count = 0
for a in range(1, N+1):
    if ap[a] == False:
        count += 1

print(count)

Measured memory_bytes: 20048
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  //ll a;cin>>a;
  //ll a,b;cin>>a>>b;
  //ll a,b,c;cin>>a>>b>>c;
  //ll a,b,c,d;cin>>a>>b>>c>>d;
  string s;cin>>s;
  vector<string>ss={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  rep(i,0,ss.size()){
    if(s==ss[i])cout<<7-i<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const int INF = 100001;

string s;

int main()
{
    cin >> s;
    int ans = 0;
    for (auto c : s)
    {
        if (c == '+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
// always use 1LL instead of 1
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
// just comment the line below in case of interactive problems
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		string s,t;
		cin >> s >> t;
		int n = s.size();
		int sz = t.size();
		int ans = INT_MAX;
		for(int i=0;i<n;i++)
		{
			string ss = "";
			int j = i;
			int f = sz;
			while(j<n && f>0)
			{
				f--;
				ss += s[j];
				j++;
			}
			if(ss.size()<sz)
				break;
			int c = 0;
			rep(k,0,sz)
			{
				if(t[k]!=ss[k])
					c++;
			}
			ans = min(ans,c);
		}
		cout << ans;
	}
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N+1];
		for (int i=1;i<=N;i++) {
			A[i] = sc.nextInt();
		}
		int B[] = new int[N];
		for (int i=0;i<N-1;i++) {
			B[i]= Math.abs(A[i+2]-A[i]);
		}
		long sum = 0;
		for (int i=0;i<N;i++) {
			sum +=Math.abs(A[i+1]-A[i]);
		}
		sum +=Math.abs(A[N]-A[0]);
		for (int i=1;i<N;i++) {
			System.out.println(sum -Math.abs(A[i]-A[i-1])-Math.abs(A[i+1]-A[i])+B[i-1]);
		}
		System.out.println(sum -Math.abs(A[N]-A[N-1]) -Math.abs(A[N]-A[0])+Math.abs(A[N-1]-A[0]));
	}
}

Measured memory_bytes: 63944
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool check(char c)
{
	char v = '0';
	for(int i = 0; i <= 9; i++){
		if(c == (char)(v+i)){
			return true;
		}
	}
	
	return false;
}

string cfunc(string str, int n)
{
	string s = str.substr(1);
	s += str[0];
	
	return s;
}

string jfunc(string str, int n)
{
	string s = str.substr(0, n-1);
	s = str[n-1] + s;
	
	return s;
}

string efunc(string str, int n)
{
	string s;
	if(n%2 == 0){
		s = str.substr(n/2);
		s += str.substr(0, n/2);
	} else {
		s = "";
		for(int i = n/2+1; i < n; i++){
			s += str[i];
		}
		s += str[n/2];
		for(int i = 0; i < n/2; i++){
			s += str[i];
		}
	}
	
	return s;
}

string afunc(string str, int n)
{
	string s = str;
	reverse(s.begin(), s.end());
	
	return s;
}

string pfunc(string str, int n)
{
	string s = str;
	
	for(int i = 0; i < n; i++){
		if(check(s[i])){
			if(s[i] == '0'){
				s[i] = '9';
			} else {
				s[i] = (char)(s[i]-1);
			}
		}
	}
	
	return s;
}

string mfunc(string str, int n)
{
	string s = str;
	
	for(int i = 0; i < n; i++){
		if(check(s[i])){
			if(s[i] == '9'){
				s[i] = '0';
			} else {
				s[i] = (char)(s[i]+1);
			}
		}
	}
	
	return s;
}

int main()
{
	int n, l, m;
	string str, st;
	cin >> n;
	
	while(n--){
		cin >> st;
		cin >> str;
		l = st.size();
		m = str.size();
		
		for(int i = l-1; i >= 0; i--){
			if(st[i] == 'J'){
				str = jfunc(str, m);
			} else if(st[i] == 'C'){
				str = cfunc(str, m);
			} else if(st[i] == 'E'){
				str = efunc(str, m);
			} else if(st[i] == 'A'){
				str = afunc(str, m);
			} else if(st[i] == 'P'){
				str = pfunc(str, m);
			} else if(st[i] == 'M'){
				str = mfunc(str, m);
			}
		}
		
		cout << str << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import sys
def main():
    for line in sys.stdin:
        x, y = map(int, line.split())
        if x == 0 and y == 0:
            break
        else:
            if x > y:
                tmp = y
                y = x
                x = tmp
            print(x, y)


if __name__ == "__main__":
    main()

Measured memory_bytes: 8068
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll maxh = 5e4 + 10;
const ll maxn = 1010;

ll p[maxn], c[maxn];
ll dp[maxh];

int main() {
ll n, h;
scanf("%lld%lld", &h, &n);
    for(ll i = 0; i < n; i++) scanf("%lld%lld", &p[i], &c[i]);
    fill(dp, dp +  maxh, INF);
    dp[0] = 0;
    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j <= h; j++) {
            dp[j + p[i]] = min(dp[j + p[i]], dp[j] + c[i]);
        }
    }
   ll mins = INF;
    for (ll i = h; i < maxh; i++) mins = min(mins, dp[i]);
        printf("%lld\n", mins);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>

#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;

	cin >> n;

	ll x = 1;
	while (1000 * x < n) {
		x++;
	}

	cout << 1000* x - n << endl;

	
	return 0;
}

Measured memory_bytes: 3576
def kaibun(s):
    for i in range(len(s)//2):
        if s[i] != s[-(1+i)]:
            return False
    return True

s = input()
if (kaibun(s) and kaibun(s[:(len(s)-1)//2]) and kaibun(s[(len(s)+3)//2-1:])):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;
typedef long double ld;

const ll INF = 4e18;
const ld EPS = 1e-8;

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> x(N), y(N);
  REP(i, N) cin >> x[i] >> y[i];

  ll ret = INF;
  for(int xmin : x) for (int xmax : x) {
    for (int ymin : y) for (int ymax : y) {
      if(xmin > xmax || ymin > ymax) continue;
      int cnt = 0;
      REP(i, N) if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) ++cnt;
      if(cnt >= K) {
        ret = min(ret, (ll)(xmax - xmin) * (ll)(ymax - ymin));
      }
    }
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <tuple>
using namespace std;

using vec = complex<double>;
using line = pair<vec,vec>;
const double eps = 0.0000001;

double inner_product(vec u,vec v){
    return real(u*conj(v));
}
double cross_product(vec u,vec v){
    return imag(conj(u)*v);
}

double norm(vec& u){
    return abs(u);
}

vec projection(line l,vec p){//p???l???????°???±
    vec s=l.first, t=l.second;
    double k = inner_product(t-s,p-s)/inner_product(t-s,t-s);
    return (1.0-k)*s+k*t;
}

vec reflection(line l,vec p){
    return 2.0*projection(l,p)-p;
}

int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    double o = cross_product(ab,ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(inner_product(ab,ac)<0){
        return 2; //C-A-B
    }else{
        if(inner_product(ab,ab)<inner_product(ac,ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

bool isIntersect(line l0, line l1){
    int s = ccw(l0.first,l0.second,l1.first)*ccw(l0.first,l0.second,l1.second);
    if(s!=0&&s!=-1&&s!=-4) return false;
    s=ccw(l1.first,l1.second,l0.first)*ccw(l1.first,l1.second,l0.second);
    if(s!=0&&s!=-1&&s!=-4) return false;
    else return true;
}

vec interSection(line l0, line l1){
    vec s0, t0, s1, t1;
    tie(s0,t0)=l0; tie(s1,t1)=l1;
    double k = cross_product(t1-s1,s1-s0)/cross_product(t1-s1,t0-s0);
    return s0+(t0-s0)*k;
}

//???????????§???????????????

int main(void){
    int q;
    cin >> q;
    cout.precision(10);
    cout << fixed;
    while(q--){
        int x,y;
        cin>>x>>y;
        vec s0(x,y);
        cin>>x>>y;
        vec t0(x,y);
        cin>>x>>y;
        vec s1(x,y);
        cin>>x>>y;
        vec t1(x,y);
        vec v = interSection(line(s0,t0),line(s1,t1));
        cout << v.real() << " " << v.imag() << endl;
    }
    return 0;
}

Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;

int main(){ 
int s;
string n,a;
cin>>n;

s=n.size();
a=n.substr(s-1,s);
if(
a=="2"||a=="4"||a=="5"||a=="7"||a=="9"){
cout<<"hon"<<endl;
}
else if(
a=="0"||a=="1"||a=="6"||a=="8"){
cout<<"pon"<<endl;
}
else{
cout<<"bon"<<endl;
}

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, r;
  cin >> n >> r;
  if (n >= 10) {
    cout << r << '\n';
  } else {
    cout << r + 100 * (10 - n) << '\n';
  }
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll euclidean_gcd(ll a, ll b) {
  if(a < b) euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

double input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    ll ans=2018;
    FOR(i,a,b+1)FOR(j,i+1,b+1){
      if(!(j%2019) || !(i%2019)){
        cout << 0 << endl;
        return 0;
      }
      ans= min((ll)i*(ll)j%2019 , ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    string s; cin >> s;
    for(int i = 0; i <4; i++){
        if((i == 0 && s[i] != 'Y' ) || (i == 1 && s[i] != 'A')
        || (i == 2 && s[i] != 'K') || (i == 3 && s[i] != 'I' )){
            cout << "No" << endl;
            return 0;
        }
    }   
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

/*
void print(long a[], long n)
{
	for (long i = 1; i <= n; i++){
		printf("[%d] ", a[i]);
	}
	puts("");
}
*/
void sort(long data[], long left, long right)
{
	long sample = data[left], lptr = left, rptr = right;
	if (lptr < rptr){
		while (lptr != rptr){
			while ((sample < data[rptr]) && (lptr != rptr)) rptr--;
			if (lptr != rptr) data[lptr++] = data[rptr];
			while ((data[lptr] < sample) && (lptr != rptr)) lptr++;
			if (lptr != rptr) data[rptr--] = data[lptr];
		}
		data[lptr] = sample;
		sort(data, left, lptr - 1);
		sort(data, rptr + 1, right);
	}
}

long search(long x, long B[], long n)
{
	
	long l, h, m;
	l = 1; h = n;
	while (l <= h)
	{
		//printf("search for %d from %d - %d \n",x, l, h);
		m = (l + h) / 2;
		//printf("m=%d:\n ", m);
		if (x == B[m]){
			//printf("found>>%d\n", m);
			return m;
		}
		if (x > B[m]) l = m + 1;
		else h = m - 1;
	}
	//printf("Cannot Find\n");
	return -1;
}

long count(long A[], long B[], long C[], long n)
{
	sort(A, 1, n);
	//print(A, n);
	long i; long idx = 1; long id;
	for (i = 1; i <= n; i++) {
		if ((id = search(A[i], B, idx)) == -1) { B[idx++] = A[i]; C[idx - 1] += 1; /*print(B, idx);*/ }
		else { C[id] += 1; }
	}
	//printf("Finished!\n");
	return idx;
}


int main(void)
{
	long N, i, cnt;
	scanf("%ld", &N);
	long a[100001], b[100001] = { 0 }, c[100001] = { 0 };
	for (i = 1; i <= N; i++){ scanf("%ld", &a[i]); }
	//printf("Start Count\n");
	long idx = count(a, b, c, N);
	/*printf("Counted\n");
	print(a, N);
	
	print(b, idx);
	
	print(c, idx);
	*/
	cnt = 0; long x;
	for (i = 1; i <idx; i++){
		if (c[i] > 0){
			if (c[i] > b[i]) { x = c[i] - b[i]; }
			if (c[i] < b[i]) { x = c[i]; }
			if (c[i] == b[i]) { x = 0; }
			cnt += x;
		}
		else continue;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
       
using namespace std;
       
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
 
// #define MAX 100010
 
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
long long binpow(long long a,long long b)
{
    if (b == 1) return a;
    long long res = binpow(a, b/2)%MOD;
    if (b % 2) return (res*((res*a)%MOD))%MOD;
    else return (res * res)%MOD;
}

long long int fact(long long int a)
{
    if(a==0||a==1)
        return 1;
    long long int ans = 1;
    for(int i=a;i>=1;i--)
        ans = (ans * i)% MOD;
    return ans;
}

long long int ivmod(long long int a)
{
    return binpow(a,MOD-2);
}
 
long long int summ[1000005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    // #endif
    int a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
    return 0;
}

Measured memory_bytes: 256
// sandeep_007  
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define PI acos(-1)
#define mod 1000000007
#define ll long long
#define nitro std::ios_base::sync_with_stdio (false); cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define vi vector < ll >
#define mod 1000000007

bool sortbysec(const pair<ll,ll> &A,
              const pair<ll,ll> &b){
    return (A.second < b.second);
}
 
inline ll mx(ll A,ll b){
    if(A > b) return A;
    else return b;      
}

ll power(ll x,ll y,ll p){
    ll res = 1;   
    x = x % p;    
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
 
        y = y>>1; 
        x = (x*x) % p; 
    }
    return res;
}

ll gcd(ll A,ll b){if(b==0) return A; else return gcd(b,A%b);}

#define N 105
#define X(x,u,v) (b[x][v]-b[x][(u)-1])
#define Y(x,u,v) (a[v][x]-a[(u)-1][x])
int n,m,u,v;short dp[N][N][N][N],a[N][N],b[N][N],Ans;

short maxi(short A,short B){
    return max(A,B);
}

int main()
{
    #ifdef DBG
        freopen("in","r",stdin);
    #endif

    // scanf("%d%d",&n,&m);
    cin >> n >> m;
    for (int i=1;i<=n;i++){
        // scanf("%s",s+1);
        string s;
        cin >> s;
        for (int j=1;j<=m;j++)
        {
            if (s[j-1]=='E') u=i,v=j;
            if (s[j-1]=='o') a[i][j]=b[i][j]=1;
            a[i][j]+=a[i-1][j];
            b[i][j]+=b[i][j-1];
        }
    }

    for (int i=0;i<n;i++){
        for (int j=0;j<m;j++){
            for (int x1=1;x1+i<=n;x1++){
                for (int y1=1;y1+j<=m;y1++){
                    int x2=x1+i,y2=y1+j;
                    short tmp=dp[x1][x2][y1][y2];

                    Ans = maxi(Ans,dp[x1][x2][y1][y2]);
                    int x3=max(1,x2-(u-1)),x4=min(n,x1+(n-u)),y3=max(1,y2-(v-1)),y4=min(m,y1+(m-v));
                    
                    if (x3>x4||y3>y4) continue;
                    
                    if (x1>1&&x3<x1) dp[x1-1][x2][y1][y2] = maxi(dp[x1-1][x2][y1][y2],tmp+X(x1-1,max(y1,y3),min(y2,y4)));
                    if (x2<n&&x4>x2) dp[x1][x2+1][y1][y2] = maxi(dp[x1][x2+1][y1][y2],tmp+X(x2+1,max(y1,y3),min(y2,y4)));
                    if (y1>1&&y3<y1) dp[x1][x2][y1-1][y2] = maxi(dp[x1][x2][y1-1][y2],tmp+Y(y1-1,max(x1,x3),min(x2,x4)));
                    if (y2<m&&y4>y2) dp[x1][x2][y1][y2+1] = maxi(dp[x1][x2][y1][y2+1],tmp+Y(y2+1,max(x1,x3),min(x2,x4)));
                }
            }
        }
    }
    cout << Ans << "\n";
    // printf("%d\n",(int)Ans);
}


Measured memory_bytes: 225536
#include <bits/stdc++.h>
int main(void)
{
  int n, a[100001] = {}, tmp, d = 0;  
  std::cin >> n;
  for(int i = 0; i != n; i++){
    std::cin >> tmp;
    if(tmp > n) d++;
    else a[tmp]++;
  }
  for(int i = 1; i <= n; i++) d += (a[i] >= i ? a[i] - i : a[i]);
  std::cout << d << std::endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
	int H, W;
	cin >> H >> W;
	VT<string> C(H);
	REP(i, H) cin >> C[i];
	REP(i, 2 * H) {
		cout << C[(i) / 2] << endl;
	}
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())
K=int(input())

tag=False
for i in range(K+1):
    for j in range(K-i+1):
        for k in range(K-i-j+1):
            if (b*(2**j)) > (a*(2**i)) and (c*(2**k)) > (b*(2**j)):
                tag=True
if tag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;

int main(){
    int x, y, z;
    int k;
    cin >> x >> y >> z >> k;

    long long a[2000];
    long long b[2000];
    long long c[2000];

    for(int i = 0;i < x;i++) cin >> a[i];
    for(int i = 0;i < y;i++) cin >> b[i];
    for(int i = 0;i < z;i++) cin >> c[i];

    vector<long long> vec;

    for(int i = 0;i < x;i++){
        for(int j = 0;j < y;j++){
            vec.push_back(a[i] + b[j]);
        }
    }

    sort(vec.begin(), vec.end(), greater<long long>());

    vector<long long> ans;
    for(int i = 0;i < min((int)vec.size(), 4000);i++){
        for(int j = 0;j < z;j++){
            ans.push_back(vec[i]+c[j]);
        }
    }

    sort(ans.begin(), ans.end(), greater<long long>());

    for(int i = 0;i < k;i++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 42852
var i,j,k,m,n:longint;
s,st:string;
begin
  readln(m,n);
  str(m,st);str(n,s);
  s:=st+s;val(s,m);
   if trunc(sqrt(m))=sqrt(m) then writeln('Yes')
   else writeln('No');
end.


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll sz[4];
    sz[0] = a*c;
    sz[1] = a*d;
    sz[2] = b*c;
    sz[3] = b*d;
    ll M = sz[0];
    for(int i=1; i<4; i++) {
        M = max(M, sz[i]);
    }
    cout << M << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
bool cs(pair<int,int> a,pair<int,int> b){
  if(a.second==b.second)return a.first>b.first;
  else return a.second>b.second;
}
int main(){
  int n;cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n)cin>>a[i]>>b[i];
  vector<pair<int,int>> sum(n);
  rep(i,n){
    sum[i].second=a[i]+b[i];
    sum[i].first=i;
  }
  sort(sum.begin(),sum.end(),cs);
  //  rep(i,n)cout<<sum[i].second<<endl;
  ll sa=0;ll sb=0;
  rep(i,n){
    if(i%2==0)sa+=a[sum[i].first];
    else sb+=b[sum[i].first];
  }
  cout<<sa-sb<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	vi a(n), b(n);
	rep(i, n) {
		cin >> a[i];
		cin >> b[i];
	}
	vi c(m), d(m);
	rep(i, m) {
		cin >> c[i];
		cin >> d[i];
	}

	rep(i, n) {
		ll ans = INFL;
		int t;
		rep(j, m) {
			if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < ans) {
				ans = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				t = j + 1;
			}
		}
		cout << t << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < (int) n; i++)
#define forin(i, a, b) for(int i = a; i < (int) b; i++) 
#define rofin(i, a, b) for(int i = a; i > b; i--)
#define v vector
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define debug(i) cout << #i << ": " << i << endl
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int max_nodes = 1e6;
vi g[max_nodes];
int dist[max_nodes];
bool visited[max_nodes];
int in_degree[max_nodes];


void dfs(int a) {
    assert(!visited[a]);
    visited[a] = true;
    for(int b : g[a]) {
        dist[b] = max(dist[b], dist[a] + 1);
        in_degree[b]--;
        if(in_degree[b]==0) {
            dfs(b);
        }
    }

}

int main() {
    crap;
    int N, M;
    cin >> N >> M;
    forn(i, M) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        in_degree[y]++;
    }

    forin(i,1,N+1) {
        if(!visited[i] && in_degree[i]==0) {
            dfs(i);
        }
    }
    int ans = 0;
    forin(i, 1, N+1) {
        ans = max(ans, dist[i]);
    }

    cout << ans << endl;

}

Measured memory_bytes: 35072
#include<bits/stdc++.h>
using namespace std;
#define int long long
int extgcd(int a,int b,int& x,int& y){
  int d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}
int mod_inverse(int a,int m){
  int x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}
int mod_pow(int x,int n,int mod){
  int res=1;
  while(n>0){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}
int a[114514],b[114514],c[114514],r[114514];
signed main(){
  int n,s,w,q;
  while(cin>>n>>s>>w>>q,n){
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    memset(r,0,sizeof(r));
    int g=s;
    for(int i=0;i<n;i++){
      a[i+1]=(g/7)%10;
      if(g%2==0) g=(g/2);
      else g=(g/2)^w;
    }
    if(q==2||q==5){
      int ans=0,cnt=0;
      for(int i=0;i<n;i++){
	if(a[i+1]) cnt++;
	if(a[i+1]%q==0) ans+=cnt;
      }
      cout<<ans<<endl;
      continue;
    }
    for(int i=0;i<n;i++)
      b[i+1]=(b[i]*10+a[i+1])%q;
    map<int,int> m;
    m[0]=1;
    r[0]=1;
    for(int i=0;i<n;i++){
      r[i+1]=(r[i]*mod_inverse(10,q))%q;
      c[i+1]=(b[i+1]*r[i+1])%q;
      m[c[i+1]]++;
    }
    int ans=0;
    for(int i=0;i<n;i++){
      m[c[i]]--;
      if(!a[i+1]) continue;
      ans+=m[(b[i]*r[i])%q];
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 12240
#include <bits/stdc++.h>
using namespace std;

struct TXY{
    int t;
    int x;
    int y;
};

int distance(const struct TXY& lhs, const struct TXY& rhs){
    int dx = abs(lhs.x - rhs.x);
    int dy = abs(lhs.y - rhs.y);
    return dx + dy;
}

int main(){
    int N; cin >> N; N++;
    
    struct TXY txy_prev={0,0,0};
    for(int i=1; i<N; ++i){
        struct TXY txy_now;
        cin >> txy_now.t >> txy_now.x >> txy_now.y;
        
        int t = txy_now.t - txy_prev.t;
        int d = distance(txy_now, txy_prev);
//        if(t%d!=0){
        if((t+d)&1 || t<d){
            cout << "No";
            return 0;
        }
        txy_prev = txy_now;
    }
    cout << "Yes";
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int w,n,i,a,b;
	scanf("%d\n%d", &w, &n);
	int *row = (int *)malloc(sizeof(int) * w);
	for(i = 0; i < w; i++){
		row[i] = i + 1;
	}
	for(i = 0; i < n; i++){
		scanf("%d,%d", &a, &b);
		int tmp = row[a - 1];
		row[a - 1] = row[b - 1];
		row[b - 1] = tmp;
	}
	for(i = 0; i < w; i++){
		printf("%d\n", row[i]);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        sum += b[i];
    }
    for (int i = 0; i < n - 1; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < n; i++) {
        if (i > 0 && a[i] == a[i - 1] + 1) {
            sum += c[a[i - 1] - 1];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <set>

using namespace std;

inline int getInt() { int s; scanf("%d", &s); return s; }

// bad knowhow
#define ALL(c) (c).begin(), (c).end()
#define REP(i,n) for(long long i=0;i<(long long)n;++i)
#define MAX_SIZE 100

set<int> g_p[MAX_SIZE];
set<int> g_leak;

int main() {
	//freopen("Text.txt", "r", stdin);
	while (true) {
		REP(i, MAX_SIZE) g_p[i].clear();
		g_leak.clear();

		const int n = getInt();
		if (n==0) break;
		
		REP(i, n) {
			const int m = getInt();
			REP(j, m) g_p[i].insert(getInt()-1);
		}

		const int k = getInt();
		REP(i, k) g_leak.insert(getInt()-1);

		vector<int> suspect;
		REP(i,n) {
			vector<int> is;
			if (includes(ALL(g_p[i]), ALL(g_leak))) suspect.push_back(i);
		}

		cout << ((suspect.size()==1) ? suspect[0] + 1 : -1) << endl;
	}
}

Measured memory_bytes: 1612
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
 
  ll N,K;
  cin>>N>>K;
  
  vl h(N);
  rep(i,N)cin>>h[i];
  vl dp(100001);
  rep(i,N)dp[i]=2000000000;
  dp[0]=0; 
  for(ll i=1; i<N ;i++){
    for(ll j=i-1; j>=i-K && j>=0 ;j--){
      dp[i] =min(dp[i],dp[j]+abs(h[i]-h[j]) );
    }
 }
 cout<<dp[N-1]<<endl;;
}





Measured memory_bytes: 4760
import Text.Regex
import Text.Regex.Posix
import Data.Char

main = do
  s <- getContents
  mapM_ (putStrLn . cae) . lines $ s

cae::String -> String
cae s = head . filter (\x->x =~ "that|the|this")
        $ [rot i s| i<-[0..25]]

rot::Int -> String -> String
rot _ [] = []
rot n (x:xs) = if (ord x) >= (ord 'a') &&  (ord x) <= (ord 'z') then
               (aux n x):(rot n xs)
             else
               x:(rot n xs)
  where
    aux::Int -> Char -> Char
    aux n c = (!! ((ord c) - (ord 'a') + n)) . cycle
              $ "abcdefghijklmnopqrstuvwxyz"

Measured memory_bytes: 4420
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 1001001001;
    for (int i = 0; i <= s.size()-t.size(); i++) {
        int cnt = 0;
        rep(j,t.size()) {
            if (t[j] != s[i+j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        int k = sc.nextInt();

        int digits = n.length();

        int[] digit = new int[digits];
        int second = 0;
        int third = 0;
        long ans = 0;

        for(int i = 0 ; i < digits ; i++){
            digit[i] = Integer.valueOf(n.substring(i, i+1));
            if(i > 0 && digit[i] > 0){
                if(second == 0) {
                    second = i;
                }else if(third == 0){
                    third = i;
                }
            }
        }

        System.out.println(count(n, k));
    }

    static long count(String n, int k){
        int digits = n.length();

        int[] digit = new int[digits];
        int second = -1;

        long ans = 0;

        for(int i = 0 ; i < digits ; i++){
            digit[i] = Integer.valueOf(n.substring(i, i+1));
            if(i > 0 && digit[i] > 0){
                if(second == -1) {
                    second = i;
                }
            }
        }

        if(k == 1){
            return 9*(digits-1) + digit[0];
        }else if(k == 2){
            ans += 81 * (digits - 2) * (digits - 1) / 2;
            ans += 9 * (digits - 1) * (digit[0] - 1);
            if(second != -1) {
                return (ans + count(n.substring(second, digits), k - 1));
            }else{
                return (ans);
            }
        }else{
            ans += 729 * (digits - 3) * (digits - 2) * (digits - 1) / 6;
            ans += 81 * (digits - 2) * (digits - 1) * (digit[0] - 1) / 2;
            if(second != -1) {
                return (ans + count(n.substring(second, digits), k - 1));
            }else{
                return(ans);
            }
        }
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++) s.at(i) = 'x';

    cout << s << endl;

    return 0;

}

Measured memory_bytes: 256
(* O(|s|) *)
let string_count s sub =
  let n = String.length s in
  let sub_len = String.length sub in
  let reg = Str.regexp sub in
  let rec loop acc i =
    try
      if i >= n then
        acc
      else
        let j = Str.search_forward reg s i + sub_len in
        loop (acc + 1) j
    with
    | _ -> acc
  in
    loop 0 0

(* O(n^2) *)
let solve n ss =
  let b_start, a_end, both, ab = List.fold_left
    (fun (b_start, a_end, both, ab) s ->
      let count = string_count s "AB" in
      let new_ab = ab + count in
      let starts_b = s.[0] = 'B' and ends_a = s.[String.length s - 1] = 'A' in
      let new_b_start = if starts_b then b_start + 1 else b_start in
      let new_a_end = if ends_a then a_end + 1 else a_end in
      if starts_b && ends_a then
        new_b_start - 1, new_a_end - 1, both + 1, new_ab
      else
      new_b_start, new_a_end, both, new_ab)
    (0, 0, 0, 0)
    ss
  in
    let pair = min b_start a_end in
    let addition =
      if b_start + a_end >= 1 then
        both
      else if both >= 2 then
        both - 1
      else
        0
    in
      addition + pair + ab

(* O(n) *)
let rec fold_btw f a i n = if i >= n then a else fold_btw f (f a i) (i + 1) n
let fold_int f a n = fold_btw f a 0 n

let _ =
  let n = read_int () in
  fold_int
    (fun acc _ -> read_line () :: acc)
    []
    n |> solve n |> string_of_int |> print_endline

Measured memory_bytes: 5120
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
int a, b, n;
bool ex=false;

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int i, x; cin>>n;
	for(i=1 ; i<=n ; i++)
	{
		cin>>x;
		if(x%2==1) a++;
		else if(x%4==0) b++;
		else ex=true;
	}
	if(ex && a<=b) cout<<"Yes";
	else if(!ex && a<=b+1) cout<<"Yes";
	else cout<<"No"; return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<list>
#include<set>
using namespace std;
int main(){
int n,m,a[111],b[111][111];
int t[111];
memset(t,0,sizeof(t));
cin >> n;
cin >> m;
for(int i=1;i<=m;i++){
cin >> a[i];
}
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
cin >> b[i][j];
if(a[i]==b[i][j]){
t[j]++;
}else{
t[a[i]]++;
}
}
}
for(int i=1;i<=n;i++){
cout << t[i] << endl;
}
return 0;
}


Measured memory_bytes: 3076