akhauriyash/Code-Regression huggingface dataset:
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;

int n, p[MAXN];

map <int, int> imam;

int k;

int main() {
	scanf("%d %d",&n,&k);
	REP(i, n) {
		scanf("%d",&p[i]);
		imam[p[i]] = 1;
	}

	imam[0] = 1;
	sort(p, p + n);
	bool ok = 0;
	REP(i, n) if (imam[k - p[i]]) ok = 1;
	if (p[n - 1] >= k && ok) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define PB push_back
#define MP make_pair

typedef pair<int, int> PII;

int n;
int c[10000];


int solve(int l) {
	int r = l + 1, res = n;

	while (l >= 0 && r < n) {
		int color = c[l];
		int count = 0;
		for (; l >= 0 && c[l] == color; l--, count++);
		for (; r < n && c[r] == color; r++, count++);

		if (count < 4) break;
		res -= count;
	}
	return res;
}

int main() {
	while (true) {
		int ans;
		cin >> n;
		if (n == 0) break;

		REP(i, n) scanf("%d", &c[i]);

		ans = n;
		REP(i, n) {
			int tmp = c[i];
			REP(j, 3) {
				c[i] = j + 1;
				ans = min(ans, solve(i));
			}
			c[i] = tmp;
		}

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

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int dp[105][5][2];

int main(){
    string s;
    cin >> s;
    int K;
    cin >> K;
    int n = s.size();

    dp[0][0][0] = 1;

    rep(i, n){
        int nd = s[i]-'0';
        rep(j, 4) rep(k, 2){
            rep(d, 10){
                int ni=i+1, nj=j, nk=k;
                if(d!=0) nj++;
                if(nj>K) continue;
                if(k==0){
                    if(d > nd) continue;
                    if(d < nd) nk = 1;
                }
                dp[ni][nj][nk] += dp[i][j][k];
            }
        }
    }

    cout << dp[n][K][0] + dp[n][K][1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i<int(n); i++)
using V = vector<int>;
using VV = vector<V>;
const int MOD = 998244353;

int main() {
  int N, S; cin >> N >> S;
  V a(N);
  rep(i, N) cin >> a[i];

  V dp(S+1);
  int ans = 0;
  rep(r, N) {
    for (int s = S; s >= 0; --s) {
      if (s >= a[r]) dp[s] += dp[s-a[r]];
      if (s == a[r] || s == 0) ++dp[s];
      dp[s] %= MOD;
    }
    (ans += dp[S]) %= MOD;
  }
  cout << ans << endl;
  return 0;
}


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

using cat = long long;

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N;
	cin >> N;
	cat mod = 998244353;
	vector<cat> pw(N+1, 1);
	for(int i = 0; i < 18; i++) pw[1] = pw[1] * 10 % mod;
	for(int i = 2; i <= N; i++) pw[i] = pw[i-1] * pw[1] % mod;
	vector<int> level[3];
	vector<cat> level_w[3];
	int V[3] = {0, 0, 0};
	for(int k = 0; k < 3; k++) {
		int M;
		vector< vector<int> > G(N);
		cin >> M;
		for(int i = 0; i < M; i++) {
			int u, v;
			cin >> u >> v;
			G[--u].push_back(--v);
			G[v].push_back(u);
		}
		level[k].resize(N, 0);
		for(int i = N-1; i >= 0; i--) {
			static vector<int> l_gt(N+1, 0);
			for(auto x : G[i]) if(x > i) l_gt[level[k][x]]++;
			while(l_gt[level[k][i]]) level[k][i]++;
			for(auto x : G[i]) if(x > i) l_gt[level[k][x]]--;
			V[k] = max(V[k], level[k][i]);
		}
		level_w[k].resize(V[k]+1, 0);
		for(int i = N-1; i >= 0; i--) {
			level_w[k][level[k][i]] += pw[i+1];
			if(level_w[k][level[k][i]] >= mod) level_w[k][level[k][i]] -= mod;
		}
	}
	vector< vector< vector<char> > > state(V[0]+1, vector< vector<char> >(V[1]+1, vector<char>(V[2]+1, 0)));
	vector< vector<char> > used[3];
	used[0].resize(V[1]+1, vector<char>(V[2]+1, 0));
	used[1].resize(V[0]+1, vector<char>(V[2]+1, 0));
	used[2].resize(V[0]+1, vector<char>(V[1]+1, 0));
	for(int i = 0; i <= V[0]; i++)
		for(int j = 0; j <= V[1]; j++)
			for(int k = 0; k <= V[2]; k++)
				if(!used[0][j][k] && !used[1][i][k] && !used[2][i][j])
					state[i][j][k] = used[0][j][k] = used[1][i][k] = used[2][i][j] = 1;
	cat ans = 0;
	for(int i = 0; i <= V[0]; i++)
		for(int j = 0; j <= V[1]; j++)
			for(int k = 0; k <= V[2]; k++)
				if(state[i][j][k])
					ans = (ans + level_w[0][i] * level_w[1][j] % mod * level_w[2][k]) % mod;
	cout << ans << "\n";
}


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

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

    for(int i=0; i<k; i++){
        int ma = max({a,b,c});
        if(ma == a) a*=2;

        else if(ma == b) b *= 2;

        else c *= 2;
    }

    cout<<a+b+c<<endl;

    return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  vector<int> vn(3);
  for (int i = 0; i < 3; ++i) {
    cin >> vn[i];
  }

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

  if (vn[0] == 5 && vn[1] == 5 && vn[2] == 7) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
  return 0;
}

Measured memory_bytes: 3592
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
# print(A)
B = []
for i in range(N):
    heapq.heappush(B,-A[i])
# print(B)
for i in range(M):
    x = -heapq.heappop(B)
    if x == 0:
      break
    x = x//2
    heapq.heappush(B,-x)

# print(B)
print(-sum(B))

Measured memory_bytes: 14180
#include <iostream>
#include <cstring>
using namespace std;
const long long INF = 1LL<<60;
#define MAX_N 110
#define MAX_V 100010
int N, W;
long long w[MAX_N], v[MAX_N];
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < MAX_V; j++) dp[i][j] = INF;
    }
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < MAX_V; j++) {
            if (j < v[i]) {
                dp[i+1][j] = dp[i][j];
            } else {
                dp[i+1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < MAX_V; i++) {
        if (dp[N][i] <= W) ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 80256
#include <iostream>

int main(){
    int right = 0, left = 0;
    int n;
    std::cin >> n;

    while(n--){
        char in;
        std::cin >> in;
        if('(' == in){
            int num;
            std::cin >> num;
            //if(right == 0) left += num;
            //else if(right < num){
              //  num -= right;
                //right = 0;
                //left += num;
            //}
            //else right -= num;
            left += num;
        }
        
        if(')' == in){
            int num;
            std::cin >> num;
            if(left == 0) right += num;
            else if(left < num){
                num -= left;
                left = 0;
                right += num;
            }
            else left -= num;
        }
    }
    
    if(right == 0 && left == 0) std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    char A[110],B[110]; cin >> A >> B;
    string res = "EQUAL";
    
    if(strlen(A) > strlen(B)){
        res = "GREATER";
    }else if(strlen(A) < strlen(B)){
        res = "LESS";
    }
    
    else{
        rep(i,strlen(A)){
            if(A[i]==B[i]){
                continue;
            }else if(A[i]>B[i]){
                res = "GREATER";
                break;
            }else if(A[i]<B[i]){
                res = "LESS";
                break;
            }
        } 
    }
    pr(res);
}


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

int main(){
	int n;
	int x[210][2];
	for(;cin>>n,n;){
		x[0][0]=x[0][1]=0;
		int nn,d;
		for(int i=1;i<n;i++){
			cin>>nn>>d;
			x[i][0]=x[nn][0]+(d==0?1:d==2?-1:0);
			x[i][1]=x[nn][1]+(d==1?1:d==3?-1:0);
		}
		int max,min;
		max=min=0;
		for(int i=0;i<n;i++){
			if(max<x[i][0])max=x[i][0];
			if(min>x[i][0])min=x[i][0];
		}
		cout<<max-min+1<<" ";
		max=min=0;
		for(int i=0;i<n;i++){
			if(max<x[i][1])max=x[i][1];
			if(min>x[i][1])min=x[i][1];
		}
		cout<<max-min+1<<"\n";
	}
}

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

bool isprime(ll a)
{
	ll count=0;
	for(int i=1;i*i<=a;i++)
	{
		if(a%i==0)count+=2;
		if(i*i==a)count--;
	}
	
	if(count==2)return true;
	else
	return false;
	
}


vector<ll>d(151,0);
ll digitsum(ll n)
{
	ll s=0;
		while(n>0)
		{
			s+=n%10;
			n=n/10;
		}
		return s;
		
	
}
void solve()
{
	
 ll n,q;
 cin>>n;
 ll sum=0;
 map<ll,ll>m;
 for(int i=0,a;i<n;i++)
 {
 	cin>>a;
 	sum+=a;
 	m[a]++;
 }
 
 cin>>q;
 for(ll i=0,b,c;i<q;i++)
 {
 	
	 	cin>>b>>c;
	 	//for(auto x:m)cout<<x.first<<" "<<x.second<<"\n";
	 	sum+=m[b]*c-m[b]*b; 
 		m[c]+=m[b];
	 	m[b]=0;
 		
 		
 		
 		cout<<sum<<"\n";		
 	
 	
 }
 
 

 
 
	
	

}




int main()
{


ios::sync_with_stdio(0); 
	cin.tie(0);

		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 9520
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <map>

using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)
LL dp[35];
int main(){
	int n;
	dp[0] = 1;
	for(int i=1;i<=30;i++){
		for(int j=1;j<=min(3,i);j++){
			dp[i] += dp[i-j];
		}
	}
	while(cin >> n){
		if(n==0)break;
		cout << ((dp[n]/3650)  + (dp[n]%3650 == 0 ?0:1)  )<< endl;
	}
	return 0;
}

Measured memory_bytes: 3080
def solve(n, a, b, c, d):
    if d == 0:
        return a == b
    t = n - 1
    ab = abs(a - b)
    if ab > d * t:
        return False
    return (ab - c * t) % (c + d) <= (d - c) * t


print('YES' if solve(*map(int, input().split())) else 'NO')


Measured memory_bytes: 2940
Scanf.scanf "%d %d %d" (fun n m q ->
    let abcd = Array.init q (fun _ ->
        Scanf.scanf " %d %d %d %d" (fun a b c d -> a - 1, b - 1, c, d))
    in
    let check hist =
        let arr = Array.of_list hist in
        Array.fold_left (fun acc (a, b, c, d) ->
            if arr.(b) -  arr.(a) = c then acc + d else acc) 0 abcd
    in
    let rec take r cur hist acc =
        if r = 0 then max acc (check hist) else
            if cur = 0 then acc else
                let acc = take r (cur - 1) hist acc in
                take (r - 1) cur (cur :: hist) acc
    in
    take n m [] 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 5856
#include <bits/stdc++.h>
using namespace std; 
#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int col[10];
int color(int r){
	if(r >= 1 && r <= 399){
		return 0;
	}else if(r >= 400 && r <= 799){
		return 1;
	}else if(r >= 800 && r <= 1199){
		return 2;
	}else if(r >= 1200 && r <= 1599){
		return 3;
	}else if(r >= 1600 && r <= 1999){
		return 4;
	}else if(r >= 2000 && r <= 2399){
		return 5;
	}else if(r >= 2400 && r <= 2799){
		return 6;
	}else if(r >= 2800 && r <= 3199){
		return 7;
	}else{
		return 8;
	}
}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	vector<int> a;
	cin >> n;

	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.pb(t);
	}

	for(int i=0; i<n; i++){
		col[color(a[i])]++;
	}

	int mi = 0;
	int rem = 0;
	int ma = 0;
	for(int i=0; i<8; i++){
		if(col[i] > 0){
			mi++;
		}else{
			rem++;
		}
	}

	ma = mi;
	if(col[8] > 0){
		//ma = mi + min(rem, col[8]);
		ma = mi + col[8];
	}
	if(col[8] > 0 && mi == 0){
		mi++;
	}

	cout << mi << ' ' << ma << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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



		int ansTop = sc.nextInt();
		int ansSouth = sc.nextInt();
		int ansEast = sc.nextInt();
		int ansWest = sc.nextInt();
		int ansNorth = sc.nextInt();
		int ansBottom = sc.nextInt();

		if(ansTop == dice.south || ansTop == dice.north || ansTop == dice.bottom) {
			while(ansTop != dice.top) {
				dice.goNorth();
			}
			while(ansBottom != dice.bottom) {
				dice.goNorth();
			}
		} else if(ansTop == dice.west || ansTop == dice.east) {
			while(ansTop != dice.top) {
				dice.goEast();
			}
		}

		if(ansSouth == dice.east || ansSouth == dice.west || ansSouth == dice.north ) {
			while(ansSouth != dice.south) {
				dice.spin();
			}
		}

		if(ansEast == dice.east && ansWest == dice.west && ansNorth == dice.north && ansBottom == dice.bottom) {
			System.out.println("Yes");
		}  else {
			System.out.println("No");
		}




	}

	int top;
	int south;
	int east;
	int west;
	int north;
	int bottom;


	public Main(Scanner sc) {
		this.top = sc.nextInt();
		this.south = sc.nextInt();
		this.east = sc.nextInt();
		this.west = sc.nextInt();
		this.north = sc.nextInt();
		this.bottom = sc.nextInt();
	}

	public void goNorth() {
		int t = this.top;
		int s = this.south;
		int e = this.east;
		int w = this.west;
		int n = this.north;
		int b = this.bottom;

		this.top = s;
		this.south = b;
		this.north = t;
		this.bottom = n;
	}

	public void goSouth() {
		int t = this.top;
		int s = this.south;
		int e = this.east;
		int w = this.west;
		int n = this.north;
		int b = this.bottom;

		this.top = n;
		this.south = t;
		this.north = b;
		this.bottom = s;
	}

	public void goEast() {
		int t = this.top;
		int s = this.south;
		int e = this.east;
		int w = this.west;
		int n = this.north;
		int b = this.bottom;

		this.top = w;
		this.east = t;
		this.west = b;
		this.bottom = e;
	}

	public void goWest() {
		int t = this.top;
		int s = this.south;
		int e = this.east;
		int w = this.west;
		int n = this.north;
		int b = this.bottom;

		this.top = e;
		this.east = b;
		this.west = t;
		this.bottom = w;
	}

	public void spin() {
		int t = this.top;
		int s = this.south;
		int e = this.east;
		int w = this.west;
		int n = this.north;
		int b = this.bottom;


		this.south = w;
		this.east = s;
		this.west = n;
		this.north = e;


	}


	public int getTop() {
		return this.top;
	}

	public int getEast() {
		return this.east;
	}
}

Measured memory_bytes: 26408
<?php
fscanf(STDIN, '%d %d', $n, $q);
fscanf(STDIN, '%s', $s);
$cnt[0] = 0;
for ($i = 0; $i < $n; $i++) {
    if ($s[$i] === 'A' && ($s[$i + 1] ?? '') === 'C') $cnt[$i + 1] = $cnt[$i] + 1;
    else $cnt[$i + 1] = $cnt[$i];
}
for ($i  = 0; $i < $q; $i++) {
    fscanf(STDIN, '%d %d', $l, $r);
    echo ($cnt[$r - 1] - $cnt[$l - 1]) . PHP_EOL;
}

Measured memory_bytes: 10744
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF=100000001,ID_MAX=20;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}
//x^n mod m (nが負の時は０)
long myPow(long x, long n, long m){
    if(n<0)return 0;
    long ans=1,l=n,y=x;
    while(l>0){
        if(l % 2 == 0){
            y=(y*y)%m;
            l=l/2;
        }else{
            ans=(ans*y)%m;
            l=l-1;
        }
    }
    return ans;
}

const int N_MAX=101,W_MAX=10001;
int v[N_MAX]={0},w[W_MAX]={0},N,W,dp[N_MAX][W_MAX]={0};

int main(){
    int i;
    //入力
    cin>>N>>W;
    rep(i,N){
        cin>>v[i+1]>>w[i+1];
    }
    //処理
    for(int i=1;i<=N;i++){
        for(int j=1;j<=W;j++){
            if(j>=w[i])dp[i][j]=max(dp[i-1][j],dp[i][j-w[i]]+v[i]);
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    //出力
    cout<<dp[N][W]<<endl;
}


Measured memory_bytes: 7004
#include <stdio.h>
long long t[2], a[2], b[2];
long long w, x, y, z, e, f;
long long ans;
int main() {
	scanf("%lld%lld", t, t + 1);
	scanf("%lld%lld", a, a + 1);
	scanf("%lld%lld", b, b + 1);
	if (t[0] * a[0] + t[1] * a[1] == t[0] * b[0] + t[1] * b[1]) {
		printf("infinity\n");
		return 0;
	}
	x = t[0]; y = t[1];
	if (t[0] * a[0] + t[1] * a[1] > t[0] * b[0] + t[1] * b[1]) {
		w = b[0] - a[0];
		z = b[1] - a[1];
	}
	else {
		w = a[0] - b[0];
		z = a[1] - b[1];
	}
	if (w < 0) {
		printf("0\n");
		return 0;
	}
	e = w * x + z * y;
	f = w * x;
	e = -e;
	ans = f / e * 2;
	if (f % e)ans++;
	printf("%lld\n", ans);
	if (z > 0)printf("wa\n");
}

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

using namespace std;

const int N = 100001;
long long a[N];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] + a[i - 1] > x) {
            ans += (a[i] + a[i - 1]) - x;
            a[i] = max(0LL, a[i] - ((a[i] + a[i - 1]) - x));
        }
    }
    cout << ans;
    return 0;
}


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

int AskLCS(string s1,string s2){
    int m[s1.size()+1][s2.size()+1];
    int res = 0;
    for(int i = 0;i <= s2.size();++i) m[0][i] = 0;
    for(int i = 0;i <= s1.size();++i) m[i][0] = 0;
    for(int i = 1;i <= s1.size();++i){
        for(int j = 1;j <= s2.size();++j){
            if(s1[i-1] == s2[j-1]){
                m[i][j] = m[i-1][j-1] + 1;
            } else{
                m[i][j] = max(m[i][j-1],m[i-1][j]);
            }
            res = max(m[i][j],res);
        }
    }
    return res;
}
int main(){
    string X,Y;
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n;++i){
        cin >> X;
        cin >> Y;
        printf("%d\n",AskLCS(X,Y));
    }

}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll m,n1,n2;
  while(cin >> m >> n1 >> n2 && m+n1+n2){
    vector<ll> v(m);
    rep(i,m){
      cin >> v[i];
    }
    sort(all(v));
    ll gapM = -1,ans = 0;
    REP(i,n1,n2+1){
      if(gapM <= v[m-i] - v[m-i-1]){
        gapM = v[m-i] - v[m-i-1];
        ans = i;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int ans[100050];
int main(){
//	freopen("input.txt","r",stdin);
	int n;
	scanf("%d",&n);
	memset(ans,0,sizeof(ans));
	for(int i=1;i<=n;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		for(int j=l;j<=r;j++) ans[j]++;
	}
	int re=0;
	for(int i=1;i<=100000;i++) re+=ans[i];
	printf("%d\n",re);
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
 
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int n = sc.nextInt();
		int[] a = new int[n];
		int t = 0;
		
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
			t += a[i];
		}
		
		if((h-t)<=0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
 
		sc.close();
	}
}

Measured memory_bytes: 50888
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		long x = sc.nextLong();
		long y = sc.nextLong();
		System.out.println(Math.min(n, k) * x + Math.max(n - k, 0) * y);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	int a,b;
	cin>>a>>b;
	if(b%a==0) {
		cout<<a+b<<endl;
	}
	else {
		cout<<b-a<<endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
long double f(const long double all, const int mono, const int di, const int tri, std::vector<std::vector<std::vector<long double>>>& memo) {
	if (mono < 0 || di < 0 || tri < 0) return 0;
	if (memo[mono][di][tri] >= 0) return memo[mono][di][tri];
	return memo[mono][di][tri] = all / (mono + di + tri) + (mono  * f(all, mono - 1, di, tri, memo) + di * f(all, mono + 1, di - 1, tri, memo) + tri * f(all, mono, di + 1, tri - 1, memo)) / (mono + di + tri);
}
int main() {
	int n; std::cin >> n;
	int mono = 0, di = 0, tri = 0;
	for (auto i = 0; i < n; ++i) {
		int a; std::cin >> a;
		switch (a) {
		case 1: ++mono; break;
		case 2: ++di; break;
		case 3: ++tri; break;
		default: throw "?";
		}
	}
	std::vector<std::vector<std::vector<long double>>> memo(n + 1, std::vector<std::vector<long double>>(n + 1, std::vector<long double>(tri + 1, -1)));
	memo[0][0][0] = 0;
	std::cout << std::setprecision(15) << std::fixed << f(n, mono, di, tri, memo) << std::endl;
}

Measured memory_bytes: 431488
#include <stdio.h>
int main(void) {
	int R, B, W, G;
	scanf("%d", &R);
	scanf("%d", &B);
	scanf("%d", &W);
	scanf("%d", &G);
	R = R + B + W + G;
	printf("%d\n", R);
	return 0;
}


Measured memory_bytes: 2700
N, M = map(int, input().split())
T = (N - M) * 100 + M * 1900
Y = (0.5)**M
Z = 1
X = 0
for i in range(1000):
    X += T * (i + 1) * Z * Y
    Z *= 1 - Y
if X - int(X) < 0.5:
    print(int(X))
else:
    print(int(X) + 1)

Measured memory_bytes: 38256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void)
{
  int hour_long, minute_long;
  int hour, minute;
  long double deg_hour, deg_minute;
  long double theta;
  long double theta_rad;
  
  cin >> hour_long >> minute_long >> hour >> minute;
  deg_hour = 30.0 * ((long double)hour + ((long double)minute / 60)) ;
  deg_minute = 6 * (long double)minute;
  theta = (long double)abs(deg_hour - deg_minute);
  theta_rad = (PI / 180)*theta;
  
  long double dist = sqrt(hour_long*hour_long + minute_long*minute_long
                     - 2.0*hour_long*minute_long*cos(theta_rad));
  
  cout << setprecision(20);
  cout << dist << endl;
}


Measured memory_bytes: 4116
import math
n=int(input())
a=[int(x) for x in input().split()]
a_log=[]
if 0 not in a:
  for i in a:
    i_log=math.log10(i)
    a_log.append(i_log)
  
  if sum(a_log)>18:
    print("-1")
  else:
    for i in range(n-1):
  	  a[i+1]*=a[i]
    if a[n-1]>10**18:
      print("-1")
    else:
      print(a[n-1])
else:
  print("0")

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

int main() {
    int A, B;
    cin>>A>>B;
    /**
    int AA = 100*A/8;
    int BB = 10*B;
    if(AA<BB)cout<<BB<<endl;
    else cout<<AA<<endl;
    **/
    long ans1=-1;
    for(long ans=0;ans<100000;++ans){
        if((floor(ans*0.08)==A) & (floor(ans*0.1)==B)){
            ans1 = ans;
            break;
        }
    }
    cout<<ans1<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MAX 500002
int main()
{
    int k,i,j,q;
    scanf("%d %d",&k,&q);
    int d[k];
    long long int temp[k+1];
    for(i=0;i<k;i++)
    {
        scanf("%d",&d[i]);
    }
    for(j=0;j<q;j++)
    {
        int n,x,m;
        scanf("%d %d %d",&n,&x,&m);
        temp[0]=x%m;
        int rem=(n-1)%k;
        int zrem=0,total=0;
        int division=(n-1)/k;
        for(i=1;i<=k;i++)
        {
            temp[i]=d[i-1]%m;
            if(temp[i]==0)
            {
                total++;
                zrem=zrem+(i<=rem);
            }
            temp[i]=temp[i]+temp[i-1];
        }
        long long int ans=total;
        ans=ans*division;
        ans=ans+zrem;
        long long int dd=(temp[k]-temp[0])*division+temp[rem];
        dd=dd/m;
        ans=ans+dd;
        ans=n-1-ans;
        printf("%lld\n",ans);
    }
    return 0;
}


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

int main(void){
    string s; cin >> s;
    string out = "Yes";
  
    for(int i = 0; i < s.size(); i++){
        char c = s.at(i);
      	
      	if(i % 2 == 0){
          if(c == 'L'){
            out = "No";
            break;
          }
        }else if(i % 2 != 0){
          if(c == 'R'){
            out = "No";
            break;
          }
        }
    }
    
    cout << out << endl;
    return 0;
}




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

int main(){
  string s, ans;
  cin >> s;
  ans = "Yes";
  for(int i = 0; i < s.length(); i++) {
    if(i % 2 == 0) {
      if(s.at(i) == 'L'){
        ans = "No";
        break;
      }
    }
    else {
      if(s.at(i) == 'R') {
        ans = "No";
        break;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#include<stdlib.h>

#include<string.h>


int main(void){char num_str[1002];int num;long sum =0;int i;char tmp;
while(1){fgets(num_str,sizeof(num_str),stdin);
if(num_str[0]=='0') break;
for(i=0;i<strlen(num_str)-1;i++){tmp = num_str[i];num = atoi(&tmp);sum = sum + num;}
printf("%ld\n",sum);
sum = 0;memset(num_str,1002,0);}return 0;}

Measured memory_bytes: 960
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int n;
vector<vector<int>> g;
vector<int> color;

bool dfs(int v, int c) {   // 2部グラフ判定 頂点iの色(1 or -1)
    color[v] = c;   // 頂点vをcで塗る
    rep(i,n) if(g[v][i]==1) {
        if (color[i] == c) return false;                // 隣接している頂点が同じ色ならfalse
        if (color[i] == 0 && !dfs(i, -c)) return false; // 隣接している頂点がまだ塗られていないなら-cで塗る
    }
    return true;    // すべての頂点を塗れたらtrue
}

int main() {
    cin >> n;
    g = vector<vector<int>>(n,vector<int>(n, INF));
    rep(i,n) {
        string s;
        cin >> s;
        rep(j,n) {
            if (s[j] == '1') g[i][j] = 1;
            else if (i==j)   g[i][j] = 0;
        }
    }
    rep(k,n) rep(i,n) rep(j,n) {    // warshall_floyd
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
    }
    int ans = -1;
    rep(i,n) rep(j,n) ans = max(ans, g[i][j]+1);

    color = vector<int>(n);
    if (!dfs(0,1)) ans = -1;    // 2部グラフでなければ-1
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
import numpy as np


def solve():
    n = 10**5+1
    like = np.zeros(n, dtype='uint64')
    like[2] = 0

    p = [True] * (n)
    p[0] = False
    p[1] = False
    for i in range(4, n, 2):
        p[i] = False

    for j in range(3, n, 2):
        q = (j+1)//2
        if p[j]:
            for k in range(j*2, n, j):
                p[k] = False
            if p[q]:
                like[j] = 1
            else:
                like[j] = 0
        else:
            like[j] = 0

    return np.cumsum(like)


if __name__ == '__main__':
    q = int(input())
    accum = solve()
    for l in range(q):
        l, r = map(int, input().split())
        print(accum[r]-accum[l-1])


Measured memory_bytes: 14796
n = int(input())
listH = list(map(int, input().split()))

for i in range(0, n-1):
    if(listH[i+1] - listH[i] == -1):
        listH[i+1] += 1
    if(listH[i+1] - listH[i] < -1):
        print("No")
        quit()


print("Yes")

Measured memory_bytes: 63984
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0; cin>>n;
    vector<string> s(3);
    rep(i,3) cin>>s[i];
    rep(i,n){
        int cnt=0;
        rep(j,3)if(s[j%3][i]==s[(j+1)%3][i]) cnt++;
        if(cnt==0) ans+=2;
        else if(cnt==1) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include <string>
#include <iostream>
#include <set>
 
using namespace std;
 
// 文字列一つ受け取る場合
// string s;
// 整数(max 2^31-1 or 10^9)一つ受け取る場合
// int x;
long long int k;
long long int n;
set<long long int> a;
 
int main(){
    cin >> n;
    cin >> k;
    a.insert(n);
    long long int prev;
    prev = n;
    long long int minn;
    minn = n;
    while(true){
        if(prev>k){
            prev = (prev-k)%k;
        }else{
            prev = abs(prev-k);
        }
        minn = min(minn, prev);
        if(a.find(prev)!=a.end()){
            break;
        }
        a.insert(prev);
    }

    cout << minn;
  
}

//containsを作っておく

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int H, W;
    while (1){
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0){
            break;
        }
        else{
            char S[H][W];
            int i, j;
            for (i = 0; i < H; i++){
                for (j = 0; j < W; j++){
                    if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)){
                        S[i][j] = '#';
                    }
                    else{
                        S[i][j] = '.';
                    }
                    printf("%c", S[i][j]);
                }
                printf("\n");
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 592
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

vector<int> g[10000];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  sort(c.begin(), c.end());
  int sum = 0;
  for (int i = 0; i < n - 1; ++i) {
    sum += c[i];
  }
  vector<int> ans(n, -1);
  queue<int> que;
  que.push(0);
  ans[0] = c.back();
  c.pop_back();
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (auto u : g[v]) {
      if (ans[u] == -1) {
        que.push(u);
        ans[u] = c.back();
        c.pop_back();
      }
    }
  }
  cout << sum << endl;
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << (i == n - 1 ? '\n' : ' ');
  }
  return 0;
}

Measured memory_bytes: 1024
var
	N,i,t,x,y,d,nx,ny,nt:Longint;
begin
	read(N);
	for i:=1 to N do begin
		read(t,x,y);
		d:=0;
		if x>nx then inc(d,x-nx)else inc(d,nx-x);
		if y>ny then inc(d,y-ny)else inc(d,ny-y);
		if(d mod 2<>(t-nt)mod 2)or(d>t-nt)then begin
			writeln('No');
			exit;
		end;
		nt:=t;
		nx:=x;
		ny:=y;
	end;
	writeln('Yes');
end.


Measured memory_bytes: 128
fun main(args: Array<String>) {
    while (true) {
        val x = readLine()!!
        val digits = x.length
        if (x == "0") break

        var sum = 0
        for (i in 0 until digits) {
            val number: Int = x.substring(i, i + 1).toInt()
            sum += number
        }
        println(sum)

    }
}


Measured memory_bytes: 26840
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int main(){
    

    string s;
    vector<int>black;
    vector<int>white;

    cin >> s;
    int ans=0;
    char c;
    c=s[0];

    for(int i=1;i<s.size();i++){
        if(s[i]==c){
            continue;
        }
        else{
            ans++;
            c=s[i];
        }
    }
   cout <<ans <<endl;

 return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
inline ulint getAns(ulint a, ulint b) {
	ulint res = a - 1;
	a -= res, b -= res;
	++res, --b;
	return res += (b - a) / 2;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	ulint n, a, b;
	cin >> n >> a >> b;
	if ((b - a) & 1) {
		ulint res = getAns(a, b);
		res = min(res, getAns(n - b + 1, n - a + 1));
		cout << res << endl;
	} else {
		cout << (b - a) / 2 << endl;
	}
	return 0;
}

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

bool isPrime(int x) {
    if(x == 2) return true;
    if(x < 2 || x % 2 == 0) return false;

    for(int i=3; i<=sqrt(x); i=i+2) {
        if(x % i == 0) return false;
    }
    return true;
}


int main() {
    vector<int> A;
    A.clear();
    for(int i=11; i<=55555 && A.size() < 55 ; i += 5) {
        if(isPrime(i)) A.push_back(i);
    }
    int N; cin >> N;
    for(int i=0; i<N; ++i) {
        cout << A[i];
        if(i+1<N) cout << " ";
        else cout << endl;
    }
}

Measured memory_bytes: 256
s=input()
n=len(s)
mod=10**9+7
dp=[0]*13
data=[0]*n
data[n-1]=1
for i in range(1,n):
    data[n-1-i]=data[n-i]*10%13
if s[0]=="?":
    for i in range(10):
        dp[i*data[0]%13]=1
else:
    dp[int(s[0])*data[0]%13]=1
for i in range(1,n):
    if s[i]=="?":
        h=[0]*13
        for j in range(1,10):
            c=data[i]*j
            for k in range(13):
                h[k]=(h[k]+dp[(k-c)%13])%mod
        for j in range(13):
            dp[j]=(dp[j]+h[j])%mod
    else:
        a=int(s[i])
        b=a*data[i]%13
        dp=dp[-b:]+dp[:-b]
print(dp[5])

Measured memory_bytes: 45804
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int main() {
  ll a,b;
  cin>>a>>b;
  
  cout<<a/__gcd(a,b)*b<<endl;
  
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int h,w,d;
  cin >> h >> w >> d;
  map<int,pii> mp;
  for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
    int a; cin >> a;
    mp[a]=pii(i,j);
  }
  vector<ll> s(1+h*w+d);
  for(int i=1;i<=h*w;i++){
    s[i+d]=s[i]+abs(mp[i+d].first-mp[i].first)+abs(mp[i+d].second-mp[i].second);
  }
  int q; cin >> q;
  vector<ll> ans(q);
  rep(i,q){
    int l,r; cin >> l >> r;
    ans[i]=s[r]-s[l];
  }
  rep(i,q) cout << ans[i] << endl;
}

Measured memory_bytes: 13824
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Scanner;

/**
 * https://arc090.contest.atcoder.jp/tasks/arc090_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Node[] nodes = new Node[N];
		for(int i=0; i<N; i++) nodes[i] = new Node(i);
		int M = sc.nextInt();
		for(int i=0; i<M; i++){
			int l = Integer.parseInt(sc.next())-1;
			int r = Integer.parseInt(sc.next())-1;
			int d = Integer.parseInt(sc.next());
			nodes[l].neighbor.put(nodes[r], d);
		}
		sc.close();
		List<Node> list = topologicalSort(nodes);
		
		String ans = "Yes";
		if(list.size() == N){
			for(Node n:list){
				if(n.x==-1){
					if(!dfs(n,0)){
						ans = "No";
						break;
					}		
				}
			}
		}else{
			ans = "No";
		}
		
		System.out.println(ans);
		
	}
	
	static boolean dfs(Node node, long current){
		node.x = current;
		for(Entry<Node, Integer> n:node.neighbor.entrySet()){
			Node nn = n.getKey();
			int d = n.getValue();
			if(nn.x!=-1){
				if(nn.x != current+d) return false;
			}else{
				if(!dfs(nn, current+d)){
					return false;
				}	
			}
		}
		return true;
	}
	
	static class Node{
		int id;
		long x = -1;
		Map<Node,Integer> neighbor = new HashMap<>();
		int color = -1;
		int status = -1;
		int inDegree = 0;
		Node(int id){
			this.id = id;
		}
	}
	
	static List<Node> topologicalSort(Node[] nodeList){
		List<Node> sortedList = new ArrayList<>();
		for(Node node:nodeList)
			for(Node n:node.neighbor.keySet())
				n.inDegree++;
		for(Node node:nodeList){
			if(node.status!=-1 || node.inDegree>0) continue;
			Queue<Node> que = new ArrayDeque<>();
			node.status=1;
			que.add(node);
			while(!que.isEmpty()){
				Node current = que.remove();
				sortedList.add(current);
				for(Node n:current.neighbor.keySet()){
					if(--n.inDegree==0 && n.status==-1){
						n.status=1;
						que.add(n);
					}
				}
			}
		}
		return sortedList;
	}

}

Measured memory_bytes: 115972
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	string s;
	cin >> s;
	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
		cout << "Bad" << endl;
	else
		cout << "Good" << endl; 




	return 0;
}

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

int power(int x, int y, int p)
{
    int res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

int32_t main(){
	string s;
	cin>>s;
	for(int i=0; i<s.size(); i++){
		if(s[i]==',') cout<<' ';
		else cout<<s[i];
	}
}


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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	for(int i = 0; i * 4 <= n; i++){
			if((n - i * 4) % 7 == 0){
					cout << "Yes" << endl;
					return 0;
			}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int s, w;
    cin >> s >> w;
    if (w >= s)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
    return 0;
}



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

int main(){
  char ch;

  while(1){
    scanf("%c", &ch);

    if( ch == '\n' ){
      break;
    }

    if( islower(ch) ){
      cout << (char)toupper(ch);
    }else if( isupper(ch) ){
      cout << (char)tolower(ch);
    }else{
      cout << ch;
    }
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 3156
fun main(args: Array<String>) {
    val list = mutableListOf<Int>()
    readLine()!!.forEach {
        if (acgt.contains(it)) list.add(if (list.isEmpty()) 1 else list.last() + 1) else list.add(0)
    }
    println(list.max())
}

val acgt = arrayOf('A', 'C', 'G', 'T')

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

int main() 
{
    int k, x;
    cin >> k >> x;
    rep(i,x-k+1,x+k)
    {
        if(i < -1000000 || i > 1000000)
            continue;
        cout << i << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define N (60000)
int pt[N];

int main() {
    for (int i = 2; i < N; i++) if (pt[i] == 0) {
        for (int j = i+i; j < N; j+=i) pt[j] = i;
    }
    int n;
    while (scanf("%d", &n) != EOF) {
        int lo = n-1, hi = n+1;
        while (pt[lo]) lo--;
        while (pt[hi]) hi++;
        printf("%d %d\n", lo, hi);
    }
    return 0;
}

Measured memory_bytes: 0
#!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input

try:
	while True:
		n=int(raw_input())
		if n==0: break
		r=0
		i=1
		while 1:
			n-=i
			i+=1
			if n<i: break
			if n%i==0: r+=1
		print(r)
except EOFError:
	pass

Measured memory_bytes: 6264
#include <iostream>
#include <string>
using namespace std;
int m,n,i,j,f[3009][3009];
string p,st1,st2;
void truyvet()
{
    if (m*n==0) return;
    if (st1[m-1]==st2[n-1])
    {
        p=st1[m-1]+p;
        m=m-1;
        n=n-1;
    } else if (f[m-1][n]==f[m][n]) m=m-1; else n=n-1;
    truyvet();
}
int main()
{

    cin>>st1;
    m=st1.size();
    cin>>st2;
    n=st2.size();
    f[i][0]=0;
    f[0][j]=0;
    for(i=0;i<=st1.size()-1;i++)
    {
        for (j=0;j<=st2.size()-1;j++)
        {
            if (st1[i]==st2[j]) f[i+1][j+1]=f[i][j]+1;
            if (st1[i]!=st2[j]) f[i+1][j+1]=max(f[i+1][j],f[i][j+1]);
        }

    }
    p="";
    truyvet();
    cout<<p;
    return 0;

}


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


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
#define maxn 100010
int n;
ll a,b,h[maxn];
bool test(ll mid){
	ll ans=0;
	for(int i=0;i<n;i++){
		int c=h[i]-mid*b;
		if(c>0){
			if(c%(a-b)==0)
				ans+=c/(a-b);
			else
				ans+=c/(a-b)+1;
		}
	}
	return ans<=mid;
}
int main(){
	scanf("%d%lld%lld",&n,&a,&b);
	ll maxh=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&h[i]);
		maxh=max(maxh,h[i]);
	}
	ll l=0,r=maxh/b+1;
	while(l<r){
		ll mid=(l+r)/2;
		if(test(mid))
			r=mid;
		else
			l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){

ll n;
cin>>n;

vector<ll>is(n);
for(int i = 0;i<n;i++){
     ll x;
     cin>>x;
     is.push_back(x);

}
ll m;
cin>>m;
ll cnt = 0;
for(int i = 0;i<m;i++){
    ll y;
    cin>>y;
    auto it = binary_search(is.begin(),is.end(),y);
    if(it){
        cnt++;
    }

}
cout<<cnt<<endl;





}



Measured memory_bytes: 4288