akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<map>
using namespace std;
 
#define N 100000
#define fs first
#define sc second
typedef pair<int,int> P;

P par[N];
int rank[N];
 
void init(int n){
  for(int i=0;i<n;i++)par[i] = P(i,0);
}
 
P find(int a){
  if(par[a].fs == a)return par[a];
  P tmp = find(par[a].fs);
  return par[a] = P(tmp.fs,tmp.sc + par[a].sc);
}
 
bool same(int a,int b){
  return (find(a).fs == find(b).fs);
}

bool unite(int a,int b,int cost){
  P x = find(a);
  P y = find(b);
     
  if(same(x.fs,y.fs)){
    if(y.sc - x.sc != cost)return false;
  }else{
    if(rank[x.fs]<rank[y.fs]){
      par[x.fs] = P(y.fs,y.sc-x.sc-cost);
    }else{
      par[y.fs] = P(x.fs,x.sc-y.sc+cost);
      if(rank[x.fs] == rank[y.fs])rank[x.fs]++;
    }
  }
  return true;
}

int main(){
  char c;
  int a,b,w,n,m;

  while(scanf("%d%d",&n,&m),(n||m)){
    init(n);
    for(int i=0;i<m;i++){
      scanf(" %c ",&c);
      if(c=='?'){
	scanf("%d%d",&a,&b);
	a--; b--;
	if(same(a,b))printf("%d\n",par[b].sc - par[a].sc);
	else printf("UNKNOWN\n");
      }else{
	scanf("%d%d%d",&a,&b,&w);
	a--; b--;
	unite(a,b,w);
      }
    }
  }
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N, M;
	
	while (cin >> N >> M, N) {
		vector< int > P(N);
		for_(i,0,N) cin >> P[i];
		
		P.push_back(0);
		for_(i,0,N) for_(j,0,N) if (P[i] + P[j] <= M) P.push_back(P[i] + P[j]);
		sort(P.begin(), P.end());
		
		int m = P.size(), ans = 0;
		for_(i,0,m) {
			int x = P[i];
			int y = *(upper_bound(P.begin(), P.end(), M - x) - 1);
			ans = max(ans, x + y);
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 10736
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+5;
void solve(){
	string s,t; 
	cin>>s>>t; 
	int n = s.size();
	int m = t.size();
	int ans = 1e9;
	for(int i=0;i<=n-m;i++){
		int trt = 0;
		for(int j=0;j<m;j++){
			if(t[j]!=s[i+j])trt++;
		}
		ans = min(ans,trt);
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

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

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()


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

    vector<int> p(n);
    REP(i, n) {
        cin >> p[i];
    }

    int cnt = 0;
    REP2(i, 1, n-1) {
        if (p[i] > p[i-1] && p[i] < p[i+1]) {
            cnt++;
        }
        if (p[i] > p[i+1] && p[i] < p[i-1]) {
            cnt++;
        }
    }
    std::cout << cnt << '\n';

    return 0;
}


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

int main() {
  ll k, n; cin >> k >> n;
  vector<ll> a(2 * n); rep(i, n) cin >> a[i];
  rep(i, n)
    a[i+n] = a[i] + k;
  ll ans = 2e13;
  rep(i, n+1) {
    ans = min(a[i+n-1] - a[i], ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    int i, j;
    for(i=sqrt(N); i>=0; i--){
        if(N%i==0){
            j=N/i;
            break;
        }
    }
    if(i<j){
        swap(i,j);
    }
    int ans=1;
    while(i/10>0){
        i/=10;
        ans++;
    }
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int n=gi();
	    int m=gi();
	    
        int a=0;
        if(n!=0) {
        	a+= n*(n-1);
        }
        if(m!=0) {
        	a+= m*(m-1);
        }

	    System.out.print(a/2);

//        if (s.charAt(0)==s.charAt(1) && s.charAt(1)== s.charAt(2)) {
//        	System.out.print("Yes");
//        }else {
//        	System.out.print("No");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35728
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct Edge {
    int to, cost, enemy;
    Edge(int t, int c, int e) : to(t), cost(c), enemy(e) {}
};
typedef vector< vector<Edge> > Graph;

struct Elem {
    int pos, money, cost;
    Elem(int p, int m, int c) : pos(p), money(m), cost(c) {}
    bool operator<(const Elem &x) const {
        return cost > x.cost;
    }
};

const int INF = 1 << 28;
int N, M, L;
int dist[110][110];

int main() {
    while(1) {
        scanf("%d%d%d", &N, &M, &L);
        if(!N) break;

        Graph G(N);
        for(int i=0; i<M; i++) {
            int a, b, d, e; scanf("%d%d%d%d", &a, &b, &d, &e);
            a--; b--;
            G[a].push_back(Edge(b, d, e));
            G[b].push_back(Edge(a, d, e));
        }

        for(int i=0; i<N; i++) {
            fill(dist[i], dist[i]+L+1, INF);
        }
        dist[0][L] = 0;

        // 出発地 0 で目的地 N-1
        priority_queue<Elem> que;
        que.push(Elem(0, L, 0));
        while(que.size()) {
            Elem cur = que.top(); que.pop();
            for(size_t i=0; i<G[cur.pos].size(); i++) {
                Edge e = G[cur.pos][i];
                // 雇える
                if(e.cost <= cur.money) {
                    int n_money = cur.money - e.cost;
                    int n_pos   = e.to;
                    int n_cost  = cur.cost;
                    if(dist[n_pos][n_money] > n_cost) {
                        dist[n_pos][n_money] = n_cost;
                        que.push(Elem(n_pos, n_money, n_cost));
                    }
                }
                // 雇わない
                int n_money = cur.money;
                int n_pos   = e.to;
                int n_cost  = cur.cost + e.enemy;
                if(dist[n_pos][n_money] > n_cost) {
                    dist[n_pos][n_money] = n_cost;
                    que.push(Elem(n_pos, n_money, n_cost));
                }
            }
        }
        printf("%d\n", *min_element(dist[N-1], dist[N-1]+L+1));
    }
    return 0;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9
// Darker and Darker

int H, W;
vector<string> A;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int main(){
  cin >> H >> W;
  A.resize(H);
  REP(i, H){
    cin >> A[i];
  }
  queue<pair<int, int>> que;
  vector<vector<int>> homon(H, vector<int>(W, 0));
  REP(i, H){
    REP(j, W){
      if(A[i][j] == '#'){
        que.push({i, j});
      }
    }
  }
  int ans = 0;
  while(!que.empty()){
    int x, y;
    tie(y, x) = que.front();
    que.pop();
    REP(i, 4){
      int nx = x + dx[i], ny = y + dy[i];
      if(nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
      if(A[ny][nx] == '.'){
        homon[ny][nx] = homon[y][x]+1;
        ans = max(ans, homon[ny][nx]);
        A[ny][nx] = '#';
        que.push({ny, nx});
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13456
// ABC154_B
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <cstring>  // std::memset
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
#define rep(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define rep1(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define repr(i, n) for (ll i=n-1; i >= 0; i++)  // n-1 ~ 0
#define all(vec) (vec).begin(), (vec).end()
#define sum(vec) accumulate(all(vec), 0LL)  // 0 は初期値
#define min_vec(vec) min_element(all(vec))  // iterator: * を先頭につける
#define max_vec(vec) max_element(all(vec))  // iterator: * を先頭につける
#define idx(vec, element_iter) distance((vec).begin(), element_iter)
const ll INF = 1LL<<60;  // 10^18（const int inf = 1<<29;）
const double PI = acos(-1);

void replaceStr(string &str, char sub) {
    // target -> sub
    for (ll i = 0; i < str.length(); ++i) {
        str[i] = sub;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    // input(sunippets: inpv, inpn, inps)
    string S;
    cin >> S;
    
    // calculation
    replaceStr(S, 'x');
    cout << S << "\n";
    return 0;
}



Measured memory_bytes: 256
temp_a, temp_b, temp_c, temp_d, temp_e = [int(input()) for _ in range(5)]

frozen = temp_c * abs(temp_a) 
not_frozen = temp_e * temp_b + temp_d

if temp_a <= 0:
    print(frozen + not_frozen)
else:
    print((temp_b - temp_a) * temp_e)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
long long int sum(long long int a,long long int b) 
{ 
    // add two numbers 
    long long int s = a + b; 
  
    // do a mod with m 
    s = s % mod; 
  
    return s; 
} 
int main()
{
    long long int r,c;
    cin>>r>>c;
    long long int grid[r][c];

    for(long long int i=0;i<r;i++)
    {
        for(long long int j=0;j<c;j++)
        {
            char c; cin>>c;
            if(c=='.')
                grid[i][j] = 0;
            else 
            {
                grid[i][j] = 1;
            }
        }
    }
    
    vector<vector<long long int> > dp(r + 1, vector<long long int> (c + 1, 0));
    dp[0][1] = 1;
        
    for (int i = 1; i <= r; i++)
            for (int j = 1; j <= c; j++)
                if (grid[i - 1][j - 1]==0)
                    dp[i][j] = sum(dp[i - 1][j],dp[i][j - 1]);
        
    cout<<dp[r][c]<<endl;
    return 0;


}

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

/*
int main() {
	ll n; cin >> n;

	string c;

	
	while(n){
		ll r = n % 26;
		string s;
		s = (char)((int)r + 96);

		s += c;

		c = s;

		//cout << r + 96 << endl;

		n /= 26;
	}

	cout << c << endl;
	return 0;
}
*/



ll ll_max(int a, ll b) {
	ll A = (ll)a;
	if (A > b) return A;
	else return b;
}

int main() {
	int n; cin >> n;
	vector<ll> a(n);
	ll s = 0;

	map<ll, ll> mp;

	rep(i, n) {
		cin >> a[i];
		s += a[i];
		mp[a[i]]++;
	}
	int q; cin >> q;
	vector<ll> si(q);

	rep(i, q) {
		ll b, c; cin >> b >> c;

		if (mp[b] == 0) {
			si[i] = s;
			continue;
		}
		//b => cにする
		s = s - b * mp[b] + c * mp[b];
		si[i] = s;

		mp[c] += mp[b];
		mp[b] = 0;

		
	}

	
	rep(i, q) {
		cout << si[i] << endl;
	}
	
}


Measured memory_bytes: 10552
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=1<<18;

int main(){
    int n,q;
    cin>>n>>q;
    vector<vector<int> > G(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> count(n,0);
    for(int i=0;i<q;i++){
        int p,x;
        cin>>p>>x;
        p--;
        count[p]+=x;
    }
    vector<bool> done(n,false);
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()){
        int u=Q.front(); Q.pop();
        done[u]=true;
        for(int v:G[u]){
            if(!done[v]){
                count[v]+=count[u];
                Q.push(v);
            }
        }
    }

    for(int i=0;i<n;i++){
        cout<<count[i]<<" ";
    }
    cout<<endl;

}

Measured memory_bytes: 16580
#include<bits/stdc++.h>
using namespace std;
int main()

 {
     int a[35]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51},i,n;
     cin>>n;
     for(i=0;i<n;i++)
     {
         if(i==n-1)
         {
             cout<<a[i]<<endl;
         }
     }
     return 0;
 }


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

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

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

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

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

int n, W;
int weight[110], value[110];

int dp[110][10010];

int main() {
   cin >> n >> W;
   rep (i, n) cin >> value[i] >> weight[i];

   rep (i, W+1) dp[0][W] = 0;

   rep (i, n) {
      for (int w = 0; w <= W; w++) {
         if (w >= weight[i]) {
            dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
         } else {
            dp[i+1][w] = dp[i][w];
         }
      }
   }

   cout << dp[n][W] << endl;

   return 0;
}


Measured memory_bytes: 7020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		
		long[] A = new long[N];
		long ans = 0;
		StringTokenizer st = new StringTokenizer(br.readLine());
		for(int i=0; i<N; i++)
			A[i] = Long.parseLong(st.nextToken());
		
		for(int i=1; i<N; i++) {
			if(A[i-1] > A[i]) {
				ans += A[i-1] - A[i];
				A[i] = A[i-1];
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 55628
N = int(input())
ST = []
for i in range(N):
    s, t = input().split()
    ST.append([s, int(t)])
X = input()

flag = False
r = 0
for s, t in ST:
    # print(s, t)
    if s == X:
        flag = True
        continue
    if flag:
        r += t

print(r)

Measured memory_bytes: 3064
INT_MAX=10**11+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
a,b=INPUT()
print(a*b)


Measured memory_bytes: 61716
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

D = get_input()

A = {}

for d in D:
    s, p = [x for x in d.split()]
    p = int(p)
    if s in A:
        A[s].append(p)
    else:
        A[s] = [p]

B = sorted(A)

for i in B:
    L = sorted(list(A[i]))
    print(i)
    printA(L)




Measured memory_bytes: 5728
import java.util.*;
public class Main{
	public static void main(String[] a){
    	buffet();
    }
  	public static void buffet(){
    	Scanner s = new Scanner(System.in);
    	int n = s.nextInt();
    	int[] as = new int[n];
    	int[] bs = new int[n];
		int[] cs = new int[n-1];
    	for (int i = 0; i < n; i++){
    		as[i] = s.nextInt();
		}
		for (int i = 0; i < n; i++){
			bs[i] = s.nextInt();
		}
		for (int i = 0; i < n - 1; i++){
			cs[i] = s.nextInt();
		}

		int sum = 0;
		for (int a : as){
			sum += bs[a-1];
		}
		for (int i=0; i < n - 1; i++){
			if (as[i] + 1 == as[i + 1])
				sum += cs[as[i] - 1];
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 23636
#include<stdio.h>
int main(void){
	int n,m,a[4]={0,-1,-1,-1},s,c,i,j,f=0;
	scanf("%d %d",&n,&m);
	if(n==3){
		for(i=0;i<m;i++){
			scanf("%d %d",&s,&c);
			if(a[s]==-1||a[s]==c){
				a[s]=c;
			}else{
				f=-1;
			}
		}
		for(i=2;i<=3;i++){
			if(a[i]<0){
				a[i]=0;
			}
		}
		if(a[1]==0){
			f=-1;
		}else if(a[1]<0){
			a[1]=1;
		}
		
		if(f==-1){
			printf("-1\n");
		}else{
			printf("%d\n",a[1]*100+a[2]*10+a[3]);
		}
	}else if(n==2){
		for(i=0;i<m;i++){
			scanf("%d %d",&s,&c);
			if(a[s]==-1||a[s]==c){
				a[s]=c;
			}else{
				f=-1;
			}
		}
		if(a[1]==0){
			f=-1;
		}else if(a[1]<0){
			a[1]=1;
		}
		if(a[2]<0){
			a[2]=0;
		}
		if(f==-1){
			printf("-1\n");
		}else{
			printf("%d\n",a[1]*10+a[2]);
		}
	}else if(n==1){
		for(i=0;i<m;i++){
			scanf("%d %d",&s,&c);
			if(a[s]==-1||a[s]==c){
				a[s]=c;
			}else{
				f=-1;
			}
		}
		if(a[1]<0){
			a[1]=0;
		}
		if(f==-1){
			printf("-1\n");
		}else{
			printf("%d\n",a[1]);
		}
	}
		
	return 0;
}

Measured memory_bytes: 128
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = getLine >> solve <$> f >>= print
  where
    f = readil B.readInt <$> B.getLine

solve :: [Int] -> Int
solve xs = minimum $ map (power xs) [1..100]

power :: [Int] -> Int -> Int
power xs p = sum [(p - x) ^ 2 | x <- xs]

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')


Measured memory_bytes: 508
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main(){
  int a,b;
  stringstream c;
  vector<int> d;
  while(cin >> a >> b){
    c.str("");
    c << a+b;
    string str = c.str();
    d.push_back(str.length());
  }

  for(int i=0; i<d.size(); i++){
    cout << d[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1244
N = int(input())
H_list = list(map(int,input().split()))
max_h = 0
flag = True
for i in H_list:
  if(i >= max_h):
    max_h = i
  elif(max_h-1 >i):
    print("No")
    flag = False
    break
if flag:
  print ("Yes")


Measured memory_bytes: 14252
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b;
    cin>>a>>b;
    
    ll ans;
    if(abs(a)<=abs(b)){
        ans=abs(b)-abs(a);
        if(a<0) ans++;
        if(b<0) ans++;
    }else{
        ans=abs(a)-abs(b);
        if(a>0) ans++;
        if(b>0) ans++;
    }
    cout1(ans)
}

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

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 75352
def out_p(bx, by, x0, y0, x1, y1):
    a, b = x0-bx, y0-by
    c, d = x1-bx, y1-by
    return a*d - b*c
def sgn(x):
    return -1 if x<0 else 1
n = input()
xp = [0] * 3; yp = [0] * 3;
xk, yk, xs, ys = [0]*4
for i in xrange(n):
    xp[0], yp[0], xp[1], yp[1], xp[2], yp[2], xk, yk, xs, ys = map(int, raw_input().split())
    rk = [0]*3
    for i in xrange(3):
        rk[i] = sgn(out_p(xp[i], yp[i], xp[i-2], yp[i-2], xk, yk))
    k_in = (rk[0] == rk[1] == rk[2])
    rs = [0]*3
    for i in xrange(3):
        rs[i] = sgn(out_p(xp[i], yp[i], xp[i-2], yp[i-2], xs, ys))
    s_in = (rs[0] == rs[1] == rs[2])
    print "OK" if k_in ^ s_in else "NG"

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

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
#define len(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define lb lower_bound
#define ub upper_bound
#define mine min_element
#define maxe max_element
#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <class T> void __f(const char* name, T&& a) {
    cerr << name << ": " << a << '\n';
}
template <class T, class... Ts> void __f(const char* names, T&& a, Ts&&... b) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << a << " /";
    __f(comma + 1, b...);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> bool mini(T& a, const T& b) { return a > b ? (a = b, 1) : 0; }
template <class T> bool maxi(T& a, const T& b) { return a < b ? (a = b, 1) : 0; }

typedef long long ll;
typedef double db;
typedef pair<int, int> pi;
typedef pair<int, pi> ti;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ti> vti;
typedef vector<vpi> vvpi;

const int inf = (int)0x3f3f3f3f3f3f3f3f;
const int ninf = (int)0xc0c0c0c0c0c0c0c0;
const int M = (int)1e9 + 7;
const int N = 2e5 + 3;

int n, m, par[N];

int root(int u) {
    return par[u] < 0 ? u : par[u] = root(par[u]);
}

bool dsu(int u, int v) {
    if ((u = root(u)) == (v = root(v))) return 0;
    if (par[u] > par[v]) swap(u, v);
    par[u] += par[v];
    par[v] = u;
    return 1;
}

signed main() {
//    freopen("CP.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    ms(par, -1);
    while (m--) {
        int u, v; cin >> u >> v;
        dsu(u, v);
    }
    int ans = 0;
    fort(i, 1, n) maxi(ans, -par[root(i)]);
    cout << ans << '\n';
}


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

const int N = 3000;

int ans[N][N][2];

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

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

	vector<pair<int, int>> xs(n);
	for (auto& x : xs) {
		cin >> x.first >> x.second;
	}

	sort(xs.begin(), xs.end());

	for (int j = 0; j < m; j++) {
		if (j >= xs[n-1].first) {
			ans[n-1][j][0] = xs[n-1].second;
		}
		ans[n-1][j][1] = xs[n-1].second;
	}
	for (int i = n-2; i >= 0; i--) {
		for (int j = 0; j < m; j++) {
			ans[i][j][0] = ans[i+1][j][0];
			ans[i][j][1] = ans[i+1][j][1];
			if (j >= xs[i].first) {
				ans[i][j][0] = max(ans[i][j][0], ans[i+1][j-xs[i].first][0] + xs[i].second);
				ans[i][j][1] = max(ans[i][j][1], ans[i+1][j-xs[i].first][1] + xs[i].second);
			}
			ans[i][j][1] = max(ans[i][j][1], ans[i+1][j][0] + xs[i].second);
		}
	}
	cout << max(ans[0][m-1][0], ans[0][m-1][1]) << endl;

	return 0;
}



Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);
}

int main()
{
   IOS
    int n;
    int m;
    cin>>n>>m;
    ll arr[100005];
    fo(i,n){
        cin>>arr[i];
        arr[i]=arr[i]/2;
    /*if(arr[i]%2==0) {
        cout<<0<<endl;
        return 0;
      }*/
    }
    ll ans=1;
    fo(i,n){
        ans=(arr[i]*ans)/gcd(arr[i],ans);

    }
    fo(i,n){
        if((ans/arr[i])%2==0) {cout<<0<<endl; return 0; }
    }
    
    //cout<<ans<<"  dfds "<<endl;
    int left=m/ans;
    if(left==0){cout<<0<<endl; return 0;}
    int real=(left-1)/2+1;
    if(real>0) cout<<real<<endl;



}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		no1();
	}

	static void no1() {
		try (Scanner sc = new Scanner(System.in)) {
			long x = sc.nextLong();
			long y = sc.nextLong();

			if (x % y == 0) {
				System.out.println("-1");
				return;
			}

			long i = 1;
			long t = x;
			while (true) {
				if (t % y != 0) {
					System.out.println(t);
					return;
				}
				if(t > 1000000000000000000L - x) {
					System.out.println("-1");
					return;
				}
				t += x;
			}
		}
	}

}


Measured memory_bytes: 23124
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999

int main(){
  int N,K,ans=0,p;
  cin >>N>>K;
  REP(i,N){
    cin >>p;
    if(p>=K)ans++;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> A, std::vector<long long> B){
  ll ans=0;
  vector<ll> cpA(A),cpB(B);
  sort(cpA.begin(),cpA.end());
  sort(cpB.begin(),cpB.end());
  if(N%2){
    ans=cpB[N/2]-cpA[N/2]+1;
  }else{
    ans=cpB[N/2]+cpB[N/2-1]-cpA[N/2]-cpA[N/2-1]+1;
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9596
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

int main(){fastio
    ll n,m;cin>>n>>m;
    rep(i,0,m-1){
        ll c;cin>>c;
        n-=c;
    }
    if(n<0)n=-1;
    cout<<n<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3652
N,T = map(int,input().split())
t = list(map(int,input().split()))
X = 0

for i in range(N):
  if t[i] == 0:
    continue
  elif t[i] - t[i-1] > T:
    X += T
  else:
    X += (t[i] - t[i-1])

X += T
print(X)

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i = (n); i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = (ll)(1e9+7);//998244353;
const int N = (int)(1e6+5);

void pre() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int n,k;  cin>>n>>k;
  vector<int> a(n);
  rep(i,n)  cin>>a[i];
  rep(i,n) {
    if(i < k) continue;
    if(a[i] > a[i-k]) cout<<"Yes";
    else  cout<<"No";
    cout<<'\n';
  }
}

int main() {
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  pre();
  int t = 1;
  //cin>>t;
  rep(i,t)  {
    //cout<<"Case #"<<(i+1)<<": ";
    solve();
    cout<<'\n';
  }
  return 0;
}


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

using namespace std;

#define ll long long int

void printStr(ll n)
{
    char str[1000];
    ll i=0;
    while(n>0)
    {
        ll rem = n%26;
        if(rem==0)
        {
            str[i++] = 'z';
            n = (n/26)-1;
        }
        else
        {
            str[i++] = (rem-1)+'a';
            n = n/26;
        }
    }
    str[i]='\0';
    reverse(str, str + strlen(str));
    cout << str << endl;
    return ;
}
int main()
{
    long long int n;
    cin>>n;
    printStr(n);

    return 0;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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


class CompleteBinaryTree{
    VI A;
public:
    CompleteBinaryTree(int n){
        A.resize(n + 1);
    }
    void setValue(int i, int v){
        A[i] = v;
    }

    int getValue(int i){
        return A[i];
    }

    bool haveParent(int i){
        return i / 2 >= 1;
    }

    int parent(int i){
        return A[i / 2];
    }

    bool haveLeft(int i){
        return 2 * i < int(A.size());
    }

    int left(int i){
        return A[2 * i];
    }

    bool haveRight(int i){
        return 2 * i + 1 < int(A.size());
    }

    int right(int i){
        return A[2 * i + 1];
    }
};

int main(){
    int H; cin >> H;
    CompleteBinaryTree T(H);
    FORS(i, 1, H){
        int a; cin >> a;
        T.setValue(i, a);
    }
    FORS(i, 1, H){
        cout << "node " << i << ": key = " << T.getValue(i) << ", ";
        if(T.haveParent(i)) cout << "parent key = " << T.parent(i) << ", ";
        if(T.haveLeft(i)) cout << "left key = " << T.left(i) << ", ";
        if(T.haveRight(i)) cout << "right key = " << T.right(i) << ", ";
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());

    long long ans = 1;
    if(k % 2 != 0){
        if(a.back() < 0){
            for(int i=0; i<k; ++i){
                ans *= a[n-1-i];
                ans = (ans % MOD + MOD) % MOD;
            }
            cout << ans << endl;
            return 0;
        }
        ans = a.back();
        a.pop_back();
        -- n;
        -- k;
    }

    int x = 0;
    int y = n - 1;
    while(k > 0){
        long long val1 = a[x] * (long long)a[x+1];
        long long val2 = a[y] * (long long)a[y-1];
        if(val1 > val2){
            ans *= val1 % MOD;
            x += 2;
        }
        else{
            ans *= val2 % MOD;
            y -= 2;
        }
        ans = (ans % MOD + MOD) % MOD;
        k -= 2;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3996
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>

//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
constexpr ll    BIGP = 1000000007;
constexpr ll    INF_I = std::numeric_limits<ll>::max();
constexpr float INF_F = std::numeric_limits<float>::infinity();
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, K;
    vector<ll> h;
    cin >> N >> K;
    rep(i, N)
    {
        ll t;
        cin >> t;
        h.push_back(t);
    }
    vector<ll> dp(N,INF_I);
    dp[0] = 0;
    rep(i, N)
    {
        rep(j, K)
        {
            ll t = i - j - 1;
            if (t >= 0)
            {
                chmin(dp[i], dp[t] + abs(h[i] - h[t]));
            }
        }
    }
    cout << dp.back();
}

Measured memory_bytes: 4528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

struct Card {
  int i, A, B;
  int val(int j) { return (i - j) % 2 == 0 ? A : B; }
};

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

  vector<Card> C(N);
  rep(i, N) C[i].i = i;
  rep(i, N) cin >> C[i].A;
  rep(i, N) cin >> C[i].B;

  const int INF = 1e9;
  vector<vector<int>> dp((1 << N), vector<int>(N, INF));

  rep(i, N) dp[0][i] = 0;

  rep(s, (1 << N)) {
    int c = __builtin_popcount(s);
    rep(i, N) {
      if (s && !((s >> i) & 1)) continue;
      if (dp[s][i] == INF) continue;

      int inv = -1;
      rep(j, N) {
        if ((s >> j) & 1) continue;
        ++inv;
        if (c && C[i].val(c - 1) > C[j].val(c)) continue;

        dp[s | (1 << j)][j] = min(dp[s | (1 << j)][j], dp[s][i] + inv);
      }
    }
  }

  int ans = *min_element(all(dp[(1 << N) - 1]));
  if (ans == INF) ans = -1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 26880
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

bool isTrue(string S) {
    bool ret = true;
    for (int i = 0; i < S.size()/2; i++) {
        ret = ret && (S[i] == S[i+S.size()/2]);
    }
    return ret;
}

void solve(string S) {
    bool ret = S.size()-2;
    S.pop_back();
    S.pop_back();
    while(S.size() > 1) {
        if (isTrue(S)) {
            break;
        }
        S.pop_back();
        S.pop_back();
    }
    std::cout << S.size() << std::endl;
}

int main() {
    struct timeval start,end;
    long long span;
    string S;

    gettimeofday(&start,NULL);

    std::cin >> S;
    solve(S);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    int ans = 0;
    sort(p.begin(),p.end());
    for (int i = 0; i < k; i++)
    {
        ans += p[i];
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string S;
    cin >> S;
    cout << S.substr(0,3) << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = (int)1e6+7;

ll dfs(ll now) {
    if (now == 0) return 0;
    if (now == 1) return 1;
    ll to = now/2;
    return dfs(to)*2+1;
}

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

    ll n;
    cin >> n;
    cout << dfs(n) << endl;
}




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

int main() {
	int n, m, l, mat1[100][100], mat2[100][100];
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> mat1[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> mat2[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			long long sum = 0;
			for (int k = 0; k < m; k++) {
				sum += mat1[i][k] * mat2[k][j];
			}
			cout << sum;
			if (j < l - 1) cout << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 1232