akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans


void solve() {
}

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

    int a, b;
    cin >> a >> b;

    if (a <= 0 && b >= 0) {
        cout << "Zero" << endl;
        return 0;
    }
    if (b < 0) {
        if ((a - b) % 2 == 0) {
            cout << "Negative" << endl;
            return 0;
        }
    }
    cout << "Positive" << endl;

    solve();
    return 0;
}


Measured memory_bytes: 3632
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(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;
}

int modpow(int x, int n, const int mo) {
	int res = 1;
	while (n > 0) {
		if (n & 1) (res *= x) %= mo;
		(x *= x) %= mo;
		n >>= 1;
	}
	return res;
}

int inverse(int x, const int mo) {
	return modpow(x, mo - 2, mo);
}

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

	COMinit();

	int N, M;
	cin >> N >> M;

	int ans = 1;
	ans *= COM(M, N);
	ans *= fac[N];
	ans %= MOD;
	
	int res = 0;
	rep(i, 0, N + 1)
	{
		int tres = fac[M - i];
		tres *= inverse(fac[M - i - (N - i)], MOD);
		tres %= MOD;
		tres *= COM(N, i);
		tres %= MOD;
		if (i % 2 == 0)res += tres;
		else res = (res - tres + MOD);
		res %= MOD;
	}

	ans *= res;
	ans %= MOD;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 15604
x, n = map(int, input().split())
p = list(map(int, input().split()))
p = set(p)

cand1 = x
while cand1 in p:
    cand1 -= 1

cand2 = x
while cand2 in p:
    cand2 += 1

ans = cand1 if abs(cand1 - x) <= abs(cand2 - x) else cand2
print(ans)


Measured memory_bytes: 61568
#include <cstdio>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN=1005;
LL a[MAXN];
void init()
{
    a[0]=2;
    a[1]=1;
    for(int i=2;i<=90;++i)
    {
        a[i]=a[i-1]+a[i-2];
    }
}
int main()
{
    init();
    int n;
    scanf("%d", &n);
    printf("%lld\n", a[n]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

#include<sstream>
using namespace std;
bool furui[246912];
int main(){
	int n;
	int j;
	int count;
	stringstream s;
	for(int i=2;i<=246912;i++){
		if(!furui[i]){
			j=i;
			while(j<=246912){
				
				furui[j]=true;
				j+=i;
			}
			furui[i]=false;
		}
	}

	while(cin>>n,n>0){
	count=0;
	for(int i=n+1;i<=n*2;i++)if(!furui[i])count++;
	s << count <<endl;
	}
	cout<<s.str();

	return 0;
}

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

int main(){
 int a=0;
 int b=0;
int D[3];
  cin >> D[0] >> D[1] >> D[2];
  sort(D,D+3,greater<int>());
    a=D[0]-D[1];
       b+=a;
       D[2]+=a;
      a= D[0]-D[2];
      if(a%2==1&&a!=0){
        b+=2+a/2;

      }else {
          b+=a/2;
      }
    
cout << b;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b;
  cin>>a>>b;
  if((a==1 && b==2) ||  (a==2 && b==1) )
    cout<<"3";
  else if((a==3 && b==1)||(a==1 && b==3))
    cout<<"2";
  else
    cout<<"1";
}

Measured memory_bytes: 256
function main(input) {
    const args = input.split(' ');
    var N = parseInt(args[0], 10);

    var flag = 0;
    var count = 1;

    var store = [];
    store.push(N);

    while(1) {
        count += 1;
        if(N % 2 === 0) {
            N = N / 2;
        } else {
            N = 3 * N + 1;
        }
        if(store.indexOf(N) !== -1) {
            console.log(count);
            break;
        } 
        store.push(N);
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
import java.util.*;
public class Main{
	public static void main(String args[]){
    	Scanner s = new Scanner(System.in);
      	int t[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    	int k = s.nextInt();
      System.out.println(t[k-1]);
    }
}

Measured memory_bytes: 22996
import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List

main :: IO()
main = do
  n <- getLine
  x <- map read . words <$> getLine
  let (m, k) = slv x
  printf "%d %d\n" m k

slv :: [Integer] -> (Integer, Integer)
slv x = (maxx, fst ans)
  where maxx = maximum x 
        middleVal = (fromIntegral maxx) / (fromIntegral 2)
        ans = minimumBy (\(_,a) (_,b) -> compare a b) $ zip x $ map (\l -> calc l maxx middleVal) x
        
calc :: Integer -> Integer -> Double -> Double
calc l maxVal midVal | l == maxVal = 10^10
                     | otherwise = abs(realToFrac l - midVal)


Measured memory_bytes: 42108
import kotlin.*

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val a = sc.nextInt()
        val x = sc.intList()

        val dp = Array(51) { Array(2501) { 0L } }
        dp[0][0] = 1
        for (i in 0 until n) {
            for (j in i downTo 0) {
                for (k in 0..50 * j) {
                    dp[j + 1][k + x[i]] += dp[j][k]
                }
            }
        }

        var ans = 0L
        for (i in 1..n) {
            val j = i * a
            ans += dp[i][j]
        }

        println(ans)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        if (ptr >= l.size) {
            var s: String
            do {
                s = readLine()!!
            } while (s.isEmpty())
            l = s.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        val s = readLine()!!
        return if (s.isEmpty()) listOf() else s.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 46024
import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import Control.Monad
import Control.Applicative

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 (a:b:_) = (a,b)
listToTuple3 (a:b:c:_) = (a,b,c)
listToTuple4 (a:b:c:d:_) = (a,b,c,d)



main :: IO ()
main = do
  (n:k:_) <- getLine >>= return . map read . words :: IO [Int]
  print $ if mod n k == 0 then 0 else 1
  

  return ()


Measured memory_bytes: 508
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
A = [0]
B = [0]
for i in range(n):
    A.append(A[-1]+a[i])
for i in range(m):
    B.append(B[-1]+b[i])

for i in range(n+1):
    if A[i] <= k:
        ans = max(i+bisect.bisect(B,k-A[i])-1,ans)
    else:
        break

for i in range(m+1):
    if B[i] <= k:
        ans = max(i+bisect.bisect(A,k-B[i])-1,ans)
    else:
        break
print(ans)

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

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

string S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	int ret[2]={};
	FOR(i,S.size()) {
		if(S[i]-'0'==(i%2)) ret[0]++;
		if(S[i]-'0'!=(i%2)) ret[1]++;
	}
	cout<<min(ret[0],ret[1])<<endl;
}


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


Measured memory_bytes: 512
#include <cstdio>

const int MAXN = 1E5 + 10;

int n;
int a[MAXN];

int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	int cnt = 0;
	for (int i = 1; i <= n; ++i)
		cnt += a[a[i]] == i;
	printf("%d\n", cnt >> 1);
	return 0;
}


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

int main() {

  int n;
  cin >> n;
  
  vector<int> t(n);
  rep(i,n) cin >> t[i];
  
  sort(t.begin(), t.end());
  
  t[n-1] /= 2;
  
  int ans = 0;
  rep(i,n) ans += t[i];
  cout << ans << endl;
  
  
  
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

from collections import deque

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

def gcd(n,m):
    while m:
        n,m = m, n%m
    return n

def lcm(n,m):
    return n*m//gcd(n,m)

def main():
    N = int(input())
    # N,M = linput()
    # vA = linput()
    # S = input()
    # mX = [linput() for _ in [0,]*N]

    # vR = []
    # vR_app = vR.append

    pp = "a"

    vQ = deque([])
    vQ_app = vQ.append

    vQ_app(pp)
    while vQ:
        pp = vQ.popleft()
        if len(pp)>=N: break
        ma = max(ord(s) for s in pp)
        for i in range(ord('a'), ma+2):
            vQ_app(pp + chr(i))

    # res = 0
    # res = -(-N//M)
    vQ.appendleft("a" * N)

    res = vQ
    print(*sorted(res), sep="\n")

main()


Measured memory_bytes: 14880
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int A,B;
  cin>>A>>B;
  if((A+B)%2 == 0)
  {
    cout<<(A+B)/2<<endl;
  }
  else
  {
    cout<<"IMPOSSIBLE"<<endl;
  }
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i

road = Array.new(n + 1) {[]}
(n - 1).times do
    a, b, c = gets.split.map(&:to_i)
    road[a] << [b, c]
    road[b] << [a, c]
end

q, k = gets.split.map(&:to_i)

dis = Array.new(n + 1)
dis[k] = 0
queue = [k]

while now = queue.shift
    road[now].each do |t, d|
        next if dis[t]
        dis[t] = dis[now] + d
        queue << t
    end
end

q.times do
    x, y = gets.split.map(&:to_i)
    puts dis[x] + dis[y]
end

Measured memory_bytes: 30332
#include <iostream>
#include <string>

int main(int argc, char const* argv[])
{
    std::string S;
    std::cin >> S;
    int high, low;
    high = std::stoi(S.substr(0, 2));
    low = std::stoi(S.substr(2, 2));

    bool b0, b1;
    b0 = (high <= 12 && 0 < high);
    b1 = (low <= 12 && 0 < low);

    if (b0 && b1) {
        std::cout << "AMBIGUOUS" << std::endl;
    }
    else if (b0) {
        std::cout << "MMYY" << std::endl;
    }
    else if (b1) {
        std::cout << "YYMM" << std::endl;
    }
    else {
        std::cout << "NA" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[0] << c[0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define crap ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846264338327950288419716939937510
#define pb(a) push_back(a)
#define pf(a) push_front(a)

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define MAXN   10000001 
  
// stores smallest prime factor for every number 
int spf[MAXN]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 
int get_count(int x) 
{ 
    unordered_map<ll,ll> ret ; 
    while (x != 1) 
    { 
        ret[spf[x]]++; 
        x = x / spf[x]; 
    } 
    ll ans = 1;
    for(auto it = ret.begin() ; it!=ret.end() ; ++it)
    {
    	ans *= (it->second+1) ;
	}
	return ans ;
} 
  
int main()
{
	crap;
	sieve() ;
	int n;
	cin >> n;
	ll ans = 0;
	ll i,j ;
	vector <ll> arr(n+1,2) ;
	for(i=2;i<=n;++i)
	{
		for(j=i+i;j<=n;j+=i)
			arr[j]++ ;
	}
	arr[1] = 1;
	for(int i = 1;i<=n;++i)
	{
//		cout << i sp << get_count(i) endl ;
//		ans += i*get_count(i) ;
		ans += i*arr[i] ;
	}
	cout << ans endl ;
	return 0;
}

Measured memory_bytes: 120416
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(){
	const int INF=1<<29;
	for(int n,i,j,f;scanf("%d",&n),n;){
		vector<pair<int,int> >v(n+1);
		vector<vector<int> >m(n+1);
		for(int i=0;i<=n;i++){
			if(i)scanf("%d%d",&v[i].first,&v[i].second);
			m[i].resize(4),fill(m[i].begin(),m[i].end(),INF);
		}
		m[0][0]=0;
		for(m[0][0]=i=0;i<n;i++){
			for(f=j=0;j<4;j++)if(m[i][j]<INF){
				int d=abs(v[i+1].first-v[i].first),dt=v[i+1].second-v[i].second;
				if(j<3&&d*(j+1)<=dt)f=m[i+1][j+1]=min(m[i+1][j+1],m[i][j]+d);
				if(v[i+1].first+v[i].first*(j+1)<=dt)f=m[i+1][1]=min(m[i+1][1],m[i][j]+v[i+1].first+v[i].first);
			}
			if(!f)break;
		}
		if(i<n)printf("NG %d\n",i+1);
		else printf("OK %d\n",v[n].first+*min_element(m[n].begin(),m[n].end()));
	}
}

Measured memory_bytes: 1036
# AOJ ITP2_8_B: Map: Delete
# Python3 2018.6.24 bal4u

dict = {}
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = a[1]
	if a[0] == '0':	dict[ki] = int(a[2])
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	else:
		if ki in dict: dict[ki] = 0



Measured memory_bytes: 37508
#include <bits/stdc++.h>
using namespace std;
map <int , long long> mp ;
vector <int> v;
int main()
{
cin.tie(nullptr);
    ios::sync_with_stdio(false);
int n ; cin >> n ;
for (int i = 0 ; i< n ; i++){
    int a ; cin >> a ;
    mp[a]++;
    v.push_back(a);
}
long long sum = 0 ;
for (auto it=mp.begin(); it!=mp.end(); ++it){
    sum += it->second*(it->second-1) / 2;
}
for (int i = 0 ; i < n ; i ++){
    int a= v[i];
    long long ans = sum - (mp[a]*(mp[a]-1))/2;
    ans += ((mp[a]-1)*(mp[a]-2))/2;
    cout << ans << endl ;
}
}


Measured memory_bytes: 10356
import copy
from collections import deque
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = inf

D, G = LI()

P = [0]*D
c = [0]*D
p = [0]*D

for i in range(D):
    P[i], c[i] = LI()

full = [0]*D
for i in range(D):
    full[i] = 100*(i+1)*P[i] + c[i]

for i in range(2**D):
    ansC = int(0)
    p = copy.deepcopy(P)
    candi = [i for i in range(D)]
    cur = int(0)
    for j in range(D):
        if ((i >> j) & 1):
            cur += full[D-j-1]
            ansC += p[D-j-1]
            candi.remove(D-j-1)

    remain = G - cur
#    print(candi,remain,ansC)
    while(candi and remain>0):
        remain -= (candi[-1]+1)*100
        p[candi[-1]] -=1
#        print(p)
        ansC +=1
        if p[candi[-1]]==0:
            candi.remove(candi[-1])

    ans = min(ansC,ans)

print(ans)




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

struct st{
	int c1,c2,Min1,Min2;
};
int main(){
	int n;cin>>n;
	vector<st>L,R;
	rep(i,n){
		string s;cin>>s;
		int c1=0,c2=0,Min1=0,Min2=0;
		for(char c:s){
			if(c=='(')c1++;
			else c1--;
			Min1=min(Min1,c1);
		}
		for(int i=s.size()-1;i>=0;i--){
			if(s[i]==')')c2++;
			else c2--;
			Min2=min(Min2,c2);
		}
		if(c1>=0)L.push_back({c1,c2,Min1,Min2});
		else R.push_back({c1,c2,Min1,Min2});
	}
	sort(L.begin(),L.end(),[](st a,st b){return a.Min1>b.Min1;});
	sort(R.begin(),R.end(),[](st a,st b){return a.Min2<b.Min2;});
	int cnt=0;
	for(auto s:L){
		if(cnt+s.Min1<0){puts("No");return 0;}
		cnt+=s.c1;
	}
	for(auto s:R){
		if(cnt+s.Min1<0){puts("No");return 0;}
		cnt+=s.c1;
	}
	if(cnt)puts("No");
	else puts("Yes");
}

Measured memory_bytes: 19064
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;

long long factorial(long long i){ // 階乗
 if(i > 0)
   return i * factorial(i-1);
 else
   return 1;
}
//// a^n mod
long long modpow(long long a, long long n, long long mod) {
 long long res = 1;
 while (n>0) {
   if(n & 1) res = res * a % mod;
   a = a * a % mod;
   n >>= 1;
 }
 return res;
}

//// a^(-1) mod
long long modinv(long long a, long long mod) {
 return modpow(a, mod-2, mod);
}

int main() {
	const ll mod = 1000000000 + 7;
	string S;
	cin >> S;
	ll keta = 0;
	int head = 0;
	ll cnt = 1;
	vector<vector<ll>> dp(S.size(), vector<ll>(13, 0)); 
	vector<vector<int>> p(13, vector<int>(13, 0)); // 
	// p[i][j] : i*10 + X のうちあまりがjになるものの数

	for(int i=0; i<130; i++) {
		int ten = i/10; // 10, 100のくらい
		int q = i%13;
		p[ten][q] += 1;
	}
	// dp[i][j] 13で割ったあまりがj 

	// 初期化
	if(S[0]=='?') {
		rep(i, 10) {
			dp[0][i] = 1;
		}
	} else {
		int s0 = (int)(S[0]-'0');
		dp[0][s0] = 1;
	}

	for(int i=1; i<S.size(); i++) {
		if(S[i]=='?') {
			rep(j, 13) {
				rep(k, 13) { //k: 一桁前のあまり, j: 次のあまり
					dp[i][j] += (dp[i-1][k]*p[k][j])%mod;
					dp[i][j] %= mod;
				}
			}
		} else {
			int Si = (int)(S[i]-'0');
			rep(j, 13) {
				rep(k, 13) {
					if((k*10+Si)%13 == j)	{
						dp[i][j] += dp[i-1][k];
						dp[i][j] %= mod;
					}
				}
			}
		}
	}
	
	// rep(i, 13) {
	// 	cout << dp[S.size()-1][i] << ' ';
	// }
	// cout << endl;
	
	cout << dp[S.size()-1][5] << endl;

  return 0;
}

Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    int ans = 0;
    for (int i = 0; i < 5; i++) {
        int x;cin >> x;
        if(x == 0) ans = i + 1;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    int ans = min(min((x+499)/500*b, (x+999)/1000*a), x/1000*a+(x%1000+499)/500*b);
    printf("%d\n", ans);
}


Measured memory_bytes: 3228
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int A[50];

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
    }
    sort(A, A + N, greater<>());
    bool flag = true;
    int ans = 0;
    while (flag) {
        flag = false;
        rep(i, N) {
            if (A[i] >= N) {
                flag = true;
                int cnt = A[i] / N;
                A[i] -= (N + 1) * cnt;
                rep(j, N) {
                    A[j] += cnt;
                }
                ans += cnt;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

vector<int> v[101];
bool p[101];

int dfs(int x){
  if(p[x]){
    return 0;
  }else{
    p[x]=true;
    int m=0;
    for(int i=0;i<v[x].size();i++){
      m=max(m,dfs(v[x][i]));
    }
    p[x]=false;
    return m+1;
  }
}

int main(){
  for(int n;cin>>n,n;){
    for(int i=1;i<=100;i++){
      v[i].clear();
    }
    while(n--){
      int a,b;
      cin>>a>>b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    int r=0;
    for(int i=1;i<=100;i++){
      r=max(r,dfs(i));
    }
    cout<<r<<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a[5],ans=0;
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  sort(a,a+3);
  ans=abs(a[0]-a[1])+abs(a[2]-a[1]);
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3616
import itertools

nums = [0,1,2,3,4]
kumi = list(itertools.permutations(nums))

dishes = [int(input()) for _ in range(5)]

Minimum = 99999

for i in range(len(kumi)):
    temp = 0
    for j in range(5):
        if temp % 10 == 0:
            temp += dishes[kumi[i][j]]
        else:
            temp = temp + 10 - (temp % 10)
            temp += dishes[kumi[i][j]]
    Minimum = min(Minimum, temp)

print(Minimum)


Measured memory_bytes: 3064
import math
n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
count = 0
for i in range(n):
  for j in range(i + 1, n):
    tmp = 0.0
    for k in range(d):
      tmp += (X[j][k] - X[i][k]) ** 2
    tmp = math.sqrt(tmp)
    if tmp.is_integer():
      count += 1
print(count)

Measured memory_bytes: 3064
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

  static int N;
  static int K;
  static long Q;
  static int A;
  static int B;
  static long C;
  static double min = 9999999;
  static long ans = 0;

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


    int A = scanner.nextInt();
    int B = scanner.nextInt();
    
    if(A <= 5){
      System.out.println(0);
    }else if(A <=12){
      System.out.println(B / 2);
    }else{
      System.out.println(B);
    }
  }
}


Measured memory_bytes: 21844
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            y = 500 * i + 100 * j + 50 * k
            if y == x:
                cnt += 1
                
print(cnt)

Measured memory_bytes: 3064
W, H = map(int, input().split( ))
if W ==1 or H ==1:
    ans = 1
    print(ans)

elif W % 2 ==0 or H % 2 ==0:
    print(int(0.5*W*H))

elif W % 2 !=0 and H %2 !=0:
    print(int(0.5*(W*H+1)))

Measured memory_bytes: 3060
def get_next_int():
    return int(float(input()))
def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])

def main():
    n = get_next_int()
    numbers = get_next_ints()
    
    minimum_number = abs(numbers[0])
    
    count_of_minus = 0
    total = 0
    
    for number in numbers:
        if number < 0:
            count_of_minus += 1
        abs_number = abs(number)
        total += abs_number
        if abs_number < minimum_number:
            minimum_number = abs_number
        
    if count_of_minus % 2 == 1:
        total -= minimum_number * 2
    
    print(total)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 14412
from collections import defaultdict

INF = float("inf")

N, *A = map(int, open(0).read().split())

dp_in = defaultdict(lambda: -INF)

dp_out = defaultdict(lambda: -INF)
dp_out[(0, 0)] = 0

for i, a in enumerate(A, 1):
    p = i // 2
    for j in [p - 1, p, p + 1]:
        dp_in[(i, j)] = a + dp_out[(i - 1, j - 1)]
        dp_out[(i, j)] = max(dp_in[(i - 1, j)], dp_out[(i - 1, j)])

print(max(dp_in[(N, N // 2)], dp_out[(N, N // 2)]))

Measured memory_bytes: 291152
/*
#####################################################
# I will win.. maybe not immediately but definitely #
#####################################################
*/

#include <bits/stdc++.h>
using namespace std;

//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//save time
#define endl '\n'
#define db(x) cout << "> " << #x << ": " << x << endl;
typedef long long ll;

//for sorting
#define all(a) a.begin(),a.end()

//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f

//loops
#define REP(i,n) 	    for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)

//vectors
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int>>
#define vlll vector<pair<ll,ll>>
#define pb 	push_back

//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define F first
#define S second

//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define gc getchar
#define pc putchar

//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)

//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue

//general
#define E empty()

//Declare all variables and methods needed between this comment and the next one(OCD lol)
int n;
ll seq[200010],pos[200010],ans=LLONG_MAX,x;
void solve(int k){
    ll temp=0,prevTemp=0;
    int uLim=n/k;
    REP(i,uLim){
        temp+=(seq[i]*(pos[min(n,(i+1)*k)]-pos[i*k]));
        if(prevTemp>=temp)
            return ;
        else
            prevTemp=temp;
    }

    if(n%k){
        temp+=(seq[uLim]*(pos[n]-pos[uLim*k]));
        if(prevTemp>temp)
            return ;
    }

    temp+=((ll)(k+n))*x;
    ans=(temp>ans)?ans:temp;
}
//Main function
int main(){
    IOS;
    TIE;

    cin>>n>>x;

    FOR(i,1,n+1)
        cin>>pos[i];
    sort(pos+1,pos+n+1,greater<ll>());

    FOR(i,1,n+1)
        pos[i]+=pos[i-1];

    seq[0]=seq[1]=5;
    FOR(i,2,n+1)
        seq[i]=seq[i-1]+2;

    FOR(i,1,n+1)
        solve(i);

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k, t;
	cin>>k>>t;
	vector<int> cakes(t);
	for(int i = 0; i < t; ++i){
		int a;
		cin>>a;
		cakes[i] = a;
	}
	int n = cakes.size();
	if(n > 1){
		while(true){
			sort(cakes.begin(), cakes.end());
			if(cakes[n - 1] > 0 && cakes[n - 2] > 0){
				cakes[n - 1]--;
				cakes[n - 2]--;
			}
			else{
				break;
			}
		}
	}
	int ans = 0;
	if(cakes[n - 1] > 0){
		ans = cakes[n - 1] - 1;
	}
	else{
		ans = 0;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var AL=Arr.shift();
var g=[[],[],[]];
for(var i=0;i<AL;i++){
   var arr=Arr[i].split(" ").map(Number);
   g[0].push(arr[0]);
   g[1].push(arr[1]);
   g[2].push(arr[2]);
}

for(var i=0;i<AL;i++){
   var arr=Arr[i].split(" ").map(Number);
   var sum=0;
   if((g[0].filter(function(v){return v==arr[0];})).length==1)sum+=arr[0];
   if((g[1].filter(function(v){return v==arr[1];})).length==1)sum+=arr[1];
   if((g[2].filter(function(v){return v==arr[2];})).length==1)sum+=arr[2];
   console.log(sum);
}

Measured memory_bytes: 9924
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, M, ABs):
    f_map = [[] for _ in range(N + 1)]
    for A, B in ABs:
        f_map[A].append(B)
        f_map[B].append(A)
    group = [-1] * (N + 1)
    latest_gnum = 1
    for i in range(1, N  + 1):
        if group[i] != -1:
            continue
        group[i] = latest_gnum
        latest_gnum += 1
        dq = deque([i])
        while dq:
            n = dq.popleft()
            for f in f_map[n]:
                if group[f] != -1:
                    continue
                group[f] = group[n]
                dq.append(f)
    group_sum = [0] * latest_gnum
    for g in group[1:]:
        group_sum[g] += 1
    print(max(group_sum))


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    N, M = map(int, input().split())
    ABs = [[int(i) for i in input().split()] for _ in range(M)]
    # Bs = [int(i) for i in input().split()]
    solve(N, M, ABs)


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

namespace AtCoder.Abc
{
    // 問題:
    class A_163_Circle_Pond
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            double n = double.Parse(Console.ReadLine());

            double result = n * 2 * 3.14;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27584
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
ll l[N], r[N];
priority_queue<ll> q;
int x, y, z, n;
struct Node{
  int gold, silver, bronze;
  bool operator < (const Node& rh) const{
    if(gold-silver != rh.gold-rh.silver)
      return gold-silver < rh.gold-rh.silver;
    return silver > rh.silver;
  }
}node[N];

ll solve(){
  sort(node, node+n);
  ll sum = 0;
  while(!q.empty()) q.pop();
  for(int i = 0; i < y; i++){
    q.push(node[i].bronze - node[i].silver);
    sum += node[i].silver;
  }
  for(int i = y; i < y+z; i++){
    l[i] = sum;
    sum += node[i].silver;
    if(q.top() > node[i].bronze - node[i].silver){
      sum += q.top();
      q.pop();
      q.push(node[i].bronze - node[i].silver);
    }
    else sum += node[i].bronze - node[i].silver;
  }
  l[y+z] = sum;
  sum = 0;
  while(!q.empty()) q.pop();
  for(int i = n-1; i >= y+z; i--){
    q.push(node[i].bronze - node[i].gold);
    sum += node[i].gold;
  }
  r[y+z] = sum;
  for(int i = y+z-1; i >= y; i--){
    sum += node[i].gold;
    if(q.top() > node[i].bronze-node[i].gold){
      sum += q.top();
      q.pop();
      q.push(node[i].bronze-node[i].gold);
    }
    else sum += node[i].bronze-node[i].gold;
    r[i] = sum;
  }
  ll ans = 0;
  for(int i = y; i <= y+z; i++) ans = max(ans, l[i]+r[i]);
  return ans;
}

int main(){
  scanf("%d%d%d", &x, &y ,&z);
  n = x + y + z;
  for(int i = 0; i < n; i++)
  scanf("%d%d%d", &node[i].gold, &node[i].silver, &node[i].bronze);
  ll ans = solve();
  printf("%lld\n", ans);
}


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

using namespace std;

using int64 = long long;


int main() {
  int N, Q;
  string S;

  cin >> N >> S;
  cin >> Q;

  int64 dp[1000001] = {};
  int sum = 0;
  for(int i = 0; i < N; i++) {
    if(S[i] == 'M') {
      sum += 1;
    } else if(S[i] == 'C') {
      dp[i + 1] = sum;
    }
  }
  for(int i = 1; i <= N; i++) {
    dp[i] += dp[i - 1];
  }
  int64 sums[3][1000001] = {{}};
  string v = "DMC";
  for(int i = 1; i <= N; i++) {
    auto pos = v.find(S[i - 1]);
    if(pos != string::npos) {
      sums[pos][i]++;
    }
    for(int j = 0; j < 3; j++) {
      sums[j][i] += sums[j][i - 1];
    }
  }


  while(Q--) {
    int K;
    cin >> K;
    int64 ret = 0;
    for(int i = 0; i < N; i++) {
      if(S[i] == 'D') {
        int C = min(N, K + i);
        int64 add = dp[C] - dp[i];
        add -= 1LL * (sums[2][C] - sums[2][i]) * sums[1][i];
        ret += add;
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 32644
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i(a); i <= (b); ++i)

#define gc getchar()
struct Reader {
	template <class T> inline operator T() {
		T w; char c, p = 0;
		for(; !isdigit(c = gc); c == '-' && (p = 1));
		for(w = c & 15; isdigit(c = gc); w = w * 10 + (c & 15));
		return p ? -w : w;
	}
}rd;

template <class T> inline bool smin(T&x, const T&y) { return y < x ? x = y, 1 : 0; }
template <class T> inline bool smax(T&x, const T&y) { return x < y ? x = y, 1 : 0; }

typedef long long ll;

const int N(3005);
int n, a[N];
bool vis[N][N];
ll f[N][N];
ll dfs(int t, int x){
	if (t > n) return 0;
	if(vis[t][x])return f[t][x];
	vis[t][x] = 1;
	return f[t][x] = t & 1 ? std::max(a[x] + dfs(t + 1, x + 1), a[n - t + x] + dfs(t + 1, x)) : std::min(-a[x] + dfs(t + 1, x + 1), -a[n - t + x] + dfs(t + 1, x));
}
int main() {
	n = rd;
	REP(i, 1, n) a[i] = rd;
	std::cout << dfs(1, 1);
	return 0;
}



Measured memory_bytes: 78208
#include<stdio.h>
#include<math.h>

typedef struct {
  double x;
  double y;
} point;
void kock(int ,point ,point );

  int main(){
    point p1,p2;
    int n;
     scanf("%d",&n);
    p1.x=0,p1.y=0,p2.x=100,p2.y=0;
        printf("%.8f %.8f\n",p1.x,p1.y);
        kock(n,p1,p2);
            printf("%.8f %.8f\n",p2.x,p2.y);

            return 0;
  }

  void kock(int n, point p1, point p2) {
      if (n == 0)
          return;
      // p1, p2 ?????? s, t, u ????¨????
      point s,u,t;
      double rad = M_PI * 60.0/180.0;

      s.x = (2.0*p1.x + 1.0*p2.x) / 3.0;
      s.y = (2.0*p1.y + 1.0*p2.y) / 3.0;
      t.x = (1.0*p1.x + 2.0*p2.x) / 3.0;
      t.y = (1.0*p1.y + 2.0*p2.y) / 3.0;
      u.x=(t.x-s.x)*cos(rad)-(t.y-s.y)*sin(rad)+s.x;
      u.y=(t.x-s.x)*sin(rad)+(t.y-s.y)*cos(rad)+s.y;
      kock(n-1, p1, s);
      printf("%.8f %.8f\n",s.x,s.y);
      kock(n-1, s, u);
          printf("%.8f %.8f\n",u.x,u.y);
      kock(n-1, u, t);
          printf("%.8f %.8f\n",t.x,t.y);
      kock(n-1, t, p2);
    }

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int x = 0;
    int next = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (next == a) {
            next++;
            x++;
        }
    }

    cout << (x == 0 ? -1 : n - x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;

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

  if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    vector<int> ringo(n);
    for (int i = 0; i < n; i++)
    {
        ringo[i] = l + (i + 1) - 1;
    }
    int index = 0;
    int rec = INF;
    for (int i = 0; i < n; i++)
    {
        if (rec > abs(ringo[i]))
        {
            rec = abs(ringo[i]);
            index = i;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (i == index)
        {
            continue;
        }
        ans += ringo[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string S;
  cin >> S;
  int r=0, b=0;
  for(int i=0; i<S.length(); i++){
    if(S[i] == '0') r++;
    else b++;
  }
  if(r<b) cout << r*2 << endl;
  else cout << b*2 << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<string>
using namespace std;
 
int ans = 0;
 
void ansf(string p,string q){
q=q+q;
if(q.find(p)!=string::npos){ans++;}
	}
 
int main() {
	string a;
	cin>>a;
	int b;
	cin>>b;
	for(int i = 0;i<b;i++){
		string h;
		cin>>h;
		ansf(a,h);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1212
k=int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[k-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define  ren(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) ren(i,0,(n))
#define  all(a) begin(a),end(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;
 
int main()
{
    int n;
    cin>>n;
    int a[26][n];
    rep(i,26)rep(j,n)a[i][j]=0;
    rep(i,n){
        string s;
        cin>>s;
        for(char c:s) a[c-'a'][i]++;
    }
//    rep(i,26){rep(j,n) cout<<a[i][j]<<" "; cout<<endl;}
    rep(i,26){
        int m=50;
        rep(j,n) m=min(a[i][j],m);
        rep(q,m) cout<<char('a'+i);
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <sstream>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int stoi(string str){
int ret;
stringstream ss;
ss << str;
ss >> ret;
return ret;
}

int main()
{
	int n;
	scanf("%d", &n);
	for(int l=0; l<n; l++){
		string s;
		cin>>s;
		int m=s.length();
		int d=0;
		while(s[d]=='['){
			d++;
		}
		P used[10000];
		fill(used, used+10000, P(0, 0));
		vector<int> G[10000];
		int t=1, p1;
      bool e=0;
		for(int k=d-1; k>=0; k--){
			vector<int> v;
			for(int i=0; i<m; i++){
				if(s[i]=='[' && used[i]==P(0, 0)){
					p1=i, e=1;
				}else if(s[i]==']' && used[i]!=P(0, 0)){
					if(used[i].second==k+1){
                      v.push_back(used[i].first);
                    }
				}else if(s[i]==']' && used[i]==P(0, 0) && e==1){
                  e=0;
					used[i]=P(t, k);
					used[p1]=P(t, k);
					for(int j=0; j<v.size(); j++){
						G[t].push_back(v[j]);
					}
					v.clear();
					t++;
				}
			}
		}
		vector<int> num;
		num.push_back(0);
		string ns;
		for(int i=0; i<m; i++){
			if(s[i]!='[' && s[i]!=']'){
				ns+=s[i];
			}else{
				if(!ns.empty()){
					int x=stoi(ns);
					num.push_back(x);
					ns.clear();
				}
			}
		}
		int ans[10000]={};
		for(int i=1; i<t; i++){
			if(G[i].empty()){
				ans[i]=(num[i]+1)/2;
			}else{
				vector<int> v;
				for(int j=0; j<G[i].size(); j++){
					v.push_back(ans[G[i][j]]);
				}
				sort(v.begin(), v.end());
				for(int j=0; j<=(v.size()/2); j++){
					ans[i]+=v[j];
				}
			}
		}
		printf("%d\n", ans[t-1]);
	}
	return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    int x = a[n-1];
    int y;
    int now = abs(x - a[0]*2);
    REP(i,n-1) {
        if (abs(x-a[i]*2) < now) {
            y = a[i];
            now = abs(x-a[i]*2);
        }
    }
    cout << x << " " << y << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    cin>>n;
    bool status=0;
    string u[300];
    string t[300];
    for(int i=0;i<n;i++)cin>>u[i];
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>t[i];
        int check=0;
        for(int j=0;j<n;j++){
            if(t[i]==u[j])check=1;
        }
        if(!check){
            cout<<"Unknown "<<t[i]<<endl;
        }else{
            if(!status){
                cout<<"Opened by "<<t[i]<<endl;
            }else{
                cout<<"Closed by "<<t[i]<<endl;
            }
            status=!status;
        }
    }
    return 0;
}


Measured memory_bytes: 3224
class Array
  include Comparable
end

n = gets.to_s.to_i
a, b = Array.new(n){ gets.to_s.split.map{|t| t.to_i } }.transpose

if a == b
  puts 0
  exit
end

puts b.reduce(0){|s,t| s+t } - a.zip(b).select{|(x, y)| x > y }.map{|(_, y)| y }.min

Measured memory_bytes: 4476
N = int(input())
p = [int(s) for s in input().split(' ')]

l = []
for k in range(1, N+1):
    l.append(k)

count = 0

for i in range(N):
    if l[i] != p[i]:
        count += 1

if count <= 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
#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 vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
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 bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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);
}


void Main() {
	int N; string S; cin >> N >> S;
	vvint dp(N+1, vint(N+1, 0));
	int maxv = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			if (S[i] == S[j]) {
				dp[i+1][j+1] += dp[i][j]+1;
				chmin(dp[i+1][j+1], j-i);
				chmax(maxv, dp[i+1][j+1]);
			}
		}
	}
	cout << maxv << endl;
}

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


Measured memory_bytes: 98304