akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll fib(ll n){
    vll a(n+1);
    a[0] = 1;
    a[1]  = 1;

    REP(i,2,n+1){
        a[i] = a[i-1] + a[i-2];
        a[i] %= mod;
    }

    return a[n-1];
}

int main()
{
    ll n;
    cin >> n;
    vll a(n),b(n);
    rep(i,n)cin >> a[i] >> b[i];
    
    vector<pair<ll,ll>> tmp(n);
    rep(i,n){
        tmp[i].first = b[i];
        tmp[i].second = a[i];
    }

    sort(all(tmp));

    ll t = 0;

    rep(i,n){
        t += tmp[i].second;
        if(t > tmp[i].first){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin>>n;
  if (n%1000 == 0) cout<<0<<'\n';
  else cout<<1000 - (n%1000)<<'\n';
}

Measured memory_bytes: 3640
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var s = new HashSet<int>();
		for (var i = 0; i < N; i++) s.Add(F);
		WriteLine(s.Count);
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;
    ans += 1 * min(a, k); k -= a;
    if(k > 0) ans += 0 * min(b, k);
    k -= b;
    if(k > 0) ans += -1 * min(c, k);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                int cnt = 0;
                int l = 0;
                while(l < n){
                    if (cnt == 0 && s[l] == '0'+i) cnt++;
                    else if (cnt == 1 && s[l] == '0'+j) cnt++;
                    else if (cnt == 2 && s[l] == '0'+k) cnt++;
                    l++;
                }
                if (cnt == 3) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define setpre(a) cout.precision(a),cout<<fixed;
#define ALL(a) a.begin(),a.end()
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

ll k,q,d[10000],n,x,m,s[10000],s0[10000];

int main(){Tie
	cin>>k>>q;
	for(int i=0;i<k;i++){
		cin>>d[i];
	}
	while(q--){
		cin>>n>>x>>m;
		for(int i=0;i<k;i++){
			if(i==0)s[i]=d[i]%m,s0[i]=0;
			else s[i]=s[i-1]+d[i]%m,s0[i]=s0[i-1];
			if(d[i]%m==0) s0[i]++;
		}
		ll ans=0;
		__int128 tmp=s[k-1];
		tmp*=((n-1)/k);
		tmp+=x%m;
		if((n-1)%k>0)
			tmp+=s[(n-1)%k-1],ans+=s0[(n-1)%k-1];
		ans+=tmp/m;
		ans+=s0[k-1]*((n-1)/k);
		cout<<n-1-ans<<'\n';
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) (a).begin(),(a).end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define ub(s,x) upper_bound(all(s),x)-s.begin()
#define uniq(a) a.erase(unique(all(a)),a.end())
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    int x;
    cin>>x;
    cout<<((x==3 || x==5 || x==7) ? "YES" : "NO")<<endl;
    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
int main(void){
    double r,are,circ;
    scanf("%lf", &r);
    
    are=r*r*3.141592653589;
    circ=2*r*3.141592653589;
    
    printf("%f %f\n", are, circ);
    
    return 0;
}



Measured memory_bytes: 2104
(function(input) {
  var p = input.replace(/\n$/, '').split(' ');
  var n = p.length;
  var r = [];
  var max = '';
  for (var i = 0; i < n; i++) {
    var x = p.shift();
    if (x.length > max.length) {
      max = x;
    }
    if (x in r) {
      r[x]++;
    } else {
      r[x] = 0;
    }
  }
  var a = [];
  for (i in r) {
    var m = r[i];
    if (isNaN(m)) {
      m = 0;
    }
    if (m in a) {
      a[m].push(i);
    } else {
      a[m] = [i];
    }
  }
  console.log('%s %s', a[a.length - 1].join('\n'), max);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7640
#include <bits/stdc++.h>
using namespace std;
int main(){
	char  v;
	int vic = 0,i;
	for(i = 0;;++i){
		scanf("%c",&v);
		if(v == '\n')
			break;
		if(v == 'o'){
			++vic;
		}
	}	
	int x = 15-i;
	if(8-x <= vic){
		puts("YES");
		return 0;
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] hoge = new int[m];
        String[] fuga = new String[m];
        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                hoge[i] += (int)Math.pow(2, sc.nextInt()-1);
            }
            fuga[i] = Integer.toBinaryString(hoge[i]);
            while (fuga[i].length() < n) {
                fuga[i] = "0" + fuga[i];   
            }
        }
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
        }

        int ans = 0;
        for (int i = 0; i < Math.pow(2,n); i++) {
            String test = make_bi_nari(n, i);
            int check = 0;
            for (int j = 0; j < m; j++) {
                int count = 0;
                for (int l = 0; l < n;) {
                    if (test.charAt(l) == '1' && fuga[j].charAt(l) == '1'){
                        count++;
                    }
                    l++;
                }
                if (count % 2 == p[j]) {
                    check++;
                }
            }
            if (check == m) {
                ans++;
            }
        }

        System.out.println(ans);
        sc.close();
    }

    public static String make_bi_nari(int nbit, int num_to_binary) {
        String res = Integer.toBinaryString(num_to_binary);
        while(res.length() != nbit){
            res = "0" + res;
        }
        return res;
    }

}





Measured memory_bytes: 23124
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,t:Integer;
  l:array of Integer;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  //nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(s);

    if (s[1]='9')or(s[2]='9') then       
      Writeln('Yes')
    else  
      Writeln('No');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define test(t) int t;cin>>t;while(t--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
const int MOD = 1e9+7,MAX = 1e5+5;
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
ll modInv(ll a)
{
	return powN(a,MOD-2);
}

int visited[MAX];
vector<vector<int>> V(MAX+1);
vector<int> indeg(MAX+1);
int dist[MAX+1];

void dfs(int a)
{
	if(visited[a]) return;
	else
	{
		visited[a]=true;
		for(int b:V[a])
		{
			dist[b]=max(dist[b],dist[a]+1);
			--indeg[b];
			if(indeg[b]==0)
			{
				dfs(b);
			}
		}
	}
}

int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		V[x].push_back(y);
		indeg[y]++;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(visited[i]==0&&indeg[i]==0)
		{
			dfs(i);
		}
	}
	for(int i=1;i<=n;i++) ans=max(ans,dist[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 9984
// READ & UNDERSTAND
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first		
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s;
	cin >> s;
	int n=s.length();
	reverse(all(s));
	int ten = 1; int ans = 0; int cur = 0;
	map<int,int>mp;
	mp[0]++;
	for(int i=0; i<n; i++){
		cur = (cur+(s[i]-'0')*ten%2019)%2019;
		ten = (ten*10)%2019;
		ans += mp[cur];
		mp[cur]++;
	}
	cout << ans << endl;
}	


Measured memory_bytes: 3752
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100002;

int n, A[CMax], ats;
string S, T;

int main() {
    cin >> S;
    cin >> T;

    int i = S.length() - 1;
    int si = S.length() - 1;
    int ti = T.length() - 1;
    bool tik = true;

    for (int i = S.length() - T.length(); i >= 0 && tik; i--) {
        for (int j = 0; j < T.length(); j++) {
            if (S[i+j] != '?' && S[i+j] != T[j]) break;
            else if (j == T.length() - 1) tik = false;
        }
        if (!tik) {
            for (int j = 0; j < T.length(); j++) {
                S[i+j] = T[j];
            }
        }
    }

    if (tik) {
        cout << "UNRESTORABLE" << endl;
    } else {
        for (int i = 0; i < S.length(); i++) {
            if (S[i] == '?') S[i] = 'a';
        }

        cout << S << endl;
    }
}


Measured memory_bytes: 256
s = input()
t = input()
ans = len(t)
 
for i in range(len(s)):
  if (i + len(t) - 1 >= len(s)): break
  dif = 0
  for j in range(len(t)):
    if (s[i + j] != t[j]):
      dif += 1
  ans = min(ans, dif)
print(ans)

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int X,Y,Z,K;
ll A[1000], B[1000], C[1000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>X>>Y>>Z>>K;
    rep(i,0,X) cin>>A[i];
    rep(i,0,Y) cin>>B[i];
    rep(i,0,Z) cin>>C[i];
    sort(A,A+X);
    sort(B,B+Y);
    sort(C,C+Z);
    ll ok=0,ng=4e10;
    while(ng-ok>1){
        ll mid=(ok+ng)/2;
        ll res=0;
        rep(i,0,X){
            rep(j,0,Y){
                res+=C+Z-lower_bound(C, C+Z, mid-A[i]-B[j]);
            }
        }
        if(res>=K) ok=mid;
        else ng=mid;
    }
    vector<ll> v;
    int cnt=0;
    bool t=true;
    rep(i,0,X){
        rep(j,0,Y){
            rep(k,lower_bound(C, C+Z, ok-A[i]-B[j])-C,Z){
                v.pb(A[i]+B[j]+C[k]);
                if(A[X-1]+B[Y-1]+C[Z-1]!=A[i]+B[j]+C[k]) t=false;
                cnt++;
                if(t&&cnt>=K){
                    sor(v);
                    rer(i,K,0){
                        cout <<v[i]<<"\n";
                    }
                    return 0;
                }
            }
        }
    }
    sor(v);
    rev(v);
    rep(i,0,K){
        cout <<v[i]<<"\n";
    }
}

Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <iomanip>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <functional>

#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <cstdlib>


using namespace std;

#define tr(x) cout << x << endl;
#define tr2(x, y) cout << x << " " << y << endl;
#define tr3(x, y, z) cout << x << " " << y << " " << z << endl;
#define tr4(w, x, y, z) cout << w << " " << x << " " << y << " " << z << endl;
#define tr6(a, b, w, x, y, z) cout << a << " " << b << " " << w << " " << x << " " << y << " " << z << endl;

#define ll long long
#define fastIO  ios::sync_with_stdio(false); cin.tie(0);
inline int in() { int x; scanf("%d", &x); return x; }
inline ll inL() { ll x; scanf("%lld", &x); return x; }


const int N = 2e3 + 9;

vector <int> G[N];

int dfs(int v, int prev, int d, int lim) {
    int res = 0;
    if (d > lim) res++;
    
    for (int x : G[v]) {
        if (prev != x) {
            res += dfs(x, v, d + 1, lim);
        }
    }
    
    return res;
}

int main(){
#ifdef __APPLE__
    const clock_t begin_time = clock();
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    
    int n, k;
    n = in(), k = in();
    
    int u, v;
    for (int i = 1; i < n; i++) {
        u = in(), v = in();
        G[u].push_back(v);
        G[v].push_back(u);
    }
    
    if (k&1) {
        int ans = 1e9;
        
        for (int i = 1; i <= n; i++) {
            for (int x : G[i]) {
                ans = min(ans, dfs(i, x, 0, k / 2) + dfs(x, i, 0, k / 2));
            }
        }
        cout << ans << endl;
    } else {
        int ans = 1e9;
        
        for (int i = 1; i <= n; i++) {
            ans = min(ans, dfs(i, -1, 0, k / 2));
        }
        cout << ans << endl;
                      
    }
#ifdef __APPLE__
    cout << endl;
    cout << "Time : ";
    cout << float( clock () - begin_time ) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

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

int main(){
    int n;
    int t;
    vector<int> A;

    cin >> n;
    for(int i = 0; i < n-1; i++){
        cin >> t;
        A.push_back(0);
        A[t-1]++;
    }
    A.push_back(0);
    for(int i = 0; i < n; i++){
        cout << A[i] << endl;
    }
}

Measured memory_bytes: 4316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PGC
{
	class Program
	{
		static void Main(string[] args)
		{
			var header = Console.ReadLine().Split();

			var S = header[0];
			var T = header[1];

			System.Console.WriteLine($"{T}{S}");
		}
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
const int M = 102;
int g[M][M];
int c[M*M];
int h,w,n;
int main(){
    while(scanf("%d%d",&h,&w)!=EOF){
        scanf("%d",&n);
        memset(g,0,sizeof(g));
        for(int i=1;i<=n;++i) scanf("%d",c+i);
        int k=1,t=1;
        int i=0,j=w-1;
        g[i][j]=1;
        if(--c[k]==0) ++k;
        while(t<h*w){
            while(i+1<h && g[i+1][j]==0) {
                g[++i][j]=k;
                if(--c[k]==0) ++k;
                ++t;
            }
            while(j-1>=0 && g[i][j-1]==0){
                g[i][--j]=k;
                if(--c[k]==0) ++k;
                ++t;
            }
            while(i-1>=0 && g[i-1][j]==0){
                g[--i][j]=k;
                if(--c[k]==0) ++k;
                ++t;
            }
            while(j+1<w && g[i][j+1]==0){
                g[i][++j]=k;
                if(--c[k]==0) ++k;
                ++t;
            }
        }
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j)
                printf("%d%c",g[i][j],j==w-1?'\n':' ');
        }
    }
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <utility>
using namespace std;

int main() {
	int n, x, p, minx, sum = 0, ans = 0;
	cin >> n >> x;
	cin >> p;
	minx = p;
	sum += p;
	ans ++;
	for(int i = 0; i < n-1; i++){
		cin >> p;
		minx = min(p, minx);
		sum += p;
		ans ++;
	}
	ans += (x - sum) / minx;
	cout << ans;
}

Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)


import math
# isprime, prime_division

def isprime(x):
    q = int(math.sqrt(x))  # int() rounds to zero
    for i in range(2,q+1):   # upto q
        if x%i == 0:
            return False
    return True

x = inn()
for i in range(x,10**5+10000):
    if isprime(i):
        print(i)
        exit()


Measured memory_bytes: 38644
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

int L;

int main() {
    cin >> L;
    vector<vector<long long>> dp(L + 1, vector<long long>(5));
    for (int i = 0; i < L; i++) {
        int a;
        cin >> a;
        dp[i + 1][0] = dp[i][0] + a;
        long long m = min(dp[i][0], dp[i][1]);
        int even = a == 0? 2: a % 2;
        dp[i + 1][1] = m + even;
        m = min(m, dp[i][2]);
        dp[i + 1][2] = m + (a + 1) % 2;
        m = min(m, dp[i][3]);
        dp[i + 1][3] = m + even;
        m = min(m, dp[i][4]);
        dp[i + 1][4] = m + a;
    }
    long long ans = dp[L][0];
    for (int i = 1; i < 5; i++) {
        ans = min(ans, dp[L][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 14336
#include <iostream>
#include <climits>
using namespace std;

int main() {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n==0 && m==0) {
      break;
    }
    int a[n];
    for (int i=0; i<n; i++) {
      cin >> a[i];
    }
    int ans = -INT_MAX;
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
	if (i!=j && a[i]+a[j]<=m) {
	  ans = max(ans,a[i]+a[j]);
	}
      }
    }
    if (ans<0) {
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;

char section[20000];
int tot_area = 0;

int main()
{
	cin >> section;
	stack<int> S;
	stack<pair<int, int> > S2;

	for (int i = 0; i < strlen(section); i++)
	{
		if (section[i] == '\\')
		{
			S.push(i);
		}
		if (section[i] == '/' && !S.empty())
		{
			int left = S.top(); S.pop();
			tot_area += i - left;
			
			int area = i - left;
			while (!S2.empty() && S2.top().first > left)
			{
				area += S2.top().second;
				S2.pop();
			}
			S2.push(make_pair(left, area));
			
		}
		
	}

	vector<int> ans;
	int length = S2.size();
	if (length)
	{
		for (int i = 0; i < length; i++)
		{
			ans.push_back(S2.top().second);
			S2.pop();
		}

		cout << tot_area << endl << length << ' ';
		for (int i = length - 1; i > 0; i--)
			cout << ans[i] << ' ';

		cout << ans[0] << endl;
	}
	else
		cout << 0 << endl << 0 << endl;

//	cin.get();
//	cin.get();
	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;


int main() {
    int n, a;
    cin >> n;
    vector<int> v(n, 0);
    for (int i = 1; i < n; i++) {
        cin >> a;
        v[a - 1]++;
    }
    for (int i = 0; i < n; i++) {
        cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
ll N,M,x;
ll a[MAX],b[MAX];
ll A[MAX],B[MAX];
vector<ll> s,t,p;

int main(){  
  cin>>N>>M;
  s.resize(N);
  t.resize(N);
  for(int i=0;i<N;i++){
    cin>>s[i]>>t[i];
  }
  for(int i=0;i<M;i++){
    cin>>x;
    p.push_back(x);
  }
  p.push_back(0);
  p.push_back(1e9);
  sort(p.begin(),p.end());

  for(int i=0;i+1<(int)p.size();i++){
    if(i%2)a[i]=p[i+1]-p[i];
    else b[i]=p[i+1]-p[i];
  }
  A[0]=a[0];
  B[0]=b[0];
  for(int i=0;i<(int)p.size();i++){
    A[i]=A[i-1]+a[i];
    B[i]=B[i-1]+b[i];
  }
  
  ll ans=0;
  for(int i=0;i<N;i++){
    ll si=upper_bound(p.begin(),p.end(),s[i])-p.begin()-1;
    ll ti=upper_bound(p.begin(),p.end(),t[i])-p.begin()-1;

    if(s[i]<t[i]){
      ans-=(s[i]-p[si]);
      if(a[si]>0){
	ans+=A[ti];
	if(si)ans-=A[si-1];
	if(a[ti]>0)ans-=(p[ti+1]-t[i]);
      }else if(b[si]>0){
	ans+=B[ti];
	if(si)ans-=B[si-1];
	if(b[ti]>0)ans-=(p[ti+1]-t[i]);
      }
    }else{
      if(s[i]==p[si])si--;
      ans-=(p[si+1]-s[i]);
      if(a[si]>0){
	ans+=A[si];
	if(ti)ans-=A[ti-1];
	if(a[ti]>0)ans-=(t[i]-p[ti]);
      }else{
	ans+=B[si];
	if(ti)ans-=B[ti-1];
	if(b[ti]>0)ans-=(t[i]-p[ti]);	
      }      
    }

  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6800
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b;
	cin>>a>>b;
	long long li=1,ri=a;
	for(int i=0;i<b;i++){
		long long x,y;
		cin>>x>>y;
		if(y<li||ri<li){
			cout<<0<<endl;
			return 0;
		}
		else if(x>ri){
			cout<<0<<endl;
			return 0;
		}
		li=max(x,li);
		ri=min(y,ri);
	}
	cout<<abs(li-ri)+1<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int N;
using Edge = std::pair<int, int>;
using Graph = std::vector<std::vector<Edge>>;
Graph G;

std::vector<int> res;

void dfs(const int v, const int p) {
  for (auto e : G[v]) {
    if (e.first == p)
      continue;
    res[e.first] = (e.second % 2 == 0) ? res[v] : 1 - res[v];
    dfs(e.first, v);
  }
}

int main() {
  // Input
  std::cin >> N;
  G.resize(N);
  for (int i = 0; i < N - 1; ++i) {
    int u, v, w;
    std::cin >> u >> v >> w;
    G[u - 1].push_back({v - 1, w});
    G[v - 1].push_back({u - 1, w});
  }

  // Main
  res.assign(N, -1);
  res[0] = 0;
  dfs(0, -1);

  // Output
  for (int i = 0; i < N; ++i)
    std::cout << res[i] << std::endl;

  return 0;
}


Measured memory_bytes: 8960
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  real l;
  cin.scan(l);
  writefln("%.12f", (l / 3.0) ^^ 3);
}


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

int main(){
  pair<int, int> a[5];
  int tempans=0, cnttemp=0;
  for(int i=0; i<5; i++){
    cin >> a[i].second;
    if(a[i].second%10==0){
      tempans+=a[i].second;
      a[i].first=0;
      cnttemp++;
      continue;
    }

    a[i].first=(a[i].second)%10;
  }

  sort(a, a+5);
  
  int ans=0, temp=0;
  for(int i=4; i>cnttemp; i--){
    temp=a[i].second;
    ans+=(temp+10)-temp%10;
  }

  cout << ans+tempans+a[cnttemp].second << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import re

S=input()
if S.isalpha():
    pattern='[A,T,C,G][A,T,C,G][A,T,C,G][A,T,C,G]*'
    match_list=re.findall(pattern, S)
    if match_list:
        size_str=[]
        for item in match_list:
            size_str.append(len(item))
        print(max(size_str))
    else:
        pattern='[A,T,C,G][A,T,C,G][A,T,C,G]'
        match_list=re.findall(pattern, S)
        if match_list:
            print("3")
        else:
            pattern='[A,T,C,G][A,T,C,G]'
            match_list=re.findall(pattern, S)
            if match_list:
                print("2")
            else:
                pattern='[A,T,C,G]'
                match_list=re.findall(pattern, S)
                if match_list:
                    print("1")
                else:
                    print("0")


Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;


int main(){
	string str, ans;
	int i;
	cin >> str;

	for(i=0 ; i<str.size() ; i++){
		ans += str[str.size()-i-1];
	}

	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){

	string s,aux1,aux2,aux3;

	cin >> s;

	string s1 = s.substr(0,(s.size()-1)/2);
	string s2 = s.substr((s.size()+3)/2-1);

	aux1 = s1;reverse(s1.begin(),s1.end());
	aux2 = s2;reverse(s2.begin(),s2.end());
	aux3 = s;reverse(s.begin(),s.end());

	cout << (aux1 == s1 && aux2 == s2 && aux3 == s ? "Yes" : "No") << '\n';
 
	return 0;
}

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

using namespace std;

int sosuu[]={
        11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381
};

int main() {
    int n;
    cin>>n;
    for (int i = 0; i < n-1; ++i) {
        cout<<sosuu[i]<<" ";
    }
    cout<<sosuu[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int temp;
	long long avg;
	int i;
	
	
	avg = 0;
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d", &temp);
		avg += temp;
	}
	
	avg /= n;
	
	printf("%lld\n", avg);
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  string s;cin>>s;
  sort(ALL(s));
  bool ans = true;
  rep(i,s.size()-1) if (s[i] == s[i+1]) ans = false;
  cout << (ans?"yes":"no") << endl;
}


Measured memory_bytes: 256
package main
import (
  "fmt"
  // "math"
)

func main() {
  var (
    N string
  )
  fmt.Scan(&N)

  if string(N[0]) == "9" || string(N[1]) == "9" {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }

}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    int a[100010] = {};
    int inp;
    rep(i,0,n) {
        cin >> inp;
        a[inp]++;
    }
    int ans = 0, cnt = 0;
    rep(i,0,100010) {
        if(a[i] != 0) ans++;
        if(a[i] != 0 && a[i] % 2 == 0) {
            // printf("find: %lld\n", i);
            cnt++;
        }
    }

    // printf("cnt = %lld\n", cnt);
    if(cnt % 2 == 0) cout << ans << endl;
    else cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string s,t;
    int start;
    bool check=false;
    cin>>s>>t;
    rep(i,s.size()-t.size()+1){
        for(int j=i;j<i+t.size();j++){
            if(s.at(j)==t.at(j-i)||s.at(j)=='?'){
                if(j==i+t.size()-1){

                    check=true;
                    start=i;
                    break;
                }
                else{
                    continue;
                }
                
            }
            else{
                break;
            }
        }
    }
    if(check){
        for(int i=start;i<start+t.size();i++){
            s.at(i)=t.at(i-start);
        }
        rep(i,s.size()){
            if(s.at(i)=='?'){
                s.at(i)='a';
            }   
        }
        cout<<s;
    }
    else{
        cout<<"UNRESTORABLE";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a;
	cin>>a;
	while(a>=0){
		if(a%4==0){
			cout<<"Yes"<<endl;
			return 0;
		}
		else if(a==0){
			cout<<"Yes"<<endl;
			return 0;
		}
		else
			a-=7;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

using namespace std;

int main() {
    long long int L; cin >> L;
    long long int R; cin >> R;

    if (L + 2019 < R)
    {
        L %= 2019;
        R = 2020;
    }
    else if (L % 2019 >= R % 2019)
    {
        L %= 2019;
        R = R % 2019 + 2019;
    }
    else
    {
        L %= 2019;
        R %= 2019;
    }

    int ans = 2018;
    int res;
    for (int l = L; l <= R; l++)
    {
        for (int r = l+1; r <= R; r++)
        {
            res = l * r % 2019;
            if (res == 0)
            {
                cout << 0 << endl;
                return 0;
            }
            else if (res < ans)
            {
                ans = res;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	ff 				first
#define 	ss 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
// vll pwx(32);
// void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve(){
    ll n, d, x, y, ans = 0;
    cin >> n >> d;

    rep(i, 0, n){
        cin >> x >> y;
        if(x*x + y*y <= d*d)
            ans++;
    }
    cout << ans << nl;
}

int main(){
    boost;
    // cal(3);

    // // For getting input from input.txt file 
    // freopen("alchemy_input.txt", "r", stdin); 
  
    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout);

    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}


Measured memory_bytes: 3612
readstr() = split(readline())
readnum(T::Type{<:Number} = Int) = parse.(T, split(readline()))
let
  X, N = readnum()
  p = readnum()
  X ∉ p && (println(X); exit())
  tmp = 0
  for ans = 0:101
    ans ∈ p && continue
    if X - ans > 0
      tmp = X - ans
    else
      if ans - X < tmp
        println(ans)
        break
      else
        println(X - tmp)
        break
      end
    end
  end
end


Measured memory_bytes: 173824
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int n, a, b, c, d, v[4][3][10] = {};
	cin >> n;
	while (n--) {
		cin >> a >> b >> c >> d;
		v[a - 1][b - 1][c - 1] += d;
	}
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 10; ++k) {
				cout << " " << v[i][j][k];
			}
			cout << endl;
		}
		if (i < 3)
			cout << string(20, '#') << endl;
	}

	return 0;
}


Measured memory_bytes: 3096
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

ll A, B, K;

int main() {
    cin >> A >> B >> K;

    if (A > K) {
        A -= K;
    } else {
        B -= (K - A);
        A = 0;
        if (B < 0) B = 0;
    }

    cout << A << ' ' << B << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
using namespace std;
typedef pair<int,int> P;
const int INF = ~(1<<31) / 2;

int c[100][100];
int t[100][100];
int n,m,k;

int main(){
    while(1){
        scanf("%d %d",&n,&m);
        if(n==0) break;
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                c[i][j] = 1000000;
                t[i][j] = 1000000;
            }
        }
        for(int i=0;i<n;i++){
            int a,b,co,ti;
            scanf("%d %d %d %d",&a,&b,&co,&ti);
            a--;b--;
            c[a][b] = co;
            c[b][a] = co;
            t[a][b] = ti;
            t[b][a] = ti;
        }

        for(int k=0;k<m;k++){
            for(int i=0;i<m;i++){
                for(int j=0;j<m;j++){
                    c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
                    t[i][j] = min(t[i][j],t[i][k]+t[k][j]);
                }
            }
        }

        scanf("%d",&k);
        for(int i=0;i<k;i++){
            int p,q,r;
            scanf("%d %d %d",&p,&q,&r);
            p--;q--;
            if(r)printf("%d\n",t[p][q]);
            else printf("%d\n",c[p][q]);
        }
    }
    return 0;
}

Measured memory_bytes: 1264
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cctype>
using namespace std;
int main(){
	char a[1001];
	while(1){
	scanf("%s", a);
	if(a[0]=='0')break;
	int sum=0;
	for(int i=0; i<strlen(a); i++){
		sum+=a[i]-'0';
	}
	cout << sum <<endl;
	}
	return 0;
}


Measured memory_bytes: 3248
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

int main(){
    ll A,B;
    cin>>A>>B;
    ll ans=0;
    ll a=A%4;
    ll b=B%4;
    if(a+1==b || (a==b && (a==1 || a==3)) || (a==0 && b==2) || (a==2 && b==0) || (a==3 && b==0)){
        ans++;
    }else{
        ans=0;
    }
    int i=1;
    while(pow(2,i)<=max(A,B)){
        ll a=A%(ll)pow(2,i+1);
        ll b=B%(ll)pow(2,i+1);
        if(b>=a){
            if(b>=pow(2,i) && a<pow(2,i)){
                if((b-(ll)pow(2,i)+1)%2==1){
                    ans+=pow(2,i);
                }
            }else if(a<pow(2,i) && b<pow(2,i)){
                i++;
                //cout<<a<<","<<b<<" "<<ans<<endl;
                continue;
            }else{
                if((b-a)%2==0){
                    ans+=pow(2,i);
                }
            }
        }else{
            if(b<pow(2,i) && a>=pow(2,i)){
                if(((ll)pow(2,i+1)-a)%2==1){
                    ans+=pow(2,i);
                }
            }else if(a<pow(2,i) && b<pow(2,i)){
                i++;
                //cout<<a<<","<<b<<" "<<ans<<endl;
                continue;
            }else{
                if((a-b)%2==0){
                    ans+=pow(2,i);
                }
            }
        }
        //cout<<a<<","<<b<<" "<<ans<<endl;
        i++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=2e3+5;
int dis[maxn];
int main(){
	int n,x,y;
	cin>>n>>x>>y;
	for(int k=1;k<=n-1;k++){
		for(int i=1;i<=n;i++){
			int r=i+k;
			if(r>n)break;
			int tmp=k;
			tmp=min(min(tmp,abs(r-y)+abs(i-x)+1),abs(r-x)+abs(i-x));
			tmp=min(min(tmp,abs(r-y)+abs(i-y)),abs(r-x)+abs(i-y)+1);
			//cout<<i<<" "<<r<<" "<<tmp<<endl;
			dis[tmp]++;
		}
	}
	for(int k=1;k<=n-1;k++)cout<<dis[k]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
struct UnionFind{
	vector<int> par;
	UnionFind(int N){
		par.assign(N,0);
		rep(i,N) par[i]=i;
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		par[y]=x;
	}
};
string s[500];
int dx[4]={1,0,-1,0};
int dy[4] = {0,1,0,-1};
int main(){
	int H,W;
	cin>>H>>W;
	rep(i,H) cin>>s[i];
	UnionFind UF(H*W);
	rep(i,H) rep(j,W) rep(d,4){
		int ni = i + dx[d], nj = j+dy[d];
		if(0<=ni&&ni<H&&0<=nj&&nj<W && s[i][j] != s[ni][nj]) UF.unite(i*W+j,ni*W+nj);
	}
	using P = pair<int,int>;
	map<int,V<P>> mp;
	rep(i,H) rep(j,W) mp[UF.find(i*W+j)].pb(P(i,j));
	ll ans = 0;
	for(auto it: mp){
		ll a[2] = {};
		for(P p:it.sc) a[(p.fs+p.sc)%2]++;
		ans += a[0]*a[1];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 16256
program ABC060A
    implicit none
    character(10)::A,B,C
    read(5,*)A,B,C

    if(A(len_trim(A):len_trim(A))==B(1:1).and.B(len_trim(B):len_trim(B))==C(1:1))then
        print'(A)',"YES"
    else
        print'(A)',"NO"
    end if
end program ABC060A

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x,n,i,ans,j;
    int flag[105]= {0};
    cin>>x>>n;
    while(n--)
    {
        cin>>i;
        flag[i]=1;
    }
    if(flag[x]!=1)cout<<x<<endl;
    else
    {
        i=1;
        while(1)
        {
            if(flag[x-i]!=1)
            {
                cout<<x-i<<endl;
                break;
            }
            else if(flag[x+i]!=1)
            {
                cout<<x+i<<endl;
                break;
            }
            i++;

        }

    }
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

/********************Template********************/

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

	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	int d1 = x2-x1, d2 = y2-y1;
	cout << x2-d2 << " " << y2+d1 << " ";
	cout << x2-d2-d1 << " " << y2+d1-d2 << endl;

	rtn 0;
}

Measured memory_bytes: 256