akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) a.begin(),a.end()
#define debug(x) cout<<#x<<": "<<x<<endl
typedef long long ll;

typedef pair<int,int> Point;
typedef vector<Point> VP;
#define X first
#define Y second

bool compy(const Point &a, const Point &b) {
    return a.Y < b.Y;
}

Point p[50],pp[50];

int main(void){
    int N,K;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>K;
    rep(i,N){
        cin>>p[i].X>>p[i].Y;
    }
    sort(p,p+N);
    ll res = LLONG_MAX;
    rep(r,N)rep(l,r){
        ll w = p[r].X-p[l].X;
        if(r-l+1<K)continue;
        int idx=0;
        for(int i=l;i<=r;i++){
            pp[idx++]=p[i];
        }
        int n = idx;
        sort(pp,pp+n,compy);
        rep(i,n-K+1){
            ll h = pp[i+K-1].Y-pp[i].Y;
            res = min(res,w*h);
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    cout << ((n == m) ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
const int mod = 1e9 + 7;
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N = getint();
	ll kei = 0;
	ll kei2 = 0;
	ll kei3 = 0;
	const ll ma = (1ll << 60) - 1;
	rep(i, N) {
		ll a = getint();
		kei += a;
		kei2 += a * a;
		kei3 += kei2 >> 60;
		kei2 &= ma;
	}
	kei %= mod;
	kei = kei * kei % mod;

	kei2 = kei2 % mod;
	kei3 %= mod;
	kei3 = kei3 * ((1ll << 60) % mod) % mod;
	kei = (kei - kei2 - kei3 + mod + mod) % mod;

	kei = kei * (mod / 2 + 1) % mod;

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


	Would you please return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define gap ''
#define L(i) ((i) - (&i))

const int MAXN = 1e7 + 5;
int n, cnt[MAXN];
	
int main(){	
	cin >> n;
	ll ans = 0;
	for(int i = 1; i <= n; ++i){
		for(int j = 0; (j+=i)<=n;){
			cnt[j]++;
		}
	}
	for(int i = 1; i <= n; ++i){
		ans+=(ll)i * cnt[i];
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 42684
N = int(input())
ans = ''
if N > 81 or N < 1:
    ans = 'No'
else:
    a = [i for i in range(1,10)]
    for i in a:
        q, mod = divmod(N, i)
        if q < 10 and mod == 0:
            ans = 'Yes'
            break
if ans == 'No' or ans == '':
    print('No')
else:
    print('Yes')

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

using namespace std;
const int maxn = 2e5+2;
const int mod = 1e9+7;
const int inf = 1e9;

typedef long long ll;

int n;
int arr[maxn][5], dp[maxn][5];

int solve_dp (int pos, int last){
    if (pos - 1 == n) return 0;

    int &ans = dp[pos][last];

    if (ans != -1) return ans;

    ans = -inf;
    for (int i = 1; i <= 3; i++){
        if (last == i) continue;
        ans = max(ans, solve_dp(pos + 1, i) + arr[pos][i]);
    }
    return ans;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n;

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= 3; j++){
            cin >> arr[i][j];
        }
    }

    memset(dp, -1, sizeof dp);

    cout << solve_dp(1, -1) << "\n";

    return 0;
}


Measured memory_bytes: 14208
n = gets.to_i
vs = []
(n+1).times do |i|
  vs << [[],0]
end
(n-1).times do
  a,b = gets.split.map(&:to_i)
  vs[a][0] << b
  vs[a][1] += 1
  vs[b][0] << a
  vs[b][1] += 1
end
c = gets.split.map(&:to_i).sort.reverse
que = []
(n+1).times do |i|
  t,u = vs[i]
  que << i if u == 1
end

ans = 0
ds = []*(n)
while !que.empty? && !c.empty?
  v = que.shift
  tmp = vs[v]
  t = tmp[0]
  u = tmp[1]
  x = c.pop
  ans += x * u
  ds[v-1] = x
  t.each do |i|
    vs[i][1] -= 1
    if vs[i][1] == 1
      que << i
    end
  end
end
p ans
n.times do |i|
  t = ds[i]
  print "#{t}"
  print i == n-1 ? "" : " "
end


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

using namespace std;

int main() {
  string S;
  cin >> S;

  int ans{753};
  for (size_t i = 0; i != S.size() - 2; ++i) {
    ans = min(ans, abs(753 - stoi(S.substr(i, 3))));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

#include <vector>


void execute() {
	int n = 0;
	std::cin >> n;

	std::vector<int> ary;
	for (int i = 0; i < n; ++i) {
		int num = 0;
		std::cin >> num;
		ary.push_back(num);
	}


	for (int i = 0, end=ary.size(); i < end; ++i) {
		int j = 0;
		while (j < i) {
			if (ary[i] < ary[j]) {
				int tmp = ary[i];
				for (int k = i - 1; k >= j; --k) {
					ary[k + 1] = ary[k];
				}
				ary[j] = tmp;
				break;
			}
			++j;
		}
		for (int l = 0; l < end - 1; ++l) {
			std::cout << ary[l] << " ";
		}
		std::cout << ary[ary.size() - 1] << std::endl;
	}
}

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

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define mem(a,b) memset(a,b,sizeof(a))
#define shutdown ios::sync_with_stdio(false)
#define MAX 10e18+1000
#define INF 0x3f3f3f3f
#define MAR 10e5+100

int main(){
    shutdown;
    int a;
    ULL m[100];
    m[0]=2;m[1]=1;
    for(int i=2;i<=86;i++){
        m[i]=m[i-1]+m[i-2];
    }
    cin>>a;
    cout<<m[a]<<endl;

    return 0;
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
d = dict()
ans = 0
for x in a:
  if x not in d:
    d[x] = 0
  d[x] += 1
for x in a:
  t = (1<<x.bit_length()) - x
  f = (d.get(t,0) and d.get(x,0))
  if t == x:
    f = (d.get(t,0) >= 2)
  if f:
    d[x] -= 1
    d[t] -= 1
    ans += 1
print(ans)

Measured memory_bytes: 33856
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll N;
  cin>>N;
  for(ll h=1;h<=3500;h++){
    for(ll n=1;n<=3500;n++){
      if(4*h*n-n*N-h*N==0){
        continue;
      }
      if((N*h*n)%(4*h*n-n*N-h*N)==0 && 4*h*n-n*N-h*N>0){
        cout<<h<<' '<<n<<' '<<(N*h*n)/(4*h*n-n*N-h*N)<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    char c;
    cin >> a >> c >> b;
    ll ans = (c == '+' ? a+b : a-b);
    print(ans);

}


Measured memory_bytes: 256
if __name__ == '__main__':

	n = int(input())
	A = list(map(int,input().split()))

	cnt = 0
	for i in A:
		if i % 2 == 0:
			if i % 3 == 0 or i % 5 == 0:
				cnt += 1
		else:
			cnt += 1
	if cnt == n:
		print("APPROVED")
	else:
		print("DENIED")


Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
int dp[3005][3005];
signed main()
{
    IOS
    int n; cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int L = n-1;L >=0 ;L--)
    {
      for(int R = L;R < n;R++)
      {
        if(L == R) dp[L][R] = arr[L];
        else dp[L][R] = max(arr[L] - dp[L+1][R],arr[R] - dp[L][R-1]);
      }
    }
    cout<<dp[0][n-1];
    return 0;
}

Measured memory_bytes: 70016
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	if(n<1200)
	{
		cout<<"ABC";
	}
	else if(n>=1200&&n<2800)
	{
		cout<<"ARC";
	}
	else
	{
		cout<<"AGC";
	}
	return 0;
}

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

int main() {
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int m=a[0],p=1;
	for(int i=1;i<n;i++)
	{
		if(m>a[i]){m=a[i];p=i+1;}
	}
	cout<<p<<endl;
	return 0;
}



Measured memory_bytes: 3472
import java.util.*;
 
class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        double a = sc.nextDouble();
                        double b = sc.nextDouble();
                        double c = Math.toRadians(sc.nextDouble());
                        System.out.println(a * b * Math.sin(c) / 2.);
                        System.out.println((a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(c))));
                        System.out.println(b * Math.sin(c));
                }
        }
}


Measured memory_bytes: 28016
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  char s[n],t[n];
  scanf("%s",&s);
    scanf("%s",&t);
 
  for(int i=0;i<n;i++){
	printf("%c%c",s[i],t[i]);
  }
  
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	
	public static int N, A, B, C;
	public static int[] l;
	public static int INF = 32767;
	
	public static int dfs( int n, int a, int b, int c) {
		if( n == N ) {
			if( a > 0 && b > 0 && c > 0 ) {
				return Math.abs(a-A) + Math.abs(b-B) + Math.abs(c-C) - 30;
			}
			return INF;
		}
		int r = dfs( n+1, a, b, c );
		int ra = dfs( n+1, a+l[n], b, c ) + 10;
		int rb = dfs( n+1, a, b+l[n], c ) + 10;
		int rc = dfs( n+1, a, b, c+l[n] ) + 10;
		return Math.min(r, Math.min(ra, Math.min(rb, rc)));
	}
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	N = sc.nextInt();
    	A = sc.nextInt();
    	B = sc.nextInt();
    	C = sc.nextInt();
    	l = new int[N];
    	for( int i = 0; i < N; i++  ) {
    		l[i] = sc.nextInt();
    	}
    	
    	System.out.println( dfs( 0, 0, 0, 0 ) );
    	
    	sc.close();
    }
}

Measured memory_bytes: 24000
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ll a=0,b=0;
    cin>>a>>b;
    cout<<max(0ll,a-2*b);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
template <class T>void UNIQUE(vector<T> &x){
	sort(all(x));
	x.erase(unique(all(x)), x.end());
}

// }}} End Header
ll kaijo(ll n){
	ll ans = 1;
	for(ll i=1; i<=n; i++){
		ans*=i;
		ans%=mod;
	}
	return ans;
}

int main() {
	ll n, m, ans = 0;
	cin >> n >> m;
	if(abs(n-m)>1){
		cout << 0 << endl;
		return 0;
	}
	ans = kaijo(n)*kaijo(m);
	if(n == m) ans*=2;
	cout << ans%mod << endl;
	return 0;
}


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

using namespace std;

int main(void) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> b(m);
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int s;
            cin >> s;
            b[i].push_back(s);
        }
    }
    vector<int> p(m);
    for (int i = 0; i < m; i++) cin >> p[i];

    int ans = 0;
    for (int sw = 0; sw < (int)pow(2, n); sw++) {
        bool all_on = true;

        for (int i = 0; i < m; i++) {
            int on = 0;
            for (int s: b[i]) {
                on += (sw >> (s - 1)) % 2;
            }
            all_on &= (on % 2 == p[i]);
        }

        if (all_on) ans += 1;

    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    int k = 0;
    long t = 0;
    long tt = 26;
    while(t < n) {
      t += tt;
      tt *= 26;
      k++;
    }
    String[] s = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    long r = n;
    for(int i = 1; i < k; i++) {
      r -= (long)Math.pow(26, i);
    }
    String ans = "";
    for(int i = 1; i <= k; i++) {
      int rr = (int)(r % 26);
      if((rr % 26) == 0) {
        ans = s[25] + ans;
        r = (r / 26);
      } else {
        ans = s[rr - 1] + ans;
        r = (r / 26) + 1;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 39240
A,B,C,D=map(int,input().split())
if C%B==0:
    a=C//B
else:
    a=C//B+1
if A%D==0:
    b=A//D
else:
    b=A//D+1
if a<=b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9120
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    input()
    s=list(map(int,input().split()))
    input()
    t=list(map(int,input().split()))
    s=set(s)
    t=set(t)
    print(len(s&t))

main()



Measured memory_bytes: 6820
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

class Compare {
public:
	bool operator()(const string&l, const string&r) {
		if (l.size() == r.size()) {
			for (int i = 0; i < l.size(); ++i) {
				if (l[i] == r[i])continue;
				else return l[i] < r[i];
			}
			return false;
		}
		else {
			return l.size()< r.size();
		}
	}
};	//aa?????????????????¶

int main() {
	int N; cin >> N;
	map<string, int,Compare>mp;
	for (int i = 0; i < N; ++i) {
		string st; int n; cin >> st >> n;
		mp[st] += n;
	}
	for (auto m : mp) {
		cout << m.first << " " << m.second << endl;
	}

	return 0;
}

Measured memory_bytes: 3128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long[] numbers = new long[5];
        for (int i = 0; i < 5; i++) {
            numbers[i] = sc.nextLong();
        }

        Arrays.sort(numbers);
        long min = numbers[0];

        long waitTime = 0;
        if ((N % min) == 0) {
            waitTime = N / min - 1;
        }
        else {
            waitTime = N / min;
        }

        long ans = waitTime + 5;
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

Measured memory_bytes: 23892
using System;
using System.IO;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {            
            string[] arr = Console.ReadLine().Split(' ');

            var a = ulong.Parse(arr[0]);
            var b = decimal.Parse(arr[1]);

            var sum =(ulong)(a * b);

            Console.WriteLine(sum);
        }

    }
}

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

#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define F first
#define S second

using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, P>;

class S {
  public:
    ll cur;
    ll s;
    ll t;

    S(ll c_, ll s_, ll t_) : cur(c_), s(s_), t(t_) {}

    bool operator < (const S& s) const {
      return this->t > s.t;
    };
};

int main() {
  ll n, m, s;
  cin >> n >> m >> s;
  vector<vector<PP>> edge(n);

  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edge[u].push_back(PP(v, P(a, b)));
    edge[v].push_back(PP(u, P(a, b)));
  }

  vector<P> ex(n);
  rep(i, n) {
    ll c, d;
    cin >> c >> d;
    ex[i] = P(c, d);
  }

  const ll s_max = 5000;

  const ll inf = 1e18;
  vector<vector<ll>> res(n, vector<ll>(s_max + 1, inf));

  priority_queue<S> q;
  s = min(s, s_max);
  q.push(S(0, s, 0));
  while(!q.empty()) {
    S t = q.top(); q.pop();
    ll tc = t.cur;
    ll ts = t.s;
    ll tt = t.t;

    if(res[tc][ts] <= tt) continue;
    res[tc][ts] = tt;

    ll c = ex[tc].F;
    ll d = ex[tc].S;

    {
      ll ns = ts + c;
      ll nt = tt + d;
      if(ns < s_max) {
        q.push(S(tc, ns, nt));
      }
    }

    rep(j, edge[tc].size()) {
      ll next = edge[tc][j].F;
      ll a = edge[tc][j].S.F;
      ll b = edge[tc][j].S.S;

      ll ns = ts - a;
      ll nt = tt + b;

      if(ns < 0) continue;
      if(ns >= s_max) continue;
      if(res[next][ns] <= nt) continue;
      q.push(S(next, ns, nt));
    }
  }

  for(ll i = 1; i < n; i++) {
    ll r = inf;
    rep(j, res[i].size()) {
      r = min(res[i][j], r);
    }
    cout << r << endl;
  }

  return 0;
}


Measured memory_bytes: 17480
n, x = map(int, input().split())
while n != 0:
    cnt = 0
    i = 1
    while i < n - 1:
        j = i + 1
        while j < n:
            k = j + 1
            while k <= n:
                if (i + j + k == x):
                    cnt += 1
                k += 1
            j += 1
        i += 1
            
    print(cnt)
    n, x = map(int, input().split())



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

int main() {
  int n;
  cin>>n;
  vector<vector<int>> ans(n, vector<int>(n, 0));
  for(int i=0;i<n;i++){
    int u, k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v;
      cin>>v;
      ans[u-1][v-1]=1;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cout<<ans[i][j];
      if(j!=n-1)cout<<' ';
    }
    cout<<endl;
  }
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	priority_queue<double> s;
	for(int i = 0; i < n; i++){
		double num;
		cin >> num;
		s.push(-num);
	}
	while(1){
		double first = -s.top();
		s.pop();
		if(s.empty()){
			cout << first;
			return 0;
			break;
		}
		double second = -s.top();
		s.pop();
		double res = (first + second) / 2.0;
		s.push(-res);
	}
}

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

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

int main() {
    ll N, D, A, X, H;
    cin >> N >> D >> A;
    priority_queue<vector<ll>> pq;
    rep(i, N) {
        cin >> X >> H;
        pq.push({-X, H});
    }
    ll ans = 0, bomb = 0;
    while (pq.size() > 0) {
        auto p = pq.top();
        pq.pop();
        //cout << "p[0]=" << p[0] << ", p[1]=" << p[1];
        if (p[1] > 0) {
            if (D == 0) {
                ans += (p[1] + A - 1) / A;
            } else if (p[1] > A * bomb) {
                ll add = (p[1] - A * bomb + A - 1) / A;
                ans += add;
                pq.push({p[0] - D - D, -add});
                bomb += add;
            }
        } else {
            bomb += p[1];
        }
        //cout << ", ans=" << ans << ", bomb=" << bomb << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12336
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int X[100];

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

	for (int i=0; i<N; i++) {
		cin >> X[i];
	}

	int min_vital = INF;
	int min_P;
	for (int P=1; P<=100; P++) {
		int vital = 0;
		for (int i=0; i<N; i++) {
			vital += (X[i] - P) * (X[i] - P);
		}

		if (vital < min_vital) {
			min_vital = vital;
		}
	}

	cout << min_vital << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;
	cin>>h>>w;
	vs a(h);
	rep(i,h)cin>>a[i];
	set<int> dx,dy;
	rep(i,h){
		bool ok=true;
		rep(j,w)ok&=a[i][j]=='.';
		if(ok)dy.insert(i);
	}
	rep(j,w){
		bool ok=true;
		rep(i,h)ok&=a[i][j]=='.';
		if(ok)dx.insert(j);
	}
	rep(i,h){
		if(dy.find(i)!=dy.end())continue;
		rep(j,w)if(dx.find(j)==dx.end())cout<<a[i][j];
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  auto p = minmax({a, b});
  for (; p.second % p.first; p = minmax({p.first, p.second - p.first})) {
  }
  cout << p.first << endl;
}



Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;

int arr[11];

bool check(int n)
{
  string temp  = to_string(n);
  for(int i=0;i<temp.length();i++)
  {
    int k = temp[i]-'0';
    if(arr[k]==true){
      return false;
    }
  }
  return true;
}

int main()
{
  ios_base::sync_with_stdio(0);
  int num,n;
  cin >> num >> n;
  memset(arr,false,sizeof(arr));
  for(int i=0;i<n;i++)
  {
    int x;
    cin >> x;
    arr[x]=true;
  }
  while(true){
    if(check(num)){
      cout << num << endl;
      break;
    }
    else{
      ++num;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const ll INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
const ll Maxn=1e5;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll kc(ll a,ll b)
{
    ll c=1;
    while(b)
    {
        if(b&1)c=(c*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return c;
}
bool cmp(double x,double y)
{
    return x>y;
}
int d[12][12];
int main()
{
    ios::sync_with_stdio(false);
   int n,m;
   cin>>n>>m;
   for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    cin>>d[i][j];
   int sum=0;
   for(int i=1;i<n;i++)
    for(int j=i+1;j<=n;j++)
    {int ant=0;
        for(int k=1;k<=m;k++)
            ant+=(d[i][k]-d[j][k])*(d[i][k]-d[j][k]);
           // cout<<ant<<endl;
            int b=sqrt(ant);
        if(b*b==ant)sum++;
    }cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int a, b, h=0, s=0, m=0;
	cin >> a;
	if (a >= 3600) {
		h = a / 3600;
		a = a - h * 3600;
	}
	if (a >= 60) {
		m = a / 60;
		a = a - m * 60;
	}
	s = a;
	printf("%d:%d:%d\n", h, m, s);
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[10051]={0};
          for(int j=1;j<=105;j++)
          {
              for(int k=1;k<=105;k++ )
              {
                  for(int l=1;l<=105;l++)
                  {
                      if(j*j+k*k+l*l+j*k+k*l+l*j<=10050)
                        a[j*j+k*k+l*l+j*k+k*l+l*j]++;

                  }
              }
          }
       for(int i=1;i<=n;i++)
        cout<<a[i]<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<string> v(n);
    map<string, int> m;
    int x = 0;
    for (auto &&i : v) {
        cin >> i;
        m[i]++;
        x = max(x, m[i]);
    }
    for (auto &&j : m) {
        if(j.second == x) cout << j.first << "\n";
    }
    return 0;
}

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

int M,N;
char C[511][511];
int xa[26],ya[26];
int xb[26],yb[26];

bool check(int x1,int y1,int x2,int y2 ){
  assert( x2 == x1 || y1 == y2 );
  if( x1 > x2 ) swap(x1,x2);
  if( y1 > y2 ) swap(y1,y2);
  if( x1 == x2 ){
    for(int y=y1+1;y<y2;y++){
      if( C[x1][y] != '.' ) return false;
    }
  } else if( y1 == y2 ){
    for(int x=x1+1;x<x2;x++){
      if( C[x][y1] != '.' ) return false;
    }
  }
  return true;
}

bool check2(int x1,int y1,int x2,int y2 ){
  assert( x2 == x1 || y1 == y2 );
  if( x1 > x2 ) swap(x1,x2);
  if( y1 > y2 ) swap(y1,y2);
  if( x1 == x2 ){
    for(int y=y1+1;y<y2;y++){
      if( C[x1][y] == '.' ) return true;
    }
  } else if( y1 == y2 ){
    for(int x=x1+1;x<x2;x++){
      if( C[x][y1] == '.' ) return true;
    }
  }
  return false;
}
void view(){
  cout <<"view" << endl;
  for(int i=0;i<M;i++)
    {
      for(int j=0;j<N;j++) cout << C[j][i] ;
      cout << endl;
    }
}



int main(){
  cin >> M >> N;
  memset( xa, -1,sizeof(xa) );
  memset( xb, -1,sizeof(xb) );
  memset( ya, -1,sizeof(ya) );
  memset( yb, -1,sizeof(yb) );
  for(int i=0;i<M;i++){
    for(int j=0;j<N;j++){
      cin >> C[j][i];
      if( C[j][i] != '.' ){
        int id = (int)(C[j][i] - 'A');
        if( xa[id] == -1 ) {
          xa[id] = j; ya[id] = i;
        } else {
          xb[id] = j; yb[id] = i;
        }
      }
    }
  }

  bool flag;
  int res = 0;
  do{
    flag = false;
    for(int i=0;i<26;i++){
      if( xa[i]==-1 ) continue;
      if( xa[i] == xb[i] || ya[i] == yb[i] ) {
        if( check(xa[i],ya[i],xb[i],yb[i]) && check2(xa[i],ya[i],xb[i],yb[i]) ){
          res+=2; 
          C[xa[i]][ya[i]]='.';
          C[xb[i]][yb[i]]='.';
          xa[i] = ya[i] = -1;
          flag = true;
        }
      } else {
        if( (check(xa[i],yb[i],xb[i],yb[i]) && check(xa[i],yb[i],xa[i],ya[i]) && C[xa[i]][yb[i]] == '.') ||
            (check(xb[i],ya[i],xa[i],ya[i]) && check(xb[i],ya[i],xb[i],yb[i]) && C[xb[i]][ya[i]] == '.') ){
          res+=2;
          C[xa[i]][ya[i]]='.';
          C[xb[i]][yb[i]]='.';
          xa[i] = ya[i] = -1;
          flag = true;
        }
      }
    }
    // view();
  } while( flag );

  cout << res << endl;  

}

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

int main() {
	int64_t X;
	cin >> X;
	int ans = 0;
	int64_t x = 100;
	while (true) {
		ans++;
		x = (int64_t)(x * 1.01);
		if (x >= X) {
			cout << ans << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
   int a,b;
   cin>>a>>b;
   int x;
   if(b<10){
       x=10*a+b;
   }
   else if(b>9&&b<100){
       x=100*a+b;
   }
   else{
       x=1000*a+b;
   }
   int m=0;
   for(int i=1;i<1000;i++){
       if(x==i*i){
           cout<<"Yes"<<endl;
           m++;
           break;
       }
       if(x<i*i){
           break;
       }
   }
   if(m==0){
       cout<<"No"<<endl;
   }
}

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

int main(){
  float x[10], ans = 0;
  string u[10];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> x[i];
    cin >> u[i];

    if (u[i] == "BTC")
    {
      ans += 380000.0 * x[i];
    }
    else
    {
      ans += x[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
given_a = list(map(int, input().split()))

money = 1000
kabu = 0

a = []

for kabuka in given_a:
    if len(a) > 0 and a[-1] == kabuka:
        continue
    else:
        a.append(kabuka)

n = len(a)

if n == 1:
    print(money)
    exit()
    
for i in range(n):
   if i == 0:
       if a[i+1] < a[i]:
           continue
       else:
           kabu += money // a[i]
           money %= a[i]
   elif i == n-1:
       money += kabu * a[i]
       kabu = 0
   else:
       if a[i-1] < a[i] and a[i] > a[i+1]:
           money += kabu * a[i]
           kabu = 0
       if a[i-1] > a[i] and a[i] < a[i+1]:
           kabu += money // a[i]
           money %= a[i]

print(money)
           
       


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


/*
int solve(int i){
	if(i == 0) return 0;
	if(i == 1) return 0;
	if(memo[i] != -1) return memo[i];
	int m = INT_MAX;
	for(int d = 1; d <= k; d++){
		if(i - d < 0) break;
		m = min(solve(i-d, k)+abs(h[i]-h[i-d]), m);
	}
	return memo[i] = m;
}*/


int n;
long long a[3000];

long long dp[3001][3001] = {};


long long solve(int l, int r, bool first){
	if(dp[l][r] != 0) return dp[l][r];
	if(l == r) return 0;
	long long ret;
	if(first){
		ret =
			max(solve(l+1, r, false) + a[l],
			solve(l, r-1, false) + a[r-1]);
	}
	else{
		ret =
			min(solve(l+1, r, true) - a[l],
			solve(l, r-1, true) - a[r-1]);
	}
	return dp[l][r] = ret;
}


int main(){
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	

	cout << solve(0, n, true) << endl;
	//cout << setprecision(12) << solve(k) << endl;

    return 0;
}


Measured memory_bytes: 70144
l = []

for i in range(3):
    l.append(list(map(int, input().split())))

for i in range(2):
    for j in range(2):
        a = l[i][j] - l[i][j+1]
        b = l[i+1][j] - l[i+1][j+1]
        if a != b:
            print("No")
            exit(0)

print("Yes")

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

int n ;
int m[110] ;
long long int dp[110][30] ;

long long int f( int p , int sum ){
	
	if( p == n-2 ){
		if( sum == m[p+1] ) return 1 ;
	}
	
	if( dp[p][sum] != -1 ) return dp[p][sum] ;
	
	long long int ans = 0 ;
	if( sum + m[p+1] <= 20 ){
		ans += f( p+1 , sum + m[p+1] ) ;
	}
	if( sum - m[p+1] >= 0 ){
		ans += f( p+1 , sum - m[p+1] ) ;
	}
	return dp[p][sum] = ans ;
}

int main(){
	
	cin >> n ;
	for( int i=0 ; i<n ; i++ ) cin >> m[i] ;
	
	for( int i=0 ; i<110 ; i++ )
		for( int j=0 ; j<30 ; j++ )
			dp[i][j] = -1 ;
	
	cout << f(0,m[0]) << endl ;
	
return 0 ;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>

using namespace std; using ll=long long; const int INF=1e9;
typedef pair<int,int> P;

int main() {
  int n, m; cin>>n>>m;
  //int m; cin>>m; int n=m*3+1;
  //cout<<n<<" ";
  vector<bool> b(n);
  int jj=0, pp=0;
  for(int i=0,j=(m/2)*2-1;j>=0&&jj<m;i++,j-=2) {
    if (i+j+2 <= n) {
      cout<<i+1<<" "<<i+j+2<<endl;
      pp=max(pp,i+j+2); jj++;
      b[i]=true; b[i+j+1]=true;
    }
  }
  for(int i=pp,j=(m/2)*2;jj<m;i++,j-=2) {
    if (i+j+2 <= n) {
      cout<<i+1<<" "<<i+j+2<<endl;
      jj++;
      b[i]=true; b[i+j+1]=true;
    }
    else i--;
  }

  assert(jj == m);
  int oo = 0;
  for(int i=0;i<n;i++) {
    oo += b[i];
  }
  assert(m*2 == oo);
  //cout<<"Done!"<<endl;
  //cout<<jj<<" "<<m<<endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
using P = pair<int,int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

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

    cout << s.substr(0,3);
    return 0;
}

Measured memory_bytes: 3596
n,m = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)

a.sort!.reverse!
kijun = a.inject(:+) / (4*m).to_f
if (a[m-1] < kijun)
  puts 'No'
else
  puts 'Yes'
end

Measured memory_bytes: 1788
n=int(input())
a=[int(i) for i in input().split()]
su = sum(a)
pref = a[0]
suf = su - pref
ans  = abs(suf-pref)
for i in range(1,len(a)-1):
    pref+=a[i]
    suf = su-pref
    ans  = min(ans,abs(pref-suf))

print(ans)


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

int main() {
    long long int dp[101][100001],a[101][2];
    long long int n,w,i,j,item,wt;
    cin>>n>>w;
    for(i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1];
    }
    for(j=0;j<w+1;j++)
    {
        dp[0][j]=0;
    }
    for(j=0;j<n+1;j++)
    {
        dp[j][0]=0;
    }
    for(item=1;item<=n;item++)
    {
        for(wt=1;wt<=w;wt++)
        {
            if(a[item-1][0]<=wt)
            {
                dp[item][wt] = std::max(dp[item-1][wt],a[item-1][1]+dp[item-1][wt-a[item-1][0]]);
            }
            else
            {
                dp[item][wt] = dp[item-1][wt];
            }
        }
    }
    cout<<dp[n][w];
	return 0;
}


Measured memory_bytes: 79104
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    System.out.println(String.valueOf(s.charAt(0)) + (s.length()-2)+ String.valueOf(s.charAt(s.length()-1)));
  }
}

/*
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String blank = sc.nextLine();
String s = sc.nextLine();
System.out.println();
System.exit(0)
*/


Measured memory_bytes: 21716
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define MAX_DIGIT 20
#define SIZE 100005

struct Node{

	int child[2];
	ll count;
};

ll N,K;
int root = 0,num_nodes;
int A[SIZE],POW[MAX_DIGIT+1];
int is_ONE[SIZE][MAX_DIGIT+1],MID[MAX_DIGIT+1];
Node nodes[SIZE*(MAX_DIGIT+1)];

void add(int index){

	int loc = root;

	for(int i = MAX_DIGIT; i >= 0; i--){

		int digit = is_ONE[index][i];

		if(nodes[loc].child[digit] == -1){

			nodes[loc].child[digit] = num_nodes++;
		}
		loc = nodes[loc].child[digit];
		nodes[loc].count++;
	}
}

void init(){

	for(int i = 0; i <= num_nodes; i++){

		nodes[i].child[0] = -1;
		nodes[i].child[1] = -1;
		nodes[i].count = 0;
	}

	num_nodes = 1;
}

ll calc(int index){

	int loc = root;
	ll ret = 0;

	for(int i = MAX_DIGIT; i >= 0; i--){
		int digit = is_ONE[index][i];
		int rev_digit = 1-digit;

		if(MID[i] == 0){

			if(nodes[loc].child[digit] == -1){

				return ret;
			}
			loc = nodes[loc].child[digit];

		}else{ //MID[i] == 1

			if(nodes[loc].child[digit] != -1){

				ret += nodes[nodes[loc].child[digit]].count;
			}
			if(nodes[loc].child[rev_digit] == -1){

				return ret;
			}
			loc = nodes[loc].child[rev_digit];
		}
	}

	ret += nodes[loc].count;
	return ret;
}

int main(){

	POW[0] = 1;
	for(int i = 1; i <= MAX_DIGIT; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%lld %lld",&N,&K);

	num_nodes = SIZE*(MAX_DIGIT+1);

	K = (N*(N+1))/2-K+1;

	A[0] = 0;
	for(int i = 1; i <= N; i++){
		scanf("%d",&A[i]);
		A[i] = A[i]^A[i-1];
	}

	for(int i = 0; i <= N; i++){
		for(int loop = 0; loop < MAX_DIGIT; loop++){
			if(A[i] & POW[loop]){

				is_ONE[i][loop] = 1;

			}else{

				is_ONE[i][loop] = 0;
			}
		}
	}

	int left = 0,right = 2*1024*1024-1,mid = (left+right/2);
	ll ans,tmp;

	while(left <= right){

		for(int loop = 0; loop < MAX_DIGIT; loop++){
			if(mid & POW[loop]){

				MID[loop] = 1;

			}else{

				MID[loop] = 0;
			}
		}

		init();

		tmp = 0;
		for(int i = N; i >= 0; i--){

			tmp += calc(i);
			add(i);
		}

		if(tmp >= K){

			ans = mid;
			right = mid-1;

		}else{

			left = mid+1;
		}

		mid = (left+right)/2;
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 44624
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    char c;
    cin >> c;
    if(c >= 65 and c <= 90 )
        cout << 'A' << endl;
    else
    {
        cout << 'a' << endl;
    }
    
    
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int  n;
  cin>>n;
  if(n%2!=0){
    cout<<(((double)n+1.0)/2.0)/(double)n<<"\n";
  }else{
    cout<<((double)n/2.0)/(double)n<<"\n";
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
 
        int numOfGame = stdIn.nextInt();
 
        int taroScore = 0;
        int hanakoScore = 0;
        for(int i = 0; i < numOfGame; i++) {
            String taroHand = stdIn.next();
            String hanakoHand = stdIn.next();
             
            int result = taroHand.compareTo(hanakoHand);
            if(result > 0) {
                // taro win
                taroScore += 3;
            } else if(result < 0) {
                // hanako win
                hanakoScore += 3;
            } else {
                // draw
                taroScore++;
                hanakoScore++;
            }
        }
        System.out.println(taroScore + " " + hanakoScore);
    }
}

Measured memory_bytes: 29896
#include <stdio.h>
int main(void){
    
    char s[1001];
    int cntn=0, cnts=0, cnte=0, cntw=0, i=0;

    scanf("%s", s);

    while(s[i] != '\0'){
        if(s[i]=='N') cntn++;
        else if(s[i]=='S') cnts++;
        else if(s[i]=='E') cnte++;
        else if(s[i]=='W') cntw++;
        i++;
    }

    if(((cntn==0 && cnts==0) || (cntn>0 && cnts>0)) &&
       ((cnte==0 && cntw==0) || (cnte>0 && cntw>0))) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 128
use std::io::*;

fn read_bytes(length: usize, skip_next: bool) -> Vec<u8> {
    let mut bytes = vec![0; length];
    let stdin = stdin();
    let mut stdin = stdin.lock();
    stdin.read_exact(&mut bytes).unwrap();
    if skip_next {
        stdin.bytes().next();
    }
    bytes
}

fn println<T: ToString>(s: T) {
    println!("{}", s.to_string());
}

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

fn main() {
    let s = read_bytes(4, false);

    for pair in s.windows(2) {
        if pair[0] == pair[1] {
            println("Bad");
            return;
        }
    }

    println("Good");
}


Measured memory_bytes: 4352
#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<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  int n; cin >> n;
  vector<int> a(n); REP(i,n) cin >> a[i];
  int ans = 0;
  REP(i,n) {
    if (i % 2 == 0) {
      if (a[i] % 2 == 1) ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
import sys
from itertools import accumulate

limit = 2 * 123456 + 1

def solve():
    is_prime = eratos(limit)
    cnt = [0] + list(accumulate(is_prime))

    while 1:
        n = int(sys.stdin.readline().rstrip())

        if n == 0:
            return

        ans = cnt[2*n + 1] - cnt[n + 1]

        print(ans)

def eratos(n):
    sieve = [True] * n
    sieve[0] = sieve[1] = False

    for p in range(2, n):
        if p*p > n:
            break
        if sieve[p]:
            for q in range(p*p, n, p):
                sieve[q] = False

    return sieve

if __name__ == '__main__':
    solve()

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader vd = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(vd.readLine());
		int a = Integer.parseInt(vd.readLine());


		if(n%500<=a) System.out.println("Yes");
		else System.out.println("No");

	}

}


Measured memory_bytes: 21332
def main():
    N, M, Q = map(int, input().split())
    cs = [[0 for _ in range(N + 1)] for _ in range((N + 1))]
    for _ in range(M):
        L, R = map(int, input().split())
        cs[L][R] += 1
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            cs[i][j] += cs[i - 1][j]
            cs[i][j] += cs[i][j - 1]
            cs[i][j] -= cs[i - 1][j - 1]
    for _ in range(Q):
        p, q = map(int, input().split())
        print(cs[q][q] - cs[q][p - 1] - cs[p - 1][q] + cs[p - 1][p - 1])


main()


Measured memory_bytes: 13472
#include<cstdio>
#include<bits/stdc++.h>
#define fi first
#define sc second
#define pb push_back


using namespace std;

long long arr[5];

int main() {
	memset(arr, 0, sizeof (arr));

	int N;
	string s;
	
	map<char, int> mep;
	mep['M'] = 0;
	mep['A'] = 1;
	mep['R'] = 2;
	mep['C'] = 3;
	mep['H'] = 4;
	
	cin >> N;
	for (int i = 0; i < N; i++) { 
		cin >> s;
		if (mep.find(s[0]) == mep.end()) continue;
		arr[mep[s[0]]]++;
	}
	long long ans = 0;
	
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += (arr[i] * arr[j] * arr[k]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int ptn;
  long long allPtn = 0;
  cin >> ptn;
  vector<int> vec(ptn);
  vector<int> cntNum(ptn);
  vector<long long> numPtn(ptn);
  
  // vecの中に値をセット
  for(int i = 0; i < ptn; i++){
   cin >> vec.at(i); 
  }
  
  // 同じ値の数求める
  for(int i = 0; i < ptn; i++){
    cntNum.at(vec.at(i)-1) += 1;
  }
  
  // 各値のパターンを求める
  long long n;
  for(int i = 0; i < ptn; i++){
    n = cntNum.at(i);
    numPtn.at(i) = (n * (n-1)) / 2;
    allPtn += numPtn.at(i);
  }
  
  // 1つ消去したパターンを求める    
  // 全体 - Aiの消去前 + Aiの消去後  ※消去前を引いて一旦なかったことにする
  long long aft;
  long long ans;
  for(int i = 0; i < ptn; i++){
    aft = cntNum.at(vec.at(i)-1) - 1;// Ai消去後
    ans = allPtn - numPtn.at(vec.at(i)-1) + (aft * (aft-1) / 2); // 全体 - Aiの消去前 + Aiの消去後
    cout << ans << endl;
  } 
}


Measured memory_bytes: 5760
#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 <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int main()
{
  _int64 ans;
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  if (a>b) printf("0\n");
  else if (n==1)
  {
    if (a==b) printf("1\n");
    else printf("0\n");
  }
  else
  {
    ans=b-a;
    ans*=(n-2);
    ans++;
    printf("%lld\n",ans);
  }
  return 0;
}

Measured memory_bytes: 256