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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/29  Problem: 070_abc_b / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	ans = min(b,d) - max(a,c);
	if (ans < 0)ans = 0;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  string a, b, c;
  cin >>a >> b>>c;
  if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0)) cout << "YES" <<endl;
  else cout << "NO" <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n;
 cin>>n;
 string s;
 cin>>s;
 if(n==1){
  cout<<0<<endl;
  return 0;
 }
 vector<int> a(n);
 a[n-1]=(s[n-1]=='.');
 vector<int> b(n);
 b[0]=(s[0]=='#');
 for(int i=n-2;i>=0;i--){
  if(s[i]=='.') a[i]=a[i+1]+1;
  else a[i]=a[i+1];
 }
 for(int i=1;i<n;i++){
  if(s[i]=='#') b[i]=b[i-1]+1;
  else b[i]=b[i-1];
 }
 int ans=a[1];
 ans=min(b[n-2],ans);
 for(ll i=1;i<n-1;i++){
  ans=min(ans,a[i+1]+b[i-1]);
 }
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 2180
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict, Counter


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = Counter(v[::2])
    d2 = Counter(v[1::2])
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans, half = n, (n // 2)
    la1, la2 = len(a1) - 1, len(a2) - 1
    for h in range(3):
        for i in range(3):
            ai1, ai2 = min(h, la1), min(i, la2)
            aa1, aa2 = rd1[a1[ai1]], rd2[a2[ai2]]
            s1, s2 = set(aa1), set(aa2)
            if len(s1) > 1 or len(s2) > 1 or (s1 - s2):
                ans = min(
                    ans, 2 * half - a1[ai1] - a2[ai2])
            else:
                ans = min(ans,
                          2 * half - a1[ai1] - a2[ai2] + min(a1[ai1], a2[ai2]))
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 107244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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

int main()
{
    int n,k; cin >> n >> k;
    vector<ll> h(n);
    for(int i=0;i<n;i++) cin >> h[i];
    sort(h.begin(),h.end());
    ll count =0;
    for(int i=0;i<n-k;i++){
        count += h[i];
    }
    cout << count << endl;
}
    

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, P; cin >> A >> P;
    int cnt = A * 3 + P;
    cout << cnt / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int prime(ll a){
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){
    if(a%i==0){return 0;}
  }
  return 1;
}
int main(){
  ll N,ans=0;
  cin>>N;
  ll n=N,count=0,sqrtN=sqrt(N);
  vector<ll> vec(sqrtN);
  for(ll i=1;i*i<=n;i++){
    count=0;
    while(N%i==0 && N>1 && prime(i)==1){
      N/=i;
      count++;
    }
    if(count>0){
      ll j=1;
        while(count>=j){
          count-=j;
          if(count>=j+1){j++;}
        }
        ans+=j;
    }
    count=0;
    if(n%i==0 && prime(n/i)==1 && N%(n/i)==0){
      while(N%(n/i)==0 && N>1){
        N/=(n/i);
        count++;
      }
      if(count>0){
        ll j=1;
          while(count>=j){
            count-=j;
            if(count>=j+1){j++;}
          }
          ans+=j;
      }
    }
  }
  cout<<ans<<endl;
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;
const int mod = (int)1e9 + 7;
const ull BS = 10000019ULL;

inline int in() {int x; scanf("%d",&x); return x;}
inline ll lin() {ll x; scanf("%lld",&x); return x;}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

char s[55], t[55];

int n;
int dp[55][4][4];

int go(int pos, int c1, int c2){
    if(pos > n) return 1;
    if(dp[pos][c1][c2] != -1) return dp[pos][c1][c2];
    int ret = 0;
    if(s[pos] == t[pos]){
        for(int i = 1; i <= 3; i++){
            if(i != c1 && i != c2){
                ret = ret + go(pos + 1, i, i) % mod;
                ret %= mod;
            }
        }
    }
    if(pos + 1 <= n){
        if(s[pos] == s[pos + 1] && t[pos] == t[pos + 1]){
            for(int i = 1; i <= 3; i++){
                for(int j = 1; j <= 3; j++){
                    if(i != j){
                        if(i != c1 && j != c2){
                            ret = ret + go(pos + 2, i, j) % mod;
                            ret %= mod;
                        }
                    }
                }
            }
        }
    }
    return dp[pos][c1][c2] = ret;
}

int main(){
    n = in();
    scanf("%s %s", s + 1, t + 1);
    memset(dp, -1, sizeof dp);
    printf("%d\n", go(1, 0, 0) % mod);
}


Measured memory_bytes: 256
///apigs property
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second
#define pb push_back
#define vll vector< ll >
#define vi vector< int >
#define pll pair< ll , ll >
#define pi pair< int , int >
#define all(s) s.begin() , s.end()
#define sz(s) s.size()
#define md (s + e) / 2
#define mid (l + r) / 2
using namespace std;
typedef long long ll;
ll q, dp[25][(1 << 21) + 5], a[55][55] , b[555555], k, l, m, n, o, p;
map < ll , ll > mp;
vll adj[555555];
const ll mod = 1e9+7;
ll mem(ll i , ll mask){
	if(i == n){
		return 1;
	}
	ll &r = dp[i][mask];
	if(r != -1)return r;
	r = 0;
	for(ll j = 0 ; j < n ; j++){
		if((mask & (1 << j))) continue;
		if(a[i][j]){
			r = (r + mem(i + 1 , mask | (1 << j))) % mod; 
		}
	}
	return r;
}
void solve(){
	memset(dp , -1 , sizeof dp);
	cin >> n;
	for(ll i = 0 ; i < n ; i++){
		for(ll j = 0 ; j < n ; j++){
			cin >> a[i][j];
		}
	}
	cout << mem(0,0) << endl;
}
int main() {
    fast ;
	// cin >> q;
    q = 1;
    while(q--){
    	solve();
	}
}

Measured memory_bytes: 426292
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	double r;
	cin >> r;
	cout << r * 2 * 3.141592 << endl;
	return 0;
}

Measured memory_bytes: 3784
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




vector<int> topologicalSort(int v, const vector<int> edge[]) {
	vector<int> zeros;
	vector<int> in(v), res;
	for (int i = 0; i < v; i++) {
		for (int j = 0; j < (int)edge[i].size(); j++)in[edge[i][j]]++;
	}
	for (int i = 0; i < v; i++)if (in[i] == 0)zeros.push_back(i);
	while (!zeros.empty()) {
		int u = zeros.back();
		zeros.pop_back();
		res.push_back(u);
		for (int i = 0; i < (int)edge[u].size(); i++) {
			if (--in[edge[u][i]] == 0)zeros.push_back(edge[u][i]);
		}
	}
	return res;
}




int n;
vector<int> edge[1000 * 1000];
int dp[1000 * 1000];


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

	cin >> n;
	rep(i,n) {
		int prev = -1;
		rep(j,n - 1) {
			int a = i;
			int b;
			cin >> b;
			b--;
			if (prev != -1) {
				edge[min(a, prev) * n + max(a, prev)].push_back(min(a, b) * n + max(a, b));
			}
			prev = b;
		}
	}

	vector<int> tsort = topologicalSort(n* n, edge);
	if (tsort.size() != n*n) {
		cout << -1 << endl;
		return 0;
	}

	int ans = 1;

	rep(i, n* n)dp[i] = 1;

	for (int v : tsort) {
		for (int nxt : edge[v]) {
			dp[nxt] = max(dp[nxt], dp[v] + 1);
		}
		ans = max(ans, dp[v]);
	}


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 52596
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)n ; i++)
#define invrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef long double ld;
const int MODULO = 1000000007;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, 3){
        cnt += (s.at(i) == 'R');
    }
    if (cnt != 2){
        cout << cnt;
    }
    else{
        if (s.at(1) == 'R'){
            cout << 2;
        }
        else{
            cout << 1;
        }
    }
    return 0;
}


Measured memory_bytes: 3644
n,Y = map(int,(input().split()))
x = -1
y = -1
z = -1
for i in range(n+1):
    for j in range(n+1):
        k=Y-i*10000-j*5000
        if k==(n-i-j)*1000 and k>=0:
            x=i
            y=j
            z=int(k/1000)
print(x,y,z)



Measured memory_bytes: 3060
from operator import itemgetter

n = int(input())
r = [tuple(map(int, input().split())) for i in range(n)]
b = [tuple(map(int, input().split())) for i in range(n)]

r = sorted(r, key=itemgetter(1), reverse=True)
b.sort()

ans = 0
pair = [False]*n

for i in range(n):
    for j in range(n):
        if b[i][0] > r[j][0] and b[i][1] > r[j][1] and pair[j] == False:
            pair[j] = True
            ans += 1
            break

print(ans)


Measured memory_bytes: 3064
# coding: utf-8
# Your code here!
SIZE=300000; MOD=10**9+7 #ここを変更する

inv = [0]*(SIZE+1)# inv[j] = j^{-1} mod MOD
fac = [0]*(SIZE+1)# fac[j] = j! mod MOD
finv = [0]*(SIZE+1)# finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE+1):
    inv[i] = MOD -(MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0


h,w,n = [int(i) for i in input().split()]
xy = [[1,1]]+[[int(i) for i in input().split()] for _ in range(n)]

dp = [0]*(n+1)
dp[0] = 1

xy.sort(key=lambda x: x[1])
xy.sort(key=lambda x: x[0])

#print(xy)

for i in range(1,n+1):
    x,y = xy[i]
    for j in range(i):
        xj,yj = xy[j]
        dp[i] -= choose(x - xj + y-yj, y-yj)*dp[j]
        dp[i] %= MOD

ans = 0
#print(dp)
for i,dpi in enumerate(dp):
    x,y=xy[i]
    ans += choose(h-x + w-y, w-y) * dpi
    ans %= MOD
print(ans)




Measured memory_bytes: 53976
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll a, b, k; cin >> a >> b >> k;

    ll ans = max(0ll, a + b - k);

    ll aa = max(0ll, ans - b);
    ll bb = min(ans, b);

    cout << aa << " " << bb;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    for(int i=0; i<s.length(); i++){
      if(i%2 == 0){
        System.out.print(s.charAt(i));
      }
    }

    sc.close();
  }
}


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

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String ans = "Christmas";
		int b = 25; 
		while(b != a) {
			ans += " Eve ";
			b--;
		}
		System.out.println(ans);
	}
}

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

int main()
{int n;
 cin >> n;
 cout << n / 3 << endl;

  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(void)
{
  double a;
  int i;
  double b[1001];
  double c = 0;
  double d = 0;
  
  scanf("%lf", &a);
  
  for(i = 0; i < a; i++){
    scanf("%lf", &b[i]);
  }
  
  for(i = 0; i < a; i++){
    c = 1 / b[i];
    d += c;
  }
  d = 1 / d;
  printf("%lf", d);
  return 0; 
}

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

using namespace std;

int main(int argc, char const *argv[]) {
  string c;
  cin >> c;
  string aiueo = "aiueo";
  if (aiueo.find(c[0]) != string::npos) cout << "vowel";
  else cout << "consonant" << endl;
  return 0;
}


Measured memory_bytes: 256
require 'pp'

n, m = gets.split.map(&:to_i)
a_n = gets.split.map(&:to_i)

sum = a_n.inject(&:+)

a_n.sort!.reverse!

#pp a_n

ok = true
m.times do |i|
    x = a_n[i]
    if sum <= 4 * m * x
        ok = true
    else
        ok = false
        break
    end
end

if ok
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 2172
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
long long int D,G;
long long int p[11],c[11];
long long int ans=100000;
int a[11];
int main(){
	cin >> D >> G;
	for(int i=1;i<=D;i++)cin >> p[i] >> c[i];
	for(int i=0;i<1<<D;i++){
		//printf("%d\n",i);
		long long int sum=0,temp=0;
		int x=i;
		int cnt=1;
		while(x>0){
			if(x&1 == 1){a[cnt]=1;}
			cnt++;
			x>>=1;
		}

		for(int z=1;z<=D;z++){
			if(a[z]==1){
				sum+=100*z*p[z]+c[z];
				temp+=p[z];
			}
		}
		//printf("sum %d temp %d\n",sum,temp);
		long long int rest=(G-sum);
		if(rest<=0)ans=min(ans,temp);
		else{
			for(int z=1;z<=D;z++){
				if(a[z]==0){
					if(rest<=100*z*p[z]+c[z]) {
						if(rest%(100*z)==0)ans=min(ans,temp+rest/(100*z));
						else ans=min(ans,temp+rest/(100*z)+1);
						//printf("z %d ans %d\n",z,ans);
					}
				}
			}
			
		}
		for(int z=1;z<=D;z++)a[z]=0;		
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define V vector<vector<vector<int>>>
using namespace std;
int util(int i,int j,int k,vector<int>&arr,V &dp){
	if(k==0 || i>j)
		return 0;
	if(dp[i][j][k]!=INT_MIN)
		return dp[i][j][k];
	dp[i][j][k]=max(max(arr[i]+util(i+1,j,k-1,arr,dp),util(i+1,j,k-2,arr,dp)),max(arr[j]+util(i,j-1,k-1,arr,dp),util(i,j-1,k-2,arr,dp)));
	dp[i][j][k]=max(dp[i][j][k],0);
	return dp[i][j][k];	
}
int main(){
	int n,k;
	cin>>n>>k;
	vector<int>arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	V dp(n+1,vector<vector<int>>(n+1,vector<int>(k+1,INT_MIN)));
	cout<<util(0,n-1,k,arr,dp);
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int  i,j,k;

int main(){
	string s;
	int k;
	cin>>k>>s;
	int ssize=s.size();

	if(k>=ssize){
		cout<<s<<endl;
	}else{
		for(i=0;i<k;i++){
			cout<<s[i];
		}
		cout<<"..."<<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
ll int MOD=1e9+7;
#define N 300000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");
main(){
    ll int n,a[N];
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        a[i]-=i+1;
    }
    sort(a,a+n);
    ll int temp=a[n/2];
    ll int ans=0;
    rep(i,n){
        ans+=abs(a[i]-temp);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
	static boolean isFill(int[][] f) {
		for ( int i = 0; i < f.length; i++ ) {
			for( int j = 0; j < f[i].length; j++ ) {
				if ( f[i][j] == 0 ) return false;
			}
		}
		return true;
	}
	static void putAry( int[][] f ) {
		for ( int i = 0; i < f.length; i++ ) {
			for ( int j = 0; j < f[i].length; j++ )
				System.out.printf("%4d", f[i][j]);
			System.out.println();
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while ( !sc.hasNext("0") ) {
			int n = sc.nextInt();
			int[][] field = new int[n][n];
			int y = (n/2)+1, x = n/2 , num = 1;
			field[y][x] = num++;
			x++; y++;
			while ( true ) {
				if ( y >= n ) y = 0;
				else if ( y < 0 ) y = n-1;
				if ( x >= n ) x = 0;
				else if ( x < 0 ) x = n-1;
				if ( field[y][x] != 0 ) {
					y++; x--;
				} else {
					field[y][x] = num++;
					if ( isFill(field) ) break;
					x++; y++;
				}
			}
			putAry(field);
		}
	}
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll N,K;
  cin >> N >> K;

  if(K%2==1){
    ll cnt=0;
    for(int i=1;i<=N;i++) if(i%K==0)  cnt++;
    cout << cnt * cnt * cnt << endl;
  }
  else{
    ll cnt1=0;
    ll cnt2=0;
    for(int i=1;i<=N;i++){
      if(i%K==0)  cnt1++;
      if(i%K==K/2)  cnt2++;
    }
    cout << cnt1 * cnt1 * cnt1 + cnt2 * cnt2 * cnt2 << endl;
  }

  return 0;
}

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

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

	vector<int> p(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}

	int ans = 0;

	for (int i = 1; i <= n; i++) {
		
		if (p[i] == i) {

			if (i != n) {
				swap(p[i], p[i + 1]);
			}
			else {
				swap(p[i - 1], p[i]);
			}
			
			ans++;
		}
	
	}

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

Measured memory_bytes: 768
#include <iostream>
#include <vector>


void trace(int a[], int n) {
	for (int i = 0; i < n-1; i++)
		std::cout << a[i] << " ";
	std::cout << a[n-1] << std::endl;
}

int main() {

	int n;
	std::cin >> n;

	int a[100]; // n is larger than 0 and smaller than 101

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

	// small <- sorted items... -> large :a[i]
	//                     a[j]( j:i-1 -> 0 ) and shifting...
	//            | a[i] < a[j] found!
	//            
	trace(a, n);
	for (int i = 1; i < n; i ++) {
		int key = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > key) {
			a[j + 1] = a[j]; //shifting...
			j--;
		}
		a[j + 1] = key; // insert!
		trace(a, n);
	}


	//
	// TODO
	//
	// insertion sort is slow when shifting too large array 
	// * pointer improves it?
	// * size should be limited
	// a[] is awful
	// * can implement with std::vector<int> nicely?
	// *

	return 0;
}

Measured memory_bytes: 3088
import java.util.*


data class Coordinate(val x:Int, val y:Int){
    inline fun forEachNeighbors(func:(Int, Int) -> Unit):Unit {
        (-1 .. 1).forEach { dx ->
            if (dx == 0) (-1 .. 1 step 2).forEach { func(x + dx, y + it) }
            else (-1..1).forEach { func(x + dx, y + it) }
        }
    }
}
fun main(args:Array<String>):Unit {
    val (h, w) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(h){readLine()!!.trim().map{if (it == '.') 0 else it.toString().toInt()}.toIntArray()}
    val queue :Deque<Coordinate> = LinkedList<Coordinate>()
    state.forEachIndexed { y, chars -> chars.forEachIndexed { x, c -> if (c == 0) queue.push(Coordinate(x, y)) } }
    var count = 0
    if (queue.size == h * w) {
        println(0)
        return
    }
    while (queue.isNotEmpty()){
        ++count
        repeat(queue.size){
            queue.removeFirst().forEachNeighbors { x, y ->
                if (x in 0 until w && y in 0 until h && state[y][x] > 0){
                    --state[y][x]
                    if (state[y][x] == 0) queue.addLast(Coordinate(x, y))
                }
            }
        }
    }
    println(count - 1)
}


Measured memory_bytes: 112248
n,k=map(int,input().split())

import math

def boxball(box,ball):
    if ball>=box:
        cal=math.factorial(ball-1)//math.factorial(ball-box)//math.factorial(box-1)
        return cal%1000000007
    else:
        return 0

def redball(box,ball,i):
    if ball==0:
        if i==1:
            return 1
        else:
            return 0
    else:
        if ball>=box-2:
            cal=math.factorial(ball+1)//math.factorial(ball-box+2)//math.factorial(box-1)
            return cal%1000000007
        else:
            return 0
#print(boxball(3,5),redball(3,5))
    
for i in range(k):
    ans=boxball(i+1,k)*redball(i+2,n-k,i+1)
    print(ans%1000000007)

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

void solve(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  priority_queue<pair<int, int>> q;
  ll ans = 0LL, prans = 0LL;
  for (int i = n-1; i > -1; i--){
    int cnt = 1;
    while (!q.empty() && q.top().ff > a[i]) {
      cnt += q.top().ss;
      prans -= (ll)q.top().ss * (ll)q.top().ff;
      q.pop();
    }
    prans += (ll)cnt * (ll)a[i];
    ans += prans;
    q.push(mp(a[i], cnt));
    //cerr << "i: " << prans << '\n';
  }

  cout << ans << '\n';
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

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

    solve();

    return 0;
}


Measured memory_bytes: 6120
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())
#define PI 2 * acos(0)

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 




int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
 
    while (1) {
        if (C <= 0) {
            cout << "Yes" << endl;
            return 0;
 
        }
        if (A <= 0) {
            cout << "No" << endl;
            return 0;
        }
        C -= B;
        A -= D;
    }
    return 0;
}




Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
		    int count = 0;
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x == 0){break;}
			for(int i = 1; i < n ; i++){
				for(int k = i + 1; k < n; k++){
					int l = x - i - k;
					if(l > k){
						if(l <= n){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}



Measured memory_bytes: 26324
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>r(n);
    for(int i=0; i<n; i++){
        cin >> r[i];
    }
    sort(r.begin(),r.end());
    long long a[2]={0,0};
    for(int i=n-1; i>=0; i--){
        if(r[i]==r[i-1]){
            if(a[0]==0) a[0] = r[i];
            else if(a[1]==0) a[1] = r[i];
            i--;
        }
    }
    cout << a[0]*a[1] << endl;
    return 0;
}

Measured memory_bytes: 3716
n=int(input())
a=list(map(int,input().split()))
for i in range(n): a[i]-=i+1
a.sort()
if n%2==0: p=(a[n//2]+a[n//2-1])//2
else: p=a[n//2]
ans=0
for i in a: ans+=abs(i-p)
print(ans)

Measured memory_bytes: 30920
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

#define MAX 100100
int N,A[MAX];

void compute() {
  map<int,int> cnt;
  rep(i,N) ++cnt[A[i]];
  int ans = (int)cnt.size();
  if( ans % 2 != 0 ) cout << ans << endl;
  else cout << ans-1 << endl;
}

int main() {
  cin >> N;
  rep(i,N) cin >> A[i];
  compute();
  return 0;
}


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

int main(){
    lint n, k, q;
    cin >> n >> k >> q;
    lint x = k-q;
    vector <lint> vec;
    for(int i=0; i<=n; i++){
        vec.push_back(x);
    }
    for(int i=0; i<q; i++){
        lint temp;
        cin >> temp;
        vec[temp]++;
    }
    for(int i=1; i<vec.size(); i++){
        if(vec[i] > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;
int main(){
	cin>>n>>a>>b;
	ll t=a+b;
	ll tmp=n/t,tme=n%t;
	if(tme>a)tme=a;
	cout<<tmp*a+tme;
	return 0;
}

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

public class Main {
	
	public static int hand(int con, char[] array, int aces){
		int sum = 0;
		
		int ace_count = 0;
		for(int i = 0; i < con; i++){
			if(array[i] == 'T' || array[i] == 'J' || array[i] == 'Q' || array[i] == 'K'){
				sum += 10;
			}else if(array[i] == 'A'){
				sum += (ace_count < aces ? 11 : 1);
				ace_count++;
			}else if('0' <= array[i] && array[i] <= '9'){
				sum += array[i] - '0';
			}
		}
		
		return sum;
	}
	
	public static boolean contain_ace(int con, char[] array){
		for(int i = 0; i < con; i++){
			if(array[i] == 'A'){
				return true;
			}
		}
		
		return false;
	}
	
	public static int score(int con, char[] array, int aces){
		int max = -1;
		for(int i = 0; i <= aces; i++){
			int cur = hand(con, array, i);
			if(cur <= 21 && max < cur){
				max = cur;
			}
		}
		
		return max;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		final int N = sc.nextInt();
		
		for(int tt = 0; tt < N; tt++){
			char[] hands = new char[10];
			
			int ace_count = 0;
			for(int i = 0; i < 10; i++){
				hands[i] = sc.next().charAt(0);
				if(hands[i] == 'A'){
					ace_count++;
				}
			}
			
			//System.out.println(Arrays.toString(hands));
			
			if(hand(2, hands, 1) == 21){
				System.out.println("blackjack");
				continue;
			}
			
			int cons = 2;
			while(true){
				if(cons > 10){
					cons = 10;
					break;
				}
				
				if(ace_count >= 1 && contain_ace(cons, hands) && hand(cons, hands, 1) == 17){
					cons++;
				}else{
					final int sco = score(cons, hands, ace_count);
					//System.out.println("debug :: " + sco);
					if(sco == -1){
						break;
					}else if(sco <= 16){
						cons++;
					}else{
						break;
					}
				}
			}
			
			final int sco = score(cons, hands, ace_count);
			if(sco == -1){
				System.out.println("bust");
			}else{
				System.out.println(sco);
			}
		}
	}

}

Measured memory_bytes: 20416
def inpl(): return [int(i) for i in input().split()]
N = int(input())
t, a = 1, 1
for _ in range(N):
    Ti, Ai = inpl()
    n = max(-(-t//Ti), -(-a//Ai))
    t, a = n*Ti, n*Ai
print(t+a)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
ll A, B, C, K;

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

  cin >> A >> B >> C >> K;

  if (K%2){
    cout << B-A << endl;
  }else{
    cout << A-B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

  int n,i;

  scanf("%d",&n);
  
  if(n % 4 == 0 || n % 7 == 0){
    printf("Yes\n");
    return 0;
  }

  for(i = 0;i*7 < n;i++){
    if((n - 7*i) % 4 == 0){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");

  return 0;
}


Measured memory_bytes: 128
n = int(input())
p = list(map(int,input().split()))
 
ans = 0
 
for i in range(1,n-1):
  if p[i-1]<p[i]<p[i+1] or p[i+1]<p[i]<p[i-1]:
    ans += 1
    
print(ans)
    

Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007LL
#define INF 2000000000
#define PI 3.1415926

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

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m, a[100000], b[100000];
	vector<pair<int, int> > vec;
	cin >> n >> m;
	REP(i, n) {
		cin >> a[i] >> b[i];
		vec.pb(mp(a[i], b[i]));
	}

	int ans = 0;
	sort(ALL(vec));
	REP(i, n){
		if(vec[i].second >= m){
			ans += vec[i].first * m;
			break;
		} else {
			ans += vec[i].second * vec[i].first;
			m -= vec[i].second;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>
int main(void){
	int i,n,m,a[10000],so=0,ans=0;
	double q;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		so+=a[i];
	}
	q=(double)so/(4*m);
	
	
	for(i=0;i<n;i++){
		if(a[i]>=q){
			ans++;
		}
	}
	if(ans>=m){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

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

using Lint=long long;
using Graph=vector<vector<int>>;

int main()
{
   int N,M; cin>>N>>M;
   Graph G(N);
   for(int i=0;i<N-1;i++){
      int a,b; cin>>a>>b;
      a--; b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }

   vector<map<int,int>> dp(N);
   function<int(int,int)> dfs=[&](int v,int p)
   {
      int res=1;
      for(int u:G[v]) if(u!=p) res=(Lint)res*(dfs(u,v)+1)%M;
      return dp[v][p]=res;
   };
   vector<int> ans(N);
   function<void(int,int)> reroot=[&](int v,int p)
   {
      int sz=G[v].size();
      vector<int> L(sz+1,1),R(sz+1,1);
      for(int i=0;i<sz;i++)   { L[i+1]=(Lint)L[i]*(dp[G[v][i]][v]+1)%M; }
      for(int i=sz-1;i>=0;i--){ R[i]=(Lint)(dp[G[v][i]][v]+1)*R[i+1]%M; }
      ans[v]=R[0];
      for(int i=0;i<sz;i++) if(G[v][i]!=p){
         dp[v][G[v][i]]=(Lint)L[i]*R[i+1]%M;
         reroot(G[v][i],v);
      }
   };
   dfs(0,-1); reroot(0,-1);
   for(int i=0;i<N;i++) cout<<ans[i]<<endl;
   return 0;
}


Measured memory_bytes: 35840
#!/usr/bin/env python3
import math
A, B, H, M = map(int, input().split())

h = 30
h_m = 1/2
m = 6

x = A**2 + B**2 - 2*A*B*math.cos(math.radians(H*h+M*h_m-M*m))
print(math.sqrt(x))


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

int main(void){
  int time = 0, menu, x = 0;
  for(int i = 0; i < 5; i++){
    cin >> menu;
    if(menu%10 == 0) time += menu;
    else time += (menu+9)/10*10; // Round up
    if(x < (10-menu%10)%10) x = (10-menu%10)%10;
  }
  cout << time-x << endl;
  return 0;
}


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

int main() {

	unsigned long long N;
	unsigned long long A;
	unsigned long long B;

	cin >> N;
	cin >> A;
	cin >> B;

	unsigned long long ans = 0;

	if (0 == (B - A) % 2) {
		ans = (B - A) / 2;
	}
	else {
		unsigned long long c = min(A - 1, N - B);
		unsigned long long d = max(A - 1, N - B);
		ans = (B - A - 1) / 2 + c + 1;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(raw_input())

while n > 0:
    a = 0
    b = 0
    for _ in range(n):
        t_a, t_b = map(int, raw_input().split())
        if t_a > t_b:
            a += t_a + t_b
        elif t_a < t_b:
            b += t_a + t_b
        else:
            a += t_a
            b += t_b
    print "%d %d" % (a, b)
    n = int(raw_input())

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

using namespace std;

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

    int n, d, x;
    cin >> n >> d >> x;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        ans += 1 + (d - 1) / a;
    }
    ans += x;

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>

#define MAX 2e5

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, inp;
    cin >> n;
    vector<int> count_(n, 0);

    for(int i=0; i<n-1; i++){
        cin >> inp;
        count_[inp-1]++;
    }

    for(int i=0; i<n; i++)
        cout << count_[i] << endl;

    return 0;

}

Measured memory_bytes: 3976
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<set>
#include<math.h>
#include<random>
#include<set>

#define lli long long int
#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}

struct SegmentTree {
private:
	int n;
	vector<long long int> node;
	int TANNI;

	long long int Func(long long int a, long long int b) {
		return min(a,b);
	}

public:
	//元配列ｖをセグメント木で表現する。
	SegmentTree(vector<long long int> v, long long int tanni) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪→これをｎとおく。
		//セグメント木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1;
		while (n < sz)n *= 2;

		TANNI = tanni;
		node.resize(2 * n - 1, TANNI);

//最下段に値を入れた後に、下の段から順番に値を入れる。
//値を入れるには、自分の子の２値を参照すればよい。
for (int i = 0; i < sz; i++)node[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)node[i] = Func(node[2 * i + 1], node[2 * i + 2]);
	}

	void update(long long int x, long long int val) {
		//最下段のノードにアクセスする。
		x += (n - 1);

		//最下段のノードを更新したら、あとは親に上って更新していく。
		node[x] = val;

		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = Func(node[2 * x + 1], node[2 * x + 2]);
		}
	}

	long long int getVal(int x) {
		x += (n - 1);
		return node[x];
	}

	long long int getAns(int a, int b, int k = 0, int l = 0, int r = -1) {
		//最初に呼び出された時の区間は[0,n)
		if (r < 0)r = n;

		//要求区間と対象区間が交わらない→単位元を返す。
		if (r <= a || b <= l) return TANNI;

		//要求区間が対象区間を完全に被覆する→対象区間を答えの計算に使う。
		if (a <= l && r <= b) return node[k];

		//要求区間が対象区間の一部を被覆→子をよびだす。
		//左の子をvl、右の子をvrとしている。
		//新しい対象区間は現在の対象区間を半分に割ったもの。
		int vl = getAns(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = getAns(a, b, 2 * k + 2, (l + r) / 2, r);
		return Func(vl, vr);


	}



};



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

	int k;
	cin >> k;

	bool flg = false;
	vector<string> v;

	for (int i = 1;i <= 5; i++) {
		for (int j = 0; j < str.size(); j++) {
			if (j + i - 1 >= str.size())break;

			v.push_back(str.substr(j, i));
		}
	}

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

	cout << v[k - 1] << endl;




	return 0;

}



Measured memory_bytes: 1660
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../../../bits/stdc++.h"
#endif

using namespace std;

//#define int long long

using ll = long long;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)

#define rep(i,n) for_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define pb push_back
//#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

bool a[26];
char c[limit];

signed main(){
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin>>c;
  int l = strlen(c);
  rep(i, l) {
    a[c[i]-'a'] = true;
  }
  
  bool f=false;
  rep(i, 26) {
    if(!f && !a[i]){
      cout<<(char)(i+'a')<<endl;
      f = true;
    }
  }
  
  if(!f)cout<<"None"<<endl;
  
  return 0;
}


Measured memory_bytes: 384
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s,w = inpl()
print('safe' if s > w else 'unsafe')

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

int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    if ((r * 100 + g * 10 + b) % 4 == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N, W;
int v[110], w[110];
int dp[110][100010];


signed main(){
    cin >> N >> W;
    rep(i, 0, N) cin >> v[i] >> w[i];

    rep(i, 0, N) repe(j, 0, W){
        chmax(dp[i+1][j], dp[i][j]);
        chmax(dp[i+1][min(j+w[i], W+1)], dp[i][j]+v[i]);
    }

    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 11200
#include<iostream>
#include<vector>
#include<set>
using namespace std;

int main(){
  int n;
  while(std::cin >> n, n){
    vector<set<int> > vs(n);
    set<int> hoge;
    int k, tmp;
    for (int i = 0; i < n; i++) {
      std::cin >> k;
      for (int j = 0; j < k; j++) {
        std::cin >> tmp;
        vs[i].insert(tmp);
      }
    }
    std::cin >> k;
    for (int i = 0; i < k; i++) {
      std::cin >> tmp;
      hoge.insert(tmp);
    }
    int ans = -1;
    for (int i = 0; i < n; i++) {
      bool flag = true;
      for (int j: hoge) {
        flag &= (vs[i].find(j) != vs[i].end());
      }
      if(flag){
        if(ans == -1)ans = i + 1;
        else ans = -100;
      }
    }
    if(ans == -100 or ans == -1){
      std::cout << -1 << std::endl;
    }else{
      std::cout << ans << std::endl;
    }
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll sum = 0;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        sum += v[i];
    }

    ll ret = 5141141919810364364;
    ll now = 0;
    for (int i = 0; i <= n; i++) {
        ret = min(ret, abs(now - (sum - now)));
        if (i < n)now += v[i];
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 * 
 * @author daltao
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "daltao", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            TaskA solver = new TaskA();
            solver.solve(1, in, out);
            out.close();
        }
    }
    static class TaskA {
        public void solve(int testNumber, FastInput in, PrintWriter out) {
            String target = "CODEFESTIVAL2016";
            String source = in.readString();
            int n = target.length();
            int need = 0;
            for (int i = 0; i < n; i++) {
                if (source.charAt(i) != target.charAt(i)) {
                    need++;
                }
            }
            out.println(need);
        }

    }
    static class FastInput {
        private final InputStream is;
        private StringBuilder defaultStringBuf = new StringBuilder(1 << 13);
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public String readString(StringBuilder builder) {
            skipBlank();

            while (next > 32) {
                builder.append((char) next);
                next = read();
            }

            return builder.toString();
        }

        public String readString() {
            defaultStringBuf.setLength(0);
            return readString(defaultStringBuf);
        }

    }
}



Measured memory_bytes: 24916