akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	char s[20]={};
	chin(s);
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 128
//
// ACL Beginner Contest - A
//

#include <bits/stdc++.h>
using namespace std;

int main()
{
    // 標準入力から値を受け取る。
    int k;
    cin >> k;

    // 標準出力に結果を表示する。
    for (int i =0; i< k; i++)
    {
        cout << "ACL";
    }
    cout << endl;

    // 戻り値
    return (0);
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repp(i,a,b) for(ll i=a;i<=b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define endl "\n"
#define deb(x) cerr << #x << "=" << x << endl
#define debb(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define mod ((ll)1e9+7)
#define N ((ll)1e4)
#define pb push_back
#define in insert
#define F first
#define S second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI 3.1415926535897932384626
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
ll dr[] = { -1, 1, 0, 0};
ll dc[] = {0, 0, 1, -1};

/*Functions*/
ll gcd(ll a, ll b);
ll exp(ll x, ll y, ll p);
ll exp(ll x, ll y);
void InverseofNumber();
void InverseofFactorial();
void factorial();
ll Binomial(ll n, ll R);


ll factorialNumInverse[N + 1];
ll naturalNumInverse[N + 1];
ll fact[N + 1];

void fileIO() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main() {
    clock_t start, end;
    start = clock();
    speed
    // InverseofNumber(),InverseofFactorial(),factorial();
    fileIO();
    string s,t;cin>>s>>t;
    ll ans=0;
    rep(i,0,s.size()){
        if(s[i]!=t[i])
            ans++;
    }
    cout<<ans;




    end = clock();
    double timeTaken = double(end - start) * 1000 / double(CLOCKS_PER_SEC);
    deb(timeTaken);

    return 0;
}



/*All Functions*/
ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll exp(ll x, ll y, ll p) {
    ll res = 1;
    while (y) {
        if (y % 2)
            res = (res * x % p) % p;
        x = (x * x) % p;
        y /= 2;
    }
    return res;
}
ll exp(ll x, ll y) {
    ll res = 1;
    while (y) {
        if (y % 2)
            res = (res * x ) ;
        x = (x * x) ;
        y /= 2;
    }
    return res;
}
void InverseofNumber() {
    naturalNumInverse[0] = naturalNumInverse[1] = 1;
    for (ll i = 2; i <= N; i++)
        naturalNumInverse[i] = naturalNumInverse[mod % i] * (mod - mod / i) % mod;
}
void InverseofFactorial() {
    factorialNumInverse[0] = factorialNumInverse[1] = 1;
    for (ll i = 2; i <= N; i++)
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % mod;
}
void factorial() {
    fact[0] = 1;
    for (ll i = 1; i <= N; i++)
        fact[i] = (fact[i - 1] * i) % mod;
}
ll Binomial(ll n, ll R) {
    ll ans = ((fact[n] * factorialNumInverse[R]) % mod * (factorialNumInverse[n - R]) % mod) % mod;
    return ans;
}

Measured memory_bytes: 3972
import itertools

N,M,R = map(int,input().split())

r = list(map(int,input().split()))
for i in range(R):
    r[i] -= 1

inf = 10 ** 12

dp = [[inf]*N for i in range(N)]
for i in range(M):
    A,B,C = map(int,input().split())
    A -= 1
    B -= 1
    dp[A][B] = C
    dp[B][A] = C

for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])

l = list(range(R))
m = inf

for x in itertools.permutations(l,R):
    count = 0
    for i in range(len(l)-1):
        count += dp[r[x[i]]][r[x[i+1]]]
    m = min(count,m)

print(m)

Measured memory_bytes: 46936
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a < b) {
            System.out.println("a < b");
        } else if (a > b) {
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }

    }
}


Measured memory_bytes: 26388
#include<bits/stdc++.h>
using namespace std;
inline int calc(int x){
	return x*12+(x>>1)+(x&1);
}
int main(){
	int a,b,l1,r1,l2,r2;scanf("%d%d",&a,&b);
	l1=calc(a),r1=calc(a+1)-1,l2=b*10,r2=(b+1)*10-1;
	if(l1>r2||l2>r1)return puts("-1"),0;
	printf("%d",max(l1,l2));
	return 0;
}

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

int main(){
  int K, A, B;
  cin >> K >> A >> B;
  bool flag = false;
  
  for(int i=A;i<=B;i++){
    if(i%K == 0){
      flag = true;
    }
  }
  
  if(flag) cout << "OK" << endl;
  else cout << "NG" << endl;
}


Measured memory_bytes: 3636
#include<stdio.h>

double n;

int main(){
    while(scanf("%lf",&n)!=EOF){
        if(n<=48.0)printf("light fly\n");
        else if(n<=51.0)printf("fly\n");
        else if(n<=54.0)printf("bantam\n");
        else if(n<=57.0)printf("feather\n");
        else if(n<=60.0)printf("light\n");
        else if(n<=64.0)printf("light welter\n");
        else if(n<=69.0)printf("welter\n");
        else if(n<=75.0)printf("light middle\n");
        else if(n<=81.0)printf("middle\n");
        else if(n<=91.0)printf("light heavy\n");
        else printf("heavy\n");
    }
    
    return 0;
}


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

int a,b;

int n;
char s[123456][31];

string ss[123456];
string str;
bool cmp(char a,char b)
{
	return a<b;
}
bool cmp1(string a,string b)
{
	return a<b;
}
int main()
{
    cin>>n;
    long long k=0,sum=0,t=1;
    for(int i=1;i<=n;i++)
    {
    	cin>>s[i];
	}
    for(int i=1;i<=n;i++)
    {
    	sort(s[i],s[i]+10,cmp);
    	ss[i]+=s[i];
    	
	}
	sort(ss+1,ss+n+1,cmp1);
//	for(int i=1;i<=n;i++)
	//{
		//cout<<ss[i]<<endl;
	//}
	for(int i=1;i<=n;i++)
	{
		if(ss[i]==ss[i+1])
		{
			t++;
		}
		if(ss[i]!=ss[i+1])
		{
			sum+=t*(t-1)/2;
			t=1;
		}
	}
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 8960
#include<iostream>
#include<string>
using namespace std;
int main()
{
	double sum = 0 ;
	double s[10];
	string p[10];
	int a;
	cin >> a;
	for (int i = 0; i < a; i++)
	{
		cin >> s[i] >> p[i];
	}
	for (int i = 0; i < a; i++)
	{
		if (p[i] == "JPY")
		{
			sum = sum + s[i];
		}
		else 
		{
			sum = sum + s[i] * 380000.0;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
dp = [10**10 for i in range(0, N)]
dp[0] = 0
dp[1] = min(dp[1], dp[0]+abs(H[0]-H[1]))
for i in range(2, N):
    dp[i] = min(dp[i], dp[i-1]+abs(H[i]-H[i-1]))
    dp[i] = min(dp[i], dp[i-2]+abs(H[i]-H[i-2]))
print(dp[N-1])


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

int main() {
    string S;
    string T;
    cin >> S;
    cin >> T;

    int ans = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) != T.at(i)) {
            ans++;
        }
    }

    if (ans == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h> 
using namespace std;
#define ll long long 
#define pb push_back 

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

   ll i,j,t,n;
   string s;
   cin>>s;
   n=s.size()-1;
   if(s[n]=='s')
   {
     s=s+"es";
   }
   else s=s+'s';
   
   cout<<s<<endl;
}   

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int serch(int num,int n)
{
	for(int i=1,now=num;now<=n&&num-i>0;i++){
		now+=num-i;
		if(now==n)return 1;
		if(now>n)return 0;
	}
	return 0;
}
int main() {
	int n;
	while(cin>>n,n){
		int ans=0;
		for(int i=n/2+1;i>0;i--)ans+=serch(i,n);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
int arr[10007];
int main()
{
	int n,m,sum = 0,ans = 0;
	scanf("%d %d",&n,&m);
	for(int i = 1;i <= n;i ++){
		scanf("%d",&arr[i]);
		sum += arr[i];
	}
	for(int i = 1;i <= n;i ++){
		if(4*arr[i]*m>=sum) ans ++;
	}
	if(ans >= m) printf("Yes");
	else printf("No");
	return 0;
}

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

using namespace std;

#define rep(i,n) for(i=0;i<(int)(n);i++);

int main(){
  int n,k;
  cin>>n>>k;
  int c=1;
  for(int i=0;i<n;i++){
    if(c*2>=c+k) c+=k;
    else c*=2;
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.range;
import std.algorithm;

void main(){
    while(true){
        int n = readln().chomp().to!int();
        if(n == 0){
            break;
        }
        string str = readln().chomp();
        foreach(i; 0..n){
            string res;
            int count = 1;
            char current = '$';
            foreach(c; str){
                if(current == '$'){
                    current = c;
                }else if(current == c){
                    ++count;
                }else{
                    res ~= text(count, current);
                    current = c;
                    count = 1;
                }
            }
            res ~= text(count, current);
            str = res;
        }
        str.writeln();
    }
}

Measured memory_bytes: 2072
<?php
  
function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);
     
    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}
  

fscanf(STDIN,"%d%d",$n,$x);
$x_li = explode(" ",trim(fgets(STDIN)));
$x_li[] = $x;
//print_r($x_li);
//sort($x_li);
$gcd = abs($x_li[1]-$x_li[0]);
for($i=1;$i<count($x_li)-1;$i++){
  $dis = abs($x_li[$i+1]-$x_li[$i]);
  $gcd = gcd($gcd,$dis);
 //echo $gcd."\n";
}



echo $gcd;

Measured memory_bytes: 12792
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  int N, M, X, Y;
  ci(N, M, X, Y);
  ve<int> x(N + 1), y(M + 1);
  rep(i, N){
    ci(x.at(i));
  }
  rep(i, M){
    ci(y.at(i));
  }
  x.at(N) = X;
  y.at(M) = Y;
  sort all(x);
  sort all(y);
  if(x.at(N) - y.at(0) < 0){
    co("No War");
  }
  else{
    co("War");
  }
}

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

int main() {
  int h1, m1, s1, h2, m2, s2;
  for (int i = 0; i < 3; i++) {
    cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
    int start = h1 * 3600 + m1 * 60 + s1;
    int finish = h2 * 3600 + m2 * 60 + s2;
    int time = finish - start;
    
    cout << time / 3600 << " ";
    time %= 3600;
    cout << time / 60 << " ";
    time %= 60;
    cout << time << endl;
  }
  
  return 0;
}


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

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;
}

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

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

	vector<int> vi(p);
	sort(vi.begin(), vi.end());

	if (p == vi) {
		cout << "YES" << endl;
		return 0;
	}

	for (int i = 0; i < n - 1; i++) {
		for (int j = 1; j < n; j++) {
			int tmp = p[i];
			p[i] = p[j];
			p[j] = tmp;
			if (p == vi) {
				cout << "YES" << endl;
				return 0;
			} else {
				int tmp = p[i];
				p[i] = p[j];
				p[j] = tmp;
			}

		}
	}

	cout << "NO" << endl;
}


Measured memory_bytes: 256
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.14 02:24:23
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n,m,q;cin >> n >> m >> q;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    vector<vector<int>> color_cnt(n+1,vector<int>(m+1,0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            color_cnt[i + 1][j + 1] = color_cnt[i][j + 1] + color_cnt[i + 1][j] - color_cnt[i][j] + s[i][j] - '0';
        }
    }
    vector<vector<int>> tate(n,vector<int>(m+1,0)), yoko(m,vector<int>(n+1,0));
    for (int i = 0; i < n-1; i++) {
        for (int j = 0; j < m; j++) {
            tate[i + 1][j + 1] = tate[i][j + 1] + tate[i + 1][j] - tate[i][j] + (s[i][j] == '1' && s[i+1][j] == '1' ? 1 : 0);
        }
    }
    for (int i = 0; i < m-1; i++) {
        for (int j = 0; j < n; j++) {
            yoko[i + 1][j + 1] = yoko[i][j + 1] + yoko[i + 1][j] - yoko[i][j] + (s[j][i] == '1' && s[j][i+1] == '1' ? 1 : 0);
        }
    }
    while(q--) {
        int x1,y1,x2,y2;cin >> x1 >> y1 >> x2 >> y2;
        int cnt_v = color_cnt[x2][y2] - color_cnt[x1-1][y2] - color_cnt[x2][y1-1] + color_cnt[x1-1][y1-1]; 
        int cnt_tate = tate[x2-1][y2] - tate[x2-1][y1-1] - tate[x1-1][y2] + tate[x1-1][y1-1]; 
        int cnt_yoko = yoko[y2-1][x2] - yoko[y2-1][x1-1] - yoko[y1-1][x2] + yoko[y1-1][x1-1]; 
        cout << cnt_v - cnt_tate - cnt_yoko << endl;
    }
    return 0;
}


Measured memory_bytes: 57904
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

const int NIL = -1;

struct Node {
    int left, right;
    
    Node(int left, int right):left(left), right(right){}
    
    bool isLeaf() {
        return degree() == 0;
    }
    
    int degree() {
        int deg = 0;
        if (left != NIL) {
            deg++;
        }
        if (right != NIL) {
            deg++;
        }
        return deg;
    }
};



struct Tree {
    int n; // number of nodes
    vector<int> parent; //parent
    vector<Node> nodes;
    vector<int> depth; //depth
    vector<int> height;
    
    Tree(int n): n(n) {
       parent.assign(n, -2);
       depth.assign(n, 0);
       nodes.assign(n, Node(NIL, NIL));
       height.assign(n, 0);
    }
    
    void addNode(int u, int left, int right) {
        nodes[u].left = left;
        nodes[u].right = right;
        if (left != -1) {
            parent[left] = u;
        }
        if (right != -1) {
            parent[right] = u;
        }
    }
    
    void dfs(int u, int p, int d) {
        int h = 0;
        parent[u] = p;
        depth[u] = d;
        int l = nodes[u].left;
        int r = nodes[u].right;
        if (l != NIL) {
            dfs(l, u, d + 1);
            h = max(h, height[l] + 1);
        }
        if (r != NIL) {
            dfs(r, u, d + 1);
            h = max(h, height[r] + 1);
        }
        height[u] = h;  
    }

    int formatSibling(int u){
        int s = -1;
        int p = parent[u];
        if (p != -1) {
            if (nodes[p].left == u) {
                s = nodes[p].right;
            }
            else {
                s = nodes[p].left;
            }
        }
        return s;
    }

    string formatNodeType(int u){
        string type = "";
        if (parent[u] == -1) {
            type = "root";
        } else if (nodes[u].degree() > 0) {
            type = "internal node";
        } else {
            type = "leaf";
        }
        return type;
    }
    
    void solve() {
        int root = -1;
        for (int i = 0; i < n; i++) {
            if (parent[i] == -2) {
                root = i;
                break;
            }
        }
        parent.assign(n, -2);
        dfs(root, -1, 0);
        //node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root
        for (int i = 0; i < n; i++) {
            printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", 
                    i, parent[i], formatSibling(i), nodes[i].degree(), depth[i], height[i], 
                    formatNodeType(i).c_str());
        }
    }
};

int main() {
    int n;
    cin >> n;
    Tree tree(n);
    for (int i = 0; i < n; i++) {
        int u, l, r;
        cin >> u >> l >> r;
        tree.addNode(u, l, r);   
    }
    tree.solve();
    
    return 0;
}

Measured memory_bytes: 3368
#include <iostream>
#include <algorithm>
#include <vector>


int my_abs(int a) {
	return a < 0 ? -a : a;
}


int main() {


	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	//int N; std::cin >> N;
	//std::vector<int> H(N); for (int i = 0; i < H.size(); i++)std::cin >> H.at(i);
	//bool flag = true;//見れる
	//
	//for (int i = 1; i < H.size(); i++) {
	//	for (int j = 0; j < i; j++) {
	//
	//	}
	//}
	int A, B;
	std::cin >> A >> B;
	int ans = 0;
	if (my_abs(A - B) >= 2) {
		ans = std::max(A, B) * 2 - 1;
	}
	else {
		ans = A + B;
	}

	std::cout << ans;

	return 0;


}

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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> a(n+1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if((i % 2 == 1) && (a[i] % 2 == 1)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> a;
int n;

bool isok(ll m) {
  ll cnt = 0;
  for (int i = 0; i < n && cnt <= m; i++) {
    ll t = a[i] + m - (n - 1);
    ll d = n+1;
    cnt += (t+d-1) / d;
  }
  return cnt <= m;
}

ll f() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  sum -= n*(n-1);
  if (sum < 0) sum = 0;
  for(;;sum++) if (isok(sum)) return sum;
}

int main() {
  cout << f() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(xx) (xx).begin(),(xx).end()
#define print(a); for(auto xx:a)cout<<xx<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n,greater<ll>());
    ll ans=a[0];
    ll i=1;
    for(;i<n/2;i++){
        ans+=a[i]*2;
    }
    if(n&1)ans+=a[i];
    cout<<ans<<"\n";
}


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

using namespace std;

vector<int> Name;
typedef struct{int number; int point;} SCORE;

vector <int> toV(string in){
  vector<int> out;
  for(int i = 0; i < in.length(); i++){
    int num = 0;
    while(in[i] != ' '){
      num *= 10;
      num += in[i]-'0';
      i++;
    }
    out.push_back(num);
  }
  return out;
}

int score(vector<int> V){
  int j= 0;
  int sum = 0;
  int po;
  for(int i = 1; i < V.size(); i++){
    j++;
    if(j == 10){
      po = i;
      break;
    }
    if(V[i] == 10) sum += 10+V[i+1]+V[i+2];
    else if(V[i] + V[i+1] == 10){
      i++;
      sum += 10+V[i+1];
    }else{
      sum += V[i] + V[i+1];
      i++;
    }
  }
  if(V[po] + V[po+1] >= 10) sum += V[po] + V[po+1] + V[po+2];
  else sum += V[po]+V[po+1];
  return sum;
}

int main(){

  int in;
  while(cin >> in && in){
    SCORE SC[in];
    Name.clear();
    string t;
    getline(cin,t);
    vector<int> V;
    for(int i = 0; i < in; i++){
      string s;
      getline(cin,s);
      s += ' ';
      V = toV(s);
      Name.push_back(V[0]);
      SC[i].number = V[0];
      SC[i].point = score(V);
    }
    for(int i = 0; i < in; i++){
      for(int j = 0; j < in-i-1; j++){
	if(SC[j].point < SC[j+1].point) swap(SC[j],SC[j+1]);
	else if(SC[j].point == SC[j+1].point &&
		SC[j].number > SC[j+1].number) swap(SC[j],SC[j+1]);
      }
    }

    for(int i = 0; i < in; i++) cout << SC[i].number  << " " << SC[i].point<< endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;
    cin>>n;
    int ans=1e9;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            ans=min(ans,(int)log10(max(i,n/i))+1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <stdlib.h>


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

    //偶数　高橋
    //奇数　青木
    bool round = true;
    bool f = false;
    while(a > 0 && c > 0){
        if(round){
            c -= b;
            if(c <= 0) {
                f = true;
                break;
            }
        }else{
            a -= d;
            if(a <= 0){
                f = false;
                break;
            }
        }
        if(round) round = false;
        else round = true;


    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0; 
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>
#include<cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int minv(int x, int n) {
  int ans = 1, pr = x;
  while(n) {
    if(1 & n) ans = 1LL * ans * pr % mod;
    n >>= 1;
    pr = 1LL * pr * pr % mod;
  }
  return ans;
}

int dp[1<<20];

int solve(int n, int m) {
  if(n == 0) return 1;
  if(n == 1) return m-1;

  if(dp[n]) return dp[n];

  int ans1 = (m-n)*1LL*solve(n-1, m-1)%mod;
  int ans2 = (n-1)*1LL*(solve(n-1, m-1) + solve(n-2, m-2))%mod;

  return dp[n] = (ans1 + ans2) % mod;
}

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

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

 int ans = 0;
 int n, m;
 cin>>n>>m;

 int mf = 1, mnif = 1;
 rep(i, m) mf = 1LL * mf * (i+1) % mod;
 rep(i, m-n) mnif = 1LL * mnif * (i+1) % mod;
 ans = 1LL * mf * minv(mnif, mod-2) % mod;
 ans = ans * 1LL * solve(n, m) % mod;
 cout << ans << endl;

 return 0;
}

//41093363 315 413


Measured memory_bytes: 44668
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define REP(i, n) for (LL i = 0; i < (LL)(n); i++)
#define REP2(i, n) for (LL i = 1; i <= (LL)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(),0)
#define vLL(v,n) vector<LL> v(n); REP(i,n)cin>>v[i];
#define vstr(v,n) vector<string> v(n); REP(i,n)REP(i,n)cin>>v[i];
LL INF = 1e9 + 1;
LL MOD = 1e9+7;
  LL zero,a,b,c,d,e,n,m,l,k,r,x,y,z,odd,ans=0,ans2=0,h,w;
string s,S,t;
int main() {
ios_base::sync_with_stdio(false);
cin >>n;
odd=0;
vector<LL> A(n);
REP(i,n){
    cin>> a;
    if(a<0)odd++;
    else if(a==0)zero++;
   A[i] =abs(a);
}
SORT(A);
if(odd%2==0){
 REP(i,n)ans+=A[i];
cout << ans;
return 0;
}else if(zero>=1){
  REP(i,n)ans+=A[i];
cout << ans;
return 0;
}else{
    A[0]*=-1;
  REP(i,n)ans+=A[i];
    cout << ans;
    return 0;
}
}


Measured memory_bytes: 4044
N, K = map(int, input().split())
A = list(map(int, input().split()))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i & -i
        return ret

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

# inter = 0
# for i in range(N):
#     ai = A[i]
#     for j in range(i + 1):
#         aj = A[j]
#         if ai > aj:
#             inter += 1

bit = Bit(2000)

intra = 0
inter = 0
for i in range(len(A)):
    a = A[i]
    bit.add(a, 1)
    intra += i + 1 - bit.sum(a)
    if a != 1:
        inter += bit.sum(a - 1)

# for i in range(len(A)):
#     a = A[i]
#     if a != 1:
#         inter += bit.sum(a - 1)

# print(inter, intra)

mod = 10**9 + 7

ans = (intra * K * (K + 1) // 2) % mod
ans += (inter * (K - 1) * K // 2) % mod
print(ans % mod)


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

int dice[6];

int dr[6][6] = {
	{-1,  2,  4,  1,  3, -1},
	{ 3, -1,  0,  5, -1,  2},
	{ 1,  5, -1, -1,  0,  4},
	{ 4,  0, -1, -1,  5,  1},
	{ 2, -1,  5,  0, -1,  3},
	{-1,  3,  1,  4,  2, -1}
};

int getIndex(int n){
	for(int i=0; i<6; i++){
		if(dice[i] == n) return i;
	}
	return -1;
}

int main(){
	for(int i=0; i<6; i++) cin >> dice[i];
	int q;
	cin >> q;
	for(int i=0; i<q; i++){
		int a, b;
		cin >> a >> b;
		cout << dice[ dr[ getIndex(a) ][ getIndex(b) ] ] << "\n";
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 3016
raw_input = input()
input_list = raw_input.split()   
 
coding_contest_rank = int(input_list[0])
robot_rank = int(input_list[1])


if coding_contest_rank == 3:
    coding_money = 100000
if robot_rank == 3:
    robot_money = 100000
if coding_contest_rank == 2:
    coding_money = 200000
if robot_rank == 2:    
    robot_money = 200000
if coding_contest_rank == 1:
    coding_money = 300000
if robot_rank == 1:    
    robot_money = 300000
if coding_contest_rank > 3:
    coding_money = 0
if robot_rank > 3:
    robot_money = 0

if coding_contest_rank == 1 and robot_rank == 1: 
    print(coding_money + robot_money + 400000)
else:
    print(coding_money + robot_money)

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

int main(){
  string s;
  cin>>s;
  if(s == "A") cout << "T" << endl;
  if(s == "T") cout << "A" << endl;
  if(s == "G") cout << "C" << endl;
  if(s == "C") cout << "G" << endl;
}

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

int N, A, arr[2000001], max1 = 0, max2 = 0;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A;
        arr[i] = A;
        if (A > max1) {
            max2 = max1;
            max1 = A;
        } else if (A > max2) {
            max2 = A;
        }
    }
    for (int i = 0; i < N; i++) {
        if (arr[i] == max1) {
            cout << max2 << "\n";
        } else {
            cout << max1 << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 2432
def insertionSort( nums, g ):
	cnt = 0
	i = g
	n = len( nums )
	while i < n:
		v = nums[i]
		j = i - g
		while 0 <= j and v < nums[j]:
			nums[ j+g ] = nums[j]
			j -= g
			cnt += 1
		nums[ j+g ] = v
		i += 1
	return cnt


def shellSort( nums, n ):
	cnt = 0
	g = []
	val =0
	for i in range( 0, n ):
		val = 3*val+1
		if  n < val:
			break
		g.append( val )

	g.reverse( )
	m = len( g )
	print( m )
	print( " ".join( map( str, g ) ) )
	for i in range( 0, m ):
		cnt += insertionSort( nums, g[i] )
	print( cnt )


n = int( raw_input( ) )
nums = []
for i in range( 0, n ):
	nums.append( int( raw_input( ) ) )

shellSort( nums, n )
for val in nums:
	print( val )

Measured memory_bytes: 67872
import re
S = input()
flag = False
if len(re.findall('[A-Z]',S)) == 2:
    if S[0] == "A":
        if S[-1] != "C":
            if S[2:-1].count("C") == 1:
                flag = True

if flag:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3188
from operator import itemgetter
import numpy as np

N, M = map(int, input().split()) # 横に2個
stores = [list(map(int, input().split())) for _ in range(N)]

astores = np.array(sorted(stores, key=itemgetter(0)))

stock = 0
price = 0
for i in range(N):
    if stock + astores[i, 1] > M:
        price += astores[i, 0] * (M - stock)
        break
    else:
        price += astores[i, 0] * astores[i, 1]
        stock += astores[i, 1]

print(price)


Measured memory_bytes: 38864
S = input()
T = input()

result = float("inf")
count = len(S) - len(T) + 1

for i in range(count):
    tmp = 0
    for j in range(len(T)):
        if T[j] != S[i+j]:
            tmp += 1
    result = min(result, tmp)

print(result)


Measured memory_bytes: 9052
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 20;

int n;
char ch[N];

inline LL Pow2(int k) {
    return (k <= 0) ? (1ll) : (1ll << k);
}

int main() {
    scanf("%s", ch + 1);
    n = strlen(ch + 1);
    LL res = 0;
    for (int i = 1; i <= n; ++i) {
        LL sum = 0;
        for (int j = i; j <= n; ++j) {
            sum = sum * 10 + ch[j] - 48;
            res += sum * Pow2(i - 2) * Pow2(n - j - 1);
        }
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(ll i=0; i<n; i++)
#define all(v) v.begin(), v.end()
#define vec vector
typedef long long ll;
const int INF = 1001001001;

/*　<<stringで読み込んだ数列を一桁ずつint型へ変換>>
 
    string str;
    int N[桁数];
 
    cin >> str;
 
    for (int i = 0; i < 桁数; ++i) {
 
        N[i] = (int)(str[i] - '0');  //str[i]　はchar型なのでchar→intへ変換
 
        //cout << N[i] << endl;  //確認のため表示
    }
*/
 


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


int main() {

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

    vec<int> c(n);
    int a[12][12];

    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }

    int ans = INF;
    rep(s,1<<n){
        int cost = 0;
        vec<int> d(m);
        rep(i,n){
            if(s>>i&1){
                cost += c[i];
                rep(j,m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j,m) if(d[j] < x) ok = false;
        if(ok) ans = min(ans, cost);
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<pair<ll, ll>> rs(N), bs(N);

  for (auto i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    rs[i] = make_pair(a, b);
  }
  for (auto i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    bs[i] = make_pair(a, b);
  }
  ll res = 0;
  sort(rs.begin(), rs.end());
  sort(bs.begin(), bs.end());
  vector<bool> used(N, false);
  for (auto ir = N-1; ir >= 0; ir--) {
    auto r = rs[ir];
    ll bmax = -1;
    for (auto ib = N-1; ib >= 0; ib--) {
      if (used[ib]) continue;
      auto b = bs[ib];
      if (b.first > r.first && b.second > r.second
          && (bmax == -1 || b.second < bs[bmax].second)) {
        bmax = ib;
      }
    }
    if (bmax != -1) {
      used[bmax] = true;
      res++;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<bool> Vb;
typedef vector<int> Vi;
typedef vector<ll> Vl;

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

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

void init();

int n;
Vi opt, dp;

int main()
{
	init();

	REP(i, n - 1)
		for (int x : opt)
			if (i + x <= n)
				chmin(dp[i + x], dp[i] + 1);

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

void init()
{
	cin >> n;
	dp.resize(n + 1);
	REP(i, n + 1)
		dp[i] = i;

	int x = 6;
	while (x <= n)
	{
		opt.PB(x);
		x *= 6;
	}

	x = 9;
	while (x <= n)
	{
		opt.PB(x);
		x *= 9;
	}

	sort(ALL(opt));
}

Measured memory_bytes: 640
import sys
from collections import deque

N=input()

nl=[ [] for i in range(N+1) ]
for _ in range(N-1):
	a,b,c=map(int, sys.stdin.readline().split()) 
	nl[a].append( (b,c) )
	nl[b].append( (a,c) )

Q,K=map(int, sys.stdin.readline().split())

question=[ map(int, sys.stdin.readline().split())  for i in range(Q) ] 

Visit=[ None for i in range(N+1) ] 
Visit[K]=0

q=deque()
q.append(K)


while q:
	fro=q.popleft()
	for to,cost in nl[fro]:
		if Visit[to] is None:
			Visit[to]=Visit[fro]+cost
			q.append(to)


for x, y in question:
	print Visit[x]+Visit[y]


Measured memory_bytes: 67484
#include <cstdio>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=1e5+5;
int n,i,ans,a[N],cnt[2];
int gcd(int a,int b) {
	int c=a%b;
	while (c) { a=b; b=c; c=a%b; }
	return b;
}
int solve()
{
	int i,ret,g,pos=0;
	cnt[0]=cnt[1]=0;
	rep(i,1,n) {
		cnt[a[i]%2]++;
		if (a[i]%2 && a[i]>1) pos=i;
	}
	if (cnt[0]%2==0 && cnt[1]==1 && pos) {
		a[pos]--; g=a[1];
		rep(i,2,n) g=gcd(g,a[i]);
		rep(i,1,n) a[i]/=g;
		ret=solve()^1;
	}
	else ret=cnt[0]%2;
	return ret;
}
int main()
{
//	freopen("game.in","r",stdin);
//	freopen("game.out","w",stdout);
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	ans=solve();
	if (ans) printf("First\n");
	else printf("Second\n");
	return 0;
}

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

// macros
#define overload_rep(va_0, va_1, va_2, name, ...) name
#define rep_0(i, n) for(int i = 0; i < (n); ++i)
#define rep_1(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations

// solve
int main(){

    int N;
    cin >> N;
    vector<long long> sum(N + 1, 0);
    rep(i, 1, N)cin >> sum[i];
    rep(i, 1, N)sum[i] += sum[i - 1];

    long long ans = 1ll << 60;
    rep(i, 1, N - 1){
        chmin(ans, abs((sum[N] - sum[i]) - (sum[i] - sum[0])));
    }

    cout << ans << '\n';
    return 0;

}


Measured memory_bytes: 1792
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
h = na()

prev = 999999999999
for i in range(n-1,-1,-1):
    if h[i] > prev:
        h[i] -= 1
    if h[i] > prev:
        print("No")
        sys.exit(0)
    prev = h[i]
print("Yes")

Measured memory_bytes: 14812
import java.io.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int dataCount = Integer.parseInt(br.readLine());
		String inputData = br.readLine();
		String[] inputValue = inputData.split(" ");
		int[] outputData = new int[dataCount];
		
		for(int i = 0; i < inputValue.length ; i++){
			outputData[i] = Integer.parseInt(inputValue[i]);
		}
		
		Arrays.sort(outputData);
		
		int min = outputData[0];
		int max = outputData[outputData.length-1];
		long sum = 0;
		
		for(int i = 0; i<outputData.length; i++){
			sum = sum + outputData[i];
		}
				
		System.out.println(min + " " + max + " " + sum);
		
		
	}

}

Measured memory_bytes: 29004
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 10, INF = 1e9 * 1e5;

ll cnt = 0;


ll x = 0, add = 0, r;

ll kth(ll k) {
	ll vl = 0;
	r = cnt;
	for (ll i = 60; i >= 0; i--) {
		if ((add >> i) & 1) {
			vl |= (1ll << i);
			continue;
		}
		if (((x >> i) & 1)) {
			if ((1ll << cnt) <= k) {
				k -= (1ll << cnt);
				vl |= (1ll << i);
			}
			cnt--;
		}
	}
	cnt = r;
	return vl;
}

int main()
{
	fastInp;

	ll n;
	cin >> n;
	vector<ll> vec(n);
	for (int i = 0; i < n; i++) cin >> vec[i];

	for (int i = 2; i < n; i++) x ^= vec[i];

	if (vec[0] + vec[1] < x) {
		cout << "-1";
		return 0;
	}

	ll left = (vec[0] + vec[1]) - x;
	for (ll i = 60; i >= 0; i--) {
		if (left >= (1ll << (i + 1)) && !((x >> i) & 1)) {
			add |= (1ll << i);
			left -= (1ll << (i + 1));
		}
		if (((x >> i) & 1)) {
			cnt++;
		}
	}

	cnt--;
	if (x == 0) {
		if (vec[0] < vec[1]) {
			cout << "-1";
		}
		else {
			ll dif = vec[0] - vec[1];
			if (dif % 2 != 0) {
				cout << "-1";
			}
			else {
				cout << dif / 2;
			}
		}
		return 0;
	}
	if (left != 0) {
		cout << "-1";
		return 0;
	}
	ll l = -1, r = INF;
	while (r - l > 1) {
		ll mid = (l + r) / 2;
		if (kth(mid) >= vec[1]) {
			r = mid;
		}
		else {
			l = mid;
		}
	}

	if (r == INF) {
		cout << "-1";
	}
	else {
		if (kth(r) - vec[1] >= vec[0]) {
			cout << "-1";
			return 0;
		}
		cout << kth(r) - vec[1];
	}
	return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int x,y;
		try{
			while((x = scn.nextInt()) != 0 | (y = scn.nextInt()) != 0) {
				System.out.println((x < y)?x + " " + y:y + " " + x);
			}
		}catch(Exception e) {

		}
		scn.close();
	}
}


Measured memory_bytes: 36708
// B - K-th Common Divisor
#include <bits/stdc++.h>
using namespace std;

int main(){
	int a,b,k; cin>>a>>b>>k;
	for(int i=min(a,b); i>=1; --i)
		if(a%i+b%i==0) if(--k==0) cout<< i <<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split();
        var N = int.Parse(input[0]);
        var M = int.Parse(input[1]);
        var X = int.Parse(input[2]);

        var list = new List<int[]>();

        for(var i = 0; i < N; i++)
        {
            var nums = new int[M + 1];
            var line = Console.ReadLine().Split();
            for(var j = 0; j < M + 1; j++)
            {
                nums[j] = int.Parse(line[j]);
            }
          list.Add(nums);

        }

        var minPrice = int.MaxValue;
        for (int bit = 0; bit < (1 << N); bit++)
        {
            int total = 0;
            var price = 0;
            var skills = new int[M];
            for (int i = 0; i < N; i++)
            {
                if ((bit & (1 << i)) > 0)
                {
                    var j = 0;
                    foreach(var s in skills)
                    {
                        skills[j] += list[i][j + 1];
                      j++;
                    }
                    price += list[i][0];
                        
                }
            }
            var flag = true;
            foreach(var skill in skills)
            {
                if(skill < X)
                {
                    flag = false;
                }
            }
            if (flag)
            {
                if (price < minPrice)
                {
                    minPrice = price;
                }
            }
        }
      
              if(minPrice == int.MaxValue)
        {
            minPrice = -1;
        }



        Console.WriteLine(minPrice);
        Console.ReadLine();
    }


}


Measured memory_bytes: 18196
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    for(int i = 0; i < N; i++) cin >> x[i] >> y[i] >> h[i];
    int flag = 0;
    for(int i = 0; i < N; i++){
        if(h[i] > 0) flag = 1;
    }
    if(flag == 0){
        for(int i = 0; i <= 100; i++){
            for(int j = 0; j <= 100; j++){
                int flag = 0;
                for(int k = 0; k < N; k++){
                    if(i == h[k] && j == h[k]) flag = 1;
                }
                if(flag == 0){
                    cout << i << ' ' << j << ' ' << 1 << endl;
                    return 0;
                }
            }
        }
    }
    vector<vector<int>> d(101, vector<int> (101, -1));
    for(int i = 0; i < N; i++){
        if(h[i] > 0){
            for(int j = -100; j <= 100; j++){
                for(int k = -100; k <= 100; k++){
                    int nx = x[i] + j, ny = y[i] + k;
                    if(0 <= nx && nx <= 100 && 0 <= ny && ny <= 100){
                        d[nx][ny] = h[i] + abs(j) + abs(k);
                    }
                }
            }
            break;
        }
    }
    int ans = 0, cx, cy;
    for(int i = 0; i < 101; i++){
        for(int j = 0; j < 101; j++){
            int flag = 0;
            for(int k = 0; k < N; k++){
                if(h[k] != 0 && d[i][j] - abs(x[k] - i) - abs(y[k] - j) != h[k]) flag = 1;
                else if(h[k] == 0 && d[i][j] - abs(x[k] - i) - abs(y[k] - j) > h[k]) flag = 1;
            }
            if(flag == 0 && ans < d[i][j]){
                ans = d[i][j];
                cx = i;
                cy = j;
            }
        }
    }
    cout << cx << ' ' << cy << ' ' << ans << endl;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

static class Program
{
    static long[] Solve(long S)
    {
        const long M = 1000000000;
        return new long[] {
            0,
            0,
            M,
            1,
            (-S % M + M) % M,
            (S + M - 1) / M,
        };
    }

    static void Main(string[] args)
    {
        long S = long.Parse(Console.ReadLine());
        Console.WriteLine(string.Join(" ", Solve(S)));
    }
}


Measured memory_bytes: 27584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;

int main() {
  int N; cin >> N;
  
  ll ans = 1;
  repi(i,1,N) {
    ans *= i;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
#from fractions import gcd
from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def main():
    s, w =map(int, input().split())
    print("safe") if s > w else print("unsafe")

if __name__ == '__main__':
    main()



Measured memory_bytes: 9476
import sys

s = input()
t = input()

finalans = 1000000
for i in range(len(s) - len(t) + 1):
    ans = 0
    for j in range(len(t)):
        if (s[i+j] == t[j]):
            pass
        else:
            ans += 1
    finalans = min(finalans, ans)

print(finalans)


Measured memory_bytes: 9040
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
 
using namespace std;
 
int main(){
  int N;
  cin>>N;
  vector<int> H(N,100);
  for(int i=0;i<N;++i){
    cin>>H[N-1-i];
  }
  
  for(int i=0;i<N-1;++i){
    //cout<<H[i]<<" "<<H[i+1]<<endl;
    if(H[i]+1<H[i+1]){
      cout<<"No"<<endl;
      return 0;
    }else if(H[i]+1==H[i+1]){
      H[i+1]=max(H[i+1]-1,0);;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 640