akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;


signed _main(){
  int N; cin >> N;
  unordered_map<int,int> mp;
  int ans=1;
  rep(i,N){
    int A; cin >> A;
    mp[A]++;
    if(A==0){
      ans=(ans*(4LL-mp[A]))%MOD;
    }
    else{
      ans=(ans*(mp[A-1]-mp[A]+1LL))%MOD;
    }
  }
  cout << ans%MOD << endl;
}


Measured memory_bytes: 4388
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main()
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	double a = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
	printf("%lf\n", a);
    return 0;
}




Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
int n;
double a[111];
double ans=0;
int main()
{
	cin >>n;
	for(int i=0;i<n;i++)
	{
		cin >>a[i];
		ans+=(1/a[i]);
	}
	ans=1/ans;
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
ans = 0
l = len(s)-1
for i in range(2**(len(s)-1)):
    bs = ("{0:0>"+str(l)+"b}").format(i)
    s1 = 0
    temp = s[:]
    j = 0
    for b in bs:
        j+=1
        if b == '1':
            s1 += int(temp[:j])
            temp = temp[j:]
            j = 0
    s1 += int(temp)
    ans += s1
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll calc(char c) {
    if(c == 'r') {
        return 0;
    }
    if(c == 's') {
        return 1;
    }
    if(c == 'p') {
        return 2;
    }
}

int main() {
    ll n, k;
    cin >> n >> k;

    vl rsp(3);
    rep(i, 3) {
        cin >> rsp[i];
    }

    string t;
    cin >> t;

    vvl dp(n+1, vl(3));  // dp[i][j] : i回目(iは0-index)に自分がj('r' = 0, 's' = 1, 'p' = 2)を出すとき i mod.k の手番についての得点の総和の最大値
    rep(i, n) {
        rep(j, 3) {
            if(i >= k) {
                rep(x, 3) {
                    if(j != x) {
                        chmax(dp[i][j], dp[i-k][x]);
                    }
                }
            }
            if((j+1)%3 == calc(t[i])) {
                dp[i][j] += rsp[j];
            }
        }
    }

    ll ans = 0;
    exrep(i, n-k, n-1) {
        ll now = 0;
        rep(j, 3) {
            chmax(now, dp[i][j]);
        }
        ans += now;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int A, B, K;

	vector<int> ans;

	cin >> A >> B >> K;

	for(int i = 1; i <= A; i++){
		if( A % i == 0 && B % i == 0) ans.push_back(i);
	}

	sort(ans.begin(), ans.end());
	reverse(ans.begin(), ans.end());

	cout << ans[K-1] << endl;

	return 0;
}


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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define pqll priority_queue<ll>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) ll a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define qll queue<ll>
#define sll set<ll>
#define inf LLONG_MAX


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

	ll n,i;
	cin>>n;
	ll a[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	ll ans=a[0],cnt=1;
	for(i=1;i<n;i++)
	{
		if(cnt==n-1)
			break;
		ans+=a[i];
		++cnt;
		if(cnt==n-1)
			break;
		ans+=a[i];
		++cnt;
		if(cnt==n-1)
			break;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5184
from math import sqrt

def is_prime(n):
  if n == 1:
    return False
  for i in range(2, int(sqrt(n))+1):
    if n % i == 0:
      return False
  return True

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(sqrt(n))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
        if len(arr) > 1:
          break

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

base=int(input())
tmp=base
num=[]
if is_prime(base):
  num.append(base)
else:
  for i in range(2, base+1):
    if i > tmp:
      break
    if tmp % i == 0 and len(factorization(i)) == 1:
      num.append(i)
      tmp/=i
      if is_prime(tmp):
        num.append(tmp)
        break
print(len(list(set(num))))

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

int main () {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  cout << a[0] + 10 * a[2] + a[1] << endl;
}

Measured memory_bytes: 256
N=int(input())
L = list(map(int, input().split()))
count=0
for i in range(0,N-2):
    for j in range(i,N-1):
        if L[i]!=L[j]:
            for k in range(j,N):
                if L[j]!=L[k] and L[k]!=L[i] and L[i]<L[j]+L[k] and L[j]<L[k]+L[i] and L[k]<L[i]+L[j]:
                    count=count+1
print(count)


Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 55
int n;
int a[MN];
int b[MN];

vector<int> good;
bool vis[MN];

void dfs(int cur, int mx){
    if(vis[cur] == true) return;

    vis[cur] = true;
    for(auto u : good){
        if(cur >= u) dfs(cur%u, mx);
    }

    FOR(i, 1, mx){
        if(cur >= i) dfs(cur%i, mx);
    }
}
bool cm(int ind, int mx){ //check max
    memset(vis, false, sizeof vis);

    dfs(a[ind],  mx);
    if(vis[b[ind]]) return true;
    else return false;
}
int fm(int ind){ //find max
    int l = -1, r = 51;
    while(l+1 < r){
        int mid = (l+r)/2;

        if(cm(ind, mid)){
            r = mid;
        } else{
            l = mid;
        }
    }
    return r;
}
int gom(){ //get overall max
    int mx = 0;
    F0R(i, n){
        mx = max(mx, fm(i));
    }

    return mx;
}

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

    cin >> n;
    F0R(i, n){
        cin >> a[i];
    }
    F0R(i, n){
        cin >> b[i];
    }

    ll ans = 0;

    int cmx = gom();
    if(cmx == 51){
        cout << "-1\n";
        return 0;
    }
    while(cmx != 0){
        ans += (1LL<<cmx);

        good.pb(cmx);

        cmx = gom();
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define MOD 1000000007
#define ra 380000
using namespace std;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
int a,b,c;
  cin>>a>>b>>c;
  cout<<a * b / 2<<endl;
  
	return 0;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  int l[N];
  for(int i=0;i<N;i++){
    cin >> l[i];
  }
  int length=0;
  sort(l,l+N,greater<int>());
  for(int i=0;i<K;i++){
    length +=l[i];
  }
  cout << length << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string S;
    cin >> S;
    bool MMYY = false;
    bool YYMM = false;
    int a = stoi(S.substr(0, 2));
    int b = stoi(S.substr(2, 2));
    if(a && a <= 12) MMYY = true;
    if(b && b <= 12) YYMM = true;
    if(MMYY && YYMM) cout << "AMBIGUOUS";
    else if(MMYY) cout << "MMYY";
    else if(YYMM) cout << "YYMM";
    else cout << "NA";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int n;
	cin >> n;
	std::vector<pair<pair<string,int>, int>> v;

	int num = 0;
	for (int i = 0; i < n; ++i)
	{
		string s;
		int p;
		cin >> s >> p;
		num++;

		v.push_back(make_pair(make_pair(s, -1 * p), num));
	}

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

	for (int i = 0; i < n; ++i)
	{
		cout << v[i].second << endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int N = 2e5 + 87;
ll n, k, a[N];
ll c0, cn, cp;
ll solvene()
{
  vector<ll> x(a, a + cn);
  vector<ll> y(a + n - cp, a + n);
  ll lo = x[0] * y.back();
  ll hi = x.back() * y[0];
  //cerr << "lo hi "<< lo << ' '<< hi << endl;
  reverse(x.begin(), x.end());
  reverse(y.begin(), y.end());
  //cerr << "x= "; for (ll t : x) cerr << t << ' '; cerr << endl;
  //cerr << "y= "; for (ll t : y) cerr << t << ' '; cerr << endl;
  while (lo <= hi) {
    ll mi = lo + (hi - lo) / 2;
    ll c = 0;
    for (ll i = 0, j = 0; i < x.size(); ++i) {
      for (; j < y.size() && x[i] * y[j] <= mi; ++j);
      //cerr << "i,j,x[i] " << i << ' ' << j << ' ' << x[i]<< endl;
      c += j;
    }
    //cerr << "mi, c "<< mi << ' ' << c << endl;
    if (c < k)
      lo = mi + 1;
    else
      hi = mi - 1;
  }
  return lo;
}
ll solvenp(ll k)
{
  vector<ll> x(a, a + cn);
  reverse(x.begin(), x.end());
  vector<ll> y(a + n - cp, a + n);
  ll lo = LLONG_MAX;
  ll hi = LLONG_MIN;
  if (x.size() >= 2) {
    lo = min(lo, x[0] * x[1]);
    hi = max(hi, x[cn - 1] * x[cn - 2]);
  }
  if (y.size() >= 2) {
    lo = min(lo, y[0] * y[1]);
    hi = max(hi, y[cp - 1] * y[cp - 2]);
  }
  while (lo <= hi) {
    ll mi = lo + (hi - lo) / 2;
    ll c = 0;
    for (ll i = cp - 1, j = 0; i >= 0; --i) {
      for (; j < i && y[i] * y[j] <= mi; ++j);
      c += min(j, i);
    }
    for (ll i = cn - 1, j = 0; i >= 0; --i) {
      for (; j < i && x[i] * x[j] <= mi; ++j);
      c += min(j, i);
    }
    //cerr << "mi, c " << mi << ' ' << c << endl;
    if (c < k)
      lo = mi + 1;
    else
      hi = mi - 1;
  }
  return lo;
}
int main()
{
  ios::sync_with_stdio(0);

  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  //freopen("error.txt", "w", stderr);
  freopen("output1.txt", "w", stdout);
#endif
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0)
      ++c0;
    else if (a[i] > 0)
      ++cp;
    else
      ++cn;
  }
  sort(a, a + n);
  ll ne = cn * cp;
  ll n0 = c0 * (c0 - 1) / 2 + c0 * (n - c0);
  ll np = cp * (cp - 1) / 2 + cn * (cn - 1) / 2;
  ll ans;
  if (k <= ne) {
    ans = solvene();
  } else if (k <= ne + n0) {
    ans = 0;
  } else {
    ans = solvenp(k - ne - n0);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 6064
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int x, a, b;
    scan(x, a, b);
    if (b - a <= 0) {
        writeln("delicious");
    }
    else if (b - a <= x) {
        writeln("safe");
    }
    else {
        writeln("dangerous");
    }
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007

using namespace std;

string s[1000];

int main()
{
	IOS;
	int h, w;
	cin >> h >> w;

  	vector< vector<int> > ar(h, vector<int>(w, -1));
  	queue< pair<int, int> > que;
  	for (int i=0; i<h; i++) {
      	for (int j=0; j<w; j++) {
          	char ch;
            cin >> ch;
            if (ch == '#') {
		        que.push(make_pair(i, j));
              	ar[i][j] = 0;
            }
        }
    }

  	int max = 0;
    while(!que.empty()){
		int i = que.front().first;
      	int j = que.front().second;
      	que.pop();
      	//printf("[%d,%d]: %d\n", i, j, ar[i][j]);

      	int dist = ar[i][j] + 1;
      	bool found = false;
      	if (0<=i-1 && ar[i-1][j]==-1) {
        	que.push(make_pair(i-1, j));
          	ar[i-1][j] = dist;
			found = true;
        }
      	if (i+1<h && ar[i+1][j]==-1) {
        	que.push(make_pair(i+1, j));
          	ar[i+1][j] = dist;
			found = true;
        }
      	if (0<=j-1 && ar[i][j-1]==-1) {
        	que.push(make_pair(i, j-1));
          	ar[i][j-1] = dist;
			found = true;
        }
      	if (j+1<w && ar[i][j+1]==-1) {
        	que.push(make_pair(i, j+1));
          	ar[i][j+1] = dist;
			found = true;
        }

      	if (found){
        	if (max < dist) {
            	max = dist;
            }
        }
    }

  	cout << max << endl;
	return 0;
}


Measured memory_bytes: 12432
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int x,y;
    cin>>x>>y;
    if(x==2 || y==2)
        cout<<"No\n";
    else
        cout<<"Yes\n";
    return 0;
}



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

long int mod=(pow(10,9))+7;

int main(){
	int h,w;
	cin>>h>>w;
	vector<vector<char> > g(h,vector<char>(w));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>g[i][j];
		}
	}
	vector<vector<long int> > dp(h+1,vector<long int>(w+1,0));
	dp[1][1]=1;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(i==1 &&j==1)continue;
			if(g[i-1][j-1]=='.'){
				dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod;
			}
		}
	}
	cout<<dp[h][w]<<endl;
	return 0;
}

Measured memory_bytes: 9088
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int X = sc.nextInt();
    int[]A = new int[M];
 
    int dai = 0;
    int syou = 0;
    for(int i=0; i<M; i++){
        A[i] = sc.nextInt();
        if(A[i] > X) {
        	dai++;
        }else if(A[i] < X){
        	syou++;
    }
}
       if(dai>syou) {
        	System.out.println(syou);
        }else {
        	System.out.println(dai);
    }
}
}

Measured memory_bytes: 35960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
string s;
cin >> s;
bool ans = false;
for(int i=1;i<s.size();i++){
    if(s.at(i-1)=='A'&&s.at(i)=='C')ans =true;
}
if(ans)cout<<"Yes"<<endl;
else cout <<"No"<<endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var x, y int
	fmt.Scanf("%d %d", &x, &y)

	for kameNum := 0; kameNum <= x; kameNum++ {
		if y == tsuruKame(kameNum, x) {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

func tsuruKame(kameNum, tsurukameNum int) int {
	return kameNum*4 + (tsurukameNum-kameNum)*2
}


Measured memory_bytes: 1816
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int A[1010][1010];
int process[1010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    
    rep(i, N) {
        rep(j, N - 1) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }
    int ans = 0;
    int cnt = 0;
    set<int> st;
    rep(i, N) st.insert(i);
    while(true) {
        bool change = false;
        bool used[1010] = {};
        vector<int> v;
        for(auto itr = st.begin(); itr != st.end(); itr++) {
            int j = *itr;
            int p = A[j][process[j]];
            if(!used[j] && !used[p] && A[p][process[p]] == j) {
                //cerr << ans << " " << j << " " << p << endl;
                used[j] = true;
                used[p] = true;
                process[p]++;
                process[j]++; 
                if(process[p] < N - 1) v.push_back(p);
                if(process[j] < N - 1) v.push_back(j);
                cnt++;
                change = true;
            }
        }
        st.clear();
        for(auto e: v) st.insert(e);
        if(!change) break;
        ans++;
    }
    if(cnt != N * (N - 1) / 2) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n=0,m=0;
    cin>>n>>m;
    vector<int> a(n,0);
    vector<int> b(n,0);
    
    int k=0, sum_a=0, sum_w=0;
    string s ="";
    
    for(int i=0; i<m; i++){
        cin>>k>>s;
        if(s == "AC"){
            if(b[k-1] == 0)
            b[k-1] = 1;
        }
        else if(b[k-1] == 0)
            a[k-1]++;
    }
    
    for(int i=0; i<n; i++){
        if(b[i]==1){
            sum_a+=1;
            sum_w+=a[i];
        }
    }
    
    cout<<sum_a<<" "<<sum_w<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
 
int run_test(){
      int n;
      cin >> n;
      if(n == 1){
            ll p;
            cin >> p;
            cout << 0;
            return 0;
      }
      ll arr[n];
      for(int  i =0; i < n; i++){
            cin >> arr[i];
      }       
      int count = 2;
      sort(arr, arr + n);
      ll sum = arr[n-1];
      if(count == n){
            cout << sum;
            return 0;
      }
      for(int i = n-2; i >= 0; i--){
            sum += arr[i];
            count++;
            if(count == n) break;
            sum += arr[i];
            count++;
            if(count == n) break;
      } 
      cout << sum;
      return 0;
}
 
int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 5176
import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.next().toLong()
    println(problem56c(x))
}

fun problem56c(x: Long): Long {
    var time = 0L
    var currentX = 0L
    while(currentX < x) {
        time++
        currentX += time
    }
    return time
}

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

typedef long long int   ll;
#define cases           int t;cin>>t;while(t--)
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define scan(n)         scanf("%d",&n)
#define pb              push_back
#define vi              vector<int>
#define ii              pair<int,int>

using namespace std;

int main(){
    int n;cin>>n;
    int a,b;
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%n==0){
            cout<<"OK"<<endl;
            goto last;
        }
    }
    cout<<"NG"<<endl;
    last:;
}


Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


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

    int N;
    cin >> N;
    vector<int> A(N - 1), B(N);
    for(int i = 0; i < N - 1; i++){
        cin >> A[i];
        A[i] = A[i] - 1;
    }

    for(int i = 0; i < N - 1; i++){
        int boss = A[i];
        B[boss] = B[boss] + 1;
    }
    for(int i = 0; i < N; i++){
        cout << B[i] << endl;
    }
    return 0;

}


// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

namespace
{
	ll GCD(ll a, ll b)
	{
		return a == 0 ? b : GCD(b % a, a);
	}
}
void ABC162C()
{
	int K;
	cin >> K;
	ll sum = 0;
	for (int i = 1; i <= K; ++i)
	{
		for (int j = 1; j <= K; ++j)
		{
			ll x = GCD(i, j);
			for (int k = 1; k <= K; ++k)
			{
				sum += GCD(x, k);
			}
		}
	}
	cout << sum << endl;
}

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

Measured memory_bytes: 3636
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  cin>>N;
  string S[200000];
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  sort(S,S+N);
  int kind=1;
  string T=S[0];
  for(int i=1;i<N;i++){
    if(S[i].size()==T.size()){
     for(int j=0;j<T.size();j++){
       if(S[i][j]!=T[j]){
        T=S[i];
         kind++;
         j=j+100;
       }
     }
    }
    else{
      T=S[i];
      kind++;
    }
  }
  cout<<kind<<endl;
  return 0;
}

Measured memory_bytes: 9888
#include<cstdio>
#include<utility>
#include<queue>

struct P {int x,y;};

using namespace std;

char map[1005][1005];
int h,w,n;

int distance(char start, char goal) {
    bool visited[1005][1005];
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            visited[i][j] = false;


    queue<pair<P,int> > q;
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            if(map[i][j] == start) q.push(pair<P,int>({j,i}, 0));
    
    while(!q.empty()) {
        pair<P,int> t = q.front(); q.pop();
        struct P p = t.first;
        int d = t.second;

        if(p.x < 0 || p.y < 0 || p.x >= w || p.y >= h) continue;
        if(map[p.y][p.x] == 'X') continue;
        if(visited[p.y][p.x]) continue;
        if(map[p.y][p.x] == goal) return d;
        visited[p.y][p.x] = true;
        
        q.push(pair<P,int>({p.x+1,p.y},d+1));
        q.push(pair<P,int>({p.x,p.y+1},d+1));
        q.push(pair<P,int>({p.x-1,p.y},d+1));
        q.push(pair<P,int>({p.x,p.y-1},d+1));
    }
    return -1;
}


int main(void) {
    int res=0;

    scanf("%d%d%d",&h,&w,&n);
    for(int i=0;i<h;i++)
        scanf("%s",map[i]);
    res += distance('S','1');
    for(int i=1;i<n;i++)
        res += distance('0'+i,'1'+i);

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

    return 0;
}

Measured memory_bytes: 4644
#include<bits/stdc++.h>
using namespace std;
int a[6];
int main(){
	int k;
	for(int i=1;i<=5;i++)
		cin>>a[i];
	cin>>k;
	for(int i=1;i<=5;i++){
		for(int j=i;j<=5;j++){
			if(a[j]-a[i]>k){
				cout<<":(";
				return 0;	
			}
		} 
	} 
	cout<<"Yay!";
	return 0;
}

Measured memory_bytes: 256
import numpy as np

S = list(input())
l = len(S) + 1
A = [0] * l
B = [0] * l

for i in range(len(S)):
    if S[i] == '<':
        A[i+1] = A[i] + 1

for i in range(len(S)-1, -1, -1):
    if S[i] == '>':
        B[i] = B[i+1] + 1
answer = 0
for i in range(l):
    answer += max(A[i], B[i])
print(answer)


Measured memory_bytes: 40224
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100000+100;
int a[maxn];
int main()
{
    ios::sync_with_stdio(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    int minn = 0x3f3f3f3f;
    sort(a+1,a+1+n,greater<int>());
    for(int i=1;i<=n-k+1;i++)
    minn = min(minn,a[i]-a[i+k-1]);
    cout<<minn;
}


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

int main(){
    vector<int64_t> A(7);
    copy_n(istream_iterator<int64_t>(cin), 7, A.begin());
    int64_t I = A[0], O = A[1], J = A[3], L = A[4];

    int64_t ans = O * 2;
    int64_t mi = min({1L, I, L, J});
    ans += max(mi * 6 + (L - mi) / 2 * 4 + (J - mi) / 2 * 4 + (I - mi) / 2 * 4, L / 2 * 4 + J / 2 * 4 + I / 2 * 4);

    cout << ans / 2 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

const bool Check(const int a, const int b, const int c)
{
    std::vector<int> nums{ a, b, c };
    sort(nums.begin(), nums.end());
    return nums[1] == b;
}

int main()
{
    int N;
    cin >> N;
    vector<int> nums(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> nums[i];
    }
    int count = 0;
    for (int i = 1; i < N - 1; ++i)
    {
        if (Check(nums[i - 1], nums[i], nums[i + 1]))
        {
            ++count;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
import java.util.*;  
public class Main{    
      public static void main(String args[]){ 
      Scanner sc = new Scanner (System.in);
	int h = sc.nextInt();
	int b = sc.nextInt();
	int r=0;
	while(h>0)
	{
	    h=h-b;
	    r++;
	}
	System.out.println("" +r);
      }
  }
  

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		int a, b;
		String str;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		String[] line = str.split(" ");
		a = Integer.parseInt(line[0]);
		b = Integer.parseInt(line[1]);
		if (a == b) {
			System.out.println("a == b");
		} else if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		}


	}

}


Measured memory_bytes: 24240
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  
  vector<string> lines;
  for(int h = 0; h < H; h++){
    string str;
    cin >> str;
    bool ret = false;
    for(int i = 0; i < str.size(); i++){
      if(str.at(i)=='#'){
        ret = true; break;
      }
    }
    if(ret){lines.push_back(str);}
  }
  
  vector<bool> rets(W);
  for(int w = 0; w < W; w++){
    bool ret = false;
    for(int h = 0; h < lines.size(); h++){
    	if(lines.at(h).at(w) == '#'){
          ret = true; break;
        }
  	}
    rets.at(w) = ret;
  }
  
  
  for(int h = 0; h < lines.size(); h++){
    for(int w = 0; w < W; w++){
      if(rets.at(w)){
        cout << lines.at(h).at(w) ;
      }
    }
    cout << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>

using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X, A;
	cin >> X >> A;
	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}
}


Measured memory_bytes: 256
// #includes {{{
	#include<stdio.h>
	#include<stdlib.h>
	#include<string.h>
	#include<math.h>
	#include<assert.h>
	#include<stdarg.h>
	#include<time.h>
	#include<limits.h>
	#include<ctype.h>
	#include<string>
	#include<map>
	#include<set>
	#include<queue>
	#include<algorithm>
	#include<vector>
	#include<iostream>
	#include<sstream>
	using namespace std;
	// }}}
	// #defines {{{
	#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
	#define SZ(x) ((int)(x).size())
	#define ALL(x) (x).begin(),(x).end()
	#define REP(i,n) for(int i=0;i<(n);i++)
	#define REP1(i,a,b) for(int i=(a);i<=(b);i++)
	#define PER(i,n) for(int i=(n)-1;i>=0;i--)
	#define PER1(i,a,b) for(int i=(a);i>=(b);i--)
	#define RI(x) scanf("%d",&x)
	#define DRI(x) int x;RI(x)
	#define RII(x,y) scanf("%d%d",&x,&y)
	#define DRII(x,y) int x,y;RII(x,y)
	#define RIII(x,y,z) scanf("%d%d%d",&x,&y,&z)
	#define DRIII(x,y,z) int x,y,z;RIII(x,y,z)
	#define RS(x) scanf("%s",x)
	#define PI(x) printf("%d\n",x)
	#define PIS(x) printf("%d ",x)
	#define CASET int ___T,cas=1;scanf("%d",&___T);while(___T--)
	#define CASEN0(n) int cas=1;while(scanf("%d",&n)!=EOF&&n)
	#define CASEN(n) int cas=1;while(scanf("%d",&n)!=EOF)
	#define MP make_pair
	#define PB push_back

	#define MS0(x) memset(x,0,sizeof(x))
	#define MS1(x) memset(x,-1,sizeof(x))

	#define F first
	#define S second
	typedef pair<int,int> PII;
	typedef long long LL;
	typedef unsigned long long ULL;
	// }}}
string s;
int a[666];
main(){
	cin>>s;
	for(auto i:s){
		a[i]++;
	}
	LL ans=s.length();
	ans=1LL*ans*(ans-1)/2;
	for(int i='a';i<='z';i++)
		if (a[i]>1) ans-=1LL*a[i]*(a[i]-1)/2;
	cout<<ans+1<<endl;


}

Measured memory_bytes: 640
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1], T = ip[2];
	writeln((T / A * B));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
/// https://github.com/hatoo/competitive-rust-snippets
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules !get {([$t:ty]) => {{let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace().map(|t| t.parse::<$t>() .unwrap () ) .collect ::<Vec <_ >>() } } ;([$t :ty ] ;$n :expr ) =>{(0 ..$n ) .map (|_ |get !([$t ] ) ) .collect ::<Vec <_ >>() } ;($t :ty ) =>{{let mut line :String =String ::new () ;stdin () .read_line (&mut line ) .unwrap () ;line .trim () .parse ::<$t >() .unwrap () } } ;($($t :ty ) ,*) =>{{let mut line :String =String ::new () ;stdin () .read_line (&mut line ) .unwrap () ;let mut iter =line .split_whitespace () ;($(iter .next () .unwrap () .parse ::<$t >() .unwrap () ,) *) } } ;($t :ty ;$n :expr ) =>{(0 ..$n ) .map (|_ |get !($t ) ) .collect ::<Vec <_ >>() } ;($($t :ty ) ,*;$n :expr ) =>{(0 ..$n ) .map (|_ |get !($($t ) ,*) ) .collect ::<Vec <_ >>() } ;}
#[allow(unused_macros)]
macro_rules !debug {($($a :expr ) ,*) =>{eprintln !(concat !($(stringify !($a ) ," = {:?}, " ) ,*) ,$($a ) ,*) ;} }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let (a, b) = get!(u32, u32);
    println!("{}", a*b);
}

Measured memory_bytes: 2248
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		int n,i;
		cin>>n;
		VI64 v(n);
		map<int64,int64> mp;
		for(i=0;i<n;i++)
		{
			cin>>v[i];
			mp[v[i]]++;
		}
		int ans=0;
		for(auto x:mp)
		{
			ans+=x.S*(x.S-1);
		}
		//cout<<"ans "<<ans<<endl;
		for(i=0;i<n;i++)
		{
			int f=mp[v[i]];
			int temans=ans-f*(f-1);
			f--;
			temans+=f*(f-1);
			cout<<temans/2<<endl;

		}
	}

	return 0;
}

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

int main(){
  int n;
  cin >>n;
  vector<int> b(n-1);
  rep(i,n-1) cin >>b[i];
  vector<int> a(n);
  a[0] = b[0];
  a[n-1] = b[n-2];
  int sum = a[0]+a[n-1];
  for(int i = 1; i<n-1; i++){
    a[i] = min(b[i-1], b[i]);
    sum += a[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        1000005
#define mod         1000000007  
#define pi          3.1415926535897932384626433
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll sum=0;
    for(auto x:s){
        sum+=(x-'0');
    }
    if(sum%9){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}

Measured memory_bytes: 3768
import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
b = np.array(a)
a += np.arange(n)+1
b -= np.arange(n)+1
b *= -1
a = np.sort(a)
b = np.sort(b)
c = 0
for i in a:
    l = np.searchsorted(b,i,side="left")
    r = np.searchsorted(b,i,side="right")
    c += r-l

print(c)

Measured memory_bytes: 51060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n, cnt = 0;
    cin >> n;
    rep(i, n){
        int x;
        cin >> x;
        if(x % 2 == 1)
            cnt++;
    }
    if(cnt % 2 == 1) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 384
// D-Insertion
// https://atcoder.jp/contests/abc064/tasks/abc064_d?lang=en

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MAX 100 + 4
int n;
char s[MAX];     

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

  int a=0; // the extra number of "("
  int b=0; // the extra number of ")"
  for (int i=0; i<n; i++) {
    if (s[i] == '(') {
      a++;
      continue;
    }            
    if (s[i] == ')' && a > 0) {
      a--;
      continue;  
    }
    // case ")"
    b++;
  }  
                 
  string ans = "";
  for (int i=0; i<b; i++)
    ans += "(";  
  ans += s;
  for (int i=0; i<a; i++)
    ans += ")";
  cout << ans << "\n";
}                


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

vector<int> e[MAX_N];

signed main() {
  INIT;
	VAR(int,n,q);
  vector<int> a(n-1), b(n-1);
  vector<int> h(n,0);
  REP(i,n-1){
    cin>>a[i]>>b[i];
    --a[i]; --b[i];
    e[a[i]].push_back(b[i]);
    e[b[i]].push_back(a[i]);
  }
 
  vector<int> weight(n,0);
  while(q--){
    VAR(int,p,x);
    --p;
    weight[p] += x;
  }

  vector<int> ans(n,0);
  vector<bool> used(n, false);

  stack<int> st;
  st.push(0);
  used[0] = true;

  while(!st.empty()){
    int frm = st.top(); st.pop();
    ans[frm] += weight[frm];
    used[frm] = true;

    EACH(nxt, e[frm]){
      if (used[nxt]) continue;
      weight[nxt] += weight[frm];
      st.push(nxt);
    }
  }
  
  OUT(weight[0]);
  REP(i,n-1){
    SP;
    OUT(weight[i+1]);
  }
  BR;
  
  return 0;
}


Measured memory_bytes: 26608
n = gets.chomp.split.map(&:to_i)
d = gets.chomp.to_s

d.chars{ |i|
  if i == "S"
    n[0],n[1],n[4],n[5] = n[4],n[0],n[5],n[1]
  elsif i == "E"
    n[0],n[2],n[3],n[5] = n[3],n[0],n[5],n[2]
  elsif i == "W"
    n[0],n[2],n[3],n[5] = n[2],n[5],n[0],n[3]
  else
    n[0],n[1],n[4],n[5] = n[1],n[5],n[0],n[4]
  end
}
puts n[0]

Measured memory_bytes: 8680
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int N;
  cin >> N;
  int A[N];
  rep(i, N) cin >> A[i];
  int bit[64] = {};
  for(int i=0;i<N;i++){
    int mo = 2;
    for(int j=0;j<63;j++){
      if(A[i] % mo != 0){
        bit[j]++;
        A[i] -= mo/2;
        if(A[i] == 0) break;
      }
      mo *= 2;
    }
  }
  int kai = 1;
  int ans = 0;
  for(int i=0;i<63;i++){
    kai %= MOD;
    int M = bit[i] * (N - bit[i]);
    M %= MOD;
    ans += kai * M;
    ans %= MOD;
    kai *= 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <math.h>
 
int main(void)
{
  long int i, j, n, sum = 0;
  
  scanf("%ld", &n);
  
  for( i = 1; i < n+1; i++ ){
    if( i % 3 != 0 && i % 5 != 0 ){
      sum += i;
    }    
  }
 
  printf("%ld\n", sum);
  return 0;
}

Measured memory_bytes: 1728
(N,M,K),A,B = $<.map{|ln| ln.split.map(&:to_i) }
A << K+1
B << K+1

a,b,k = 0,0,K
(k-=A[a]; a+=1) while A[a]<=k
(k-=B[b]; b+=1) while B[b]<=k
nmax = a+b
while 0<a
	(a-=1; k+=A[a]) while 0<a && k<B[b]
	(k-=B[b]; b+=1) while B[b]<=k
	nmax = a+b if nmax<a+b
end
p nmax


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

public class Main {
	public static void main(String[] args) throws IOException {

		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String[] d1 = r.readLine().split(" ");
		String[] d2 = r.readLine().split(" ");

		if(d1[0].equals(d2[0])) {
			System.out.println("0");
		} else {
			System.out.println("1");
		}

		r.close();
	}
}

Measured memory_bytes: 21072
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,sum;
    char odd[100],even[100],pass[200];
    gets(odd);
    gets(even);
    sum=strlen(odd)+strlen(even);
    for(i=0;i<sum;i++)
    {
        if(i%2==0)
            pass[i]=odd[i/2];
        else
            pass[i]=even[(i-1)/2];
    }
    pass[i]='\0';
    puts(pass);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {
	    final int N = stdin.nextInt();
	    final int M = stdin.nextInt();
	    if ( N == 0 && M == 0 ){
		break;
	    }
	    
	    int[] map = new int[N + 1];
	    for ( int i = 1; i <= N; i++ ) {
		map[i] = stdin.nextInt();
	    }
	    
	    int[] dices = new int[M + 1];
	    for ( int i = 1; i <= M; i++ ) {
		dices[i] = stdin.nextInt();
	    }
	    
	    int p = 1;
	    for ( int i = 1; i <= M; i++ ) {
		final int dice = dices[i];
		p += dice;
		if ( p >= N ) {
		    System.out.println( i );
		    break;
		}
		p += map[p];
		if ( p >= N ) {
		    System.out.println( i );
		    break;
		}
	    }
	}
    }    
}

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

int main()
{
	int n;
	while( cin >> n && n != -1 ){
		int exp = 1;
		string d;
		while( n > 0 ){
			int m = n % ( 1 << ( 2 * exp ) );
			m /= ( 1 << ( 2 * ( exp - 1 ) ) );
			d.insert( d.begin(), ( m + '0') );
			n -= ( m * ( 1 << ( 2 * ( exp - 1 ) ) ) );
			++exp;
		}
		if( d.empty() ){
			d = '0';
		}
		cout << d << endl;
	}

	return 0;
}

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

int main(){
    string S;
    cin >> S;
    long long ans=0LL; // long long(でかい整数)は0LLで初期化

    for(int i=0; i<(1<<S.size()-1); ++i){ // bit全探索
        string tmp = "";
        tmp += S[0];

        for(int j=0; j<S.size()-1; ++j){ // jはiと同じだけ回す
        // 例えばbitset<4>に対しi=3を表示するなら0011になるが、これはj=1,3の時に引っかかりif内の処理が行われる
            if((i & (1<<j)) != 0){
                tmp += "+";
                tmp += S[j+1];
            }else{
                tmp += S[j+1];
            }
        }

        long long ad = 0;
        for(int j=0; j<tmp.size(); ++j){
            if(tmp[j] == '+'){
                ans += ad;
                ad = 0;
            }else{
                ad = 10*ad + (tmp[j] - '0'); // - '0'でsting型をint型に変換
                if(j == tmp.size()-1) ans += ad; // 最後まできたら足す(12+13なら3に引っかかったところで13が足される)
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
using System;

namespace AOJ
{
    class Program
    {
        static void Main()
        {
            string[] line = Console.ReadLine().Split(' ');
            int x = int.Parse(line[0]);
            int y = int.Parse(line[1]);

            string output =
                (x > y) ? "a > b" :
                (x < y) ? "a < b" :
                (x == y) ? "a == b" : null;

            Console.WriteLine(output);
        }
    }
}

Measured memory_bytes: 5292
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5+3;
int n;
int s1,s2,s4;

int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        int t;
        scanf("%d",&t);
        if (t%4==0) s4++;
        else if (t%2==0) s2++;
        else s1++;
    }
    if (s1>s4+(s2==0)) puts("No");
    else puts("Yes");
    return 0;
}

Measured memory_bytes: 256