akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**9)

read=sys.stdin.read
class Unionfind():
    def __init__(self,n):
        self.parents=[-1]*n
        self.dist=[0]*n 
    
    def find(self,x):
        if self.parents[x]<0:
            return self.dist[x],x
        else:
            tmp=self.find(self.parents[x])
            self.dist[x]+=tmp[0]
            self.parents[x]=tmp[1]
        return self.dist[x], self.parents[x]
    
    def union(self,x,y,d):
        _,rx=self.find(x)
        _,ry=self.find(y)
        diff=self.dist[y]-self.dist[x]-d
        if rx==ry:
            if diff!=0:
                return True
            return False
        if diff<0:
            rx,ry=ry,rx
            diff=-diff
        self.parents[ry]=min(self.parents[ry],self.parents[rx]-diff)
        self.parents[rx]=ry
        self.dist[rx]=diff
        return False
    
def main():
    n,m,*lrd=map(int,read().split())
    v=Unionfind(n)
    for l,r,d in zip(*[iter(lrd)]*3):
        if v.union(l-1,r-1,d):
            print('No')
            break
    else:
        if max(-d-1 for d in v.parents if d<0) >10**9:
            print('No')
        else:
            print('Yes')
if __name__=='__main__':
    main()


Measured memory_bytes: 74568
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 4000;
int dp[2][N];

/*
  find substr of txt from word
 */
int solve(string &txt,string &word){
  rep(j,word.size())dp[0][j] = 0,dp[1][j] = 0;
  rep(j,word.size())if (txt[0] == word[j])dp[0][j] = 1;
  int ret = 0;
  REP(i,1,txt.size()){
    rep(j,word.size()){
      if (txt[i] == word[j]){
	dp[1][j] = 1;
	if (j-1 >= 0)dp[1][j] = max(dp[1][j],dp[0][j-1]+1);
      }else dp[1][j] = 0;
      ret = max(ret,dp[1][j]);
    }
    rep(j,word.size()){dp[0][j] = dp[1][j];dp[1][j] = 0;}
  }
  return ret;
}

main(){
  string a,b;
  while(cin>>a>>b){
    cout << solve(a,b)<<endl;
  }
}

Measured memory_bytes: 964
import java.util.*;

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

        String s = sc.next();

        boolean m = s.charAt(2) == s.charAt(3);
        boolean n = s.charAt(4) == s.charAt(5);

        if(m && n) System.out.println("Yes");
        else System.out.println("No");
 
    } 
}

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

const int64_t MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  string s;
  cin >> s;

  int zeroCount = 0;
  for(auto c:s){
    if(c=='0'){
      zeroCount++;
    }
  }
  int n = s.length();
  if(n-zeroCount > zeroCount){
    cout << zeroCount*2 << endl;
  }
  else{
    cout << (n-zeroCount)*2 << endl;
  }
  #if 0
  int count = 0;
  int pos = string::npos;
  while(true){
    pos = s.find("01");
    if(pos!=string::npos){
      s.erase(pos,2);
      count += 2;
    }
    else{
      pos = s.find("10");
      if(pos!=string::npos){
        s.erase(pos,2);
        count += 2;
      }
      else{
        break;
      }
    }
  }
  
  cout << count << endl;
  #endif
  return 0;
}



Measured memory_bytes: 3836
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

ans = 10 ** 9
for v in a:
    tmp = 0
    while v % 2 == 0:
        tmp += 1
        v //= 2
    ans = min(ans, tmp)
print(ans)


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

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}


int main(void){
    double r;
    cin>>r;
    printf("%f\n",2*r*PI);
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &A[i]);
  }
  sort(A.begin(), A.end());
  ll n = A[N - 1], r = -1;
  ll diff = numeric_limits<ll>::max();
  for (int i = 0; i < N - 1; ++i) {
    if (abs(n - 2 * A[i]) < diff) {
      diff = abs(n - 2 * A[i]);
      r = A[i];
    }
  }
  printf("%lld %lld\n", n, r);
  return 0;
}


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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#define co(n) cout << (n) << endl;
#define cn(n) cin >> n;
#define all(x) (x).begin(), (x).end()

int main(){
  ll n;
  cn(n)
  ll cnt = 1; //next
  rep(i,n){
    ll a;cn(a)
    if (cnt==a)++cnt;
  }
  if (cnt==1){
    puts("-1");
  }else{
    cout << n-cnt+1 << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
flag = True
ans = 1
now = n
count = 1


for i in range(10000):
    if n > 2**i:
        pass
    elif n == 1:
        print(1)
        break
    elif n == 2**i:
        print(4*(2**(i)//2)-1)
        break
    else:
        print(4*(2**(i-1)//2)-1)
        break

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

ans = sum(A[1::2])
dA = []
for a1, a2 in zip(A, A[1:]):
    dA.append(a1 - a2)

max_cum_l = 0
cum_l = 0
L = [0]
for idx_l in range(0, N - 1, 2):
    cum_l += dA[idx_l]
    max_cum_l = max(max_cum_l, cum_l)
    L.append(max_cum_l)
max_cum_r = 0
cum_r = 0
R = [0]
for idx_r in range(N - 2, -1, -2):
    cum_r -= dA[idx_r]
    max_cum_r = max(max_cum_r, cum_r)
    R.append(max_cum_r)
R.reverse()
if N%2:
    ma = -(1<<60)
    for l, r in zip(L, R):
        if ma < l+r:
            ma = l+r
    print(ans + ma)
else:
    print(max(L) + ans)


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  ll D, X; cin >> D >> X;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  ll sum = X;
  for (ll i = 0; i < N; i++) {
    ll t = 1;
    while (t <= D) {
      sum += 1;
      t += A[i];
    }
  }
  cout << sum << endl;

  return 0;
}



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

const int N = 1 << 19;
const int MOD = 1e9 + 7;
inline void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
        int n, m, k;
        scanf("%d%d%d", &n, &m, &k);
        n --; //attention
        vector<vector<int>> check(m, vector<int> (n, -1));
        for (int i = 0; i < k; i ++) {
                int a, b, c;
                scanf("%d%d%d", &a, &b, &c);
                a --, b --;
                check[a][b] = c;
        }
        vector<vector<int>> dp(2, vector<int> (N, 0));
        dp[0][0] = 1;
        for (int i = 0; i < m; i ++) {
                for (int j = 0; j < n; j ++) {
                        for (int mask = 0; mask < (1 << n); mask ++) {
                                dp[1][mask] = 0;
                        }
                        for (int mask = 0; mask < (1 << n); mask ++) {
                                if (dp[0][mask] == 0) continue;
                                //left
                                if (check[i][j] != 1 && (~mask >> j) & 1) {
                                        add(dp[1][mask], dp[0][mask]);
                                } 
                                //right
                                if (check[i][j] != 0) {
                                        int mask2 = (((mask - (1 << j)) & mask) | (1 << j));
                                        add(dp[1][mask2], dp[0][mask]);
                                }
                        }
                        swap(dp[0], dp[1]);
                }
        }
        int ans = 0;
        for (int mask = 0; mask < (1 << n); mask ++) {
                add(ans, dp[0][mask]);
        }
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 6400
//Coalbert Ramirez
//AtCoder Begginer Contest D - String Formation
#include <bits/stdc++.h>
using namespace std;

int main(){
  string s;
  char ch;
  deque<char> deq;
  int q, op, op2;
	bool rev = 0;
  cin >> s >> q;
  for(int i = 0; i < s.size(); ++i) deq.push_front(s[i]);
  while(q--){
  	cin >> op;
  	if (op == 1) rev ^= 1;
  	else {
  		cin >> op2 >> ch;
  		if (op2 == 1){
  			if (rev) deq.push_front(ch);
  			else     deq.push_back(ch);
			}
			else{
				if (rev) deq.push_back(ch);
				else     deq.push_front(ch);
			}
		}
	}
	
	if (rev){
		while (deq.size()){
			cout << deq.front();
			deq.pop_front();
		}
	} else {
		while(deq.size()){
			cout << deq.back();
			deq.pop_back();
		}
	}
	cout << "\n";
	
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  map<int ,int>mp;
  for(int i=2;i<=n;i++)
  {
    int x;
    cin>>x;
    mp[x]++;
  }
  for(int i=1;i<=n;i++)
    cout<<mp[i]<<endl;
}

Measured memory_bytes: 13020
#include <iostream>
using namespace std;
long long as(long long  a,long long  b){
	if(a<b) swap(a,b);
	long long c;
	while(a%b){
		c=a%b;
		a=b;
		b=c;
	}
	return b;
}
		
int main(){

	long long a,b;
	int n;
	cin>>n>>a;
	for(int i=1;i<n;i++){
		cin>>b;
		a=a/as(a,b)*b;
	}
	cout<<a<<endl;
	
	return 0;
	
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N,K,A[101010];
ll Kp;
ll i,j,xa[100],xan,ans;

bool grdy(ll k,ll x,ll xi){
    //printf("%lld,%lld,%lld\n", k, x, xi);
    if(k==0){
        xa[xi] = x;
        xan = xan < xi ? xi : xan;
        return false;
    }
    ll ct = 0,i;
    if(x+k>K){
        grdy(k>>1, x, xi);
        return true;
    }
    fornum(i,0,N){
        if((A[i]&k)==0){
            ct++;
            //printf("%lld ", A[i]);
        }
    }
    //printf("%lld\n", ct);
    if(N/2<ct){
        if(grdy(k>>1,x+k,xi)){
            grdy(k>>1, x, xi + 1);
        }
    }else{
        grdy(k >> 1, x, xi);
    }
    return false;
}

int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i, 0,N){
        scanf("%lld",&A[i]);
    }
    

    for (Kp = 0; (1ll << Kp) <= K;Kp++)
        ;
    if(K!=0)
    grdy(1ll << (Kp - 1), 0, 0);
    //printf("%lld ", x);
    fornum(i,0,xan+1){
        ll a = 0;
        fornum(j,0,N){
            a+=(xa[i]^A[j]);
        }
        if(ans<a){
            ans = a;
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,-1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    vector<int> S(1000000,0);
    for(int i=0; i<N; i++){
        S[A[i]]++;
    }
    int ans = 0;
    for(int i=0; i<1000000; i++){
        S[i+1] += S[i];
        if(S[i+1]*2 == N){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4608
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;


int main()
{
	ll n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2 << endl;
	}
	else {
		cout << min(a-1,n-b)+1+(b-a-1)/2 << endl;
	}

	return 0;
}


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

using namespace std;

int main()
{
    long long K;
    scanf("%lld",&K);
    long long arr[50];
    for(int i=0;i<50;i++)
    {
        arr[i] = i + (K/50);
    }
    for(int i=0;i<(K%50);i++)
    {
        arr[i] += (long long)50;
        for(int j = 0;j<50;j++)
        {   if(j == i)
                continue;
            else
                arr[j]--;
        }
    }

    printf("50\n");
    for(int i=0;i<50;i++)
        printf("%lld ",arr[i]);

}


Measured memory_bytes: 256
// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;

int main(){
	
	int N,W; cin>>N>>W;
	long long int dp[W+1];
	for(int i=0;i<W+1;i++) dp[i]=0;

	for(int i=0;i<N;i++){
		int weight,value; cin>>weight>>value;
		for(int i=W-weight;i>=0;i--){
			dp[i+weight]=max(dp[i+weight],dp[i]+value);
		}
	}

	cout<<dp[W]<<endl;
	
	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
int main() {
  int n, y;
  cin >> n >> y;
  
  for (int i=0; i<n+1 && i*10000<=y; ++i) {
    for (int j=0; i+j<n+1 && i*10000+j*5000<=y; ++j) {
      if ((y-i*10000-j*5000)/1000 + i + j == n) {
        cout << i << ' ' << j << ' ' << n-i-j << endl;
        goto FOUND;
      }
    }
  }
  cout <<"-1 -1 -1"<<endl;
  FOUND: 
  
  int c;
}

Measured memory_bytes: 256
package main

import (
        "fmt"
        "math"
)

func main() {
        var n int
        fmt.Scanf("%d", &n)
        for i := 0; i < n; i++ {
                var ax, ay, ar, bx, by, br float64
                fmt.Scanf("%f %f %f %f %f %f", &ax, &ay, &ar, &bx, &by, &br)

                d := math.Sqrt((bx-ax)*(bx-ax) + (by-ay)*(by-ay))
                if d <= ar + br {
                        if ar > br {
                                if ar > br + d {
                                        fmt.Println("2")
                                } else {
                                        fmt.Println("1")
                                }
                        } else {
                                if br > ar + d {
                                        fmt.Println("-2")
                                } else {
                                        fmt.Println("1")
                                }
                        }
                } else {
                        fmt.Println(0)
                }
        }
}



Measured memory_bytes: 1136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,i;
    string s;
    cin>>s;
    n=0;x=0;
    for(i=0;i<3;i++)
    {
        if(s[i]=='R')
            n++;
        else
        {
            x=max(x,n);
            n=0;
        }
    }
    if(n)
    {
        x=max(x,n);
    }
    cout<<x<<endl;
}

Measured memory_bytes: 3620
//
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    string S;
    cin >> S;
    vector<int> cnts(26, 0);
    for (int i = 0; i < S.size(); ++i)
    {
        ++cnts[S[i] - 'a'];
    }
    for (int i = 0; i < 26; ++i)
    {
        if (cnts[i] == 0)
        {
            cout << char('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


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

typedef pair< double , vector<int> > P;
P dp[(1<<16)][15];
double INF =9999999.9;
int n,no[15];
double r[15],t[15];


P rec(int S,int pos){
  //cout<<S<<' '<<pos<<' '<<cost<<' '<<size<<endl;
  if(dp[S][pos].first!=INF){
    return dp[S][pos];
  }

  if(S==(1<<(n))-1){
    vector<int> res;
    res.push_back(pos);
    return P(0.0,res);
  }

  double w=0.0;
  for(int i=0;i<n;i++){
    if((S>>i)&1){
      w+=(t[i]*20.0);
    }
  }

  
  int s;
  double v=2000.0/(70.0+w),add;

  for(int i=0;i<n;i++){
    if((S>>i)&1==1)continue;

    s=S+(1<<i);
    add=abs(r[i]-r[pos])/v;
    P X =rec(s,i);
    X.first+=add;
    //X.second.erase(X.second.end());
    
    if(X<dp[S][pos]){
      dp[S][pos].second.clear();
      dp[S][pos].second.push_back(pos);
      dp[S][pos].first=X.first;
      for(int j=0;j<(int)X.second.size();j++){
	dp[S][pos].second.push_back(X.second[j]);
      }
    }
   
  }
  
  return dp[S][pos];
}

int main(){
  while(cin>>n){
  for(int i=0;i<n;i++){
    cin>>no[i]>>r[i]>>t[i];
  }
  for(int i=0;i<(1<<16);i++)
    for(int j=0;j<15;j++){dp[i][j].first=INF;dp[i][j].second.clear();}
  
  P x,ans;
  ans.first=INF;
  for(int i=0;i<n;i++){
    x=rec((1<<i),i);
    if(x<ans){
      ans=x;
    }
    //cout<<x.first<<endl;
  }

  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<no[ans.second[ i ]];
  }
  cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 46416
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define ll long long int
#define lim 100010
#define mod 1e9+7
#define INF 1e9
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))

int main(void){
	int N,D;
	scanf("%d%d",&N,&D);
	double x[N][D];
	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++){
			scanf("%lf",&x[i][j]);
		}
	}
	int ans=0;
	double r;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			r=0;
			for(int k=0;k<D;k++){
				r+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			r = sqrt(r);
			if(ceil(r)==r && floor(r)==r)ans++;
		}
	}
	printf("%d",ans);
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define adrep(i,s,n) for (int i=(s);i<(n);i++)
using namespace std;
typedef long long ll;
ll INF=1e9;

int main(){

  ll N,M;
  cin>>N>>M;
  
  ll a[N],b[N];
  rep(i,N){
    cin>>a[i]>>b[i];
  }
  
  ll c[M],d[M];
  rep(i,M){
    cin>>c[i]>>d[i];
  }
  
  rep(i,N){

    ll distance=INF;
    int label=0;
    rep(j,M){

      ll now=abs(c[j]-a[i])+abs(d[j]-b[i]);
      if(now<distance){
        distance=now;
        label=j+1;
      }

    }
    cout<<label<<endl;

  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;


int main(){
    V<int> a;
    loop (5, i) {
        int v; cin >> v;
        a.push_back(v);
    }
    int k; cin >> k;
    int ok = 1;
    loop (5, i) loop (5, j) {
        if (abs(a[i] - a[j]) > k) ok = 0;
    }
    if (ok) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long i,j,k,a,b,c=0,d,n,m,x,y;
  cin>>a>>b>>c>>d;
  n=a*c;
  m=a*d;
  x=b*c;
  y=b*d;
  i=max(n,m);
  j=max(x,y);
  cout<<max(i,j)<<endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#define rep(i, n)for(int i=0; i<n; i++)
using ll = long long int;
using namespace std;

int main(){
    int x;
    cin >> x;
    if(x>=30)cout << "Yes"<< endl;
    else cout << "No"<< endl;

    return 0;
}

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

using namespace std;

#define INF (int) 1000000000

typedef long long ll;

int n;
double arr[3005], dp[3005][1505];
bool visited[3005][1505];

double prob(int cur, int left){
//	cout << "inside with: " << cur << " " << left << endl;
    if(left < 0){
//    	cout << "cant take no more tails" << endl;
        return 0;//outside
    }
    if(cur == n){//we want left to be nonnegative, any positive value is also acceptable
//    	cout << "finished seq, left nonnegative, return 1" << endl;
        return 1;//desired output
    }
    if(visited[cur][left] == 1){
//    	cout << "already calculated" << endl;
        return dp[cur][left];
    }
    dp[cur][left] = prob(cur+1, left-1)*(1-arr[cur]) + prob(cur+1, left)*arr[cur];
    visited[cur][left] = 1;
    return dp[cur][left];
}

int main(){
	for(int i = 0; i < 3005; i++){
		for(int j = 0; j < 3005; j++){
			visited[i][j] = 0;
		}
	}

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

    double ans = prob(0, (n-1)/2 );//tails are restricted
    printf("%.10f", ans);
}

Measured memory_bytes: 40192
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100100;
int a[2 * maxn];
int main(){
  int n, m; cin >> n >> m;
  for(int i = 0; i < 2 * n; i++) cin >> a[i];
  sort(a, a + 2 * n);
  int l = 0, r = n, a = 0;
  while(l <= r){
    int mid = (l + r)>>1;
    bool ok = true;
    for(int i = 2 * mid, j = 2 * n - 1; i < j; i++, j--){
      if(::a[i] + ::a[j] < m){
        ok = false;
        break;
      }
    }
    if(ok) r = mid - 1, a = mid;
    else l = mid + 1;
  }
  int ans = 0;
  for(int i = 0, j = 2 * a - 1; i < j; i++, j--) ans = max(ans, ::a[i] + ::a[j]);
  for(int i = 2 * a, j = 2 * n - 1; i < j; i++, j--) ans = max(ans, ::a[i] + ::a[j] - m);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{

    int a,b,i,j,z,min,l,x=0;
    scanf("%d%d",&a,&b);
    int ara[a];
    for(i=0;i<a;i++)
    {
        scanf("%d",&ara[i]);
        x=x+ara[i];
    }
    min=ara[0];

    for(j=0;j<a;j++)
    {

        if(ara[j]<min)
        {
            min=ara[j];
        }
    }
    
    if(b-x>0)
    {
        z=b-x;
        l=z/min;
        printf("%d\n",l+a);
    }
    else
        {
        printf("%d\n",a);
    }

}




Measured memory_bytes: 1720
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <chrono>
#include <numeric>

using namespace std;


int main(){
  long long n;
  long long a;
  long long t = 1;
  long long o = 1;
  cin >> n;
  for (long long i=0;i<n;i++) {
    cin >> a;
    t *= 3;
    if (a % 2 == 0)
      o *= 2;
  }
  cout << t - o << endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

e = [""] * h
for i in range(h):
    e[i] = input()
    

row = [False] * h
col = [False] * w



for i in range(h):
    for j in range(w):
        if e[i][j] == "#":
            row[i] = True
            col[j] = True


for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(e[i][j], end = '')
		print()


Measured memory_bytes: 4468
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <cstring>
#include <cstdlib>


using namespace std;

using ll = long long;

ll N, A[200000];

void solve() {
    cin >> N;
    ll p = 0;
    ll sum = 0;
    A[0] = 0;
    for (ll i = 0; i < N; i++) {
        cin >> A[i + 1];
        sum += llabs(A[i + 1] - p);
        p = A[i + 1];
    }
    sum += llabs(A[N]);
    A[N + 1] = 0;
    for (ll j = 1; j <= N; j++) {
        ll x1 = llabs(A[j - 1] - A[j]);
        ll x2 = llabs(A[j] - A[j+1]);
        ll x3 = llabs(A[j + 1] - A[j - 1]);
        printf("%lld\n", sum - x1 - x2 + x3);
    }
}

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


Measured memory_bytes: 2048
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n;
    cin>>n;
   long long int a[n],i,j=1,k=0,l,p=0,v;
   long long int h[n],f[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,greater<int>());
    for(i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            j++;
        }
        else{
          h[k++]=a[i];
          f[p++]=j;
          j=1;
    }
    }
    h[k]=a[n-1];
    f[p]=j;
  /*  for(i=0;i<=p;i++){
        cout<<f[i]<<endl;
    }*/
    for(i=0;i<=p;i++){
        if(f[i]>=4){
            cout<<(h[i]*h[i])<<endl;
            return 0;
        }
        else if(f[i]>=2){
               // cout<<"i="<<i<<endl;
            for(v=i+1;v<=p;v++){
                if(f[v]>=2){
                   // cout<<"i="<<i<<endl;
                    cout<<(h[i]*h[v])<<endl;
                    return 0;
                }
            }
            break;
        }
    }
    cout<<0<<endl;
}

Measured memory_bytes: 5928
integer(8) a,b,AA,BB
read*,a,b
if(mod(a-1,4)==3)AA=0
if(mod(a-1,4)==0)AA=a-1
if(mod(a-1,4)==1)AA=1
if(mod(a-1,4)==2)AA= xor(1,a-1)
if(mod(b,4)==3)BB=0
if(mod(b,4)==0)BB=b
if(mod(b,4)==1)BB=1
if(mod(b,4)==2)BB= xor(1,b)
print"(i0)",xor(AA,BB)
end

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	if N == 1 {
		fmt.Printf("Hello World\n")
	}
	if N == 2 {
		var a, b int
		fmt.Scan(&a)
		fmt.Scan(&b)
		fmt.Printf("%d\n", a+b)
	}
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

using namespace std;

static int count = 0;


template<typename T>
void merge(T ar[], T tmp[], int left, int mid, int right_last){
    int n, left_last, tmp_pos=left;

    left_last = mid - 1;
    n = right_last - left + 1;

    // ??????????????????????????§
    while (left <= left_last && mid <= right_last) {
        count++; // ???????????°
        if(ar[left] <= ar[mid]){
            tmp[tmp_pos] = ar[left];
            left++;
        }else{
            tmp[tmp_pos] = ar[mid];
            mid++;
        }
        tmp_pos++;
    }

    // ????????????
    while(left <= left_last){
        count++; // ???????????°
        tmp[tmp_pos] = ar[left];
        left++;
        tmp_pos++;
    }
    // ????????????
    while (mid <= right_last) {
        count++; // ???????????°
        tmp[tmp_pos] = ar[mid];
        mid++;
        tmp_pos++;
    }

    // tmp??????ar???
    for (int i = 0; i < n; i++) {
        ar[right_last] = tmp[right_last];
        right_last--;
    }

}

template<typename T>
void m_sort(T ar[], T tmp[], int left, int right){
    int mid;


    if(right > left){
        mid = (left + right) / 2;

        m_sort(ar, tmp, left, mid);
        m_sort(ar, tmp, mid + 1, right);

        merge(ar, tmp, left, mid + 1, right);
        
    }
}

template<typename T>
void merge_sort(T ar[], T tmp[], int n){
    m_sort(ar, tmp, 0, n - 1);
}

int ar[500000], tmp[500000];

int main(int argc, char const* argv[])
{
    int n;

    scanf("%d ", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &ar[i]);
    }

    merge_sort(ar, tmp, n);

    for (int i = 0; i < n - 1; i++) {
        printf("%d ", ar[i]);
    }
    printf("%d\n", ar[n-1]);
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 6648
#include<stdio.h>

int n;
int A[20];

int solve(int i,int m){
  if(m==0)return 1;
  if(i>=n)return 0;
  int res= solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}


int main(){
  int q,m,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m)==1){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }
  return 0;
}




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

int main(void) {
	char b;
	cin >> b;
	if (b == 'A') cout << 'T';
	if (b == 'T')cout << 'A';
	if (b == 'C')cout << 'G';
	if (b == 'G')cout << 'C';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

#define int long long

signed main(){
	string s;
	cin >> s;
	if(s.at(2) == s.at(3) && s.at(4) == s.at(5))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
abc = input()
abc = abc.split(" ")
abc = [int(x) for x in abc]
a = abc[0]
b = abc[1]
c = abc[2]


ac = c - a
total = 0
if ac < 0:
  total += c
  total += b
else:
  count = 0
  total += a
  if ac > b :
    total += b *2 + 1
  else :
    total += ac + b
print(total)

Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int main(void) {
  int n;
  cin >> n;
  cout << n * n;
  return 0;
}

Measured memory_bytes: 256
import math
foods = [int(input()) for _ in range(5)]
def hoge(value):
    return 9 if value % 10 == 0 else value % 10

last = min([(i, f) for i, f in enumerate(foods)], key=lambda i: hoge(i[1]))
time = 0
for food in foods[:last[0]] + foods[last[0]+1:]:
    time += math.ceil(food / 10) * 10
print(time+last[1])


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main(){
    int N;
    cin>>N;
    ll power=1,mod=pow(10,9)+7;
    for(int i=1;i<=N;i++){
        power=power*i%mod;
    }
    cout<<power<<endl;
 }

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

int main() {

  string input;
  int ans = 0;
  int cnt = 0;

  while( getline( cin, input ) ) {
    ans += cnt;
    cnt = 0;
    for ( int i = 0; i < input.size(); i++ ) {
      if ( input[i] >= '0' && input[i] <= '9' ) {
	cnt = cnt*10 + input[i] - '0';
      }else {
	ans += cnt;
	cnt = 0;
      }
    }
  }

  ans += cnt;

  cout << ans << endl;

  return 0;

}

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

int main() {
 int A,B = 0;
 cin >> A >> B;

 int res = 0;

 if(A < 10 && B < 10) {
	res = A * B;
 } else {
	res = -1;
 } 

 cout << res << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int N, R;
  cin >> N >> R;
  if(N >= 10) {
    cout << R << endl;
    return 0;
  } else {
    cout << R + 100 * (10 - N) << endl;
  }
  return 0;
}

Measured memory_bytes: 3612
# -*- coding: utf-8 -*-
import math

def main():
    """Function."""
    n = int(input())

    vals = []
    for i in range(100):
        base = (i * 2) + 1

        counter = 0
        max_num = int(math.sqrt(base))
        for j in range(1, max_num+1):
            if base % j == 0:
                counter += 2

        if counter == 8:
            vals.append(base)

    counter = 0
    for dum in vals:
        if dum <= n:
            counter += 1

    print(counter)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include<unordered_map>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = 998244353;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        ll n;
        cin >> n;
        ll a, b, c;
        cin >> a >> b >> c;
        ll dp[n][3];
        dp[0][0] = a;
        dp[0][1] = b;
        dp[0][2] = c;
        for(int i = 1; i < n; i++){
            cin >> a >> b >> c;
            dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2]);
            dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2]);
            dp[i][2] = c + max(dp[i - 1][0], dp[i - 1][1]);
        }
        cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl;
    }
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <map>
using namespace std;
typedef long long ll;
#define GG puts("FUCK")
#define N 500050
#define mr(x,y) make_pair(x,y)
inline char nc() {
	static char buf[100000],*p1,*p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
int rd() {
	int x=0; char s=nc();
	while(s<'0'||s>'9') s=nc();
	while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+s-'0',s=nc();
	return x;
}
char rc() {
	char s=nc();
	while(s!='+'&&s!='-'&&s!='>'&&s!='<') s=nc();
	return s;
}
int mod1=998244353,base1=19260817,inv1;
int mod2=353448299,base2=20000003,inv2;
int h1[N],mi1[N],imi1[N],p[N],n,C;
int h2[N],mi2[N],imi2[N];
map<pair<int,int>,int>mp;
int qp(int x,int y,int p) {
	int re=1;
	for(;y;y>>=1,x=ll(x)*x%p) if(y&1) re=ll(re)*x%p;
	return re;
}
int main() {
	inv1=qp(base1,mod1-2,mod1);
	inv2=qp(base2,mod2-2,mod2);
	n=rd(); char str;
	int i;
	for(mi1[0]=imi1[0]=mi2[0]=imi2[0]=i=1;i<=(n<<1);i++) {
		mi1[i]=ll(mi1[i-1])*base1%mod1;
		imi1[i]=ll(imi1[i-1])*inv1%mod1;
		mi2[i]=ll(mi2[i-1])*base2%mod2;
		imi2[i]=ll(imi2[i-1])*inv2%mod2;
	}
	p[0]=n;
	for(i=1;i<=n;i++) {
		str=rc();
		if(str=='+') {
			p[i]=p[i-1];
			h1[i]=(h1[i-1]+mi1[p[i]])%mod1;
			h2[i]=(h2[i-1]+mi2[p[i]])%mod2;
		}else if(str=='-') {
			p[i]=p[i-1];
			h1[i]=(h1[i-1]-mi1[p[i]]+mod1)%mod1;
			h2[i]=(h2[i-1]-mi2[p[i]]+mod2)%mod2;
		}else if(str=='>') {
			p[i]=p[i-1]+1;
			h1[i]=h1[i-1]; h2[i]=h2[i-1];
		}else {
			p[i]=p[i-1]-1;
			h1[i]=h1[i-1]; h2[i]=h2[i-1];
		}
		mp[mr(h1[i],h2[i])]++;
	}
	ll ans=0;
	for(i=1;i<=n;i++) {
		int d=p[i-1]-n,t1=h1[n],t2=h2[n];
		if(d>=0) t1=ll(t1)*mi1[d]%mod1,t2=ll(t2)*mi2[d]%mod2;
		else t1=ll(t1)*imi1[-d]%mod1,t2=ll(t2)*imi2[-d]%mod2;
		t1=(t1+h1[i-1])%mod1;
		t2=(t2+h2[i-1])%mod2;
		ans+=mp[mr(t1,t2)];
		mp[mr(h1[i],h2[i])]--;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 44288
import itertools

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

connection = []

for i in range(M):
    input_list = list(map(int,input().split()))
    connection.append(input_list[1:])

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

A = [0,1]
all_pt = list(itertools.product(A,repeat=N))

all_cnt = 0


for pt in all_pt:
    for con, on_pt in zip(connection, light_on):
         # 1個ずつ精査
        OK = False
        ON = 0
        for t in con:
            if pt[t-1] == 1:
                ON = ON + 1
        if ON % 2 != on_pt:
            break
        OK = True
    if OK:
        all_cnt += 1

print(all_cnt)


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

#define debug(a) cerr << #a << " = " << (a) << endl; 
#define get(t, i) get<(i)>((t))
#define fst first
#define snd second

template<typename T> ostream& operator<<(ostream& o, const vector<T>& v) {
  int b = 0; for (const auto& a : v) o << (b++ ? " " : "") << a; return o;
}

template<typename T, typename U> ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << p.fst << ' ' << p.snd; return o;
}

int n;
int A[101010][3];
int dp[2][3];

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

  for (int i = 0; i < n; i++)
    cin >> A[i][0] >> A[i][1] >> A[i][2];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      dp[i%2][j] = max(dp[i%2][j], dp[(i+1)%2][(j+1)%3] + A[i][(j+1)%3]);
      dp[i%2][j] = max(dp[i%2][j], dp[(i+1)%2][(j+2)%3] + A[i][(j+2)%3]);
    }
  }

  int ans = dp[(n-1)%2][0];
  ans = max(dp[(n-1)%2][1], dp[(n-1)%2][2]);
  cout << ans << endl;
}



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

#define pb       push_back
#define all(a)   a.begin(), a.end()
#define mp       make_pair
#define ll	long long

using namespace std;
string s;

int main(){
	cin >> s;
  int sum=0;
  for(char c : s){
    if(c == '+') sum++;
    else sum--;
  }
  cout << sum << endl;
	return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *Node;

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL)
    {
      y=x;
      if(z->key<x->key) x=x->left;
      else x=x->right;
    }
  z->parent=y;
  if(y==NIL) root=z;
  else
    {
      if(z->key < y->key) y->left=z;
      else y->right=z;
    }
}

void inorder(struct node *t)
{
  if(t==NIL)return;
  inorder(t->left);
  printf(" %d",t->key);
  inorder(t->right);
}

void preorder(struct node *t)
{
  if(t==NIL)return;
  printf(" %d",t->key);
  preorder(t->left);
  preorder(t->right);
}

int main()
{
  int i,count,number;
  char order[10];

  scanf("%d",&count);
  for(i=0;i<count;i++)
    {
      scanf("%s",order);
      if(strcmp(order,"insert")==0)
	{
	  scanf("%d",&number);
	  insert(number);
	}
      else if(strcmp(order,"print")==0)
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
    }
  return 0;
}

Measured memory_bytes: 24036
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, ans;
	cin >> n;
	vector<int> a(n);
	for (i = 0; i < n; i++) cin >> a[i];
	ans = 0;
	for (i = 0; i < n; i++) {
		for (j = i; (j < n) && (a[i] == a[j]); j++);
		ans += (j - i) / 2;
		i = j - 1;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  int i,j;
  for(i=0;i<n;i++) cin >> w[i];
  int min = 10000;
  for(i=0;i<n-1;i++){
    int s1=0;
    int s2=0;
    for(j=0;j<=i;j++) s1 += w[j];
    for(j=i+1;j<n;j++) s2 += w[j];
    if(min>abs(s1-s2)) min = abs(s1-s2);
  }
  cout << min << "\n";
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

const int N = 1e5;

int n;
int a[N << 1 | 1], b[N << 1 | 1];

bool check(int t);

int main() {
	// freopen("contest.in", "r", stdin);
	// freopen("contest.out", "w", stdout);
	scanf("%d", &n);
	for (int i = 1; i <= 2 * n - 1; ++i) scanf("%d", &a[i]);
	int l = 1, r = 2 * n - 1;
	while (l < r) {
		int mid = (l + r) >> 1;
		if (!check(mid)) l = mid + 1;
		else r = mid;
	}
	printf("%d\n", l);
	return 0;
}

bool check(int t) {
	for (int i = 1; i <= 2 * n - 1; ++i) b[i] = a[i] <= t;
	for (int i = 0; i < n; ++i) {
		if (b[n - i] == b[n - i - 1]) return b[n - i];
		if (b[n + i] == b[n + i + 1]) return b[n + i];
	}
	return b[1];
}


Measured memory_bytes: 1664
import java.text.DecimalFormat;
import java.util.*;

public class Main {
    static int n = 0;
    static Set<Integer>[] paths = null;
    static int m = 0;
    static int[] a = null;
    static int[] b = null;
    static int[] depths = null;
    static int[] parents = null;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        paths = new Set[n+1];
        for(int i=1; i<=n; i++) {
            paths[i] = new HashSet<>();
        }
        m = in.nextInt();
        a = new int[m];
        b = new int[m];
        for(int i=0; i<m; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
            paths[a[i]].add(b[i]);
            paths[b[i]].add(a[i]);
        }
        
        depths = new int[n+1];
        parents = new int[n+1];
        Queue<Integer> bfsQueue = new LinkedList<>();
        bfsQueue.add(1);
        boolean[] queued = new boolean[n+1];
        for(int i=0; i<=n; i++) {
            queued[i] = false;
        }
        queued[1] = true;
        while(bfsQueue.size()>0) {
            int target = bfsQueue.poll();
            int depth = depths[target];
            Iterator<Integer> childrenIT = paths[target].iterator();
            while(childrenIT.hasNext()) {
                int child = childrenIT.next();
                if(depths[child]>0 && depths[child]<=depth) {
                    continue;
                }
                if(queued[child]) {
                    continue;
                }
                depths[child] = depth+1;
                parents[child] = target;
                bfsQueue.add(child);
                queued[child] = true;
            }
            
        }
        
        System.out.println("Yes");
        for(int i=2; i<=n; i++) {
            System.out.println(parents[i]);
        }
    }
}


Measured memory_bytes: 101840
from collections import deque
n,m=map(int,input().split())
a=[tuple(map(int,input().split())) for i in range(m)]
pr=[[] for i in range(n)]
for i in a:
    pr[max(i)-1].append(min(i))
    pr[min(i)-1].append(max(i))
d=deque([1])
checked=[0]*n
checked[0]=1
ans=[0]*(n-1)
while len(d)>0:
    rm=d.popleft()
    for i in pr[rm-1]:
        if checked[i-1]==0:
            d.append(i)
            checked[i-1]=1
            ans[i-2]=rm
    #print(d)
print('Yes')
for i in ans:
    print(i)

Measured memory_bytes: 123244
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
using namespace std;
int main() {
	long long int n, a[100000], k = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 1) {
			k++;
		}
	}
	if (k % 2 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> RL(N);
    for(int i=0; i<N; i++){
        int x, l;
        cin >> x >> l;
        RL[i] = {x+l, x-l};
    }
    sort(RL.begin(), RL.end());

    int ans = 0;
    int R = -2e9;
    for(auto& p : RL){
        int r = p.first, l = p.second;
        if(R <= l){
            R = r;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=305;
int n,m,l,r,mid,ans,a[N][N],now[N],cnt[N];
bool use[N];
bool check(){
	for(int i=1;i<=n;i++){
		now[i]=1;
	}
	for(int i=1;i<=m;i++){
		use[i]=false;
	}
	while(1){
		for(int i=1;i<=m;i++){
			cnt[i]=0;
		}
		for(int i=1;i<=n;i++){
			cnt[a[i][now[i]]]++;
		}
		int maxn=-1,maxw;
		for(int i=1;i<=m;i++){
			if(!use[i]&&cnt[i]>maxn){
				maxn=cnt[i];
				maxw=i;
			}
		}
		if(maxn>mid){
			use[maxw]=true;
			for(int i=1;i<=n;i++){
				if(a[i][now[i]]==maxw){
					now[i]++;
					while(now[i]<=m&&use[a[i][now[i]]]){
						now[i]++;
					}
					if(now[i]>m){
						return false;
					}
				}
			}
		}else{
			break;
		}
	}
	return true;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	l=1,r=n;
	while(l<=r){
		mid=(l+r)/2;
		if(check()){
			ans=mid;
			r=mid-1;
		}else{
			l=mid+1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) {
		cin>>s;
		cout<<s<<endl;
		cout<<s<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int x,a,b;
int l;
int donut;
int main()
{
    scanf("%d%d%d",&x,&a,&b);
    l=x-a;
    donut=l/b;
    l=l-donut*b;
    printf("%d",l);
    
    
    
    return 0;
    }


Measured memory_bytes: 256