akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
    int i, j;

    int r, c;
    scanf("%d%d", &r, &c);
    int a[r+1][c+1];
    for( i = 0; i < r+1; ++i )
        for( j = 0; j < c+1; ++j )
            a[i][j] = 0;
    for( i = 0; i < r; ++i )
        for( j = 0; j < c; ++j )
            scanf("%d", &a[i][j]);

    int sum;
    for( i = 0; i < r; ++i ){
        sum = 0;
        for( j = 0; j < c; ++j ){
            sum += a[i][j];
        }
        a[i][j] = sum;
    }
    for( i = 0; i < c+1; ++i ){
        sum = 0;
        for( j = 0; j < r; ++j ){
            sum += a[j][i];
        }
        a[j][i] = sum;
    }
    for( i = 0; i < r+1; ++i ){
        for( j = 0; j < c+1; ++j ){
            printf("%d", a[i][j]);
            if( j != c ) printf(" ");
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 644
use std::io::{self, Write, BufWriter};

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n = read::<usize>();
    let mut a = vec![];
    for _ in 0..n {
        let ai = read::<usize>();
        a.push(ai);
    }

    let mut sorted = a.clone();
    sorted.sort_by(|x, y| y.cmp(x));

    let stdout = std::io::stdout();
    let mut buf = BufWriter::new(stdout.lock());

    for ai in a.into_iter() {
        let res = if ai == sorted[0] {
            sorted[1]
        } else {
            sorted[0]
        };
        writeln!(buf, "{}", res).unwrap();
    }
}

Measured memory_bytes: 9724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int K,X;
    cin >> K >> X;
    if(K * 500 >= X){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    H,W=map(int,input().split())
    c=0
    for _ in range(H):
        c+=input().count('#')
    print('Possible' if c==H+W-1 else 'Impossible')
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String s = sc.next();
            if (s.equals("0")) {
                break;
            }
            System.out.println(digitSum(s));
        }
    }

    private static int digitSum(String num) {
        int sum = 0;
        for (int i = 0; i < num.length(); i++) {
            sum += Integer.parseInt(String.valueOf(num.charAt(i)));
        }
        return sum;
    }
}

Measured memory_bytes: 26384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<double,int,double> tp;
typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	double l;
	cin>>n>>m>>l;
	vt in;
	rep(i,n){
		double a,b,c;
		cin>>a>>b>>c;
		a/=100;
		double sum=0;
		vd dp(200);
		dp[100]=1;
		rep(j,m){
			vd ndp(200);
			rep(k,200)if(dp[k]>0){
				ndp[k+1]+=dp[k]*a;
				ndp[k-1]+=dp[k]*(1-a);
			}
			dp=ndp;
		}
		rep(j,m+1){
			sum=dp[100-m+2*j];
			if(c)in.pb(tp(l/c+j*b,i,sum));
			else in.pb(tp(inf,i,sum));
		}
	}
	sort(all(in));
	vd out(n);
//	double t=1;
	vd t(n,1);
	rep(i,in.size()){
		double a,c;int b;
		tie(a,b,c)=in[i];
//		cout<<shosu(4)<<a<<" "<<b<<" "<<c<<endl;
		vt tmp;
		tmp.pb(in[i]);
		t[b]-=c;
		while(i!=in.size()-1){
			double d,f;int e;
			tie(d,e,f)=in[i+1];
			if(abs(a-d)<EPS){
				i++;
				tmp.pb(in[i]);
				t[e]-=f;
			}else break;
		}
//		rep(j,t.size())cout<<" "<<t[j];cout<<endl;
		rep(j,tmp.size()){
			double d,f;int e;
			tie(d,e,f)=tmp[j];
			double sum=f;
			rep(k,n)if(k!=e)sum*=t[k];
			out[e]+=sum;
		}
//		cout<<t<<endl;
	}
	rep(i,n)cout<<shosu(9)<<out[i]<<endl;
}

Measured memory_bytes: 3404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define MOD                 1000000007LL
#define EPS                 1e-9
#define io                  ios_base::sync_with_stdio(false);cin.tie(NULL);

const int MAXN = 1e5+5;

int main(){
	io;
	int n, a;
	cin >> n >> a;
	cout << (n*n - a) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 aa, bb;
	cin >> aa >> bb;
	cout << (max(aa, bb) <= 8 ? "Yay!" : ":(") << endl;
	return 0;
}

Measured memory_bytes: 3580
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def ceil(x, y):
    return -(-x // y)


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    bamari = 0
    for i in range(N):
        if A[i] == B[i]:
            continue
        elif A[i] > B[i]:
            bamari -= A[i] - B[i]
        else:
            bamari += ceil(B[i] - A[i], 2)
            bamari -= (B[i] - A[i]) % 2

    if bamari >= 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 10448
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int t[101];
int pri[26];
int res = 0;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[y] = px;
	}
	else {
		pr[x] = py;
	}
	return true;
}
struct edge {
	int to;
	bool use = false;
	edge(int _to) : to(_to) {}
};

ll te[100010];
void solv() {

	ll	n, m;
	cin >> n >> m;
	for (size_t i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		te[a]++;
		te[b]++;
	}

	for (size_t i = 1; i <= n; i++)
	{
		if (te[i] % 2 == 1) {
			cout << "NO" << endl;
			return;
		}
	}

	cout << "YES" << endl;
}


int main() {
	solv();

	return 0;
}


Measured memory_bytes: 1024
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func binarySearch(a []int, k int) int {
	n := len(a)
	if n == 0 {
		return 0
	}
	// fmt.Println(a)
	h := n / 2
	if a[h] == k {
		return 1
	} else if a[h] < k {
		return binarySearch(a[(h+1):], k)
	} else {
		return binarySearch(a[:h], k)
	}
}

func main() {
	scanner.Split(bufio.ScanWords)
	sizeA := nextInt()
	a := make([]int, sizeA)
	for i := 0; i < sizeA; i++ {
		a[i] = nextInt()
	}
	sizeB := nextInt()
	notIncluded := false
	for i := 0; i < sizeB; i++ {
		bi := nextInt()
		if binarySearch(a, bi) == 0 {
			notIncluded = true
			break
		}
	}
	if notIncluded {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}



Measured memory_bytes: 5888
#include<iostream>
using namespace std;
int t[35],a[35],ans;
int main(){
	int n,m,k;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>k;
		for(int j=1;j<=k;j++){
			cin>>a[j];
			t[a[j]]++;
		}
	} 
	for(int i=1;i<=30;i++){
		if(t[i]==n)
			ans++;
	} 
	cout<<ans;
} 

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

int N, six[10], nine[10], minc = 1e9;
bool visited[100009];

int main(void){
    
    cin >> N;
    
    if(N<6) {
        cout << N << endl;
        return 0;
    }
    
    memset( visited, false, sizeof(visited));
    
    int cnt = 0;
    queue<int> now, nxt;
    now.push(0);
    for(int i = 0; i < 200; i++) {
        
        while(!now.empty()) {
            int p = now.front(); now.pop();
            if ( p == N) { cout << cnt << endl; return 0;}
            minc = min( minc, N-p + cnt);
            for (int n = 6; p+n <= N; n*=6 ) {
                if (visited[p+n]) continue;
                nxt.push(p+n);
                visited[p+n] = true;
            }
            for (int n = 9; p+n <= N; n*=9 ) {
                if (visited[p+n]) continue;
                nxt.push(p+n);
                visited[p+n] = true;
            }
        }
        cnt++;
        now.swap(nxt);
    }
    cout << minc << endl;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    if(n == m)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int a,b;
  cin>>a>>b;
  if(a==1) a+=13;
  if(b==1) b+=13;

  if(a>b) cout<<"Alice"<<endl;
  else if(a==b) cout<<"Draw"<<endl;
  else cout<<"Bob"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string> 
typedef long long ll;
using namespace std;

int main() {
    
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll ac = a * c;
    ll ad = a * d;
    ll bc = b * c;
    ll bd = b * d;
    ll res = max({ ac, ad, bc, bd });
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3552
#include<iostream>
using namespace std;
int main() {
	float v,y,t;
	while (cin >> v) {
		t = v / 9.8;
		y = 4.9*t*t;
		int a=-5;
		int ans = 0;
		while (1) {
			ans = ans + 1;
			a = a + 5;
			if (y <= a) {
				goto a;
			}
		}
	a:;
		cout << ans << endl;
	}
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
     
     
typedef long long ll;
typedef vector <int> vi;
typedef pair <int,int> pi;
typedef tuple <int,int,int> ti;

#define forn(i,a,n) for(int i = a; i < n ; i++)
#define mem(str,a) memset(str, a, sizeof(str));
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(nullptr)
const int MOD = 1e9+7, N = 1e7 + 10, E = 1e-9;
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//vector <int> show;
//for (auto x : show)
//   cout << x << " ";
getline(cin,s);


*/

int main() {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '+')
        cout << a+b << endl;
    else
        cout << a-b << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <assert.h>
using namespace std;
#define int long long

signed main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	vector<int> F(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> F[i];
	}
	sort(A.begin(), A.end());
	sort(F.rbegin(), F.rend());
	int ok = 1e18;
	int ng = -1;
	while (ok - ng > 1) {
		int m = (ok + ng)/2;
		int need = 0;
		for (int i = 0; i < N; i++) {
			need += max((int)0, (A[i] * F[i] - m + F[i] - 1) / F[i]);
		}
		if (need <= K) {
			ok = m;
		}
		else {
			ng = m;
		}
	}
	cout << ok << endl;
	return 0;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){
    int n, ans = 0;
    cin >> n;

    int b[n];
    for(int i = 1; i < n; i++){
        cin >> b[i];
    }

    // FOR(i, n){
    //     cout << b[i] << " ";
    // }
    // cout << endl;

    b[0] = b[n] = INF;
    for(int i = 1; i <= n; i++){
        ans += min(b[i-1], b[i]); 
    }

    cout << ans;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

#define FOR(i,a,b) for(int i=(a);i<(b);++(i))
#define REP(i,n) FOR(i,0,n)

#define dump(x) cerr << #x << " = " <<(x)<<endl;
#define debug(x) cerr << #x << " = " <<(x) << "(L" << __LINE__ << ")" << __FILE__ << endl;

using namespace std;

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int* A, int n, int left, int mid, int right){
  int n1=mid-left;
  int n2 =right-mid;
  REP(i,n1) L[i]=A[left+i];
  REP(i,n2) R[i]=A[mid+i];
  L[n1] =R[n2] = SENTINEL;
  int i=0;
  int j=0;
  for(int k=left; k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k] =L[i++];
    } else{
      A[k]=R[j++];
    }
  }
}

void merge_sort(int* A, int n,int left, int right){
  if(left+1<right){
    int mid= (left+right) >> 1;
    merge_sort(A,n,left,mid);
    merge_sort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}


int main(void){
  int A[MAX],n,i;
  cnt =0;
  cin >> n;
  REP(i,n)cin >> A[i];
  merge_sort(A,n,0,n);
  FOR(i,0,n) {
    if(i)cout<<" ";
    cout <<A[i];
  }cout << endl;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 5060
import java.util.*;


class Main{
    static long mod = 1000000007;
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[][] A = new int[N][2];
        for(int i=0;i<N;i++){
            A[i][0] = sc.nextInt();
            A[i][1] = sc.nextInt();
        }
        sc.close();

        Arrays.sort(A, (a,b) -> a[1]-b[1]);
        //dump(A);

        long time = 0;
        for(int i=0;i<N;i++){
            time += A[i][0];
            if(time>A[i][1]){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");


    }

    public static void dump(int[][] a) {
        for(int i=0;i<a.length;i++){
            System.out.println(a[i][0] + " " + a[i][1]);
        }
        return;
    }
}

Measured memory_bytes: 106728
#include<bits/stdc++.h>
using namespace std;
const long long M =1e3+2,MOD=1e9+7;
typedef long long ll;
#define pb push_back
#define Y printf("Yes\n")
#define N printf("No\n")
#define O printf("-1\n")
bool f_2=false,vis[M]= {false},f=false;
vector<ll>v[M],v_1,v_2,v_3,v_4,v_5;
string s,p,q,ok,ch;
map<ll,ll>mp,mp_2;
set<ll>st,st_1;
ll Rank[M],parent[M]= {-1};
ll cnt=0,cost=0,mx=0,NODE,t,par;
deque<ll>Q;
//vector< pair<ll,ll > >v,v_1;
struct node
{
    ll pa,ran,visit;

};
//node X[M];
int main()
{
    ios::sync_with_stdio(false);//ISHWAR
    cin.tie(0);//Tourist_Twin
   //freopen("kamona.txt","r",stdin);
    ll a,b,c=1,n,t,sum=0,mx=0,l,x,y,i=0,j=0,result=0,e,sum_2,ans=0,d,k;
    cin>>a>>b;
    if((a+b)%2==0)
        cout<<(a+b)/2<<endl;
    else
        cout<<"IMPOSSIBLE"<<endl;

        return 0;
    }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int H, W;
	while (true) {
		cin >> H >> W;
		if (H == 0 & W == 0)return 0;
		for (int i = 0;i < H;i++) {
			for (int j = 0; j < W;j++) {
				if (i == 0 | i == H - 1) { cout << "#"; continue; }
				if (j == 0 | j == W - 1) { cout << "#"; continue; }
				cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3052
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n;
	cin >> n;
	vector<ll> vc(n);
	for(auto& el: vc) cin >> el;
	ll ans = 0;
	for(int i = 1; i < n; i++) {
		ll cnd = max(0LL, vc[i - 1] - vc[i]);
		ans += cnd;
		vc[i] += cnd;
	}
	cout << ans << '\n';
}



Measured memory_bytes: 4776
import heapq
N,M=map(int,input().split())
A=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(A) #落としたりするのもO(N)かかってしまうのでHeapで実装
#A=[i for i in range(N)]
for i in range(M):
  B = heapq.heappop(A)
  heapq.heappush(A,-1*(-1*B//2))
  #print(A)
print(-sum(A))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,m;cin>>n>>m;
  vpii a(n);
  rep(i,n){
    int x,y;cin>>x>>y;
    a[i]=mp(x,y);
  }
  vpii c(m);
  rep(i,m){
    int x,y;cin>>x>>y;
    c[i]=mp(x,y);
  }
  rep(i,n){
    int d=INT_MAX;
    int ans=0;
    rep(j,m){
      int tmp=abs(a[i].first-c[j].first)+abs(a[i].second-c[j].second);
      if(tmp<d){
        d=tmp;
        ans=j+1;
      }
    }
    cout(ans);
  }
  return 0;
}

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

using namespace std;

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

    int K;
    cin >> K;

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

    vector<long long> dp( 100010 );
    for ( int i = 0; i < 100010; ++i ) dp[ i ] = 1LL << 60;
    dp[ 1 ] = 0;
    for ( int i = 1; i < N; ++i )
    {
        for ( int j = 1; j <= K && j < N; ++j )
        {
            dp[ i + j ] = min( dp[ i + j ], dp[ i ] + abs( h[ i + j - 1 ] - h[ i - 1 ] ) );
        }
    }

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

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
 
const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
 
int main()
{
  cout << fixed << setprecision(10);
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  rep(i,ty-sy)
  {
    cout << "U";
  }
  rep(i,tx-sx)
  {
    cout << "R";
  }
  rep(i,ty-sy)
  {
    cout << "D";
  }
  rep(i,tx-sx)
  {
    cout << "L";
  }
  cout << "L";
  rep(i,ty-sy+1)
  {
    cout << "U";
  }
  rep(i,tx-sx+1)
  {
    cout << "R";
  }
  cout << "D";
  cout << "R";
  rep(i,ty-sy+1)
  {
    cout << "D";
  }
  rep(i,tx-sx+1)
  {
    cout << "L";
  }
  cout << "U" << endl;
  return 0;
}

Measured memory_bytes: 3580
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

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

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

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

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

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

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

mymath = mymath()

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

output = output()

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

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

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

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

def main():
    A = []
    while True:
        N = input()
        if N == '0':
            break
        A.append(N)
    
    for i in A:
        ans = 0
        for j in i:
            ans += int(j)
        print(ans)

if __name__ == '__main__':
    main()




Measured memory_bytes: 5760
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> f(n + 1);
    ll ans = 0;
    REP(i, 1, n + 1){
        for(int j = i; j <= n; j += i){
            f[j]++;
        }
        ans += i * f[i];
    }
    print(ans);

}



Measured memory_bytes: 81360
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TheFirstHeat
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            //int a = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int A = int.Parse(input[1]);
            int B = int.Parse(input[2]);
            // 文字列の入力
            //string s = Console.ReadLine();

            int max = 0;
            if (A > B)
            {
                max = B;
            }
            else
            {
                max = A;
            }
            //
            int min = 0;
            if (A + B - N < 0)
            {
                min = 0;
            }
            else
            {
                min = A + B - N;
            }
            //出力
            Console.WriteLine(max+ " " + min);
        }
    }
}


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

using ll=long long;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  ll wcnt=0;
  ll res=0;
  for(int i=0;i<n;i++){
    if(s[i]=='B') wcnt++;
    else res+=wcnt;
  }

  cout<<res<<endl;
  return 0;
}

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

using namespace std;

int main(){
	vector<int> square;
	for(int i = 1;i <= 1<<8;i++){
		if(i*i > 1<<15) break;
		square.push_back(i * i);
	}
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		int ans = 0;
		for(int i = 0;i < square.size();i++){
			if(n == square[i]) ans++;
			if(n < square[i]) break;
			for(int j = i;j < square.size();j++){
				if(n == (square[i]+square[j])) ans++;
				if(n < (square[i]+square[j])) break;
				for(int k = j;k < square.size();k++){
					if(n == (square[i]+square[j]+square[k])) ans++;
					if(n < (square[i]+square[j]+square[k])) break;
					int rest = n - (square[i] + square[j] + square[k]);
					bool flag = false;
					for(int l = 1;l<rest;l++){
						if(l*l > rest) break;
						if(l*l == rest && l*l >= square[k]){
							flag = true;
							break;
						}
					}
					if(flag) ans++;
				}
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()

int main(){

    int N;
    cin >> N;
    vector<int> A(N+1);
    rep(i, N+1) cin >> A[i];

    if(N==0){
        if(A[0]==1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }

    int64_t ans=0;
    vector<int64_t> ok(N+1);
    ok[0]=1;
    int64_t leaf = 0;
    rep(i, N+1) leaf+=(int64_t)A[i];
    leaf -=2;
    int64_t INF = 100000000000000000;

    rep(i, N+1){

        if(i==0){
            if(A[0]!=0){
                cout << -1 << endl;
                return 0;
            }
        }

        else{
            int64_t x=ok[i-1]*2-A[i];
            if(x<0){
                cout << -1 << endl;
                return 0;
            }
            if(x>=INF) x=INF;
            ok[i]=x;
        }

    }

    rep(i, N) ans+=(int64_t) A[i+1]*(i+1);
    ans++;
  
    int cnt=1;
    
    while(leaf>0){
        if(leaf<ok[cnt]) ans-=(int64_t) leaf*cnt;
        else ans-=(int64_t) ok[cnt]*cnt;
        leaf-=ok[cnt];
        cnt++;
    }
  
    cout << ans << endl;
  	
}

Measured memory_bytes: 4580
#include <iostream>
#include <map>
#include <vector>
#include <set>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		set<int> Set;
		vector<int> num;
		map<int, unsigned long long int> Map;
		while(n--)
		{
			unsigned long long int a, b, c;
			cin >> a >> b >> c;
			if(Set.find(a) == Set.end())
			{
				num.push_back(a);
			}
			Set.insert(a);
			Map[a] += b * c;
		}
		bool exist_flag = false;
		for(int i = 0; i < num.size(); ++i)
		{
			if(Map[num[i]] >= 1000000)
			{
				cout << num[i] << endl;
				exist_flag = true;
			}
		}
		if(!exist_flag)
		{
			cout << "NA" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1336
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a,b;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

bool chk(lli i)
{
    return 2*b[i]>=a[i+1];
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    a.clear();a.reserve(n);

    fo(i,n)
    {
        cin>>in;
        a.pb(in);
    }

    a.pb(-INF);
    sort(all(a));
    a[0]=0;

    b.pb(0);
    repA(i,1,n)
        b.pb(a[i]+b.back());

    dbg(a,b);

    repD(i,n-1,1)
    {
        if(chk(i))
            continue;
        break;
    }
    dbg(i);
    cout<<n-i<<endl;

}   aryanc403();
    return 0;
}


Measured memory_bytes: 2928
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
c = Counter(s)
# print(c)
res = 1
for v in c.values():
    # print(v)
    res *= v+1
    res %= mod
print(res-1)

Measured memory_bytes: 10392
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  string s,t;
  cin >> s;
  cin >> t;
  if(s.size()<t.size()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  int i = s.size()-t.size();
  while(i>=0){
    if(i==-1) break;
    bool buf = true;
    rep(j,t.size()) buf = buf && (t[j] == s[i+j] || s[i+j] == '?');
    if (buf) break;
    i--;
  }
  if(i==-1){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  rep(j,t.size()) s[i+j] =t[j];
  rep(k,s.size()) if(s[k]=='?') s[k] = 'a';
  cout<<s<<endl;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n; vector<bool> tf(n,false); vl num(n); ll ans = 0;
  rep(i,n){ ll x; cin >> x; num[i] = x; } ll ramp = 0; ll count = 0;
 
  while(ans == 0){
    if(tf[ramp]){
      ans = -1;
      break;
    }
    else{
      tf[ramp] = true;
      ramp = num[ramp] - 1;
      count++;
      
    }
    
    if(ramp == 1) ans = count;
  }
  
  cout << ans << endl;
}
      

Measured memory_bytes: 1024
def insertion_sort(A, N):
    for i  in range(N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        
        print(' '.join(map(str, A)))

def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    
    insertion_sort(A, N)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 7748
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	double a, b, c, d, e, f, x, y;

	while(1){
		cin >> a >> b >> c >> d >> e >> f;

		if(cin.eof()){
			break;
		}

		x = ((b * f) - (e * c)) / ((b * d) - (a * e));
		y = ((a * f) - (d * c)) / ((a * e) - (d * b));

		if(x == 0){
			x = 0;
		}
		if(y == 0){
			y = 0;
		}

		cout << fixed << setprecision(3) << x << " ";
		cout << fixed << setprecision(3) << y << endl;
	}

	return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> a(3);
  for (int i=0;i < 3; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  cout << a.at(2)-a.at(0) << endl;
}


Measured memory_bytes: 256
class UnionFind
  # @param {Integer} n
  def initialize(n)
    @id = Array.new(n)
    @sz = Array.new(n)
    n.times do |i|
      @id[i] = i
      @sz[i] = 1
    end
  end
 
  def connected?(i, j)
    root(i) == root(j)
  end
 
  def unite(i, j)
    iroot = root(i)
    jroot = root(j)
    return if iroot == jroot
    if @sz[iroot] < @sz[jroot]
      @id[iroot] = j
      @sz[jroot] += @sz[iroot]
    else
      @id[jroot] = i
      @sz[iroot] += @sz[jroot]
    end
  end
 
  private
 
  def root(i)
    if @id[i] == i
      i
    else
      @id[i] = @id[@id[i]] # pass compression
      root(@id[i])
    end
  end
end

N = gets.to_i
V = N.times.map{gets.split.map(&:to_i)}
Ex = N.times.sort_by{|i| V[i][0] }.each_cons(2).map{|a,b| [V[b][0] - V[a][0], a, b] }
Ey = N.times.sort_by{|i| V[i][1] }.each_cons(2).map{|a,b| [V[b][1] - V[a][1], a, b] }

E = Ex + Ey
E.sort_by!(&:first)

uf = UnionFind.new(N)

# kruskal
ans = E.inject(0) do |total, (cost, u, v)|
  # 辺を追加しても閉路ができないなら、その辺を採用する
  unless uf.connected?(u,v)
    uf.unite(u, v)
    total + cost # 採用した辺のコストを足す
  else
    # すでにconnectedな辺を追加すると閉路が出来てしまうので何もしない
    total
  end
end
puts ans

Measured memory_bytes: 28168
def main():
    N, T = map(int, input().split())
    A = [0] * N
    B = [0] * N
    X = [list(map(int, input().split())) for _ in range(N)]
    X.sort(lambda x: x[0])
    for i in range(N):
        A[i], B[i] = X[i]
    M = T+max(A)
    dp = [[(0, 0)] * M for _ in range(2)]
    for i in range(N):
        a, b = A[i], B[i]
        for j in range(M):
            dp[i & 1][j] = dp[(i-1) & 1][j]
        for j in range(a, M):
            t, m = dp[(i-1) & 1][j-a]
            t += b
            m = max(m, a)
            if j - m < T and dp[i & 1][j][0] < t:
                dp[i & 1][j] = (t, m)
    ans = 0
    for i in range(M):
        ans = max(ans, dp[(N-1) & 1][i][0])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 48856
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,r;
  cin >> h >> r;
  if(h<0&&h+r==0) cout << 0 << endl;
  else if(h+r<0) cout << -1 << endl;
  else cout << 1 << endl;
  return (0);
}



Measured memory_bytes: 3092
S = input()

def solver(S):
    l = 0   
    r = len(S)-1

    ans = 0
    while l < r:
        if S[l] == S[r]:
            l += 1
            r -= 1
            continue

        if S[l] == "x":
            l += 1
            ans += 1
            continue
        
        if S[r] == "x":
            r -= 1
            ans += 1
            continue
        
        return -1
    
    return ans


print(solver(S))

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

const int BIT_SIZE = 28;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	vector<int> a(N), b(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	int res = 0;
	for (int bi = 0; bi <= BIT_SIZE; bi++) {
		vector<int> v(N);
		for (int i = 0; i < N; i++) {
			v[i] = b[i] & ((1 << (bi + 1)) - 1);
		}
		sort(v.begin(), v.end());
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			int val = a[i] & ((1 << (bi + 1)) - 1);
			cnt += upper_bound(v.begin(), v.end(), (2 << bi) - val - 1) - lower_bound(v.begin(), v.end(), (1 << bi) - val);
			cnt += upper_bound(v.begin(), v.end(), (4 << bi) - val - 1) - lower_bound(v.begin(), v.end(), (3 << bi) - val);
		}
		cnt &= 1;
		res |= cnt << bi;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2672
fun main(args: Array<String>) {

    val input = readLine()
    var n:Int = Integer.parseInt(input)
    var sum:Long = 0

    for(i in 1 until n+1){
        for(j in 1 until n+1){
            for(k in 1 until n+1){
                sum += gcd(i,j,k)
            }
        }
    }
    println(sum)
}

fun gcd(a:Int,b:Int,c:Int):Int{
    val v1 = calc_gcd(a,b)
    val v3 = calc_gcd(v1,c)
    return v3
}

fun calc_gcd(a:Int,b:Int):Int{
    if(a < b) return calc_gcd(b,a)
    if(b == 0) return a
    return calc_gcd(b, a % b)
}

Measured memory_bytes: 34704
#include <iostream>
    #include <vector>
    #include <bits/stdc++.h>
    #define rep(i,n) for (int i = 1; i <= (n); ++i)
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> P;
     
    int main(){
      int k,x;
	cin>>k>>x;
      rep(i,(k*2)-1){
      cout<<x+(i-k)<<" ";
      }
    }

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

int main() {
  int n;
  cin>>n;
  pair<int, int> tasks[n];
  for(int i=0; i<n; i++) {
    int a,b;
    cin>>a>>b;
    pair<int, int> task;
    task.first = b;
    task.second = a;
    tasks[i] = task;
  }

  sort(tasks, tasks + n);

  int sum = 0;
  for(int i=0; i<n; i++) {
    sum += tasks[i].second;
    if(sum>tasks[i].first) {
      cout<<"No"<<endl;
      return 0;
    }
  }

  cout<<"Yes"<<endl;

  return 0;
}

Measured memory_bytes: 5184
#include <iostream>
#include <algorithm>
#include <set>

using i64 = long long;

const int N = 400000 + 7;

int n;
int a[N], b[N];
i64 u[N], v[N];
i64 x, y, z;

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", a + i, b + i),
		x += v[i] = a[i], y += v[i + n] = b[i];
	std::sort(v + 1, v + n * 2 + 1);
	for (int i = 1; i <= n * 2; ++i)
		u[i] = u[i - 1] + v[i];
	z = std::min(x, y);
	for (int i = 1; i <= n; ++i) {
		if (a[i] > b[i]) std::swap(a[i], b[i]);
		if (a[i] > v[n - 2])
			z = std::min(z, u[n - 2] + a[i] + b[i]);
		else {
			if (b[i] > v[n - 1])
				z = std::min(z, u[n - 1] + b[i]);
			else
				z = std::min(z, u[n]);
		}
	}
	printf("%lld", z);
		
	return 0;
}


Measured memory_bytes: 7936
k,n = map(int,input().split())

a = list(map(int,input().split()))

memo = []

for i in range(1,n):
    memo.append(abs(a[i]-a[i-1]))
memo.append(k-a[-1]+a[0])
memo.sort()

ans = 0

for i in range(len(memo)-1):
    ans += memo[i]

print(ans)

Measured memory_bytes: 87828
#include "bits/stdc++.h"
#define F first
#define S second
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
ll fun(ll x) {
  if (x > 1)
    return 2 * fun(x / 2) + 1;
  else
    return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll h = 0;
  cin >> h;
  cout << fun(h);
}



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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        System.out.println(problem102a(n));
    }

    private static int problem102a(int n) {
        return (n % 2 == 0) ? n : (n * 2);
    }
}

Measured memory_bytes: 21204
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string s, t;
    cin >> s >> t;

    int ans = 0;
    REP(i, s.size()) {
        if (s[i] != t[i]) ans++;
    }

    print(ans);
    
}


Measured memory_bytes: 3680
from collections import deque
INF = 10 ** 9 + 7

N, u, v = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N - 1)]

edges = [[] for _ in range(N)]
for x, y in X:
    edges[x - 1].append(y - 1)
    edges[y - 1].append(x - 1)
    
def bfs(s):
    d = [INF] * N
    d[s] = 0

    visited = [False] * N
    visited[s] = True
    
    q = deque()
    q.append(s)
    
    while q:
        u = q.popleft()
        for v in edges[u]:
            if visited[v]:
                continue
            
            visited[v] = True
            d[v] = d[u] + 1
            q.append(v)
            
    return d

ans = 0
for x, y in zip(bfs(u - 1), bfs(v - 1)):
    if x <= y:
        ans = max(ans, y - 1)
        
print(ans)


Measured memory_bytes: 79704
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007

struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};

using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<edge>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

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


int main(){

    int n; cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; i++){
    	if(i%3 == 0 || i%5 == 0) continue;
        sum += i;
    }
    cout << sum << endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    string s;
    cin>>s;
    int n=s.size()+1;
    vector<ll> v(n);
    
    for (int i = 0; i < n-1; i++)
    {
        if(s[i]=='<')
        {
            v[i+1]=max(v[i+1],v[i]+1);
        }
    }
    for (int i = n - 2; i >= 0; i--)
    {
        if(s[i]=='>')
        {
            v[i]=max(v[i],v[i+1]+1);
        }
    }
    ll ans=0;
    for (int i = 0; i < n; i++)
    {
        ans+=v[i];
        //cout<<v[i]<<" ";//
    }
    //cout<<endl;

    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 4740
from collections import deque
N = 3
goal = "123456780"
def g(i, j, a):
    if i > j:
        i, j = j, i
    return a[:i] + a[j] + a[i + 1:j] + a[i] + a[j + 1:]
def solve():
    m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}}
    start = "".join(input().replace(" ", "") for _ in range(N))
    if start == goal:
        return 0
    zero = start.find("0")
    dp = deque([(0, start, zero, 1), (0, goal, 8, 0)])
    TABLE = {start:(1, 0), goal:(0, 0)}
    while dp:
        cnt, M, yx, flg = dp.popleft()
        cnt += 1
        for nyx in m[yx]:
            key = g(yx, nyx, M)
            if key in TABLE:
                if TABLE[key][0] != flg:
                    return TABLE[key][1] + cnt
                continue
            TABLE[key] = (flg, cnt)
            dp.append((cnt, key, nyx, flg))
def MAIN():
    print(solve())
MAIN()



Measured memory_bytes: 8884
s = gets.chomp.split('')
if s.size == 2
  if s[0] == s[1]
    puts "1 2"
    exit
  end
else
  2.upto(s.size - 1) do |i|
    if s[i-2] == s[i-1] || s[i-2] == s[i] || s[i-1] == s[i]
      puts "#{i-1} #{i+1}"
      exit
    end
  end
end
puts "-1 -1"


Measured memory_bytes: 6908