akhauriyash/Code-Regression huggingface dataset:
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 15 2019
 * 
 */

#include <bits/stdc++.h>

#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define ef else if
#define wh while
#define el else
#define ivv(x) int x; cin>>x
#define lv(x) bint x; cin>>x
#define sv(x) string x; cin>>x
#define cv(x) char x; cin>>x
#define fv(x) float x; cin>>x
#define dv(x) double x; cin>>x
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 


    int ab , bc , ca;

    cin>>ab>>bc>>ca;

    cout<<(int)(0.5 * ab * bc)<<endl;



    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pii make_pair
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
vector<pair<int, int> >adj[100005];
int mp[100005];
int vis[100005], dep[100005];

void dfs(int node)
{
    //cout<<node<<endl;
    vis[node]=1;
    for(int i=0; i<adj[node].size(); i++) {
        int chl=adj[node][i].first;
        int len=adj[node][i].second;
        if(vis[chl]) continue;
        dep[chl]=dep[node]+len;
        if(dep[chl]%2==0) mp[chl]=1;
        else mp[chl]=0;
        dfs(chl);
    }
}

main()
{
    //fastio;
    int n, x, y, z;
    cin>>n;
    for(int i=0; i<n-1; i++) {
        cin>>x>>y>>z;
        adj[x].push_back(pii(y, z));
        adj[y].push_back(pii(x, z));
    }
    if(n==1) {
        cout<<"1";
        return 0;
    }
    memset(vis, 0, sizeof(vis));
    memset(dep, 0, sizeof(dep));
    for(int i=1; i<=n; i++) {
        if(adj[i].size()==1) {
            mp[i]=1;
            dfs(i);
            break;
        }
    }
    for(int i=1; i<=n; i++) cout<<mp[i]<<endl;
}


Measured memory_bytes: 18216
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;

inline int read(){
    register int x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
	return x * flag;
}

template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 

string s;
int a, b, c, n;
int main() {
	cin >> n;
	int i;
	for (i = 400; i <= 2000; i += 200) {
		if (n < i) break;
	}
	cout << 8 - ((i - 500) / 200) << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  string S;
  cin >> S;
  int N = S.size();
  bool ok = N%2 == 0;
  rep(i, N) {
    if (i%2) ok &= S[i] == 'i';
    else ok &= S[i] == 'h';
  }
  if (ok) cout << "Yes\n";
  else cout << "No\n";
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] s = in.readLine().split("/");
    System.out.println(Integer.parseInt(s[1])>4?"TBD":"Heisei");
  }
}

Measured memory_bytes: 21204
#include <iostream>
#include <string>
#define MAX_N 1000000
#define PLUS 10
#define MULTI 20
using namespace std;

string a[MAX_N];
int b[MAX_N];
int level[MAX_N];

void revise(int first, int last, int n) {
  int diff = last - first + 1;
  for (int i = first; i + diff < n; i++) {
    b[i] = b[i + diff];
    level[i] = level[i + diff];
  }
}

int calc(int first, int last) {
  if (b[first - 1] == PLUS) {
    int sum = 0;
    for (int i = first; i <= last; i++)
      sum += b[i];
    return sum;
  } else {
    int multi = 1;
    for (int i = first; i <= last; i++)
      multi *= b[i];
    return multi;
  }
}

void make_b(int n) {
  for (int i = 0; i < n; i++) {
    int lev = level[i];
    if (a[i][lev] == '+') b[i] = PLUS;
    else if (a[i][lev] == '*') b[i] = MULTI;
    else b[i] = a[i][lev] - '0';
  }
}

void count_level(int n) {
  for (int i = 0; i < n; i++) {
    int count = 0;
    for (int j = 0; ; j++) {
      if (a[i][j] != '.') break;
      count++;
    }
    level[i] = count;
  }
}

void init(int n) {
  for (int i = 0; i < n; i++) {
    a[i] = "\0";
    b[i] = 0;
    level[i] = 0;
  }
}

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;
    init(n);

    for (int i = 0; i < n; i++)
      cin >> a[i];

    count_level(n);
    
    make_b(n);

    int level_max = level[0];
    for (int i = 1; i < n; i++)
      if (level[i] > level_max) level_max = level[i];

    while (level_max) {
      for (int i = 0; i < n; i++) {
	int temp;
	if (level[i] == level_max) {
	  temp = i;
	  while (level[temp] == level_max && temp < n) {
	    temp++;
	  }
	  temp--;
	  int result = calc(i, temp);
	  b[i - 1] = result;
	  revise(i, temp, n);
	  n -= temp - i + 1;
	}
      }
      level_max--;
    }
    cout << b[0] << endl;
  }
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int dp[50][3001];
int newdp[50][3001];

int main()
{
    const int mod=100000;
    int n,m,s;
    while(cin >>n >>m >>s,n)
    {
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;

        //i?????????????????????
        for(int i=1; i<=m; ++i)
        {
            memset(newdp,0,sizeof(newdp));

            rep(j,n*n+1)rep(k,s+1)
            {
                //??????
                if(j<n*n && k+i<=s)
                {
                    newdp[j+1][k+i]+=dp[j][k];
                    newdp[j+1][k+i]%=mod;
                }

                //????????????
                newdp[j][k]+=dp[j][k];
                newdp[j][k]%=mod;
            }

            //copy
            rep(j,n*n+1)rep(k,s+1) dp[j][k]=newdp[j][k];
        }

        cout << dp[n*n][s] << endl;
    }
    return 0;
}

Measured memory_bytes: 4276
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] trees = new int[n];
		for(int i=0; i<n; i++){
			trees[i] = sc.nextInt();
		}
		
		quick_sort(trees, 0, n-1);
		
		int min = trees[n-1];
		for(int i=0; i<n-k+1; i++){
			if(trees[i+k-1] - trees[i] < min){
				min = trees[i+k-1] - trees[i];
			}
		}
		
		System.out.println(min);
	}
	
	static void quick_sort(int[] d, int left, int right) {
		if(left>=right){
				return;
		}
		int p = d[(left+right)/2];
		int l = left, r = right, tmp;
		while(l<=r){
			while(d[l] < p){ l++; }
			while(d[r] > p){ r--; }
			if (l<=r) {
				tmp = d[l]; d[l] = d[r]; d[r] = tmp;
				l++;
				r--;
			}
		}
		quick_sort(d, left, r);
		quick_sort(d, l, right);
	}
}

Measured memory_bytes: 50028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, M, L;
	cin >> N >> M >> L;
	int C[301][301];
	rep1(i, N) rep1(j, N) C[i][j] = 1e9 + 1;
	rep1(i, N) C[i][i] = 0;
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		C[a][b] = c;
		C[b][a] = c;
	}

	rep1(k, N) rep1(i, N) rep1(j, i - 1) {
		chmin(C[i][j], C[i][k] + C[k][j]);
		chmin(C[j][i], C[i][j]);
	}

	rep1(i, N) rep1(j, N) {
		C[i][j] = (C[i][j] <= L) ? 1 : 1e9;
	}

	rep1(k, N) rep1(i, N) rep1(j, i - 1) {
		chmin(C[i][j], C[i][k] + C[k][j]);
		chmin(C[j][i], C[i][j]);
	}

	int Q;
	cin >> Q;
	rep(i, Q) {
		int s, t;
		cin >> s >> t;
		if (C[s][t] < 1e9) co(C[s][t] - 1);
		else co(-1);
	}

	Would you please return 0;
}

Measured memory_bytes: 896
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let xs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref 0
let _ =
  for i = 0 to n - 1 do ans := !ans + min (xs.(i) * 2) (abs (xs.(i) - k) * 2) done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 384
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll H[100010];
    ll A[100010], B[100010];
    vector<ll> tree[100010];
    rep(i,0,N) cin >> H[i];
    rep(i,0,M){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        tree[A[i]].push_back(B[i]);
        tree[B[i]].push_back(A[i]);
    }
    ll ans = 0;
    rep(i,0,N){
        ll max_val = 0;
        for(auto &e: tree[i]){
            max_val = max(max_val, H[e]);
        }
        if(max_val < H[i]) ans++;
    }
    print(ans);
    

}

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

int main(void){
	string nu;
	while(cin >> nu){
		if(nu[0] == '0') break;
		int ans = 0;
		for(int i=0; i<nu.length(); i++){
			ans += nu[i] - '0';
		}
		printf("%d\n", ans);
	}

	return 0;
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int T,D; cin >> T >> D;
  int ta,tb; cin >> ta >> tb;
  int da,db; cin >> da >> db;

  double ans = 1 << 30;
  for(int i = 0; i < 1000; i++){
    for(int j = 0; j < 1000; j++){
      if(i*da + j*db > D || i*da + j+db < 1) continue;
      int va = i*da,vb = j*db;
      double res = (ta*va + tb*vb) / (double)(va + vb);
      ans = min(ans,abs(res - T));
    }
  }
  printf("%.10f\n",ans);

  return 0;
}



Measured memory_bytes: 3220
package main

import "fmt"

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,l,x[2019],a[100];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>a[i];
  }
  for(int i=0;i<m;i++){
    l=a[i]-1;
    if(x[l]<2019){
      if(x[l]+1!=x[l+1] || l==n-1) {
	x[l]+=1;
      }   
    }
  }
  for(int i=0;i<n;i++){
    cout<<x[i]<<endl;
  }
  return 0;
}
    



Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int count = 0, mini = 1001;
    string s, t, s1, s2 = "";
    cin >> s >> t;

    int n = t.length();

    for(int i = 0; i <= s.length() - n; i++)
    {
        count = 0;
        for(int j = i; j < i + n; j++)
        {
            s1.pb(s[j]);
        }
        for(int k = 0; k < s1.length(); k++)
        {
            if(s1[k] != t[k])
            {
                count++;
            }
        }
        mini = min(mini, count);
        s1.clear();
    }
    cout << mini << endl;
    return 0;
}

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

#include <deque>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
using coord = pair<int, int>;

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

    vector<string> s(H);
    for (int i = 0; i < H; i++) {
        cin >> s[i];
    }

    vector<vector<int>> dp(H, vector<int>(W, -1));
    if (s[0][0] == '.') {
        dp[0][0] = 0;
    } else {
        dp[0][0] = 1;
    }
    for (int w = 1; w < W; w++) {
        if (s[0][w - 1] == '.' && s[0][w] == '#') {
            dp[0][w] = dp[0][w - 1] + 1;
        } else {
            dp[0][w] = dp[0][w - 1];
        }
    }
    for (int h = 1; h < H; h++) {
        if (s[h - 1][0] == '.' && s[h][0] == '#') {
            dp[h][0] = dp[h - 1][0] + 1;
        } else {
            dp[h][0] = dp[h - 1][0];
        }
    }
    for (int h = 1; h < H; h++) {
        for (int w = 1; w < W; w++) {
            int tmp = 1e9;
            if (s[h][w] == '#') {
                if (s[h][w - 1] == '#') tmp = min(dp[h][w - 1], tmp);
                if (s[h - 1][w] == '#') tmp = min(dp[h - 1][w], tmp);
                if (s[h][w - 1] == '.') tmp = min(dp[h][w - 1] + 1, tmp);
                if (s[h - 1][w] == '.') tmp = min(dp[h - 1][w] + 1, tmp);
            }
            if (s[h][w] == '.') {
                tmp = min(tmp, min(dp[h][w - 1], dp[h - 1][w]));
            }
            dp[h][w] = tmp;
        }
    }

    // for (int h = 0; h < H; h++) {
    // for (int w = 0; w < W; w++) {
    // cout << std::right << std::setw(2) << dp[h][w] << " ";
    // }
    // cout << endl;
    // }
    cout << dp[H - 1][W - 1] << endl;

    return 0;
}


Measured memory_bytes: 3596
def gcd(a,b):
    if a < b:
        return gcd(b,a)
    if a%b == 0:
        return b
    return gcd(b, a%b)

def n_div(N, a, b):
    return N - (N//a + N//b - N//(a*b//gcd(a,b)))

A,B,C,D = (int(x) for x in input().split())

ans = n_div(B, C, D)-n_div(A-1, C, D)

print(ans)


Measured memory_bytes: 3060
#!/usr/bin/env python3
n, a, b, c, d = map(lambda x: int(x) - 1, input().split())
s = list(input())

if d < c:
    s[b] = 'b'
    while a < b:
        if a + 1 <= c and s[a + 1] == '.':
            a += 1
        elif a + 2 <= c and s[a + 2] == '.':
            a += 2
        elif b < d:
            if b + 1 <= d and s[b + 1] == '.':
                s[b] = '.'
                s[b + 1] = 'b'
                b += 1
            elif b + 2 <= d and s[b + 2] == '.':
                s[b] = '.'
                s[b + 2] = 'b'
                b += 2
            else:
                print('No')
                exit()
        else:
            print('No')
            exit()
    a, b = b, a
    c, d = d, c
while b < d:
    if b + 1 <= d and s[b + 1] == '.':
        b += 1
    elif b + 2 <= d and s[b + 2] == '.':
        b += 2
    else:
        print('No')
        exit()
while a < c:
    if a + 1 <= c and s[a + 1] == '.':
        a += 1
    elif a + 2 <= c and s[a + 2] == '.':
        a += 2
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 4984
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;


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

    int n; cin>>n;
    vl a(n);
    for (lint &i:a) cin>>i;
    lint m = 1e18;
    lint res = 1;
    for (int i=0; i<n; ++i){
        if (a[i] == 0){
            cout<<0;
            return 0;
        }
    }

    for (int i=0; i<n; ++i){
        if (a[i] <= m/res){
            res = res*a[i];
        } else {
            cout<<-1;
            return 0;
        }
    }
    cout<<res;

}


Measured memory_bytes: 3988
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
    ll n,k; cin >> n >> k;
    ll ans = 1e10,minel;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];

    ll l = 0;
    for(int l = 0; l + k - 1 < n; l++){
        ll r = l + k - 1;
        if(x[r] <= 0){
            ans = min(ans,-x[l]);
        }else if(x[l] >= 0){
            ans = min(ans,x[r]);
        }else{
            minel = min(x[r] - x[l] + x[r], x[r] - x[l] - x[l]);
            ans = min(ans,minel);
        }
    }
    cout << ans << endl;
}



    

Measured memory_bytes: 1024
def findFirstNot1(arg):
    ret = 1000
    ichi = 0
    for c in range(0, len(arg)):
        if arg[c] == '1':
            ichi += 1
        else:
            return ichi + 1
    return ret

instr = input()
nanmojime = int(input())
first1igai = findFirstNot1(instr)
if first1igai > nanmojime:
    ans = 1
else:
    ans = int(instr[first1igai - 1])
print(ans)

Measured memory_bytes: 3060
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;

int main ( ){
  scanf("%d",&n);
  for ( int i = 1 ; i <= n; i++ ) {
    scanf("%d",a+i);
  }
  int ANS =0 ;
  for ( int i = 1; i <= n;  i++ )
    for ( int j = i+1 ; j <= n ; j++ )
       ANS += a[i]*a[j];
  printf("%d\n",ANS);
return 0 ;
}


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

int main(){
	int a[3];

	cin >> a[0] >> a[1] >> a[2];

	sort(a, a + 3);

	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vector<P> ans;
    if (n&1) {
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (i == j || j == n - i) continue;
                ans.push_back(P(i,j));
            }
        }
    } else {
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (i == j || i + j == n + 1) continue;
                ans.push_back(P(i,j));
            }
        }
    }
    cout << ans.size() << endl;
    rep(i,ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
}

Measured memory_bytes: 3708
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int h, w;
	scanf("%d%d", &h, &w);
	string s;
	rep(i, h){
	  rep(j, w){
	    cin >> s;
	    if(s == "snuke"){
	      printf("%c%d\n", 'A' + j, i + 1);
			}
		}
	}
	
	Please AC;
}


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//切り上げ除算
long long cutup(long long a,long long b){return (a+b-1)/b;}

//累乗
template<typename t>
constexpr t my_pow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
    }
    return x;
}
#define pow my_pow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    char A,B;
    cin>>A>>B;
    if(A>B)cout<<'>'<<endl;
    if(A==B)cout<<'='<<endl;
    if(A<B)cout<<'<'<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);

using ll = long long;
using namespace std;
typedef pair<int,int> pii;


int main()
{
#ifndef RICARDO
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    int n;
    ll h;
    cin >> n >> h;
    ll maxx=0;
    vector<ll> a(n);
    for(int i=0; i<n; ++i)
    {
        ll u,v;
        cin >> u >> v;
        a[i]=v;
        maxx=max(maxx,u);
    }
    sort(a.begin(),a.end(), greater<ll>());
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        if (a[i]/maxx==0)
            break;
        h-=a[i];
        ans++;
        if (h<=0) break;
    }
    if (h<=0) cout << ans; else cout << ans+(h+maxx-1)/maxx;
    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;
	unsigned long first, check, tmp;
	int i;

	cin >> n;
	cin >> first;
	check = first ^ first;
//	cout << "first = " << first << endl;
	for (i = 1; i < n; i++) {
		cin >> tmp;
		check = check ^ tmp;
	}

	if (first == check) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
//
//  main.cpp
//

#include <bits/stdc++.h>

using namespace std;

int a[2];

int main() {
    cin >> a[0] >> a[1];
    sort(a, a + 2);
    int ans = 0;
    ans += a[1];
    a[1]--;
    ans += max(a[1], a[0]);
    cout << ans;
    return 0;
}


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

using namespace std;

int main(){
    int a,b,cont=0;
    while(cin >> a >> b && a||b){
        for(int i=1;i<=a;i++){
            for(int j=i+1;j<=a;j++){
                for(int y=j+1;y<=a;y++){
                    if(i+j+y==b){cont++;}
                }
            }
        }
        cout << cont << endl;
        cont=0;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    if(n<1200) printf("ABC");
    else printf("ARC");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	string a;
	cin >> a;
	int ans = 0;
	int n = a.size();
	FOR(i,1,n){
		if(a[i] != a[i-1]){
			ans++;
		}
	}
	cout << ans;
    return 0;
}

Measured memory_bytes: 512
A = str(input())
B = str(input())
C = str(input())
S = [A, B, C]
la = len(A)
lb = len(B)
lc = len(C)
L = [la, lb, lc]

turn = 0
l = [0, 0, 0]
i = 1
while i == 1:
  if l[turn] == L[turn]:
    i = 0
    ans = turn
  else:
    x = S[turn][l[turn]]  
    l[turn] += 1
    if x == "a":
      turn = 0
    elif x == "b":
      turn = 1
    else:
      turn = 2
  #print(l, L)
if ans == 0:
  print("A")
elif ans == 1:
  print("B")
else:
  print("C")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
  lint N;
  cin >> N;
  lint X, D;
  cin >> X >> D;
  if(D == 0 && X == 0) {
      cout << 1 << endl;
      return 0;
  } else if(D == 0) {
      cout << (N+1) << endl;
      return 0;
  } else if(X == 0) {
      cout << (N*(N-1)/2 + 1) << endl;
      return 0;
  }
  if(D < 0) {
      X = -X;
      D = -D;
  }
  map<lint, multiset<pair<lint, lint>>> mp;
  REP(i, N+1) {
    lint Xdiff = (lint)i*X;
    lint Dmin = (lint)i*(i-1)/2*D + Xdiff;
    lint Dmax = (N*(N-1)/2 - (N-i)*(N-i-1)/2)*D + Xdiff;
    lint key = Dmin%D;
    if(key < 0) key += D;
    vector<pair<lint, lint>> remset;
    if(mp.find(key) != mp.end()) {
      auto itr = mp[key].upper_bound(make_pair(Dmax, 1e18));
      while(true) {
        if(itr == mp[key].begin()) break;
        itr = prev(itr);
        if((*itr).first > Dmax) continue;
        if((*itr).second < Dmin) break;
        Dmin = min(Dmin, (*itr).first);
        Dmax = max(Dmax, (*itr).second);
        remset.push_back(*itr);
      }
    } else {
      mp[key] = multiset<pair<lint, lint>>();
    }
    REP(i, remset.size()) mp[key].erase(remset[i]);
    mp[key].insert(make_pair(Dmin, Dmax));
  }
  lint ans = 0;
  for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
    for(pair<lint, lint> p : itr->second) {
      ans += (p.second - p.first) / D + 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 34836
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))


# In[6]:


idx_max = A.index(max(A))
tmp = [x for x in A]
del tmp[idx_max]
most_max = max(A)
second_max = max(tmp)
for i in range(N):
    if i == idx_max:
        print(second_max)
    else:
        print(most_max)


# In[ ]:






Measured memory_bytes: 14080
h,w,a,b = map(int,input().split())
for i in range(b):
    tmplist = ["0"]*(a) + ["1"]*(w-a)
    print("".join(tmplist))
for i in range(h-b):
    tmplist = ["1"]*(a) + ["0"]*(w-a)
    print("".join(tmplist))

Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n;

int calc() {
  int c = -1;
  int n2 = 2 * n;
  FOR(i, 1, n2) {
    if(n2 % i == 0 && (n2 / i == i + 1)) {
      c = i;
      break;
    }
  }

  return c;
}

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

  int c = calc();

  if(c == -1) {
    cout << "No" << endl;
    return 0;
  }
  int memo[c + 1][c];
  int p = 1;
  REP(i, c + 1) {
    REP(j, i) {
      memo[i][j] = memo[j][i - 1];
    }

    FOR(j, i, c) {
      memo[i][j] = p++;
    }
  }

  cout << "Yes" << endl;
  cout << c + 1 << endl;
  REP(i, c + 1) {
    cout << c << " ";
    REP(j, c) cout << memo[i][j] << " ";
    cout << endl;
  }
}


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

struct fast_io {
    fast_io() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} __fast_io;

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

    ll sum = 0;
    for (char c : N)
        sum += c - '0';

    cout << (sum % 9 ? "No" : "Yes") << endl;
}


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

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

    int n;
    cin >> n;

    priority_queue<lint, vector<lint>, less<lint>> lower;
    priority_queue<lint, vector<lint>, greater<lint>> upper;

    lint ans = 0;
    lint lazy_lower = 0;
    lint lazy_upper = 0;

    vector<lint> len(n);
    for (int i = 0; i < n; i++) {
        lint l, r;
        cin >> l >> r;
        len[i] = r - l + 1;

        if (i == 0) {
            lower.emplace(l);
            upper.emplace(l);
            continue;
        }

        lazy_lower -= len[i] - 1;
        lazy_upper += len[i - 1] - 1;

        if (l <= lower.top() + lazy_lower) {
            lint top = lower.top() + lazy_lower;
            ans += top - l;
            lower.emplace(l - lazy_lower);
            lower.emplace(l - lazy_lower);
            lower.pop();
            upper.emplace(top - lazy_upper);
        } else if (upper.top() + lazy_upper <= l) {
            lint top = upper.top() + lazy_upper;
            ans += l - top;
            upper.emplace(l - lazy_upper);
            upper.emplace(l - lazy_upper);
            upper.pop();
            lower.emplace(top - lazy_lower);
        } else {
            lower.emplace(l - lazy_lower);
            upper.emplace(l - lazy_upper);
        }
    }

    cout << ans << "\n";
    return 0;
}


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

int main(){
	int n;
	while(cin >> n && n){
		vector<string> a;
		vector< pair<int,int> > v;
		for(int i = 0 ; i < n ; i++){
			string name;
			cin >> name;
			a.push_back(name);
			int w = 0;
			for(int j = 0 ; j < n - 1 ; j++){
				int t;
				cin >> t;
				if( t == 0 ) w += 10000;
				if( t == 2 ) w += 1;
			}
			v.push_back(make_pair(-w,i));
		}
		sort(v.begin(),v.end());
		for(int i = 0 ; i < v.size() ; i++){
			cout << a[v[i].second] << endl;
		}
	}
	
}

Measured memory_bytes: 1204
import collections
n = int(input())
s_ls = []
dic = collections.defaultdict(int)
for i in range(n):
    [s,t] = [j for j in input().split()]
    s_ls.append(s)
    dic[s] = int(t)
x = input()
f = 0
ans = 0
for i in range(n):
    if f:
        ans += dic[s_ls[i]]
    if x == s_ls[i]:
        f = 1
print(ans)


Measured memory_bytes: 65300
#include <bits/stdc++.h>
using namespace std;
int main()
{	
	char a,b;
	scanf("%c %c",&a,&b);
	if(a>b){
		cout << ">" << endl;
	}
	else if(a<b){
		cout << "<" << endl;
	}
	else{
		cout << "=" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
using Primes

function main()
    n::Int=parseInt(readline())
    res::Primes.Factorization{Int64}=factor(n)
    ans::Int=0
    for i in keys(res)
        j::Int=1
        while j<=res[i]
            ans+=1
            res[i]-=j
            j+=1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 216904
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Graph{
    struct Edge{
        int cost, dest;
        Edge(int cost, int dest): cost(cost), dest(dest){ }
        ostream& operator >> (ostream& out){
            return out << '(' << cost << ':' << dest << ')';
        }
    };
    struct Node{
        vector<Edge> edges;
        ll height = 0;
    };
    vector<Node> nodes;
    Graph(int num): nodes(num){ }
    // vector<Edge> edges;
    // Graph(int nn, int en = 10): nodes(nn){
    //     edges.reserve(en);
    // }
    // void addEdge(int from, int dest, ll cost = 1){
    //     nodes[from].outEdges.emplace_back(edges.size());
    //     edges.emplace_back(from, dest, limit);
    // }
    void addEdge(int from, int dest, int cost = 1){
        nodes[from].edges.emplace_back(cost, dest);
    }
    void addEdge2(int from, int dest, int cost = 1){
        addEdge(from, dest, cost);
        addEdge(dest, from, cost);
    }
    void dfs(int idx, ll height, int from = -1){
        nodes[idx].height = height;
        for(auto& e : nodes[idx].edges){
            if(e.dest == from){ continue; }
            dfs(e.dest, height + e.cost, idx);
        }
    }
};

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n; cin >> n;
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        // cin >> a >> b >> c;
        scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        g.addEdge2(a, b, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    g.dfs(k, 0);
    for(int i = 0; i < q; i++){
        int x, y;
        // cin >> x >> y;
        scanf("%d %d", &x, &y);
        x--; y--;
        cout << g.nodes[x].height + g.nodes[y].height << '\n';
    }
}


Measured memory_bytes: 14336
#include <iostream>
#include <map>

using namespace std;

int main() {
    int N;
    cin >> N;
    
    map<long long int, long long int> mp;
    for(int n=0; n<N; n++) {
        long long int a;
        cin >> a;
        
        mp[a]++;
    }
    
    long long int ans=0;
    for(auto i=mp.begin(); i!=mp.end(); i++) {
        if(i->first==i->second) continue;
        else if(i->first>i->second) {
            ans += i->second;
        } else {
            ans += i->second-i->first;
        }
    }
    
    cout << ans << endl;

    return 0;
    
}

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

int main() {
    ll n, x;
    cin >> n >> x;
    vector<ll> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    sort(arr.begin(), arr.end());
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if (x >= arr[i]) {
            x -= arr[i];
            ans += 1;
        }
    }
    if (ans == n && x != 0) {
        ans -= 1;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define endl '\n'
#define MAX 1500

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

char board[MAX][MAX];
int dp[MAX][MAX];
int L[MAX][MAX];
int R[MAX][MAX];
int A[MAX][MAX];
int B[MAX][MAX];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
		
    int n,m;
    cin >> n >> m;

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> board[i][j];

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(board[i][j] == '0')
                A[i][j] = 1;

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
                B[i][j] += A[i][j];
                B[i][j] += B[i][j - 1];
                B[i][j] += B[i - 1][j];
                B[i][j] -= B[i - 1][j - 1];
        }

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
            if(board[i][j] == '1')
                dp[i][j] = 0;
            else
                dp[i][j] = 1 + dp[i - 1][j];
        }

    for(int i = 1; i <= n; i++){
        stack<int> st;
        for(int j = 1; j <= m; j++){
            while(!st.empty() && dp[i][st.top()] >= dp[i][j])
                st.pop();
            if(st.empty())
                L[i][j] = 1;
            else
                L[i][j] = st.top() + 1;
            st.push(j);
        }
    }

    for(int i = 1; i <= n; i++){
        stack<int> st;
        for(int j = m; j >= 1; j--){
            while(!st.empty() && dp[i][st.top()] >= dp[i][j])
                st.pop();
            if(st.empty())
                R[i][j] = m;
            else
                R[i][j] = st.top() - 1;
            st.push(j);
        }
    }

    int solve = 0;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
            if(dp[i][j] == 0)
                continue;
            int size = R[i][j] - L[i][j] + 1;
            int rectangle_size = size * dp[i][j];

            solve = max(solve,rectangle_size);
        }

    cout << solve << endl;

	return 0;
}



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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

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

    long r;
    cin >> r;
    cout << 3 * r * r << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  string s;
  cin >> s;
  
  sort(s.begin(), s.end());
  
  if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2]){
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<55)
#define mod 1000000007
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;}

int main(){
    ll n,m;cin>>n>>m;
    vector<vector<ll>> c(m,vector<ll>());
    vector<ll> cost(m);
    rep(i,m){
        ll b;cin>>cost[i]>>b;
        rep(j,b){
            ll C;cin>>C;C--;
            c[i].push_back(C);
        }
    }

    vector<vector<ll>> dp(1010,vector<ll>((1<<12),INF));
    dp[0][0]=0;


    rep(i,m){//i-1番目の鍵まで選択可能
        rep(j,(1<<n)){
            ll choice=0;
            rep(k,c[i].size()){//i番目の鍵が開けることができる宝箱
                choice+=(1<<c[i][k]);
            }
            chmin(dp[i+1][j|choice],dp[i][j]+cost[i]);//i番目を選択する
            chmin(dp[i+1][j],dp[i][j]);//i番目を選択しない
        }
    }

/*    rep(i,m+1){
        rep(j,1<<n){
            if(dp[i][j]!=INF) cout<<dp[i][j]<<" ";
            else cout<<-1<<" ";
        }
        cout<<endl;
    }
*/

    if(dp[m][(1<<n)-1]!=INF) cout<<dp[m][(1<<n)-1]<<endl;
    else cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 35732
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CThREE {
public:
    int cnto = 0, cnte = 0;
    vc<int> col, ans;
    vvc<int> G;

    void dfs(int s, int p, int c){
        if(c) cnto++;
        else cnte++;
        col[s] = c;
        for(auto u : G[s]){
            if(u==p) continue;
            dfs(u, s, c^1);
        }
    }

    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        G.resize(N);
        col.resize(N);
        ans.resize(N);
        REP(i, N-1){
            int a, b;
            in>>a>>b;
            a--, b--;
            G[a].pb(b);
            G[b].pb(a);
        }
        dfs(0, -1, 0);
        int z = 3, o = 1, e = 2;
        if(cnto<=N/3){
            REP(i, N){
                if(col[i]) ans[i] = z, z += 3;
                else{
                    if(o<=N) ans[i] = o, o += 3;
                    else if(e<=N) ans[i] = e, e += 3;
                    else ans[i] = z, z += 3;
                }
            }
        }else if(cnte<=N/3){
            REP(i, N){
                if(col[i]==0) ans[i] = z, z += 3;
                else{
                    if(o<=N) ans[i] = o, o += 3;
                    else if(e<=N) ans[i] = e, e += 3;
                    else ans[i] = z, z += 3;
                }
            }
        }else{
            REP(i, N){
                if(col[i]){
                    if(o<=N) ans[i] = o, o += 3;
                    else ans[i] = z, z += 3;
                }else{
                    if(e<=N) ans[i] = e, e += 3;
                    else ans[i] = z, z += 3;
                }
            }
        }
        for(auto a : ans) out<<a<<' ';
        out<<'\n';
    }
};


int main() {
	CThREE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 14832