akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

class Combination {
public:
    Combination(ll max_num, ll mod) {
        fact_.resize(max_num + 1, 1);
        inv_fact_.resize(max_num + 1, 1);
        mod_ = mod;
        for (ll i = 2; i <= max_num; i++) {
            fact_[i] = i * fact_[i - 1] % mod_;
            inv_fact_[i] = MODpow(fact_[i], mod_ - 2);
            assert(fact_[i] * inv_fact_[i] % mod_ == 1);
        }
    }
    ll operator()(ll n, ll m) const {
        if (m < 0 || m > n) return 0;
        return fact_[n] * inv_fact_[n - m] % mod_ * inv_fact_[m] % mod_;
    }
private:
    ll MODpow(ll n, ll m) const {
        ll result = 1;
        while (m) {
            if (m % 2 == 1) {
                result *= n;
                result %= mod_;
            }

            m /= 2;
            n *= n;
            n %= mod_;
        }

        return result;
    }

    vector<ll> fact_, inv_fact_;
    ll mod_;
};

int main() {
    constexpr ll MOD = 1e9 + 7;
    ll X, Y;
    cin >> X >> Y;
    if (X > Y) {
        swap(X, Y);
    }

    if ((X + Y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    const ll N = (X + Y) / 3;

    Combination comb(N, MOD);

    cout << comb(N, X - N) << endl;
}

Measured memory_bytes: 10624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.printf("%d %d %.10f\n", a/b,a%b,(double)a/(double)b);
	}
}





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

int main(){
    
    int N;
    cin >> N;
    
    long long X[N];
    long long Y[N];
    
    for(int i = 0; i < N;i++){
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(X,X+N);
    
    for(int i = 0; i < N;i++){
     if(Y[i]<X[N/2]) cout << X[N/2] << endl;
     else cout << X[N/2 - 1] << endl;
    }
}

    
    



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

int main(){
string s;
cin>>s;
  bool a=true;
if(s.at(2)!=s.at(3)){
 a=false;
}
if(s.at(4)!=s.at(5)){
a=false;
}
if(a==true)
  cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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





int main() {

	string S;
	cin >> S;

	ll a1 = 0;
	ll a2 = 0;

	rep(i, S.size()) {
		if (i % 2 == 0 && S[i] == '0') { a1++; }
		if (i % 2 == 0 && S[i] == '1') { a2++; }
		if (i % 2 == 1 && S[i] == '0') { a2++; }
		if (i % 2 == 1 && S[i] == '1') { a1++; }
	}

	cout << min(a1, a2);

	system("PAUSE");
}

Measured memory_bytes: 760
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  int N, a;
  cin >> N;
  long ans = 0;
  vector<int> vec(N*3);
  for(int i = 0; i < N*3; i++){
    cin >> a;
    vec.at(i) = a;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  int x = 0;
  for (int i = 1; i <= N; i++) {
    x = 2*i-1; // 2〜2N番目までの数をみる
    ans += vec.at(x);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


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


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    print(int(input())**2)


main()


Measured memory_bytes: 4788
#include<cstdio>
#include<iostream>
#include<climits>
#define M LLONG_MAX
using namespace std;
int a[2*100000];
int main(void){
	int n,i,j;
	long long int x,y,zxy,min,xy,sum;
	cin>>n;
	sum=0;
	for(i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	min=9223372036854775807;
	x=0;
	for(i=0;i<n-1;i++){
		x+=a[i];
		y=sum-x;
		zxy=x-y;
		if(zxy<0) zxy=zxy*-1;
		if(min>zxy) min=zxy;
	}
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**9)

N,K = map(int,input().split())
edge = [[] for i in range(N)]
for i in range(N-1) :
    u,v = map(lambda x: int(x)-1, input().split())
    edge[u].append(v)
    edge[v].append(u)

deg = [len(E) for E in edge]

MOD = 10**9 + 7
u = 10**5 + 1

fact = [1] * (u+1)
for i in range(1, len(fact)) :
    fact[i] = (fact[i-1] * i) % MOD

fact_inv = [1] * (u+1)
fact_inv[u] = pow(fact[u], MOD-2, MOD)
for i in range(u-1,0,-1) :
    fact_inv[i] = (fact_inv[i+1] * (i+1)) % MOD

def perm(n, r) :
    if r < 0 or n < r :
        return 0
    return (fact[n] * fact_inv[n-r]) % MOD

def F(node, parent=None) :
    if parent is None :
        res = perm(K, deg[node] + 1)
    else :
        res = perm(K-2, deg[node] - 1)
    
    for next_node in edge[node] :
        if next_node == parent :
            continue
        
        res *= F(next_node, parent=node)
        res %= MOD
    return res

ans = F(0, parent=None)

print(ans)


Measured memory_bytes: 110188
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
//#define P pair<ll, ll>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;


int main() {

  int N, M; cin >> N >> M;
  vector<vector<int>> graph(N);
  vector<int> in(N);
  rep(i, 0, M){
    int x, y; cin >> x >> y;
    --x, --y;
    graph[x].push_back(y);
    in[y] += 1;
  }

  queue<int> q;
  rep(i, 0, N){
    if(in[i] == 0)q.push(i);
  }

  vector<int> tp;
  vector<int> dp(N, 0);

  while(!q.empty()){
    int v = q.front();
    q.pop();
    tp.push_back(v);
    for(auto next: graph[v]){
      in[next] -= 1;
      if(in[next] == 0){
        q.push(next);
        if(dp[next] < dp[v] + 1) dp[next] = dp[v] + 1;
      }
    }
  }

  ll ans = -1;
  rep(i, 0, N){
    if(ans < dp[i]) ans = dp[i];
  }

  cout << ans << endl;

}


Measured memory_bytes: 9980
import sys
from operator import xor
from functools import reduce
readline = sys.stdin.readline

mod = 10**18+3
base = 10**9+9
def rollinghash(S):
    N = len(S)
    has = [0]*(N+1)
    power = [1]*(N+1)
    for i in range(N):
        s = S[i]
        has[i+1] = (has[i]*base + s)%mod
        power[i+1] = power[i]*base%mod
    return has, power
 
def rh(i, j):
    return (has[j] - has[i]*power[j-i])%mod

def rotate(k):
    pass

N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
CA = [a1^a2 for a1, a2 in zip(A, A[1:])]
CA.append(A[0]^A[-1])
CB = [a1^a2 for a1, a2 in zip(B, B[1:])]
CB.append(B[0]^B[-1])

rA = [1+ca for ca in CA]
has, power = rollinghash(rA)
R = rh(0, N)
    
HA = [None]*N
suf = pow(base, N-1, mod)
for i in range(N):
    HA[i] = R
    R = ((R-suf*rA[i])*base + rA[i])%mod

rB = [1+cb for cb in CB]
has, power = rollinghash(rB)
R = rh(0, N)

Ans = []
for i in range(N):
    if HA[i] == R:
        Ans.append((i, A[i]^B[0]))

if Ans:
    print('\n'.join(' '.join(map(str, a)) for a in Ans))


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

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;

long long GCD(long long x, long long y) {
	return y ? GCD(y, x % y) : x;
}

long long LCM(long long x, long long y) {
	return x * y / GCD(x, y);
}

int A() {
	int n;

	scani(n);

	YesNo(7 == n % 10 || 7 == n / 10 % 10 || 7 == n / 100);


	return 0;
}

int B() {
	int n;

	scani(n);

	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 && i % 5) {
			ans += i;
		}
	}

	printll(ans);

	return 0;
}

int Main() {
	int k;
	int ans = 0;

	scani(k);

	int a = 1, b = 1, c = 1;
	for (a = 1; a <= k; a++) {
		for (b = 1; b <= k; b++) {
			for (c = 1; c <= k; c++) {
				//so
				if (1 == a || 1 == b || 1 == c ||
					(0 == a % b &&
						0 == a % c &&
						0 == b % a &&
						0 == b % c &&
						0 == c % a &&
						0 == c % b))
				{
					ans += 1;
					continue;
				}
				int tmp = GCD(a, b);
				ans += GCD(tmp, c);
			}
		}
	}

	printi(ans);

	return 0;
}

int D() {
	int n;

	string s;
	scani(n);
	cin >> s;
	ll r, g, b;
	r = g = b = 0;
	for (auto x : s) {
		switch (x) {
		case 'R':
			r++;
			break;
		case 'G':
			g++;
			break;
		default:
			b++;
			break;
		}
	}

	ll ans = r * g * b;
	ll sub = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j]) continue;
			int k = j * 2 - i;
			if (n <= k || s[k] == s[i] || s[k] == s[j]) continue;
				sub++;
		}
	}

	ans -= sub;

	printll(ans);

	return 0;
}

int main()
{
	//Main();
	D();
	return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,m; cin >> n >> m;
    ll ans = 0;
    ll mn = INF;
    if(n>0 && m>1){
        mn = min(n,m/2);
        ans += mn;
        n -= mn;
        m -= mn * 2;
    }
    if(m>3){
        ans += m/4;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
S = list(input())
K = int(input())

if len(S) == 1:
    print( K // 2)
    exit()

count = 1
i = 0
sum = 0
while(1):
    if S[i] == S[i+1]:
        count += 1
        i += 1
    else:
        sum += count//2
        count = 1
        i += 1
    if i == len(S)-1:
        break

sum += count//2 #最後のカウントの加算

#print("check1",sum)

#先頭の連続数をカウント
j = 0 # リストカウント
a = 1 # 連続数カウント
while(1):
    if S[j] == S[j+1]:
        a += 1
        j += 1
    else:
        break
    if j == len(S) -1:
        break
#print("check")

#末尾の連続数をカウント
m = len(S)-1 # リストカウント
b = 1 # 連続数カウント
while(1):
    if S[m] == S[m-1]:
        m -= 1
        b += 1
    else:
        break
    if m == 0:
        break

#print("a is",a)
#print("b is",b)
#print("sum is", sum)
if a == len(S): #１文字のみで文字列構成の場合
    print((len(S)* K)//2)
elif S[len(S)-1] == S[0]:
    print( sum * K + ((a+b)//2 - a//2 - b //2 ) * ( K -1))
else:
    print( sum * K)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int A;
  cin>>A;
  string S;
  cin>>S;
  if(A>=3200) cout<<S<<endl;
  else cout<<"red"<<endl;
}

Measured memory_bytes: 256
from bisect import bisect_left

N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9 + 7

num = []
num2 = []
ret = 0
for i in range(N):
    ind = N-1-i
    j = bisect_left(num, A[ind])
    num.insert(j, A[ind])
    ret += j
    
count = 0
a = {}
for i in range(N):
    if A[i] in a:
        a[A[i]] += 1
    else:
        a[A[i]] = 1

ret2 = N * (N-1)//2 - ret
for e in a.values():
    ret2 -= (e * (e-1))//2

ret *= K * (K+1)//2
ret2 *= K * (K-1)//2
ret += ret2
ret %= mod
print(ret)


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

using namespace std;

using ll = long long;

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

    string w;
    cin >> w;

    map<char, int> cnt;
    for (auto c : w) ++cnt[c];

    bool is_beautiful = true;
    for (const auto &it : cnt)
        if (it.second % 2 == 1) is_beautiful = false;

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

    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
ta=''
for i in range(n):
    if t[i]=='r':
        if i<k or ta[i-k]!='p':
            ans+=p
            ta+='p'
        else:
            ta+='*'
    elif t[i]=='s':
        if i<k or ta[i-k]!='r':
            ans+=r
            ta+='r'
        else:
            ta+='*'
    elif t[i]=='p':
        if i<k or ta[i-k]!='s':
            ans+=s
            ta+='s'
        else:
            ta+='*'
print(ans)

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();

		if(X>=Y) {
			if(X>=Z) {
				System.out.println(Y+Z);
			}else {
				System.out.println(X+Y);
			}
		}else {
			if(Y>=Z) {
				System.out.println(X+Z);
			}else {
				System.out.println(X+Y);
			}
		}
	}
}


Measured memory_bytes: 21844
n = gets.to_i
a = []
n.times do |i|
  num = gets.to_i
  a << num
end

a_sorted = a.sort
max = a_sorted[n-1]
second = a_sorted[n-2]
max_second = max == second

if max_second
  n.times do 
    puts max
  end
else
  n.times do |i|
    if a[i] != max
      puts max
      next
    elsif a[i] != second
      puts second
      next
    else
      n.times do |j|
        last = a_sorted[n-(j+1)]
        if a[i] != last || n-(j+1) == 0
          puts last
          break
        end
      end
    end
  end
end

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

public class Main {
	static public void main(String[] argv) {
		try{
			//FileReader file_in = new FileReader("test.txt");
			//BufferedReader d = new BufferedReader( file_in );
			BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
	
			while(true) {
				String buf = d.readLine();
				
				int num = Integer.valueOf(buf);
				if(num == 0) break;
				
				Converter converter = new Converter();
				
				for(int i = 0; i < num; i++) {
					buf = d.readLine();
					converter.addElement(buf);
				}
				
				buf = d.readLine();
				num = Integer.valueOf(buf);
				
				for(int i = 0; i < num; i++) {
					buf = d.readLine();
					char c = buf.charAt(0);
					converter.printCharConverted(c);
				}
				
				System.out.println();
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}

class Converter {
	class Dictionary {
		public char _key;
		public char _converted;
	}
	
	ArrayList<Dictionary> _dictionary;
	
	public Converter() {
		_dictionary = new ArrayList<Dictionary>();
	}
	
	void addElement(char key, char converted) {
		Dictionary element = new Dictionary();
		element._key = key ;
		element._converted = converted;
		_dictionary.add( element );
	}
	
	void addElement(String str) {
		StringTokenizer st = new StringTokenizer(str);
		char key = st.nextToken().charAt(0);
		char converted = st.nextToken().charAt(0);
		addElement(key, converted);
	}
	
	void printCharConverted(char c) {
		for(int i = 0; i < _dictionary.size(); i++) {
			Dictionary element = _dictionary.get(i);
			if( c == element._key ) {
				System.out.print(element._converted);
				return;
			}
		}
		System.out.print(c);
	}
}

Measured memory_bytes: 42192
#include<bits/stdc++.h>
using namespace std;
/*
if(x=='N')
	{m1=d2;m2=d6;m6=d5;m5=d1;
	}
if(x=='S')
	{m1=d5;m5=d6;m6=d2;m2=d1;
	}
if(x=='W')
	{m3=d6;m6=d4;m4=d1;m1=d3;
	}
if(x=='E')
	{m6=d3;m3=d1;m1=d4;m4=d6;
	}
*/
int main(){
//DICE inputa;
int a=0;
cin>>a;
int x1[100],x2[100],x3[100],x4[100],x5[100],x6[100],ans=0;
for(int i=0; i<a;i++)
{cin>>x1[i]>>x2[i]>>x3[i]>>x4[i]>>x5[i]>>x6[i];
}
int m1,m2,m3,m4,m5,m6,z1,z2,z3,z4,z5,z6,d1,d2,d3,d4,d5,d6;
//END DICE input

int i=0,i2=1;
while(1)
{
z1=x1[i];z2=x2[i];z3=x3[i];z4=x4[i];z5=x5[i];z6=x6[i];
d1=x1[i2];d2=x2[i2];d3=x3[i2];d4=x4[i2];d5=x5[i2];d6=x6[i2];
for(int i3=0; i3<6 ; i3++)
	{
	for(int i4=0;i4<4;i4++)
		{
		m1=d1;m2=d2;m3=d3;m4=d4;m5=d5;m6=d6;
		m1=d2;m2=d6;m6=d5;m5=d1;
		d1=m1;d2=m2;d3=m3;d4=m4;d5=m5;d6=m6;
		if(z1==d1 && z2==d2 && z3==d3 && z4==d4 &&z5==d5 &&z6==d6) {ans++; break;}
		}
	if(z1==d1 && z2==d2 && z3==d3 && z4==d4 &&z5==d5 &&z6==d6) break;
	if(i3<3)
	{m1=d1;m2=d2;m3=d3;m4=d4;m5=d5;m6=d6;
	m3=d6;m6=d4;m4=d1;m1=d3;
	d1=m1;d2=m2;d3=m3;d4=m4;d5=m5;d6=m6;}
	if(i3==3)
	{m1=d1;m2=d2;m3=d3;m4=d4;m5=d5;m6=d6;
	m1=d2;m2=d6;m6=d5;m5=d1;
	d1=m1;d2=m2;d3=m3;d4=m4;d5=m5;d6=m6;
	m1=d1;m2=d2;m3=d3;m4=d4;m5=d5;m6=d6;
	m3=d6;m6=d4;m4=d1;m1=d3;
	d1=m1;d2=m2;d3=m3;d4=m4;d5=m5;d6=m6;}
	if(i3==4)
	{m1=d1;m2=d2;m3=d3;m4=d4;m5=d5;m6=d6;
	m3=d6;m6=d4;m4=d1;m1=d3;
	d1=m1;d2=m2;d3=m3;d4=m4;d5=m5;d6=m6;
	m1=d1;m2=d2;m3=d3;m4=d4;m5=d5;m6=d6;
	m3=d6;m6=d4;m4=d1;m1=d3;
	d1=m1;d2=m2;d3=m3;d4=m4;d5=m5;d6=m6;}
	}
if(i==a-2) break;
else if(i2==a-1) {i++; i2=i+1;}
else i2++;
}
if(ans==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3120
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

//文字列としての数字を
//整数数型に変換する関数
long long getint(string str) {
	long long ret = 0;

	for (int i = 0; i < str.size(); i++) {
		ret = ret * 10 +(str[i] - '0');
	}

	return ret;
}

int main() {

	string s; cin >> s;

	//一文字なら＋を入れる余地がないので、表示して終了
	if (s.size() == 1) {
		cout << s << endl;
		return 0;
	}
	

	//s[0] s[1] s[2]…という添字の向きだと扱いにくいのでひっくり返す
	//…s[2] s[1] s[0]になる
	reverse(s.begin(), s.end());

	long long ans = 0;

	//＋が入る隙間の数
	int l = s.size() - 1;

	//＋の有無のパターンを全列挙
	//ビットが立ってる位置には＋を入れる

	//…s[2] l[1] s[1] l[0] s[0]
	//という対応になっている
	for (int bit = 0; bit < (1 << l); bit++) {
		
		//各＋の間にある数字を表す文字列
		string tmp ="";

		tmp += s[0];
		
		//＋が入る隙間の位置i
		for (int i = 0; i < l; i++) {

			if ((bit >> i) & 1) {
				ans += getint(tmp);
				tmp = s[i+1];
			}
			else {
				tmp= s[i+1]+tmp;
			}

			//一番左の文字を最後に回収
			if (i == l - 1) {
				ans += getint(tmp);
			}
		}
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
p = 0
for i in range(n):
    if a[i]%2 == 0:
        if a[i]%3 != 0 and a[i]%5 != 0:
            p += 1
if p > 0:
    print("DENIED")
else:
    print("APPROVED")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    
    int n, k;
    cin >> n >> k;
    
    ll sum = 0;
    int nn = min(n, n - k + 1); // k = 1, 0のとき同じ
    sum += (ll)nn * (nn - 1) / 2;
    rep3(b, 1, n + 1) { // 割る数
        sum += (ll)(n / b - 1) * max(0, b - k);
        int r = n % b;
        sum += max(0, r + 1 - k);
    }
    
    out(sum);
}





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

int main( int argc, char *argv[] )
{
int i;
char S[ 20 ];
char C;
int iPos;
char T[ 20 ];

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;

	iPos = 0;
	i = 0;
	C = S[ i ];
	while( C != '\0' )
	{
		if( C == 'B' )
		{
			if( iPos > 0 ) iPos--;
		}
		else
		{
			T[ iPos ] = S[ i ];
			iPos++;
		}

		i++;
		C = S[ i ];
	}

	T[ iPos ] = '\0';
	cout << T << endl;

	return 0;
}



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



int main(){
    ll n;cin>>n;
    ll a[200020];
    map<ll,ll> m;
    rep(i,0,n){
        cin>>a[i];
        m[a[i]]++;
    }
    ll zenbu=0;
    for(auto i:m){
        zenbu+=i.second*(i.second-1)/2;
    }
    rep(i,0,n){
        ll an=zenbu;
        ll cnt=m[a[i]];
        an=an-(cnt*(cnt-1)/2)+(cnt-1)*(cnt-2)/2;
        cout<<an<<endl;
    }
}







Measured memory_bytes: 11008
import collections
q = int(input())
v = collections.deque()
for _ in range(q):
	op = list(map(int, input().split()))
	if op[0]==0:
		if op[1]==0:
			v.appendleft(op[2])
		else:
			v.append(op[2])
	elif op[0]==1:
		print(v[op[1]])
	else:
		if op[1]==0:
			v.popleft()
		else:
			v.pop()



Measured memory_bytes: 21984
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli c, h, n, w, ans = 0, count = 0;
  string s, t;
  vvi a(3, vi(3));
  cin >> a;
  cin >> n;
  vi b(n);
  rep(i, 0, n)
  {
    cin >> b[i];
  }
  rep(i, 0, 3)
  {
    rep(j, 0, 3)
    {
      rep(k, 0, n)
      {
        if (b[k] == a[i][j])
          a[i][j] = 0;
      }
    }
  }
  repe(i, 0, 0)
  {
    repe(j, 0, 0)
    {
      if ((a[i][j] == 0 && a[i + 1][j] == 0 && a[i + 2][j] == 0) || (a[i][j] == 0 && a[i][j + 1] == 0 && a[i][j + 2] == 0) || (a[i][j] == 0 && a[i + 1][j + 1] == 0 && a[i + 2][j + 2] == 0) || (a[i][j + 1] == 0 && a[i + 1][j + 1] == 0 && a[i + 2][j + 1] == 0) || (a[i][j + 2] == 0 && a[i + 1][j + 2] == 0 && a[i + 2][j + 2] == 0) || (a[i + 1][j] == 0 && a[i + 1][j + 1] == 0 && a[i + 1][j + 2] == 0) || (a[i + 2][j] == 0 && a[i + 2][j + 1] == 0 && a[i + 2][j + 2] == 0) || (a[i][j + 2] == 0 && a[i + 1][j + 1] == 0 && a[i + 2][j] == 0))
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f(i,n) for(ll i=0;i<n;i++)
#define fi(i,j,n) for(ll i=j;i<=n;i++)
#define fr(i,n) for(ll i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF LLONG_MAX
#define ALL(a) a.begin(),a.end()
#define MAX 2005

int main()
{
    ll t=1;
    //cin>>t;
    while(t--)
    {
        string s;ll k;
        cin>>k>>s;
        ll n=s.length();
        if(n<=k)
        cout<<s;
        else
        {
            string ans="";
            f(i,k)
            {
                ans+=s[i];
            }
            ans+="...";
            cout<<ans;
        }
    }
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <thread>///////////////////

#define rep(i,m,n) for(int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;

//int N, Y;
int mode = 0;

//tuple<int, int, int> calc(int A, int B, int C) {}



int main() {
	string S;
	cin >> S;
	int N = S.length();
	string X, Y,xx,yy,Z;

	Z = S;
	reverse(Z.begin(), Z.end());
	X = S.substr(0, (N - 1) / 2);
	xx = S.substr(0, (N - 1) / 2);
	reverse(xx.begin(), xx.end());
	Y = S.substr((N + 3) / 2 - 1, S.length() - ((N + 3) / 2 - 1));
	yy = S.substr((N + 3) / 2 - 1, S.length() - ((N + 3) / 2 - 1));
	reverse(yy.begin(), yy.end());

	//cout << S << "  " << Z << '\n';
	//cout << X << "  " << xx << '\n';
	//cout << Y << "  " << yy << '\n';

	if (S == Z) {
		if (X == xx) {
			if (Y == yy) {
				cout << "Yes" << '\n';
				return 0;
			}
		}
	}
	cout << "No" << '\n';

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    H, W, K = map(int, input().split())
    C = [list(input()) for _ in range(H)]

    ans = 0
    for i in range(2 ** H):
        for j in range(2 ** W):
            count = 0
            for n in range(H):
                for m in range(W):
                    if ((i >> n) & 1) == 0 and ((j >> m) & 1) == 0 and C[n][m] == '#':
                        count += 1

            if count == K:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
N, P = map(int, input().split())
B = 0
Q = []
for i in range(N):
    w, b = map(int, input().split())
    B += b
    Q.append((100 - P)*w + P*b)
Q.sort()
s = 0
for i in range(N):
    s += Q[-i-1]
    if B*P <= s:
        print(i+1)
        break

Measured memory_bytes: 56152
#include<bits/stdc++.h>
#define max(a,b,c) max(a,max(b,c))
#define min(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 1145141919

using namespace std;

int main(void){
  unsigned long long int N,M,ans;
  cin >> N >> M;
  if(N*2>=M){
    cout << M/2 << endl;
  }
  else{
    cout << N+(M-2*N)/4 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n, k;
int a[100000];
vector<int> g[100000];
int ans;

int dfs(int x){
	int s = 0;
	for(int v: g[x]){
		s = max(dfs(v) + 1, s);
	}
	if(s >= k - 1 && a[x]){
		++ans;
		return -1;
	}
	return s;
}

int main(){
	cin >> n >> k;
	rep(i, n){
		cin >> a[i];
		--a[i];
	}

	if(a[0]){
		++ans;
		a[0] = 0;
	}
	for(int i = 1; i < n; ++i){
		g[a[i]].push_back(i);
	}

	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10752
#include <algorithm>
#include<bits/stdc++.h>
#include <ios>
#include <iterator>
using namespace std;
#define ll long long 
#define f(n)  for(ll int i=0;i<n;i++) 
#define pb push_back
#define mp make_pair
#define vi vector<ll int>
#define all(v)   v.begin(),v.end()  
#define take(n)   ll int n;cin>>n;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
 int n;
    cin>>n;
    set<string>s;
    for(int i=0;i<n;i++){
        string x;
        cin>>x;
        s.insert(x);
    }
    cout<<s.size();
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  
  ll N = (ll)(S.length()) - 1, ans = 0;
  vector<ll> num(N + 1);
  for (ll i = 0; i < N + 1; i++){
    num.at(i) = S.at(i) - 48;
  }
  
  for (ll i = 0; i < (1<<N); i++){
    ll now = num.at(0);
    for (ll j = 0; j < N; j++){
      if (i & (1<<j)){
        ans += now;
        now = num.at(j + 1);
      }
      else{
        now *= 10;
        now += num.at(j + 1);
      }
    }
    
    ans += now;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<string>
#include<cmath>
using namespace std;

class function {

public:

	static bool isPrime(int x) {
		if (x == 2) {
			return true;
		}
		if (x < 2 || x % 2 == 0) {
			return false;
		}
		for (int i = 2; i <= sqrt(x); i++) {
			if (x % i == 0) {
				return false;
			}
		}
		return true;

	}





};



int main() {
	int n,i=0,c=0;
	int x[10000];
	bool j;
	cin >> n;
	class function isPrime;
	while (i < n) {
		cin >> x[i];
		
		j = isPrime.isPrime(x[i]);
		if (j == true) {
			c++;
		}
		i++;
	}

	cout << c << endl;
	return 0;
}


Measured memory_bytes: 3096
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
int main() {
  int n;
  cin >> n;
  vector<int> card(n);
  rep(i,n) cin >> card[i];
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  
  int a = 0, b = 0;
  if(n%2 == 0){
    rep(i,n/2){
      a += card[2*i];
      b += card[2*i+1];
    }
  }
    else{
      rep(i,(n-1)/2){
        a += card[2*i];
        b += card[2*i+1];
      }
      a += card[n-1];
    }
    dunk( a-b );
  }
        
      
  

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

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    cout << r/d - (l-1)/d << endl;
}


Measured memory_bytes: 3564
<?php
fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%s", $S);
$count = strlen(str_replace("0","",$S));
$list = str_split($S);
$mai = array_fill(0,count($list),0);
$mai_sum = 0;

$pra = array_fill(0,count($list),0);
$pra_sum = 0;

$mai_value = 1;
$pra_value = 1;
for($i=count($list)-1;$i>=0;$i--){
    if($count !== 1) {
        $mai_value %= ($count-1);
        $mai[$i] = $mai_value;
    }
    $pra_value %= ($count + 1);
    $pra[$i] = $pra_value;
    $mai_value*=2;
    $pra_value*=2;
    if($list[$i] == 1){
        $mai_sum += $mai[$i];
        $pra_sum += $pra[$i];
    }
}
for($i=0;$i<$N;$i++){
    if($list[$i] == 0){
        $tmp = ($pra_sum + $pra[$i] )% ($count+1);
        $tmp_count = bitnum($tmp);
    }else{
        if($count === 1){
            echo 0 .PHP_EOL;
            continue;
        }
        $tmp = ($mai_sum - $mai[$i] + $count - 1 ) % ($count-1);
        $tmp_count = bitnum($tmp);
    }
    if(isset($memo[$tmp][$tmp_count])){
        echo $memo[$tmp][$tmp_count].PHP_EOL;
        continue;
    }
    $t_tmp = $tmp;
    $t_tmp_count = $tmp_count;
    $t_ans = 1;
    while($t_tmp>0){
        $t_tmp %= $t_tmp_count;
        $t_tmp_count = bitnum($t_tmp);
        $t_ans++;
    }
    echo $t_ans.PHP_EOL;
    $memo[$tmp][$tmp_count] = $t_ans;

}

function bitnum($bits){
    $bits = ($bits & 0x55555555) + ($bits >> 1 & 0x55555555);
    $bits = ($bits & 0x33333333) + ($bits >> 2 & 0x33333333);
    $bits = ($bits & 0x0f0f0f0f) + ($bits >> 4 & 0x0f0f0f0f);
    $bits = ($bits & 0x00ff00ff) + ($bits >> 8 & 0x00ff00ff);
    return ($bits & 0x0000ffff) + ($bits >>16 & 0x0000ffff);
}

Measured memory_bytes: 49388
nums = gets.split.map(&:to_i)
min = nums.min
max = nums.max
if min >= 3
  ans = (min - 2) * (max - 2)
elsif min == 2
  ans = 0
elsif min == 1 && max >= 2
  ans = max - 2
else
  ans = 1
end
puts ans


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

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

vi B(M);
vvi A(N,vi(M));
rep(j,M) cin >> B[j];
rep(i,N) rep(j,M) cin >> A[i][j];

int ans = 0;

rep(i,N) {
    int sum = 0;
    rep(j,M) {
        sum += A[i][j]*B[j];
    }
    sum += C;
    if(sum > 0) ans++;
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
N,M=gets.chomp.split(" ").map(&:to_i)
ORD={}
LOW={}
EDGES={}
edeges = []
M.times do
    a,b=gets.chomp.split(" ").map(&:to_i)
    edeges.push([a,b])
    EDGES[a] ||= []
    EDGES[b] ||= []
    EDGES[a].push(b)
    EDGES[b].push(a)
end

$k=0
def dfs(u, pre)
    ORD[u] = $k
    $k += 1
    LOW[u] = ORD[u]
    EDGES[u].each do |v|
        if ORD[v] == nil
            dfs(v, u)
            LOW[u] = (LOW[u] < LOW[v]) ? LOW[u] : LOW[v]
        elsif v != pre
            LOW[u] = (LOW[u] < ORD[v]) ? LOW[u] : ORD[v]
        end
    end
end
dfs(edeges[0][0], nil)

ret = 0
edeges.each do |a,b|
    ret += 1 if ORD[a] < LOW[b] || ORD[b] < LOW[a]
end
puts ret


Measured memory_bytes: 14236
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	string S;
	int a[3] = {};
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		a[S[i] - 'a']++;
	}
	sort(a, a + 3);
	if (a[2] - a[0] <= 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  console.log(' ' + buildMaxHeap(lines.shift().split(' ').map(Number)).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && arr[left] > arr[i]) largest = left;
    else largest = i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 110732
import java.util.Scanner;

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

		int x[][] = new int[N][D];

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans =0;
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include<stdio.h>
#define MAX 100000
int A[MAX],n;
int partition(int p,int r){
 int x,i,j,t;
 x=A[r];
 i=p-1;
 for(j=p;j<r;j++){
  if(A[j]<=x){
   i++;
   t=A[i];A[i]=A[j];A[j]=t;
  }
 }
 t=A[i+1];A[i+1]=A[r];A[r]=t;
 return i+1;
}
int main(){
 int i,q;
 scanf("%d",&n);
 for(i=0;i<n;i++)scanf("%d",&A[i]);
 q=partition(0,n-1);
 for(i=0;i<n;i++){
  if(i)printf(" ");
  if(i==q)printf("[");
  printf("%d",A[i]);
  if(i==q)printf("]");
 }
 printf("\n");
 return 0;
}


Measured memory_bytes: 2932
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int T = sc.nextInt();
		int R = ((N + X - 1) / X) * T;
		System.out.println(R);
	}
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  vi a(n);
  REP(i,n)cin>>a[i];
  sort(ALL(a));reverse(ALL(a));
  int ans = 0;
  REP(i,n)ans += a[i] * (i%2==0 ? 1 : -1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
module Main where

import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List                      ( unfoldr )
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- VU.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ VU.length $ VU.ifilter (\i x -> even i && odd x) as


Measured memory_bytes: 4200
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x: x[0])
ans = 0
for i in a:
    if i[1] > m:
        ans += i[0] * m
        break
    else:
        ans += i[0] * i[1]
        m -= i[1]
print(ans)

Measured memory_bytes: 29020
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_110
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            var changeDict = new Dictionary<char, char>();
            for(int i = 0; i < s.Length; i++)
            {
                if (changeDict.ContainsKey(s[i]))
                {
                    if (changeDict[s[i]] != t[i])
                    {
                        Console.WriteLine("No");
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    changeDict.Add(s[i], t[i]);
                }
            }
            //keyの重複チェック
            var checkDict = new Dictionary<char, bool>();
            foreach (KeyValuePair<char, char> pair in changeDict)
            {
                if (checkDict.ContainsKey(pair.Value))
                {
                    Console.WriteLine("No");
                    return;
                }
                else
                {
                    checkDict.Add(pair.Value, true);
                }
            }

            Console.WriteLine("Yes");
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 14816
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[N];
        int count = 0;
        int sumA = 0;
        for(int i = 0; i < N; i++) {
        	A[i] = sc.nextInt();
        	sumA += A[i];
        }
        sc.close();
        
        
        for(int i = 0; i < N; i++) {
        	if((double)A[i] >= (double)sumA / (4 * M)) {
        		count ++;
        	}
        }
        
        
        if(count >= M)
        System.out.println("Yes");
        else
        System.out.println("No");



        
        }
	}


Measured memory_bytes: 23124
#include <stdio.h>
int binarySearch(int [], int, int);

int main()
{
  int i,j,n,q,key,A[100000],count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&j);
      A[i]=j;
    }
  
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&key);
      
      //      binarySearch(A, n, key);
      if(binarySearch(A, n, key)==1)
	{
	  count++;
	  //printf("%d",key);
	}
    }
  printf("%d\n",count);
  return 0;
}
int binarySearch(int A[],int n,int key)
{
  int left=0,right=n,mid;
  while(left<right)
    {
      mid = (left+right)/2;
      if(A[mid]==key)
	{
	  return 1;
	}
      if(key<A[mid])
	{
	  right = mid;
	}
      else if(key>A[mid])  left = mid + 1;
      // return 0;
    }
   return 0;
}
 



      



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

int main()
{
	int a, b, c;
	int tmp;
	
	cin >> a >> b >> c;
	
	if (a > b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	
	if (b > c)
	{
		tmp = b;
		b = c;
		c = tmp;
	}
	
	if (a > b)
	{
		tmp = a;
		a = b;
		b = tmp; 
	}
	
	cout << a <<" "<< b <<" "<< c << endl;
	return 0;
}

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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;



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

    int a;
    cin >> a;
    
    cout << a + a*a + a*a*a;


    return 0;
}


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

int main() {
	long long int N, ans = 0, j = 2;
	scanf("%lld",&N);
	if (N % 2 == 0) {
		for (int i = 0; i <= 26; i++) {
			j = j * 5;
			ans = ans + N / j;
		}
		printf("%lld", ans);
	}
	else {
		printf("0");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
	int n; cin>>n;;
	ll sum=0;
	ll ma=-MOD;
	ll mi=MOD;
	rep(i,0,n){
		ll a; cin>>a;
		chmin(mi,a);
		chmax(ma,a);
		sum+=a;
	}
	cout<<mi<<" "<<ma<<" "<<sum<<endl;


	return 0;
}


Measured memory_bytes: 3128
#include <stdio.h>

int main(void)
{
	int n;
	int score[20];
	int hi, hi2, x, max, max_n;
	
	scanf("%d", &n);
	
	for (x = 0; x < n; x++) {
		scanf("%d %d", &hi, &score[x]);
		if (x == 0) {
			max = score[x];
			max_n = hi;
		}
		else {
			if (max < score[x]) {
				max = score[x];
				max_n = hi;
			}
			else if (max == score[x]) {
				if (max_n > hi) {
					max_n = hi;
				}
			}
					
		}
	}
	
	printf("%d %d\n", max_n, max);
	
	return (0);
}

Measured memory_bytes: 600