akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define IN(n) int n; cin>>n;
#define ARR(arr,i,n) int arr[n]; REP(i,0,n){cin>>arr[i];}
#define MOD 1000000007

using namespace std;

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

    // code comes here
    int n,r;
    cin>>n>>r;


    if(n>=10)
    {

        cout<<r<<endl;
    }
    else
    {

        cout<<r+100*(10-n)<<endl;
    }


    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
#define N 101

int a[N];
int count=0;

void swap(int *x,int *y){
  int t=*x;
  *x=*y;
  *y=t;
}

void bubblesort(int n){
  int i;
  for(i=0;i<n;i++){ // ??????????????¨???????????????????´???????
    int j;
    for(j=n-1;j>i;j--){
      if(a[j]<a[j-1]){
	swap(&a[j],&a[j-1]);
	count++;
      }
    }
  }
}

int main()
{
  int n;
  scanf("%d",&n);
  int i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  bubblesort(n);
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i<n-1) printf(" ");
  }
  printf("\n%d\n",count);
  
  return 0;
}

Measured memory_bytes: 604
/******************************************
* AUTHOR : Eaugene Thomas
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main() {
faster;
string s="";
cin>>s;
int c=0;
for(int i=0;i<s.length();i++)
{
	if(s[i]=='2')
	c++;
}
cout<<c<<"\n";
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int q,i;
long long c[100],d[100],a[100],b[100],e[100];
double x; 
int main()
{ 
  cin >> q;
  for(i=0;i<q;i++){cin >> a[i] >> b[i];
                   c[i]=a[i]*b[i];
                   x=sqrt(c[i])-2;
                   d[i]=x;
                   while(d[i]*d[i]<c[i]){
                     d[i]++;
                   }
                  }
  for(i=0;i<q;i++){cin >> a[i] >> b[i];
                   c[i]=a[i]*b[i];
                   x=sqrt(c[i])-2;
                   e[i]=x;
                   while(e[i]*(e[i]+1)<c[i]){
                     e[i]++;
                   }
                  }
for(i=0;i<q;i++){
  if(a[i]!=b[i]){
    if((d[i]-1)*2-2<(e[i]-1)*2-1)printf("%lld\n",(e[i]-1)*2-1);
    else printf("%lld\n",(d[i]-1)*2-2);
  }else{
    if((d[i]-1)*2-2<(e[i]-1)*2-1)printf("%lld\n",(e[i]-1)*2);
    else printf("%lld\n",(d[i]-1)*2-1);
                }
}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#define max(x,y) x > y ? x : y
#define min(x,y) x < y ? x : y
int main(){
	long long n,a,b;
  std::cin >> n >> a >> b;
  long long t = min(a,b);
 	std::cout << t;
  long long tmp = (max(a,b)) - n + (min(a,b));
  //tmp = -tmp;
  if (tmp <0) tmp = 0;
  std::cout << " " << tmp;
}

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

int a[110];

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

    int n,m,x;
    cin>>n>>m>>x;

    int l=0,r=0;

    for(int i=0;i<m;i++)
    {
        int a;
        cin>>a;
        if(a<x)l++;
        else r++;
    }

    cout<<min(l,r)<<"\n";

    return 0;
}


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

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	int m1, m2, d1, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (m1 != m2) { cout << "1" << endl; }
	else { cout << "0" << endl; }
	return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long
using namespace std;
int main()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    int i;
    i=d-b;
    while(i--)
        cout<<"U";
    i=c-a;
    while(i--)
        cout<<"R";
    i=d-b;
    while(i--)
        cout<<"D";
    i=c-a;
    while(i--)
        cout<<"L";
    cout<<"L";
    i=d-b+1;
    while(i--)
        cout<<"U";
    i=c-a+1;
    while(i--)
        cout<<"R";
    cout<<"D";
    cout<<"R";
    i=d-b+1;
    while(i--)
        cout<<"D";
    i=c-a+1;
    while(i--)
        cout<<"L";
    cout<<"U";
    return 0;
}

Measured memory_bytes: 256
S = input()
n = len(S)
SS = list(map(int, S))
A1 = [x&1 for x in range(n)]
A2 = [x&1 for x in range(1, n+1)]

cnt = [0, 0]
for i in range(n):
    cnt[0] += abs(SS[i] - A1[i])
    cnt[1] += abs(SS[i] - A2[i])

print(min(cnt))

Measured memory_bytes: 5620
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main() {
int N,M,X;
cin>>N>>M>>X;
int C[N],A[N][M];
rep(i,N){
  cin>>C[i];
  rep(j,M){
    cin>>A[i][j];
  }
}
int min_cost=1e8;
rep(i,1<<N){
  vector<int> master(M,0);
  rep(j,N){
    if((i>>j)&1){
      rep(k,M){
        master[k]+=A[j][k];
      }
    }

  }
  bool judge=true;
  rep(k,M){
    if(master[k]<X){
      judge=false;
    }
  }
  if(judge){
    int cost=0;
    rep(j,N){
      if((i>>j)&1){
        cost+=C[j];
      }
    }
    min_cost=min(min_cost,cost);

  }
}

if(min_cost==1e8){
  cout<<-1<<endl;
}
else{
  cout<<min_cost<<endl;
}



return 0;
}

Measured memory_bytes: 3632
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix

N = int(input())
A = []
for i in range(N):
    x, y = map(int, input().split())
    A.append((i, x, y))

length, frm, to = [], [], []
path_set = set()


def path(axis):
    A.sort(key=lambda x: x[axis])
    for i in range(N - 1):
        if (A[i][0], A[i + 1][0]) in path_set:
            continue
        length.append(min(abs(A[i][1] - A[i + 1][1]),
                          abs(A[i][2] - A[i + 1][2])))
        frm.append(A[i][0])
        to.append(A[i + 1][0])
        path_set.add((A[i][0], A[i + 1][0]))


path(1)
path(2)
matr = csr_matrix((length, (frm, to)), shape=(N, N))

T = minimum_spanning_tree(matr).astype(int)
print(sum(T.data))


Measured memory_bytes: 75536
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
	int a, b;
  	cin >> a >> b;

  	for(int i=1;i<=3;i++){
  		if(i!=a && i!=b) cout << i <<endl;
  	}

    
  	return 0;
}





Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

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

  cout<<c<<" "<<a<<" "<<b<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int gcd(int a, int b) {
  if (b > a) {
  	int tmp = a;
    a = b;
    b = tmp;
  }
  if (b == 0) return a;
  return gcd(b, a%b);
}
int main() {
	int k;
  	cin >> k;
  	int sum = 0;
  	int gcd1;
  	for (int i = 1; i <= k; i++) {
    	for (int j= 1; j <= k; j++) {
          	gcd1 = gcd(i, j);
        	for (int l = 1; l <= k; l++) {
              	sum += gcd(l, gcd1);
            }
        }
    }
  cout << sum;
  return 0;
}

Measured memory_bytes: 3152
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(double x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};
// ll pas[5001][5002];
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) { cin >> a[i]; }
	ll g = a[0];
	for (int i = 1; i < n; ++i) { g = gcd(g, a[i]); }
	dump(g);
	return 0;
}

Measured memory_bytes: 1024
N,M = map(int,input().split())
Ss = []
for m in range(M):
    S = list(map(int,input().split()))
    Ss.append(S[1:])
ps = list(map(int,input().split()))
output= []
for i in range(1 << N):
    nums = []
    for j in range(N):
        if ((i >> j) & 1) == 1:
            nums.append(1)
        else:
            nums.append(0)
    output.append(nums)
ans = 0
for out in output:
    num = 0
    for (s,p) in zip(Ss,ps):
        count = 0
        for ss in s:
            if out[ss-1]==1:
                count+=1
        if count%2==p:
            num+=1
    if num==len(ps):
        ans+=1
print(ans)

Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		int w = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int ch = Integer.parseInt(sa[0]) - 1;
		int cw = Integer.parseInt(sa[1]) - 1;
		sa = br.readLine().split(" ");
		int dh = Integer.parseInt(sa[0]) - 1;
		int dw = Integer.parseInt(sa[1]) - 1;
		char[][] s = new char[h][w];
		for (int i = 0; i < h; i++) {
			s[i] = br.readLine().toCharArray();
		}
		br.close();

		int[][] d = new int[h][w];
		for (int i = 0; i < h; i++) {
			Arrays.fill(d[i], Integer.MAX_VALUE);
		}

		Deque<Integer> que = new ArrayDeque<>();
		que.add(ch * w + cw);
		d[ch][cw] = 0;
		while (!que.isEmpty()) {
			int cur = que.poll();
			int cx = cur / w;
			int cy = cur % w;
			for (int nx = cx - 2; nx <= cx + 2; nx++) {
				if (nx < 0 || h <= nx) {
					continue;
				}
				for (int ny = cy - 2; ny <= cy + 2; ny++) {
					if (ny < 0 || w <= ny) {
						continue;
					}
					if (s[nx][ny] == '#') {
						continue;
					}
					if (d[nx][ny] > d[cx][cy]) {
						if (d[nx][ny] > d[cx][cy] &&
								Math.abs(nx - cx) + Math.abs(ny - cy) <= 1) {
							d[nx][ny] = d[cx][cy];
							que.addFirst(nx * w + ny);
						} else if (d[nx][ny] > d[cx][cy] + 1) {
							d[nx][ny] = d[cx][cy] + 1;
							que.addLast(nx * w + ny);
						}
					}
				}
			}
		}
		if (d[dh][dw] == Integer.MAX_VALUE) {
			System.out.println(-1);
		} else {
			System.out.println(d[dh][dw]);
		}
	}
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<long long,long long> ii;
vector<pair<long long,ii>> edge;
long long n,up[100005],sz[100005];
pair<ii,long long> x[100005];

bool cmp(const pair<ii,long long> &a,const pair<ii,long long> &b){
    return a.fi.fi<b.fi.fi;
}
bool cmp1(const pair<ii,long long> &a,const pair<ii,long long> &b){
    return a.fi.se<b.fi.se;
}
int findSet(int x){
    if(x==up[x]) return x;
    else return findSet(up[x]);
}
void unionSet(int x,int y){
    long long x1=findSet(x),y1=findSet(y);
    if(sz[x1]<sz[y1]) swap(x1,y1);
    up[y1]=x1;
    sz[x1]+=sz[y1];
}
bool checkSet(int x,int y){
    long long x1=findSet(x),x2=findSet(y);
    if(x1==x2)
        return 1;
    else
        return 0;
}
int main(){
    cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i].fi.fi>>x[i].fi.se;
        x[i].se=i;
    }
    sort(x+1,x+1+n,cmp);
    for(int i=1;i<=n;i++){
        up[i]=i;
        sz[i]=1;
    }
    for(int i=1;i<n;i++){
        long long x1=x[i].se,x2=x[i+1].se;
        long long val=abs(x[i].fi.fi-x[i+1].fi.fi),val1=abs(x[i].fi.se-x[i+1].fi.se);
        edge.pb(mp(val,mp(x1,x2)));
    }
    sort(x+1,x+1+n,cmp1);
    for(int i=1;i<n;i++){
        long long x1=x[i].se,x2=x[i+1].se;
        long long val=abs(x[i].fi.fi-x[i+1].fi.fi),val1=abs(x[i].fi.se-x[i+1].fi.se);
        edge.pb(mp(val1,mp(x1,x2)));
    }
    long long sum=0;
    sort(edge.begin(),edge.end());
    for(int i=0;i<edge.size();i++){
        long long x1=edge[i].se.fi,x2=edge[i].se.se;
        if(checkSet(x1,x2)==0){
            unionSet(x1,x2);
            sum+=edge[i].fi;
        }
    }
    cout<<sum;
}


Measured memory_bytes: 12400
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	int n;
	cin >> n;
	REP(i, n) {
		string d;
		cin >> d;
		if (d == "nobiro") {
			x += a;
		}
		else if (d == "tidime") {
			x += b;
		}
		else {
			x = 0;
		}
		x = max(x, 0);
	}
	cout << x << endl;
}


Measured memory_bytes: 3208
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;

class Connection{
private:
    ll v;
    vector<vector<ll>> E;
    vector<ll> tree; //depth
    vector<bool> con;
    
    pll dfs(ll where,ll count){
        tree[where]=count;
        ll c=0;
        ll mx_c=0;
        ll mi_c=count;
        ll mi_m=count;
        count++;
        for(int i=0;i<E[where].size();i++){
            ll t=E[where][i];
            if(tree[t]==-1){
                pll child=dfs(t,count);
                mx_c=max(mx_c,child.F);
                mi_c=min(mi_c,child.F);
                c++;
                if(child.S==0){con[t]=false;}
            }
            else{
                mi_m=min(mi_m,tree[t]);
            }
        }
        if(mx_c!=tree[where]){con[where]=false;}
        return {min(mi_c,mi_m),c};
    }
    
    void clear(){
        tree.resize(v);
        con.resize(v);
        for(int i=0;i<v;i++){
            tree[i]=-1;
            con[i]=true;
        }
    }
    
public:
    Connection(ll v):v(v){
        E.resize(v);
    }
    
    void add_edge(ll from,ll to){
        E[from].push_back(to);
        E[to].push_back(from);
    }
    
    vector<ll> search(){
        clear();
        vector<ll> ret;
        for(int i=0;i<v;i++){
            if(tree[i]==-1){
                ll r=dfs(i,0).S;
                if(r<2){con[i]=false;}
            }
        }
        for(int i=0;i<v;i++){
            if(con[i]){
                ret.push_back(i);
            }
        }
        for(int i=0;i<v;i++){
            //cout<<i<<" "<<tree[i]<<endl;
        }
        return ret;
    }
};



int main(){
    ll v,e;
    cin>>v>>e;
    Connection C(v);
    for(int i=0;i<e;i++){
        ll s,t;
        cin>>s>>t;
        C.add_edge(s,t);
    }
    vector<ll> ans=C.search();
    for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 5220
#include <iostream>
#include <string>

#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cout << #x << ": " << x << endl

// five-five-everywhere.cpp ---
// author: Seong Yong-ju <sei40kr@gmail.com>

using namespace std;

int n;
bool ps[55556] = {false, false};

int main() {
  std::ios::sync_with_stdio(false);

  cin >> n;
  fill(&ps[2], ps + 55555, true);
  for (int i = 2; i <= 55555; ++i) {
    if (!ps[i]) {
      continue;
    }
    for (int j = i * 2; j <= 55555; j += i) {
      ps[j] = false;
    }
  }
  REP(i, 55556) { ps[i] = (ps[i] && i % 5 == 1); }

  int cnt = 0;
  REP(i, 55556) {
    if (ps[i]) {
      if (n <= ++cnt) {
        cout << i << endl;
        break;
      } else {
        cout << i << ' ';
      }
    }
  }

  return 0;
}


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

int main(){
	
	int a,b,k;
	cin >> a >> b >> k;
	int cnt = 0;
  	vector<int> num;
  
	for (int i = 1; i < 101; i++)
	{
		if(a%i==0 && b%i ==0){
			num.push_back(i);
		}
	}
  	cout << num[num.size()-k] << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var k, s int
	fmt.Scan(&k, &s)

	var cnt int
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z := s - (x + y)
			if x+y <= s && z <= k {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sca = new Scanner(System.in);
		int n = sca.nextInt();
		String str = sca.next();
		int length = str.length();
		int an[] = new int[length];


		int result = 0;
		for(int i = 0; i < length; i++) {
			an[i] = (str.charAt(i) - '0');
		}
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				for(int k = 0; k < 10; k++) {
					int bn[] = new int[3];
					bn[0] = i;
					bn[1] = j;
					bn[2] = k;
					boolean flag1 = false;
					boolean flag2 = false;
					boolean flag3 = false;
					for(int l = 0; l < length; l++) {
						if(flag1 != true && an[l] == bn[0]) {
							flag1 = true;
							continue;
						}
						if(flag1 == true && flag2 != true && an[l] == bn[1]) {
							flag2 = true;
							continue;
						}
						if(flag1 == true && flag2 == true && flag3 != true && an[l] == bn[2]) {
							flag3 = true;
							continue;
						}
					}
					if(flag1 == true && flag2 == true && flag3 == true) {
						result++;
					}
				}
			}
		}
		System.out.println(result);
	}
}


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

using namespace std;

#define ll long long

ll cnt[26];

int main() {
    string s;
    cin>>s;
    ll n=(ll)s.size();
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<s.size();i++) {
        cnt[s[i]-'a']++;
    }
    
    ll ans=n*(n-1)/2;
    for(int i=0;i<26;i++) {
        ans-=cnt[i]*(cnt[i]-1)/2;
    }
    ans++;
    cout<<ans<<endl;
    
    return 0;;
}

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, p;
  cin >> n >> p;
  unordered_map<ll, ll> mp;
  ll t = p;
  while (t % 2 == 0)
  {
    mp[2]++;
    t /= 2;
  }
  for (ll i = 3; i <= sqrt(p) + 1; i += 2)
  {
    if (t == 1)
      break;
    while (t % i == 0)
    {
      mp[i]++;
      t /= i;
    }
  }
  mp[t]++;
  ll ans = 1;
  for (auto &e : mp)
  {
    if (e.second >= n)
      ans *= pow(e.first, (e.second / n));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,i;
  cin >> n;
  vector<double> v(n);
  for(i=0;i<n;i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  double ans=(v[0]+v[1])/2;
  for(i=2;i<n;i++){
    ans=(ans+v[i])/2;
  }
  printf("%.12lf\n",ans);
  return 0;
}

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


int main()
{
    long long int n,k;
    scanf("%lld %lld",&n,&k);
    n%=k;
    if(n>k-n)
        printf("%lld\n",k-n);
    else
        printf("%lld\n",n);
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut raw_s: String = String::new();
    io::stdin().read_line(&mut raw_s).ok();
    raw_s.pop();
    
    let s_vec: Vec<&str> = raw_s.split(' ').collect();
    let A: i32 = s_vec[0].parse().unwrap();
    let B: i32 = s_vec[1].parse().unwrap();
    let mut ans: i32 = A - B*2;
    if ans < 0 {
        ans = 0;
    }
    println!("{}", ans.to_string());
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

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

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

  vector<int> A(N);
  vector<int> B(N);

  rep(i, 0, N) {
    cin >> A[i] >> B[i];
  }

  sort(All(A));
  reverse(All(A));

  sort(All(B));
  reverse(All(B));

  int ma = A[0];

  int ans = 0;
  rep(i, 0, N) {
    if (B[i] > ma) {
      ans += 1;
      H -= B[i];
      if (H <= 0) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  ans += (H + ma - 1) / ma;
  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
    //mint(2).pow(n); 2^n
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  ll n,s;
  cin >> n>>s;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  mint dp[n+5][s+5];
  rep(i,n+5)rep(j,s+5)dp[i][j]=0;
  dp[0][0]=1;
  rep(i,n)rep(j,s+1){
    dp[i+1][j]+=dp[i][j]*2;
    if((j+a[i])<=s){
      dp[i+1][j+a[i]]+=dp[i][j];
    }
  }
  cout<<dp[n][s]<<endl;


}


Measured memory_bytes: 74148
N, Q = gets.split.map(&:to_i)
str = gets.chomp
# 0文字目まで、1文字目までは自明に0
rui = [0, 0]
ite = 2
str.chars.each_cons(2) do |c1, c2|
  rui[ite] = rui[ite - 1] + ((c1 == 'A' && c2 == 'C') ? 1 : 0)
  ite += 1
end
Q.times do
  s, l = gets.split.map(&:to_i)
  puts rui[l] - rui[s]
end

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

const int MAXN = 10;
const double inf = 1e10;

int n;
string f[MAXN];
int w[MAXN], s[MAXN];
double minG;
vector<int> t, ans, used;

void rec(int k, int sumww, int sumw) {
  if(k == -1) {
    double G = (double)sumww/(double)sumw;
    if(G < minG) {
      ans = t;
      minG = G;
    }
    return;
  }
  for(int i = 0; i < n; ++i) {
    t[k] = i;
    if(used[t[k]]) continue;
    if(s[t[k]] >= sumw) {
      used[t[k]] = true;
      rec(k-1, sumww + (k+1)*w[t[k]], sumw + w[t[k]]);
      used[t[k]] = false;
    }
  }
}

int main() {
  for(; cin >> n, n;) {
    for(int i = 0; i < n; ++i) {
      cin >> f[i] >> w[i] >> s[i];
    }
    minG = inf;
    t = used = vector<int>(n);
    rec(n-1, 0, 0);
    for(int i = 0; i < n; ++i) {
      cout << f[ans[i]] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
def lower_bound(arr, v)
  l = -1; r = arr.size
  while l + 1 < r
    m = (l + r) / 2
    if arr[m] <= v then l = m
    else r = m
    end
  end
  l
end
n = gets.to_i
arr = []
n.times{ arr << gets.to_i }
sum = Array.new(2*n+1, 0)
(2*n).times{ |i| sum[i+1] += sum[i] + arr[i%n] }
l = 0; r = sum[n] / 3 + 1
while l + 1 < r
  m = (l + r) / 2
  f = nil
  n.times do |i|
    a = lower_bound(sum[i,n], m + sum[i] - 1) + i + 1
    if a < i+n
      b = lower_bound(sum[a...i+n], m + sum[a] - 1) + a + 1
      if b < i+n && sum[i+n] - sum[b] >= m
        l = m
        f = true
        break
      end
    end
  end
  r = m unless f 
end
p l

Measured memory_bytes: 11352
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    char c; cin >> c;
    cout << (char)(c + 1) << endl;
    return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 1

int main(){
	lli n;
	lli k;

	cin >> n;
	cin >> k;
	lli tmp;
	lli pos=0;
	REP(i,n){
		cin>>tmp;
		if(tmp==1)pos=i;
	}
	lli ans = (n-1)/(k-1);
	if( (n-1)%(k-1)){
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 20000;

/* typedef */

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<char,int> pci;
typedef stack<pci> spci;

/* global variables */

int as[MAX_N + 1], lis[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  string s;
  cin >> s;

  int n = s.size();

  spci st;
  vpii rv;

  for (int i = 0; i < n; i++) {
    if (s[i] == '\\') 
      st.push(pci('\\', i));
    else if (s[i] == '/') {
      if (! st.empty() && st.top().first == '\\') {
	pci u = st.top(); st.pop();
	rv.push_back(pii(u.second, i));
      }
      else
	st.push(pci('/', i));
    }
  }
  sort(rv.begin(), rv.end());

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

  int pri = -1, ar = 0, sum = 0;
  vi ars;

  for (int i = 0; i < rv.size(); i++) {
    int &li = rv[i].first, &ri = rv[i].second;
    if (pri < li) {
      if (ar > 0) ars.push_back(ar);
      ar = 0;
      pri = ri;
    }

    int d = ri - li;
    ar += d;
    sum += d;
  }
  if (ar > 0) ars.push_back(ar);

  printf("%d\n%lu", sum, ars.size());
  for (int i = 0; i < ars.size(); i++) printf(" %d", ars[i]);
  putchar('\n');
  return 0;
}

Measured memory_bytes: 1384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder line = new StringBuilder(br.readLine());
    
    String[] input = line.toString().split(" ");
    int a = Integer.parseInt(input[0]);
    int b = Integer.parseInt(input[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: 24208
import java.util.*;
import java.math.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int vNum = scanner.nextInt();
    int hNum = scanner.nextInt();

    int[] v = new int[vNum];
    for (int ii = 0; ii < v.length; ii++) {
      v[ii] = ii + 1;
    }

    String[] h = new String[hNum];
    for (int ii = 0; ii < h.length; ii++) {
      h[ii] = scanner.next();
    }

    for (int ii = 0; ii < h.length; ii++) {
      String[] hs = h[ii].split(",");
      int[] hwork = new int[2];
      hwork[0] = Integer.parseInt(hs[0]) - 1;
      hwork[1] = Integer.parseInt(hs[1]) - 1;
      v[hwork[0]] = v[hwork[0]] + v[hwork[1]];
      v[hwork[1]] = v[hwork[0]] - v[hwork[1]];
      v[hwork[0]] = v[hwork[0]] - v[hwork[1]];
    }

    for (int ii = 0; ii < v.length; ii++) {
      System.out.println(v[ii]);
    }
  }
}

Measured memory_bytes: 17204
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  int a[2][N];
  for (int i = 0; i < N; i++) cin >> a[0][i];
  for (int i = 0; i < N; i++) cin >> a[1][i];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      if (j <= i) sum += a[0][j];
      else sum += a[1][j];
      if (i == j) sum += a[1][j];
    }
    ans = max(ans, sum);
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    ll k;
    cin>>k;
    queue<ll> q;
    for(int i = 1; i < 10; i++){
        q.push(i);
    }
    ll t = 0;
    while(1){
        t++;
        ll x = q.front();
        if(t == k){
            cout<<x;
            return 0;
        }
        q.pop();
        if(x%10 != 0) q.push(x*10+(x%10)-1);
        q.push(x*10+x%10);
        if(x%10 != 9) q.push(x*10+x%10+1);
    }
}

Measured memory_bytes: 4776
n = int(input())
num_list = [ int(v) for v in input().split() ]

def cumsum(inlist):
    s = 0
    outlist = []
    for i in inlist:
        s += i
        outlist.append(s)
    return outlist

cumsum_list = [0] + cumsum(num_list)
cumsum_list = sorted(cumsum_list)
dup_list = []
before, c = None, 1
for i in cumsum_list:
    if i == before:
        c += 1
    else:
        if before != None:
            dup_list.append(c)
            c = 1
        before = i
if c != 1:
    dup_list.append(c)

print(sum([ (i*(i-1)) //2 for i in dup_list ]))



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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

const int inf = 1 << 28;
const int N = 52;
const int M = N * N;

struct Mat {
  Mat () {
    fill(&val[0][0], &val[N - 1][N - 1] + 1, 0);
  }
  int val[N][N];
};

Mat operator * (Mat a, Mat b)
{
  Mat c;
  for (int i = 0; i < N; ++i) {
    for (int k = 0; k < N; ++k) {
      for (int j = 0; j < N; ++j) {
        c.val[i][j] += a.val[i][k] * b.val[k][j];
        c.val[i][j] = min(c.val[i][j], 1);
      }
    }
  }
  return c;
}

Mat e;

Mat pow(Mat m, int p)
{
  if (p == 0) return e;
  if (p == 1) return m;
  Mat tmp = pow(m, p / 2);
  return p % 2 ? tmp * tmp * m : tmp * tmp;
}

Mat mat_a;
Mat mat_b;
Mat mat_c;

int memo[N][M];
int n, m, a, b, c;
int rec(int curr, int step)
{
  unless (step < M) return inf;
  int& ret = memo[curr][step];
  if (ret != -1) return ret;
  if (curr == n - 1) return step;
  int mn_a = inf;
  int mn_b = inf;
  int mn_c = inf;
  for (int next = 0; next < N; ++next) {
    if (mat_a.val[curr][next]) mn_a = min(mn_a, rec(next, step + 1));
    if (mat_b.val[curr][next]) mn_b = min(mn_b, rec(next, step + 1));
    if (mat_c.val[curr][next]) mn_c = min(mn_c, rec(next, step + 1));
  }
  return ret = max({mn_a, mn_b, mn_c});
}

int main(int argc, char *argv[])
{
  for (int i = 0; i < N; ++i) {
    e.val[i][i] = 1; 
  }
  while (cin >> n >> m >> a >> b >> c) {
    Mat in;
    for (int i = 0; i < m; ++i) {
      int src, dst;
      cin >> src >> dst;
      --src;
      --dst;
      in.val[src][dst] = 1;
    }
    mat_a = pow(in, a);
    mat_b = pow(in, b);
    mat_c = pow(in, c);

    // cout << "A" << endl;
    // for (int i = 0; i < n; ++i) {
    //   for (int j = 0; j < n; ++j) cout << mat_a.val[i][j] << ' ' ; cout << endl;
    // }
    // cout << "B" << endl;
    // for (int i = 0; i < n; ++i) {
    //   for (int j = 0; j < n; ++j) cout << mat_b.val[i][j] << ' ' ; cout << endl;
    // }
    // cout << "C" << endl;
    // for (int i = 0; i < n; ++i) {
    //   for (int j = 0; j < n; ++j) cout << mat_c.val[i][j] << ' ' ; cout << endl;
    // }
    
    
    fill(&memo[0][0], &memo[N - 1][M - 1] + 1, -1);
    const int dist = rec(0, 0);
    if (dist < inf) cout << dist << endl;
    else cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 4340
N = int(input())
As = list(map(int, input().split()))

for i in range(len(As)):
    As[i] -= i+1
As = sorted(As)

bs = [As[N//2]]
if N % 2 == 0:
    bs.append(As[N//2-1])

total = 2*10**14
for b in bs:
    t = 0
    for A in As:
        t += abs(A - b)
    total = min(total, t)
print(total)

Measured memory_bytes: 26708
#include <bits/stdc++.h>
using namespace std;
#define ll long long
char mp[300][300];
int main(){
    int N;
    cin>>N;
    for(int y=0;y<N;y++){
        for(int x=0;x<N;x++){
            char c;
            cin>>c;
            mp[y][x] = c;
        }
    }
    cout<<endl;
    int ans=0;
    for(int A=0;A<N;A++){
        int flg = 1;
        for(int fy=0;fy<N&&flg;fy++){
            for(int fx=0;fx<N&&flg;fx++){
                int tx = (fx + A) % N;
                int ty = fy;
                int mtx = ty;
                int mty = tx;
                int mfx = (mtx+N-A)%N;
                int mfy = mty;
                if(mp[fy][fx]!=mp[mfy][mfx]){
                    flg=0;
                }
            }
        }
        if(flg)ans+=N;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	odd := false
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		if a%2 == 1 {
			odd = true
		}
	}

	if odd {
		fmt.Println("first")
	} else {
		fmt.Println("second")
	}
}


Measured memory_bytes: 5504
#include <iostream>
#include <list>
#include <bitset>
#include <cmath>

int main()
{
	const int max = 50021;
	std::bitset<max + 1> bitTable;
	
	bitTable.set(0);
	bitTable.set(1);
	
	int loop = sqrt(max);
	
	for (int i = 2; i <= loop; ++i) {
		if (bitTable.test(i) == false) {
			for (int j = i * i; j <= max; j += i) {
				bitTable.set(j);
			}
		}
	}
	
	std::list<int> primeList;
	for (int i = 2; i <= max; ++i) if (bitTable.test(i) == false) primeList.push_back(i);
	
	int n;
	while (std::cin >> n) {
		if (n == 0 || n > max) break;
		
		std::list<int>::iterator itr = primeList.begin();
		int num;
		
		for (num = 0; itr != primeList.end(); ++itr) {
			if (n - (*itr << 1) < 0) break;
			if (bitTable.test(n - *itr) == false) ++num;
		}
		
		std::cout << num << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1352
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int min = 1000;
        int sum = 0;

        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            sum += num;
            if (num % 10 != 0) {
                min = Math.min(min, num);
            }
        }

        sc.close();

        if (sum % 10 == 0) {
            sum -= min;
        }

        if (sum % 10 == 0) {
            System.out.println(0);
        } else {
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 21972
import sys

def walk(T, nid, order):
  if nid < 0: return
  pid, lid, rid = T[nid]

  if order == "pre":
    sys.stdout.write(" " + str(nid))
    walk(T, lid, order)
    walk(T, rid, order)
  elif order == "in":
    walk(T, lid, order)
    sys.stdout.write(" " + str(nid))
    walk(T, rid, order)
  else:
    walk(T, lid, order)
    walk(T, rid, order)
    sys.stdout.write(" " + str(nid))

T = {}
for i in range(int(input())):
  nid, lid, rid = map(int, input().split())
  T[nid] = [-1, lid, rid]

# set parent
for nid in T:
  pid, lid, rid = T[nid]
  if lid >= 0: T[lid][0] = nid
  if rid >= 0: T[rid][0] = nid

# select root
for nid in T:
  if T[nid][0] == -1: root_id = nid

print("Preorder"),  walk(T, root_id, "pre"),  print()
print("Inorder"),   walk(T, root_id, "in"),   print()
print("Postorder"), walk(T, root_id, "post"), print()

Measured memory_bytes: 7820
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
//intは10桁、long longは18桁、doubleは308桁、long double は4932桁
int main()
{
    int N;
    ll K;
    cin >> N >> K;
    vector<pair<ll, ll>> v(N);
    for (int i = 0; i < N; ++i)
        cin >> v[i].first >> v[i].second;

    // ソート
    sort(v.begin(), v.end());

    // a_i が小さい順に b_i を合計して K 以上になる瞬間をとらえる
    ll res = 0;
    ll sum = 0;
    for (int i = 0; i < N; ++i)
    {
        sum += v[i].second;
        if (sum >= K)
        {
            res = v[i].first; // sum >= K になった瞬間の a_i
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 4e2 + 10;
int n;
int ans = 0;
void dfs(LL cur, int o = 0)
{
	if (cur > n) return;
	if (o == 7) ans++;
	for (int i = 0; i < 3; i++)
	{
		dfs(cur * 10 + i * 2 + 3, 1 << i | o);
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n;
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl

int a, b, c, d;
int main() {
    cin >> a >> b >> c >> d;
    for(int i=0; true; i++){
        if(i%2 == 0) c -= b;
        else a -= d;
        if(a<=0 || c<=0) break;
    }
    if(a<=0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <stdio.h>
#include <cctype>
#include <bits/stdc++.h>
using namespace std;

int main(){
    string str1, str2;
    getline(cin, str1);
    getline(cin, str2);
    str1 = str1 + str1;
    if (str1.find(str2) == std::string::npos) {
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }
}


Measured memory_bytes: 3204
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    int a[100010];
    int b[100010];
    cin >> n;
    for (int i = 0; i < n + 1; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > 0) {
            if (a[i] >= b[i]) {
                ans += b[i];
                b[i] = 0;
            }
            else {
                ans += a[i];
                b[i] -= a[i];
            }
        }

        if (a[i+1] >= b[i]) {
            ans += b[i];
            a[i+1] -= b[i];
        }
        else {
            ans += a[i+1];
            a[i+1] = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <unordered_map>
#include <list>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        ll a, v, b, w, t;
        cin >> a >> v >> b >> w >> t;
        if(v <= w){
            cout << "NO" << endl;
        }
        else{
            if(t * (v - w) >= abs(a - b)){
                cout << "YES" << endl;
            }
            else{
                cout << "NO" << endl;
            }
        }
    }
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 8 && b <= 8)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int main()
{
    int a,b,c=0 ;
    string x ;
    cin >> a >> b ;
    if (a>b){
        c = a ;
        a = b ;
        b = c ;
    }
    for(int i=a ; i<=b ; i++){
        c = i ;
        if(a*b*c %2 == 1)
        x = "Yes" ;
        else
            x = "No" ;

    }

    cout << x ;



    return 0 ;
}


Measured memory_bytes: 256
n = int(input())
li = list(map(int, input().split()))
nxt = True
for i in range(n-1):
    if next:
        li[i] -= 1
    if li[i]>li[i+1] :
        print("No")
        break
    elif li[i]==li[i+1]:
        next = False
    else:
        next = True
else:
    print("Yes")

Measured memory_bytes: 14396
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	sc = initScanner(os.Stdin)
	a, b := scanInt(sc), scanInt(sc)
	fmt.Println(resolve(a, b))
}

func resolve(a, b int) string {
	if a == b {
		if a < 0 {
			return "Negative"
		}
	}

	if a <= 0 && b >= 0 {
		return "Zero"
	}
	if a > 0 && b > 0 {
		return "Positive"
	}

	count := 0
	for i := a; i <= b; i++ {
		count++
	}

	if count%2 == 0 {
		return "Positive"
	} else {
		return "Negative"
	}

}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


Measured memory_bytes: 1792