akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    // 入力
    int N;
    cin >> N;
    vector<int64_t> D(N); // 与えられる整数列
    vector<int64_t> cnt(N, 0); // 各距離の個数をカウント
    for(int i = 0; i < N; i++)
    {
        int t;
        cin >> t;
        D[i] = t;
        cnt[t]++;
    }

    // 頂点1から頂点1までの距離が0だったらダメ
    if(D[0] != 0)
    {
        cout << "0" << endl;
        return 0;
    }

    // 距離が0である頂点が二つ以上あったらダメ
    int zeroCnt = 0;
    for(int i = 0; i < D.size(); i++)
    {
        if(D[i] == 0) zeroCnt++;
        if(zeroCnt >= 2)
        {
            cout << "0" << endl;
            return 0;
        }
    }

    // 距離が飛び飛びになっていたらダメ
    // （そんな状況はない？）
    bool flag = true;
    for(int i = 0; i < cnt.size(); i++)
    {
        if(flag == true && cnt[i] == 0) flag = false;
        else if(flag == false && cnt[i] > 0)
        {
            cout << "0" << endl;
            return 0;
        }
    }

    // 頂点1から距離がiの頂点の個数をT[i]
    // 頂点1から距離がi+1の頂点の個数をT[i+1]
    // ans *= T[i] ^ T[i+1]
    // 高校数学の組み分け問題と同じ考え方
    // 注意点：一回掛け算するたびにmodをとる
    long long ans = 1;
    const long long mod = 998244353;
    for(int i = 0; i < cnt.size()-1; i++)
    {
        if(cnt[i] != 0 && cnt[i+1] != 0)
        {
            for(long long p = 0; p < cnt[i+1]; p++)
            {
                ans *= cnt[i];
                ans %= mod;
            }
        }
    }    

    // 解を出力
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define int long long
using namespace std;
int n,m,money;
int a[100001],b[100001],c[100001];
bool cmp(int x,int y){
    if(a[x]!=a[y])
        return a[x]<a[y];
    return x<y;
}
main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i],&b[i]);
        c[i]=i;
    }
    sort(c,c+n,cmp);
    for(int i=0;i<n && m>0;i++){
        if(m<b[c[i]])
            money+=m*a[c[i]],m=0;
        else
            money+=b[c[i]]*a[c[i]],m-=b[c[i]];
    }
    cout<<money<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main () {
  int n,m;
  
  cin >> n;
  vector<string> a(n);
  for (int i=0; i<n ; i++){
    cin>> a.at(i);
  }
  
  cin >> m;
  vector<string> b(m);
  for (int i=0;i<m;i++){
    cin >> b.at(i) ;
  }
  
  int count=0;
  for (int i=0; i<n;i++){
    int counter=1;
    for (int j=1;j<=n-i-1; j++){
      if (a.at(i)==a.at(i+j)) counter++;
    }
    for (int j=0; j<m;j++){
      if (a.at(i)==b.at(j)) counter--;
    }
    if (counter>count) count=counter;
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	ll n,x,t;
	cin>>n>>x>>t;
	cout<<((n+x-1)/x)*t;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3784
"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

import heapq

N, M = map(int,input().split())
A = list(map(int,input().split())) ## 横一列

heap = []
for i in range(N):
  heapq.heappush(heap, -A[i])
  
for i in range(M):
  max_price = heapq.heappop(heap)
  heapq.heappush(heap, max_price / 2.0)

ans = 0
for i in range(N):
  ans += -int(heap[i])

print(ans)

Measured memory_bytes: 14180
#include<stdio.h>
main(){
	int i;     
	char a[21];
	
	scanf("%s",a);
	
	for(i=0;a[i] != '\0';i++){	
	}
	
	for(i=i-1;i>=0;i--){
		printf("%c",a[i]);
	}
	
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define ll long long
#define WEIGHTSUM weight + i
#define VALUESUM maxValue[i] + value
using namespace std;
bitset <100005> foundWeight;
ll maxValue[100005];

int main() {
	ll n, w, weight, value, result = 0;

	cin >> n >> w;
	for (int i = 1; i <= n; i++) {
		cin >> weight >> value;

		for (int i = w; i >= 1; i--)
			if (maxValue[i] && WEIGHTSUM <= w) {
				maxValue[WEIGHTSUM] = max(maxValue[WEIGHTSUM], VALUESUM);
				result = max(result, VALUESUM);
			}

		maxValue[weight] = max(maxValue[weight], value);
		result = max(result, value);
	}

      cout << result;

	return 0;
}


Measured memory_bytes: 4336
#include<stdio.h>
#include<string.h>
#include<math.h>
int a,s,d[10000000],f,g,h;
int main(void)
{
	int i,j,k;
	for(i=2;i<=10000000;i++) d[i]=1;
	d[1]=0;
	d[2]=1;
	for(i=2;i*i<=10000000;i++){
		if(d[i]==1){
			for(j=2;j<=5000000;j++){
				if(i*j>10000000) break;
				d[i*j]=0;
			}
		}
	}
	//for(i=0;i<10000000;i++) if(d[i]==1) printf("%d  ",i);
	while(1){
		g=0;
		scanf("%d",&a);
		if(a==0) break;
		for(i=a;i>12;i--){
			if(d[i]==1&&d[i-2]==1&&d[i-6]==1&&d[i-8]==1){
				g=i;
				break;
			}
		}
		printf("%d\n",g);
	}
	return 0;
}

Measured memory_bytes: 41632
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

vector <ll> Prime;
int Calc(ll N){
  for (ll i = 1; i * i <= N; i++){
    if (N % i == 0){
      if (i * i == N){
        Prime.push_back(i);
      }else{
        Prime.push_back(i);
        Prime.push_back(N / i);
      }
    }
  }
  return 0;
}

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

  int ans = 0;
  for (int i = 0; i < Prime.size(); i++){
    if (Prime[i] == 1) continue;
    ll num = N;
    while (num % Prime[i] == 0){
      num /= Prime[i];
    }
    if (num % Prime[i] == 1) ans++;
  }
  
  Prime = {}; Calc(N - 1);
  for (int i = 0; i < Prime.size(); i++){
    if (Prime[i] == 1) continue;
    ans++;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e10+1
#define d(x) cerr<<#x<<"="<<x<<endl;

#define MAX 1000001

ll n,dp[MAX],W,maxv,v,w;

int main(void){
    cin>>n>>W;
    rep(i,MAX)dp[i]=inf;
    dp[0]=0;
    rep(i,n){
        cin>>w>>v;
        for(int j=MAX-v; j>=0; j--)dp[j+v]=min(dp[j+v],dp[j]+w);
    }
    rep(i,MAX)if(dp[i]<=W)maxv=i;
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 8064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

ll A, B, C, D;
map<ll, ll> memo;

ll coin(ll N) {
	if (memo.count(N) > 0) return memo[N];

	ll res = 1LL << 60LL;

	if (N % 2LL == 0LL) {
		res = min(res, coin(N / 2LL) + A);
	}
	else {
		ll residual = 1LL;
		res = min(res, coin(N / 2LL) + A + residual * D);
		res = min(res, coin(N / 2LL + 1LL) + A + (2LL - residual) * D);
	}
	if (N % 3LL == 0LL) {
		res = min(res, coin(N / 3LL) + B);
	}
	else {
		ll residual = N % 3LL;
		res = min(res, coin(N / 3LL) + B + residual * D);
		res = min(res, coin(N / 3LL + 1LL) + B + (3LL - residual) * D);
	}
	if (N % 5LL == 0LL) {
		res = min(res, coin(N / 5LL) + C);
	}
	else {
		ll residual = N % 5LL;
		res = min(res, coin(N / 5LL) + C + residual * D);
		res = min(res, coin(N / 5LL + 1LL) + C + (5LL - residual) * D);
	}

	memo[N] = res;
	if (res / N >= D) {
		memo[N] = N * D;
	}

	return memo[N];
}

int solve() {
	ll N;
	cin >> N >> A >> B >> C >> D;

	memo.clear();
	memo[0] = 0;
	memo[1] = D;

	ll res = coin(N);

	cout << res << endl;

	return 0;
}

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

	ll T;
	cin >> T;
	for (ll i = 0; i < T; ++i) {
		solve();
	}

	return 0;
}


Measured memory_bytes: 4392
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cstdio> 
using namespace std; 
int main(){
	long long a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a*b >= c*d){
		cout << a*b << endl;
	}
	else{
		cout << c*d << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = list(map(int,list(input())))

if len(s) == 1:
    print(s[0])
    exit()

from collections import deque

cands=deque([[0],[1]])

while len(cands[0]) != len(s)-1:
    newcands = []
    for cand in cands:
        newcands.append(cand+[0])
        newcands.append(cand+[1])
    cands = newcands

memo = []
while cands:
    pos = cands.pop()
    siki = ''
    for i, p in enumerate(pos):
        siki += str(s[i])
        if p == 1:
            siki += '+'
    siki += str(s[-1])
    memo.append(eval(siki))

print(sum(memo))



    




Measured memory_bytes: 3436
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int d[200000][3];
vector<int>E[200000];

int main(){
	int n,m;cin>>n>>m;
	rep(i,m){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
	}
	int s,t;cin>>s>>t;s--;t--;
	memset(d,-1,sizeof(d));
	queue<P>que;
	d[s][0]=0;
	que.push(P(s,0));
	while(!que.empty()){
		P p=que.front();que.pop();
		for(int u:E[p.first]){
			if(d[u][(p.second+1)%3]==-1){
				d[u][(p.second+1)%3]=d[p.first][p.second]+1;
				que.push(P(u,(p.second+1)%3));
			}
		}
	}
	if(d[t][0]==-1)puts("-1");
	else cout<<d[t][0]/3<<endl;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;
int main() {
	ll n;
	cin >> n;

	int pMax = 0;
	
	vector<int> vec(n);
	for (int i = 0; i < n; i++)
	{
		
		cin >> vec[i];
		pMax = max(vec[i], pMax);
	}
	ll minAns = LLONG_MAX;
	ll temp = 0;
	
	// p = i

	for (int p = 1; p <= pMax; p++)
	{
		for (int i = 0; i < n; i++)
		{
			temp += pow((vec[i] - p), 2);
		}
		minAns = min(temp, minAns);
		temp = 0;
	}

	cout << minAns << endl;

}


Measured memory_bytes: 256
/*

*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
 
#define ll long long
#define cint const int
#define ld long double
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
 
using namespace std;
 
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef pair <int, int> pi;
//typedef pair <long long, long long> pll;
//typedef pair <int, long long> pil;
//typedef pair <int, string> pis;
//typedef pair <int, char> pic;
//typedef pair <long long, int> pli;
//typedef pair <long long, string> pls;
//typedef pair <long long, char> plc;
//typedef pair <string, int> psi;
//typedef pair <string, long long> psl;
//typedef pair <string, char> psc;
//typedef pair <char, int> pci;
//typedef pair <char, long long> pcl;
//typedef pair <char, string> pcs;
int a, b;
int main () {
	cin >> a >> b;
	cout << 6 - (a + b);
	return 0;
}

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

int main () {
    char s[100005];
    scanf ("%s", s);
    int len = strlen(s);
    int a=0;
    int b=0;
    int c=0;
    for (int i=0; i<len; i++) {
        if (s[i]=='a') a++;
        else if (s[i]=='b') b++;
        else if (s[i]=='c') c++;
    }
    int dif[3];
    dif[0] = abs(a-b);
    dif[1] = abs(a-c);
    dif[2] = abs(b-c);
    int no=0;
    for (int i=0; i<3; i++) {
        if (dif[i] > 1) no=1;
    }
    if (no>0) printf("NO\n");
    else printf("YES\n");
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a,bbb;
  cin>>n>>m;
  set<int> bb;
  vector<int> b[n+1];
  for(int i=0;i<m;i++){
    cin>>a>>bbb;
    bb.insert(bbb);
    b[bbb].push_back(a);
  }
  int c=0,me=0;
  for(int x:bb){
    for(int y:b[x]){
      if(me<=y){
        me=x;
        c++;
      }
    }
  }
  cout<<c;
}

Measured memory_bytes: 7936
import numpy as np


from functools import *
import sys
sys.setrecursionlimit(100000)


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


mod = 10**9+7


class UnionFind:
    def __init__(self, size):
        # -nが木のroot
        # 親ノードの位置を格納
        self.table = [-1 for i in range(size)]

    def _find(self, x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def find(self, x):
        if self.table[x] < 0:
            return x
        self.table[x] = self.find(self.table[x])
        return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    def get_ntree(self):
        res = 0
        for c in self.table:
            if c < 0:
                res += 1
        return res

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_nclass(self):
        done = []
        for x in range(len(self.table)):
            if x in done:
                continue
            while self.table[x] >= 0:
                done.append(x)
                x = self.table[x]

    def get_nodenum(self):
        res = []
        for t in self.table:
            if t < 0:
                res.append(-t)

        return res


def ij_to_n(i, j, W):
    return i*W+j


def n_to_ij(n, W):
    return (n//W, n % W)


if __name__ == '__main__':

    N, M, K = acinput()

    uf = UnionFind(N)
    A=[[]for i in range(N)]
    for i in range(M):
        tmp = acinput()
        uf.union(tmp[0]-1, tmp[1]-1)
        A[tmp[0]-1].append(tmp[1]-1)
        A[tmp[1]-1].append(tmp[0]-1)


    block=[[]for i in range(N)]
    for i in range(K):
        tmp = acinput()
        block[tmp[0]-1].append(tmp[1]-1)
        block[tmp[1]-1].append(tmp[0]-1)

    nt = uf.get_ntree()
    res=[]
    for i in range(N):
        nblock = 0
        for sb in block[i]:
            if uf.is_same(sb,i):
                nblock += 1

        nn =(-uf.table[uf.find(i)])

        nn-=1
        
        #print(uf.find(i),nn, A[i], nblock)
        tmp = nn-(len(A[i]))-nblock
        res.append(tmp)

    print(" ".join(map(str,res)))


Measured memory_bytes: 101988
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  cin >> k >> a >> b;
  int ans=0;
  for(int i=a;i<b+1;i++){
    if(i%k==0) ans=1;
  }
  if (ans){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;


int main() { 
    int A[3][3], N, B;
    bool Card[3][3] = {};
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> A[i][j];
        }
    }
    cin >> N;
    for(int k=0; k<N; k++){
        cin >> B;
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(A[i][j]==B) Card[i][j]=true;
            }
        }
    }
    
    bool ok = false;
    for(int i=0; i<3; i++){
        if(Card[i][0] && Card[i][1] && Card[i][2]) ok = true;
        if(Card[0][i] && Card[1][i] && Card[2][i]) ok = true;
    }
    if(Card[0][0] && Card[1][1] && Card[2][2]) ok = true;
    if(Card[2][0] && Card[1][1] && Card[2][0]) ok = true;

    cout << (ok ? "Yes": "No") << endl; 

}

Measured memory_bytes: 256
#include<stdio.h>


bool lineSearch(int A[], int n, int key) {
    for (int i = 0; i < n; i++) {
        if (A[i] == key) {
            return true;
        }
    }
    return false;
}

int main() {
    int A[10000];
    int n, q, key;
    int count = 0;

    scanf("%d", &n);

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

    for (int i = 0; i < q; i++) {
        scanf("%d", &key);
        if (lineSearch(A, n, key))  count++;
    }
    
    printf("%d\n", count);
}

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

int main() {
  int x, y, ans;
  cin >> x >> y;
  ans = 0;
  for (int i = 0; i <= x; i++) {
    if (i * 2 + (x - i) * 4 == y) {
      cout << "Yes" << endl;
      ans += 1;
      break;
    }
  }
  if (ans == 0) {
    cout << "No" << endl;
  }  
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <utility>
#include <algorithm>
#include <numeric>

int calc(std::vector<int> const& pts) {
  std::vector<std::vector<int>> frame(10);
  {
    size_t i = 0;
    for (int p: pts) {
      frame[i].push_back(p);
      if (i < 9) {
        if (frame[i].size() == 2) {
          ++i;
        } else if (std::accumulate(frame[i].begin(), frame[i].end(), 0) == 10) {
          ++i;
        }
      }
    }
  }
  std::vector<int> framescore(10);
  for (size_t i = 0; i < 9; ++i) {
    framescore[i] = std::accumulate(frame[i].begin(), frame[i].end(), 0);
    if (framescore[i] == 10) {
      if (frame[i].size() == 1) {
        // strike
        framescore[i] += frame[i+1][0];
        if (frame[i+1].size() > 1) {
          framescore[i] += frame[i+1][1];
        } else {
          framescore[i] += frame[i+2][0];
        }
      } else {
        assert(frame[i].size() == 2);
        // spare
        framescore[i] += frame[i+1][0];
      }
    }
  }
  framescore[9] = std::accumulate(frame[9].begin(), frame[9].end(), 0);
  return std::accumulate(framescore.begin(), framescore.end(), 0);
}

int testcase_ends() {
  size_t m;
  scanf("%zu", &m);
  if (m == 0) return 1;

  std::vector<std::pair<int, int>> ss(m);
  for (size_t i = 0; i < m; ++i) {
    int id;
    scanf("%d", &id);

    char buf[1024];
    fgets(buf, sizeof buf, stdin);
    char* pos = buf;
    std::vector<int> pts;
    while (true) {
      char* endpos;
      int x = strtol(pos, &endpos, 10);
      if (endpos == pos) break;
      pos = endpos;
      pts.push_back(x);
    }
    // for (size_t j = 0; j < ss[i].second.size(); ++j)
    //   fprintf(stderr, "%d%c", ss[i].second[j], j+1<ss[i].second.size()? ' ':'\n');

    ss[i].first = -calc(pts);
    ss[i].second = id;
  }
  std::sort(ss.begin(), ss.end());
  for (auto const& si: ss)
    printf("%d %d\n", si.second, -si.first);

  return 0;
}

int main() {
  while (!testcase_ends()) {
  }
}



Measured memory_bytes: 2572
#include<bits/stdc++.h>
        #define F first
        #define S second
        using ll = long long;
        const ll mod = 1000000007;
        const ll infi = 1000000000000000;
        const ll md = 998244353;
        using namespace std;
        using vl = vector<ll>;
        using pll =  pair<ll,ll>;
        
        ll power(ll y){
            if(y==0)
            return 1;
            ll res=power(y/2);
            res=(res*res)%mod;
            if(y&(ll)1)
            res=(res*2)%mod;
            return res;
        }
        
        void  solve(){
            int n;
            ll ans =0;
            cin>>n;
            vl a(n);
            deque<vector<int>> b(n);
            for(int i=0;i<n;i++) cin>>a[i];
            
            for(int j=0;j<n;j++){
                for(int i=0;i<64;i++){
                    b[j].push_back(a[j]%2);
                    a[j] = a[j]/2;
                }
            }
            
            for(int i=0;i<64;i++){
                ll cnto=0,cntz=0,term;
                for(int j=0;j<n;j++){
                    if(b[j][i] == 1) cnto ++;
                }
                term=((n - cnto)*power(i))%mod;
                term = (((cnto)*term))%mod;
                ans = (ans+term)%mod;
            }
            cout<<ans;
        }
        
        
        int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            int n;
            //cin>>n;
            
            //for (int i = 0; i < n; i++) {
                solve();
            //}
            return 0;
        }

Measured memory_bytes: 89600
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n;
bool mat[22][22];
long long dp[22][1<<22];
long long way(int i,int n,int mask){
    if(i>n){
      return (mask+1) ==(1<<n);
    }
    if(dp[i][mask]!=-1)
        return dp[i][mask];
    long long ans=0;
    for(int j=1;j<=n;j++){
       if(mask&(1<<(j-1)))
       continue;
       if(!mat[i][j])
       continue;

       ans=(ans%mod+way(i+1,n,mask|(1<<(j-1))%mod))%mod;
    }
     dp[i][mask]=ans;
     return ans;

}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        cin>>mat[i][j];
    }
}
memset(dp,-1,sizeof(dp));
cout<<way(1,n,0)<<"\n";

}


Measured memory_bytes: 721152
#include<stdio.h>
#include<iostream>
#include<math.h>

using namespace std;

int main(){
  long long n;
  cin >> n;
  long long res = 0;
  
  long long i;
  
  for(i=1; i*i <= n; ++i){
    if(n%i == 0 && (n/i -1 > i)){
      res += n/i - 1;
    }
  }
  
  cout << res << "\n";

  return 0;
}


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

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

    priority_queue<string, vector<string>, greater<string>> q;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        q.push(s);
    }

    while (!q.empty()) {
        cout << q.top();
        q.pop();
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    string s;
    cin>>s;
    long long int c;
    cin>>c;
    long long int digit_num = s.size();
    long long int zero_num = digit_num - c;
  if(zero_num < 0){
    cout << 0 << endl;
    return 0;
  }
    //cout << zero_num << endl;
    vector<vector<vector<long long int>>> dp(digit_num+1, vector<vector<long long int>>(2, vector<long long int>(120, 0)));
    long long int x0 = (long long int)(s[0] - '0');
    dp[0][0][0] = x0-1 ;
    dp[0][0][1] = 1;
    dp[0][1][0] = 1;
    FOR(i,1,digit_num){
        long long int xi = (long long int)(s[i] - '0');
        //cout << xi << endl;
        if(xi==0){
            dp[i][0][0] += dp[i - 1][0][0] * 9 + dp[i - 1][0][0 + 1] * 0 + dp[i - 1][1][0] * (0) + dp[i - 1][1][0 + 1] * 0;

            REP(j,110){
                
                dp[i][0][j+1]+=dp[i - 1][0][j] * 1 + dp[i - 1][0][j + 1] * 9 + dp[i - 1][1][j] * (0) + dp[i - 1][1][j + 1] * 0;
         
                //dp[i][1][j]=dp[i - 1][0][j] * 9 + dp[i - 1][0][j + 1] * 0 + dp[i - 1][1][j] * (0) + dp[i - 1][1][j + 1] * 0;
                dp[i][1][j+1]+=dp[i - 1][0][j] * 0 + dp[i - 1][0][j + 1] * 0 + dp[i - 1][1][j] * (1) + dp[i - 1][1][j + 1] * 0;
            }
        }else{
            dp[i][0][0] += dp[i - 1][0][0] * 9 + dp[i - 1][0][0 + 1] * 0 + dp[i - 1][1][0] * (xi-1) + dp[i - 1][1][0 + 1] * 0;

            REP(j,110){
                
                dp[i][0][j+1]+=dp[i - 1][0][j] * 1 + dp[i - 1][0][j + 1] * 9 + dp[i - 1][1][j] * (1) + dp[i - 1][1][j + 1] * (xi-1);
                dp[i][1][j]+=dp[i - 1][0][j] * 0 + dp[i - 1][0][j + 1] * 0 + dp[i - 1][1][j] * (1) + dp[i - 1][1][j + 1] * 0;
                //dp[i][1][j+1]=dp[i - 1][0][j] * 0 + dp[i - 1][0][j + 1] * 0 + dp[i - 1][1][j] * (0) + dp[i - 1][1][j + 1] * 0;
            }
            
        }

      /*  cout << i << endl;
        FOR(j,i,i+5){
            cout<<"j="<<j<<" " << dp[i][0][j] << " " << dp[i][1][j] << endl;
        }
        cout << endl;*/
    }
    cout << dp[digit_num - 1][1][zero_num]+ dp[digit_num - 1][0][zero_num] << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std; 
#define ll long long
template<class T> void chmin(T& x, T& y){if(x > y) x = y;}
template<class T> void chmax(T& x, T& y){if(x < y) x = y;}

int N;
int A[100010];
int fg[100010];
int bg[100010];

int main(){
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
    }
    for(int i = 1; i <= N; i++){
        fg[i] = __gcd(A[i], fg[i - 1]);
    }
    for(int i = N; i >= 1; i--){
        bg[i] = __gcd(A[i], bg[i + 1]); 
    }
    int ans = 1;
    for(int i = 1; i <= N; i++){
        int y = __gcd(fg[i - 1], bg[i + 1]);
        chmax(ans, y);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
P.insert(0, 0)
C.insert(0, 0)

ans = -float("inf")
for i in range(1, N+1):
    S = i
    visited = [False for i in range(N+1)]
    point = []
    while visited[S] == False:
        point.append(C[S])
        visited[S] = True
        S = P[S]

    L = len(point)
    index = 0
    for i in range(L):
        if point[i] == C[S]:
            index = i
            break

    not_loop = index
    loop = L-index
    Loop = point[index:]
    B = 0
    for i in range(index, L):
        B += point[i]
    if B > 0:
        if not_loop > K:
            D = 0
            for i in range(K):
                D += point[i]
                ans = max(D, ans)

        if not_loop <= K:
            D = 0
            for i in range(not_loop):
                D += point[i]
            K -= not_loop
            for i in range(1, loop):
                Loop[i] += Loop[i-1]
            for i in range(1, loop):
                Loop[i] = max(Loop[i], Loop[i-1])
            if K % loop == 0:
                ans = max(ans, D+B*(K//loop-1)+Loop[-1])
            elif K % loop != 0:
                ans = max(ans, D+B*(K//loop-1) +
                          Loop[-1], D+B*(K//loop)+Loop[K % loop-1])

    else:
        ans = max(point[0], ans)
        for i in range(1, min(L, K)):
            point[i] += point[i-1]
            ans = max(point[i], ans)


print(ans)

Measured memory_bytes: 108156
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a * b % 2 == 0) {
			pr.println("No");
		} else {
			pr.println("Yes");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 25172
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

char S[200005];
int cnt[27][200005];

int main()
{
	scanf("%s", S + 1);
	for (int i = strlen(S + 1); i >= 1; i--) {
		for (int j = 0; j < 27; j++) cnt[j][i] = cnt[j][i + 1];
		cnt[S[i] - 'a'][i]++;
		cnt[26][i]++;
	}

	LL ans = 0;
	for (int i = 1; i <= strlen(S + 1); i++) {
		ans += cnt[26][i] - cnt[S[i] - 'a'][i];
	}
	printf("%lld\n", ans + 1);
	return 0;
}


Measured memory_bytes: 21504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

vvll g;
vll color(110000, 0);
bool dfs(ll x, ll p = -1, ll c = 0) {
    color[x] = c;
    for(auto nx : g[x]) {
        if(color[nx] == c) return false;
        if(color[nx] ==0 && !dfs(nx, x, -c)) return false;
    }
    return true;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll n, m;
    cin >> n >> m;
    g = vvll(n);
    rep(i,m) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bool is_bipartite = dfs(0, -1, 1);
    if(is_bipartite) {
        ll cw = 0, cb = 0;
        rep(i, n) {
            if(color[i] == 1) cw++;
            else cb++;
        }
        cout << cw * cb - m << endl;
    }
    else cout << n * (n-1) / 2 - m << endl;
}


Measured memory_bytes: 7552
//#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<optional>
#include<assert.h>
#include<tuple>

using namespace std;

template <typename T>
void make_fenwick(vector<T>& nums) {
	for (size_t i = 0; i < nums.size(); ++i) {
		nums[i | (i + 1)] += nums[i];
	}
}

template <typename T>
int64_t fenwick_sum(const vector<T>& fenwick, const int amount) {
	int64_t result = 0;
	int ind = amount - 1;
	for (; ind >= 0; ind = (ind&(ind+1)) - 1) {
		result += fenwick[ind];
	}
	return result;
}

template <typename T>
void fenwick_update(vector<T>& fenwick, int ind, T new_value) {
	T old_val = fenwick_sum(fenwick, ind + 1) - fenwick_sum(fenwick, ind);
	T dif = new_value -  old_val;
	for (; ind < fenwick.size(); ind = (ind | (ind + 1))) {
		fenwick[ind] += dif;
	}
}

vector<vector<int>> read_input() {
	int q;
	cin >> q;
	vector<vector<int>> queries(q, vector<int>(3, 0));
	for (size_t i = 0; i < q; ++i) {
		cin >> queries[i][0];
		if (queries[i][0] == 1) {
			cin >> queries[i][1] >> queries[i][2];
		}
	}
	return queries;
}
struct ParamsForMin {
	const vector<int64_t>& fenwick;
	const vector<int64_t>& fenwick_count;
	int last_ind;
};

void solve() {
	vector<vector<int>> queries = read_input();
	vector<pair<int, int>> a;
	for (size_t i = 0; i < queries.size(); ++i) {
		if (queries[i][0] == 1) {
			a.push_back({ queries[i][1],(int)i });
		}
	}
	sort(a.begin(), a.end());
	vector<int64_t> fenwick(a.size(), 0);
	vector<int64_t> fenwick_count(a.size(), 0);
	int64_t b_sum = 0;
	int lhs = 0;
	int rhs = 0;
	multiset<int> readed;
	auto it = readed.end();
	//ParamsForMin par = { fenwick ,fenwick_count ,a,0 };
	for (size_t i = 0; i < queries.size(); ++i) {
		if (queries[i][0] == 1) {
			b_sum += queries[i][2];
			int ind = lower_bound(a.begin(), a.end(), pair<int, int>{ queries[i][1], (int)i }) - a.begin();
			fenwick_update(fenwick, ind, (int64_t)queries[i][1]);
			readed.insert(queries[i][1]);
			if (it == readed.end()) {
				it = readed.begin();
			}
			else {
				if (queries[i][1] >= * it) {
					++rhs;
				}
				else {
					++lhs;
				}
				if (lhs < rhs) {
					++lhs;
					--rhs;
					++it;
				}
				if (lhs > rhs) {
					--it;
					--lhs;
					++rhs;
				}
			}
			fenwick_update(fenwick_count, ind, (int64_t)1);
		}
		else {
			int ind = upper_bound(a.begin(), a.end(), pair<int, int>{ *it,-1 }) - a.begin();
			int64_t left = fenwick_sum(fenwick_count, ind) * (*it) - fenwick_sum(fenwick, ind);
			int64_t right = fenwick_sum(fenwick, fenwick.size()) + left - fenwick_sum(fenwick_count, fenwick_count.size()) * (*it);
			cout << *it << " " << left + right + b_sum << "\n";
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--)solve();
	return 0;
}

Measured memory_bytes: 28108
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                  1000000007
#define eps         0.00000000000000001
#define endl                       '\n'

using namespace std;

int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};

vector<int> adj[300010];
vector<int> par(300010,-1);
vector<int> disco(300010,-1);
vector<int> finis(300010,-1);
vector<int> typ(300010,0);
vector<int> vis(300010,0);
vector<int> dis(300010,0);
vector<int> val;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n,k;
    string s;
    cin>>n;
    cin>>s;
    cin>>k;
    char ch=s[k-1];
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=ch)
        {
            s[i]='*';
        }
    }
    cout<<s<<endl;
}



Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
#define maxn 500005
using namespace std;
bool same(string s) {
	char base = s[0];
	for (char c : s)
		if (c != base)
			return false;
	return true;
}
int f[2][maxn];
bool good[2][maxn];
void kmp(string s, int* f, bool* good) {
	f[0] = -1;
	for (int i = 1, j = -1; i < (int)s.size(); i++) {
		while (j != -1 && s[i] != s[j + 1])	j = f[j];
		if (s[i] == s[j + 1])	j++;
		f[i] = j;
	}
	good[0] = true;
	for (int i = 1; i < (int)s.size(); i++)
		if (f[i] == -1 || (i + 1) % (i - f[i]) != 0)
			good[i] = true;
}
int main() {
	string s; cin >> s;
	if (same(s)) {
		cout << (int)s.size() << endl << 1 << endl;
	}
	else {
		kmp(s, f[0], good[0]);
		if (good[0][(int)s.size() - 1]) {
			cout << 1 << endl << 1 << endl;
		}
		else {
			reverse(s.begin(), s.end());
			kmp(s, f[1], good[1]);
			int ans = 0;
			for (int i = 0; i < (int)s.size() - 1; i++)
				if (good[0][i] && good[1][(int)s.size() - 1 - (i + 1)])
					ans++;
			cout << 2 << endl << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 6168
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
	#endif
  int d,t,s;
  cin>>d>>t>>s;
  if(d<=(t*s)){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int pref[N];
char c[200][200];

signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   int n, m;
   cin >> n >> m;
   for (int i = 0; i < n; i++) {
      for (int j  = 0; j < m; j++) {
         cin >> c[i][j];
         if (c[i][j] == '#') pref[i]++;
      }
   }
   int j = 0;
   for (int i = 0; i < n; i++) {
      int kol = 0;
      while (j < m && c[i][j] == '#') kol++, j++;
      if (kol != pref[i] || pref[i] == 0) {
         cout << "Impossible";
         return 0; 
      }
      j--;
   }
   if (j == m - 1) {
      cout << "Possible";
   }
   else cout << "Impossible";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 10
#define MAXM 1000
typedef long long LL;
int cd;
LL res;
char s[MAXN<<2];
bool p[MAXM];
int main()
{
	scanf("%s", s);
	const int lim = 1 << (strlen(s) - 1);
	int cnt=0;
	for(cd=0; cd<=lim; cd++)
	{
		memset(p, 0, sizeof p);
		int t = cd;
		cnt = 0;
		while(t)
		{
			p[cnt] = t & 1;
			t >>= 1;
			cnt++;
		}
		LL ans = 0;
		LL tmp = s[0]-'0';
        for(int j=0; j<strlen(s)-1; j++)
        {
            if(p[j])
            {
                ans += tmp;
                tmp = s[j+1] - '0';
            }
            else
                tmp = tmp*10+s[j+1]-'0';
        }
        res += ans+tmp;
	}
	LL g=0;
	for(int i=0; i<strlen(s); i++)
		g = (g * 10LL + LL(s[i] - '0')) ;
	printf("%lld", res-g);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int r;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> r;
    cout << r*r << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "20" ].solve == "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0" );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	auto anss = new long[ n ];
	foreach( x; 1L .. 101 )
	{
		foreach( y; x .. 101 )
		{
			foreach( z; y .. 101 )
			{
				auto t = x ^^ 2 + y ^^ 2 + z ^^ 2 + x * y + y * z + z * x;
				if( n < t ) break;
				if(      x == y && y == z           ) anss[ t - 1 ]++;
				else if( x == y || y == z || x == z ) anss[ t - 1 ] += 3;
				else                                  anss[ t - 1 ] += 6;
			}
		}
	}
	return anss.to!( string[] ).join( "\n" );
}


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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define EACH(i,c) for (auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int A, B;

int f(int x) {
  int sum = 0;
  FOR(i, 1, 60) {
    int v = PW(i);
    int r = x % (v << 1);
    if (r < v) continue;
    if ((r-v) % 2 == 0) {
      sum += v;
    }
  }
  if (x % 4 >= 1 && x % 4 <= 2) {
    sum++;
  }
  return sum;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> A >> B;
  int ans = f(B);
  if (A > 0) ans ^= f(A-1);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<complex>
using namespace std;

int main(){
  double a,b,c; cin >> a >> b >> c;
  double p = acos(-1);
  double s = a * b * sin(c*p/180)/2;
  double l = a + b + sqrt(a*a + b*b - 2*a*b*cos(c*p/180));
  double h = s / a * 2;
  printf("%.10f\n%.10f\n%.10f\n", s, l, h);
  return 0;
}



Measured memory_bytes: 3448
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;

#define Rep(i,l,r) for (int i = (l); i <= (r); ++ i)
#define RepD(i,r,l) for (int i = (r); i >= (l); -- i)
#define RepG(i,x) for (int i = hd[x]; i; i = e[i].nxt)

const int N = 1e5+5;

int n, a[N]; char s[N];

int main () {
	scanf ("%s", s+1), n = strlen (s+1);
	Rep(i,1,n) a[i] = s[i]-'0';
	if (!a[1] || a[n]) {puts ("-1"); return 0;}
	Rep(i,1,n-1) if (a[i]!=a[n-i]) {puts ("-1"); return 0;}
	Rep(i,2,n-1) if (a[i]) {
		RepD(j,i-1,1) {
			printf ("%d %d\n", i, j);
			if (a[j]) break;
		}
	}
	RepD(i,n-1,1) if (a[i]) {printf ("%d %d\n", n, i); break;}
	return 0;
}


Measured memory_bytes: 1920
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
N = line[0] * 1
K = line[1] * 1 
A = lines.shift().split(' ')

heap = [0]
_insertHeap = (v) => {
    var idx = heap.length
    while(idx > 1) {
        var parent = ~~(idx / 2)
        if (heap[parent] < v) {
            heap[idx] = heap[parent]
            idx = parent
        } else {
            break;
        }
    }
    heap[idx] = v
}

_popHeap = () => {
    var val = heap[1]
    var last = heap.pop()
    
    if (heap.length == 1) {
        return val
    }
    
    var idx = 1
    while(true) {
        var left = idx * 2
        var right = idx * 2 + 1
        var next = idx
        if (left < heap.length && heap[left] > last) {
          next = left
        }
        if (right < heap.length && heap[right] > last && heap[right] > heap[left]) {
          next = right
        }
        if (next != idx) {
          heap[idx] = heap[next]
          idx = next
        } else {
            break;
        }
    }
    heap[idx] = last
    return val
}

for(i=0; i<N; i++) {
    _insertHeap(A[i] * 1)
}

for(i=0; i<K; i++) {
    a = _popHeap()
    _insertHeap(~~(a / 2))
}

sum = 0
for(i=1; i<heap.length; i++) {
    sum += heap[i]
}

console.log(sum)

Measured memory_bytes: 28940
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#define INF 100000000
 
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;


int main(void) {
    ll x, a, b;
    cin >> x;
    ll list[1001];
    for(ll i=0;i<1001;i++) {
        list[i] = i*i*i*i*i;
    }
    for(ll i=0;i<1001;i++) {
        a=list[i];
        for(ll j=i;j<1001;j++) {
            b=-list[j];
            if(a+b==x) {
                cout << i << ' ' << j << endl;
                return 0;
            } else if(-a+b==x) {
                cout << -i << ' ' << j << endl;
                return 0;
            } else if(a-b==x) {
                cout << i << ' ' << -j << endl;
                return 0;
            } else if(-a-b==x) {
                cout << -i << ' ' << -j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] h = new int[10];
        for(int i = 0; i < 10; i++){
            h[i] = sc.nextInt();
        }
        Arrays.sort(h);
        System.out.printf("%d\n%d\n%d\n", h[9], h[8], h[7]);
    }
}

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

#define llong long long 
#define ii pair<int, int>
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )

llong sumdig(llong i) {
  llong ans = 0;
  while (i) {
    ans += i % 10;
    i /= 10;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  llong n;cin >> n;
  llong ans = n;
  rep1(i, n - 1) {
    llong f = n - i;
    ans = min(ans, sumdig(i) + sumdig(f));
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
def main():
    n = int(input())
    D = map(int, input().split())
    m = int(input())
    T = map(int, input().split())
    C = Counter(D)
    for t in T:
        if t not in C or C[t] == 0:
            print('NO')
            return
        else:
            C[t] -= 1
    print('YES')
main()

Measured memory_bytes: 59492
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    N = SI()
    S = input()
    
    left = 0
    right = 0
    for s in S:
        if s == '(':
            left += 1
        else:
            if left > 0:
                left -= 1
            else:
                right += 1
    ret = '(' * right + S + ')' * left
    print(ret)

if __name__ == "__main__":
    main()

Measured memory_bytes: 4076
#include <iostream>
using namespace std;
int P[10010];
void init(int N){
  for (int i=0; i<N; i++) P[i] = i;
}
int root (int a){
  if (P[a] == a) return a;
  else {
    P[a] = root(P[a]);
    return P[a];
  }
}
bool is_same_set(int a, int b){
  return root(a) == root(b);
}
void unite(int a, int b){
  P[root(a)] = root(b);
}

int main(){
  int n, q;
  cin >> n;
  init(n);
  cin >> q;
  int c, x, y;
  for (int i=0; i<q; i++){
    cin >> c;
    cin >> x;
    cin >> y;
    if (c == 0) unite(x,y);
    else cout << is_same_set(x, y) << endl;
    }
}

Measured memory_bytes: 1320