akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    if (D == 25){
        cout << "Christmas" << endl;
    }
    else if (D == 24){
        cout << "Christmas Eve" << endl;
    }
    else if (D == 23) {
        cout << "Christmas Eve Eve" << endl;
    }
    else if (D == 22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 3496
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main(void){
	int N;
	cin >> N;
	
	vector<int> factors(N + 1, 0);
	factors[1] = 1;
	for(int i = 2; i <= N; i ++){
		if(factors[i] == 0){
			for(int j = i; j <= N; j += i){
				factors[j] = i;
			}
		}
	}
	
	map<int, int> table;
	unsigned long long total = 1;
	
	for(int i = 2; i <= N; i ++){
		table.clear();
		int j = i;
		while(true){
			int f = factors[j];
			if(table.find(f) == table.end()){
				table[f] = 1;
			}else{
				table[f] ++;
			}
			if(f == j){
				break;
			}
			j /= f;
		}
		unsigned long long count = 1;
		for(auto p = table.begin(); p != table.end(); p ++){
			count *= (p->second + 1);
		}
		total += count * i;
	}
	
	cout << total << endl;
	return 0;
}



Measured memory_bytes: 41852
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n; cin >> n;
    ll x = 0;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
        x ^= a[i];
    }
    rep(i, n){
        ll b = x ^ a[i];
        cout << b << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

ll o=0;
set<ll> op;
bool isPrime(ll n)
{
	// Corner case
	if(n==2){
		return true;
	}
	else if (n <= 1 || n%2==0)
		return false;

	for (ll i = 3; i <= sqrt(n); i+=2)
		if (n % i == 0)
			return false;

	return true;
}

void tbaben(ll i){
	if(isPrime(i)){
		if(!op.count(i)){
			o++;
		}
		return;
	}
	for (ll k=2;k<=i;k++){
		if (i%k==0 && !op.count(k)){
			if(isPrime(k)){
				o++;
				op.insert(k);

				ll sif=i/k;
				ll oi=k*k;
				while(oi<=sif){
					if(sif%oi==0){
						o++;
						op.insert(k);
						sif/=oi;
					}
					oi*=k;
				}

				tbaben(sif);
				return;
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll t;
	cin>>t;
	tbaben(t);
	cout<<o<<endl;
	return 0;
}


Measured memory_bytes: 3592
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n;
  cin >> n;
    
  unordered_map<string,int> p;
  rep(i,n){
    string s;
    cin >> s;
    sort(all(s));
      if(p.count(s)) p.at(s)++;
      else p[s]=1;
  }
  
  ll ans = 0;
  for(auto x : p){
    auto t = x.se;
    ans+=(ll)t*(t-1)/2;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 10660
from itertools import compress, product

N, M, X = map(int, input().split())
clist = [list(map(int, input().split())) for _ in range(N)]
prices = []

for p in product(range(2), repeat=N):
    sumlist = [0] * (M+1) 
    for c in compress(clist, p):
        for i, val in enumerate(c):
            sumlist[i] += val
    if all(i >= X for i in sumlist[1:]):
        prices.append(sumlist[0])

if prices:
    print(min(prices))
else:
    print(-1)


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, m, k;

int main(){
	cin >> n >> m >> k;
	int fl=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if((n-i)*j+(m-j)*i==k)fl++;
		}
	}
	if(fl==0){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int a,b,c;
  int count,count2=0,count3=0;
  int shu[100];
scanf("%d %d %d",&a,&b,&c);
for(count=1;;count++){
  if(a%count==0&&b%count==0){shu[count3]=count; count3++;}
  if(count==a||count==b){break;}
}
  printf("%d",shu[count3-c]);
return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int a, b, sum;

    cin >> a >> b;

    sum = a + b;

    if( sum % 2 == 0 )
        cout << sum / 2 << endl;
    else
        cout << (sum/2)+1 << endl;

    return 0;
}

Measured memory_bytes: 256
#-------------------------------------------------------------------------------
#関数定義
def f(a,d,T):
    try:
        return T[d+1:].index(a)+(d+1)
    except ValueError:
        return len(T)

def g(a,d,T):
    try:
        return (d-1)-T[d-1::-1].index(a)
    except ValueError:
        return 0
#-------------------------------------------------------------------------------
#インポート
from math import inf,exp
from random import random,randint
import time
from copy import copy
#-------------------------------------------------------------------------------
#定数
TIME_LIMIT=1.864 #ループの時間制限  
A=26 #アルファベットの数
START=time.time()

ALPHA=15
ep=10**(-6) #アニーリングの微小温度
#-------------------------------------------------------------------------------
#読み込み部
D=int(input())

C=[True]+list(map(int,input().split())) #減る満足度のベース
S=[True]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度

for i in range(1,D+1):
    S[i]=[0]+list(map(int,input().split()))           
#-------------------------------------------------------------------------------
#貪欲部
L=[0]*(A+1)
T=[0]
for d in range(1,D+1):
    Y=-inf
    E=0
    for a in range(1,A+1):
        X=S[d][a]
        for s in range(1,A+1):
            if a!=s:
                X-=C[s]*(d-L[s])

        if X>Y:
            Y=X
            E=a
    L[E]=d
    T.append(E)
#-------------------------------------------------------------------------------
#調節部
t=time.time()-START
while t<TIME_LIMIT:
    d=randint(1,D)
    p=T[d]
    q=randint(1,A)
    Y=(d-g(p,d,T))*(f(p,d,T)-d)
    Z=(d-g(q,d,T))*(f(q,d,T)-d)
        
    Delta=(S[d][q]-S[d][p])+Z*C[q]-Y*C[p]
    if (Delta>=0) or (Delta<0 and random()<exp(Delta/(ALPHA*(TIME_LIMIT-t)+ep))):
        T[d]=q
    
    t=time.time()-START

for i in range(1,D+1):
    print(T[i])


Measured memory_bytes: 93820
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ar[3001][8001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,t;
    cin>>n>>t;
    vector<pair<ll,ll>>v;
    for(ll i=0;i<=3000;i++)
    {
        for(ll j=0;j<=8000;j++)
        {
            ar[i][j]=0;
        }
    }
    ll a,b;
    for(ll i=1;i<=n;i++)
    {
        cin>>a>>b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());
    for(ll i=1;i<=n;i++)
    {
        a=v[i-1].first;
        b=v[i-1].second;
        for(ll j=1;j<=8000;j++)
        {
            ar[i][j]=ar[i-1][j];
            if(j-a<t && j-a>=0)
            {
                ar[i][j]=max(ar[i][j],ar[i-1][j-a]+b);
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<=8000;i++)
    {
        //cout<<ar[n][i]<<endl;
        ans=max(ans,ar[n][i]);
    }
    cout<<ans;
}

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

using namespace std;
int main() {
	int N, ans;
	vector<int>a;

	cin >> N;

	int num;
	for (int i = 0; i < N; ++i) {
		cin >> num;
		a.push_back(num);
	}

	a.erase(unique(a.begin(), a.end()), a.end());
	sort(a.begin(), a.end());

	ans = a[a.size() - 1] - a[0];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()


def check(i):
    s = list(S)
    for j in range(len(T)):
        if s[i + j] == '?':
            s[i + j] = T[j]
    return ''.join(s).startswith(T, i)


def restore(i):
    s = list(S)
    for j in range(len(T)):
        s[i + j] = T[j]
    for i in range(len(S)):
        s[i] = 'a' if s[i] == '?' else s[i]
    return ''.join(s)


i = 0
ans = []
while i + len(T) <= len(S):
    if check(i):
        ans.append(restore(i))
    i += 1

if ans:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')


Measured memory_bytes: 15700
A,B,C,X,Y = gets.split(" ").map { |e| e.to_i }

count = 0

if B+A<= 2*C
  count = A*X + B*Y
elsif X<Y #とりま片方を０にする
  count += 2*C*X
  if B < 2*C
    count += B*(Y-X)
  else
    count += 2*C*(Y-X)
  end
else
  count += 2*C*Y
  if A < 2*C
    count += A*(X-Y)
  else
    count += 2*C*(X-Y)
  end
end


puts count


Measured memory_bytes: 1788
Q = int(input())
N = [int(input()) for i in range(Q)]

def divisor_prod(n):
    m = 2
    s = set()
    while m*m <= n:
        if n%m == 0:
            s.add(m)
            s.add(n//m)
        m += 1
    ret = 1
    for a in s:
        ret *= a
    return ret

imos = [0]*(10**5+1)

for m in range(2,10**5+1):
    if divisor_prod(m) >= m*2:
        imos[m] += 1

for i in range(10**5):
    imos[i+1] += imos[i]

for q in N:
    print(imos[q])


Measured memory_bytes: 13788
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
# gcd
from fractions import gcd
# 切り上げ，切り捨て
from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
from collections import Counter
import math
from functools import reduce
# input関係の定義
# fin = open('in_3.txt', 'r')
# sys.stdin = fin
#
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def solve(N: int, d: "List[int]"):
    d.sort()
    print(d[N // 2] - d[N // 2 - 1])


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 78688
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 20:57:42 2019

@author: Yamazaki Kenichi
"""

S = input()

a,b = 0,0
for i in range(len(S)):
    if (int(S[i]) + i) % 2 == 0:
        a += 1
    else:
        b += 1
print(min(a,b))

Measured memory_bytes: 3316
a, b = [int(_) for _ in input().split(' ')]

def f0(n):
    m = n % 4
    if (m == 0):
        return n
    elif (m == 1):
        return 1
    elif (m == 2):
        return n + 1
    elif (m == 3):
        return 0

print(f0(b) ^ f0(a - 1))


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int n;
	string a;
	stringstream b;
	while (true) {
		cin >> n; if (!n)break;
		cin >> a;
		while (n-- > 0) {
			for (int i = 0; i < a.size();) {
				int cnt = 1;
				for (int j = 1; a[i] == a[i + j]; j++)
					cnt++;
				b << cnt << a[i];
				i += cnt;
			}
			b >> a;
			b.clear(stringstream::goodbit);
		}
		cout << a << endl;
	}
}

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

int main() {
  int a, b, c ;
  cin >> a >> b >> c;
    vector<int> vec = {a, b, c};
    sort(vec.begin(), vec.end());

    for (int i = 0; i < vec.size(); i++) ;

    if (vec.at(0)==5 && vec.at(1)==5 && vec.at(2)==7){
      cout << "YES" << endl;
    }
  else {
    cout << "NO" << endl;
  }
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    string s;
    cin >> s;
    bool f = true;
    if( s[0] != 'A' ) {
        f = false;

    }

    int c = 0;
    for( int i = 2; i < s.size() - 1; ++i ) {
        if( s[i] == 'C' ) ++c;

    }
    if( c != 1 ) f = false;

    for( int i = 1; i < s.size(); ++i ) {
        if( s[i] != 'C' && s[i] < 'a' ) f = false;

    }

    if( f ) cout << "AC";
    else cout << "WA";
    cout << endl;
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  
  int S = 0;
  for(int i = 0; i < N; i++){
    int x, y;
    cin >> x >> y;
    S += y - x + 1;
  }
  
  cout << S << endl;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    string S;
    vector<int> amin(26, 1e9);
    rep(i, n) {
        cin >> S;
        vector<int> a(26, 0);
        rep(j, S.size()) {
            a[S[j] - 'a']++;
        }
        rep(j, 26) {
            amin[j] = min(amin[j], a[j]);
        }
    }
    rep(i, 26) {
        rep(j, amin[i]) {
            cout << (char)(i + 'a');
        }
    }
    cout << "\n";
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 N          PIC 9(10).
01 i          PIC 9(10).
01 j          PIC 9(10).
01 flg        PIC 9(1) VALUE ZERO.
01 ans        PIC X(30).
01 zs         PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT N.
  PERFORM VARYING i FROM 1 BY 1 UNTIL 9 < i
    PERFORM VARYING j FROM 1 BY 1 UNTIL 9 < j
      IF i * j = N
        MOVE 1 TO flg
        EXIT PERFORM
      END-IF
    END-PERFORM
    IF 1 = flg
      EXIT PERFORM
    END-IF
  END-PERFORM.
  IF 1 = flg
    DISPLAY "Yes"
  ELSE
    DISPLAY "No"
  END-IF.
  STOP RUN.


Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U> bool chmax(T &a, U b) { if (a <= b) {a = b; return 1;} return 0; }
template <class T, class U>  bool chmin(T &a, U b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T>  ostream &operator<<(ostream &os, vector<T> &v) { os << "{"; rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); } os << "}"; return os; }

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
    ll x=0,y=0,z=0,n,m,ans=0,sum=0,k,w,Max=-1,Min=1e9+1;
    bool ok = true;
    string s,t;
    cin >> n;
    VI a(n);
    rep(i,n) { cin >> a[i]; }
    for(int i=-100; i<=100; i++){
      rep(j,n){
        ans += pow(a[j]-i,2);
      }
      chmin(Min,ans);
      ans=0;
    }
    cout << Min << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read( ){
	int x=0,y=1;char ch=' ';
	for(;(ch!='-' && (ch>'9' || ch<'0'));ch=getchar( ));
	if(ch=='-')y=-1,ch=getchar( );
	for(;ch>='0' && ch<='9';ch=getchar( ))x=x*10+ch-48;
	return x*y;
}
const int N=1e5+10;
struct node{
	int to,nex;
}e[N<<1];
int bgn[N],d[N],fr[N],sz[N],b[N];
int n,cnt;
vector<int>v;
void add(int x,int y){
	e[++cnt]=(node){y,bgn[x]};bgn[x]=cnt;
}
void dfs(int x,int k){
	d[x]=k;
	for(register int i=bgn[x];i;i=e[i].nex){
		int y=e[i].to;if(d[y])continue;
		fr[y]=x;dfs(y,k+1);
	}
}
void getsz(int x,int fa){
	sz[x]=1;
	for(register int i=bgn[x];i;i=e[i].nex){
		int y=e[i].to;if(y==fa)continue;
		getsz(y,x);sz[x]+=sz[y];
	}
}
int main( ){
	int x,y,z,k;
	n=read();
	for(register int i=1;i<n;++i){
		x=read();y=read();
		add(x,y);add(y,x);
	}
	dfs(1,1);
	int mn=0;
	for(register int i=1;i<=n;++i)if(d[i]>mn){
		mn=d[i];x=i;
	}
	for(register int i=1;i<=n;++i)d[i]=fr[i]=0;
	dfs(x,1);
	mn=0;
	for(register int i=1;i<=n;++i)if(d[i]>mn){
		mn=d[i];x=i;
	}
	getsz(x,0);
	int u=x;
	while(u){
		b[u]=1;	
		u=fr[u];
	}
	u=x;
	while(u){
		for(register int i=bgn[u];i;i=e[i].nex){
			int y=e[i].to;if(b[y])continue;
			if(sz[y]>1){
				puts("-1");return 0;
			}
		}
		v.push_back(sz[u]-sz[fr[u]]);
		u=fr[u];
	}
	for(register int i=0;i<v.size();++i){
		if(v[i]<v[v.size()-i-1])break;
		if(v[i]>v[v.size()-i-1]){
			reverse(v.begin(),v.end());
			break;
		}
	}
	x=0;
	for(register int i=0;i<v.size();++i){
		for(register int j=x+2;j<=x+v[i];++j)printf("%d ",j);
		printf("%d ",x+1);
		x=x+v[i];
	}
	
	return 0;
}


Measured memory_bytes: 9592
n = int(input())
a = list(map(int, input().split()))
ave_a = sum(a) / n
sa = 101
min_ind = 0
for i in range(n):
    if sa > abs(a[i] - ave_a):
        sa = abs(a[i] - ave_a)
        min_ind = i
print(min_ind)

Measured memory_bytes: 3060
from itertools import *

N,a,b,c = map(int,input().split())
L = [int(input()) for i in range(N)]

ans = float("inf")

products = product(range(4), repeat=N)

for prod in products :
    A = []
    B = []
    C = []
    
    for i,v in enumerate(prod) :
        if v == 1 :
            A.append(L[i])
        elif v == 2 :
            B.append(L[i])
        elif v == 3 :
            C.append(L[i])
    
    if len(A) * len(B) * len(C) == 0 :
        continue
    
    cost = 0
    
    for li in [A, B, C] :
        cost += (len(li)-1) * 10
    
    cost += abs(a-sum(A))
    cost += abs(b-sum(B))
    cost += abs(c-sum(C))
    
    ans = min(ans, cost)

print(ans)


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


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

  vector<int>hgyou(m);
  vector<int>wretu(m);

  //入力
  for (int i = 0; i < m; i++) {
    cin >> hgyou.at(i) >> wretu.at(i);
  }
  
  vector<int>cnt_g(300010, 0);

  for (int i = 0; i < m; i++) {
    cnt_g.at(hgyou.at(i))++;
  }

  //行の選択、checkが最終的に選択する行
  int check = 0, max = 0;
  for (int i = 0; i < cnt_g.size(); i++) {
    if(max < cnt_g.at(i)) {
      max = cnt_g.at(i);
      check = i;
    }
  }
  
  //行の選択を元に列の選択をする
  vector<int>cnt_r(300010);
  for (int i = 0; i < m; i++) {
    if (hgyou.at(i) != check) {
      cnt_r.at(wretu.at(i))++;
    }
  }
  int check2=0, max2=0;
  for(int i = 0; i < cnt_r.size(); i++) {
    if(max2 < cnt_r.at(i)) {
      max2 = cnt_r.at(i);
      check2 = i;
    }
  }
  int ans = max + max2;





  vector<int>cnt_r2(300010, 0);

  for (int i = 0; i < m; i++) {
    cnt_r2.at(wretu.at(i))++;
  }

  //行の選択、checkが最終的に選択する行
  int Check = 0, Max = 0;
  for (int i = 0; i < cnt_r2.size(); i++) {
    if(Max < cnt_r2.at(i)) {
      Max = cnt_r2.at(i);
      Check = i;
    }
  }
  
  //行の選択を元に列の選択をする
  vector<int>cnt_g2(300010);
  for (int i = 0; i < m; i++) {
    if (wretu.at(i) != Check) {
      cnt_g2.at(hgyou.at(i))++;
    }
  }
  int Check2=0, Max2=0;
  for(int i = 0; i < cnt_g2.size(); i++) {
    if(Max2 < cnt_g2.at(i)) {
      Max2 = cnt_g2.at(i);
      Check2 = i;
    }
  }
  int ans2 = Max+Max2;
  if (ans >= ans2) cout << ans << endl;
  else cout << ans2 << endl;
  }

Measured memory_bytes: 10376
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int n = (int)Math.floor(Math.sqrt(sc.nextLong()));
		System.out.println(n*n);
	}
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int r=scan.nextInt();
		int g=scan.nextInt();
		int b =scan.nextInt();

		if((r*100+g*10+b)%4==0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}
}


Measured memory_bytes: 21844
def sq(a, b, mod):  # aのb乗を剰余,kは初期値#20191116-D-Knight
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10 ** 9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer


X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
else:
    n = (2 * Y - X) // 3
    m = (2 * X - Y) // 3
    if n < 0 or m < 0:
        print(0)
    else:
        print(nCk(n + m, n))


Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
	int n[100][100],r,c,i,j,t[100],v[100],b=0;
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d",&n[i][j]);
			t[i]+=n[i][j];
			v[j]+=n[i][j];
			b+=n[i][j];
		}
	}
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			printf("%d ",n[i][j]);
		}
		printf("%d\n",t[i]);
	}
	for(i=0;i<=c;i++){
		if(i!=c){
			printf("%d ",v[i]);
		}else{
			printf("%d\n",b);
		}
	}
	return 0;
}

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

int64_t beki(int64_t n){
 int64_t s,ans;
  s=(n*n)%1000000007;
  ans=(s*n)%1000000007;
  return ans;}

int main() {
int64_t k,a;
  a=0;
  cin>>k;
  vector<int64_t> ans(k);
  ans.at(k-1)=1;
  for(int64_t i=k-2;i>=0;i--){
  ans.at(i)=beki(k/(i+1));
    for(int64_t j=1;(i+1)*j<=k;j++){
    ans.at(i)=ans.at(i)-ans.at((i+1)*j-1);
     }
    ans.at(i)=ans.at(i)+beki(k/(i+1));
  }
  for(int64_t i=0;i<k;i++){a=a+(i+1)*ans.at(i);
  while(a>=1000000007){a=a-1000000007;}}
  cout<<a<<endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
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; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int main() {
	int N; cin >> N;
	vector<string> S(N); cin >> S;
	map<string, int> mp;
	int maxv = 0;
	for (auto &s : S) {
		mp[s]++;
		chmax(maxv, mp[s]);
	}
	
	vector<string> ans;
	for (auto &v : mp) {
		if (v.second == maxv) {
			ans.push_back(v.first);
		}
	}
	sort(begin(ans), end(ans));
	
	cout << ans;
	return (0);
}

Measured memory_bytes: 28404
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int a, b, h, m;
	cin >> a >> b >> h >> m;

	long double rad = PI * 2 *
		((long double)h / 12.0 + ((long double)m / 60.0) / 12.0
			- (long double)m / 60.0);

	long double rsq = (long double)(a * a + b * b) -
		(long double)(2 * a * b) * cosl(rad);

	out(sqrt(rsq));

	return 0;
}

Measured memory_bytes: 4180
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


ll n,m;
vll G[100010];
ll color[100010]={};
bool b[100010];



bool dfs(ll s,ll c){
    color[s]=c;
    for(ll t:G[s]){
        if(color[t]==c) return false;
        if(color[t]==0 && !dfs(t,-c)) return  false;
        }
    return true;
}


bool solve(){
    rep(i,n){
        if(color[i]==0){
            if(!dfs(i,1)){
                return false;
            }
        }
    }
    return true;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;


    cin>>n>>m;
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    if(solve()){
        ll a=0,b=0;
        rep(i,n){
            if(color[i]==1) a++;
            else b++;
        }
        cout<<a*b-m<<endl;
    }
    else{
        cout<<n*(n-1)/2-m<<endl;
    }
    return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  string s;
  cin>>s;
  if((s.at(0)==s.at(1)&&s.at(2)==s.at(3)&&s.at(0)!=s.at(2))||
      (s.at(0)==s.at(2)&&s.at(1)==s.at(3)&&s.at(0)!=s.at(1))||
      (s.at(0)==s.at(3)&&s.at(1)==s.at(2)&&s.at(0)!=s.at(2))){
    
    ou("Yes");
    return 0;
  }
  ou("No");
  return 0;
}

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

int main() {
    int N, Q;
    cin >> N >> Q;
    string s;
    cin >> s;

    vector<char> t(Q), d(Q);
    for (int i = 0; i < Q; i++) {
        cin >> t[i] >> d[i];
    }
    int left = -1, right = N;
    for (int i = Q - 1; i >= 0; i--) {
        if (d[i] == 'L' && t[i] == s[left + 1]) left++;
        if (d[i] == 'R' && t[i] == s[right - 1]) right--;
        if (d[i] == 'L' && t[i] == s[right]) right++;
        if (d[i] == 'R' && t[i] == s[left]) left--;
    }
    cout << max(0, right - left - 1) << '\n';
}


Measured memory_bytes: 900
#include <stdio.h>

int main() {
	long long int A, B, K;
	long long int a,b;
	scanf("%lld%lld%lld",&A,&B,&K);
	if (A + B < K) {
		a = 0, b = 0;
	}
	else if (A>=K) {
		a = A - K;
		b = B;
	}
	else{
		a = 0;
		b = B - (K - A);
	}
	printf("%lld %lld",a,b);
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int a[n], b[n], c[n-1];
	for(int i=0; i<n; i++){
		cin >> a[i];
		a[i]--;
	}
	for(int i=0; i<n; i++) cin >> b[i];
	for(int i=0; i<n-1; i++) cin >> c[i];

	int ans=0;
	for(int i=0; i<n; i++) ans+=b[a[i]];
	for(int i=0; i<n-1; i++){
		if(a[i+1]==a[i]+1) ans+=c[a[i]];
	}
	cout << ans << endl;
	return 0;
}

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 r; cin >> r;
	cout << 3*r*r << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
	int cmp(int a,int b)
	{
		return a<b;
	}
int main()
{
	int n;
	int a[2000]={0};
	while(~scanf("%d",&n))
	{
		int total=0;
		for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
		sort(a,a+n,cmp);
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				for(int l=j+1;l<n;l++)
				if(a[i]+a[j]>a[l])
				total++;
			}
		}
		printf("%d\n",total);
	}
}

Measured memory_bytes: 128
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b


from collections import Counter

cnt = Counter()
s = input()
for c in s:
    cnt[c] += 1

if len(cnt.keys()) == 1:
    print(0)
else:
    print(min(cnt.values()) * 2)

Measured memory_bytes: 3564
N = gets.chomp.to_i
A = gets.chomp.split.map{|i| i.to_i}.sort

def isValid(arr)
  if N.odd?
    return false if arr.any?{|i| i.odd?}
    return false if arr.select{|i|i==0}.length > 1
  else
    return false if arr.include?(0)
    return false if arr.any?{|i| i.even?}
  end

  i = 0
  while i < arr.length
    return false if arr[i] != arr[i+1]
    i += 2
  end
  true
end

def calc
  if N.odd?
    a = A.shift
    return 0 if a != 0
  end
  return 2 ** (A.length / 2)if isValid(A)
  return 0
end

puts calc % (10**9 + 7)


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

int fifc = 0;
int sevc = 0;
vector<int> vec(3);
int main(){

  for (int i = 0; i < 3; i++) {
    cin >> vec.at(i);
  }
  for(int i = 0;i < 3; i++){
  if(vec.at(i) == 5)fifc++;
  else if(vec.at(i) == 7)sevc++;
  }
  if(fifc == 2 && sevc ==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

################################

n,m,l = map(int,input().split()) #n:頂点数　w:辺の数

cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(m):
    x,y,z = map(int,input().split())
    cost[x-1][y-1] = z
    cost[y-1][x-1] = z

kyolist=[]
for i in range(n):
    kyolist.append(dijkstra(i,n,m,cost))
zerolist=[]

for i in range(n):
    nowzero=[]
    for j in range(n):
        if i!=j and kyolist[i][j]<=l:
            nowzero.append(j)
    zerolist.append(nowzero)


llist=[]
for i in range(n):
    nowlist=[1000]*n
    nowlist[i]=0
    next=[i]
    now=0
    while next!=[]:
        newnext=[]
        for nx in next:
            for ima in zerolist[nx]:
                if nowlist[ima]==1000:
                    nowlist[ima]=now
                    newnext.append(ima)
        next=newnext
        now+=1
    llist.append(nowlist)

q=int(input())
for i in range(q):
    s, t = (int(i) for i in input().split())
    kotae=llist[s-1][t-1]
    if kotae==1000:
        print(-1)
    else:
        print(kotae)

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

int main() {
 UL N; scanf("%u",&N);
 int A[200000]; rep(i,N) scanf("%d",&A[i]);
 UL M; scanf("%u",&M);
 int B[200000]; rep(i,M) scanf("%d",&B[i]);
 UL q=0;
 bool ok=true;
 rep(p,M){
  while(q<N-1){
   if(B[p]>A[q]) q++; else break;
  }
  if(B[p]!=A[q]) ok=false;
 }
 printf(ok?"1\n":"0\n");
 return 0;
}




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

int main()
{
	int A,B;

	cin >> A >> B;

	if (A % 2 && B % 2 == 1) {
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
a,b=map(int,input().split())

def fact(n):
  temp=n
  arr=[]
  for i in range(2,int(-(-n**0.5//1))+1):
    if temp%i==0:
      
      while temp%i==0:
        
        temp//=i
      arr.append(i)
      
  if temp!=1:
    arr.append(temp)
  if arr==[]:
    arr.append(n)
  return arr

c=fact(a)
d=fact(b)
e=[1]

  
for i in range(len(c)):
  if c[i]  in d:
    e.append(c[i])

e=set(e)    
print(len(e))

    

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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll k,t;
  cin >> k >> t;
  priority_queue<pll> que;
  vll a;
  REP(i, t){
    ll b;
    cin >> b;
    que.push(pll(b,i));
  }

  while(que.top().FI>0){
    pll b = que.top();
    que.pop();
    if(que.size()==0){
      while(b.FI>0){
        b.FI--;
        a.push_back(b.SE);
      }
      break;
    }


    pll c = que.top();
    que.pop();
    if(c.FI!=0){
      a.push_back(b.SE);
      a.push_back(c.SE);
      b.FI--;
      c.FI--;
      que.push(b);
      que.push(c);
    }
    else{
      while(b.FI>0){
        b.FI--;
        a.push_back(b.SE);
      }
    }
  }

  ll ans = 0;
  REP1(i, k){
    if(a[i]==a[i-1])
      ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007

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

    double l;
    cin>>l;

    cout<<fixed<<setprecision(10)<<((l/3.0)*(l/3.0)*(l/3.0));
     
}

Measured memory_bytes: 256
import Text.Regex.Posix
import Text.Printf

main :: IO ()
main = do
  [a, b] <- (map read . words) <$> getLine :: IO [Int]
  s <- getLine
  let regex = printf "[0-9]{%d}-[0-9]{%d}" a b :: String
  putStrLn $ if s =~ regex then "Yes" else "No"


Measured memory_bytes: 508
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var (D, N) = ReadLine().Split(' ').Select(int.Parse).ToArray();

        static long Pow(long x, long y) => (y == 0) ? 1 : x * Pow(x, y - 1);
        long DivideCount(long x, long y) => (x % y != 0) ? 0 : 1 + DivideCount(x / y, y);

        var b = Pow(100, D);
        var ans = 0L;

        for (int i = 0; i < N; i++)
        {
            do
            {
                ans += b;
            } while (DivideCount(ans, 100) != D);
        }

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28196
#include <cstdio>

int zari(int i,int j){
  return (i*(i+1)/2+j);
}
int n,m;
int maps[5000*2505]={0};
int main(void){

  //釘(i,j)をmaps[i*(i+1)/2+j]とする。
  scanf("%d%d",&n,&m);
  int i,j;
  int a,b,c;
  for(i=0;i<m;i++){
    scanf("%d%d%d",&a,&b,&c);
    a+=1;//b--;
    maps[zari(a,b)]+=1;
    maps[zari(a,b+1)]+=-1;
    maps[zari(a+c+1,b)]+=-1;
    maps[zari(a+c+2,b+1)]+=1;
    maps[zari(a+c+1,b+c+2)]+=1;
    maps[zari(a+c+2,b+c+2)]+=-1;
    }
 


  for(i=1;i<=n+3;i++){
    for(j=1;j<=i;j++){
      maps[zari(i,j)]+=maps[zari(i,j-1)];
    }
  }


  for(j=0;j<=n+3;j++){

    for(i=j;i<=n+3;i++){
       maps[zari(i,j)]+=maps[zari(i-1,j)];
    }

 
  }

  int ans=0;
  for(i=1;i<=n+3;i++){
    //for(j=0;j<i*2;i++)printf("\x0020");
    for(j=1;j<=i;j++){
       maps[zari(i,j)]+=maps[zari(i-1,j-1)];
      if(maps[zari(i,j)]!=0)ans++;
      //printf("%d\x0020",maps[zari(i,j)]);
    }
    //printf("\n");
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 49944
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextLong();
                                   
            Console.WriteLine(2.00000000000d * 3.14d * n);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 27624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define f first
#define s second

int h, w;
string g[1005];
int dp[1005][1005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout);
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> g[i];
	}
	ll MOD = 1e9 + 7;
	dp[0][0] = 1;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(i > 0 && g[i - 1][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j]) % MOD;
			if(j > 0 && g[i][j - 1] == '.') dp[i][j] = (dp[i][j - 1] + dp[i][j]) % MOD;
			if(g[i][j] == '#') dp[i][j] = 0;
		}
	}
	cout << dp[h - 1][w - 1] << endl;	
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 5248
eval"A,B,C,D,E,F="+`tr \\  ,`;d={};f=->a,b=0{a*100+b>F||a*E<b||d[[a*100+b,b]]||=(f[a+A,b];f[a+B,b];f[a,b+C];f[a,b+D];b.quo a)};f[A];f[B];p *d.invert.max[1]

Measured memory_bytes: 4184
n = int(input())
L = list(map(int, input().split()))
x = [0] * 1010
for l in L:
  x[l] += 1

ans = 0;
for a in range(1, 1001):
  if x[a] == 0:
    continue
  for b in range(a, 1001):
    if x[b] == 0:
      continue
    for c in range(b, 1001):
      if x[c] == 0:
        continue
      if c >= a + b:
        break
      if a == b == c:
        ans += x[a] * (x[b]-1) * (x[c]-2) // 6
      elif a == b:
        ans += x[a] * (x[b]-1) * x[c] // 2
      elif b == c:
        ans += x[a] * x[b] * (x[c]-1) // 2
      else:
        ans += x[a] * x[b] * x[c]

print(ans)

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

int main() {

    long long h, w;
    cin >> h >> w;

    long long ans = 1000000000000;
    for(int i = 1; i < h; i++) {
        long long A = i * w;
        long long B = (h - i) * (w / 2);
        long long C = (h - i) * (w - w / 2);
        ans = min(ans, max(max(A, B), C) - min(min(A, B), C));
        B = (h - i) / 2 * w;
        C = ((h - i) - (h - i) / 2) * w;
        ans = min(ans, max(max(A, B), C) - min(min(A, B), C));
    }

    for(int i = 1; i < w; i++) {
        long long A = i * h;
        long long B = (w - i) * (h / 2);
        long long C = (w - i) * (h - h / 2);
        ans = min(ans, max(max(A, B), C) - min(min(A, B), C));
        B = (w - i) / 2 * h;
        C = ((w - i) - (w - i) / 2) * h;
        ans = min(ans, max(max(A, B), C) - min(min(A, B), C));
    }

    cout << ans << endl;
}


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

int main()
{
    int n,i,l;
    char a[10005],b[10005];
    while(scanf("%d",&n)!=EOF)
    {
        l=0;
        getchar();
        for (i=0;i<n;i++) scanf("%c",&a[i]);
        int o=0;
        for (i=0;i<n;i++)
        {
            if (a[i]=='(') o++;
            else
            {
                if (o) o--;
                else b[l++]='(';
            }
        }
        for (i=l-1;i>=0;i--) printf("%c",b[i]);
        for (i=0;i<n;i++) printf("%c",a[i]);
        while (o--) printf(")");
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256