akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

pair<char,int> data[40];
int n;
void SelectionSort(){
	REP(i,n-1){
		int minp,mindata;
		minp = i;
		mindata = data[i].second;
		FOR(j,i+1,n){
			if(mindata>data[j].second){
				minp = j;
				mindata = data[j].second;
			}
		}
		if(data[i].second!=mindata){
			swap(data[i],data[minp]);
		}
	}
}

void BubbleSort(){
	for(int i=n-2;i>-1;i--){
		REP(j,i+1){
			if(data[j].second>data[j+1].second) {
				swap(data[j+1],data[j]);
			}
		}
	}
}

void PrintArray(){
	REP(i,n){
		cout << data[i].first << data[i].second;
		if(i!=n-1) cout << " ";
	}
	cout << endl;
}
int main(){
	string s;
	cin >> n;
	REP(i,n){
		cin >> s;
		data[i].first = s[0];
		data[i].second = stoi(s.substr(1));
	}
	pair <char,int> data2[40];
	string orderstr[10];
	string orderstr2[10];
	REP(i,n) data2[i] = data[i];
	REP(i,10) orderstr[i] = "";
	REP(i,n) orderstr[data[i].second]+=data[i].first;
	REP(i,10) orderstr2[i] = orderstr[i];

	BubbleSort();
	PrintArray();
	bool flg = true;
	REP(i,10) orderstr[i] = "";
	REP(i,n) orderstr[data[i].second]+=data[i].first;
	REP(i,10){
		if(orderstr[i]!=orderstr2[i]) {
			flg = false;
		}
	}
	cout << (flg? "Stable" : "Not stable") << endl;
	REP(i,10) orderstr[i] = orderstr2[i];

	REP(i,n) data[i] = data2[i];
	SelectionSort();
	PrintArray();
	flg = true;
	REP(i,10) orderstr[i] = "";
	REP(i,n) orderstr[data[i].second]+=data[i].first;
	REP(i,10){
		if(orderstr[i]!=orderstr2[i]) flg = false;
	}
	cout << (flg? "Stable" : "Not stable") << endl;
	
}

Measured memory_bytes: 1232
# ABC150C - Count Order
from itertools import permutations


def main():
    N, *PQ = map(int, open(0).read().split())
    P, Q = PQ[:N], PQ[N:]
    a, b = 0, 0
    for i, perm in enumerate(permutations(range(1, N + 1), N), 1):
        perm = list(perm)
        if perm == P:
            a = i
        if perm == Q:
            b = i
    ans = abs(a - b)
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    vector<int> compare_p(N);
    int count = 0;
    for (int i = 0; i < N; i++) {
        cin >> p.at(i);
        compare_p.at(i) = i + 1;
    }
    for (int i = 0; i < N; i++) {
        if (p.at(i) != compare_p.at(i)) {
           count++; 
        }
    }
    if ((count == 0) || (count == 2)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int k = sc.nextInt();

			Integer [][] data = new Integer[n][2];
			for(int i = 0; i < n; i++){
				data[i][0] = sc.nextInt();
				data[i][1] = sc.nextInt();
			}
			Arrays.sort(data,new Comparator<Integer[]>() {
				@Override
				public int compare(Integer[] o1, Integer[] o2) {
					if(o1[0] < o2[0]) return -1;
					if(o1[0] > o2[0]) return 1;
					if(o1[1] < o2[1]) return -1;
					if(o1[1] > o2[1]) return 1;
					return 0;
				}
			});
			
			
			long min = Long.MAX_VALUE;
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					for(int ii = 0; ii < n; ii++){
						for(int jj = 0; jj < n; jj++){
							
							int count = 0;
							for(int kk = 0; kk < n; kk++){
//								debug(data[kk]);
								if(data[i][0] <= data[kk][0] && data[kk][0] <= data[ii][0]
										&& data[j][1] <= data[kk][1] && data[kk][1] <= data[jj][1]){
									count++;
								}
							}
							if(count >= k){
								min = Math.min(min, ((long)data[ii][0] - data[i][0]) * ((long)data[jj][1] - data[j][1]) );
							}
						}
					}
				}
			}
			System.out.println(min);
		}
	}



	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 22844
r, c = map(int, input().split())
TBL = [list(map(int, input().split())) for _ in range(r)]
for i in TBL:
    i.append(sum(i))
TTL = [0 for i in range(c + 1)]
for i in TBL:
    for j in range(c + 1):
        TTL[j] += i[j]
TBL.append(TTL)
for i in TBL:
    ROW = ' '.join(map(str, i))
    print(ROW)


Measured memory_bytes: 5704
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] arg) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int sum = 0;
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
 
            if (m == -1 && f == -1 && r == -1)
                break;
            sum = m + f;
            if (m == (-1) || f == (-1)) {
                System.out.println("F");
            } else if (sum >= 80) {
                System.out.println("A");
            } else if (sum >= 65) {
                System.out.println("B");
            } else if (sum >= 50) {
                System.out.println("C");
            } else if (sum >= 30) {
                if (r >= 50) {
                    System.out.println("C");
                } else {
                    System.out.println("D");
                }
            } else {
                System.out.println("F");
            }
 
        }
        sc.close();
 
    }
 
}


Measured memory_bytes: 26360
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

        Scanner cin=new Scanner(System.in);
        String a = cin.nextLine();
        String[] b = cin.nextLine().split(" ");

        int[] c = new int[Integer.parseInt(a)];

        for(int i = 0; i < c.length; i++){
        	c[i] = Integer.parseInt(b[i]);
        }

        int max = 0;

        for(int i = 0; i < c.length; i++){
        	if(max < c[i]){
        		max = c[i];
        	}
        }

        int now = max;
        int count = max + 1;
        int numberCount = 0;
        boolean possible = true;
        while(count > 0){
            for(int k = 0; k < c.length; k++){
            	if(c[k] == now){
            		numberCount++;
            	}
            }

            if(numberCount !=  1 && count == 1){
            	possible = false;
            	break;
            }
            if(numberCount !=  2 && count == 2){
            	possible = false;
            	break;
            }
            if(numberCount < 2 && count != 2 && count != 1){
            	possible = false;
            	break;
            }

            count = count - 2;
            numberCount = 0;
            now--;
        }

        if(possible){
        	System.out.println("Possible");
        }else{
        	System.out.println("Impossible");
        }

	}

}

Measured memory_bytes: 9044
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n;
map<string, long long> cnt;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		cnt[s]++;
	}
	long long sum = 0;
	for(auto &i : cnt) sum += i.second * (i.second - 1) / 2;
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  string s; cin >> s;

  int cnt = 0;
  for(int i = 0; i < 1000; i++){
    string t = to_string(i);
    while(t.size() < 3) t = "0" + t;
    vector<bool> a(3, 0);
    int now = 0;
    for(int j = 0; j < n; j++){
      if(s[j] == t[now]){
        if(now == 2){
          cnt++;
          break;
        }else {
          now++;
        }
      }
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 384
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long a = tmp[0], b = tmp[1], c = tmp[2], k = tmp[3];
    writeln(k & 1 ? b - a : a - b);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define e endl
#define pii pair<int,int>
#define infinity 1<<30

using namespace std;
map<ll ,ll>check;
#define xam 10000
ll ara[xam];

int main()
{

   ll n;
   cin>>n;
   while(n){
     ll rem=n%10;
     if(rem==7){
        cout<<"Yes"<<endl;
        return 0;
     }
     n/=10;
   }
   cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(){
  int a,b,n;


  scanf("%d%d",&a,&b);

  if(a > b){
    n = a;
    a = b;
    b = n;
  }

  while(1){
    n = a % b;
    if(n == 0)break;
    a = b;
    b = n;
  }
  printf("%d\n",b);
  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int dp[100001];

int main()
{
  int N;
  string S;

  cin >> N;
  cin.ignore();
  cin >> S;

  for (int i = 1; i <= N; i++) {
    dp[i] = max(dp[i], dp[i - 1]);
    if (S[i] != S[i - 1] && i <= N - 1) {
      dp[i + 1] = max(dp[i + 1], dp[i - 1] + 1);
    }
  }
  cout << dp[N] << endl;
}



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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a, b, c, x;

int main() {
	cin >> a >> b >> c >> x;
	
	int ans = 0;
	incII(i, 0, a) {
	incII(j, 0, b) {
	incII(k, 0, c) {
		if(500 * i + 100 * j + 50 * k == x) { ans++; }
	}
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::collections::VecDeque;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    let mut q1: VecDeque<(char, usize)> = VecDeque::new();
    let mut current = (s[0], 1);
    for i in 1..n {
        if s[i] != current.0 {
            q1.push_back(current);
            current = (s[i], 1);
        } else {
            current.1 += 1;
        }
    }
    q1.push_back(current);

    let mut count: usize = 0;
    let mut score: usize = 0;
    let mut q2: VecDeque<(char, usize)> = VecDeque::new();
    while count < k && !q1.is_empty() {
        let current = q1.pop_front().unwrap();
        if current.0 == '0' {
            count += 1;
        }
        score += current.1;
        q2.push_back(current);
    }
    if !q1.is_empty() {
        let current = q1.pop_front().unwrap();
        score += current.1;
        q2.push_back(current);
    }

    let mut ans = score;
    while !q1.is_empty() {
        if let Some(removed) = q2.pop_front() {
            score -= removed.1;
            if removed.0 == '1' {
                if let Some(removed2) = q2.pop_front() {
                    score -= removed2.1;
                }
            }
        }
        let next = q1.pop_front().unwrap();
        score += next.1;
        q2.push_back(next);
        if !q1.is_empty() {
            let next = q1.pop_front().unwrap();
            score += next.1;
            q2.push_back(next);
        }
        ans = max(ans, score);
    }
    ans.to_string()
}


Measured memory_bytes: 4932
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

ll dp[3002][3002][4];

ll mp[3002][3002];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int r,c,kk; cin >> r >> c >> kk;
	while(kk--){
		int x,y,z; cin >> x >> y >> z;
		x--; y--;
		mp[x][y]=z;
	}
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			for(int k=0;k<=3;k++){
				dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
				dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
				if(k<3){
					dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]+mp[i][j]);
					dp[i][j+1][k+1]=max(dp[i][j+1][k+1],dp[i][j][k]+mp[i][j]);
				}
			}
		}
	}
	ll res=0;
	for(int i=0;i<=r;i++){
		for(int j=0;j<=c;j++){
			for(int k=0;k<=3;k++){
				res=max(res,dp[i][j][k]);
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 355444
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using ll=long long;

const ll INF = pow(10,18)+1;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}
 
int main(){
    ll N, A[10];
    cin >> N;
    REP(i,5){
        cin >> A[i];
    }
    ll mn = min(A[0],min(A[1],min(A[2],min(A[3],A[4]))));
    ll res = ceil((N-1)/mn) + 5;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int D;
	cin >> D;

	if(D == 25){
		printf("Christmas\n");
	}
	else if(D == 24){
		printf("Christmas Eve\n");
	}
	else if(D == 23){
		printf("Christmas Eve Eve\n");
	}
	else if(D == 22){
		printf("Christmas Eve Eve Eve\n");
	}
	return 0;
}



Measured memory_bytes: 3624
n, y = map(int, input().split())

stop = n + 1
for m in range(stop):
    for g in range(stop - m):
        s = n - m - g
        if y == 10000 * m + 5000 * g + 1000 * s:
            print(m, g, s, sep=" ")
            break
    else:
        continue
    break
else:
    print("-1 -1 -1")

Measured memory_bytes: 9104
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <string.h>
#include <math.h>
#include <stack>
#include <queue>
#include <sstream>
#define inf 1<<30
#define qu queue <int>
#define vc vector <int>
#define pii pair<int,int>
#define mci map <string,int>
#define at  for(int f=0;f<10;f++)
#define mm(o) memset(o,0,sizeof(o))
#define op freopen("in.txt","r",stdin)
#define op1 freopen("out.txt","w",stdout)

using namespace std;

int main()
{
   
    int a[10];
    at
    {
      scanf("%d",&a[f]);

    }
    sort(a,a+10);
    cout<<a[9]<<endl;
    cout<<a[8]<<endl;
    cout<<a[7]<<endl;
    return 0;
}

Measured memory_bytes: 1224
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        A: f64,
        B: f64,
        N: f64,
    }

    let x = f64::min(B - 1.0, N);
    let ans = (A * x / B).floor() - A * (x / B).floor();
    println!("{}", ans);
}


Measured memory_bytes: 2664
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static Scanner in;
	
	private static int n;
	private static int[][] a;
	private static long[] dp;
	private static final int MOD = (int)1e9+7;
	
	public static void main(String[] args) {
		in = new Scanner(System.in);
		n = in.nextInt();
		a =  new int[n][n];
		for(int i=0; i<n; i++) {
			for(int j=0; j<n; j++)
				a[i][j] = in.nextInt();
		}
		
		dp = new long[1<<n+1];
		
//		for(int i=0; i<dp.length; i++)
		Arrays.fill(dp, -1);
		
		System.out.println(solve(0, 0));
		
	}
	
	
	private static long solve(int i, int mask) {
		if (i==n) return 1;
		//mask --> woman mask
		
		
		if (dp[mask]!=-1) return dp[mask];
		
		
		long ans = 0;
		
		for(int j=0; j<n; j++) {
			if ((mask&(1<<j))!=0 || a[i][j]==0) continue;
			
			ans = (ans+solve(i+1, mask|(1<<j)))%MOD;
		}
		
		return dp[mask]=ans;
	}

}


Measured memory_bytes: 58196
n = int(input())
s = input()
import itertools
state = itertools.product(list(range(10)),repeat = 3)
#print(list(state))
def lucky_pin(i):
    spot = -1
    for j in i:
        
        if str(j) in s[spot +1 : ]:
            spot = s[spot +1 : ].find(str(j)) +spot +1
            
        else:
            return 0
    return 1
      
counter = 0
for i in state:
    counter += lucky_pin(i)
        
print(counter)


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

ll seqsum(ll N) {
    ll count = 0;
    for (int i = 1; i < N; i++) {
        count += i;
    }
    return count;
}

int main() {
    ll N;
    map<string, ll> ans;
    cin >> N;
    ll count = 0;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ans[s] ++;
    }

    for (pair<string, ll> t : ans) {
        if (t.second > 1) count += seqsum(t.second);
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <cstdio>
using namespace std;

int main(){
    int A, B;
    int c = 0;
    scanf("%d%d",&A,&B);
    for(int i = A; i <= B; i++){
        if(i/10000 == i%10 && (i/1000)%10 == (i/10)%10){
            c++;
        }
    }
    printf("%d\n",c);
    return 0;
}


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

int main(){
vector<int>a(6);
vector<int>b(6);
for(int c=0;c<6;c++){
	int d;
	cin>>d;
	a[c]=d;
}
for(int c=0;c<6;c++){
	int d;
	cin>>d;
	b[c]=d;
}
vector<int>m(6);
for(int h=0;h<6;h++)
m[h]=a[h];
for(int e=0;e<4;e++){
	a[0] = m[1]; a[1] = m[5]; a[4] = m[0]; a[5] = m[4];
	for(int h=0;h<6;h++)
m[h]=a[h];
for(int f=0;f<4;f++){
	a[0] = m[3]; a[2] = m[0]; a[3] = m[5]; a[5] = m[2];
	for(int h=0;h<6;h++)
m[h]=a[h];
	for(int g=0;g<4;g++){
		a[2] = m[1]; a[4] = m[2]; a[1] = m[3]; a[3] = m[4];
		for(int h=0;h<6;h++)
m[h]=a[h];
       if(a==b)
{cout<<"Yes"<<endl;goto k;}

}}
if(e==3){cout<<"No"<<endl;break;}
}k:;
}

Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            final int A  = sc.nextInt();
            final int B  = sc.nextInt();

            for (int i=0; i<=1000; i++) {
                int eight = (int)Math.floor((double)i * 0.08);
                int ten = (int)Math.floor((double)i * 0.10);
                if (eight == A && ten == B) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println("-1");

        } finally {
            sc.close();
        }
    }
}


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

int main()
{
        int n;
        int *p;
        int i;
        int count=0;

        scanf("%d",&n);
        p=(int*)malloc(sizeof(int)*n);

        for(i=0;i<n;i++){
                scanf("%d",&p[i]);
        }
        for(i=1;i<n-1;i++){
                if(p[i-1]<p[i]&&p[i+1]>p[i]){
                        count++;
                }
                if(p[i-1]>p[i]&&p[i+1]<p[i]){
                        count++;
                }
        }

        printf("%d\n",count);

        free(p);

        return 0;
}
                                                 


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	int N;
	cin >> N;
	vector<ll>v1, v2;
	for (int i = 0; i < N; i++) {
		ll x, y;
		cin >> x >> y;
		v1.pb(x + y);
		v2.pb(x - y);
	}
	sort(all(v1));
	sort(all(v2));

	puts(max(v1[N-1]-v1[0],v2[N-1]-v2[0]));

	return 0;
}

Measured memory_bytes: 6700
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main()
{

	int N;
	cin >> N;

	string S;
	cin >> S;

	int W_W_count = 0;
	int W_E_count = 0;

	int E_W_count = 0;
	int E_E_count = 0;

	for (int i = 1; i < N; i++) {
		if (S[i] == 'W') {
			W_W_count++;
		}
		else {
			W_E_count++;
		}
	}

	int min_count = W_E_count;

	for (int k = 1; k < N; k++) {

		if (S[k] == 'W') {
			W_W_count--;
		}
		else if (S[k] == 'E') {
			W_E_count--;
		}

		if (S[k-1] == 'W') {
			E_W_count++;
		}
		else if (S[k-1] == 'E') {
			E_E_count++;
		}

		if (W_E_count + E_W_count < min_count) {
			min_count = W_E_count + E_W_count;
		}
	}

	cout << min_count << endl;

	return 0;
}

Measured memory_bytes: 900
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::cmp;
use std::collections::LinkedList;

#[allow(dead_code)]
fn getline() -> LinkedList<String> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok().unwrap();
    s.split(' ').map(|x| x.trim().to_string()).collect::<LinkedList<String>>()
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>(l: &mut LinkedList<String>) -> T {
    l.pop_front().and_then(|s| s.parse().ok()).unwrap()
}

fn main() {
    let n: i32 = get(&mut getline());
    let mut ss: Vec<i32> = (0..n).map(|_| get(&mut getline())).collect();
    ss.sort();
    let mut sum = ss.iter().fold(0, |sum, x| sum + x);
    for &x in ss.iter() {
        if sum % 10 != 0 {
            break;
        }
        if x % 10 != 0 {
            sum -= x;
            break;
        }
    }
    if sum % 10 == 0 {
        println!("0");
    } else {
        println!("{}", sum);
    }
}


Measured memory_bytes: 4352
# AOJ 0064: Secret Number
# Python3 2018.6.15 bal4u

ans = k = 0
while True:
	try:
		s = list(input())
		for i in range(len(s)):
			if '0' <= s[i] <= '9': k = 10*k + int(s[i])
			else:
				ans += k
				k = 0
	except EOFError:
		break
print(ans+k)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

int gcd(int a, int b){
    if (b == 0) {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

void solve(){
    int N, K;
    cin >> N >> K;

    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }

    sort(all(h));
    int ans = INT_MAX;

    for (int i = 0; i <= N-K; i++) {
        ans = min(ans, abs(h[i+K-1] - h[i]) );
    }
    cout << ans << endl;


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Vector;

public class Main {
	public static void main(String[] args) {
		int[] p = new int[50000+1];
		p[0] = p[1] = 0;
		for(int i = 2; i <= 50000; i++) {
			p[i] = 1;
		}
		for(int i = 2; i <= Math.sqrt(50000)+1; i++) {
			if(p[i] == 1) {
				for(int j = i*2; j <= 50000; j+=i) {
					p[j] = 0;
				}
			}
		}
		
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) {
				break;
			}
			int ans = 0;
			for(int i = 2; i <= n/2; i++) {
				if(p[i] == 1 && p[n-i] == 1) {
					ans++;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 33560
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T>void read(T &x){
	x = 0; int f(1); char c = getchar();
	for(;!isdigit(c);c = getchar()) if(c == '-') f = -1;
	for(;isdigit(c);c = getchar()) x = x*10+c-'0';
	x *= f;
}
const int maxn = 200005;
int n,hd[maxn],cnt,a[maxn];
struct edge{int ed,nxt;}e[2*maxn];
void star(int u,int v){
	e[++cnt].ed = v;
	e[cnt].nxt = hd[u]; hd[u] = cnt;
}
int dp[maxn],ans[maxn],md;
void dfs(int,int);
int main(){
	read(n);
	for(int i(1);i <= n;++i)	read(a[i]);
	for(int i(1);i < n;++i){
		int u,v; read(u); read(v);
		star(u,v); star(v,u);
	}
	memset(dp,0x3f,sizeof dp);
	dp[0] = 0; dfs(1,0);
	for(int i(1);i <= n;++i)	printf("%d\n",ans[i]);
	return 0;
}
void dfs(int x,int f){
	int s = lower_bound(dp,dp+1+md,a[x])-dp-1;
	ll tmp = dp[s+1]; dp[s+1] = min(dp[s+1],a[x]);
	ll tmp2 = md; md = max(md,s+1);
	ans[x] = md;
	for(int i = hd[x];i;i = e[i].nxt){
		int j = e[i].ed;
		if(j == f)	continue;	
		dfs(j,x);
	}
	md = tmp2; dp[s+1] = tmp;
}

Measured memory_bytes: 24252
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
typedef struct {
	bool a;
	bool b;
} P;
int main( void ){
	int R, G, B, N; cin >> R >> G >> B >> N;
	ll ans = 0;
	ll lim = N + R;
	rep( r, 0, N / R + 1 ){
		lim -= R;
		rep( g, 0, lim / G + 1 ){
			int b = lim - g * G;
			if (b < 0)
				break;
			if ( b % B == 0)
				ans++;

		}
	}
	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pob pop_back
#define ft first
#define sc second
#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define ctz __builtin_ctz
typedef pair<int, int> pii;
const int maxn = 1e6;
 

bool f(int s){
    string str = to_string(s);
    for(int i = 0, si = str.size(); i <= ( si / 2); i++)
        if(str[i] != str[si - i - 1])
            return false;

        return true;



}
int main()
{FAST;
    int l ,r ,res = 0;
    cin >> l >> r;
    forp(i ,l ,r + 1)
        if(f(i))
            res++; 
    cout << res;
   return 0;
}
 












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

typedef pair<ll,int> pli;

int main(){
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    s--; t--;
    vector<pli> a[n],b[n];
    for(int i=0;i<m;i++){
        int u,v;
        ll aa,bb;
        cin>>u>>v>>aa>>bb;
        u--; v--;
        a[u].push_back({aa,v});
        a[v].push_back({aa,u});
        b[u].push_back({bb,v});
        b[v].push_back({bb,u});
    }
    ll d1[n],d2[n];
    for(int i=0;i<n;i++){
        d1[i]=d2[i]=1e18;
    }
    priority_queue<pli,vector<pli>,greater<pli>> pq;
    pq.push({0LL,s});
    d1[s]=0LL;
    while(pq.size()){
        auto v=pq.top();
        pq.pop();
        if(d1[v.second]<v.first)continue;
        for(auto u:a[v.second]){
            if(d1[u.second]>v.first+u.first){
                d1[u.second]=v.first+u.first;
                pq.push({d1[u.second],u.second});
            }
        }
    }
    pq.push({0LL,t});
    d2[t]=0LL;
    while(pq.size()){
        auto v=pq.top();
        pq.pop();
        if(d2[v.second]<v.first)continue;
        for(auto u:b[v.second]){
            if(d2[u.second]>v.first+u.first){
                d2[u.second]=v.first+u.first;
                pq.push({d2[u.second],u.second});
            }
        }
    }
    ll ans[n];
    ans[n-1]=d1[n-1]+d2[n-1];
    for(int i=n-2;i>=0;i--){
        ans[i]=min(ans[i+1],d1[i]+d2[i]);
    }
    for(int i=0;i<n;i++){
        cout<<1000000000000000-ans[i]<<endl;
    }
}


Measured memory_bytes: 19576
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, A[202020];
int dp[202020][4];

void solve() {
    Fill(dp, -INF);

    FOR (i, 0, N) {
        if (i == 0) {
            dp[i][0] = A[i];
            continue;
        }
        if (i == 1) {
            dp[i][1] = A[i];
            continue;
        }
        if (i == 2)
            dp[i][2] = A[i];
        if (i % 2 == 0) {
            dp[i][0] = dp[i - 2][0] + A[i];
            if (i > 2) {
                dp[i][2] = max({dp[i - 2][2], dp[i - 3][1], dp[i - 4][0]}) + A[i];
            }
        } else {
            dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + A[i];
        }
    }
    int ans = -INF;
    if (N % 2 == 0) {
        ans = max(dp[N - 1][1], dp[N - 2][0]);
    } else {
        chmax(ans, dp[N - 1][2]);
        chmax(ans, dp[N - 2][1]);
        if (N - 3 >= 0)
            chmax(ans, dp[N - 3][0]);
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N;
    FOR (N)
        cin >> A[i];

    solve();
    return 0;
}


Measured memory_bytes: 11500
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//トポロジカルソートの結果を返す関数.graphは隣接リスト.0-origin.
//閉路がある場合，空のvectorを返す.
vector<int> tsort(const vector<vector<int>> &graph){
	const int v = graph.size();
	vector<int> indeg(v, 0);
	vector<int> s;
	for (auto out : graph)
	{
		for (auto x:out){
			indeg[x]++;
		}
	}
	for (int i = 0; i < v; i++){
		if(indeg[i] == 0){
			s.push_back(i);
		}
	}
	vector<int> res;
	while(s.size()){
		int u = s.back();
		s.pop_back();
		res.push_back(u);
		for(auto x:graph[u]){
			indeg[x]--;
			if(indeg[x] == 0){
				s.push_back(x);
			}
		}
	}
	if (res.size() != v)
		return vector<int>();
	return res;
}

int main(){
	int v, e;
	cin >> v >> e;
	vector<vector<int>> graph(v);
	rep(i,e){
		int s, t;
		cin >> s >> t;
		graph[s].push_back(t);
	}
	vector<int> ans = tsort(graph);
	print(ans);

	return 0;
}


Measured memory_bytes: 3732
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<ll> v(n);
	vector<ll> w(n);

	vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));

	for (int i = 0; i < n; i++)
	{
		cin >> w.at(i) >> v.at(i);
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j <= m; j++)
		{
			if (j - w.at(i) >= 0)
			{
				dp.at(i + 1).at(j) = max(dp.at(i + 1).at(j), dp.at(i).at(j - w.at(i)) + v.at(i));
			}
			dp.at(i + 1).at(j) = max(dp.at(i + 1).at(j), dp.at(i).at(j));
		}
	}

	cout << dp.at(n).at(m) << endl;
}


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

int main(){
  vector<string> array;
  string s;
  int k;
  cin>>s>>k;
  for(int i=1;i<=k;i++){
    for(int j=0;j<s.size();j++){
      array.push_back(s.substr(j,i));
    }
  }
  sort(array.begin(),array.end());
  unique(array.begin(),array.end());
  cout<<array[k-1]<<endl;
}

Measured memory_bytes: 1660
while(1):
    a = input()
    if(a == '.'):
        break
    b = input()
    n = len(a)
    m = len(b)
    l = 0;
    flag = 0
    idx_dif = 0
    error_cou = 0

    while(1):
        if(l >= n-1 or l+idx_dif >= m-1):
            flag = 2

        if(flag == 0):
            for i in range(l,n):
                if(a[i] == '\"'):
                    if(i+idx_dif < m and a[l:i+1] == b[l+idx_dif:i+idx_dif+1]):
                        l = i+1
                        flag = 1
                    else:
                        flag = 2
                    break

                elif(i == n-1):
                    if(a[l:i] != b[l+idx_dif:m-1]):
                        flag = 2
                    else:
                        l = n-1
                    break
                if(flag != 0):
                    break

        elif(flag == 1):
            for i in range(l,n):
                if(a[i] == '\"'):
                    for j in range(l+idx_dif,m):
                        if(b[j] == '\"'):
                            if(a[l:i+1] != b[l+idx_dif:j+1]):
                                error_cou += 1
                            idx_dif = j-i
                            l = i+1
                            flag = 0
                            break
                        if(j == m-1):
                            flag = 2
                            break

                if(flag != 1):
                    break

        if(flag == 2 or l >= n-1 or l+idx_dif >= m-1):
            break

    if(error_cou >= 2 or flag == 2):
        print("DIFFERENT")
    elif(error_cou == 1):
        print("CLOSE")
    elif(error_cou == 0):
        print("IDENTICAL")


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

void shuffle(int *array,int n,int p,int c); //?±±???????????£???????????????

int main(void) {
	int n,r;
	int p,c;

	while(1){
		scanf("%d %d",&n,&r);
		if(n==0 && r==0){
			break;
		}

		int array[n],i;		//??????????????????
		for(i=0;i<n;i++){
			array[i] = i+1;
		}

		for(i=0;i<r;i++){
			scanf("%d %d",&p,&c);
			shuffle(&array[0],n,p,c);
		}

		printf("%d\n",array[n-1]);
	}
	return 0;
}

void shuffle(int *array,int n,int p,int c){
	int tmp[c];
	int i,j=0,k;

	for(i=n-p-c+1;i<=n-p;i++){	//???????????????????????????
		tmp[j++] = *(array + i);
	}

	i = n-p-c+1;
	for(k=n-p+1;k<n;k++){		//????????????????????????
		*(array + i) = *(array + k);
		i++;
	}

	for(j=0;j<c;j++){			//???????????????????????????????????????
		*(array + i) = tmp[j];
		i++;
	}

}

Measured memory_bytes: 600
#include <iostream>
#include <vector>

using namespace std;

void color(vector<vector<pair<int, bool>>>& t, vector<int>& answer, int i) {
    for (pair<int, bool> p : t[i]) {
        if (answer[p.first] == -1) {
            if (p.second) {
                answer[p.first] = answer[i];
            } else {
                answer[p.first] = 1 - answer[i];
            }
            color(t, answer, p.first);
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, bool>>> t(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        t[u - 1].push_back({ v - 1, w % 2 == 0 });
        t[v - 1].push_back({ u - 1, w % 2 == 0 });
    }
    vector<int> answer(n, -1);
    for (int i = 0; i < n; ++i) {
        if (answer[i] == -1) {
            answer[i] = 0;
            color(t, answer, i);
        }
    }
    for (int n : answer) cout << n << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++)
    cin >> p.at(i);
  
  int k=0;
  
  for(int i=1;i<n-1;i++){
    if(p.at(i-1)<p.at(i)&&p.at(i)<p.at(i+1))
      k++;
    else if(p.at(i+1)<p.at(i)&&p.at(i)<p.at(i-1))
      k++;
  }
  cout << k << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int large(int a,int b){
int c;
if(a<b){
    return b;
}
else {
    return a;
}
}
int main(){
 int x,y,a,s,m,l1,l2;
 scanf("%d %d",&x,&y);
 a=x+y;
 s=x-y;
 m=x*y;
 l1=large(a,s);
 l2=large(l1,m);
 printf("%d\n",l2);
return 0;

}



Measured memory_bytes: 128
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

LL a,b;

pair<LL,LL>seg[3];
int main()
{
	get2(a,b);
	int t=0;
	for(int i=62;i>=0;i--)
	{
		if(((a>>i)&1)^((b>>i)&1))
		{
			t=i+1;
			break;
		}
	}
	if(t==0)
	{
		puts("1");
		return 0;
	}
	a&=(1ll<<t)-1;b&=(1ll<<t)-1;t--;
//	cout<<"t= "<<t<<" "<<a<<" "<<b<<endl;
	seg[0]=mp(a,(1ll<<t)-1);
	
	LL b2=1ll<<t;
	for(int i=t-1;i>=0;i--)
	{
		if((b>>i)&1)
		{
			b2+=(1ll<<i+1)-1;
			break;
		}
	}
	seg[1]=mp(1ll<<t,b2);
	
	seg[2]=mp((1ll<<t)+a,(1ll<<t+1)-1);
	
	LL ans=0;
	for(int i=1;i<8;i++)
	{
		LL lb=0,ub=Linf;
		int cnt=0;
		for(int j=0;j<3;j++)if((i>>j)&1)
		{
			lb=max(lb,seg[j].ff);
			ub=min(ub,seg[j].ss);
			cnt++;
		}
		if(cnt%2)ans+=max(0ll,ub-lb+1);
		else ans-=max(0ll,ub-lb+1);
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxi 300005
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define ll long long
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define TRACE
#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
#define gc getchar
#define REP(i,j,n)               for( i=j;i<n;i++)
#define PER(i,j,n)               for( i=n-1;i>=j;i--)
ll mpow(ll a, ll n,ll mod){
	ll ret=1;ll b=a;
	while(n) {
		if(n&1)
			ret=(ret*b)%mod;
		b=(b*b)%mod;
		n>>=1;
	}
	return (ll)ret;
}
inline void read(int &x){
	x=0;
	register char c=gc();
	for(;c<'0' || c>'9';c=gc());
	for(;c>='0' && c<='9';c=gc())
		x=(x<<3)+(x<<1)+(c-'0');
}
inline void write(int x){
	register char buffor[35];
	register int i=0;
	do{
		buffor[i++]=(x%10)+'0';
		x/=10;
	} while(x);
	i--;
	while(i>=0) putchar(buffor[i--]);
	putchar('\n');
}
inline int in() { int x; read(x); return x; }
void solve();
int dbg=1;
using namespace std;
int main(){
	int t=1;
	//read(t);
	for(int i=0;i<t;i++){
		//printf("Case #%d:\n",i);
		solve();
	}
	return 0;
}
void solve() {
	ll n,i,j=99999999999999,k;
	cin>>n;
	for(i=1;i*i<=n;i++)
		if(n%i==0)
			j=min(j,i-1+n/i-1);
	cout<<j<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back

int abs(int a){
    return ( a>0 ? a : -a );
}

int main(void){
    ll n;
    cin >> n;
    vl a(n),b(n),c(n);
    lrp(i,n){
        cin >> a.at(i);
    }
    lrp(i,n){
        cin >> b.at(i);
    }
    lrp(i,n){
        cin >> c.at(i);
    }
    sort(a);
    sort(b);
    sort(c);
    ll cnt=0;
    lrp(i,n){
        ll p,q;
        p=lower_bound(a.begin(),a.end(),b.at(i))-a.begin();
        q=c.end()-upper_bound(c.begin(),c.end(),b.at(i));
        cnt += p*q;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 2560
T=[]
for t in range(10):
    t=int(input())
    T.append(t)
K=[]
for k in range(10):
    k=int(input())
    K.append(k)
T.sort()
K.sort()
print(T[7]+T[8]+T[9],K[7]+K[8]+K[9])


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
int n, m, a, b;

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main(void){
    // Your code here!
    cin >> n >> m;
    vector<P> pairs(m);
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    
    sort(pairs.begin(), pairs.end(), pairCompare);
    int i = 0;
    int s = pairs[i].second;
    int cnt = 0;
    while(true){
        if(i == m-1){
            cnt += 1;
            break;
        }
        
        if(pairs[i+1].first < s){
            i++;
        } else{
            cnt++;
            s = pairs[i+1].second;
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 1024