akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int A, B; std::cin >> A >> B;
  if(A <= 5) fin(0);
  if(A >= 13) fin(B);
  fin(B/2);
  return 0;
}


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

int main(){

	int p0x,p0y,p1x,p1y,p2x,p2y;
	int q,cr;

	cin>>p0x>>p0y>>p1x>>p1y;
	cin>>q;

	for(int i=0;i<q;i++){
		cin>>p2x>>p2y;
		cr=(p2x-p0x)*(p1y-p0y)-(p1x-p0x)*(p2y-p0y);
		if(cr==0){
			if(((p2x-p0x<0)==(p1x-p0x<0)&&(p2y-p0y<0)==(p1y-p0y<0))||((p2x==p0x)&&(p1x==p0x)&&(p2y-p0y<0)==(p1y-p0y<0))||((p2x-p0x<0)==(p1x-p0x<0)&&(p2y==p0y)&&(p1y==p0y))||(p0x==p1x&&p1y==p0y)||(p2x==p0x&&p2y==p0y)){
				if(pow(p2x-p0x,2.0)+pow(p2y-p0y,2.0)>pow(p1x-p0x,2.0)+pow(p1y-p0y,2.0)){
					cout<<"ONLINE_FRONT"<<endl;
				}
				else cout<<"ON_SEGMENT"<<endl;
			}
			else cout<<"ONLINE_BACK"<<endl;
		}
		else if(cr>0) cout<<"CLOCKWISE"<<endl;
		else cout<<"COUNTER_CLOCKWISE"<<endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int a[1000];

int main() {
	int n;	scanf("%d", &n);
	for (int i = 1; i <= n; i++)	scanf("%d", &a[i]);
	int sum = 0;
	for (int i = 1; i <= n; i++)	sum += a[i];
	sort(a + 1, a + n + 1);
	printf("%d", sum - a[n] / 2);
	return 0;
}


Measured memory_bytes: 504
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef long long int int64;
typedef unsigned long long int uint64;
typedef float float32;
typedef double float64;
typedef long double float128;


int main(){
    int A[3];
    int sum=0;
    REP(i,3){
        cin >> A[i];
        sum += A[i];
    }
    sort(A,A+3);
    int ans;
    if(sum%2==3*A[2]%2){
        ans = (3*A[2]-sum)/2;
    }else{
        ans = (3*A[2]+3-sum)/2;
    }
    cout << ans;
}




Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt //最初の整数が読み込まれる
    
    //val a = 200
    
    def gcd(x: Long, y: Long): Long = {
        if(y == 0) x
        else gcd(y, (x % y))
    }
    
    def tri_gcd(a: Long,b: Long, c:Long): Long ={
        var a2 = gcd(a,b)
        var b2 = c
        gcd(a2,b2)
    }
    
    var lst: Long = 0

    (1 to a).foreach{
        i =>
        (1 to a).foreach{
          j =>          
            (1 to a).foreach{
                k =>
                lst = lst + tri_gcd(i,j,k)
            }
        }
    }

println(lst)

  }
}


Measured memory_bytes: 56800
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

// #define fio                           \
//     ios_base::sync_with_stdio(false); \
//     cin.tie(Nll);                    \
//     cout.tie(Nll);
#define ll long long
// // #define ll unsigned long long
// #define ll long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    // fio;
    ll t, c, p, a, n, q, k, i, l, m, u, f, j, x, y, b, d;
cin>>a>>b>>c>>d;
cout<<max(max(b*d,a*c),max(b*c,d*a))<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cmath>

const int N=2e5+7;

using namespace std;

int n,A[N];
char s;

int main(){
	cin>>n;
	int tot=0;
	for(int i=1;i<=n;++i){
		cin>>s;
		if(s=='R')
			A[i]=1,tot++;
		else
			A[i]=2;
	}
	int now=0;
	int cnt=0;
	for(int i=1;i<=n;++i){
		if(A[i]==2&&now==0)
			now=i;
		else if(A[i]==1&&now>0&&i>tot){
			swap(A[i],A[now]);
			cnt++;
			now++;
			while(A[now]==1){
				now++;
			}
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int > 
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 5e5 + 10 ;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}



int main(){
	int a , b , v , w , t ;  ; 
	cin>>a>>v>>b>>w>>t ; 
	long long dis = abs(a-b) ; 
	long long s = (v - w) ; 
	if (dis==0)
		cout<<"YES" ; 
	else if (s <= 0)
		cout<<"NO" ; 
	else if (dis/s + (dis%s > 0) <= t)
		cout<<"YES" ; 
	else
		cout<<"NO" ; 
}



Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    ll res = 1;
    ll d = 1;
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n){
        if(a[i]%2==0){
            d*=2;
        }
        res*=3;
    }
    put(res-d);
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n;
    cin>>n;
    int a[n];
    for(int i = 0;i<n;i++){
        cin>>a[i];
    }
    int count = 0;
    sort(a,a+n);
    for(int i = 0;i<n-2;i++){
        for(int j = 1+i;j<n-1;j++){
            for(int k = j+1;k<n;k++){
                if((a[i] + a[j]>a[k]) && a[i]!=a[j] && a[j] != a[k] && a[i]!= a[k]){
                    count++;
                    //cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
                }
            }
        }
    }
    cout<<count<<endl;   
}
int main(){
    int t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3560
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define srep(i) for(int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 1e9
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int N;
int a[100005], b[100005], c[100005];
ll dp[100005][3];

template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

ll all_search(int i, int j) {
    ll res = 0, v1 = 0, v2 = 0;
    if(i - 1 == N) {
        return 0;
    } else if(j == 0) {
        v1 = all_search(i + 1, 1) + b[i];
        v2 = all_search(i + 1, 2) + c[i];
    } else if(j == 1) {
        v1 = all_search(i + 1, 0) + a[i];
        v2 = all_search(i + 1, 2) + c[i];
    } else if(j == 2) {
        v1 = all_search(i + 1, 0) + a[i];
        v2 = all_search(i + 1, 1) + b[i];
    }

    return max(v1, v2);
}

ll dp_recursive(int i, int j) {
    if(dp[i][j] != -1) {
        return dp[i][j];
    }

    ll res = 0, v1 = 0, v2 = 0;
    if(i - 1 == N) {
        return 0;
    } else if(j == 0) {
        v1 = dp_recursive(i + 1, 1) + b[i];
        v2 = dp_recursive(i + 1, 2) + c[i];
    } else if(j == 1) {
        v1 = dp_recursive(i + 1, 0) + a[i];
        v2 = dp_recursive(i + 1, 2) + c[i];
    } else if(j == 2) {
        v1 = dp_recursive(i + 1, 0) + a[i];
        v2 = dp_recursive(i + 1, 1) + b[i];
    }

    return dp[i][j] = max(v1, v2);
}

void dp_for(int n) {
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            if(j == 0) {
                dp[i + 1][j] =
                    a[i + 1] + max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]);
            } else if(j == 1) {
                dp[i + 1][j] =
                    b[i + 1] + max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]);
            } else if(j == 2) {
                dp[i + 1][j] =
                    c[i + 1] + max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]);
            }
        }
    }
}

int main() {
    cin >> N;
    rep(i, N) cin >> a[i] >> b[i] >> c[i];
    memset(dp, -1, sizeof(dp));
    dp_for(N);
    ll ans = 0;
    for(int i = 0; i < 3; i++) {
        ans = max(ans, dp[N][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3712
import java.io.*;
class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] num = line.split(" ");
		int a = Integer.parseInt(num[0]);
		int b = Integer.parseInt(num[1]);
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		}else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 24244
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (long long i = 0; i < (n); ++i)
#define rep(i, a, b) for (long long i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    long long h, n;
    const long long INF = 10000000000;
    cin >> h >> n;
    long long dp[n + 1][20020];
    long long a[n + 1], b[n + 1];
    REP(i, n)
    {
        cin >> a[i] >> b[i];
    }
    REP(i, 20020)
    {
        dp[0][i] = INF;
    }
    REP(i, n + 1)
    {
        dp[i][0] = 0;
    }

    for (long long i = 0; i < n; i++)
    {
        for (long long j = 0; j < 20020; j++)
        {
            if (j < a[i])
            {
                dp[i + 1][j] = dp[i][j];
            }
            else
            {
                dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
            }
        }
    }
    long long ans = INF;
    for (long long i = h; i < 20010; i++)
    {
        if (dp[n][i] < ans)
        {
            ans = dp[n][i];
        }
    }
    cout << ans << endl;
}

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

ll i,j,k,l;

ll mypow(ll a,ll b){
    ll num=1;
    while(b!=0){
        num*=a;
        b--;
    }
    return num;
}

int main(){
    ll n;cin>>n;
    if(n%2==1){cout<<0<<endl;return 0;}
    
    n/=2;
    ll number=1,ans=0;
    while(mypow(5,number)<=n){
        ans+=n/mypow(5,number);
        number++;
    }

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

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

using namespace std;

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

int R, C, n;

int get_bod_id(int x, int y) {
    if (x == 0)
        return y;
    if (y == C - 1)
        return C - 1 + x;
    if (x == R - 1)
        return R + C - 2 + (C - 1 - y);
    if (y == 0)
        return R + 2 * C - 3 + (R - 1 - x);
    return -1;
}

int main() {
#ifdef LOCAL
    // freopen("input", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(12);
    cin >> R >> C >> n;
    R++;
    C++;
    vector<pii> segm;
    for (int i = 0; i < n; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int a = get_bod_id(x1, y1);
        int b = get_bod_id(x2, y2);
        if (a == -1 || b == -1)
            continue;
        if (a > b)
            swap(a, b);
        segm.push_back({a, b});
    }
    sort(segm.begin(), segm.end());
    set<int> was;
    for (auto p : segm) {
        auto it = was.lower_bound(p.first);
        if (it != was.end() && *it <= p.second) {
            cout << "NO\n";
            return 0;
        }
        was.insert(p.second);
    }
    cout << "YES\n";
}

Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int arr[n+1]={0};
	for(int i=1; i<n; i++){
		int boss;
		cin>>boss;
		arr[boss]++;
	}
	for(int i=1; i<=n; i++) cout<<arr[i]<<'\n';
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A >= 13) {
    cout << B << endl;
  }
  else if (A <= 5) {
    cout << 0 << endl;
  }
  else {
    cout << B/2 << endl;
  }
  
  
}


Measured memory_bytes: 256
import numpy as np
a = []
a.append(input().split())
a.append(input().split())
a.append(input().split())
a = np.array(a).astype(int)

N = int(input())
for i in range(N):
    a[a == int(input())] = -1
    
def check(a):
    if a.max(axis=0).min() == -1:
        return "Yes"
    if a.max(axis=1).min() == -1:
        return "Yes"
    if a[0,0] + a[1,1] + a[2,2] == -3:
        return "Yes"
    if a[2,0] + a[1,1] + a[0,2] == -3:
        return "Yes"
    return "No"
print(check(a))

Measured memory_bytes: 12488
def main():
    N,M,D = map(int,input().split())
    s,X,Y = [],[],[]
    for _ in N*[0]:
        s.append(input())
        X.append(M*[0])
        Y.append(M*[0])
    for y in range(0,N,1):
        for x in range(M-1,-1,-1):
            if( s[y][x] != '#' ):
                X[y][x] += 1
            if( s[y][x] != '#' and x+1<M ):
                X[y][x] = X[y][x+1] + 1
    for y in range(N-1,-1,-1):
        for x in range(0,M,1):
            if( s[y][x] != '#' ):
                Y[y][x] += 1
            if( s[y][x] != '#' and y+1<N ):
                Y[y][x] = Y[y+1][x] + 1
    ans = 0
    for y in range(N):
        for x in range(M):
            if( X[y][x] >= D ):
                ans += 1
            if( Y[y][x] >= D ):
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 7812
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define x first
#define y second
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'


int n;
pii arr[200010];
vector<int> gr[200010];
int vis[200010];
int N;
int tree[800010];
void update(int node,int l,int r,int st,int val){
	if(l==r && l==st){
		tree[node]=val;
		return;
	}
	if(st<l || st>r)return ;
	int mid=(l+r)>>1;
	int L=node<<1;
	int R=L|1;
	update(L,l,mid,st,val);
	update(R,mid+1,r,st,val);
	tree[node]=max(tree[L],tree[R]);
}


int query(int node,int l,int r,int st,int en){
	// cout<<"# "<<node<<' '<<l<<' '<<r<<' '<<st<<' '<<en<<endl;
	if(st<= l && r<=en){
		return tree[node];
	}
	if(en<l || r<st)return 0;
	int mid=(l+r)>>1;
	int L=node<<1;
	int R=L|1;
	return max(query(L,l,mid,st,en),query(R,mid+1,r,st,en));
}


void dfs(int u,int par){
	int curr=arr[u-1].y;
	int cuLIS=query(1,1,N,curr,curr);
	int age=query(1,1,N,1,curr-1)+1;
	// update(curr,vis[u]);
	update(1,1,N,curr,max(cuLIS,age));
	vis[u]=query(1,1,N,1,N);
	for(auto xx:gr[u]){
		if(xx!=par){
			dfs(xx,u);
		}
	}
	// update(curr,cuLIS);
	update(1,1,N,curr,cuLIS);
}

int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i].x;
		arr[i].y=i;
	}
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		gr[u].pb(v);
		gr[v].pb(u);
	}
	sort(arr,arr+n);
	int last=-1,val=0;
	for(int i=0;i<n;i++){
		if(last!=arr[i].x){
			val++;
			last=arr[i].x;
		}
		arr[i].x=val;
		swap(arr[i].x,arr[i].y);
	}
	sort(arr,arr+n);
	// for(int i=1;i<=n;i++){
	// 	cout<<i<<' '<<arr[i-1].y<<endl;
	// }
	N=val+3;
	// cout<<N<<endl;
	dfs(1,0);
	for(int i=1;i<=n;i++){
		cout<<vis[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 28348
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
pr pair(int x,int y){return{std::min(x,y),std::max(x,y)};}
int n;
struct treeee{
	int fir[55],deg[55],dis[110],nxt[110],id;
	void clear(){memset(fir,0,sizeof fir);memset(deg,0,sizeof deg);id=0;}
	void link(int a,int b){
		++deg[a],++deg[b];
		nxt[++id]=fir[a],fir[a]=id,dis[id]=b;
		nxt[++id]=fir[b],fir[b]=id,dis[id]=a;
	}
	int FA[55];
	std::vector<int>path[55];
	void DFS(int x,int fa=-1){
		if(fa==-1)path[x].clear();
		path[x].push_back(x);
		for(int i=fir[x];i;i=nxt[i]){
			if(dis[i]==fa)continue;
			FA[dis[i]]=x;
			path[dis[i]]=path[x];
			DFS(dis[i],x);
		}
	}
	bool bad[55];
	std::vector<int>G[51];
	int in[51];
	void Link(int a,int b){++in[b];G[a].push_back(b);}
	int work(const treeee&b){
		for(int i=1;i<=n;++i)G[i].clear();
		memset(in,0,sizeof in);
		for(int i=1;i<=n;++i)if(bad[i]){
			for(int j=fir[i];j;j=nxt[j])
				if(dis[j]!=FA[i])
					Link(dis[j],i);
			for(int j=b.fir[i];j;j=b.nxt[j])
				if(b.dis[j]!=b.FA[i])
					Link(i,b.dis[j]);
			}
		std::queue<int>que;int cnt=0,sum=0;
		for(int i=1;i<=n;++i)sum+=bad[i];
		for(int i=1;i<=n;++i)if(!in[i])que.push(i);
		while(que.size()){
			int x=que.front();que.pop();++cnt;
			for(int i:G[x])if(!--in[i])que.push(i);
		}
		return cnt==n?sum:1919810;
	}
}A,B,C;
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int qwq=gi();
	while(qwq--){
		n=gi();int u,v;
		std::set<pr>sa,sb;
		A.clear(),B.clear();
		for(int i=1;i<n;++i)u=gi(),v=gi(),A.link(u,v),sa.insert(pair(u,v));
		for(int i=1;i<n;++i)u=gi(),v=gi(),B.link(u,v),sb.insert(pair(u,v));
		if(sa==sb){puts("0");continue;}
		int ans=1145141;
		for(int i=1;i<=n;++i)
			if(A.deg[i]==1){
				int t=A.dis[A.fir[i]];
				B.DFS(i);
				for(int j=1;j<=n;++j){
					if(j==t||j==i)continue;
					C.clear();
					for(pr s:sa)
						if(s!=pair(i,t))C.link(s.fi,s.se);
						else C.link(i,j);
					C.DFS(i);
					for(int j=1;j<=n;++j)C.bad[j]=(B.path[j]!=C.path[j]);
					cnk(ans,C.work(B)+1);
				}
			}
		if(ans>n)ans=-1;
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  std::string s;
  std::cin >> s;
  int a = s[0]-'0', b = s[1]-'0', c = s[2]-'0', d = s[3]-'0';
  vt<char> p = {'+','-'};

  rep(i,2) {
    rep(j,2) {
      rep(k,2) {
        int abcd = a + (i == 0 ? b : -b) + (j == 0 ? c : -c) + (k == 0 ? d : -d);
        if(abcd == 7){
          std::cout << a << p[i] << b << p[j] << c << p[k] << d << '=' << 7 << '\n';
          return 0;
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
if n%10 == 2 or n%10 == 4 or n%10 == 5 or n%10 == 7 or n%10 == 9:
    print("hon")
elif n%10 == 0 or n%10 == 1 or n%10 == 6 or n%10 == 8:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 61560
#include <bits/stdc++.h>
using namespace std;
int ps(long long a)
{
	if(a==1)
		return 1;
	long long i;
	for(i=2;i*i<=a;i++)
	{
		if(i*i==a)
		{
			//cout<<i<<endl;
			return 1;
		}
	}
	return 0;
}
int main()
{
	int n, d;
	cin>>n>>d;
	int a[n][d];
	int i, j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<d;j++)
		{
			cin>>a[i][j];
		}
	}
	//cout<<"d="<<d<<endl;
	int count = 0;
	for(i=0;i<n-1;i++)
	{
		for(j=i+1;j<n;j++)
		{
			long long s = 0;
			for(int k = 0; k<d; k++)
			{
				//cout<<a[j][k]<<" "<<a[i][k]<<endl;
				s = s +(a[j][k] - a[i][k])*(a[j][k] - a[i][k]);
			}
			//cout<<"i="<<i<<" s="<<s<<endl;
			//cout<<"s="<<s<<endl;
			if(ps(s)==1)
				count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

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

using namespace std;

#define ll long long 
int main(){
  
  
 int cnt =0 ;
  
  string s;
  int n;
  cin>>n;
  
  
  cin>>s;
  
  for(int i =0 ; i < n-2;i++){
	  if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
	  cnt++;
  }
  
  
  cout<<cnt;


  
  return 0 ;
}


Measured memory_bytes: 3568
#!/usr/bin/env python3
def main():
  # import bisect
  # from collections import Counter
  # from collections import defaultdict
  # from collections import deque
  # from copy import deepcopy
  # from fractions import gcd
  # from heapq import heappop,heappush
  # from itertools import accumulate
  # from itertools import combinations
  # from itertools import permutations
  # from itertools import product
  # from math import ceil,floor, pi
  import sys
  sys.setrecursionlimit(10**6)
  readline = sys.stdin.readline
  ints = lambda: map(int, readline().split())
  floats = lambda: map(float, readline().split())
  pyes = lambda: print("Yes")
  pno = lambda: print("No")
  lli = lambda I, J: [[0] * J for _ in range(I)]
  mod = 10**9+7

  x,y,z = ints()
  print(z,x,y)

if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
// 2^n 全探索

#include  <iostream>
#include  <vector>
#include  <cstdlib>
#include  <cmath>

long long solve0(long long var); // bit全探索
long long solve1(long long var); // 再起全探索
long long solve11(long long p, int q); // 再起全探索(探索の実体)


int main(void)
{
	long long n;
	std::cin >> n;

	long long ans = 0;
	//ans = solve0(n);
	ans = solve0(n);

	std::cout << ans << std::endl;

	return EXIT_SUCCESS;
}

long long solve0(long long var)
{
	long long rtn = 0;
	int d = (int)std::log10(var) + 1;

	// 全パターン探索
	for(int bit = 0; bit < (1 << d-1); ++bit) {
		std::vector<long long> v;
		long long p = var, q = std::pow(10, d-1);

		for(int i = 0; i < d; ++i) {	
			if(bit & (1 << i)) {
				v.push_back(p / q);
				p = p % q;
			}
			q = q / 10;
		}

		v.push_back(p);

		for(std::vector<long long>::iterator it = v.begin(); it != v.end(); ++it)
			rtn += *it;
	}

	return rtn;
}

long long solve1(long long var)
{
	long long rtn = 0;
	int d = (int)std::log10(var) + 1;

	rtn = solve11(var, std::pow(10, d-1));

	return rtn;
}

long long solve11(long long p, int q)
{
	long long rtn = 0;

	if(q == 0)
		return p;
	else
		// (1) '+'を挿入する, (2) '+'を挿入しない
		rtn = solve11(p % q, q / 10) + solve11(p, q / 10);

	return rtn;
}



Measured memory_bytes: 4028
//                                                   ¯\_(ツ)_/¯
  //#pragma GCC optimize("Ofast")
 //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pi pair<int,int>
const int N=100,MOD=998244353;

using namespace std;

int n,m,q;
int pref[505][505];

void pre(){

	 for(int i=1;i<=n;i++)
	 	 for(int j=1;j<=n;j++)
	 		 pref[i][j]= pref[i][j]+pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1];
}

int que(int l,int r){

	  return pref[r][r]-pref[r][l-1]-pref[l-1][r]+pref[l-1][l-1];
}
int main() {

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

		for(int i=0,l,r;i<m;i++)scanf("%d %d",&l,&r),pref[l][r]++;

		pre();

		while(q--){
			int l,r;
			scanf("%d %d",&l,&r);

			printf("%d\n",que(l,r) );

		}

}

Measured memory_bytes: 1920
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,T=LI()
lis=[tuple(LI()) for i in range(N)]
lis.sort()
RES=[[0]*(T+1) for i in range(N+1)]
for i in range(1, N+1):
    A, B = lis[i-1]
    for t in range(T):
        if (t-A >= 0):
            RES[i][t] = max(RES[i-1][t], RES[i-1][t-A]+B)
        else:
            RES[i][t] = RES[i-1][t]
    RES[i][T] = max(RES[i-1][T], RES[i-1][T-1]+B)

print(RES[i][T])


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

static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim()
{
  int u, minv=0;
  int d[MAX], p[MAX], color[MAX];

  for (int i = 0; i < n; i++ )
  {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while ( 1 )
  {
    minv = INFTY;
    u = -1;
    for ( int i = 0; i < n; i++ )
    {
      if ( minv > d[i] && color[i] != BLACK )
      {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1) break;
    color [u] = BLACK;
    for (int k = 0; k < n; k++ )
    {
      if ( color[k] != BLACK && M[u][k] != INFTY )
      {
        if( d[k] > M[u][k] )
        {
          d[k]=M[u][k];
          p[k]=u;
          color[k] = GRAY;
        }
      }
    }
  }
  int sum = 0;
  for ( int i = 0; i< n; i++ )
  {
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }
  return sum;
}

int main()
{
  cin >> n;
  for ( int i = 0; i < n; i++ )
  {
    for ( int j = 0; j < n; j++ )
    {
      int e; cin >> e;
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }
  cout << prim() << endl;
  return 0;
}



Measured memory_bytes: 3108
function main(input) {
  var temp = input.split('\n');
  for (var i = 0; i < temp.length; i++) {
    var temp2 = temp[i].split(' ').map(Number);
    var limit = temp2[0];
    var target = temp2[1];
    if (!limit && !target)
      break;
    var count = 0;
    for (var j = 1; j < limit - 1; j++) {
      for (var k = j + 1; k < limit; k++) {
        for (var l = k + 1; l < limit + 1; l++) {
          if ((j + k + l) == target) {
            count++;
          }
        }
      }
    }
    console.log(count)
  }
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);


Measured memory_bytes: 16336
#include <stdio.h>
#include <string.h>
#include <tuple>
#include <algorithm>
using namespace std;

constexpr int kN = int(5E5 + 10);

struct BIT {
	int val[kN];
	void init() {memset(val, 0, sizeof(val));}
	void add(int pos, int x) {
		//printf("add(%d, %d)\n", pos, x);
		while (pos < kN) {
			val[pos] += x;
			pos += pos & -pos;
		}
		//printf("return\n");
		return ;
	}
	int ask(int pos) {
		//printf("ask(%d)\n", pos);
		int ans = 0;
		while (pos) {
			ans += val[pos];
			pos ^= pos & -pos;
		}
		//printf("return\n");
		return ans;
	}
};

BIT bit;
int c[kN], ans[kN], lst[kN];
tuple<int, int, int> p[kN];

int main() {
	int n, q, l, r, pos = 0;
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
	for (int i = 1; i <= q; i++) {
		scanf("%d%d", &l, &r);
		p[i] = {r, l, i};
	}
	sort(p + 1, p + 1 + q);
	bit.init();
	for (int i = 1; i <= q; i++) {
		while (pos < get<0>(p[i])) {
			++pos;
			bit.add(1, 1);
			bit.add(pos + 1, -1);
			if (lst[c[pos]] > 0) {
				bit.add(1, -1);
				bit.add(lst[c[pos]] + 1, 1);
			}
			lst[c[pos]] = pos;
		}
		ans[get<2>(p[i])] = bit.ask(get<1>(p[i]));
	}
	for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 17268
#include <iostream>

using namespace std;

int main()
{
    int a1 , a2 , a3;
    cin >> a1 >> a2 >> a3;
    if (a1 + a2 + a3 >= 22){
        cout << "bust";
    }else{
        cout << "win";
    }
    return 0;
}


Measured memory_bytes: 3620
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
int main(){
int counter1,counter2;
counter1=0;
counter2=0;
int N;
cin>>N;
string str;
cin>>str;
for (int i=1;i<str.size();i++){
if (str.at(i)=='E')
counter1++;}
counter2=counter1;
for (int i=1;i<str.size();i++){
if (str.at(i-1)=='W'){
counter1++;}
if (str.at(i)=='E'){
counter1--;}
counter2=min(counter1,counter2);}
cout<<counter2<<endl;}




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


int main() {
  int n;
  cin >> n;
  long long int S = 0;
  vector<int> A(n);

  for (int i = 0;i < n;i++){
    cin >> A.at(i);
    S+=A.at(i);
  }
  sort(A.begin(),A.end());
  cout << A.at(0) << " " << A.at(n-1) << " " <<  S << endl;


}


Measured memory_bytes: 3176
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
ll gcd(ll a, ll b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
int a[202020];
int main()
{
	int num,gen;
	scanf("%d%d", &num, &gen);
	for (int i = 0; i < num; i++)scanf("%d", &a[i]);
	a[num] = 2100000000;
	int r = 0;
	for (int i = 0; i < num; i++)r += min(gen, a[i + 1] - a[i]);
	printf("%d\n", r);
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >=0; i--)
#define lint long long
#define all(x) (x).begin(), (x).end()


int main(){
    int q; cin>>q;
    priority_queue<long, vector<long>, greater<long> > L, R; long c = 0; int k = 0;
    long lsum,rsum,bsum; lsum=rsum=bsum=0;
    rep(i,q){
        int flag; cin>>flag;
        if(flag == 1){
            long a,b; cin>>a>>b;
            k++;
            bsum += b;
            if (k%2 == 0){
                if (a < c){
                    L.push(-a); R.push(c);
                    lsum -= a; rsum += c;
                }
                else{
                    L.push(-c); R.push(a);
                    lsum -= c; rsum += a;
                }
            }
            else if(!L.empty()){
                long lmax = -L.top(); long rmin = R.top();
                if(a < lmax){
                    L.pop(); L.push(-a); c = lmax;
                    lsum -= (a-lmax);
                }
                else if(rmin < a){
                    R.pop(); R.push(a); c = rmin;
                    rsum += (a-rmin);
                }
                else c = a;
            }
            else c = a;
        }
        else{
            long arg, val;
            if (k%2 == 0) arg = -L.top();
            else arg = c;
            val = lsum + rsum + bsum;
            cout << arg << " " << val << endl;
        }
    }
}

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

int main() {
	string s1, s2;
	cin >> s1 >> s2;
	int n = s1.size(), m = s2.size();
	int dp[n + 1][m + 1];
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i == 0 || j == 0)
				dp[i][j] = 0;
			else if (s1[i - 1] == s2[j - 1])
				dp[i][j] = 1 + dp[i - 1][j - 1];
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	int i = n, j = m;
	string s = "";
	while (i > 0 && j > 0) {
		if (s1[i - 1] == s2[j - 1]) {
			s += s1[i - 1];
			i--, j--;
		}
		else if (dp[i - 1][j] > dp[i][j - 1]) {
			i--;
		}
		else {
			j--;
		}
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int a,b,c,d;
signed main(){
    cin>>a>>b>>c>>d;
    bool ans=false;
    if(abs(a-c)<=d)ans=true;
    if(abs(a-b)<=d&&abs(b-c)<=d)ans=true;
    cout<<(ans?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  vector<int> c(n-1);
  vector<int> s(n-1);
  vector<int> f(n-1);
  for (int i = 0; i < n - 1; i++) {
    cin >> c[i] >> s[i] >> f[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int t = 0;
    for (int j = i; j < n - 1; j++) {
      if (t <= s[j]) {
        t = s[j] + c[j];
      } else {
        t = s[j] + ((t - s[j] + f[j] - 1) / f[j]) * f[j] + c[j];
      }
    }
    cout << t << '\n';
  }
  cout << 0 << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
 
const int N = (int) 2e5 + 7;
const int INF = (int) 1e9 + 7;
 
int x, y;
int a[N];
int ans[N];
vector<int> g[N];
multiset<int> ms;
 
void dfs(int s, int p) {
	ms.insert(a[s]);
	auto it = ms.lower_bound(a[s]);
	int rem = -1;
	if (++it != ms.end()) {
		rem = *it;
		ms.erase(it);
	}
	ans[s] = ms.size();
 
	for (auto next : g[s]) {
		if (next != p)
			dfs(next, s);
	}

	ms.erase(a[s]);
	if (rem != -1) {
		ms.insert(rem);
	}
 
}
 
 
int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
 
	int n;
	sf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		sf("%d", &a[i]);
	}
 
	for (int i = 0; i < n - 1; ++i) {
		sf("%d %d", &x, &y);
		g[x].pp(y);
		g[y].pp(x);
	}
 
	dfs(1, 0);
 
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", ans[i]);
	}
 
	return 0;
}


Measured memory_bytes: 28184
# -*- coding: utf-8 -*-
import sys

N, D = map(int, input().split())
s_lines = sys.stdin.readlines()

ans = 0
X_list_list = []
for s in s_lines:
    new_list = list(map(int, s.split()))
    for i in range(len(X_list_list)):
        sum_num = float(0)
        for idx, ite in enumerate(X_list_list[i]):
            sum_num += (new_list[idx] - ite) ** 2
        if pow(sum_num, 0.5).is_integer():
            ans += 1
    X_list_list.append(new_list)

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
typedef long long int ll;
const int INF = 100000000;

using namespace std;
int main() {
	int a,k;
	cin >> a >> k;
	vector<int> d(k);
	for (int i = 0; i < k; ++i) {
		cin >> d[i];
	}
	int w = 10000;
	vector<int> n;
	int x;
	while (w) {
		if (a) {
			x = a / w;
			if (x) {
				n.push_back(x);
				a -= x * w;
				
			}
		}
		else {
			n.push_back(0);
		}
		w = w / 10;
	}

	int p = 10;
	int mi = 10;
	for (int i = 9; i >= 0; --i) {
		int f = 0;
		for (int j = 0; j < (int)d.size(); ++j) {
			if (i == d[j]) {
				f = 1;
			}
		}
		if (!f) {
			mi = i;
			if (i != 0)p = i;
		}
	}
	int kuri = 0,up=0;
	vector<int> ans = n;
	for (int i = ans.size() - 1;i>=0 ; --i) {
		if (kuri) {
			ans[i]++;
			kuri = 0;
		}
		for (int j = 0; j < d.size(); ++j) {
			if (ans[i] == d[j]) {
				ans[i]++;
				for (int j = i+1; j < ans.size(); ++j)ans[j] = mi;
			}
		}
		if (ans[i] >= 10) {
			ans[i] = mi;
			kuri = 1;
		}
	}
	if (kuri) {
		printf("%d", p);
	}

	for (int i = 0; i < (int)ans.size(); ++i)printf("%d", ans[i]);
	printf("\n");

	int b;
	cin >> b;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <sstream>
#include <cctype>
using namespace std;

#define PQ priority_queue
#define P pair<int,int>
#define CLA(array) memset(array,0,sizeof array)
#define CLINF(array) memset(array,0x3f,sizeof array)
#define CLF(array) memset(array,-1,sizeof array)
#define DB(a) cout << "DEBUG " << a << endl;
#define lowbit(x) (x)&(-x)
#define fi first
#define se second
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 100000 + 10;
const int INF = 0x3f3f3f3f;
int q, h, s, d;
int n;
int main(){
    //ios_base::sync_with_stdio(false);
	scanf("%d%d%d%d", &q, &h, &s, &d);
	scanf("%d", &n);
	int m = min(4*q, min(2*h, s));
	LL sum = 0;
	if(2*m > d){
		sum += 1ll*d*(n/2);
		n -= 2*(n/2);
	}
	sum += 1ll*m*n;
	printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <cassert>
using namespace std;
const int MAXN = 505;
const int INF = 1000000;
long long int A[MAXN][MAXN], csum[MAXN][MAXN];
int main()
{
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	int tot = 0;
	for (int i = 1; i <= H; ++i)
	{
		for (int j = 1; j <= W; ++j)
		{
			if(i%h == 0 && j%w == 0)
			{
				A[i][j] = h*w*-1;
			}
			else
			{
				A[i][j] = 1;
			}
		}
	}
	for (int i = 1; i <= H; ++i)
	{
		for (int j = 1; j <= W; ++j)
		{
			if(i%h == 1 && j%w == 0)
			{
				A[i][j]+=INF;
				if(i + h - 1 <= H)
					A[i+h-1][j]-=INF;
			}
			if(i%h == 0 && j%w == 1)
			{
				A[i][j]+=INF;
				if(j + w - 1 <= W)
					A[i][j+w-1]-=INF;
			}
		}
	}
	for (int i = 1; i < MAXN; ++i)
	{
		for (int j = 1; j < MAXN; ++j)
		{
			csum[i][j] = (csum[i-1][j] + csum[i][j-1] - csum[i-1][j-1] + A[i][j]);
		}
	}
	bool ok = (csum[H][W] > 0);
	for (int i = h; i <= H; ++i)
	{
		for (int j = w; j <= W; ++j)
		{
			if(csum[i][j] - csum[i-h][j] - csum[i][j-w] + csum[i-h][j-w] >= 0)
				ok = false;
		}
	}
	if(ok)
	{
		cout<<"Yes\n";
		for (int i = 1; i <= H; ++i)
		{
			for (int j = 1; j <= W; ++j)
			{
				cout<<A[i][j]<<" ";
			}
			cout<<"\n";
		}
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int n;
vector<long long> vec;
long long in;
long long out[110100];

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> in;
		vec.push_back(in);
	}
	sort(vec.begin(), vec.end());

	int index = n / 2;
	index -= ((n % 2) == 0);
	int left = index - 1;
	int right = index + 1;
	int endIndex = vec.size() - 1;
	int startIndex = 1;
	out[index] = vec[0];
	for (int i = 0; i < n / 2 - 1; i++)
	{
		if ((i % 2) == 0)
		{
			out[left] = vec[endIndex--];
			out[right] = vec[endIndex--];
			left--;
			right++;
		}
		else
		{
			out[right] = vec[startIndex++];
			out[left] = vec[startIndex++];
			left--;
			right++;
		}
		/*for (int j = 0; j < n; j++)
		{
			cout << out[j];
		}
		cout << endl;*/
	}
	if ((n % 2) == 0)
	{
		out[right] = vec[startIndex++];
	}
	else
	{
		out[right] = vec[startIndex++];
		out[left] = vec[startIndex++];

	}
	long long sum = 0;

	for (int i = 0; i < n - 1; i++)
	{
		sum += abs(out[i] - out[i + 1]);
		//cout << out[i];
	}

	for (int i = 0; i < n; i++)
	{
		out[i] = 0;
	}

	index = n / 2;
	left = index - 1;
	right = index + 1;
	endIndex = vec.size() - 1;
	startIndex = 0;
	out[index] = vec[endIndex--];
	for (int i = 0; i < n / 2 - 1; i++)
	{
		if ((i % 2) == 0)
		{
			out[left] = vec[startIndex++];
			out[right] = vec[startIndex++];
			left--;
			right++;
		}
		else
		{
			out[left] = vec[endIndex--];
			out[right] = vec[endIndex--];
			left--;
			right++;
		}

	}
	if ((n % 2) == 0)
	{
		out[left] = vec[endIndex--];
	}
	else
	{
		
		out[left] = vec[endIndex--];
		out[right] = vec[endIndex--];

	}
	long long sum2 = 0;
	/*for (int i = 0; i < n; i++)
	{
		cout << out[i];
	}*/
	for (int i = 0; i < n - 1; i++)
	{
		sum2 += abs(out[i] - out[i + 1]);
		//cout << out[i];
	}
	if (sum >= sum2)
	{
		cout << sum;
	}
	else
	{
		cout << sum2;
	}

	


	return 0;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, m;
    cin >> n >> m;
    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> x(m);
    rep(i,m) cin >> x[i];
    sort(x.begin(), x.end());
    priority_queue<int> q;
    rep(i,m-1) {
        int a = x[i+1] - x[i];
        q.push(a);
    }
    rep(i,n-1) {
        q.pop();
    }
    int ans = 0;
    while (!q.empty()) {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll a,b,s;
    cin>>a>>b;
    if(a+b < 10)
    {
        cout<<a+b<<endl;
    }
    else
    {
        cout<<"error\n";
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, sum[200001] = {};
    cin >> N;
    REP(i, N - 1) {
        int A;
        cin >> A;
        sum[A - 1]++;
    }
    REP(i, N) cout << sum[i] << endl;
    return 0;
}

Measured memory_bytes: 4412
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
char getNext(char now,int way){
  switch(now){
  case 'a':
    return way?'y':'x';
  case 'x':
    return way?'z':'o';
  case 'z':
    return way?'b':'w';
  case 'b':
    return way?'x':'y';
  case 'w':
    return way?'y':'b';
  case 'y':
    return way?'o':'x';
  default:
    return 'o';
  }
}
int main(){
 
  string root="";
  while(cin >> root && root!="#"){
    char start='a';
    for(int i=0;i<root.size();i++){
      start=getNext(start,(int)root[i]-'0');
    if(start=='o')
      break;
    }
    if(start=='b')
    cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }  
  return 0;
  
}

Measured memory_bytes: 1188
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	int A[100000] = {};
	for (int i = 0; i < N; i++) {
		int Ai;
		cin >> Ai;
		A[Ai-1]++;
		if (A[Ai-1] == 3) A[Ai-1] = 1;
	}

	int ans = 0;
	int two = 0;
	for (int i = 0; i < 100000; i++) {
		if (A[i] > 0) ans++;
		if (A[i] == 2) two++; 
	}

	if (two % 2 == 1) ans--;

	cout << ans << endl;

	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const int NN = 111;
const int WW = 11111;
int N, W;
int w[NN], v[NN];

int bitBruteForth() {
   int ans = 0;
   rep (mask, (1<<N)) {
      int value = 0, weight = 0;;
      rep (i, N) {
         if ((mask>>i)&1) {
            value += v[i];
            weight += w[i];
         }
      }
      if (weight <= W) {
         ans = max(ans, value);
      }
   }
   return ans;
}

// int dfs(今の状態) {
//    int ret = 0;
//    for (...) ret += dfs(次の状態);
//    return ret;
// }

int dp[NN+1][WW+1];

int rec(int idx, int wLim) {
   if (idx == N) {
      return 0;
   } else if (wLim < w[idx]) {
      return rec(idx + 1, wLim);
   } else {
      int in = rec(idx + 1, wLim - w[idx]) + v[idx];
      int noIn = rec(idx + 1, wLim);
      return max(in, noIn);
   }
}

// int memo(int idx, int wLim) {
//    if (dp[idx][wLim] >= 0) {
//       return dp[idx][wLim];
//    }

//    int res;
//    if (idx == N) {
//       res = 0;
//    } else if (wLim < w[idx]) {
//       res = memo(idx + 1, wLim);
//    } else {
//       int in = memo(idx + 1, wLim - w[idx]) + v[idx];
//       int noIn = memo(idx + 1, wLim);
//       res = max(in, noIn);
//    }

//    return dp[idx][wLim] = res;
// }

int memo(int idx, int wLim) {
   if (dp[idx][wLim] >= 0) {
      return dp[idx][wLim];
   }

   if (idx == N) {
      return 0;
   } else if (wLim < w[idx]) {
      return memo(idx + 1, wLim);
   } else {
      int in = memo(idx + 1, wLim - w[idx]) + v[idx];
      int noIn = memo(idx + 1, wLim);
      return dp[idx][wLim] = max(in, noIn);
   }
}

int main() {
   cin >> N >> W;
   rep (i, NN+1) {
      rep (j, WW+1) {
         dp[i][j] = -1;
      }
   }
   rep (i, N) {
      cin >> v[i] >> w[i];
   }

   // cout << rec(0, W) << endl;
   cout << memo(0, W) << endl;

   return 0;
}


Measured memory_bytes: 7996