akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
#define test int T;cin>>T; for(int t=1;t<=T;t++)
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define memory freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define mod ((int)1e9+7)
const long long MAX_SIZE = ((int)1e6+5);
vector<long long >isprime(MAX_SIZE , true);
vector<long long >prime;
vector<long long >SPF(MAX_SIZE);
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define mp make_pair
#define forr(i,n) for(int i=0;i<n;i++)
#define inf ((int)1e18)
#define vi vector<int>
#define qi queue<int>
#define vs vector<string>
#define vc vector<char>
#define F first
#define S second
#define mii map<int,int>
#define dmii map<int, int, greater <int> >
#define msi map<string,int>
#define pii pair<int,int>
#define psi pair<string,int>
#define len() length()
#define accept(a,n) for(int i=0;i<n;i++) cin >> a[i];
#define display(a,n) for(int i=0;i<n;i++) {cout << a[i] << " ";}
#define set(a,x,n) for(int i=0;i<n;i++) {a[i] = x;}


int primeFactors(int n) {  
    set<int> x;
    while (n % 2 == 0) {  
        x.insert(2);
        n = n/2;  
    }  
  
    for (int i = 3; i <= sqrt(n); i = i + 2) {  
        while (n % i == 0) {  
            x.insert(i);
            n = n/i;  
        }  
    }  
    if (n > 2)  
        x.insert(n);

    return x.size();  
}  


signed main() {
    speed;
    int a,b;
    cin >> a >> b;
    int c = __gcd(a,b);
    cout << primeFactors(c) + 1;
}
 

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

int main(void){
    string str,tmp,command;
    int q,a,b;
    cin>>str>>q;
    for(int i=1;i<=q;i++){
        cin>>command>>a>>b;
        if(command=="print"){
            cout<<str.substr(a,b-a+1)<<endl;
        }else if(command=="reverse"){
            tmp=str.substr(a,b-a+1);
            for(int i=a;i<=b;i++)str[i]=tmp[b-i];
        }else{
            cin>>tmp;
            for(int i=a;i<=b;i++)str[i]=tmp[i-a];
        }
    }
    return 0;
}

Measured memory_bytes: 3164
n = int(input())
ans = 0
if n % 2 == 0:
    n -= 1
while True:
    c = 0
    for i in range(1, n + 1):
        if n % i == 0:
            c += 1
    if c == 8:
        ans += 1
    n -= 2
    if n == -1:
        break
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

int  A[1000000], n;

int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;

	while (left < right) {
		mid = (left + right)/2;
		if (key == A[mid]) return 1;
		if (key >  A[mid]) left = mid +  1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

int main() {
	int i, q, k, sum  = 0;

	scanf("%d", &n);
	for (i = 0; i <  n; i++) {
		scanf("%d", &A[i]);
	}

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &k);
		if (binarySearch(k)) sum++;
	}
	printf("%d\n", sum);

	return 0;
}





Measured memory_bytes: 3020
import Control.Monad
import Control.Applicative

main :: IO ()
main = do
  [a,b,c] <- map toInt . words <$> getLine
  if (b - a) == (c - b) 
  then putStrLn "YES"
  else putStrLn "NO"
  where
    toInt :: String -> Int
    toInt = read


Measured memory_bytes: 508
K=int(input())
X,Y=map(int,input().split())

sgn_X,sgn_Y=1,1
if X<0:
  X=-X
  sgn_X=-1
if Y<0:
  Y=-Y
  sgn_Y=-1

if K%2==0 and (X+Y)%2==1:
  print(-1)
else:
  xx,yy=0,0
  vec_list=[]
  while((X-xx)+(Y-yy)>2*K):
    if X-xx>K:
      xx+=K
      vec_list.append((K,0))
    elif Y-yy>K:
      yy+=K
      vec_list.append((0,K))
  #print(xx,yy,vec_list)
  diff_x=X-xx
  diff_y=Y-yy
  
  if K%2==0:
    if diff_x+diff_y==K:
      vec_list.append((diff_x,diff_y))
    else:
      buf=2*K-(diff_x+diff_y)
      if diff_x+buf//2<=K:
        vec_list.append((diff_x+buf//2,K-(diff_x+buf//2)))
        vec_list.append((-buf//2,K-buf//2))
      elif diff_y+buf//2<=K:
        vec_list.append((K-(diff_y+buf//2),diff_y+buf//2))
        vec_list.append((K-buf//2,-buf//2))
      else:
        raise("Error")    
          
  else:
    if diff_x+diff_y==K:
      vec_list.append((diff_x,diff_y))
    else:
      if (diff_x+diff_y)%2==1:
        if diff_x<=K:
          xx+=diff_x
          if K-diff_x<diff_y:
            yy+=K-diff_x
            vec_list.append((diff_x,K-diff_x))
          else:
            yy-=K-diff_x
            vec_list.append((diff_x,-K+diff_x))
        elif diff_y<=K:
          yy+=diff_y
          if K-diff_y<diff_x:
            xx+=K-diff_y
            vec_list.append((K-diff_y,diff_y))
          else:
            xx-=K-diff_y
            vec_list.append((-K+diff_y,diff_y))

      diff_x=X-xx
      diff_y=Y-yy
      buf=2*K-(diff_x+diff_y)  
      if diff_x+buf//2<=K:
        vec_list.append((diff_x+buf//2,K-(diff_x+buf//2)))
        vec_list.append((-buf//2,K-buf//2))
      elif diff_y+buf//2<=K:
        vec_list.append((K-(diff_y+buf//2),diff_y+buf//2))
        vec_list.append((K-buf//2,-buf//2))
      else:
        raise("Error")    

  #print(vec_list)
  print(len(vec_list))
  pos_x,pos_y=0,0
  for x,y in vec_list:
    pos_x+=sgn_X*x
    pos_y+=sgn_Y*y
      
    print(pos_x,pos_y)

Measured memory_bytes: 19704
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int K = 3;

typedef vector<int> vi;

int main() {
    int n, m;
    cin >> n >> m;
    vi e[n];
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        e[u].push_back(v);
    }
    int s, t;
    cin >> s >> t;
    s--, t--;

    int d[n][K];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < K; j++) {
            d[i][j] = -1;
        }
    }
    d[s][0] = 0;

    queue<int> q;
    q.push(s*K);

    while (!q.empty()) {
        int x = q.front() / 3;
        int p = q.front() % 3;
        q.pop();

        for (int y : e[x]) {
            if (d[y][(p+1)%3] == -1) {
                d[y][(p+1)%3] = p == K - 1 ? d[x][p] + 1 : d[x][p];
                q.push(y * 3 + (p + 1) % 3);
            }
        }
    }

    cout << d[t][0] << endl;

    return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
int main() {
    int card[4][13] = {0};
    char Class;
    int Rank, n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> Class >> Rank;
        if (Class == 'S') {
            card[0][Rank] = 1;
        } else if (Class == 'H') {
            card[1][Rank] = 1;
        } else if (Class == 'C') {
            card[2][Rank] = 1;
        } else if (Class == 'D') {
            card[3][Rank] = 1;
        }
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 1; j <= 13; j++) {
            if (card[i][j] != 1) {
                if (i == 0) {
                    cout << 'S' << " " << j << endl;
                } else if (i == 1) {
                    cout << 'H' << " " << j << endl;
                } else if (i == 2) {
                    cout << 'C' << " " << j << endl;
                } else if (i == 3) {
                    cout << 'D' << " " << j << endl;
                }
            }
        }
    }
    return 0;
}




Measured memory_bytes: 3064
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int cnt[26];
char s[111],n,m;
int main()
{
	get2(n,m);
	for(int i=0;i<n;i++)
	{
		scanf("%s",s);
		for(int j=0;j<m;j++)cnt[s[j]-'a']++;
	}
	int c1=0,c2=0,d1=0,d2=0;
	for(int i=0;i<26;i++)
	{
		c1+=(cnt[i]%4>1);
		c2+=(cnt[i]%2>0);
	}
	if(n%2&&m%2)
	{
		d1=(n+m-2)/2;
		d2=1;
	}
	else if(n%2)d1=m/2;
	else if(m%2)d1=n/2;
	if(c1<=d1&&c2<=d2)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<string,int,int>;

int main(){
  int k,a,b; cin >> k >> a >> b;
  for(int i = a; i <= b; i++){
    if(i % k == 0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;  
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <queue>


using namespace std;


int main(){
    int A[200000];
    int N;
    cin >> N;
    std::priority_queue<int> q;

    for(int i=0; i<N; i++){
        cin >> A[i];
        q.push(A[i]);
    }

    for(int i=0; i<N; i++){
        int top = q.top();
        if(top != A[i])
            cout << top << endl;
        else{
            q.pop();
            cout << q.top() << endl;
            q.push(top);
        }
    }

    return 0 ;

}

Measured memory_bytes: 3316
/* 
 * Project: AtCoder Beginners Contest 154 B - I miss you...
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/30
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <stdio.h>

char s[100];

void solve() {

    char *ptr;
    ptr = &s[0];

    while (*ptr ^ '\0') {
        printf("x");
        ptr++;
    }
    printf("\n");
}

int main() {

    scanf("%s", s);

    solve();

}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;

int main() {
    ll N;
    cin >> N;
    ll ans = 0;

    vector<ll> A(N, 0);
    rep(i,N) cin >> A[i];

    rep(i,N - 1){
        if(A[i] < 0){
            A[i] = -A[i];
            A[i + 1] = -A[i + 1];
        }
    }
    ll cnt = 0;
    rep(i,N){
        if(A[i] >= 0){
            cnt++;
        }
    }
    A[N - 1] = abs(A[N - 1]);
    sort(A.begin(),A.end());
    if(cnt != N){
        rep(i,N) ans += llabs(A[i]);
        ans -= A[0] * 2;

    }
    else{
        rep(i,N) ans += A[i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 3984
#include <stdio.h>
int main(){
    long long int a;
   int count=0;
    char b[100]={};
    char c[100]={};
    scanf("%lld",&a);
  for(int i=0;a>0;i++){
    if (a%26==0){
     b[i]='z';
      a/=26;
      a--;
      count++;
    }
  else {
    b[i]=a%26+96;
    a/=26;
    count++;
   }
  }
  for(int i=0;i<count;i++){
    c[i]=b[i];
    c[i]=b[count-i-1];
  }
  printf("%s",c);
  return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define int long long

signed main() {
  int n, h;
  cin >> n >> h;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a, a + n, greater<int>());
  sort(b, b + n, greater<int>());
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (h <= 0) {
       cout << count << endl;
       return 0;
    }
    if (b[i] <= a[0]) break;
    h -= b[i];
    count++;
  }
  if (h <= 0) {
    cout << count << endl;
    return 0;
  }
  if (h % a[0] == 0) count += h / a[0];
  else count += h / a[0] + 1;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
ans = float("inf")

for i in range(1, N):
    A = i
    B = N - i
    A_sum = 0
    B_sum = 0
    while True:
        if A // 10 > 0:
            A_sum += A % 10
            A  //= 10
        else:
            A_sum += A % 10
            break
    while True:
        if B // 10 > 0:
            B_sum += B % 10
            B  //= 10
        else:
            B_sum += B % 10
            break
    if ans > (A_sum + B_sum):
        ans = A_sum + B_sum
print(ans)


Measured memory_bytes: 72812
import numpy as np
n,m=map(int,input().split())
l=[]
for i in range(m):
    l.append(list(map(int,input().split())))
p=list(map(int,input().split()))
chk=[]
for i in range(m):
    tmp=[0]*n
    for k in range(1,len(l[i])):
        tmp[l[i][k]-1]+=1
    chk.append(np.array(tmp))
chk=np.array(chk)

cnt=n
sw=[]
for i in range(2**cnt):
    ln=[0]*cnt
    for j in range(cnt):
        if ((i>>j)&1):
            ln[cnt-j-1]=1
    sw.append(np.array(ln))
sw=np.array(sw)
cnt=0
for k in range(len(sw)):
    flag=True
    for i in range(m):
        if np.sum(sw[k]*chk[i])%2!=p[i]:
            flag=False
    if flag:
        cnt+=1
       
print(cnt)


Measured memory_bytes: 14292
/*
#include <iostream> 
#include <stdlib.h> 
using namespace std; 

void DIV( int divident, int divisor, int precision = 30); //小數位數內定30位 

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

DIV(a, b,10); //不指定小數位數，採內定的30位 
/* 
cout << "解答(60位小數)："; 
DIV(a, b, 60); //指定小數位數的用法 
*/ 
/*
return 0; 
} 

void DIV( int divident, int divisor, int precision) 
{ 
if (divisor == 0) //除數為零，顯示錯誤訊息並結束程式 
{ cout << "Zero divisor error!\n" ; exit( system("pause") ); } 
if ( (divident < 0) ^ (divisor < 0) ) cout << '-'; //兩數若異號，先印出負號 
if (divident < 0) divident = -divident; //被除數取其絕對值 
if (divisor < 0) divisor = -divisor; ////除數取其絕對值 
cout << divident / divisor; //印出整數部份 
 cout << '.'; //若帶有小數，印出小數點 
//迴圈印出小數部份，直到除盡或已抵指定位數 
while ( (divident %= divisor) && precision--)
if(precision == 0 && ((divident *= 10) / divisor) >= 5){
	cout<< 
}

for(int i = 0;i<precision-1;i++){
if((divident%= divisor)==0) cout << 0;
}
cout << "\n";
} 
*/

#include <bits/stdc++.h>
using namespace std;

int main(){
	int s[12];
	int a,b;
	cin >> a >> b;
	//a = a/10;
	for(int i = 1;i<12;i++){
	s[i] = a / b;
	a = (a - (s[i] * b)) * 10;
	if(i == 1){
		cout << s[1] << ".";
	}
	else if(s[11] >= 5){
		cout << s[10]+1;
	}
	else if(1 <= i <= 9){
		cout << s[i];
	}
	else{
		s[i] = s[i];
	}
}
	return 0;
}

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

typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


//===

const ll mod = ll(1e9 + 7);



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

	int a = (N - 1) * (N - 2) / 2;
	if (K > a) {
		cout << -1 << endl;
		return 0;
	}

	vector<Pii> G;
	for (int i = 2; i <= N; ++i) {
		G.emplace_back(1, i);
	}

	int r = a - K;
	int num = 0;
	bool flag = false;
	for (int i = 2; i <= N - 1; ++i) {
		for (int j = i + 1; j <= N; ++j) {
			if (num == r) {
				flag = true;
				break;
			}
			G.emplace_back(i, j);
			++num;
		}
		if (flag) break;
	}

	cout << G.size() << endl;
	for (const auto& v : G) {
		cout << v.first << " " << v.second << endl;
	}
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int K = sc.nextInt();
		int Q = sc.nextInt();
		for (int i=0;i<Q;i++) {
			int temp = sc.nextInt();
			A[temp-1]++;
		}
		for (int i=0;i<N;i++) {
			if (A[i]+K-Q>0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

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

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return -d[find(x)];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }
    int ans = 0;
    rep (i, n) if (uf.same(i, v[i]-1)) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3964
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

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

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

const int INF = 1001001001;
const ll FINAL = 0x0ba9876543210ll;

struct Data
{
	ll s;
	int d;
	bool f;
	Data(ll s, int d, bool f) : s(s), d(d), f(f) {}
};

int bfs(ll init)
{
	if(init == FINAL)
		return 0;
	
	const int move[13][5] = {
		{2, -1},
		{2, 5, -1},
		{0, 1, 3, 6, -1},
		{2, 7, -1},
		{5, -1},
		{1, 4, 6, 9, -1},
		{2, 5, 7, 10, -1},
		{3, 6, 8, 11, -1},
		{7, -1},
		{5, 10, -1},
		{6, 9, 11, 12, -1},
		{7, 10, -1},
		{10, -1}
	};
	
	set<ll> visited[2];
	queue<Data> Q;
	Q.push(Data(init, 0, false));
	Q.push(Data(FINAL, 0, true));
	visited[0].insert(init);
	visited[1].insert(FINAL);
	int now[2] = {0};
	
	while(!Q.empty()){
		Data data = Q.front();
		Q.pop();
		now[data.f] = data.d + 1;

		for(int i=0, cnt=2; cnt; ++i){
			if(((data.s>>(i*4)) & 0xfll) == 0){
				for(int j=0; move[i][j]!=-1; ++j){
					ll next = data.s;
					next &= ~((0xfll << (i*4)) | (0xfll << (move[i][j]*4)));
					next |= ((data.s >> (move[i][j]*4)) & 0xfll) << (i*4);
					
					if(visited[!data.f].find(next) != visited[!data.f].end())
						return now[0] + now[1];

					if(visited[data.f].find(next) == visited[data.f].end()){
						visited[data.f].insert(next);
						if(data.d <= 8)
							Q.push(Data(next, data.d+1, data.f));
					}
				}
				--cnt;
			}
		}
	}
	return -1;
}

int main()
{
	for(;;){
		int input[13];
		rep(i, 13){
			scanf("%d", &input[i]);
			if(input[i] == -1)
				return 0;
		}

		ll init = 0;
		rep(i, 13)
			init = (init << 4) | input[12-i];

		int ans = bfs(init);
		if(ans == -1)
			puts("NA");
		else
			printf("%d\n", ans);
	}
}

Measured memory_bytes: 2496
n, m = map(int, input().split(" "))

xyz = list()
for i in range(0, n):
    x, y, z = map(int, input().split(" "))
    xyz.append((x, y, z))

ans = 0
for a1 in [1, -1]:
    for a2 in [1, -1]:
        for a3 in [1, -1]:
            tmp = list()
            for x, y, z in xyz:
                tmp.append(x * a1 + y * a2 + z * a3)

            sorted_calc = sorted(tmp, reverse=True)
            sum = 0
            for i in range(0, m):
                sum += sorted_calc[i]

            ans = max(sum, ans)

print(ans)


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

using namespace std;

using ll = long long;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
    cin.tie(0);
    cout << fixed << setprecision(10);

    ll n, m; cin >> n >> m;
    vector<int> s(n), t(m);
    
    for(int i=0;i<n;++i) {
      cin >> s[i];
    }
    for(int i=0;i<m;++i) {
      cin >> t[i];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(m+1, 0));
    vector<vector<ll>> cnt(n+1, vector<ll>(m+1, 0));
    dp[0][0] = 1;

    for(int i=0;i<n;++i) {
      for(int j=0;j<m;++j) {
        if(s[i] == t[j]) {
          dp[i+1][j+1] = cnt[i][j] + 1;
        }
        dp[i+1][j+1] %= MOD;
        cnt[i+1][j+1] = cnt[i+1][j] + cnt[i][j+1] - cnt[i][j] + dp[i+1][j+1] + MOD;
        cnt[i+1][j+1] %= MOD;
      }
    }

/*     for(int i=0;i<n+1;++i) {
      printv(dp[i]);
    }

    for(int i=0;i<n+1;++i) {
      printv(cnt[i]);
    } */

    cout << cnt[n][m] + 1 << endl;


    

}

Measured memory_bytes: 62976
//													\[T]/ Praise
//													 (*)  The
//													 / \  Sun



#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double dbl;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<long long> vl;
typedef vector< pair<int, int> > vii;
#define mp make_pair
#define pb push_back
#define invec(a, n) for(ll i = 0; i < n; i++) {cin >> a[i];}
#define rep(n) for(ll i = 0; i < n; i++)
#define fr(i,j,k) for(ll i = j; i < k; i++)
#define FR(i,j,k) for(ll i = j; i >= 0; i--)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define INF 1000000
#define xx first
#define yy second

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

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

	ll val[n][3];

	fr(i,0,n)
	{
		cin >> val[i][0] >> val[i][1] >> val[i][2];
	}
	ll dp[n+1][3];

	fr(i,0,n+1)
	{
		fr(j,0,3)
			dp[i][j] = 0;
	}

	fr(i,0,n)
	{
		fr(j,0,3)
		{
			dp[i+1][j] = max(dp[i][(j+1)%3] + val[i][j], dp[i+1][j]);
			dp[i+1][j] = max(dp[i][(j+2)%3] + val[i][j], dp[i+1][j]);
		}
	}

	ll res = max(dp[n][0], dp[n][1]);
	res = max(res, dp[n][2]);

	cout << res;
}

Measured memory_bytes: 4992
N = int(input())
S = input()
 
l_cursor = 0
r_cursor = 1

max_l = 0
 
while l_cursor < N:
    if r_cursor - l_cursor > N - r_cursor:
        break

    serch_string = S[l_cursor:r_cursor]

    if serch_string in S[r_cursor:]:
        max_l = max(max_l, len(serch_string))
        r_cursor += 1
    else:
        l_cursor += 1
 
print(max_l)

Measured memory_bytes: 3064
$A =int(<STDIN>);#500
$B =int(<STDIN>);#100
$C =int(<STDIN>);#50
$X =int(<STDIN>);#50n

$n=0;
$X=$X/50;
for($a=0;$a<=$X/10 && $a<=$A;$a++){
	$R1=$X-$a*10;
	for($b=0;$b<=$R1/2 & $b<=$B;$b++){
		$n+=1 if ($R1-$b*2<=$C);
	}
}
print $n;


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int a, b;
    cin >> a >> b;

    if(a+b<=9) cout << a + b << endl;
    else cout << "error" << endl;
    return 0;
}


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

using namespace std;
#define int long long
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.first<<','<< P.second<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
#define show(x) cout<<#x<<" : "<<x<<'\n';


signed main(){
	fio;
	int t=1;
	// cin>>t;
	while(t--){
			string s;
			cin>>s;
			if(s=="ABC"){
				cout<<"ARC\n";
			}else{
				cout<<"ABC\n";
			}
	}
}

Measured memory_bytes: 3640
import numpy as np
N, M = map(int, input().split())
H = list(map(int, input().split()))
yoi = np.ones(N)
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
        yoi[B-1] = 0
    elif H[B-1] > H[A-1]:
        yoi[A-1] = 0
    elif H[A-1]==H[B-1]:
        yoi[A-1] = 0
        yoi[B-1] = 0
print(int(np.sum(yoi)))

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

int BIT[200001] = {0};
int N = 200000;


int n;
int a[200001];
int b[200001];

int sum(int i){
	int s = 0;
	while(i > 0){
		s += BIT[i];
		i -= i & -i;
	}
	return s;
}
void add(int i,int x){
	while(i <= N){
		BIT[i] += x;
		i += i & -i;
	}
}

int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&a[i]);
		b[i] = a[i];
	}
	sort(b,b+n); // n log n
	for(int i = 0; i < n; i++){ // 0 <= a <= 1e9 -> 1 <= a <= 200000
		int* ptr = lower_bound(b,b+n,a[i]);
		int idx = ptr - b;
		a[i] = idx + 1;
	}

	long long int ans = 0;

	for(int i = 0; i < n; i++){
		ans += i - sum(a[i]);
		add(a[i],1);
	}
	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 5612
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>c>>b>>a>>n;
    rep(i,n){
        if(c>=b){
            b*=2;
        }else{
            a*=2;
        }
    }
    //cout<<a<<" "<<b<<" "<<c<<endl;
    if(a>b&&b>c)Yes;
    else No;

    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<ll>> dp(h,vector<ll>(w,0));
    rep(i,h){
        rep(j,w){
            char t;cin>>t;
            if(t=='#')  dp[i][j]=-1;
        }
    }
    dp[0][0]=1;
    rep(i,h){
        rep(j,w){
            if(i==0&&j==0)  continue;
            if(dp[i][j]<0)  continue;
            if(i==0)        dp[0][j]=dp[0][j-1];
            else if(j==0)   dp[i][0]=dp[i-1][0];
            else{
                if(dp[i-1][j]>=0)   dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
                if(dp[i][j-1]>=0)   dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
    return 0;
}

Measured memory_bytes: 8064
class SegmentTree():
    def __init__(self, arr, func=min, ie=2**63):
        self.n = 2**(len(arr) - 1).bit_length()
        self.ie = ie
        self.func = func
        self.tree = [ie for _ in range(2 * self.n)]
        for i in range(len(arr)):
            self.tree[self.n + i - 1] = arr[i]
        for i in range(self.n - 1)[::-1]:
            self.tree[i] = func(self.tree[2 * i + 1], self.tree[2 * i + 2])

    def set(self, index, x):
        index += self.n - 1
        self.tree[index] = x
        while index:
            index = (index - 1) // 2
            self.tree[index] = self.func(self.tree[2 * index + 1], self.tree[2 * index + 2])

    def query(self, left, right):
        if right <= left:
            return self.ie
        left += self.n - 1
        right += self.n - 2
        tmp_l = self.ie
        tmp_r = self.ie
        while right - left > 1:
            if left & 1 == 0:
                tmp_l = self.func(tmp_l, self.tree[left])
            if right & 1 == 1:
                tmp_r = self.func(self.tree[right], tmp_r)
                right -= 1
            left = left // 2
            right = (right - 1) // 2
        if left == right:
            tmp_l = self.func(tmp_l, self.tree[left])
        else:
            tmp_l = self.func(self.func(tmp_l, self.tree[left]), self.tree[right])
        return self.func(tmp_l, tmp_r)

N = int(input())
H = list(map(int, input().split()))
A = list(map(int, input().split()))

arr = [0 for _ in range(N + 1)]
dp = SegmentTree(arr, max, 0)

for i in range(N):
    dp.set(H[i], dp.query(0, H[i]) + A[i])

print(dp.query(0, N + 1))

Measured memory_bytes: 121212
N,M,X=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
A.sort()
for i,a,b in zip(range(len(A)-1),A[:len(A)-1],A[1:]):
    if a<X and X<b:
        print(min(len(A[:i+1]),len(A[i+1:])))
        break
else:
    print(0)


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

int selectionSort(vector<int> &x, int n){
    int swap_cnt = 0;
    for(int i = 0; i < n; i++){
        int minj = i;

        for(int j = i; j < n; j++){
            if(x.at(j) < x.at(minj)){
                minj = j;
            }
        }

        if(i != minj){
            swap_cnt++;
            int tmp = x.at(i);
            x.at(i) = x.at(minj);
            x.at(minj) = tmp;
        }
    }
    return swap_cnt;
}

void printVec(vector<int> x, int n){
    rep(i, n-1){
        cout << x.at(i) << " ";
    }
    cout << x.at(n-1) << endl;
}

int main(){
    int n; cin >> n;
    vector<int> x(n);
    rep(i, n){
        cin >> x.at(i);
    }
    int cnt = selectionSort(x, n);

    printVec(x, n);
    cout << cnt << endl;
}


Measured memory_bytes: 3136
# Knapsack 2
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
inf = float("inf")
dp = [[inf for i in range(100100)] for j in range(N + 1)]
dp[0][0] = 0
for n in range(N):
    for v in range(100100):
        if wv[n][1] <= v:
            dp[n+1][v] = min(dp[n][v - wv[n][1]] + wv[n][0], dp[n][v])
        else:
            dp[n+1][v] = dp[n][v]

for v in reversed(range(100100)):
    if dp[-1][v] > 0 and dp[-1][v] <= W:
        print(v)
        break

Measured memory_bytes: 341276
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  int cnt = 0;
  rep(i,n) if(a[i] < 0) cnt++;
  
  ll ans = 0;
  if(cnt%2){//もしマイナスの個数が奇数だったら
    int mi = 1 << 30;
    rep(i,n){
      ans += abs(a[i]);
      chmin(mi,abs(a[i]));
    }
    ans -= mi*2;
  }else{
    rep(i,n) ans += abs(a[i]);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 640
(defun input (n)
  (let ((a (make-array n)))
    (loop for i below n do (setf (aref a i) (read)))
    a)) 

(let* ((n (read))
       (a (input n))
       (c (count-if (lambda (x) (< x 0)) a))
       (s (loop for i below n sum (abs (aref a i)))))
  (format t "~A~%"
          (if (evenp c)
            s
            (- s (* 2(loop for i below n
                           minimize (abs (aref a i))))))))

Measured memory_bytes: 59752
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

string str, ans;
char c[11];

int main(void) {
  cin>>str;
  while(str.length()>4) str.pop_back();
  if(str == "YAKI") ans = "Yes";
  else ans = "No";
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]

for cx in range(101):
    for cy in range(101):
        for xi, yi, hi in p:
            if hi > 0:
                h = abs(xi - cx) + abs(yi - cy) + hi
                break
        if all(max(h - abs(xi - cx) - abs(yi - cy), 0) == hi for xi, yi, hi in p):
            print(cx, cy, h)
            exit()

Measured memory_bytes: 3064
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete

data Color = Red | Yellow | Blue | Magenta | Green | Cyan deriving (Show, Eq, Ord, Read)

type Cube = [Color]

rotateC [c1,c2,c3,c4,c5,c6] = [c1,c3,c5,c2,c4,c6]
moveC [c1,c2,c3,c4,c5,c6] = [c2,c6,c3,c4,c1,c5]

normalize :: Cube -> Cube
normalize c = let c' = minimum [c, moveC c, moveC $ moveC c, moveC $ moveC $ moveC c, moveC $ rotateC c, moveC $ rotateC $ rotateC $ rotateC c] in minimum $ take 4 $ iterate rotateC c'

main = do
    n <- getInt
    unless (n==0) $ do
        (n-) . length . group . sort . map (normalize . map read . words) <$> replicateM n getLine >>= print >> main
    


Measured memory_bytes: 5508
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

vector<int> tonari[200005];

int main(){
    int N,Q;
    cin>>N>>Q;
    int a,b;
    for (int i = 0; i < N-1; ++i) {
        cin>>a>>b; a--; b--;
        tonari[a].push_back(b);
        tonari[b].push_back(a);
    }

    vector<ll> pushed(N,0ll);
    int p,x;
    for (int i = 0; i < Q; ++i) {
        cin>>p>>x; p--;
        pushed[p]+=x;
    }
    vector<ll> score(N,-1ll);
    queue<int> q;
    score[0]=pushed[0];
    q.push(0);
    while(!q.empty()){
        int node=q.front();
        q.pop();
        for(auto tsugi:tonari[node]){
            if(score[tsugi]>=0) continue;
            score[tsugi]=score[node]+pushed[tsugi];
            q.push(tsugi);
        }
    }

    for (int i = 0; i < N; ++i) {
        cout<<score[i];
        if(i<N-1) cout<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 17908
#include<stdio.h>
#include<algorithm>
long long n,m;
long long ans;
main()
{
	scanf("%lld%lld",&n,&m);
	if(m==0) printf("%lld\n",n*n);
	else
	{
	for(long long i=m+1;i<=n;i++)
	{
		long long k=n%i;
		ans+=(n/i)*(i-m);
		if(k>=m) ans+=k-m+1;
	}
	printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A=sc.nextLong(),B=sc.nextLong(),C=sc.nextLong(),K=sc.nextLong();
		long ans=0;
		if(K<=A) {
			ans= K;
		}else if(K>A&&K<=A+B) {
			ans= A;
		}else {
			ans=A-(K-A-B);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 35796
#include "bits/stdc++.h"
using namespace std;

#define ll long long 
ll n;

int main(){
	scanf("%lld", &n);
	if(n%2 == 0){
		ll num5 = 0;
		for(ll i = 5, j = 1; i <= n; i *= 5, ++j){
			num5 += (n/2/i);
		}
		printf("%lld\n", num5);
	}else{
		printf("0\n");
	}
}

Measured memory_bytes: 256
import numpy as np
from collections import deque
h, w = map(int, input().split())
r = [list(input()) for i in range(h)]


def dist(s, t):
    if r[s][t] == "#":
        return 0
    else:
        visited = np.zeros((h, w))
        visited[s][t] += 1
        distance = np.zeros((h, w))
        q = deque([[s, t]])
        while len(q) > 0:
            i, j = q.popleft()
            d = distance[i][j] + 1
            if j != w-1:
                if r[i][j+1] == "." and not visited[i][j+1]:
                    q.append([i, j + 1])
                    visited[i][j+1] += 1
                    distance[i][j+1] += d
            if j != 0:
                if r[i][j-1] == "." and not visited[i][j-1]:
                    q.append([i, j - 1])
                    visited[i][j - 1] += 1
                    distance[i][j - 1] += d
            if i != 0:
                if r[i-1][j] == "." and not visited[i-1][j]:
                    q.append([i - 1, j])
                    visited[i-1][j] += 1
                    distance[i-1][j] += d
            if i != h-1:
                if r[i+1][j] == "." and not visited[i+1][j]:
                    q.append([i + 1, j])
                    visited[i+1][j] += 1
                    distance[i+1][j] += d
        return np.max(distance)


ans = 0
for s in range(h):
    for t in range(w):
        ans = max(ans, dist(s, t))

print(int(ans))

Measured memory_bytes: 12532
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL W,n,i,j,ans = 0;
LL a[1000],v[10000] ;
LL dp[100+1][100000+1] ;  
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>W ; 
    REP(i,n) cin>>a[i]>>v[i] ; 
    REP(i,n)
     REP(j,W)
       if(a[i]>j) dp[i][j] = dp[i-1][j] ; 
        else dp[i][j] = max(v[i] + dp[i-1][j-a[i]],dp[i-1][j]) ; 
      
    
    cout<<dp[n][W]<<endl;
        
        
    
}
//Check for 0,1 and other corner cases.

Measured memory_bytes: 78464
#include <iostream>

using namespace std;

#define N_MAX 100

int Adj[N_MAX][N_MAX] = {};
int Chk[N_MAX][2] = {};
int search_time = 1;

void dfs(int v, int num_node);

int main()
{
    int n, i, u, k, v, j;

    cin >> n;

    //??£??\???????????????
    for (i = 0; i < n; i++) {
        cin >> u >> k;
        while (k-- > 0) {
            cin >> v;
            Adj[u-1][v-1] = 1;
        }
    }
/*
    cout << "show Adjacency matrix" << endl;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n ; j++) {
            if (j == n - 1)
                cout << Adj[i][j] << endl;
            else
                cout << Adj[i][j] << ' ';
        }
    }
*/
    //??¢?´¢??????
//    dfs(1, n);
    for (i = 1; i <= n; i++) {
        if (Chk[i-1][0] == 0)
            dfs(i, n);
    }

    //????????????
    for(i = 1; i <= n; i++) {
        cout << i << ' ' << Chk[i-1][0] << ' ' << Chk[i-1][1] << endl;
    }

    return 0;
}

void dfs(int v, int num_node) {

//    cout << "dfs node : " << v << " time : " << search_time << endl;

    int i;
    //v???????????????????¨????
    if (Chk[v-1][0] == 0) //????????????node?????´???
        Chk[v-1][0] = search_time++;
    else {                //??¢??\???node?????´???
    //    search_time++;
        return;
    }

    //v???????????¢?´¢
    for (i = 1; i <= num_node; i++) {
        if (Adj[v-1][i -1] == 1) {
            dfs(i, num_node);
        }
    }

    //?????±??¨?????§??¢?´¢??????????????????
    //v???????????????????¨????
    Chk[v-1][1] = search_time++;
}

Measured memory_bytes: 3124
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll v[555];

int main(void){
	ll x,i,j;
	for(i=0; i<=500; ++i){
		x = i-250;
		v[i] = x*x*x*x*x;
	}
	std::cin >> x;
	for(i=0; i<=500; ++i){
		for(j=0; j<=500; ++j){
			if(v[i]-v[j]==x){
				std::cout << i-250 << " " << j-250 << " " << std::endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3572
A, B, C, D = map(int, input().split())

bool = True
while A > 0 and C > 0:
    C -= B
    if C <= 0:
        bool = True
        break
    A -= D
    if A <= 0:
        bool = False
        break

if bool:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_N 400050
int n,k;
int r[MAX_N+1],r2[MAX_N+1];
int t[MAX_N+1];
bool compare_sa(int i,int j){
  if(r[i]!=r[j]) return r[i]<r[j];
  else{
    int ri=i+k<=n?r[i+k]:-1;
    int rj=j+k<=n?r[j+k]:-1;
    return ri<rj;
  }
}
void constract_sa(const string &S, int *sa){
  n=S.length();
  for(int i=0;i<=n;i++){
    sa[i]=i;
    r[i]=i<n?S[i]:-1;
  }
  for(k=1;k<=n;k*=2){
    sort(sa,sa+n+1,compare_sa);
    t[sa[0]]=0;
    for(int i=0;i<=n;i++){
      t[sa[i]]=t[sa[i-1]]+(compare_sa(sa[i-1],sa[i])?1:0);
    }
    for(int i=0;i<=n;i++){
      r[i]=t[i];
    }
  }
}
int contains(const string &S,int *sa,string T){
  int a=0,b=S.length();
  while(b-a>1){
    int c=(a+b)/2;
    if(S.compare(sa[c],T.length(),T)<0) a=c;
    else b=c;
  }
  return S.compare(sa[b],T.length(),T)==0?b:-1;
}
int contains2(const string &S,int *sa,string T){
  int a=0,b=S.length()+1;
  while(b-a>1){
    int c=(a+b)/2;
    if(S.compare(sa[c],T.length(),T)<=0) a=c;
    else b=c;
  }
  return S.compare(sa[a],T.length(),T)==0?a:-1;
}

int N,dat[2][2*MAX_N-1];
void init(int n_){
  N=1;
  while(N<n_) N*=2;
  for(int i=0;i<2*N-1;i++) {
    dat[0][i]=INT_MAX;
    dat[1][i]=INT_MIN;
  }
}
void update(int k,int a){
  k+=N-1;
  dat[0][k]=dat[1][k]=a;
  while(k>0){
    k=(k-1)/2;
    dat[0][k]=min(dat[0][k*2+1],dat[0][k*2+2]);
    dat[1][k]=max(dat[1][k*2+1],dat[1][k*2+2]);
  }
}
int query(int a,int b,int k,int l,int r,int f){
  if(r<=a||b<=l) return f?INT_MIN:INT_MAX;
  if(a<=l&&r<=b) return dat[f][k];
  else{
    int vl=query(a,b,k*2+1,l,(l+r)/2,f);
    int vr=query(a,b,k*2+2,(l+r)/2,r,f);
    return f?max(vl,vr):min(vl,vr);
  }
}

int main(){
  string S;
  int sa[MAX_N+1],m;
  cin>>S>>m;
  constract_sa(S,sa);
  init(n+1);
  for(int i=0;i<=(int)S.size();i++){
    update(i,sa[i]);
    //cout<<i<<":"<<sa[i]<<endl;
  }
  for(int i=0;i<m;i++){
    string x,y;cin>>x>>y;
    int lx=contains(S,sa,x),rx=contains2(S,sa,x);
    int ly=contains(S,sa,y),ry=contains2(S,sa,y);
    int ans;
    //cout<<lx<<" "<<rx<<endl<<ly<<" "<<ry<<endl<<query(ly,ry+1,0,0,N,1)<<":"<<query(lx,rx+1,0,0,N,0)<<endl;
    if(lx<0||ly<0) ans=0;
    else{
      int a=query(ly,ry+1,0,0,N,1),b=query(lx,rx+1,0,0,N,0);
      if(b+(int)x.size()>a+(int)y.size()) ans=0;
      else ans=a-b+y.size();
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 9760
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
	int n, ex = 1;
	cin >> n;
	while (true) {
		ex *= 2;
		if (ex > n) {
			ex /= 2;
			break;
		}
	}
	
	cout << ex << endl;
	return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

int main() {
	while (true) {
		ll w, h;
		cin >> w >> h;
		if (w == 0 && h == 0) return 0;
		map<P, set<P>> graph;
		rep(i, h - 1) {
			rep(j, w - 1) {
				int b;
				cin >> b;
				if (!b) {
					graph[{j, i}].insert({ j + 1,i });
					graph[{j + 1, i}].insert({ j ,i });
				}	
			}
			rep(j, w) {
				int b;
				cin >> b;
				if (!b) {
					graph[{j, i}].insert({ j ,i + 1 });
					graph[{j, i + 1}].insert({ j ,i });
				}
			}
		}
		rep(j, w - 1) {
			int b;
			cin >> b;
			if (!b) {
				graph[{j, h - 1}].insert({ j + 1,h - 1 });
				graph[{j + 1, h - 1}].insert({ j ,h - 1 });
			}
		}
		vector<vector<ll>> dist(h, vector<ll>(w, INF));
		queue<t3> q;
		q.emplace(0, 0, 1);
		while (!q.empty()) {
			auto t = q.front(); q.pop();
			ll x, y, d;
			tie(x, y, d) = t;
			if (dist[y][x] <= d) {
				continue;
			}
			dist[y][x] = d;
			for (auto p : graph[{x, y}]) {
				if (dist[p.second][p.first] <= d + 1) {
					continue;
				}
				q.emplace(p.first, p.second, d + 1);
			}
		}
		if (dist[h - 1][w - 1] == INF) {
			cout << 0 << endl;

		}
		else {
			cout << dist[h - 1][w - 1] << endl;

		}
	}
	return 0;
}



Measured memory_bytes: 3376
using System;
using System.Linq;
using System.Collections.Generic;

public class Test
{
	public static void Main()
	{
        string[] line = Console.ReadLine().Split(' ');
        int[] nums = new int[line.Length];
        for(int i = 0 ; i < line.Length ; i++){
            nums[i] = int.Parse(line[i]);
        }
        Array.Sort(nums);

        Console.WriteLine(nums[nums.Length-1] - nums[0]);
    }                                                                                                                                   
}

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

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

  sort (a , a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; i++){
    if (i % 2 == 0){
      Alice += a[i];
    } else {
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
using namespace std;

int main(){

    long long n;
    cin >> n;

    long long a[5];
    long long trmin = 1e15;
    for(int i=0; i<5; i++){
        cin >> a[i];
        if(a[i] < trmin){
            trmin = a[i];
        }
    }

    cout << ( 5 + (n-1)/trmin);

    return 0;
}

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

int isPrime(int x) {
    long long i;
    if ( x < 2) return 0;
    else if (x == 2) return 1;
    if ( x % 2 == 0 ) return 0;
    for ( i = 3; i*i <= x; i+=2 ) {
        if ( x % i == 0 ) return 0;
    }
    return 1;
}

int main(){
    long long x;
    cin >> x;
    
    for(long long i=x; i<1000000; i++){
        if ( 1 == isPrime(i) ) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
const int max_n = 1e4;
ll a[max_n];
void solve(){
  ll ans = 0;
  for(int i=0 ; i<n ; i++){
    while(a[i]%2 == 0){
      ans++;
      a[i] /= 2;
    }
  }
  cout << ans << endl;
}
int main(){
  cin >> n;
  for(int i=0 ; i<n ; i++){
    cin >> a[i];
  }
  solve();
  return 0;
}


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A  = sc.nextInt();
        int B = sc.nextInt();
        if(A<10&&B<10)
        System.out.println(A*B);
        else
        System.out.println(-1);
    }
}

Measured memory_bytes: 22740