akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10,INF=0x3f3f3f3f;
int n,q,op,x;
ll now;
struct segtree{
	int n;
	struct node{int l,r,mn;}e[N<<2];
	#define l(p) e[p].l
	#define r(p) e[p].r
	#define m(p) e[p].mn
	void bld(int p,int l,int r){
		l(p)=l;r(p)=r;m(p)=n;
		if(l==r){return;}
		int mid=l+r>>1;
		bld(p<<1,l,mid);bld(p<<1|1,mid+1,r);
	}
	void init(int _n){n=_n;bld(1,1,n);}
    void Min(int p,int ql,int qr,int v){
        if(ql<=l(p)&&r(p)<=qr){
            m(p)=min(m(p),v);
            return;
        }
		int mid=l(p)+r(p)>>1;
        if(ql<=mid)Min(p<<1,ql,qr,v);
		if(qr>mid)Min(p<<1|1,ql,qr,v);
    }
	int ask(int p,int x){
		if(l(p)==r(p))return m(p);
		int mid=l(p)+r(p)>>1;
		int ans=m(p);
		if(x<=mid)ans=min(ans,ask(p<<1,x));
		else ans=min(ans,ask(p<<1|1,x));
		return ans;
	}
}row,col;
int main(){
    scanf("%d%d",&n,&q);
    now=1ll*(n-2)*(n-2);
    row.init(n);
    col.init(n);
    for(int i=1;i<=q;++i){
        scanf("%d%d",&op,&x);
        if(op==1){
            int pos=col.ask(1,x);
            now-=pos-2;
            row.Min(1,1,pos-1,x);
        }
        else{
            int pos=row.ask(1,x);
            now-=pos-2;
            col.Min(1,1,pos-1,x);
        }
    }
    printf("%lld\n",now);
    return 0;
}


Measured memory_bytes: 16056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
const ll MAX = 2*(ll)pow(10, 5);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll a, b; cin >> a >> b;
  bool flag = 1;
  if (a%2==0 || b%2==0) flag = 0;
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
var input = "";
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", (chunk) => {
  input += chunk;
});
process.stdin.on("end", () => {
  input = input.split("\n");
  console.log(main(0));
});

function main(ans){
  const operation = input[0].split("");
  operation.forEach( op => {
    if(op === "+"){
      ans++;
    }
    if(op === "-"){
      ans--;
    }
  });
  return ans;
}

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


int main(){
  vector<int> A(3);
  cin >> A[0] >> A[1] >> A[2];
  int mid = A[2];
  sort(A.begin(), A.end());
  cout << (A[1]==mid?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 256
import copy
h,w = map(int,input().split())
g = [[False]*(w+2) for _ in range(h+2)]
d = [[-1]*(w+2) for _ in range(h+2)]
ans = 0
for i in range(h):
    l = list(input())
    for j in range(w):
        if l[j] == ".":
            ans += 1
            g[i+1][j+1] = True
def f(i,j):
    return [(i+1,j),(i,j+1),(i-1,j),(i,j-1)]
now = f(1,1)
d[1][1] = 0
nxt = []
cnt = 1
while now:
    for l in now:
        i,j = l[0],l[1]
        if d[i][j] == -1 and g[i][j]:
            d[i][j] = cnt
            for l2 in f(i,j):
                nxt.append(l2)
    cnt += 1
    now = copy.copy(nxt)
    nxt = []
if d[h][w] == -1:
    print(-1)
else:
    print(ans-d[h][w]-1)

Measured memory_bytes: 9300
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int g = sc.nextInt();
    int b = sc.nextInt();

    System.out.println((r * 100 + g * 10 + b) % 4 == 0 ? "YES" : "NO");
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define gap " "
#define pi 2 * acos (0.0)

int main()
{
    
    int n;
    cin>> n;
    int a[n],b[n];
    int s=0;
    for(int i=0;i<n;i++){
        cin>> a[i];
    }
    for (int i=0;i<n;i++){
        cin>> b[i];
    }
    for (int i=0;i<n;i++){
        if ((a[i]-b[i])>0) s=s+(a[i]-b[i]);
    }
    cout << s <<endl;

}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, t;
  cin >> a >> b >> t;
  int res = 0;
  if(a > t){
    cout << 0 << endl;
    return 0;
  }
  for(int i = a; i < t+1; i += a){
    res += b;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
 
vector<unsigned long long> next_p_mod(unsigned N, long long mod) { //next_permutation
  vector<unsigned long long> Next_p(N);
  unsigned long long Next_p_buff = 1;
  for (int i = 0; i < N; i++)
  {
    Next_p_buff *= (i + 1) % mod;
    Next_p.at(i) = Next_p_buff % mod;
  }
  return Next_p;
}
unsigned long long modpow(unsigned long long a, unsigned long long n, unsigned long long mod) {
   unsigned long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
void comb(vector<vector <long long int> > &v,unsigned long long mod) {
  //vector<入れたい型> v(配列の個数(x),vector<入れたい型> (配列の個数,初期値));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
    }
  }
}
// a^{-1} mod を計算する
unsigned long long modinv(unsigned long long a, unsigned long long mod) {
    return modpow(a, mod - 2, mod);
}
 
 
int main() {
  long long N,L;
  bool flag=0;
  cin >> N>>L;
    long long L_sum=L,L_max=L;
  long long L_low;
  vector<long long> Li(N);  
  for(int i=1;i<N;i++){
    L_max+=1;
    //cout<<"max:"<<L_max<<endl;
    L_sum+=L+i;
  }
  if(L<0&&L_max>=0){
    L_low=0;
  }else if(L<0&&L_max<0){
    L_low=L_max;
  }else if(L>=0){
    L_low=L;
  }
  cout<<L_sum-L_low<<endl;
  return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	string S_, T;
	
	cin >> S_ >> T;

	int s_l = S_.size();
	int t_l = T.size();
	
	if (s_l < t_l)
	{
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	int i = 0;
	int rec = -1;

	for (; i < s_l - t_l + 1; i++)
	{
		int j = 0;

		for (; j < t_l; j++)
		{
			if ((S_[i+j] != '?') && (S_[i+j] != T[j]))
			{
				break;
			}
		}

		if (j >= t_l)
		{
			rec = i;
		}
	}

	if (rec == -1)
	{
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	string s = "";
	for(int k = 0; k < s_l; k++)
	{
		if ((k >= rec) && (k < (rec+t_l)))
		{
			//cout << T[k-i];
			s+= T[k-rec];
		}
		else
		{
			if (S_[k] == '?')
			{
				//cout << 'a';
				s+= 'a';
			}
			else
			{
				//cout << S_[k];
				s+=S_[k];
			}
		}

	}
	cout << s;
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
print(2 * (n - 1))
a = list(map(int, input().split()))
index = 0
for i in range(1, n):
  if abs(a[i]) > abs(a[index]):
    index = i
if a[index] >= 0:
  for i in range(1, n):
    a[i] += a[index]
    print(index + 1, i + 1)
    if abs(a[i]) > abs(a[index]):
      index = i
    a[i] += a[index]
    print(index + 1, i + 1)
    if abs(a[i]) > abs(a[index]):
      index = i
else:
  for i in range(n - 2, -1, -1):
    a[i] += a[index]
    print(index + 1, i + 1)
    if abs(a[i]) > abs(a[index]):
      index = i
    a[i] += a[index]
    print(index + 1, i + 1)
    if abs(a[i]) > abs(a[index]):
      index = i


Measured memory_bytes: 3064
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:break
    for j in range(H):
        for i in range(W):
            if i==0 or i==W-1 or j==0 or j==H-1:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()
    


Measured memory_bytes: 7008
import math

N = int(input())
k,S,t = int(math.sqrt(N*2))+1,[[1],[1]],[]

if k*(k-1) != N*2:
	print('No')
	exit()

for i in range(k-2):
	S[0].append(S[0][i]+i+1)
	S[1].append(S[1][i]+i+2)
	t.append([S[0][i+1]])

for i in range(k-2):
	b,n = False,t[i][-1]+1
	while n <= N:
		t[i].append(n)
		tk = int(math.sqrt(n*2))+1
		if tk*(tk-1) == n*2:
			b = True
		n = t[i][-1]+len(t[i]) if b else t[i][-1]+1
S += t

print('Yes')
print(k)
for s in S:
	print(k-1, ' '.join(map(str, s)))

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

int main() {
  long long N,X,Y,Z,A,B,C,ans,a,b;
  cin >>N;
  int x[N+1];
  for(int i=0;i<N+1;i++){
    x[i]=0;
  }
  for(int i=1;i<N;i++){
    cin>>A;
    x[A]++;
  }
  for(int i=1;i<N+1;i++){
  cout<<x[i]<<endl;
  }
}


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

int main(){
  int N,K,T,U,V,L;
  cin>>N>>K>>T>>U>>V>>L;
  queue<int> que;
  double lv[10005];
  for(int i=0;i<=10000;i++){
    lv[i]=U;
  }
  for(int i=0;i<N;i++){
    int val;
    cin>>val;
    que.push(val);
  }
  int l=1,k=0,vl=0;
  while(l<=L){
    if(l<vl) lv[l]=V;
    if(l==que.front()){
      k++;
      que.pop();
    }
    if(k>0&&l>=vl){
      k--;
      lv[l]=V;
      vl=l+T*V;
    //  cout<<"a"<<vl<<endl;
    }
    if(l<vl && k>K){
      k--;
      vl=l+T*V;
  //    cout<<vl<<endl;
    }
    l++;
  }
  double ans=0.0;
  int x=0,y,v=lv[1],h=0;
  for(int i=0;i<L;i++){
    ans+=1.00/lv[i];
  }
  printf("%.10lf\n",ans);
  return 0;
}



Measured memory_bytes: 3296
import numpy as np

n, a, b = np.asarray(input().split(), dtype=np.uint64)

times = np.asarray([0], dtype=np.uint64)
times += n // (a+b)

last = np.asarray([0], dtype=np.uint64)
last += n % (a+b)

answer = np.asarray([0], dtype=np.uint64)

if last <= a:
    answer += times * a + last
else:
    answer += a * (times + 1)

print(int(answer))

Measured memory_bytes: 21004
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	ini(n);
	ini(n1);
	if(n1*2>=n){
		out(0);
	}
	else{
		out(n-n1*2);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	long number;
	long stock;
} S_ARRAY;

int cmpAscNum(const void * n1, const void * n2)
{
	if (((S_ARRAY *)n1)->number > ((S_ARRAY *)n2)->number)
	{
		return 1;
	}
	else if (((S_ARRAY *)n1)->number < ((S_ARRAY *)n2)->number)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n,k;
  scanf("%ld %ld", &n, &k);
  S_ARRAY array[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld", &array[i].number, &array[i].stock);
  }
  qsort(array, n, sizeof(S_ARRAY), cmpAscNum);
  long count = 0;
  for (long i = 0; i < n; i++) {
    count += array[i].stock;
    if (count >= k) {
      printf("%ld\n", array[i].number);
      break;
    }
  }

  return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i <= k; i++)
#define SZ 110000
#define PB push_back
#define MEM(n, val) memset((n), val, sizeof(n))
#define INF 1000000000
#define F first
#define S second
#define MP make_pair
#define LL long long

int n, k;
string s;

vector<int> st_pos;///0 starting
vector<int> ed_pos;///0 starting
vector<int> le_one;///one to left
vector<int> ri_one;///one to left

int main()  {
//    freopen("in.txt", "r", stdin);
    cin >> n >> k;
    cin >> s;

    int mx = 0;

    int cnt = 0;
    FOR(i, 0, n - 1)   {
        if(s[i] == '0')    {
            le_one.PB(cnt);
            mx = max(mx, cnt);

            cnt = 0;

            st_pos.PB(i);
            while(i < n && s[i] == '0') {
                i++;
            }
            i--;
        }
        else    {
            cnt++;
        }
    }

    mx = max(mx, cnt);
    cnt = 0;
    for(int i = n - 1; i >= 0; i--)   {
        if(s[i] == '0')    {
            ri_one.PB(cnt);
            mx = max(mx, cnt);

            cnt = 0;

            ed_pos.PB(i);
            while(i >= 0 && s[i] == '0') {
                i--;
            }
            i++;
        }
        else    {
            cnt++;
        }
    }


    mx = max(mx, cnt);
    reverse(ed_pos.begin(), ed_pos.end());
    reverse(ri_one.begin(), ri_one.end());

//    FOR(i, 0, (int)le_one.size() - 1)   {
//        cout << le_one[i] << " ";
//    }
//    cout << "\n";
//
//    FOR(i, 0, (int)ri_one.size() - 1)   {
//        cout << ri_one[i] << " ";
//    }
//    cout << "\n";


    FOR(i, 0, (int)st_pos.size() - 1)   {
        int le = i;
        int ri = min((int)st_pos.size() - 1, i + k - 1);
//        cout << i << " : " << ri << "\n";
        mx = max(mx, le_one[le] + ri_one[ri] + (ed_pos[ri] - st_pos[le] + 1));
//        cout << i << " : " << le_one[le] + ri_one[ri] + (ed_pos[ri] - st_pos[le] + 1) << "\n";
    }
    cout << mx << "\n";
    return 0;
}
/**
*/


Measured memory_bytes: 1404
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();

		if (a >= 195) System.out.println(5);
		else if (a >= 189) System.out.println(4);
		else if (a >= 165) System.out.println(3);
		else if (a >= 135) System.out.println(2);
		else if (a >= 105) System.out.println(1);
		else System.out.println(0);

		sc.close();

	}

}

Measured memory_bytes: 24020
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define deb(x) cout << #x << ' ' << x << '\n'
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define per(i,ini) for(int i=ini;i>=0;i--)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 2019;
const int N = 1e6+2;

int main()
{
	string s;
	cin >> s; 

	int n = (int)s.size();

	int pwr[n];

	pwr[0] = 1;

	rep(i, 1, n)
	pwr[i] = (pwr[i-1] * 10) % mod;

	vector <int> fa(mod, 0);

	fa[0] = 1;

	ll ans = 0;

	int cur = n-1, sum = 0;

	rep(i, 0, n)
	{
		sum = (sum + pwr[cur] * (s[i] - '0')) % mod;

		cur --;

		ans += fa[sum];

		fa[sum] ++;
	}

	lpri(ans); 
    
    return 0;
}

Measured memory_bytes: 4552
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000007
# define mm 1000000007
# define pi acos(-1)
# define fi first
# define se second

using namespace std;
 pair<int,int> a[2005];
 int dp[2005][2005];
 int n;
 int help(int id,int st,int en)
 {
     if(id>n)
        return 0;
     if(dp[st][en]!=-1)
        return dp[st][en];
     int an = max(help(id+1,st+1,en) + abs(st-a[id].se)*a[id].fi,help(id+1,st,en-1) + abs(en-a[id].se)*a[id].fi);
     dp[st][en]=an;
     return an;
 }
signed main()
{
    gok

      //int n;
      cin>>n;

      for(int i=0;i<n;i++){
        cin>>a[i].fi;
        a[i].se=i;
      }
      sort(a,a+n);
      reverse(a,a+n);
      memset(dp,-1,sizeof(dp));



       cout<<help(0,0,n-1);
















      return 0;
    }


Measured memory_bytes: 35188
import java.lang.*;
    import java.io.*;
    import java.util.*;
     
     
    public class Main {
    	
    	public static void main(String[] args) throws java.lang.Exception {
    		InputStream inputStream = System.in;
    		OutputStream outputStream = System.out;
    		InputReader in = new InputReader(inputStream);
    		PrintWriter out = new PrintWriter(outputStream);
    		TaskA solver = new TaskA();
    		solver.solve(in, out);
    		out.close();
    	}
    }
     
    class TaskA {
    	
    	public void solve(InputReader in, PrintWriter out) {
    		final String dream = "dream";
    		final String dreamer = "dreamer";
    		final String erase = "erase";
    		final String eraser = "eraser";
    		final int dreamLen = dream.length();
    		final int dreamerLen = dreamer.length();
    		final int eraseLen = erase.length();
    		final int eraserLen = eraser.length();
    		
    		final String s = in.next();
    		final int slen = s.length();
    		int i = 0, j;
    		char ch;
    		
    		while (i < slen) {
    			ch = s.charAt(i);
    			if (ch!='d' && ch!='e') {
    				out.println("NO");
    				return;
    			}
    			
    			boolean flag = false;
    			
    			if (ch == 'e') {
    				if (i+eraserLen <= slen) {
    					if (eraser.equals(s.substring(i, i+eraserLen))) {
    						flag = true;
    						i += eraserLen;
    					}
    				}
    				if (!flag && i+eraseLen <= slen) {
    					if (erase.equals(s.substring(i, i+eraseLen))) {
    						flag = true;
    						i += eraseLen;
    					}
    				}
    			} else {
    				if (i+dreamerLen<=slen && dreamer.equals(s.substring(i, i+dreamerLen))) {
    					flag = true;
    					if (i+dreamLen+eraseLen<=slen && erase.equals(s.substring(i+dreamLen, i+dreamLen+eraseLen))) {
    						i += dreamLen;
    					} else {
    						i += dreamerLen;
    					}
    				} else if (i+dreamLen<=slen && dream.equals(s.substring(i, i+dreamLen))) {
    					flag = true;
    					i += dreamLen;
    				}
    			}
    			
    			if (!flag) {
    				out.println("NO");
    				return ;
    			}
    		}
    		
    		if (i == slen)
    			out.println("YES");
    		else
    			out.println("NO");
    	}
    }
     
    class InputReader {
    	public BufferedReader reader;
    	public StringTokenizer tokenizer;
    	
    	public InputReader(InputStream stream) {
    		reader = new BufferedReader(new InputStreamReader(stream), 32768);
    		tokenizer = null;
    	}
    	
    	public String next() {
    		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
    			try {
    				tokenizer = new StringTokenizer(reader.readLine());
    			} catch (IOException e) {
    				throw new RuntimeException(e);
    			}
    		}
    		return tokenizer.nextToken();
    	}
    	
    	public int nextInt() {
    		return Integer.parseInt(next());
    	}
    	
    	public double nextDouble() {
    		return Double.parseDouble(next());
    	}
    	
    	public long nextLong() {
    		return Long.parseLong(next());
    	}
    }

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<ll,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s, t;
	cin >>s >>t;
	
	string ans = "||";
	int n=sz(s), m=sz(t);
	rep(i, n+1-m){
		bool ck=true;
		rep(j, m){
			if(s[i+j] != t[j] && s[i+j] !='?') ck=false;
		}
		if(ck){
			string cnd = s;
			rep(j, m) cnd[i+j] = t[j];
			rep(j, n) if(cnd[j]=='?') cnd[j] ='a';
			ans = min(ans, cnd);
		}
	}
	
	cout <<(ans !="||"? ans: "UNRESTORABLE" )<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int AC=0,WA=0,TLE=0,RE=0;
	string status[a];
	for(int i=0;i<a;i++){
		string b;
		cin>>b;
		status[i]=b;
	}
	for(int i=0;i<a;i++){
		if(status[i]=="AC"){
			AC++;
		}
		if(status[i]=="WA"){
			WA++;
		}
		if(status[i]=="TLE"){
			TLE++;
		}
		if(status[i]=="RE"){
			RE++;
		}
	}
	cout<<"AC"<<" "<<"x"<<" "<<AC<<endl;
	cout<<"WA"<<" "<<"x"<<" "<<WA<<endl;
	cout<<"TLE"<<" "<<"x"<<" "<<TLE<<endl;
	cout<<"RE"<<" "<<"x"<<" "<<RE<<endl;
	return 0;
}

Measured memory_bytes: 6748
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

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

  vector<int> l(n);
  vector<int> r(n);

  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (r[i] - l[i] + 1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int n,k;
  string s;
  cin>>n;
  cin>>s;
  cin>>k;
  string ans = "";
  char c = s[k-1];
  REP(i,n){
    if(s[i] == c){
      ans += c;
    }else{
      ans += "*";
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  int a[2*M]={},b[50]={};
  for(int i=0;i<2*M;i++){
    cin >> a[i];
    b[a[i]-1]++;
  }
  for(int j=0;j<N;j++)
    cout << b[j] << endl;
}	

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

int main(){
    int h,w;
    cin >> h >> w;
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    int ans[h][w];
    int now = 1;
    int num = 0;
    for(int i = 0; i < h; i++){
        if(i%2 == 0){
            for(int j = 0; j < w; j++){
                ans[i][j] = now;
                a[num]--;
                if(a[num] == 0){
                    num++;
                    now++;
                }
            }
        } else {
            for(int j = w-1; j >= 0; j--){
                ans[i][j] = now;
                a[num]--;
                if(a[num] == 0){
                    num++;
                    now++;
                }
            }
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

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

int main() {
  int N, M;
  cin >> N >>M;
  int a[51],b[51], sum;
  for(int i=0;i<M;i++) {
    cin >> a[i] >> b[i];
  }
  
  for(int i=0;i<N;i++) {
    sum=0;
    for(int j=0;j<M;j++) {
      if(a[j]==i+1 || b[j]==i+1) {
        sum += 1;
      }
    }
    cout << sum << endl;
  }
}

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

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end() // begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)      // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--) // repeat reverse
#define size(collection) ((ll)(collection).size())           // collection size

#endif

vector<ull> lmax(50);
vector<ull> pmax(50);
ll n, x, ans;
void Solve(ll lv) {
    if (lv == 0) {
        x--;
        ans++;
        return;
    }

    x--;
    if (x <= 0)
        return;

    if (x <= lmax[lv - 1]) {
        Solve(lv - 1);
        return;
    }

    x -= lmax[lv - 1];
    ans += pmax[lv - 1];
    if (x <= 0)
        return;

    x--;
    ans++;
    if (x <= 0)
        return;

    if (x <= lmax[lv - 1]) {
        Solve(lv - 1);
        return;
    }

    x -= lmax[lv - 1];
    ans += pmax[lv - 1];
    if (x <= 0)
        return;

    x--;
}

int main(void) {
    cin >> n >> x;

    lmax[0] = pmax[0] = 1;
    rep(i, 1, 50) {
        lmax[i] = lmax[i - 1] * 2 + 3;
        pmax[i] = pmax[i - 1] * 2 + 1;
    }

    ans = 0;
    Solve(n);

    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[100];
  cin >> n;
  int k=0,count=0;
  for(int i=0; i<n; i++) cin >> a[i];
  while(1){
    for(int i=n-1; i>0+k; i--){
      if(a[i-1] > a[i]) {
        swap(a[i-1],a[i]);
        count++;
      }
    }
    k++;
    if(k==n) break;
  }
  for(int i=0; i<n; i++){
    if(i==0) cout << a[i];
    else cout << " " << a[i];
  }
  cout << endl;
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3108
N = int(input())
number_list = []
summury = 0
for i in range(N):
  if (i+1) % 3 != 0 and (i+1) % 5 != 0:
    number_list.append(i+1)
    
for i in range(len(number_list)):
  summury += number_list[i]
 
print(summury)

Measured memory_bytes: 29804
#include <stdio.h>
#include <math.h>
int main(void)
{
  int count=0;
  int i,j;
  int n;
  int flag;
  scanf("%d",&n);
  int x[n];
  
  for(i=0;i<n;i++) {
    scanf("%d",&x[i]);
  }

  for(i=0;i<n;i++) {
    if(x[i]==2) {
      count++;
      continue;
    }
    else if(x[i]<2 || x[i]%2==0)
      continue;
    else {
      j=3;
      flag=0;
      while(j<=sqrt(x[i])) {
	flag=1;
	if(x[i]%j==0)
	  break;
	else
	  j+=2;
      }
      if(x[i]%j!=0 || flag==0)
	count++;
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2036
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main(){
	
	int N;

	cin >> N;

	if(N / 10 == 9 || N % 10 == 9){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()


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

    vector<int> d(n);
    REP(i, n) {
        cin >> d[i];
    }
    sort(ALL(d));

    if (d[n/2 -1] == d[n/2]) {
        std::cout << 0 << '\n';
    } else {
        std::cout << d[n/2] - d[n/2 -1] << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

bool isPrime(long long num)
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);

    for (int i = 3; i <= (int)sqrtNum; i++)
    {
        if (num % i == 0)
            return false;
    }

    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int Q;
    cin >> Q;
    vector<int> cnt(100010);
    for (int i = 2; i < 100010; i++)
    {
        if (isPrime(i) && isPrime((i + 1) / 2))
            cnt[i]++;
    }

    vector<int> sum(100011);
    for (int i = 0; i < 100010; i++)
    {
        sum[i + 1] = sum[i] + cnt[i];
    }

    for (int i = 0; i < Q; i++)
    {
        int l, r;
        cin >> l >> r;
        r++;
        cout << sum[r] - sum[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 3944
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;


// a と b の最大公約数を返す
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}


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



// 素数判定
bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}


// 約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0)  continue;
        ll ex = 0;

        while(N % i == 0){
            ex++;
            N /= i;
        }

        res.push_back({i, ex});
    }

    if(N != 1)  res.push_back({N, 1});
    return res;
};


int main(){
    ll n;   cin >> n;
    if(n % 2 == 1){
        cout << 0 << endl;
        return 0;
    }

    ll res = 0;
    ll x = 10;
    while(x <= n){
        res += n / x;
        x *= 5;
    }

    cout << res << endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int n; cin >> n;
	vector<int> v(n);
	vector<int> ans;
	rep(i,n) cin >> v[i];
	int pushed = v[0];
	ans.push_back(pushed);
	bool can = false;
	rep(i,n){
		if (pushed == 2){
			can = true;
			break;
		}
		pushed = v[pushed-1];
		ans.push_back(pushed);
	}
	if (can){
		cout << ans.size() << endl;
	}else{
		cout << -1 << endl;
	}
}

Measured memory_bytes: 1276
def I(): return map(int, input().split())
n, m = I()
d = []
for _ in range(m):
    d += [list(I())]
u = sorted([[i, j] for i, j in enumerate(d)], key=lambda x: x[1])

f = 0
r = 0 # roop
for _, j in u:
    p, _ = j
    if f != p:
        x = 1
    u[r][1] = [str(p).zfill(6) + str(x).zfill(6)]
    x += 1
    f = p
    r += 1

for _, k in sorted(u):
    print(*k)

Measured memory_bytes: 54132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

inline bool isPrime(int x) {
  bool ans = true;
  if (x <= 1) ans = false;
  for (int i = 2; i * i <= x; ++i) {
    if (x % i == 0) {
      ans = false;
      break;
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 11; i <= 55555; i += 5) {
    if (isPrime(i)) {
      cout << i;
      if (--n == 0) {
        break;
      }
      cout << " ";
    }
  }
  cout << '\n';
}


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

using namespace std;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for (int i = 0; i < S.size();) {
        bool can2 = false;
        for (int j = 0; j < 4; ++j) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2) {
            can = false;
            break;
        }
    }

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	t = zeros(Int,n)
	e = [Int[] for i in 1:n]
	for i in 2:n
		a = readline() |> parseInt
		push!(e[a],i)
		t[i] = a
	end
	layer = zeros(Int,n)
	stack = Tuple{Int,Int}[]
	push!(stack, (1,0))
	while !isempty(stack)
		(i,k) = pop!(stack)
		layer[i] = k
		for j in e[i]
			push!(stack, (j,k+1))
		end
	end
	d = Int[length(e[i]) for i in 1:n]
	l = zeros(Int,n)
	stack = Tuple{Int,Int}[(layer[i],i) for i in 1:n]
	stack = sort(stack, by=x->x[1],rev=true)
	g = [Int[] for i in 1:n]
	for iter in 1:n
		i = stack[iter][2]
		gl = length(g[i])
		if gl>0
			g[i] = sort(g[i])
			minim = 0
			for j in 1:gl
				minim = max(minim,g[i][j]+gl-j)
			end
			l[i] = minim
			if t[i]>0
				push!(g[t[i]],minim+1)
			end
		else
			l[i] = 1
			if t[i]>0
				push!(g[t[i]],1)
			end
		end
	end
	println(l[1])
end

main()

Measured memory_bytes: 171392
#include<stdio.h>
int main()
{
    int a,b,c,min,minfinal,max,maxfinal;
    scanf("%d %d %d",&a,&b,&c);
    min=(a<b)?a:b;
    minfinal=(min<c)?min:c;
    max=(a>b)?a:b;
    maxfinal=(max>c)?max:c;
    printf("%d %d %d\n",minfinal,(a+b+c-minfinal-maxfinal),maxfinal);
    return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

typedef long long ll;

const int mod = 1000000007;
const int Maxn = 100005;

int fac[Maxn], inv[Maxn];
int n, k;
vector <int> neigh[Maxn];

int toPower(int a, int p)
{
    int res = 1;
    while (p) {
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

int Inv(int x) { return toPower(x, mod - 2); }

int C(int n, int k)
{
    if (n < 0 || k < 0 || k > n) return 0;
    return ll(fac[n]) * inv[n - k] % mod;
}

int Solve(int v, int p)
{
    int my = int(neigh[v].size()) - 1;
    int res = C(k - 2, my);
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (u == p) continue;
        res = ll(res) * Solve(u, v) % mod;
    }
    return res;
}

int main()
{
    fac[0] = inv[0] = 1;
    for (int i = 1; i < Maxn; i++) {
        fac[i] = ll(fac[i - 1]) * i % mod;
        inv[i] = Inv(fac[i]);
    }
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh[a].push_back(b);
        neigh[b].push_back(a);
    }
    int res = C(k, int(neigh[1].size()) + 1);
    for (int i = 0; i < neigh[1].size(); i++) {
        int v = neigh[1][i];
        res = ll(res) * Solve(v, 1) % mod;
    }
    printf("%d\n", res);
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int64_t> a(n);
  rep(i,n) cin >> a.at(i);
  int64_t cnt = 0;
  rep(i,n){
    if(a.at(i) % 2 == 1){
      cnt += (a.at(i) / 2);
      a.at(i) = 1;
    }else if(a.at(i) % 2 == 0 && a.at(i) != 0){
      cnt += (a.at(i) / 2) - 1;
      a.at(i) = 2;
    }else{
      a.at(i) = 0;
    }
  }
  //
  /*rep(i,n){
    cout << a.at(i);
  }
  cout << endl;*/
  //
  rep(i,n-1){
    if(a.at(i) == 1 && a.at(i+1) > 0){
      cnt++;
      a.at(i) = 0;
      a.at(i+1)--;
    }
  }
  /*rep(i,n){
    cout << a.at(i);
  }
  cout << endl;*/
  rep(i,n){
    if(a.at(i) == 2){
      cnt += 1;
    }
  }
  cout << cnt << endl;
}
    

Measured memory_bytes: 1024
$stdin.read.split.map(&:to_i).tap do |n, a, *xs|
  dp = Array.new(n) { Array.new(n+1) { Array.new(n*50+1) } }
  s = ->i, c, v {
    if i == n
      c != 0 && v%c == 0 && v/c == a ? 1 : 0
    else
      dp[i][c][v] ||= (s.(i+1, c, v) + s.(i+1, c+1, v+xs[i]))
    end
  }
  puts s.(0, 0, 0)
end

Measured memory_bytes: 51708
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    int h, w; cin >> h >> w;
    char a[h + 1][w + 1]; rrep(i, 1, h + 1) rrep(j, 1, w + 1) cin >> a[i][j];
    rep(i, w + 2) cout << '#'; cout << endl;
    rrep(i, 1, h + 1) {
        cout << '#';
        rrep(j, 1, w + 1) cout << a[i][j];
        cout << '#';
        cout << endl;
    }
    rep(i, w + 2) cout << '#'; cout << endl;
}


Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

int main(){
	for(int n,k,m;scanf("%d%d%d",&n,&k,&m),n;){
		int next[10000],prev[10000];
		rep(i,n){
			next[i]=i+1;
			prev[i]=i-1;
		}
		next[n-1]=0;
		prev[0]=n-1;

		int p=m-1;
		rep(_,n-1){
			prev[next[p]]=prev[p];
			next[prev[p]]=next[p];
			rep(__,k) p=next[p];
		}
		printf("%d\n",p+1);
	}

	return 0;
}

Measured memory_bytes: 1104
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
    int n;
    int sum = 0;
    cin >> n;

    int d[n];
    for(int i=0;i<n;i++){
        cin >> d[i];
    }

    for(int j=0;j<n;j++){
        for(int k=j+1;k<n;k++){
            sum += d[j]*d[k];
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

#include <vector>
#include <set>
using namespace std;

struct union_find {
  vector<int> par;
  vector<int> rank;
  union_find(int n) : par(n) , rank(n) {
    for(int i = 0;i < n;i++) par[i] = i;
  }
  int root(int i) {
    return par[i] == i ? i : par[i] = root(par[i]);
  }
  /* unite x, y return parent */
  int unite(int x,int y) {
    x = root(x);
    y = root(y);
    if(x == y) return -1;
    if(rank[x] < rank[y]) {
      par[x] = y;
      return y;
    }
    else {
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
      return x;
    }
  }
};

int main() {
  i64 N, M, K;
  cin >> N >> M >> K;
  vector<i64> s(N, 1);
  
  union_find uf(N);
  vector<i64> ans(N);
  rep(i,0,M) {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    ans[a]--;
    ans[b]--;
    a = uf.root(a);
    b = uf.root(b);
    i64 r = uf.unite(a, b);
    if(r != -1) {
      s[r] = s[a] + s[b];
    }
  }
  rep(i,0,N) {
    ans[i] += s[uf.root(i)];
  }
  rep(i,0,K) {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    if(uf.root(a) == uf.root(b)) {
      ans[a]--;
      ans[b]--;
    }
  }
  rep(i,0,N) {
    cout << ans[i] - 1 << " \n"[i + 1 == N];
  }
}


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

string s = "yuiophjklnm";

int main(){
  string str;
  while(cin >>str){
    if(str=="#") break;
    int pf = -1;
    int ret = 0;
    for(int i=0;i<(int)str.size();i++){
      char c = str[i];
      int f=0;
      for(int j=0;j<(int)s.size();j++){
	if( s[j]==c ) f = 1;
      }
      if(pf == -1 ) {}
      else if( pf != f ) ret++;
      pf = f;
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1188
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define INF 2147483647
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
inline void Fail(){
	printf("0");
	exit(0);
}

const int maxn=100005;
int n,e,t,l=-1;
ll cur=Inf;
ll dp[maxn];
int x[maxn];

int main(){
	scanf("%d%d%d",&n,&e,&t);
	rep(i,n)scanf("%d",&x[i]);
	rep(i,n){
		while(2LL*(x[i]-x[l+1])>=t){
			cur=min(cur,(l<0?0:dp[l])-2LL*x[l+1]);
			l++;
		}
		dp[i]=min(cur+2LL*x[i],(l<0?0:dp[l])+t);
	}
	printf("%lld",e+dp[n-1]);
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 1408
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define ALL(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(){
	int N, L; cin >> N >> L;
	int sum = 0;
	int d = INF;
	int ans = 0;
	rep(i,N){
		sum += L+i;
	}
	rep(i,N){
		if(d > abs(L+i)){
			ans = sum-L-i;
			d = abs(L+i);
		}
	}
	// cout << d << endl;

	cout << ans << endl;


	return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    multiset<int> M;
    for (int i = 0; i < N; i++) {
        auto it = M.upper_bound(A[i] - 1);
        if (it == M.begin()) {
            M.insert(A[i]);
        } else {
            advance(it, -1);
            M.erase(it);
            M.insert(A[i]);
        }

        // for(auto e : M) {
        //     cout << e << " ";
        // }
        // cout << endl;
    }
    cout << M.size() << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

#define int long long
struct Edge {
  int to;
  int own;
  int len;
};

int N;
int M;
int C;
int S;
int G;
using Tup = tuple<int, int, int>;
using Pair = pair<int, Tup>;
int mat[21][114][114];
int mind[114];
int P[21];
int Q[21][51];
int R[21][51];

int Calc(int c, int l) {
  int ret = 0;
  reps(i, 1, P[c]+1) {
    if (l < Q[c][i]) {
      ret += (l - Q[c][i-1]) * R[c][i-1];
      break;
    }
    ret += (Q[c][i]-Q[c][i-1])*R[c][i-1];
  }
  return ret;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  while (1) {
    cin >> N >> M >> C >> S >> G;
    if (N == 0) return 0;

    --S;
    --G;

    fill(mat[0][0], mat[C][0], MOD);
    rep(c, C) {
      rep(v, N) {
        mat[c][v][v] = 0;
      }
    }

    rep(i, M) {
      int u, v;
      int d, c;
      cin >> u >> v >> d >> c;
      --u;
      --v;
      --c;

      MN(mat[c][u][v], d);
      MN(mat[c][v][u], d);
    }

    rep(c, C) {
      rep(w, N) {
        rep(v, N) {
          rep(u, N) {
            MN(mat[c][v][u], mat[c][v][w] + mat[c][w][u]);
          }
        }
      }
    }

    rep(c, C) {
      cin >> P[c];
    }

    rep(c, C) {
      reps(i, 1, P[c]) {
        cin >> Q[c][i];
      }
      Q[c][0] = 0;
      Q[c][P[c]] = MOD;
      rep(i, P[c]) {
        cin >> R[c][i];
      }
    }

    priority_queue<pii, vector<pii>, greater<pii>> que;
    fill(mind, mind+N, MOD);
    mind[S] = 0;
    que.push(pii(0, S));
    while (!que.empty()) {
      pii pa = que.top(); que.pop();
      int cost = pa.X;
      int v = pa.Y;

      if (mind[v] < cost) continue;
      rep(u, N) {
        if (u == v) continue;
        rep(c, C) {
          if (mat[c][v][u] == MOD) continue;
          int nc = cost + Calc(c, mat[c][v][u]);
          if (mind[u] > nc) {
            mind[u] = nc;
            que.push(pii(mind[u], u));
          }
        }
      }
    }

    int ans = mind[G];
    if (ans == MOD) cout << "-1" << "\n";
    else cout << ans << "\n";
  }
}



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


ll ans[2001];
ll mod = 1000000007;

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

    ans[0] = 0;
    ans[1] = 0;
    ans[2] = 0;
    ans[3] = 1;
    ans[4] = 1;
    ans[5] = 1;

    long long tmp = 1;

    for(int i=6; i<=2000; i++){
        ans[i] = 1 + tmp;
        ans[i] %= mod;
        tmp += ans[i-2];
        tmp %= mod;
    }    

    cout << ans[s] << endl;
}

Measured memory_bytes: 3616
n = int(input())
s = list(map(int,input().split()))

cnt = 0
check = True
while check:
    for i in range(n):
        if s[i] % 2 == 0:
            s[i] = int(s[i]/2)
        else:
            check  = False
            break
    if check:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MX 100005
#define pb push_back
int dp[MX];
vector <int> vec[MX];
bool vis[MX];
void dfs(int a) {
	vis[a] = true;
	for (int b : vec[a]) {
		if (!vis[b])
			dfs(b);
		dp[a] = max(dp[a], 1 + dp[b]);
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	while (m--) {
		int a, b;
		cin >> a >> b;
		vec[a].pb(b);
	}
	for (int i = 1; i <= n; ++i)
		if (!vis[i])
			dfs(i);
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans = max(ans, dp[i]);
	cout << ans << endl;
}


Measured memory_bytes: 8192