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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rd(n) scanf("%d", &n)

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int main()
{
    int n; in >> n;
    int C[100]; memset(C, 0, sizeof(C));
    int D = 0;
    REP(i, n)
    {
        int x; in >> x;
        C[x]++;

        D = max(D, x);
    }

    bool flag = true;
    if(C[D] >= 2)
    {
        int p = (D+1)/2;
        REPE(i,1,p-1) if(C[i] > 0) flag = false;
        REPE(i,p+1,D) if(C[i] < 2) flag = false;

        if(D&1) // odd
        {
            if(C[p] != 2) flag = false;
        }
        else
        {
            if(C[p] != 1) flag = false;
        }
    } else flag = false;

    if(flag) out << "Possible\n";
    else out << "Impossible\n";

    return 0;
}


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

int main(){
    long long N,K,sum=0;
    cin >> N;
    K=N;
    while(K>0){
        sum+=K%10;
        K/=10;
    }
    if(N%sum==0)
    cout << "Yes" << endl;
    else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;

int h,n;

int main(){

	cin >> h >> n;
	
	int t,total = 0;
	for( int i = 0; i < n; i++ ){
		cin >> t;
		total += t;
	}

	if( total >= h )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
from copy import deepcopy

s = list(input())
k = int(input())

n = len(s)
if len(list(set(s))) == 1:
    print(n*k//2)
    exit()

n1 = 0
n2 = 0
s1 = deepcopy(s)
s2 = deepcopy(s) + deepcopy(s)

for i in range(n-1):
    if s1[i] == s1[i+1]:
        s1[i+1] = "?"
        n1 += 1

for i in range(2*n - 1):
    if s2[i] == s2[i+1]:
        s2[i+1] = "?"
        n2 += 1

d = n2 - n1

ans = n1 + d*(k-1)
print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
const int N = 3e5+10, P = 998244353;
int n, m, vis[N], sg[N], h[N], f[3][N];
vector<int> g[N];
void add(int &a, ll b) {a=(a+b)%P;}

int main() {
	h[0] = 1;
	h[1] = 1000000000000000000ll%P;
	REP(i,2,N-1) h[i] = (ll)h[i-1]*h[1]%P;
	scanf("%d", &n);
	REP(i,0,2) {
		scanf("%d", &m);
		REP(j,1,n) g[j].clear();
		REP(j,1,m) {
			int u,v;
			scanf("%d%d", &u, &v);
			if (u>v) swap(u,v);
			g[u].pb(v);
		}
		PER(j,1,n) {
			int sz = g[j].size();
			REP(k,0,sz) vis[k] = 0;
			for (int k:g[j]) vis[sg[k]] = 1;
			REP(k,0,sz) if (!vis[k]) {
				sg[j] = k;
				break;
			}
			add(f[i][sg[j]],h[j]);
		}
	}
	int ans = 0;
	REP(i,0,600) REP(j,0,600) {
		add(ans, (ll)f[0][i]*f[1][j]%P*f[2][i^j]);
	}
	printf("%d\n", ans);
}





Measured memory_bytes: 15232
// Problem B

#include <stdio.h>
//~ #include <iostream>
//~ #include <vector>
#include <string.h>
//~ #include <cassert>
//~ #include <algorithm>
//~ #include <set>
//~ #include <map>
//~ #include <math.h>
//~ #include <queue>
//~ #include <stack>

#define MAXN 200100
#define pb push_back
#define mp make_pair

//~ using namespace std;

//~ typedef long long int ll;
//~ typedef pair<int, int> ii;

char a[MAXN];

int main() {
  scanf("%s", a); 
  int i;
  int n = (int)strlen(a);
  for (i=0; i<n; i++)
    if (a[i] == '?')
      a[i] = 'D';
  printf("%s", a);
  return 0;
}


Measured memory_bytes: 1920
s = {}
for key in ("a", "b", "c"):
    s[key] = list(input())

cur = s["a"][0]
while len(s["a"]) != 0 and cur == "a" or len(s["b"]) != 0 and cur == "b" or len(s["c"]) != 0 and cur == "c":
    cur = s[cur].pop(0)
print(cur.upper())


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

int main() {

  int n;
  cin >> n;

  bool flg = true;
  int count = 1;


  while (flg) {
    int sum = count * 1.08;
    if (n == sum) {
      cout << count << endl;
      flg = false;
      return 0;
    } else if (n < sum){
      flg = false;
    } else {
      count++;
    }
  }

  cout << ":(" << endl;
  return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
typedef long long lint;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<typename T=lint> T in(){
    return *istream_iterator<T>(cin);
}

vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
int main(){
    while(1){
        lint w,h;
        cin>>w>>h;
        if(w==0&&h==0)break;
        vector<vector<lint>>v(h,vector<lint>(w));
        rep(i,h)rep(j,w){
            cin>>v[i][j];
        }
        lint ans=0;
        rep(i,h)rep(j,w){
            if(v[i][j]==0)continue;
            ans++;
            stack<pair<lint,lint>>s;
            s.emplace(i,j);
            while(!s.empty()){
                lint r,c;
                tie(r,c)=s.top();
                s.pop();
                rep(k,8){
                    if(r+dy[k]<0||h<=r+dy[k]||c+dx[k]<0||w<=c+dx[k])continue;
                    if(v[r+dy[k]][c+dx[k]]==1){
                        v[r+dy[k]][c+dx[k]]=0;
                        s.emplace(r+dy[k],c+dx[k]);
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3168
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


vector<bool> cnt(vvi G, int start)
{
    vector<bool> visited(G.size(), false);
    queue<int> Q;
    Q.push(start);
    
    while(!Q.empty()){
        int p = Q.front();
        Q.pop();
        if(visited[p]) continue;
        visited[p] = true;
        for(int e : G[p]){
            Q.push(e);
        }
    }
    
    return visited;
}


int func(int m)
{
    int n;
    cin >> n;
    
    vvi G1(n+2), G2(n+2);
    vi d(n+m);
    rep(i, n){
        cin >> d[i];
    }
    
    rep(i, n+1){
        rep(j, m){
            int v = i + j + 1 + d[i+j];
            if(0 <= v && v < n+2){
                G1[i].push_back(v);
                G2[v].push_back(i);
            }
        }
    }
    
    vector<bool> a = cnt(G1, 0), b = cnt(G2, n+1);
    rep(i, n+2){
        if(a[i] && !b[i]) return false;
    }
    return true;
}

int main()
{
    int m;
    while(cin >> m, m){
        cout << (func(m) ? "OK" : "NG") << endl;
    }
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    vector<int> ans(n,0);
    for(int re=0;re<2;re++){
        int count=0;
        for(int i=0;i<n;i++){
            if(s[i]=='R')count++;
            else{
                ans[i-1]+=(count+1)/2;
                ans[i]+=count/2;
                count=0;
            }
        }
        reverse(ans.begin(),ans.end());
        reverse(s.begin(),s.end());
        for(int i=0;i<n;i++){
            if(s[i]=='L')s[i]='R';
            else s[i]='L';
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll inv_mod(ll a, ll MOD)
{
    ll b = MOD, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t*b;   swap(a,b);
        u -= t*v;   swap(u,v);
    }
    u %= MOD;
    if(u < 0) u+= MOD;
    return u;
}

int main()
{
    ll i,j;
    ll n,m,k;
    cin >> n >> m >> k;
    
    int max_number = n*m - 2;
    int MOD = 1e9+7;
    
    vector<ll> fac(max_number+1,1);
    vector<ll> inv(max_number+1,1);
    vector<ll> finv(max_number+1,1);
    vector<ll> nCk(max_number+1,1);
    for(i = 2;i <= max_number;++i){
        inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
    }
    for(i = 1;i <= max_number;++i){
        fac.at(i) = fac.at(i-1)*i%MOD;
        finv.at(i) = finv.at(i-1)*inv.at(i)%MOD;
    }
    for(i = 1;i <= max_number;++i){
        nCk.at(i) = fac.at(max_number)*finv.at(i)%MOD*finv.at(max_number-i)%MOD;
    }


    ll tmp = 0;
    for(i = 0;i < n;++i){
        rep(j,m){
            tmp += m*((i+1)*i/2 + (n + i -1)*(n-i)/2 - i*(n - i));
            tmp += n*((j+1)*j/2 + (m + j -1)*(m-j)/2 - j*(m - j));
        }
        tmp %= MOD;
    }
    tmp *= inv_mod(2, MOD);
    tmp %= MOD;
    cout << tmp*nCk.at(k-2)%MOD << endl; 

    return 0;
}

Measured memory_bytes: 9600
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	public static void main(String[] args) {
		long a=scan.nextLong();
		long ans=0;
		long saisyo=a/11;
		ans+=saisyo*2;
		a-=saisyo*11;
		if(saisyo%2==0) {
			if(a>6) {
				ans+=2;
			}
			else if(a>0) {
				ans++;
			}
		}else {
			if(a>5) {
				ans+=2;
			}
			else if(a>0) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <stdio.h>

int main(void){
  int s; scanf("%d", &s);
  char color[101];
  scanf("%s", color);

  int i, r=0, b=0;
  for(i=0;i<s;i++){
	if(color[i] == 'R') r++;
	else b++;
  }

  if(r > b) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n,m;cin>>n>>m;
  int sum=0;
  rep(i,m){
    int buf;
    cin>>buf;
    sum+=buf;
  }
  int res=n-sum;
  if(res<0)res=-1;
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
 
int main() {
    ll h, w;
    cin >> h >> w;
 
    vvl board(h, vl(w));
    rep(i, h) {
        string s;
        cin >> s;
        rep(j, w) {
            if(s[j] == '#') {
                board[i][j] = 1;
            }
        }
    }
 
    ll ans = 0;
    rep(sx, h) {
        rep(sy, w) {

            if(board[sx][sy]) {
                continue;
            }

            vvl matrix(h, vl(w, -1));
            queue<pair<ll, ll>> next;
            
            next.push(make_pair(sx, sy));
            matrix[sx][sy] = 0;
            while(!next.empty()) {
                ll x = next.front().first;
                ll y = next.front().second;
                rep(i, 4) {
                    ll nx = x + dx[i];
                    ll ny = y + dy[i];
                    if(nx < 0 || h <= nx || ny < 0 || w <= ny) {   
                        continue;
                    }
                    if(matrix[nx][ny] >= 0) {
                        continue;
                    }
                    if(board[nx][ny]) {
                        continue;
                    }
                    matrix[nx][ny] = matrix[x][y] + 1;
                    next.push(make_pair(nx, ny));
                }
                next.pop();
            }
 
            ll now = 0;
            rep(i, h) {
                rep(j, w) {
                    chmax(now, matrix[i][j]);
                }
            }

            chmax(ans, now);
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    string s;
    cin>>s;
    string ans;
    if(s[s.size() -  1] == 's')
    ans = s+"es";
    else
    {
        ans = s + "s";
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3660
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
ll n,a,b;
int main(){
	cin>>n>>a>>b;
	if(a==0&&b==0){
		cout<<0<<endl;return 0;
	}
	ll len=n/(a+b);
	cout<<a*len+min(a,n%(a+b));
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n, m, v, p = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
a.sort()
cumsum = [0] * (n+1)
for i in range(n):
    cumsum[i+1] = cumsum[i] + a[i]

hand = n - v 
ok = [0] * (n - p)
for i in range(n - p):
    total = cumsum[n-p+1] - cumsum[i+1] - a[i] * (n - p - i)
    maxval = a[n-p] - a[i]
    turn = max((total + hand - 1) // hand, maxval)
    if m >= turn:
        ok[i] = 1
ans = sum(ok) + p
print(ans)

Measured memory_bytes: 14172
while True:
    try:
        a,b,c,d,e,f=map(int,input().split())
    except:
        break
    
    ba=(a*e)-(d*b)
    x1=(c*e)-(f*b)
    y1=(a*f)-(d*c)

    x=round(x1/ba,4)
    if x==0:
        x=0.000
    y=round(y1/ba,4)
    if y==0:
        y=0.000
    print("{:.3f}".format(x),"{:.3f}".format(y))


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

string s;
bool a[100];

int main(){
  cin>>s;
  for(int i=0;i<(int)s.length();i++){
    a[s[i]-'a']=1;
  }
  for(int i=0;i<100;i++){
    if(!a[i]){
      cout<<(char)('a'+i)<<endl;
      return 0;
    }
    if(i==25){cout<<"None"<<endl;return 0;}
  }

}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                        
using namespace std;
                        
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                        
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int long long
#define ghost signed
#define left left228
#define right right228
#define complex complex228
#define count count228
#define sin sin228
#define list list228


ghost main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	string s;
	cin >> s;
	int n = (int)s.size();
	string last = "";
	int i = 0;
	int res = 0;
	while (i < n) {
		string cur = "";
		cur += s[i];
		if (cur != last) ++res, ++i, last = cur;
		else {
			if (i + 1 < n) ++res, cur += s[i + 1], i += 2, last = cur;
			else {
				break;
			}
		}
	}
	cout << res << '\n';
    return 0;
} // kek ;
// Ого! Кажетсья это $#@!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    ll n,k;
    cin >> n >> k;
    ll a[n];
    for (ll i=0;i<n;i++)cin >> a[i];
    queue<ll> que;
    que.push(1);
    ll i=0,visited[n];
    fill(visited,visited+n,-1);
    bool flag=true;
    while(i<k){
        i++;
        ll c=que.front();
        if (visited[c-1]!=-1 and flag){
            k=(k-i)%(i-visited[c-1]);
            i=0;
            flag=false;
            que.pop();
            que.push(a[c-1]);
            continue;
        }
        visited[c-1]=i;
        que.pop();
        que.push(a[c-1]);
    }
    cout << que.front() << endl;
    return 0;
}
 
 


Measured memory_bytes: 6300
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long A, B;
    scan(A, B);
    if (A < 10 && B < 10)
    {
        writeln(A * B);
    }
    else
    {
        writeln(-1);
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

int main() {
	ll N, M;
	cin >> N >> M;

	vector<pair<ll, pair<bool, ll>>> E;
	vector<ll> C(M);
	vector<ll> sumC(M, 0);

	vvi graph(M, vi());
	ll ans = 0;

	rep(i, M) {
		ll l, r, c;
		cin >> l >> r >> c;
		E.pb(mp(l, mp(false, i)));
		E.pb(mp(r, mp(true, i)));
		C[i] = c;
	}

	sort(all(E));

	multiset<ll> CC; //cheap cost
	vi NC;

		/*
	for (auto e : E) {
		cout << e << endl;
	}
		//*/

	rep(i, 2 * M) {
		/*
		cout << i << ": ";
		for (auto itr = CC.begin(); itr != CC.end(); ++itr) {
			cout << *itr << ", ";
		}
		cout << endl;
		//*/

		ll pos = E[i].first;
		bool start = !E[i].second.first;
		ll index = E[i].second.second;
		ll cost = C[index];

		if (start) {
			if (pos == 1) {
				sumC[index] = cost;
			}
			else {
				if (CC.empty()) {
					cout << -1 << endl;
					return 0;
				}
				sumC[index] = *(CC.begin()) + cost;
			}
			CC.insert(sumC[index]);
		}
		else {
			if (pos == N) {
				NC.pb(sumC[index]);
			}

			auto itr = CC.find(sumC[index]);
			// cout << index << "..." << sumC[index] << endl;
			CC.erase(itr);
		}
	}

	sort(all (NC));
	if (NC.size() == 0) {
		cout << -1 << endl;
		return 0;
	}

	cout << NC[0] << endl;
	return 0;
}

Measured memory_bytes: 12272
import java.util.*;
import java.lang.*;

/**
 * SevenPuzzle
 */
public class Main {

    public static void main(String[] args) {
        int[] dx = { 1, -1, 0, 0 };
        int[] dy = { 0, 0, 1, -1 };
        int cost = 1;

        Queue<String> queue = new ArrayDeque<>(); // キュー（状態を入れる）
        HashMap<String, Integer> hashmap = new HashMap<String, Integer>(); // ハッシュマップ（状態と何回0を動かすかを対応）

        // 幅優先探索
        queue.add("01234567");
        hashmap.put("01234567", 0);

        while (!queue.isEmpty()) {
            int mawarukaisuu = queue.size();
            for (int j = 0; j < mawarukaisuu; j++) {
                String str = queue.poll(); // キュー取り出し
                int zeroX = str.indexOf("0") % 4;
                int zeroY = str.indexOf("0") / 4;

                for (int i = 0; i < 4; i++) {
                    int newX = zeroX + dx[i];
                    int newY = zeroY + dy[i];

                    if (newX < 0 || newX > 3 || newY < 0 || newY > 1) {
                        continue;
                    }

                    String newStr;
                    if (str.indexOf("0") < newX + newY * 4) {
                        newStr = str.substring(0, str.indexOf("0")) + str.charAt(newX + newY * 4)
                                + str.substring(str.indexOf("0") + 1, newX + newY * 4) + "0"
                                + str.substring(newX + newY * 4 + 1);
                    } else {
                        newStr = str.substring(0, newX + newY * 4) + "0"
                                + str.substring(newX + newY * 4 + 1, str.indexOf("0")) + str.charAt(newX + newY * 4)
                                + str.substring(str.indexOf("0") + 1);
                    }

                    if (hashmap.get(newStr) == null) {
                        // ハッシュマップに格納(もともとあったら虫)
                        hashmap.put(newStr, cost);

                        // 動かした後の物をキューに追加
                        queue.add(newStr);
                    }

                }
            }
            cost++;
        }

        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            String str = "";

            for (int i = 0; i < 8; i++) {
                str = str + sc.next();
            }

            System.out.println(hashmap.get(str)); // ハッシュマップに変更せよ
        }

        sc.close();
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n,m;
ll a[211111];
ll imos[211111],rc[211111];
ll res=INF;
ll sum=0;

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>m;
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  rep(i,n-1){
    if(a[i]<a[i+1]){
      imos[a[i]+1]++;
      imos[a[i+1]]--;
    }else{
      imos[(a[i]+1)%m]++;
      if(a[i]+1<m)imos[0]++;
      imos[a[i+1]]--;
    }
    rc[a[i+1]]+=(a[i+1]-a[i]+m-1)%m;
  }
  rep(i,200010){
    imos[i+1]+=imos[i];
  }
  rep(i,n-1){
    sum+=min((a[i+1]-a[i]+m)%m,a[i+1]+1);
  }
  rep(x,m){
    minch(res,sum);
    sum-=imos[x];
    sum+=rc[x];
  }
  cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 3456
#include <iostream>
using namespace std;
int main()
{
	int sum=0,n,i;
	cin>>n;
	i=n;
	while(n!=0)
	{
		sum+=n%10;
		n=n/10;
	}
	if(i%sum==0)
	  cout<<"Yes";
	else
	  cout<<"No";
	  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

int main(void) {
    llong H, W;

    cin >> H >> W;

    llong cost[10][10];

    FOR(i, 10) {
        FOR(j, 10) {
            cin >> cost[i][j];
        }
    }

    llong numberCount[10] = {0};
    llong number;

    FOR(i, H) {
        FOR(j, W) {
            cin >> number;
            if (number != -1) {
                ++numberCount[number];
            }
        }
    }

    auto weight = [] (llong start, llong cost[10][10]) {
        llong minCost[10];
        FOR(i, 10) {
            minCost[i] = INF;
        }

        priority_queue<
            pair<llong, llong>,
            vector<pair<llong, llong>>,
            greater<pair<llong, llong>>> nodeHeap;
        nodeHeap.push(make_pair(0, start));

        while (!nodeHeap.empty()) {
            llong nowCost = nodeHeap.top().first;
            llong node = nodeHeap.top().second;
            nodeHeap.pop();

            if (minCost[node] <= nowCost) {
                continue;
            }

            minCost[node] = nowCost;

            FOR(i, 10) {
                if (i == node) {
                    continue;
                }
                llong newCost = nowCost + cost[node][i];
                nodeHeap.push(make_pair(newCost, i));
            }
        }

        return minCost[1];
    };

    llong ans = 0;

    FOR(i, 10) {
        (i, cost);
        ans += weight(i, cost) * numberCount[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M), d(M - 1);
    for (auto& i : X) cin >> i;
    sort(X.begin(), X.end());
    for (int i = 0; i < M - 1; i++) d[i] = X[i + 1] - X[i];
    sort(d.begin(), d.end());
    if (M - N < 0) cout << 0 << endl;
    else cout << accumulate(d.begin(), d.begin() + M - N, 0) << endl;
}


Measured memory_bytes: 1152
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long[] a = new long[4];
        for (int i = 0; i < 4; i++) a[i] = scan.nextLong();
        long ans = Long.MIN_VALUE;
        for (int i = 0; i <= 1; i++) {
            for (int j = 2; j <= 3; j++) {
                long val = a[i] * a[j];
                ans = Math.max(ans, val);
            }
        }
        System.out.println(ans);
    }
}


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

int main(){
  int n,a,b;
  cin >>n >>a >>b;
  int dist = b-a;
  if(dist%2==0) cout << "Alice" << endl;
  else cout << "Borys" << endl;
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	map<char, int>m;
	for (auto i : s) {
		m[i]++;
	}
	if (abs(m['a'] - m['b']) > 1 || abs(m['a'] - m['c']) > 1 || abs(m['c'] - m['b']) > 1) {
		cout << "NO\n";
	}
	else {
		cout << "YES\n";
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define LOOP(i,x,n) for(int i=(x);i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e17;

int dp[200][20004];

signed main(){
  int N,W;
  cin>>N>>W;
  vector<int> v(N),w(N);
  REP(i,N)cin>>v[i]>>w[i];

  REP(i,N){
    REP(j,W+1){
      dp[i][j+w[i]]=max(dp[i][j+w[i]],dp[i][j]+v[i]);
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
      dp[i+1][j+w[i]]=max(dp[i+1][j+w[i]],dp[i][j]+v[i]);
    }
  }
  // REP(i,N+1){
  //   REP(j,W+1){
  //     cout<<dp[i][j]<<' ';
  //   }
  //   cout<<endl;
  // }
  // cout<<endl;
  int ans=0;
  REP(j,W+1){
    ans=max(ans,dp[N][j]);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 12168
N, L = map(int, input().split(' '))

largest = L + N - 1
smallest = L

passZero = largest * smallest < 0

numSum = N * ( L + N / 2.0 - 0.5)

res = 0
if passZero:
    res = int(numSum)
else:
    if numSum > 0:
        res = int(numSum - L)
    elif numSum == 0:
        res = int(numSum)
    else:
        res = int(numSum-L-N+1)

print(res)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int count = 0;
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ans = (a-b+1) * (a-c+1);
		System.out.println(ans);
	}

}


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

int r,D,x_2000;
int main(void){
  cin>>r>>D>>x_2000;
  int x=x_2000;
  for(int i=0;i<10;i++){
    x=r*x-D;
    cout<<x<<endl;
  }
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int s = 0;
  while (m--) {
    int e;
    cin >> e;
    s += e;
  }
  cout << (s <= n ? n - s : -1) << endl;
}


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

using int64 = long long;
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

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

ll lcm(ll a, ll b) {
   return a / gcd(a, b) * b;
}

int main() {
   int64 N, X;
   cin >> N >> X;
   vec<int64> x(N);
   rep (i, N) {
      cin >> x[i];
   }
   x.push_back(X);
   sort(all(x));

   int64 dif = 1;
   vec<int64> D;
   repp (i, 1, x.size()) {
      // chmin(dif, x[i]-x[i-1]);
      D.push_back(x[i]-x[i-1]);
      // dbg(x[i]-x[i-1])
      // dif = lcm(dif, x[i]-x[i-1]);
   }

   sort(all(D));
   dif = D.back();
   rep (i, D.size()) {
      dif = min(dif, gcd(dif, D[i]));
   }

   cout << dif << endl;

   return 0;
}

Measured memory_bytes: 2800
main=do
 n<-readLn
 print$length$filter(f n)$(g n)++(g$n-1)
f n x
 |x==1=False
 |n`mod`x==0=f(n`div`x)x
 |otherwise=n`mod`x==1
g n=foldr f []$takeWhile((n>=).(^2))[1..n]
 where
  f i s
   |n`mod`i==0&&i*i<n=i:n`div`i:s
   |n`mod`i==0=i:s
   |otherwise=s

Measured memory_bytes: 1020
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;


int main()
{
	int a,b,c;cin >> a >> b >> c;
	
	int num = a;
	int cou = 0;
	
	while(cou < 100000)
	{
		num = (num+a)%b;
		if(num == c)
		{
			cout << "YES" << endl;
			return 0;
		}
		cou++;
	}
	
	cout << "NO" << endl;
	
	return 0;
}

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	// Taro = 1
	// Jiro = 0
	int dp[k + 1];
	dp[0] = 0;
	for (int i = 1; i <= k; i++) {
		dp[i] = 0;
		for (int j = 0; j < n; j++) {
			if (a[j] <= i) {
				if (dp[i - a[j]] == 0) {
					dp[i] = 1;
					break;
				}
			}
		}
	}
	if (dp[k] == 1) cout << "First\n";
	else cout << "Second\n";
 	return 0;
}

Measured memory_bytes: 3968
#include<stdio.h>
int a[200010];
int ans[200010];
int main(void){
  int n;
  scanf("%d",&n);
  for(int i=2;i<=n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=2;i<=n;i++){
    ans[a[i]]++;
  }
  for(int i=1;i<=n;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  ll ans = 1;
  for (int i = 1; i < N+1; i++) {
    ans *= i;
    ans %= 1000000007;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true){

			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();

			if(op.equals("?"))break;

			int ans = 0;

			switch(op){
			case "+":
				ans = a+b;
				break;
			case "-":
				ans = a-b;
				break;
			case "*":
				ans = a*b;
				break;
			case "/":
				ans = a/b;
				break;
			}

			System.out.printf("%d\n", ans);
		}
	}
}




Measured memory_bytes: 26344
#include <cstdio>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int n;
int k;
int nQuery;
int vs[2000+10];

int main(void) {
  scanf("%d%d%d", &n, &k, &nQuery);
  set<int> ss;
  REP(i, n) {
    scanf("%d", &vs[i]);
    ss.insert(vs[i]);
  }

  int res = 2000000000;
  for(int v : ss) {
    vector<int> cands;
    { // init
      vector<int> sorted;
      REP(i, n) {
        if(vs[i] < v) {
          sort(sorted.begin(), sorted.end());
          REP(j, sorted.size() - k + 1) {
            cands.push_back(sorted[j]);
          }
          sorted.clear();
        } else {
          sorted.push_back(vs[i]);
        }
      }
      if((int)sorted.size() >= k) {
        sort(sorted.begin(), sorted.end());
        REP(j, sorted.size() - k + 1) {
          cands.push_back(sorted[j]);
        }
      }
    }
    if((int)cands.size() >= nQuery) {
      sort(cands.begin(), cands.end());
      res = min(res, cands[nQuery-1] - v);
    }
  }
  printf("%d\n", res);
  
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
while(true) {
int r, c;
int fld[10000] = {0};
scanf("%d%d", &r, &c);
if(r == 0)
break;
for(int i = 0; i < r; ++i) {
for(int j = 0; j < c; ++j) {
int t;
scanf("%d", &t);
fld[j] |= t << i;
}
}
int ans = 0;
for(int bit = 0; bit < (1 << r); ++bit) {
int sum = 0;
for(int i = 0; i < c; ++i) {
int f = fld[i] ^ bit;
int x = 0;
for(int j = 0; j < r; ++j)
x += (f >> j) & 1;
sum += max(x, r - x);
}
ans = max(ans, sum);
}
printf("%d\n", ans);
}
return 0;
}

Measured memory_bytes: 1072
import static java.lang.Integer.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class Main {

	public static void main(String[] args){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
		try {
			st = new StringTokenizer(br.readLine());

			int N = parseInt(st.nextToken());
			int M = parseInt(st.nextToken());
			int[] P = new int[N];
			String[] ans = new String[M];

			Map<Integer, int[]> citys = new TreeMap<>();

			for(int i=0;i<M;i++) {
				st = new StringTokenizer(br.readLine());
				int n = parseInt(st.nextToken());
				int y = parseInt(st.nextToken());
				int[] info = new int[2];
				info[0] = n;
				info[1] = i;
				citys.put(y, info);
			}

			for(int key : citys.keySet()) {
				int[] c = citys.get(key);
				ans[c[1]] = String.format("%06d%06d", c[0],++P[c[0]-1]);
			}

			for(String a : ans) {
				System.out.println(a);
			}


		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			System.out.println("IOException");
		}


	}
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  std::string S;
  std::cin >> S;
  S += 'R';

  char search = 'L';
  int cur_pos = 0;

  vector<ll> ans(sz(S));
  rep(i, 0, sz(S)) {
    if (search != S[i]) continue;
    if (S[i] == 'L') {
      int diff = 1;
      rrep(j, i, cur_pos) {
        ans[i - diff]++;
        diff ^= 1;
      }

      cur_pos = i;
      search = (search == 'L' ? 'R' : 'L');
    }

    if (S[i] == 'R') {
      int diff = 0;
      rep(j, cur_pos, i) {
        ans[cur_pos - diff]++;
        diff ^= 1;
      }

      cur_pos = i;
      search = (search == 'L' ? 'R' : 'L');
    }
  }

  string s;
  for (ll val : ans) {
    s += to_string(val) + " ";
  }

  s.pop_back();
  s.pop_back();
  s.pop_back();
  cout << s << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 1856
#include <iostream>
#include <iomanip>
#include <string>
#include <map>

using namespace std;
 
int main()
{
    string S;
    cin >> S;

    if (S == "Sunny") {
        cout << "Cloudy";
    } else if (S == "Cloudy") {
        cout << "Rainy";
    } else {
        cout << "Sunny";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <time.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long  ll;
static const ll INF = (ll)1 << 62;
static const ll MOD = 1e9 + 7;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll s[100002];
int main() {
	ll n, m; cin >> n >> m;
	ll ans = 0;

	rep(i, 0, m) {
		ll l, r; cin >> l >> r;
		s[l]++;
		s[r + 1]--;
	}

	repe(i, 1, n) s[i] += s[i - 1];

	repe(i, 1, n) {
		if (s[i] == m) {
			ans++;
		}
	}

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

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

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

using namespace std;

int main(){
  int r,g,b;
  cin>>r>>g>>b;

  if((100*r+10*g+b)%4==0){
    cout<<"YES";
  }else{
    cout<<"NO";
  }
  
  return 0;
}


Measured memory_bytes: 256
sub f{my$r=$v[my$u="@_"]=my$s=1;my$p=$h[my$c=$c[$u-1]-1];$v[$_]or$a[$c]+=($;=($r+=$t=f($_))-$s-$h[$c]+$p)*$s,$s+=$;for@$u;$a[$c]+=($p+$r-$h[$c])*(@a-($h[$c]=$p+$r))+1;$r}@a=(0)x<>;@c=glob<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;f 1;print"@a"

Measured memory_bytes: 590688
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define INF 1000000007
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define CLR(a) memset((a), 0, sizeof(a))

using ll = long long;
using ull = unsigned long long;
using namespace std;

inline int toInt(string s){
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}

template<class T> inline string toString(T x){
    ostringstream sout;
    sout << x;
    return sout.str();
}

int main(void){

    char p;
    cin >> p;
    FOR(i,0,3){
        char a;
        cin >> a;

        if(a==p){
            cout << "Bad" << endl;
            return 0;
        }
        p = a;
    }
    cout << "Good" << endl;

    return 0;
}


Measured memory_bytes: 256