akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
int bfs(vector<vector<ll>> &g , ll st,vector<ll> &see,vector<ll> &dist){
  ll rt=1;
  queue<ll> q;
  see[st]=1;
  q.push(st);
  while(!q.empty()){
    auto p=q.front();
    see[p]=1;
    q.pop();
    for(auto r:g[p]){
      if(see[r]!=0){
        if(dist[r]%2==dist[p]%2)rt=2;
        continue;
      }
      dist[r]=dist[p]+1;
      q.push(r);
    }
  }
  return rt;
}
int main()
{
ll n , m ;
cin >> n >> m ;
vector<vector<ll>> g(n);
vector<ll> see(n);
vector<ll> dist(n);
vector<ll> an(3);
set<ll> s;
rep(i, m)
{
  ll a, b;
  cin >> a >> b;
  s.insert(a-1);
  s.insert(b-1);
  g[a - 1].push_back(b - 1);
  g[b - 1].push_back(a - 1); //無向辺
}
an[0]=n-s.size();
rep(i,n){
  if(see[i]||s.find(i)==s.end())continue;
  an[bfs(g,i,see,dist)]++;
}
cout << an[0]*(2*n-an[0])+2*an[1]*an[1]+2*an[1]*an[2]+an[2]*an[2] << endl;
return 0;
}

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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'

ll func(ll n)
{
	ll coun = 0;
	
	if(n%2 == 0)
	{
		coun++;
		while(n%2  == 0)
		{
			n /= 2;
		}
	}
	
	ll lenn = sqrt(n);
	for(ll i = 3; i <= lenn;i+=2)
	{
		if(n%i == 0)
		{
			coun++;
			while(n%i == 0)
			{
				n /= i;
			}
		}
	}
	if(n > 2) coun++;
	return coun;
	
	
}

int main()
{
	ll a,b;
	
	cin >> a >> b;
	
	ll ans = __gcd(a,b);
	
	ll ash = func(ans);
	
	cout << ash+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long x, y, a, b, c, s = 0, i, j, k;
	cin >> x >> y >> a >> b >> c;
	vector<long long> p(a), q(b), r(c), v;
	for (i = 0; i < a; i++) cin >> p[i];
	for (i = 0; i < b; i++) cin >> q[i];
	for (i = 0; i < c; i++) cin >> r[i];
	sort(p.rbegin(), p.rend());
	sort(q.rbegin(), q.rend());
	sort(r.rbegin(), r.rend());

	s = 0;
	for (i = 0; i < x; i++) {
		v.push_back(p[i]);
		s += p[i];
	}
	for (i = 0; i < y; i++) {
		v.push_back(q[i]);
		s += q[i];
	}
	sort(v.begin(), v.end());
	for (i = 0; (i < c) && (i < v.size()); i++) {
		if (r[i] > v[i]) s += (r[i] - v[i]);
	}
	cout << s << "\n";

	return 0;
}




Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  rep(i,n){
    ll tmp;cin >> tmp;
    if(tmp%2==0 && tmp%3!=0 && tmp %5 != 0){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long mod=1e9+7;

int main() 
{ 
  string s,t;
  cin>>s>>t;
  int m=s.size();
  int n=t.size(); 
  int arr[m+1][n+1]; 
  for (int i=0;i<=m; i++){ 
	for (int j=0;j<=n;j++){ 
	   if(i==0||j==0) arr[i][j]=0; 
	   else if(s[i-1]==t[j-1]) arr[i][j]=arr[i-1][j-1] + 1; 
	   else arr[i][j]=max(arr[i-1][j],arr[i][j-1]); 
	 } 
   } 
  string res="";

  for(int i=m,j=n;i>=1,j>=1;){ 
	
	  if(s[i-1]==t[j-1]){res+=s[i-1];i--;j--;} 
 	  else if(arr[i-1][j]>arr[i][j-1]) i--;
	  else j--;
   } 
   reverse(res.begin(),res.end());
   cout<<res;
return 0; 
} 



Measured memory_bytes: 38776
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int power(long long int x,long long int y)
{
    long long int res=1;
    while(y>0)
    {
        if(y&1)
        res=(res*x)%mod;
        y>>=1;
        x=(x*x)%mod;
    }
    return res;
}
long long int dp[3001][3001];
    long int a,b,c,d;
    long long int mod2;
long long int fun(long long int row,long long int col)
{
    if(row<a || col<b)
    return 0;
    if(dp[row][col]!=0)
    return dp[row][col];
        if(row>a && col>b)
        dp[row][col]=((fun(row-1,col)*(col))%mod + (fun(row,col-1)*(row))%mod - ((row-1)*(col-1)*fun(row-1,col-1))%mod + mod)%mod;
        else
        dp[row][col] = ((fun(row-1,col)*col)%mod + (row*fun(row,col-1))%mod)%mod;
        //cout<<row<<" "<<col<<" "<<dp[row][col]<<endl;
        return dp[row][col];
}
int main() {
    cin>>a>>b>>c>>d;
    mod2=power(2,mod-2);
    for(long int i=0;i<=c;i++)
    for(long int j=0;j<=d;j++)
    dp[i][j]=0;
    dp[a][b]=1;
    /*long long int fact[1000001],infact[1000001];
    fact[0]=infact[0]=1;
    for(long int i=1;i<=1000000;i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
        infact[i]=(infact[i-1]*power(i,mod-2))%mod;
    }
    long int pp = c-a+d-b;
    long long int ans=fact[c*d-a*b];
    ans=(ans*infact[pp])%mod;
    ans=(ans*infact[c*d-a*b-pp])%mod;*/
    cout<<fun(c,d);
}


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

int main(void)
{
    long long N;
    cin >> N;

    long long A[210000];
    for (int i = 0; i < N; i++) cin >> A[i];

    long long total = 0;
    sort(A,A+N, greater<long long>());  
    total += A[0];
    for (int i=0; i < (N-2)/2; i++){
        total += A[i+1]*2;
    }
    if((N-2) % 2 == 1) total += A[(N-2)/2 +1];

    cout << total << endl;
}


Measured memory_bytes: 5168
n,y=map(int,input().split())
flag=False
for a in range(n+1):
    for b in range(n-a+1):
        if y-10000*a-5000*b==1000*(n-a-b):
            print(a,b,n-b-a)
            flag=True
            break
    if flag: break
if flag==False: print("-1 -1 -1")

Measured memory_bytes: 40684
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b,c,d;
    a=read(), b=read(), c=read(), d=read();
    int x=a+b, y=c+d;
    if(x>y) puts("Left");
    else if(x<y) puts("Right");
    else puts("Balanced");
    return 0;
}

Measured memory_bytes: 3576
N=int(input())
L=list(map(int,input().split()))

L = sorted(L)
count=0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
        if L[i]+L[j]>L[k]:
          count += 1
          
print(count)

Measured memory_bytes: 9196
#include<stdio.h>
int main()
{
	int i,t,n,s,f;
	while(1){
		scanf("%d",&t);
		if(t==0){
			break;
		}
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d%d\n",&s,&f);
			t-=(f-s);
		}
		if(t<=0){
			printf("OK\n");
		}else{
			printf("%d\n",t);
		}
	}
	return 0;
}

Measured memory_bytes: 2696
s = input()

f = True
for i in range(0, len(s), 2):
  if not (s[i] == 'R' or s[i] == 'U' or s[i] == 'D'):
    f = False
for i in range(1, len(s), 2):
  if not (s[i] == 'L' or s[i] == 'U' or s[i] == 'D'):
    f = False
print('Yes' if f else 'No')


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int least=40;
  for (int i=0;i<N;i++){
    int A;
    cin >> A;
    for (int j=0;j<40;j++){
      if (A%2 == 0){
        A/=2;
      }
      else if(least >= j){
        least=j;
        break;
      }
      else break;
    }
  }
  cout << least << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

int main(void) {

	int N, M, X;
	cin >> N >> M >> X;

	char* pa = new char[N];
	memset(pa, 0, N);

	int i;
	int v;
	for (i = 0; i < M; i++) {
		cin >> v;
		pa[v] = 1;
	}
	pa[X] = 0;

	int right = 0;
	for (i = X - 1; 0 <= i; i--) {
		if (pa[i] != 0) {
			++right;
		}
	}

	int left = 0;
	for (i = X + 1; i < N; i++) {
		if (pa[i] != 0) {
			++left;
		}
	}
	delete[] pa;

	int result = min(left, right);
	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll r,d,x;
	cin>>r>>d>>x;
	for(ll i=0;i<10;i++)
	{
		x=r*x-d;
		cout<<x<<"\n";
	}
}

Measured memory_bytes: 256
using System.Linq;
using System;

class Program
{
    static void Main()
    {
        B();
    }

    static void B()
    {
        var input = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = input[0];
        var A = input[1];
        var B = input[2];
        var C = input[3];
        var D = input[4];
        
        for (int i = 0; i < N; i++)
        {
            if ((N - 1 - i) * C - i * D <= B - A && (N - 1 - i) * D - i * C >= B - A)
            {
                Console.WriteLine("YES");
                return;
            }
        }
        Console.WriteLine("NO");
    }
    
}

Measured memory_bytes: 13396
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.TOP = top
        self.BOTTOM = bottom
        self.FRONT = front
        self.BACK = back
        self.LEFT = left
        self.RIGHT = right
    
    def move_N(self):
        tmp = self.TOP
        self.TOP = self.FRONT
        self.FRONT = self.BOTTOM
        self.BOTTOM = self.BACK
        self.BACK = tmp

    def move_S(self):
        tmp = self.TOP
        self.TOP = self.BACK
        self.BACK = self.BOTTOM
        self.BOTTOM = self.FRONT
        self.FRONT = tmp
        
    def move_W(self):
        tmp = self.TOP
        self.TOP = self.RIGHT
        self.RIGHT = self.BOTTOM
        self.BOTTOM = self.LEFT
        self.LEFT = tmp

    def move_E(self):
        tmp = self.TOP
        self.TOP = self.LEFT
        self.LEFT = self.BOTTOM
        self.BOTTOM = self.RIGHT
        self.RIGHT = tmp
    
    @property
    def top(self):
        return self.TOP
        
top, front, right, left, back, bottom = map(int,input().split())
dice = Dice(top, front, right, left, back, bottom)
m = input()
for i in range(len(m)):
    if m[i] == "N":
        dice.move_N()
    elif m[i] == "E":
        dice.move_E()
    elif m[i] == "S":
        dice.move_S()
    elif m[i] == "W":
        dice.move_W()
    else:
        raise Exception
print(dice.TOP)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	
	long long H,W;
	cin>>H>>W;
	
	int N;
	cin>>N;
	
	set<pair<int,int>> S;
	
	for(int i=0;i<N;i++){
		int a,b;
		cin>>a>>b;
		S.insert(make_pair(a,b));
	}
	
	vector<long long> ans(10);
	for(auto a:S){
		int x = a.second;
		int y = a.first;
		
		for(int i=x-2;i<x-2+3;i++){
			for(int j=y-2;j<y-2+3;j++){
				
				if(i<=0||j<=0||i+2>W||j+2>H)continue;
				int cnt = 0;
				for(int yy = 0;yy<3;yy++){
					for(int xx=0;xx<3;xx++){
						if(S.count(make_pair(j+xx,i+yy)))cnt++;
					}
				}
				ans[cnt]++;
			}
		}
				
				
		
	}
	
	ans[0] = (H-2)*(W-2);
	for(int i=1;i<10;i++){
		ans[i] /= i;
		ans[0]-=ans[i];
	}
	
	for(int i=0;i<10;i++){
		cout<<ans[i]<<endl;
	}
		
		
	
	return 0;
}


Measured memory_bytes: 4992
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int N, K, ans=0;

    cin >> N >> K;

    vector<int> p(N);

    rep(i, N) {
        cin >> p[i];
    }

    sort(p.begin(), p.end());

    rep(i,K) {
        ans += p[i];
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;

public class Main {
	static String[] dict = new String[1000005];

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

			int n = Integer.parseInt(br.readLine());
			LinkedList<Integer> list = new LinkedList<>();
			br.lines().forEach(str -> {
				String[] tmp = str.split(" ");
				switch (tmp[0]) {
				case "insert":
					// リストの先頭に追加
					list.addFirst(Integer.parseInt(tmp[1]));
					break;

				case "delete":
					// parseIntの戻り値はint型である為、
					// そのまま渡すとremove(int index)が呼び出されてしまう。
					// 明示的にInteger型に変換することで、
					// remove(Object o)メソッドを呼び出す。
					list.remove((Integer) Integer.parseInt(tmp[1]));
					break;

				case "deleteFirst":
					// 先頭の要素を削除
					list.removeFirst();
					break;

				case "deleteLast":
					// 末尾の要素を削除
					list.removeLast();
					break;
				}
			}

			);

			for (Iterator<Integer> it = list.listIterator(); it.hasNext();) {
				out.print(it.next());
				if (it.hasNext()) {
					out.print(" ");
				} else {
					out.println();
				}
			}
			out.flush();

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	static int getKey(String key) {
		int sum = 0;
		for (int i = 0, p = 0; i < key.length(); i++, p = 5) {
			char cur = key.charAt(i);
			switch (cur) {
			case 'A':
				sum += p * 1;
				break;

			case 'C':
				sum += p * 2;
				break;
			case 'G':
				sum += p * 3;
				break;
			case 'T':
				sum += p * 4;
				break;

			}
		}
		return sum;
	}

	static int h1(String key) {
		return getKey(key) % dict.length;
	}

	static int h2(String key) {
		return 1 + getKey(key) % (dict.length - 1);
	}

	static boolean insert(String key) {
		int h = 0;
		for (int i = 0; h < key.length(); i++) {
			h = (h1(key) + i * h2(key)) % dict.length;
			if (dict[h] == null) {
				dict[h] = key;
				return true;
			} else if (dict[h].equals(key)) {
				continue;
			}
		}
		return false;
	}

	static boolean search(String key) {
		int h = 0;
		for (int i = 0; h < key.length(); i++) {
			h = (h1(key) + i * h2(key)) % dict.length;
			if (dict[h] == null) {
				return false;
			} else if (dict[h].equals(key)) {
				return true;
			}
		}
		return false;
	}

}



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

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);		
		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		
		for (int i = 0 ; i < s.length() ; i += 2) {
			sb.append(s.substring(i, i+1));
		}
		System.out.println(sb.toString());
		return;
	}
}


Measured memory_bytes: 27792
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, ll k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}

const int maxn = 1e5 + 5;
int par[maxn], r[maxn];
int findp(int x)
{
    if (par[x] < 0) return x;
    else{
        int fx = findp(par[x]);
        r[x] = (r[x] + r[par[x]]) % 2;
        par[x] = fx;
    }
}
void unite(int x, int y)
{
    int fx = findp(x), fy = findp(y);
    if (fx != fy){
        r[x] = (r[x] - r[y] + 1) % 2;
        par[fy] = fx;
    }
}
bool same(int x, int y){return findp(x) == findp(y);}
int no[15];

int a[105], n;
int check(int x)
{
    int sum = 0;
    for (int i = 0; i < n; ++i){
        sum += (a[i] - x) * (a[i] - x);
    }
    return sum;
}
int main()
{
    int sum = 0;
    cin >> n;
    for (int i = 0; i < n; ++i){
        cin >> a[i];
        sum += a[i];
    }
    cout << min(check(sum / n), check(sum / n + 1)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
  int A, B, j = 0, sum = 0, k= 0, f = 0;
  cin >> A >> B;
  j = B / 2;
 
  // ここにプログラムを追記
    rep(i ,A) {
      
        int op;
        cin >> op;
      
        if (op > j) {
         sum = sum + ( B - op )*2;
        }
      	else{
         sum = sum + op * 2;
        }
  	}
    	cout << sum;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int X = in.nextInt();
        if (X >= 30) {
            out.println("Yes");
        } else {
            out.println("No");
        }

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 32592
// https://atcoder.jp/contests/abc081/tasks/abc081_a
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    ans += s[i] - '0';
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,x;
  cin>>n;
  x=-9*(n/1000000000+n/100000000+n/10000000+n/1000000+n/100000+n/10000+n/1000+n/100+n/10)+n;
  if(n%x==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;

  int tmp, V[2][100005] = {0}, m[2], n1[2];
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    V[i & 1][tmp]++;
    if (m[i & 1] < V[i & 1][tmp]) {
      m[i & 1]  = V[i & 1][tmp];
      n1[i & 1] = tmp;
    }
  }

  sort(V[0], V[0] + 100005, greater<int>());
  sort(V[1], V[1] + 100005, greater<int>());
  int ans = 0;
  if (n1[0] != n1[1])
    ans = N - m[0] - m[1];
  else
    ans = min(N - m[0] - V[1][1], N - m[1] - V[0][1]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

#define MAX 2000001
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

COMinit();

int X, Y; cin >> X >> Y;

if((double)Y/X < .5 || (double)Y/X > 2) cout << "0\n";
else if ((double)Y/X > 1 ){
    int x=X, y=Y, cnty=0;
    while((double)y/x != 2) {
        x -=2; --y;
        if ((double)y/x > 2){ cout << "0\n"; return 0;}
        ++cnty;
    }
    cout << COM(x+cnty, x) << endl;
}
else {
    int x=X, y=Y, cnty=0;
    while((double)y/x != .5) {
        --x; y -= 2;
        if ((double)y/x < .5){ cout << "0\n"; return 0;}
        ++cnty;
    }
    cout << COM(y+cnty, y) << endl;
}

}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



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

using namespace std;

#define ll long long
#define pi pair<int, int>
#define mkp make_pair
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD =  1e9 + 7;
int arr[mxn];
int n, m, k, q;
string s, t;

void solve() {
    cin >> k >> s;
    if (k >= s.size()) {
        cout << s << endl;
        return;
    } else {
        cout << s.substr(0, k);
        cout << "..." << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //cin >> T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3648
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    vector<int> v(3);
    for(int i = 0; i < 3; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int res = -v[0] + v[2];
    cout << res;
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  for(int i=0; i<n; i++) cin >> x[i] >> y[i] >> h[i];
  for(int i=0; i<=100; i++){
    for(int j=0; j<=100; j++){
      int needH = -1;
      for(int k=0; k<n; k++){
        if(h[k]>0){
          int tmp = h[k] + abs(i - x[k]) + abs(j - y[k]);
          if(needH==-1){
            needH = tmp;
          }
          else{
            if(needH!=tmp){
              needH = -2;
              break;
            }
          }
        }
      }
      if(needH==-2) continue;
      for(int k=0; k<n; k++){
        if(h[k]==0){
          int dist = abs(i - x[k]) + abs(j - y[k]);
          if(needH>dist) {
            needH = -2;
            break;
          }
        }
      }
      if(needH == -2) continue;
      cout << i << " " << j << " " << needH << endl;
      return 0;
    }
  }
}

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

class Util{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		string N = rs();

        string ans = "No";
        int num = 0;
        foreach(char c in N)
        {
            int C = int.Parse(c.ToString());
            num = (num + C) % 9;
        }

        if(num == 0) ans = "Yes";

		Console.WriteLine(ans);
		Console.ReadLine();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
    static int[] generateNums(int num, int N){return Enumerable.Repeat(num, N).ToArray();}
    static int[] generateSuretsu(int N){return Enumerable.Range(0, N).ToArray();}
}

public static class Combination {
	//使い方:int[][] Is = Combination.Enumerate(nums, k, withRepetition:false).ToArray();
    public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) {
        if (k == 1) {
            foreach (var item in items)
                yield return new T[] { item };
            yield break;
        }
        foreach (var item in items) {
            var leftside = new T[] { item };

            // item よりも前のものを除く （順列と組み合わせの違い)
            // 重複を許さないので、unusedから item そのものも取り除く
            var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

            foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
                yield return leftside.Concat(rightside).ToArray();
            }
        }
    }
}


Measured memory_bytes: 32692
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    n=int(input())
    d=[int(input()) for i in range(n)]

    print(len(set(d)))

resolve()

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)

typedef long long ll;
typedef long long int lli;

int main() {
    int N, total;
    vector<int> pi; 
    cin >> N;
    for (int i = 0; i < N; i++) {
        int num;
        cin >> num;
        pi.push_back(num);
    }
    sort(pi.begin(), pi.end(), greater<int>());
    total = 0;
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            total = total + (pi[i] / 2);
        } else {
            total = total + pi[i];
        }
    }
    cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	int mini = INT_MAX, maxi = INT_MIN; ll sum = 0;
	int n; cin >> n;
	while (n--) {
		int a; cin >> a;
		mini = min(mini, a);
		maxi = max(maxi, a);
		sum += a;
	}
	cout << mini << ' ' << maxi << ' ' << sum << endl;
}

Measured memory_bytes: 1164
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

const INF: usize = 1e9 as usize;

fn main() {
    input!(
        n: usize,
        m: usize,
        uv: [(usize1, usize1); m],
        s_pos: usize1,
        g_pos: usize1
    );

    let mut edges = vec![vec![]; n];
    for i in 0..m {
        edges[uv[i].0].push(uv[i].1);
    }

    // ゴールへの距離が3の倍数出ないとゴールできない幅優先探索
    // -> 頂点数を3倍する
    let mut dist = vec![vec![INF; n]; 3];
    dist[0][s_pos] = 0;
    let mut que = VecDeque::new();
    que.push_back((s_pos, 0));
    while let Some((from, step)) = que.pop_front() {
        if from == g_pos && step == 0 {
            println!("{}", dist[step][g_pos] / 3);
            return;
        }

        let next_step = (step + 1) % 3;
        for &to in edges[from].iter() {
            let next_d = dist[step][from] + 1;
            if dist[next_step][to] > next_d {
                dist[next_step][to] = next_d;
                que.push_back((to, next_step));
            }
        }
    }

    println!("{}", -1);
}


Measured memory_bytes: 16636
import java.util.Scanner;

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

		long D = sc.nextLong();
		long N = sc.nextLong();
		long ans =0;
		if (N == 100) {
			if (D == 0) {
				System.out.println(101);
			}else if (D == 1) {
				System.out.println(10100);
			}else if (D == 2) {
				System.out.println(1010000);
			}
		} else {
			ans = (long)Math.pow(100, D) * N;
			System.out.println(ans);
		}


	}
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main() {
	cin.sync_with_stdio(false);
	int N, A;
	cin >> N >> A;
	cout<<(N%500<=A ? "Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main()  {
	var n, m, x, y int
	fmt.Scan(&n)
	fmt.Scan(&m)
	fmt.Scan(&x)
	fmt.Scan(&y)

	xMax := math.MinInt64
	vx := make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&vx[i])
		if xMax < vx[i] {
			xMax = vx[i]
		}
	}
	yMin := math.MaxInt64
	vy := make([]int,m)
	for i := 0; i < m; i++ {
		fmt.Scan(&vy[i])
		if vy[i] < yMin {
			yMin = vy[i]
		}
	}

	if (x < xMax) && (xMax < yMin) && (yMin <= y) {
		fmt.Println("No War")
	} else {
		fmt.Println("War")
	}

}



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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input();
    vector< int > cnt(4, 0);
    range(i, 0, N) {
        cnt[input()]++;
    }
    
    auto dp = make_vector(N + 1, N + 1, N + 1, double(-1));

    function< double(int, int, int) > dfs = [&](int a, int b, int c) {
        if (a == 0 && b == 0 && c == 0) return 0.0;
        
        double &res = dp[a][b][c];
        if (res >= 0) return res;
        double m = 1.0 / (a + b + c);
        res = 0;

        if (a) res += a * m * dfs(a - 1, b, c);
        if (b) res += b * m * dfs(a + 1, b - 1, c);
        if (c) res += c * m * dfs(a, b + 1, c - 1);
        res += m * N;
        
        return res;
    };
    
    cout << dfs(cnt[1], cnt[2], cnt[3]) << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 216964
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,m,a,b,d[200010],i,c;
  scanf("%d %d %d",&n,&m,&c);
  for(i=0;i<100010;i++)d[i]=-1;
  b=a=c;
  for(i=1;i<m;i++){
    scanf("%d",&a);
    hin(a-b);
    b=a;
  }
  hin(n-a+1);
  for(i=c-1;i<n;i++){
    d[i]=N[hout()];
    hin(d[i]-1);//printf("%d\n",d[i]);
  }//printf("\n");
  for(;i<100010;i++)d[i]=1;
  scanf("%d",&m);
  while(m--){
    scanf("%d",&a);
    printf("%d\n",d[a]);
  }
  return 0;
}



Measured memory_bytes: 3328
class Heap
  def initialize(xs = [], &block)
    @que = xs
    @size = xs.size
    @cmp = block || lambda{ |a,b| a < b }
  end

  def push(x)
    i = @size
    while i > 0 do
      j = (i - 1) / 2
      break unless @cmp.call(x, @que[j])
      @que[i] = @que[j]
      i = j
    end
    @que[i] = x
    @size += 1
  end

  def replace
    m = @que[0]
    x = yield m
    i = 0
    while (ii = i * 2 + 1) < @size do
      j1 = ii
      j2 = ii + 1
      j1 = j2 if j2 < @size && @cmp.call(@que[j2], @que[j1])
      break unless @cmp.call(@que[j1], x)
      @que[i] = @que[j1]
      i = j1
    end
    @que[i] = x
    m
  end
end

def get_target(l, h, n, fs)
  r = 0
  fs.each do |f| r += h / f end

  # t0 = (l*h/r).ceil, t = (l*h/(r+n)).ceil
  lh = l * h
  t0 = (lh + r - 1) / r
  t = (lh + r + n - 1) / (r + n)

  raise if (t0 >= t + 2)

  t
end

n, k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
fs = gets.split.map(&:to_i)
 
l = as.inject(:+) - k

if (l <= 0)
  p 0
  exit
end

# O(n * log(n))
afs = as.sort.zip(fs.sort.reverse).sort_by do |item| item[0]*item[1] end

acc = 0
# O(n)
a_sums = afs.map do |a,_| acc += a end

# O(n * log(n))
m = (0...n).bsearch do |i|
  a_i, f_i = afs[i]
  af = a_i * f_i

  s = a_sums[i]
  (i+1...n).each do |j| s += af / afs[j][1] end
  s > l
end

if (m > 0)
  afs = afs.drop(m)
  n -= m
end

l = -k
max_f = 0

# O(n)
fs = afs.map do |a, f|
  l += a
  max_f = f if f > max_f
  f
end

# O(n)
t = get_target(l, l * max_f * max_f, n, fs)

max_af = 0

# O(n)
xs = fs.map do |f|
  l -= (a = t / f)
  af = a * f
  max_af = af if af > max_af
  [af + f, f]
end

if (l == 0)
  p max_af
else
  # O(n * log(n))
  xs = xs.sort_by do |item| item[0] end
  # O(n * log(n))
  q = Heap.new(xs) do |a,b| a.first < b.first end

  raise if (l > 2*n)

  # O(n * log(n))
  af, = q.replace do |a| [a[0] + a[1], a[1]] end while (l -= 1) >= 0
  p af
end

Measured memory_bytes: 63868
import java.io.*;
class Main{
  public static void main(String[] args){
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );
    
    try{
      
      String str2 = "abc";
      String str3 = "acb";
      String str4 = "bac";
      String str5 = "bca";
      String str6 = "cba";
      String str7 = "cab";
      
    String str1 = br.readLine();
    
      if(str1.equals(str2) || str1.equals(str3) || str1.equals(str4) || 
         str1.equals(str5) || str1.equals(str6) || str1.equals(str7) ){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
      
    }catch(Exception e) {
    }
  }
}

Measured memory_bytes: 22228
N = int(input())
H = list(map(int, input().split()))
isCheck = True
maxValue = 0

for i in range(N - 1):
    if H[i] >= H[i + 1]:
        H[i] -= 1

    if maxValue < H[i]:
        maxValue = H[i]

    if maxValue > H[i + 1]:
        isCheck = False
        break

if isCheck == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14396
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
li=[]
pt=0
for i in range(n):
  if i<k and t[i] == "r":
    li.append("p")
    pt+=p
  elif i<k and t[i] == "s":
    li.append("r")
    pt += r
  elif i<k and t[i] == "p":
    li.append("s")
    pt += s
  elif i>=k and t[i] == "r" and li[i-k] != "p":
    li.append("p")
    pt+=p
  elif i>=k and t[i]=="r" and li[i-k] =="p":
    li.append(0)
  elif i>=k and t[i] == "s" and li[i-k] != "r":
    li.append("r")
    pt += r
  elif i>= k and t[i]=="s" and li[i-k] == "r":
    li.append(0)
  elif i>=k and t[i] == "p" and li[i-k] != "s":
    li.append("s")
    pt += s
  elif i>=k and t[i] == "p" and li[i-k] == "s":
    li.append(0)
print(pt)

Measured memory_bytes: 4212
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
edge=[lmp() for i in range(m)]
ans=0
for _ in range(m):
    l=[[] for i in range(n+1)]
    que=deque()
    ch=[0]*(n+1)
    ch[0]=1
    for i in range(m):
        if i!=_:
            l[edge[i][0]].append(edge[i][1])
            l[edge[i][1]].append(edge[i][0])
    q=1
    que.append(l[q])
    ch[1]=1
    while len(que):
        q=que.pop()
        for j in range(len(q)):
            if ch[q[j]]==0:
                que.append(l[q[j]])
                ch[q[j]]=1
    b=0
    for k in range(n+1):
        if ch[k]==0:
            b=1
    if b==1:
        ans+=1
print(ans)

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

int main(){
  ll H,W;
  cin >> H >> W;
  ll N;
  cin >> N;
  vector<ll> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  int c[H][W];
  int i = 0, j = 0;
  int color = 0;
  for(int i = 0; i < H; i++){
    if(i % 2 == 0){
      for(int j = 0; j < W; j++){
	c[i][j] = color + 1;
	a[color]--;
	if(a[color] == 0){
	  color++;
	}
      }
    }else{
      for(int j = W-1; j >= 0; j--){
	c[i][j] = color + 1;
	a[color]--;
	if(a[color] == 0){
	  color++;
	}
      }
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cout << c[i][j] << " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define li 100005
#define lo long long
#define fi first
#define FOR for(int i=1;i<=n;i++)
#define	FOr for(int i=n;i>=1;i--)
#define For for(int j=1;j<=n;j++)
#define se second
#define inf 1000000000
using namespace std;
lo int n,k,m,cevv,cev,orta;
string s;
int main(){
	int tut=-1;
    cin>>s;
    int ok=0;
    scanf("%lld",&k);
    n=s.size();
    for(int i=0;i<n;i++){
		if(s[i]!='1'){
			ok=i+1;
			tut=s[i]-48;
			break;
		}
	}
	if(tut==-1)
		printf("1");
	else{
		if(ok>k){
			printf("1");
			return 0;
		}
		printf("%d",tut);
	}	
    return 0;
}



Measured memory_bytes: 256
n,m = map(int,input().split())
for i in range(n):
    if i==0:
        l = list(map(int,input().split()))
        l.pop(0)
    else:
        l_tmp = list(map(int,input().split()))
        l_tmp.pop(0)
        l = list(set(l)&set(l_tmp))
print(len(l))


Measured memory_bytes: 38256
#include <iostream>
#include <vector>

int main(){
    int n = 0;
    int m = 0;
    int c = 0;
    int temp = 0;
    std::vector<int> b;
    std::vector<std::vector<int>> a;
    std::vector<int> tempvec;
    int sum = 0;
    int correct = 0;

    std::cin >> n >> m >> c;

    for(int i = 0; i < m; i++){
        std::cin >> temp;
        b.push_back(temp);
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            std::cin >> temp;
            tempvec.push_back(temp);
        }
        a.push_back(tempvec);

        for(int j = 0; j < m; j++){
            tempvec.pop_back();
        }
    }

/*
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            std::cout << "a: " << a[i][j] << std::endl;
        }
        std::cout << "b: " << b[i] << std::endl;
    }
*/

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m ; j++){
            sum = sum + (a[i][j] * b[j]);
        }
        sum = sum + c;
        if(sum > 0){
            correct++;
        }
        sum = 0;
    }

    std::cout << correct << std::endl;

    return 0;
    
}

Measured memory_bytes: 256
s=gets.chomp.split(//)
t=gets.chomp.split(//)
fflag=false
s.length.times do |i|
    flag=true
    s.length.times do |j|
        flag=false if s[j]!=t[(i+j)%s.length]
    end
    fflag=true if flag==true
end

puts fflag ? "Yes":"No"

Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;

ll a[1000100];
ll b[1000100];

int main(){
    int N;
    cin >> N;
    for(int i=0; i < N ;i++) cin >> a[i] >> b[i];

    ll ans=0;
    for(int i=N-1; i >= 0; i--){
        if(a[i]%b[i] == 0){
            if(i!=0)a[i-1] += ans;
            continue;
        }
        ll t = b[i] - (a[i]%b[i]);
        if(i != 0)a[i-1] += t + ans;
        ans += t;

    }
    cout << ans << endl;

}


Measured memory_bytes: 5248
/*input
1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    ll res=0LL;
    while(b){
        if(b&1) res=(res+a)%MOD;
        a=(a+a)%MOD;
        b>>=1;
    }
    return res%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int cntq=0;
int query(string s){
    ++cntq;
    assert(cntq<850);
    cout<<"? "<<s<<endl;
    int x;
    cin>>x;
    return x;
}
bool cmp(string a,string b){
    return sz(a)>sz(b);
}
void solve(){
    string alpha="";
    REP(i,26){
        alpha+=('a'+i);
    }
    REP(i,26) alpha+=('A'+i);
    REP(i,10) alpha+=('0'+i);
    vector<string> cur;
    int len=0;
    REP(i,62){
        string z="";
        REP(zz,128) z+=alpha[i];
        int cnt=128-query(z);
        string tmp="";
        REP(zz,cnt) tmp+=alpha[i];
        if(sz(tmp)) cur.pb(tmp);
        len+=cnt;
    }
    while(sz(cur)>1){
        sort(ALL(cur),cmp);
        string a=cur.back(),b=cur[sz(cur)-2];
        //cout<<a<<' '<<b<<'\n';
        cur.pop_back(),cur.pop_back();
        int i1=0,i2=0;
        string s="";
        while(i1<sz(a) and i2<sz(b)){
            string tmp=s+b[0]+a;
            if(query(tmp)==(len-sz(tmp))){
                s+=b[0];
                b.erase(b.begin());
            }
            else{
                s+=a[0];
                a.erase(a.begin());
            }
        }
        s+=a;
        s+=b;
        cur.pb(s);
    }
    cout<<"! "<<cur[0]<<endl;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int t=1;
    while(t--) solve();
}

Measured memory_bytes: 3776