akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
long long N, A[5009], U[5009], V[5009], dp[5009][5009][2], dp2[5009][5009][2], VV[5009];
vector<int>X[5009]; bool used[5009];
 
void dfs2(int pos) {
	VV[pos] += 1;
	for (int i = 0; i < X[pos].size(); i++) {
		if (VV[X[pos][i]] >= 1) continue;
		dfs2(X[pos][i]);
		VV[pos] += VV[X[pos][i]];
	}
}
 
void dfs(int pos) {
	used[pos] = true; vector<int>Y;
	for (int i = 0; i < X[pos].size(); i++) {
		if (used[X[pos][i]] == true) continue;
		dfs(X[pos][i]);
		Y.push_back(X[pos][i]);
	}
 
	for (int i = 0; i <= Y.size(); i++) { for (int j = 0; j <= VV[pos]; j++) { dp2[i][j][0] = (1LL << 60); dp2[i][j][1] = (1LL << 60); } }
	if (A[pos] >= 1) dp2[0][0][0] =dp2[0][0][1]= A[pos]; else dp2[0][0][1] = A[pos];
 
	int S = 0;
	for (int i = 0; i < Y.size(); i++) {
		for (int j = 0; j <= S; j++) {
			if (dp2[i][j][0] != (1LL << 60)) {
				for (int l = 0; l <= VV[Y[i]]; l++) {
					dp2[i + 1][j + l][0] = min(dp2[i + 1][j + l][0], dp2[i][j][0] + dp[Y[i]][l][0]);
					dp2[i + 1][j + l][1] = min(dp2[i + 1][j + l][1], dp2[i][j][0] + dp[Y[i]][l][1]);
					if (dp[Y[i]][l][0] < (1LL << 58) || dp[Y[i]][l][1] < 0) {
						dp2[i + 1][j + l + 1][0] = min(dp2[i + 1][j + l + 1][0], dp2[i][j][0]);
					}
				}
			}
			if (dp2[i][j][1] != (1LL << 60)) {
				for (int l = 0; l <= VV[Y[i]]; l++) {
					dp2[i + 1][j + l][1] = min(dp2[i + 1][j + l][1], dp2[i][j][1] + dp[Y[i]][l][0]);
					dp2[i + 1][j + l][1] = min(dp2[i + 1][j + l][1], dp2[i][j][1] + dp[Y[i]][l][1]);
					if (dp[Y[i]][l][0] < (1LL << 58) || dp[Y[i]][l][1] < 0) {
						dp2[i + 1][j + l + 1][1] = min(dp2[i + 1][j + l + 1][1], dp2[i][j][1]);
					}
				}
			}
		}
		S += VV[Y[i]];
	}
	for (int i = 0; i <= VV[pos]; i++) {
		dp[pos][i][0] = dp2[Y.size()][i][0];
		dp[pos][i][1] = dp2[Y.size()][i][1];
	}
}
 
int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N - 1; i++) {
		cin >> U[i] >> V[i];
		X[U[i]].push_back(V[i]);
		X[V[i]].push_back(U[i]);
	}
	dfs2(1);
	for (int i = 1; i <= N; i++) { for (int j = 0; j <= N; j++) { dp[i][j][0] = (1LL << 60); dp[i][j][1] = (1LL << 60); } }
	dfs(1);
 
	int maxn = (1 << 30);
	for (int i = 0; i <= N; i++) {
		if (dp[1][i][0] < (1LL << 58) || dp[1][i][1] < 0) { maxn = min(maxn, i); }
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 784256
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
 
	public static void main(String[] args) {
		new Main();	
	}
 
	public Main() {
		new A().doIt();
	}
	class A{
		void cnt(int num,int a[]){
			if(num < 10)a[0]++;
			else if(num < 20)a[1]++;
			else if(num < 30)a[2]++;
			else if(num < 40)a[3]++;
			else if(num < 50)a[4]++;
			else if(num < 60)a[5]++;
			else a[6]++;
		}
		void doIt(){
			while(true){
				int n = Integer.parseInt(sc.next());
				if(n == 0)break;
				int a[] = new int [7];
				for(int i = 0;i < n;i++){
					int num = Integer.parseInt(sc.next());
					cnt(num,a);
				}
				for(int i = 0;i < 7;i++)System.out.println(a[i]);
			}
		}
	}
}

Measured memory_bytes: 101260
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=sc.nextInt();
        int b=sc.nextInt();
        
         if (b<a*n) {
             System.out.println(b);
         }else{
             System.out.println(n*a);
         }
      
    }
}

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

void solve(long long A, long long B){
    if (A == B) cout << "Draw" << '\n';
    else if (A == 1) cout << "Alice" << '\n';
    else if (B == 1) cout << "Bob" << '\n';
    else if (A < B) cout << "Bob" << '\n';
    else cout << "Alice" << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

int main()
{
    vector<int> v;
    int a = 3;
    for(int i = 0; i < 3; i++){
        int x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());

    if(v.at(0) == v.at(1)){
        a--;
    }
    if(v.at(1) == v.at(2)){
        a--;
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

const string L = "Left";
const string E = "Balanced";
const string R = "Right";

void solve(ll A, ll B, ll C, ll D) {
  auto l = A + B;
  auto r = C + D;
  cout << (l > r ? L : (l < r) ? R : E) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  ll D;
  cin >> D;
  solve(A, B, C, D);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	n-=2;
	int ans = n / (k - 1)+1;
	cout << ans << endl;
	return 0;
}

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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll n;
	cin >> n;
	ll ans = 1e18;
	
	for(ll i = 1; i*i <= n; i++) {
		if(n % i == 0) {
			ans = min(ans, n/i + i - 2);
		}
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n = 0;
    cin >> n;
    long A[1000];
    for(int i = 0; i < 1000; i++){
        A[i] = 0;
    }
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    int q = 0;
    cin >> q;
    for(int i = 0; i < q; i++){
        int b = 0, e = 0, c = 0;
        cin >> c >> b >> e ;
        long min = A[b];
        long max = A[b];
        if(c == 0){
            for(int j = b; j < e; j++){
                if(A[j] < min){
                    min = A[j];
                }
            }
            cout << min << endl;
        }
        else{
            for(int j = b; j < e; j++){
                if(A[j] > max){
                    max = A[j];
                }
            }
            cout << max << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

signed main(){
    int n, m;
    cin >> n >> m;
    vi p(n);
    rep(i, n){
        cin >> p[i];
        p[i]--;
    }
    
    UnionFind uni(n);
    rep(i, m){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uni.unite(x, y);
    }

    int ans = 0;
    rep(i, n){
        if(uni.same(i, p[i])) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5620
#include <iostream>
using namespace std;
int main(void){
    
    int temp=0,ans=0;
    int n,t;cin>>n>>t;
    int s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    if (n==1){
        cout<<t<<endl;
        return 0;
    }
        
    for(int i=1;i<n;i++){
        temp=s[i]-s[i-1];
        if(t>=temp){
        ans+=temp;
    }else{
        ans+=t;
    }
    }
    cout<<ans+t<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define MAX 2000005

int A[MAX];
int H = 0;;

void buildMaxHeap(int i) {
    int l,r,largest;
    l = 2*i;
    r = 2*i + 1;
    if ( l <= H && A[l] > A[i] ) largest = l;
    else largest = i;
    if ( r <= H && A[r] > A[largest] ) largest = r;

    swap(A[i], A[largest]);

    if ( largest != i ) buildMaxHeap( largest );
}

void Insert(int key) {
    H++;
    int temp = H;
    A[H] = key;
    while( temp/2 != 0 && A[temp/2] < A[temp] ) {
        swap(A[temp/2], A[temp]);
        temp = temp/2;
    }
}

int heapExtractMax() {
    int temp = A[1];
    swap(A[1], A[H]);
    H--;
    buildMaxHeap(1);
    return temp;
}

int main() {
    string str;
    int k;

    cin >> str;
    while( str != "end" ) {
        if ( str == "insert" ) {
            cin >> k;
            Insert(k);
        }
        else cout << heapExtractMax() << endl;
        cin >> str;
    }

    return 0;
}



Measured memory_bytes: 7068
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] buf = str.split(" ");
		int N= Integer.parseInt(buf[0]);
		int W= Integer.parseInt(buf[1]);
		int[] DP= new int[W+1];
		int v,w;
		
		int j;
		for(j=1;j<W+1;j++){
			DP[j]= -1;
		}
		int i;
		for(i=0;i<N;i++){
			str = br.readLine();
			buf = str.split(" ");
			v= Integer.parseInt(buf[0]);
			w= Integer.parseInt(buf[1]);
			for(j=W-w;j>=0;j--){
				if( DP[j]>=0 && DP[j]+v>DP[j+w] ){
					DP[j+w]= DP[j]+v;
				}
			}
		}
		
		int v_max=0;
		for(j=W;j>0;j--){
			if( v_max<DP[j] ){
				v_max= DP[j];
			}
		}
		System.out.println(v_max);
	}
}

Measured memory_bytes: 19548
#include<stdio.h>
#define M 100001
typedef struct tree{
  int p,l,r;
}t;
t T[M];

int main(void){
  int n,i,j,k,id,c,tmp,tmp2;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    T[i].p=T[i].l=T[i].r=-1;
  for(i=0;i<n;i++){
    scanf("%d %d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      T[c].p=id;
      if(j==0)
	T[id].l=c;
      else
	T[tmp].r=c;
      tmp=c;
    }
  }
  for(i=0;i<n;i++){
    id=0;
    k=0;
    tmp=T[i].p;
    tmp2=T[i].l;
    while(tmp!=-1){
      k++,tmp=T[tmp].p;
    }
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,k);
    if(T[i].p==-1)
      printf("root, [");
    else if(T[i].l!=-1)
      printf("internal node, [");
    else
      printf("leaf, [");
    while(tmp2!=-1){
      if(id==0){
	printf("%d",T[i].l);
	id=1;
      }
      else
	printf(", %d",tmp2);
      tmp2=T[tmp2].r;
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 1784
N, Y = [int(i) for i in input().split()]


def f(x, y, z):
    return 10000 * x + 5000 * y + 1000 * z


def b():
    for x in range(N + 1):
        for y in range(N + 1):
            z = N - x - y
            if z < 0:
                continue
            if f(x, y, z) == Y:
                print('{0} {1} {2}'.format(x, y, z))
                return
    print('-1 -1 -1')
    return


b()


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

typedef long long ll;
typedef vector<ll> v1;
typedef vector<vector<ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n;
ll a[100001];
ll b[100001];

void error(){
    cout << 0 << endl;
    exit(0);
}

ll ans = 1;

int main(){
    cin >> n;
    for(ll i = 0;i < n;i++) cin >> a[i];
    b[0] = 3;
    for(ll i = 0;i < n;i++){
        ans *= (b[a[i]]-b[a[i]+1]);
        ans %= mod;
        b[a[i]+1]++;
    }


    cout << ans << endl;


}


Measured memory_bytes: 1792
# https://atcoder.jp/contests/abc091/tasks/abc091_b

import itertools
import collections
import bisect

def main():
    N = int(input())
    S = [input() for _ in range(N)]
    sc = collections.Counter(S)
    M = int(input())
    T = [input() for _ in range(M)]
    tc = collections.Counter(T)

    ans = 0
    for item in sc.items():
        ans = max(ans, item[1] - tc[item[0]])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>

#define yes            cout<<"YES"<<endl
#define no             cout<<"NO"<<endl
#define sz(x)          x.size()
#define ll                    long long int
#define ls             long int
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test           int t;cin>>t;while(t--)
#define f(i, a, n)     for(int i=a; i<n;i++)
#define gcd(a,b)7           __gcd(a,b)
#define lcd(a,b)       (a*b)/gcd(a,b)
#define pb             push_back
#define mp(x,y)        make_pair(x,y)
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define srt(v)         sort(v.begin(),v.end())
#define basrt(a,n)     sort(a,a+n,greater<int>())
#define asrt(a,n)      sort(a,a+n)
#define fact(n)        ll x=1;for(ll i=1;i<=n;i++){x=(x*i);}
#define F              first
#define S              second
#define deb(x)         cout << #x << ": " << x << endl;
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define INF 	       1000000007
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;

double pi=3.14159265358979323846;
typedef vector<ll> vll ;
typedef vector<int> vii ;

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}
void solve()
{
      int n;
      cin>>n;
      string s;
      cin>>s;
      int k=s.size();
      //deb(k);
      if(k<=n)
	  {
	  	 cout << s;
	  }
	  else
	  {
	  	for(int i=0;i<n;i++)
		{
			cout << s[i];
		}
		 cout << "...";
	  }
	 

}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    ll test_case=1;
    //cin>>test_case ;
    while(test_case--)
	{
		 solve();
	}

	return 0;
}

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

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

    map<int, map<string,int>> m;
    m[0]["x"] = 0;
    m[0]["y"] = 0;

    int maxt = 0;
    for(int i = 0; i < n; i++)
    {
        int t,x,y;
        cin >> t >> x >> y;
        m[t]["x"] = x;
        m[t]["y"] = y;

        if(t > maxt) maxt = t;
    }

    bool possible = false;
    int start = 0;
    for(int i = 0; i <= maxt; i++)
    { 
        if(m.find(i) != m.end()){
            
            int t,x,y;
            t = i - start;
            x = m[i]["x"] - m[start]["x"];
            y = m[i]["y"] - m[start]["y"];

            for(int j = 0; j < t; j++)
            {
                if(x == 0 && y == 0 && x != 100000){
                    x++;
                }else if(x == 0 && y == 0 && x == 100000){
                    x--;
                }else if(x > 0){
                    x--;
                }else if(x < 0){
                    x++; 
                }else if(y > 0){
                    y--;
                }else if(y < 0){
                    y++; 
                }
            }
            if(x == 0 && y == 0){
                
                possible = true;
            }else{
                possible = false;
                break;
            }
            start = i;
        }
    }
    if(possible) cout << "Yes" << endl;
    if(possible == false) cout << "No" << endl;
    
}
 


Measured memory_bytes: 31488
def binary_search_low(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ok = -1
    ng = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] < v: ok = mid
        else: ng = mid
        
    return ok  #, ng
    
def binary_search_high(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ng = -1
    ok = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] > v: ok = mid
        else: ng = mid
        
    return ok


n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for b in B:
    a_count = binary_search_low(A,b) + 1
    b_count = n - binary_search_high(C, b)
    #print(a_count,b_count)

    ans += a_count*b_count


print(ans)




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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		vi x(5);
		for(int i=0 ; i<5 ; ++i)cin >> x[i];
		
		int ans;
		for(int i=0 ; i<5 ; ++i)if(x[i] == 0){
			ans = i+1;
			break;
		}
		cout << ans;
	}
}


Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h= sc.nextInt();
		long[] a=new long[n];
		long[] b=new long[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextLong();
			b[i]=sc.nextLong();
		}
		Arrays.sort(a);
		Arrays.sort(b);
		int minb=-1;
		for(int i=n-1;i>=0;i--) {
			if(b[i]<=a[n-1]) {
				minb=i;
				break;
			}
		}
		long c=0;
		for(int i=n-1;i>minb&&h>0;i--) {
			h-=b[i];
			c++;
		}
		if(h<=0)System.out.println(c);
		else System.out.println(c+(h+a[n-1]-1)/a[n-1]);

	}
}


Measured memory_bytes: 83592
/*
 *  stay hungry, stay foolish, stay home.
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define ml cout<<"\n"
#define tc(w) ll w;cin>>w;while(w--)

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define in insert
#define ff first
#define ss second
#define mod 1000000007

#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
ll mat[1000000][4];
ll dp[1000000][4];
ll n;
ll help(ll idx ,ll pre){
	//test2(idx,pre);
	if(idx>=n){
		return 0;
	}
	if(dp[idx][pre]!=-1){
		return dp[idx][pre];
	}
	ll p=INT_MIN,h=INT_MIN,j=INT_MIN;
	if(pre==0){
		p = mat[idx][1]+help(idx+1,1);
		h = mat[idx][2]+help(idx+1,2);
		j = mat[idx][3]+help(idx+1,3);
	}
		if(pre==1){
			p=0;
			h = mat[idx][2]+help(idx+1,2);
			j = mat[idx][3]+help(idx+1,3);
		}
		if(pre==2 ){
			p=0;
			h = mat[idx][1]+help(idx+1,1);
			j = mat[idx][3]+help(idx+1,3);
		}
		if(pre==3){
			p=0;
			h = mat[idx][2]+help(idx+1,2);
			j = mat[idx][1]+help(idx+1,1);
		}
	
	dp[idx][pre] = max(h,max(p,j));
	//test1(dp[idx][pre]);
	return max(h,max(p,j));
}
int main(){
	ios_base::sync_with_stdio(false);
     	cin.tie(NULL);
    	cout.tie(NULL);
    	cin>>n;
    	rep(i,0,n){
    		rep(j,1,4){
    			cin>>mat[i][j];
    		}
    	}
    	memset(dp,-1,sizeof(dp));

    	ll ans = help(0,0);
    	//cout<<ans<<endl;
    	// rep(i,0,n){
    	// 	rep(j,0,4){
    	// 		cout<<dp[i][j]<<" ";
    	// 	}ml;
    	// }
    	cout<<dp[0][0];ml;

	return 0;
		
}


Measured memory_bytes: 41344
#include<stdio.h>


int  gcd2(int a,int b){

    int bin;
    int sw;
    // switch
    if(a<b){
        a=sw;
        a=b;
        b=sw;
    }

    if(a%b==0){
        return b;
    }

    while(a%b!=0){
        bin=a%b;

        if(bin==0){
            break;
        }
        a=b;
        b=bin;
    }

    return b;
}




int main (void){

    int K,a,b,c;
    long long ans=0;
    int ab_gcd;
    int ia,ib,ic;
    int bin;
    int sw=0;

    scanf("%d",&K);

    for(ia=1;ia<=K;ia++){
        for(ib=1;ib<=K;ib++){
            for(ic=1;ic<=K;ic++){

                a=ia;
                b=ib;

                if(a<b) {
                    sw=a;
                    a = b;
                    b = sw;
                }

                while(1){
                    bin=a%b;
                    if(bin==0){
                        break;
                    }

                    a=b;
                    b=bin;
                }

                ab_gcd=b;

                /*-------------*/
                a=ab_gcd;
                b=ic;
                sw=0;
                if(a<b) {
                    sw = a;
                    a = b;
                    b = sw;
                }

                while(a%b!=0){
                    bin=a%b;
                    if(bin==0){

                        break;
                    }
                    a=b;
                    b=bin;
                }
                ans+=b;
            }
        }
    }

    printf("%d",ans);

    return 0;
}

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

int main(){
  string S; int l;
  cin >> S; l=S.length();

  vector<int> res(100010, 0), p_of_R;
  for(int i=0; i<l-1; i++){
    if(S[i] == 'R' && S[i+1] == 'L'){
      p_of_R.push_back(i);
    }
  }

  for(int i=0; i<p_of_R.size(); i++){
    int p = p_of_R[i];
    while(S[p] == 'R'){
      if(p_of_R[i] % 2 == p % 2){
        res[p_of_R[i]]++;
      } else {
        res[p_of_R[i]+1]++;
      }
      p--;
    }

    int q = p_of_R[i]+1;
    while(S[q] == 'L'){
      if((p_of_R[i]+1) % 2 == q % 2){
        res[p_of_R[i]+1]++;
      } else {
        res[p_of_R[i]]++;
      }
      q++;
    }
  }

  for(int i=0; i<S.length(); i++){
    cout << res[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(){
    int i,n,q;
    int l, r, m;
    int count = 0;
    int S[100000],T[50000];
 
    scanf("%d", &n);
    for( i=0; i<n; i++ ){
        scanf("%d", &S[i]);
    }
    scanf("%d", &q);
    for( i=0; i<q; i++ ){
        scanf("%d", &T[i]);
    }
    for( i=0; i<q; i++ ){
        l=0;
        r=n;
        while( l<r ){
            m=(l+r)/2;
            if( S[m]==T[i] ){
                count++;
                break;
            }
            else if( T[i]<S[m] ) r=m;
            else if( T[i]>S[m] ) l=m+1;
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 1184
def main():
    n = int(input())
    ans = [[0] * 10 for _ in range(15)]
    for i in range(3, 14, 4):
        ans[i] = '#' * 20
    for _ in range(n):
        b, f, r, v = map(int, input().split())
        ans[(b - 1) * 4 + f - 1][r - 1] += v
    for col in ans:
        if col.count('#') > 0:
            print(col)
        else:
            print(' ' + ' '.join(map(str, col)))


main()



Measured memory_bytes: 5608
# coding: utf-8
# Your code here!

e1,e2,e3,e4 = map(int,input().split())

if(e1 == e2 and e3 == e4):
    print("yes")
elif(e2 == e3 and e1 == e4):
    print("yes")
elif(e1 == e3 and e2 == e4):
    print("yes")
else:
    print("no")


Measured memory_bytes: 5600
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main() 
{
    //int t; cin >> t; while(t--) 
    {
        int n, m;
        cin >> n >> m;
      	int x = 0;
      	for(int i = 0; i < m; i++)
        {
          	int y;
          cin >> y;
          x += y;
        }
      
      	cout << max(n - x, -1LL) << '\n';
        
    }
    
    return 0;
}

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

map<pair<int,int>,int> m;
vector<int> g[100005];
int c[100005];
int N;
void dfs(int now,int pre,int num){
    if(num==N-1)return;
    else{
        int K=0;
        int count=num;
        for(int u:g[now]){
            if(u!=pre){
                K++;
                if(c[m[make_pair(min(pre,now),max(pre,now))]]==K)K++;
                if(c[m[make_pair(min(u,now),max(u,now))]]==0){
                    c[m[make_pair(min(u,now),max(u,now))]]=K;
                    count++;
                }
            }
        }
        for(int u:g[now]){
            if(u!=pre)dfs(u,now,count);
        }
    }}


int main(){
    int a,b;
    cin >> N;
    for(int i=1;i<N;i++){
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        m[make_pair(a,b)]=i;
    }
    dfs(1,-1,0);
    int ans=0;
    for(int i=1;i<N;i++)ans=max(ans,c[i]);
    cout << ans << endl;
    for(int i=1;i<N;i++)cout << c[i] << endl;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define LL long long
#define PB push_back
#define INF 1000 * 1000 * 1000
#define X first
#define Y second
#define x first
#define y second
#define pt pair<int , int> 
using namespace std;
const int mod = 998244353;
int n , a , b;
int t[1005];
int cnt[26];

int main()
{
	ios_base::sync_with_stdio(0);
	int n , k;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		cnt[s[0] - 'A']++;
	}
	int ans = 0;
	while(true)
	{
		vector<pair<int , int> > v;
		for(int i = 0; i < 26; i++)
			v.PB({cnt[i] , i});
		sort(v.begin() , v.end());
		reverse(v.begin() , v.end());
		bool bad = false;
		for(int i = 0; i < k; i++)
		{
			bad |= !cnt[v[i].Y];
			cnt[v[i].Y]--;
		}
		if(bad)
			break;
		ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int A[20], n;
int solve(int i,int m)
{
  int res;
  if(m == 0)
    {
      return 1;
    }
  if(i >= n)
    {
      return 0;
    }
  res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}
int main()
{
  int q, mj[200], i;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d", &A[i]);
    }
  scanf("%d", &q);
  for(i = 0; i < q; i++)
    {
      scanf("%d", &mj[i]);
    }
  
  for(i = 0; i < q; i++)
    {
      if(solve(0, mj[i]) == 1)
	{
	  printf("yes\n");
	}
      else
	{
	  printf("no\n");
	}
    }

  return 0;
}



Measured memory_bytes: 2104
A,B = map(int,input().split())
n = 50
m = n*2

grid = []
for i in range(n):
    grid.append(['.'] * m)
for i in range(n):
    grid.append(['#'] * m)

x = 0
y = 0
for i in range(B-1):
    grid[y][x] = '#'
    x += 2
    if x >= m:
        x -= m
        y += 2

x = 0
y = n+1
for i in range(A-1):
    grid[y][x] = '.'
    x += 2
    if x >= m:
        x -= m
        y += 2

print(str(m) + ' ' + str(m))
for row in grid:
    print(''.join(row))


Measured memory_bytes: 3188
/**
 * Integral Rectangles
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.lang.Integer.parseInt;

public class Main {

	static final Map<Integer, List<int[]>> rect = new HashMap<Integer, List<int[]>>();

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		for (int i = 1; i < 150; i++) {
			for (int j = i + 1; j < 151; j++) {
				int d = i * i + j * j;
				if (!rect.containsKey(d)) {
					rect.put(d, new ArrayList<int[]>());
				}
				rect.get(d).add(new int[]{i, j});
			}
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int h = parseInt(line.substring(0, line.indexOf(' ')));
			int w = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((h | w) == 0) break;

			int d = h * h + w * w;

			int[] ans = null;
			outer:
			for (int i = d; ; i++) {
				if (!rect.containsKey(i)) {
					continue;
				}
				for (int[] r : rect.get(i)) {
					if (i > d) {
						ans = r;
						break outer;
					}
					if (r[0] > h) {
						ans = r;
						break outer;
					}
				}
			}
			System.out.println(ans[0] + " " + ans[1]);
		}
	} //end while
} //end main

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

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

  vector<int> cnt(N + 1, 0);
  rep (i, M) {
    int l, r;
    cin >> l >> r;
    cnt[l - 1]++;
    cnt[r - 1 + 1]--;
  }

  rep (i, N - 1) cnt[i + 1] += cnt[i];

  int ans = 0;
  rep (i, N) ans += (cnt[i] == M ? 1 : 0);

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
// const int N = 316330;

bool ispal(int inp) {
    string chk = to_string(inp);
    rep(i,sz(chk)/2) {
        if(chk[i] != chk[sz(chk) - 1 - i])
            return false;
    }
    return true;
}

int32_t main() {

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

    int A, B;
    cin >> A >> B;

    int cnt = 0;
    repA(i,A,B) {
        if(ispal(i)) cnt++;
    }
    cout << cnt << '\n';
}

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

using namespace std;
typedef long long ll;

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


ll LINF = 1e18 ;
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  vector<ll> a(n) ;
  REP(i,n){
    cin >> a[i] ;
  }
  sort(a.begin(),a.end()) ;
  if(a[0]==0){
    cout << 0 <<endl;
    return 0 ;
  }
  ll ans =  1;
  REP(i,n){
    if(LINF/ans>=a[i]){
      ans *= a[i] ;
    }
    else{
      cout << -1 <<endl;
      return 0 ;
    }
  }
  cout << ans <<endl;


    return 0;
}

Measured memory_bytes: 4000
S = input()
keyence = 'keyence'
count = 0

for i in range(7):
	'''
	print(S[:i])
	print(keyence[:i])
	print(S[len(S)-7+i:])
	print(keyence[i:])
	'''
	
	if S[:i] == keyence[:i] and S[len(S)-7+i:] == keyence[i:]:
		count += 1
	
if count > 0:
	print('YES')
else:
	print('NO')

Measured memory_bytes: 3060
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define il inline
#define rg register
#define gi read<int>
using namespace std;
const double pi = 3.14159265358979323846;
template<class TT>
il TT read() {
	TT o = 0,fl = 1; char ch = getchar();
	while (!isdigit(ch) && ch != '-') ch = getchar();
	if (ch == '-') fl = -1, ch = getchar();
	while (isdigit(ch)) o = o * 10 + ch - '0', ch = getchar();
	return fl * o;
}
double a, b, n;
int main() {
    scanf("%lf%lf%lf", &a, &b, &n);
    if (n > a * a * b / 2) {
        double t = b - n / (a * a);
        printf("%.9lf\n", 90.0 - atan(a / (2 * t)) * 180 / pi);
    } else printf("%.9lf\n", 90.0 - atan(2 * n / (a * b * b)) * 180 / pi);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
char t[100000];
int main(){
	int i;
	int n;
	gets(t);
	n=strlen(t);
	for(i=0;i<n;i++){
		if(islower(t[i])) printf("%c",toupper(t[i]));
		else if(isupper(t[i])) printf("%c",tolower(t[i]));
		else printf("%c",t[i]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	int ans=0;
	for(int i=1;i<n-1;i++)
	{
		if((arr[i]<arr[i-1]&&arr[i]>arr[i+1])||(arr[i]>arr[i-1]&&arr[i]<arr[i+1]))
			ans++;
	}

	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
int main() {
	int n, m, person[101] = { 0 };
	std::cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		std::cin >> person[i];
	}
	for (int k = 1; k <= m; k++) {
		int i = 1;
		while (i != n) {
			if (1 <= i&&i <= n - 1 && person[i] % k > person[i + 1] % k) {
				std::swap(person[i], person[i + 1]);
				i = i + 1;
			}
			else if(1<=i&&i<=n-1){
					i = i + 1;
			}
		}
	}
	for (int j = 1; j <= n; j++) {
		std::cout << person[j] << std::endl;
	}
}

Measured memory_bytes: 3084
a = input()
b = input()
c = input()
index_a = 0
index_b = 0
index_c = 0
next = 'a'
while(True):
    if next == 'a':
        index_a += 1
        if index_a > len(a):
            print("A")
            break
        next = a[index_a - 1]
    elif next == 'b':
        index_b += 1
        if index_b > len(b):
            print("B")
            break
        next = b[index_b - 1]
    else:
        index_c += 1
        if index_c > len(c):
            print("C")
            break
        next = c[index_c - 1]

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void) {
	int n, i; cin >> n;
	double N = n;
	int  a[n];
	double ans = 100;
	double sum = 0;
	double ave;
	int h;

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

	ave = sum / n;

	for (i = n-1; i >= 0; i--) {
		if (fabs(a[i] - ave) <= ans) {
			ans = fabs(a[i] - ave);
			h = i;
		}
	}

	cout << h << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/










int N, A, B, P[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> A >> B;
    rep(i, 0, N) cin >> P[i];
    
    int a = 0, b = 0, c = 0;
    rep(i, 0, N) if (P[i] <= A) a++;
    rep(i, 0, N) if (A + 1 <= P[i] and P[i] <= B) b++;
    rep(i, 0, N) if (B + 1 <= P[i]) c++;

    int ans = min(a, min(b, c));

    cout << ans << endl;
}

Measured memory_bytes: 256
s = str(input())
acgt = ['A', 'C', 'G', 'T']

temp = 0
ans = 0

for i in range(len(s)):
    tar = s[i]
    if (tar in acgt):
        temp += 1
    else:
        temp = 0

    ans = max(ans, temp)

print(ans)


Measured memory_bytes: 8960
X = int(input())
if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)
elif 1800 <= X <= 1999:
    print(1)


Measured memory_bytes: 61640
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int arr[105];
int main()
{
    int n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    int minn=0x3f3f3f3f;
    for(int i=1;i<n;i++){
        int temp=0;
        for(int j=1;j<=i;j++){
            temp+=arr[j];
        }
        int s1=temp;
        int s2=sum-temp;
        if(abs(s2-s1)<minn){
            minn=abs(s2-s1);
        }
    }
    cout<<minn<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
    int N, D, X;
    cin >> N >> D >> X;
    int ans = 0;

    vector<int>A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        if (D % A[i] == 0) {
            A[i] = D / A[i];
        }
        else {
            A[i] = D / A[i] + 1;
        }
        
        ans += A[i];
    }
    cout << ans + X << endl;


}

Measured memory_bytes: 3632
/* ex3_2
  bonbonc */

#include<stdio.h>

int main(){
	int num,K;
	int count = 0;/*Kで何回割れるかを数える。*/
	scanf("%d %d", &num,&K);

	while(num>=K){
		num/=K;
		count++;
	}
	printf("%d\n",count+1);/*Kで割れた回数+1を出力*/

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,i,x;
    cin >> a >> b >> c;
    for(i=a; i<=b; i++){
        if(c%i==0){
            x=x+1;
        }
        else{
            x=x;
        }
    }
    cout << x;
    cout << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int Q, H, S, D;
  double N;
  cin >> Q >> H >> S >> D >> N;
  H = min(H, 2*Q);
  S = min(S, 2*H);
  D = min(D, 2*S);
  long long int total = 0;
  while(N>=2){
    N-=2;
    total+=D;
  }
  while(N>=1){
    N-=1;
    total+=S;
  }
  while(N>=0.5){
    N-=0.5;
    total+=H;
  }
  while(N){
    N-=0.25;
    total+=Q;
  }
  cout << total << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char n[3];
    for(int i=0;i<3;i++)
    {
        cin>>n[i];
        if(n[i]=='1')
            n[i]='9';
        else if(n[i]=='9')
            n[i]='1';
    }
    for(int i=0;i<3;i++)
    {
        cout<<n[i];
    }
}


Measured memory_bytes: 3644
n,q = map(int,input().split())
S = input()
N = [0]*(10**5+1)
for i in range(1,n):
    if S[i-1]=='A'and S[i]=='C':
        N[i] = 1
SUM = [0]*(10**5+1)
for i in range(1,n):
    SUM[i] += SUM[i-1]+N[i]
for i in range(q):
    l,r = map(int,input().split())
    print(SUM[r-1]-SUM[l-1])

Measured memory_bytes: 10228
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int a=sc.nextInt();
            char op = sc.next().charAt(0);
            int b=sc.nextInt();
            if (op == '+')
                System.out.println( a + b);
               
            if ( op == '-')
                System.out.println( a - b);
               
            if (op == '*')
                System.out.println(a * b);
               
            if (op == '/')
                 System.out.println(a / b);
              
            if(op == '?')
                 break;
             
        }
    }
}



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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,0,n){
        cin >> a[i];
    }
    sort(all(a));
    vector<ll> b;
    ll num=1;
    ll locate = a[0];
    rep(i,1,n){
        if(locate==a[i]) num++;
        else num = 1;
        if(num==2) b.push_back(locate);
        if(num==4) b.push_back(locate);
        locate = a[i];
    }
    sort(all(b));
    if(b.size()>1)cout << b[b.size()-1] * b[b.size()-2] << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a)      cout<<a<<" "
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll minize(ll& a,ll b){return a=(a>b?b:a);}
inline ll maxize(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


pll A[MAXN+5];

bool cmp(pll a,pll b){
	re a.se-a.fi>b.se-b.fi;
}

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc(n);
	fu(i,1,n)sc(A[i].fi);
	fu(i,1,n)sc(A[i].se);
	sort(A+1,A+1+n,cmp);
	ll r=n,l=1;
	while(l<=r){//	debug("b");
		if(A[l].se>A[l].fi){//	debug("a");
			while(r>0 and A[r].fi>A[r].se and sum<A[l].se-A[l].fi)sum+=A[r].fi-A[r].se,r--;
			if(sum>=A[l].se-A[l].fi){
				sum-=A[l].se-A[l].fi;
				l++;
			}
			else re pr(-1),0;
		}
		else break;
	} 
	pr(n-(r-l+1)); 


	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N,M; cin >> N >> M;
	V<V<int>> edge(N);
	V<int> node(N,0),depth(N,-1),parent(N);
	REP(i,N+M-1) {
		int A,B; cin >> A >> B;
		A--,B--;
		edge[A].push_back(B);
		node[B]++;
	}
	int root;
	REP(i,N) if(node[i]==0) root = i;
	queue<int> q;
	parent[root] = -1;
	q.push(root);

	while(q.size()){
		int from = q.front();
		q.pop();
		for(auto to: edge[from]){
			if(depth[to]==-1){
				depth[to] = depth[from] + 1;
				parent[to] = from;
				node[to]--;
				if(node[to]==0)q.push(to);
			}
			else{
				node[to]--;
				if(depth[parent[to]] < depth[from]){
					parent[to] = from;
					depth[to] = depth[from] + 1;
				}
				if(node[to]==0)q.push(to);
			}
		}
	}
	REP(i,N) cout << parent[i] + 1 << endl;
	return 0;
}


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

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

    int vacation,assignments,sum=0 ;

    cin >> vacation >> assignments ;

    int arr[assignments];

    for(int i=0;i<assignments;i++)
    {
        cin >> arr[i] ;
        sum +=arr[i] ;
    }

    if(sum>vacation)
        cout << "-1" ;
    else
        cout << vacation-sum ;

    return 0 ;



}


Measured memory_bytes: 3672