akhauriyash/Code-Regression huggingface dataset:
//code_sm
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int>
#define msi multiset<int>
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu ((int)1e9+7)
//sieve generation begin
vi PRIME;
void sieve(int n)
{
	bool a[n+1];
	memset(a,0,sizeof(a));
	a[0]=1;
	a[1]=1;
	for(int i=2;i*i<=n;i++)
	{
		if(a[i]==0)
		{
			for(int j=i*i;j<=n;j+=i)
			a[j]=1;
		}
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]==0)
		PRIME.pb(i);
	}
}
//sieve generation end
ll gcd(ll a,ll b)
{
	while(b%a)
	{
		ll c=b;
		b=a;
		a=c%a;
	}
	return a;
}
ll bigpow(ll x,ll y)
{
	if(y==0)
	return 1;
	else if(y&1)
	{
		return (x*bigpow((x*x)%chotu,(y-1)/2))%chotu;
	}
	else 
	return bigpow((x*x)%chotu,y/2);
}
//fastio
/*void fastscan(int &number) 
{ 
    //variable to indicate sign of input number 
    bool negative = false; 
    register int c; 
  
    number = 0; 
    c = getchar(); 
    if (c=='-') 
    { 
        
        negative = true; 
  
        c = getchar(); 
    } 
    for (; (c>47 && c<58); c=getchar()) 
        number = number *10 + c - 48; 
    if (negative) 
        number *= -1; 
} 
*/
void solve()
{
	fastio
}
int main()
{
//code
fastio
ll n,m;
cin>>n>>m;
ll sum=0;
for(ll i=0;i<m;i++)
{
	int x;
	cin>>x;
sum+=(ll)x;
}
if(sum>n)
cout<<-1;
else
cout<<n-sum;

}

Measured memory_bytes: 3648
#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(){
  ll s; cin >> s;
  ll a=1e9,b=1;
  ll x=1e9;
  ll c=s%x==0?0:x-s%x;
  ll d=c==0?s/x:s/x+1;
  cout << 0 << " " << 0 << " " << a << " " << b << " " << c << " " << d << endl;
  
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, Q = mapint()
tree = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = mapint()
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
late = [0]*N

for _ in range(Q):
    v, p = mapint()
    late[v-1] += p

ans = [0]*N
checked = [0]*N
from collections import deque
Q = deque([(0, 0)])

while Q:
    v, plus = Q.pop()
    plus += late[v]
    checked[v] = 1
    ans[v] = plus
    for nx in tree[v]:
        if not checked[nx]:
            Q.append((nx, plus))

print(*ans)

Measured memory_bytes: 124284
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<map>
#include<iostream>
using namespace std;
int main(){
int n,a[100001]={0},x,y,vis[101][101]={0},ans=0,c[101][101]={0};
int direction=1;
cin>>x>>y;
cin>>n;
for(int i=1;i<=n;i++){
	cin>>a[i];
}
int x1=1,y1=1;
int now=1; 
if(y!=1){
while(ans<x*y){
	while(a[now]==0)now++;
	c[x1][y1]=now;
	a[now]--;
	if(y1==1){
		if(c[x1][y1+1]==0)direction=1;
		else direction=3;
	}
	if(y1==y)
	{
		if(c[x1][y1-1]==0)direction=2;
		else direction=3;
	}
	ans++;
		if(direction==1)y1++;
	if(direction==2)y1--;
	if(direction==3)x1++;
}
for(int i=1;i<=x;i++){
	for(int j=1;j<=y;j++){
		cout<<c[i][j]<<" ";
	}
	cout<<endl;
}

}
else {
	for(int i=1;i<=x;i++){
		while(a[now]==0)now++;
		a[now]--;
		cout<<now<<endl;
	}
}
return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n;
    cin>>n;
    ll s=1;
    while(s<=n)
    {
      s*=2;
    }
    if(s==n)
      cout<<s;
    else
      cout<<s/2<<endl;
}
return 0;
}

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

void func_A() {
    bool f = false;
    int K, A, B;
    cin >> K;
    cin >> A >> B;
    for(int i = A; i <= B; i++) {
        if(i % K == 0) f = true;
    }
    if(f) {
        cout << "OK";
    } else {
        cout << "NG";
    }
}
void func_B() {
    ll money = 100, X;
    ll i = 0;
    cin >> X;
    while(money < X) {
        i++;
        money = money + money * 0.01;
    }
    cout << i;
}
void func_C() {}
void func_D() {}
int main() {
    func_B();
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int a, b;
    cin >> a >> b;
    if(a + b >= 10) {
        printf("error\n");
        return 0;
    }
    printf("%lld\n", a + b);

    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    int tmp = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R') tmp++;
        else {
            ans = max(ans, tmp);
            tmp = 0;
        }
    }
    cout << max(ans,tmp) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include "iostream"
using namespace std;

int main()
{
    string b;
    cin>>b;
    if (b== "A"){
        cout<<"T";
    }
    if (b== "C"){
        cout<<"G";
    }
    if (b=="G"){
        cout<<"C";
    }
    if (b== "T"){
        cout<<"A";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<bool> VB;
typedef std::vector<VB> VBB;
typedef std::vector<std::string> VS;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  solve();
  return 0;
}

void solve() {
  uint64_t n;
  std::cin >> n;
  std::vector<int> lucas(n+1, 0);
  REP(i, n+1) {
    if (i == 0) {
      lucas.at(0) = 2;
      continue;
    }
    if (i == 1) {
      lucas.at(1) = 1;
      continue;
    }
    lucas.at(i) = lucas.at(i-1) + lucas.at(i-2);
  }
  cout(lucas.at(n));
}


Measured memory_bytes: 256
import copy
def cd_generator(num):
    ans=[]
    for i in range(1,10000000):
        if num%i==0:
            ans.append(i)
    temp=copy.deepcopy(ans)
    temp.reverse()
    for ele in temp:
        ans.append(num//ele)
    return ans
def main():
    n,m=map(int,input().split())
    array=cd_generator(m)
    ans=0
    for ele in array:
        if m//ele>=n:
            ans=max(ans,ele)
    print(ans)
main()

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

typedef struct node{
    int x;
    int y;
    int value;
    struct node* next;
}node;

int main(){
    int h, w;
    scanf("%d%d", &h, &w);
    char map[h+2][w+2];
    int p[h+2][w+2];
    for(int i=0; i<h+2; i++){
        for(int j=0; j<w+2; j++){
            map[i][j] = '#';
        }
    }
    for(int i=0; i<h; i++){
        char str[w+1];
        scanf("%s", str);
        for(int j=0; j<w; j++){
            map[i+1][j+1] = str[j];
        }
    }
    for(int i=0; i<h+2; i++){
        for(int j=0; j<w+2; j++){
            if(map[i][j] == '#'){
                p[i][j] = -1;
            }else{
                p[i][j] = 0;
            }
        }
    }
    map[1][1] = '#';
    node s;
    s.x = 1;
    s.y = 1;
    s.value = 1;
    s.next = NULL;
    node* n = &s;
    node* l = &s;
    while(n != NULL){
        p[n->y][n->x] = n->value;
        if(map[n->y-1][n->x] == '.'){
            map[n->y-1][n->x] = '#';
            l->next = (node*)malloc(sizeof(node));
            l = l->next;
            l->x = n->x;
            l->y = n->y-1;
            l->value = n->value + 1;
            l->next = NULL;
        }
        if(map[n->y][n->x+1] == '.'){
            map[n->y][n->x+1] = '#';
            l->next = (node*)malloc(sizeof(node));
            l = l->next;
            l->x = n->x+1;
            l->y = n->y;
            l->value = n->value + 1;
            l->next = NULL;
        }
        if(map[n->y+1][n->x] == '.'){
            map[n->y+1][n->x] = '#';
            l->next = (node*)malloc(sizeof(node));
            l = l->next;
            l->x = n->x;
            l->y = n->y+1;
            l->value = n->value + 1;
            l->next = NULL;
        }
        if(map[n->y][n->x-1] == '.'){
            map[n->y][n->x-1] = '#';
            l->next = (node*)malloc(sizeof(node));
            l = l->next;
            l->x = n->x-1;
            l->y = n->y;
            l->value = n->value + 1;
            l->next = NULL;
        }
        n = n->next;
    }
    /*for(int i=0; i<h+2; i++){
        for(int j=0; j<w+2; j++){
            printf("%d ", p[i][j]);
        }
        printf("\n");
    }*/
    int count = 0, len = p[h][w];
    int f[len];
    for(int i=0; i<len; i++){
        f[i] = 0;
    }
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(1 <= p[i][j] && p[i][j] <= len){
                if(f[p[i][j]-1] == 0){
                    f[p[i][j]-1] = 1;
                }else{
                    count++;
                }
            }else if(p[i][j] != -1){
                count++;
            }
        }
    }
    if(p[h][w] == 0){
        printf("-1");
    }else{
        printf("%d", count);
    }

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
dic = defaultdict(int)
for i in range(n):
    s = ns()
    q = list(s)
    q.sort()
    q = "".join(q)
    dic[q] += 1

ans = 0
for v in dic.values():
    ans += v*(v-1)//2
print(ans)


Measured memory_bytes: 58716
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>

static int c[1000+1][1000+1];

static int lcs(const char x[], int m, const char y[], int n) {
    int i, j;

    for ( i = 0; i <= m; i++ ) {
        c[i][0] = 0;
    }
    for ( i = 0; i <= n; i++ ) {
        c[0][i] = 0;
    }

    for ( i = 1; i <= m; i++ ) {
        for ( j = 1; j <= n; j++ ) {
            if ( x[i] == y[j] ) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else if ( c[i - 1][j] >= c[i][j - 1] ) {
                c[i][j] = c[i - 1][j];
            } else {
                c[i][j] = c[i][j - 1];
            }
        }
    }

    return c[m][n];
}

static int ReadLine(char x[]) {
    int c;
    int i = 1;

    while ( (c = fgetc(stdin)) != '\n' ) {
        if ( isalnum(c) ) {
            x[i] = c;
            i++;
        }
    }

    return i - 1;
}

int main(int argc, char* argv[]) {
    int q;
    char x[1000 + 1];
    char y[1000 + 1];
    int m, n, i;

    scanf("%d\n", &q);

    for ( i = 0; i < q; i++ ) {
        int l;
        m = ReadLine(x);
        n = ReadLine(y);

        l = lcs(x, m, y, n);
        printf("%d\n", l);
    }

    return 0;
}

    
    

                    
    



Measured memory_bytes: 5732
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;

int hikaku(const void *n1,const void *n2)
{
    return *(int*)n1-*(int*)n2;
}

int main()
{

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

    qsort(a,n,sizeof(int),hikaku);
    int tobasu=0;
    for(int i=0;i<n-1;i++)
    {
        tobasu=fmax(a[i+1]-a[i],tobasu);
    }
    tobasu=fmax(tobasu,k-a[n-1]+a[0]);

    printf("%d\n",k-tobasu);

    return 0;
}

Measured memory_bytes: 1404
k=gets.to_i
a=gets.split.map(&:to_i).reverse
if a[0]==2
  max,min=3,2
else
  puts "-1"
  exit
end
a.each do |b|
  min=(min-1)/b*b+b
  if min>max
    puts "-1"
    exit
  end
  max=max/b*b+b-1
end
puts [min,max].join(" ")


Measured memory_bytes: 21412
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#if __cplusplus >= 201103
#include <numeric>
#endif
using namespace std;

int main(){
    int n,l;
    cin >> n >> l;
    vector<string> lis(n);
    for(int i=0;i<n;i++){
        cin >> lis.at(i);
    }
    sort(lis.begin(), lis.end());
    for(int j=0;j<n;j++){
        cout << lis.at(j);
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> a[100000];
bool v[100000];
void dfs(int cur){
    v[cur] = true;
    for (auto e : a[cur]) if (!v[e]) dfs(e);
}
int main(){
    int n, m, x, y, z, c = 0;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++){
        scanf("%d %d %d", &x, &y, &z);
        a[x - 1].push_back(y - 1);
        a[y - 1].push_back(x - 1);
    }
    fill(v, v + n, false);
    for (int i = 0; i < n; i++){
        if (!v[i]){
            dfs(i);
            c++;
        }
    }
    printf("%d\n", c);
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(ll i = a ; i < b ; ++i)

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

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 998244353  ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T power(T a,T b){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a); b/=2; a=(a*a); } return ans; }
ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll lcm(ll a, ll b) {
	return (a*b)/gcd(a,b) ; 
}
void read(vt<int> &a) {
	rep(i,0,a.size()) 
	cin >> a[i] ; 
}
void read(vt<ld> &a) {
	rep(i,0,a.size()) 
	cin >> a[i] ; 
}

bool prime(ll t) {
	for(ll i  =2 ; i*i <= t ; ++i) {
		if(t%i==0) 
			return 0 ; 
	}
	return 1 ; 
}
bool cmp(pii &a , pii &b) {
	if(a.ss == b.ss) 
		return a.ff > b.ff ; 
	return a.ss < b.ss ; 
}

// ==========OKAY==============
const int N = 51 ; 
int n, m , q ; 
int a[N],b[N],c[N],d[N] ; 
int res ; 

void solve(vt<int> &A) {
	int ans = 0;  
	for(int i = 1 ; i <= q ; ++i) {
		if(A[b[i]-1] - A[a[i]-1] == c[i]) 
			ans += d[i] ; 
	}
	umax(res, ans) ; 
}

void rec(int idx, vt<int> &a) {
	if(idx == n) {
		solve(a) ;
		return ;  
	}
	int prv ; 
	if(a.size() == 0) 
		prv = 1 ; 
	else 
		prv = a[a.size()-1]; 
	for(int i = prv ; i <= m ; ++i) {
		vt<int> copy = a ; 
		copy.pb(i) ; 
		rec(idx+1,copy) ; 
	}
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	 
	cin >> n >> m >> q ; 
	rep(i,1,q+1) {
		cin >> a[i] >> b[i] >> c[i] >> d[i] ; 
	}
	res = 0; 
	vt<int> a ; 
	rec(0,a) ; 
	cout << res  ; 

	


 	return 0 ; 
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root=NIL;

Node treeMinimum(Node x){

}

Node treeSearch(Node u, int k){
  Node i=u;
   while(i!=NIL){
     if(i->key==k)return i;
     else if(i->key<k)i=i->right;
     else i=i->left;
}
return NIL;
}
Node treeSuccessor(Node x){

}
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if( u == NIL ) return ;
  inorder( u->left );
  printf(" %d",u->key);
  inorder( u->right );
}
void preorder(Node u){
  if( u == NIL ) return ;
  printf(" %d",u->key);

  preorder( u->left );
  preorder( u->right );
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20484
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

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

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        csf: [(usize, usize, usize); n-1],
    }

    for i in 0..n - 1 {
        let mut time = csf[i].1;
        for j in i..n - 1 {
            if time < csf[j].1 {
                time = csf[j].1;
            }
            time += (csf[j].2 - time % csf[j].2) % csf[j].2;
            time += csf[j].0;
        }
        println!("{}", time);
    }
    println!("0");
}


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

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<char>> gridTable(H, vector<char>(W));

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> gridTable.at(i).at(j);
    }
  }

  vector<bool> rowFlag(H, false), colFlag(W, false);

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (gridTable.at(i).at(j) == '#') {
        rowFlag.at(i) = true;
        colFlag.at(j) = true;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    if (rowFlag.at(i)) {
      for (int j = 0; j < W; j++) {
        if (colFlag.at(j)) cout << gridTable.at(i).at(j);
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
signed main() {
	int s; cin >> s;
	if (s == 4 || s == 2 || s == 1)cout << "4\n";
	else {
		for (int i = 2; ; i++) {
			if (s % 2)s = s*3+1;
			else s /= 2;
			if (s == 4 || s == 2 || s == 1) {
				cout << i + 3 << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
{-#LANGUAGE FlexibleContexts#-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V

getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]

type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)

mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
ti = toInteger
fi = fromInteger
fig = fromIntegral
rf = realToFrac

(.<.) :: Integer -> Integer -> Integer
(.<.) f g -- combination
    | g < 1 || f < 1 || f < g = 1
    | True = foldr1 (*) (take (fi g) [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)

unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)

mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a

countIf f = length . filter f

enumDivisor :: Int -> [Int]
enumDivisor n = do
    let sqrted = floor $ sqrt (fromIntegral n)
        smaller = filter (\x -> mod n x == 0) [1..sqrted]
        bigger = reverse $ map (div n) smaller
    if head bigger == sqrted then smaller ++ (init bigger)
    else smaller ++ bigger

-- 
--
--

main = do
    [n, x] <- getIs
    _inps <- getIs
    let (i:inps) = map (flip (-) x >>> abs) _inps
        divs = reverse $ enumDivisor i
        ans = head $ filter (\x -> all (\y -> mod y x == 0) inps) divs
    putStrLn . show $ ans
        


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n; cin >> n;
  map<int, ll> mp;
  for(int i=1;i<=n;i++){
    int p = i;
    // calculate prime factor of p
    for(int j=2;j*j <= p;j++){
      while(p %j == 0){
        ++mp[j];
        p /= j;
      }
    }
    if(p != 1) ++mp[p];
  }
  ll ans = 1;
  for(auto iter = mp.begin(); iter != mp.end();iter++){
    // cout << iter -> first << " " << iter -> second << endl;
    ans = (ans * (iter -> second + 1)) %MOD;
  }
  cout << ans << endl;
}

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

int main(){
  int64_t l,r;
  cin >> l >> r;
  int64_t length = (r-l);
  int64_t lmod = l%2019;
  int64_t rmod = r%2019;
  //cout << lmod << endl;
  //cout << (l+1)%2019 << endl;
  //cout << (l*(l+1))%2019 << endl;
  //cout << l*(l+1)/2111111111 << endl;
  
  if(lmod+length>=2019||lmod==0||rmod==0){cout << 0 << endl;return 0;}
  else{
    int64_t minmod = 2019;
    for(int i=1; i<length+1; i++){
      for(int j=0; j<i; j++){
        minmod = min(((l+i)*(l+j))%2019,minmod);
      }
    }
    cout << minmod << endl;
  }
    //cout << (l*(l+1))%2019 << endl;return 0;}
}


Measured memory_bytes: 256
#A,B,C,D=map(int, list(input()))
numbers = list(map(int, list(input())))
seven="=7"

for i in range(1<<3):
    pms = []
    for j in range(3):
        if (i>>j)&1:
            pms.append(1)
        else:
            pms.append(0)
    result = numbers[0]
    result_str = str(numbers[0])
    for j, pm in enumerate(pms):
        j+=1
        if pm:
            result+=numbers[j]
            result_str+="+%d"%(numbers[j])
        else:
            result-=numbers[j]
            result_str+="-%d"%(numbers[j])
    if result==7:
        print(result_str+seven)
        break


Measured memory_bytes: 9084
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int h, w, n;
	cin >> h >> w >> n;
	set<pair<int, int> > s;
	vector<int> miny(200001, mod);
	for(int i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		s.insert(make_pair(x, y));
		miny[x] = min(miny[x], y);
	}
	int maxy = 1;
	if(s.find(make_pair(2, 1)) != s.end()){
		cout << 1 << endl;
		return 0;
	}
	for(int i = 2; i < h; i++){
		if(s.find(make_pair(i, maxy + 1)) == s.end()) maxy++;
		if(miny[i + 1] <= maxy){
			cout << i << endl;
			return 0;
		}
	}
	cout << h << endl;
}

Measured memory_bytes: 10368
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace AtcoderExpress
{


    class Program2
    {
        static long mod = 1000000007;
        static void Main(string[] args)
        {
            var KN = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var K = KN[0];
            var N = KN[1];

            var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var ans = new long[N];
            for (int i = 0; i < N; i++)
            {
                if(i == 0)
                {
                    ans[i] = A[N - 1] - A[0];
                }
                else
                {
                    ans[i] = (A[i - 1] + K) - A[i];
                }
            }

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


Measured memory_bytes: 33524
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);

  for (ll i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  ll add = 0;
  for (ll i = N - 1; i >= 0; i--) {
    add += (B[i] - (A[i] + add) % B[i]) % B[i];
  }

  cout << add << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _xx ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef long long LL;
const int mod=1e9+7;
const int MAXN=1e5+100;
int a[MAXN];
int main()
{
    int n;
    cin>>n;
    int cost=0;
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cost+=abs(a[i]-a[i-1]);
    }
    cost+=abs(a[n]);
    //cout<<cost<<endl;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i==1){
            ans=cost-abs(a[i+1]-a[i])-abs(a[i]-a[0])+abs(a[i+1]-a[i-1]);
        }else if(i==n){
            ans=cost-abs(a[0]-a[i])-abs(a[i]-a[i-1])+abs(a[0]-a[i-1]);
        }else{
            ans=cost-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1]);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a, b, x;
    cin >> a >> b >> x;
    if(a <= x && x <= (a+b)) YES();
    else NO();
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    L = [0] * (n + 1)
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            L[j] += 1

    res = 0
    for i in range(1, n + 1):
        res += i * L[i]
    print(res)


def resolve2():
    def g(n):
        return ((n + 1) * n) // 2

    n = int(input())
    res = 0
    for i in range(1, n + 1):
        res += i * g(n // i)
    print(res)


if __name__ == '__main__':
    resolve2()


Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> da(n),co(100005,0);
  for(int i=0;i<n;i++){
    cin >> da[i];
    for(int j=0;j<3;j++){
      co[j+da[i]]++;
    }
  }
  int ans=0;
  for(int i=0;i<100005;i++){
    ans=max(ans,co[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())

def factorint(N):
    """
    Nを作っている素数を辞書で返す．
    input 100
    output Counter({2: 2, 5: 2})
    """
    table = []
    tmp = 2
    while(N > 1):
        for i in range(tmp,N+1):
            if N%i == 0:
                while N%i == 0:
                    N = N//i
                    table.append(i)
                tmp = i+1
                break
    table_ = collections.Counter(table)
    return table_

def primes(n): #試し割り法で各素因数とその指数を求める
    cnt=collections.defaultdict(int)
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            while n%i==0:
                cnt[i]+=1
                n//=i
    if n!=1:
        cnt[n]+=1
    return cnt

# factors = factorint(N)
factors = primes(N)
ans = 0

for key in factors.keys():
    f_c = factors[key]
    tmp = 1
    while f_c >= tmp:
        ans += 1
        f_c -= tmp
        tmp += 1

print(ans)

Measured memory_bytes: 10960
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <queue>
#include <climits>

using namespace std;

typedef long long ll;

int t;

int main()
{
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout); 
    string s;
    while(cin>>s) {
        for(int i=0;i<s.length();++i)
            cout<<"x";
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())

# a >= b >= c を仮定できる
# a,b,c <= 3500
# 4/N <= 3/a  a <= 0.75N
# 4/N >= 3/c  c >= 0.75N

least = int(0.75 * N) + 2
max = 3501
for b in range(1,max):
  for a in range(1,least):
    res = 4/N - 1/a - 1/b
    if res<=0:
      continue
    candc = int(1/res)
    for c in range(candc-1,candc+2):
      if 4*a*b*c == N*(a*b + b*c + c*a):
        print(a,b,c)
        exit(0)



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n,a,b;
string s;
bool res[1111111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>a>>b;
	cin>>s;
	int tuuka=0,kaigai=1;
	rep(i,s.length()){
		if(s[i]=='a'){
			if(tuuka<a+b){
				tuuka++;
				res[i]=true;
			}
		}else if(s[i]=='b'){
			if(tuuka<a+b&&kaigai<=b){
				tuuka++;
				kaigai++;
				res[i]=true;
			}
		}
	}
	rep(i,n){
		if(res[i])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

const ll mod = 1000000007;
//const ll mod = 998244353;

const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void init(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    int n;
    cin >> n;
    vector<ll> x(n);
    for (int i = 0;i < n;++i) cin >> x[i];
    init(100000);
    // if (n > 2000) return 0;
    ll ans = 0;
    vector<ll> sum(n);
    for (int i = 0;i < n;++i) sum[i] = inv[i];
    for (int i = 0;i < n-1;++i) (sum[i+1] += sum[i]) %= mod;
    for (int i = 0;i < n;++i) (sum[i] *= fact[n-1]) %= mod;
    // p_ary(sum,0,n);
    for (int i = 1;i < n;++i) (ans += (x[i]-x[i-1])*sum[i]) %= mod;
    cout << ans << endl;
}

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

int main() {
    int n,m;
    std::cin>>n>>m;
    std::vector<std::pair<int,int>> l(n);
    for (int i = 0; i < m; ++i) {
        int a,b;
        std::cin>>a>>b;
        l.emplace_back(b,a);
    }
    std::sort(l.begin(),l.end());
    int ans=0;
    int lim=0;
    for(auto i:l) {
        if(i.second>lim){
            lim=i.first-1;
            ++ans;
        }
    }

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

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
vector<vector<int>> can;
vector<int> sum;
vector<int> c, w;
int rec(int l, int r) {
  if(can[l][r] >= 0) return can[l][r];
  if(r - l < 2) return can[l][r] = 1;
  bool f = false;
  if(rec(l+1, r) == 1 && sum[r] - sum[l+1] <= c[l]) f = true;
  if(rec(l, r-1) == 1 && sum[r-1] - sum[l] <= c[r-1]) f = true;
  if(f) return can[l][r] = 1;
  else return can[l][r] = 0;
}
int main()
{
  int n;cin >> n;
  c.resize(n); w.resize(n);
  rep(i,n) cin >> c[i] >> w[i];

  can.resize(n+1, vector<int>(n+1, -1));
  sum.resize(n+1, 0);
  rep(i,n) sum[i+1] = sum[i] + w[i];
  rec(0, n);

  
  vector<int> dp(n+1, 1e+9);
  dp[0] = 0;
  rep1(i,n) {
    rep(j,i) {
      if(can[j][i] == 1) chmin(dp[i], dp[j] + 1);
    }
  }
  cout << dp[n] << "\n";
  
  return 0;
}



Measured memory_bytes: 6784
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const int K = 62;
const int N   = 2e3 + 5;

ll b[K];
char s[N];
ll a[N];
int n;

bool add(ll x){
	for(int i=0;i<K;i++){
		if(((x>>i)&1)==0) continue;
		if(b[i]==-1){
			b[i] = x;
			return true;
		}
		x ^= b[i];
	}
	return false;
}

int solve() 
{
	//happy coding

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

	for(int i=0;i<K;i++){
		b[i] = -1;
	}

	for(int i=n-1;i>=0;i--){
		if(add(a[i])&&s[i] == '1'){
			printf("1\n");
			return 0;
		}
	}

	printf("0\n");
	return 0;
}
int main(){
	int test = 1;
  	scanf("%d", &test);
  	while (test--)solve();return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define ol(c, s, e) for(int pos=s; pos<e; pos++)cout << c[pos] << " ";cout <<"\n";
#define PI acos(-1LL)

const int M = 1000000007;
const int N = 2e5 + 5;
const long long INF = 1e9 + 12;

vector<vector<int>> v;
vector<int> dp;
int dfs(int i){
    int ans = 0;
    if(dp[i]!=-1)
        return dp[i];
    for(auto x: v[i]){
        ans = max(ans, 1+dfs(x));
    }
    return dp[i] = ans;
}
void solve(){
    int n, m;
    cin >> n >> m;
    v.resize(n+1);
    dp.resize(n+1,-1);
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        v[a].pb(b);
    }
    int ans = 0;
    for(int i=1; i<=n; i++){
        ans = max(ans, dfs(i));
    }
    cout << ans;
}

signed main(){
    FAST
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}


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

int main() {
  int n,INF=1<<28;
  cin >> n;
  int d[n+1][n+1];
  fill(d[0],d[n+1],INF);
  for(int i=1; i<=n; i++) d[i][i]=0;
  for(int i=0; i<n; i++) {
    int x,m;
    cin >> x >> m;
    for(int j=0; j<m; j++) {
      int y;
      cin >> y;
      d[x][y]=1;
    }
  }
  for(int k=1; k<=n; k++) {
    for(int i=1; i<=n; i++) {
      for(int j=1; j<=n; j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    }
  }
  int q;
  cin >> q;
  while(q--) {
    int x,y,z;
    cin >> x >> y >> z;
    if(d[x][y]+1<=z) cout << d[x][y]+1 << endl;
    else cout << "NA" << endl;
  }
  return 0;
}


Measured memory_bytes: 1200
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vvi v(n, vi(n));
    int i = n / 2 + 1, j = n / 2;
    loop(k, 1, n * n + 1) {
      while (v[i][j]) {
        i = (i + 1) % n;
        j = (j + n - 1) % n;
      }
      v[i][j] = k;
      i       = (i + 1) % n;
      j       = (j + 1) % n;
    }
    rep(i, n) {
      rep(j, n) cout << setw(4) << v[i][j];
      cout << endl;
    }
  }
}

Measured memory_bytes: 3120
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        String s = scan.next();
        String t = scan.next();
        int a = 0;
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == t.charAt(i)){
                a++;
            }
        }
        System.out.print(a);
    }
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

std::string Sa, Sb, Sc;
int seek[3];

int main()
{
	in >> Sa >> Sb >> Sc;

	int turn = 1;
	while (true)
	{
		if (turn == 1)
		{
			if (seek[0] == Sa.length())
			{
				out << "A" << std::endl;
				return 0;
			}
			switch (Sa[seek[0]])
			{
			case 'a':
				turn = 1;
				break;
			case 'b':
				turn = 2;
				break;
			case 'c':
				turn = 3;
				break;
			}
			seek[0]++;
		}
		if (turn == 2)
		{
			if (seek[1] == Sb.length())
			{
				out << "B" << std::endl;
				return 0;
			}
			switch (Sb[seek[1]])
			{
			case 'a':
				turn = 1;
				break;
			case 'b':
				turn = 2;
				break;
			case 'c':
				turn = 3;
				break;
			}
			seek[1]++;
		}
		if (turn == 3)
		{
			if (seek[2] == Sc.length())
			{
				out << "C" << std::endl;
				return 0;
			}
			switch (Sc[seek[2]])
			{
			case 'a':
				turn = 1;
				break;
			case 'b':
				turn = 2;
				break;
			case 'c':
				turn = 3;
				break;
			}
			seek[2]++;
		}
	}
	return 0;
}

Measured memory_bytes: 256