akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>



using namespace std;

#define int long long

// using ll=long long;

signed main(){
    int n,const_k;

    cin>>n>>const_k;

    int x_arr[n];
    int y_arr[n];

    vector<int> x;
    vector<int> y;

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

        x.push_back(x_arr[i]);
        y.push_back(y_arr[i]);

    }


    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    int x_max=x[n-1];
    int y_max=y[n-1];
    int x_min=x[0];
    int y_min=y[0];

// 1000000000000000000
// 3999999996000000001


    int x_min_tmp;
    int x_max_tmp;
    int y_min_tmp;
    int y_max_tmp;
    int num=0;
    int ans=9223372036854775807;
    // cout<<x_max<<" "<<x_min<<" "<<y_max<<" "<<y_min<<endl;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=0;k<n;k++){
                for(int l=k+1;l<n;l++){

                    num=0;


                    x_min_tmp=x[i];
                    x_max_tmp=x[j];
                    y_min_tmp=y[k];
                    y_max_tmp=y[l];

                    for(int m=0;m<n;m++){
                        if(x_min_tmp<=x_arr[m]&&x_arr[m]<=x_max_tmp&&y_min_tmp<=y_arr[m]&&y_arr[m]<=y_max_tmp){
                            num++;
                            // cout<<x_arr[m]<<" "<<y_arr[m]<<endl;
                            // cout<<(j-i)*(l-k)<<endl;
                        }
                    }

                    // cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;
                    // cout<<(j-i)*(l-k)<<endl;


                    
                    // cout<<"num:"<<num<<endl;
                    // cout<<"k:"<<const_k<<endl;

                    if(num>=const_k){
                        ans=min(ans,(x_max_tmp-x_min_tmp)*(y_max_tmp-y_min_tmp));
                    }


                    // cout<<"ans:"<<ans<<endl;

                }
            }
        }
    }



    cout<<ans<<endl;



}   

Measured memory_bytes: 256
A, B, C = map(int, input().split())


if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
    print(0)
    exit()
else:
    if A == B and B == C:
        print(-1)
        exit()
    else:
        ans = 0
        while True:        

            ans += 1

            a = (B+C)/2
            b = (A+C)/2
            c = (A+B)/2

            if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
                print(ans)
                exit()
            
            A = a
            B = b
            C = c

Measured memory_bytes: 3188
/*
 * main.c
 *
 *  Created on: 2019/05/19
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int N = 0, K = 0, i = 0;
	double dice_rate = 0, ans = 0;
	scanf("%d %d", &N, &K);
	for(i = 1; i <= N; i++) {
		dice_rate = (double)1/N;
		int val = i;
		while(val < K) {
			val *= 2;
			dice_rate /= 2;
			//printf("i=%d\n",i);
		}
		ans += dice_rate;
	}
	printf("%.16f", ans);
    return 0;
}


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

constexpr int N{4}, M{3};
bool graph[N + 1][N + 1];
bool visited[N + 1];

bool dfs(int n, int v) {
  if (n == M) {
    for (int i{1}; i <= N; ++i) {
      if (!visited[i])
        return false;
    }
    return true;
  }

  for (int i{1}; i <= N; ++i) {
    if (!graph[v][i] || visited[i]) continue;
    visited[i] = true;
    if (dfs(n + 1, i)) {
      return true;
    }
    visited[i] = false;
  }
  return false;
}

int main() {
  int a, b;
  for (int i{}; i < M; ++i) {
    scanf("%d%d", &a, &b);
    graph[a][b] = true;
    graph[b][a] = true;
  }

  bool result;
  for (int i{1}; i <= N; ++i) {
    visited[i] = true;
    result = dfs(0, i);
    if (result) {
      break;
    }
    visited[i] = false;
  }

  printf("%s\n", result ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int m1,m2,m3;
    m1=m2=m3=0;
    for(int i=0;i<10;i++)
    {
        int h;
        cin>>h;
        if(h>m1)m3=m2,m2=m1,m1=h;
        else if(h>m2)m3=m2,m2=h;
        else if(h>m3)m3=h;
        else;
    }
    cout<<m1<<endl<<m2<<endl<<m3<<endl;
    return 0;
}


Measured memory_bytes: 3020
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0 ; i < n ; i++) cin >> a[i];
	int b[9] = {};
	for (int i = 0 ; i < n ; i++) {
		if (a[i] >= 1 && a[i] <= 399) b[0]++;
		else if (a[i] >= 400 && a[i] <= 799) b[1]++;
		else if (a[i] >= 800 && a[i] <= 1199) b[2]++;
		else if (a[i] >= 1200 && a[i] <= 1599) b[3]++;
		else if (a[i] >= 1600 && a[i] <= 1999) b[4]++;
		else if (a[i] >= 2000 && a[i] <= 2399) b[5]++;
		else if (a[i] >= 2400 && a[i] <= 2799) b[6]++;
		else if (a[i] >= 2800 && a[i] <= 3199) b[7]++;
		else b[8]++;
	}
	int c = 0;
	for (int i = 0 ; i < 8 ; i++) {
		if (b[i] >= 1) c++;
		
	}
	cout << max(1, c) << ' ' << c + b[8];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++) 
#define all(v) v.begin(),v.end()
#define F first
#define S second
 
void solve()
{
	string s;
	cin>>s;
	int maxval=0;
	int len=0;
	for(int i=0;i<s.length()-1;i++)
	{
		if(s[i]=='R')
		{
			if(s[i]==s[i+1])
			{
				len++;
			}
			else
			{
				len++;
				maxval=max(maxval,len);
				len=0;
			}
		}
		else
		{
			len=0;
		}
	}
	if(s[s.length()-1]=='R')
	{
		len++;
		maxval=max(maxval,len);
	}
	else
	{
		maxval=max(maxval,len);
	}
	cout<<maxval<<endl;
	
}
int main()
{
//	ios_base::sync_with_stdio(false); 
  //  cin.tie(NULL);  
	int t;
	t=1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    rep(i, N) cin >> T[i];
    sort(all(T));
    int ans = 1;
    int cur = 1;
    int first = T[0];
    rep(i, 1, N){
        
        if(cur >= C || first + K < T[i]){
            first = T[i];
            cur = 1;
            ans++;
//            cout << T[i] << endl;
        }
        else{
            cur++;
        }
        
    }
    
    output(ans);
    
    return 0;
}

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

ll MOD = 1000000007;
ll mod_pow(ll x, ll y) {
    if (y == 0)return 1;
    else {
        return mod_pow(x * x % MOD, y >> 1) * (y & 1 ? x : 1) % MOD;
    }
}
ll nck(ll n, ll k) {
    k = min(k, n - k);
    ll x = 1, y = 1;
    for (ll i = 0; i < k; i++) {
        x = x * (n - i) % MOD;
        y = y * (i + 1) % MOD;
    }
    return x * mod_pow(y, MOD - 2) % MOD;
}
int main() {
    ll n, a, b; 
    cin >> n >> a >> b;
    ll ans = mod_pow(2, n) - 1 - nck(n, a) - nck(n, b);
    ans += MOD*4;
    ans %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 3624
n = int(input())
def make_divisors(n):
  for i in range(2, int(n**0.5)+1):
    if n % i == 0:
      x = n//i
      while x%i == 0:
        x = x//i
      if x%i == 1:
        ans += 1
  return
def count_divisors(n):
  c = 0
  for i in range(1, int(n**0.5)):
    if n % i == 0:
      c += 2
  if n%int(n**0.5) == 0:
    if n==n//int(n**0.5):
      c += 1
    else:
      c += 2
  return c
ans = 0
def count_divisors(n):
  c = 0
  for i in range(1, int(n**0.5)):
    if n % i == 0:
      c += 2
  if n%int(n**0.5) == 0:
    if int(n**0.5)==n//int(n**0.5):
      c += 1
    else:
      c += 2
  return c
ans += count_divisors(n-1)
def make_divisors(n):
  c = 0
  for i in range(2, int(n**0.5)+1):
    if n % i == 0:
      x = n//i
      while x%i == 0:
        x = x//i
      if x%i == 1:
        c += 1
  return c
ans += make_divisors(n)
print(ans)






Measured memory_bytes: 39024
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    vector<long long> B(N+1);
    B[0] = 0;
    rep(i,N) B[i + 1] = B[i] + A[i];

    map<int, int> count;
    long long ans = 0;
    rep(i,N+1) {
        ans += count[B[i] % M];
        count[B[i] % M]++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4352
//---include---
#include <stdio.h>
#include <string.h>

//---define----
#define LEN 200000

//---struct---
typedef struct pp{
  char name[100];
  int t;
}P;

//---function prototype declaration---
void enwueue(P);
P dequeue(void);
int isEmputy(void);
int isFull(void);
//---global arguments---
P Q[LEN+1];//プロセス名と処理時間の配列
int head=0;//キューの先頭
int tail=0;//キューの最後尾
int n;
//---function---
void enqueue(P x){
  if(isFull()){
  }else{
    Q[tail]=x;
    if(tail+1==LEN){
      tail=0;
    }else tail++;
  }
}
P dequeue(){
  P x;
  
  if(isEmpty()){
  }else{
    x = Q[head];
    //printf("head: %d\n",head);
    //printf("X: %s %d\n",x.name, x.t);
    if(head+1==LEN){
      head = 0;
    }else head++;
  }
  return x;
}
int isEmpty(){
  return head==tail;
}
int isFull(){
  return head == (tail+1)%LEN;
}
//---Main Function---
int main(){
  int elaps = 0, c;
  int flag=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);//プロセス数とクオンタイムの入力

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);//プロセス名
    scanf("%d", &Q[i].t);//処理時間
    tail++;
  }

  while(flag!=n){
    u = dequeue();
    //printf("u %s %d\n",u.name, u.t);
    if((u.t-q)<=0){
      elaps+=u.t;
      printf("%s %d\n",u.name, elaps);
      flag++;
    }else{
      elaps+=q;
      u.t=u.t-q;
      enqueue(u);
    }
  }
  /*
  while(flag!=n){
    if((Q[head].t-q)<=0){
      elaps+=Q[head].t;
      printf("%s %d\n",Q[head].name, elaps);
      flag++;
      dequeue();
    }else{
      elaps+=q;
      Q[head].t=Q[head].t-q;
      enqueue(Q[head]);
    }
  }
  */
  return 0;
}



Measured memory_bytes: 20904
def main():
	N = int(input())
	vertex = [[] for i in range(N)]

	ini_v = 0
	for i in range(N - 1):
		a, b = [int(x) for x in input().split(" ")]
		if i == 0:
			ini_v = a - 1
		vertex[a - 1].append({"v": b - 1, "e": i})
		vertex[b - 1].append({"v": a - 1, "e": i})

	checked_v = [0] * N
	checked_e = [0] * (N - 1)
	to_visit = [ini_v]
	checked_v[ini_v] = 1
	color_e = [-1] * (N - 1)

	while len(to_visit):
		visiting = to_visit.pop(0)
		vs = vertex[visiting]
		used_cs = []
		cless_e = []
		for d in vs:
			if checked_v[d["v"]] == 0:
				checked_v[d["v"]] = 1
				to_visit.append(d["v"])
			if color_e[d["e"]] == -1:
				cless_e.append(d["e"])
			else:
				used_cs.append(color_e[d["e"]])
		s = 0
		for j in range(len(vs)):
			if s >= len(cless_e) or len(cless_e) == 0:
				break
			elif j in used_cs:
				continue
			else:
				color_e[cless_e[s]] = j
				s += 1

	print(max(color_e) + 1)
	for i in range(len(color_e)):
		print(color_e[i] + 1)

main()


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

int main()
{
  long long N, T;
  cin >> N >> T;
  vector<long long> t(N);
  for (int i = 0; i < N; i++)
    cin >> t[i];
  long long ans = 0;
  for (int i = 0; i < N; i++)
  {
    if (i < N - 1)
    {
      if (t[i + 1] - t[i] > T)
        ans += T;
      else
        ans += t[i + 1] - t[i];
    }
    else
      ans += T;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
long long 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;
string S1,S2="CODEFESTIVAL2016";
int main()
{
	cin>>S1;
	for(i=0;i<S1.size();i++)
	{
		if(S1[i]!=S2[i])
		z++;
	}
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define endl '\n'
#define mod 1000000007
#define modd 998244353
#define PI 3.1415926535897932384626
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void io() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	io();
	
	ll a;
	cin>>a;
	string ans;
	while(a) {
		int k=a%26;
		a/=26;
		if(k==0) {
			a-=1;
			k=26;
		}
		ans+=(char)('a'+k-1);
	}
	reverse(all(ans));
	cout<<ans;
	return 0;
}


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

const int inf = 1e9;
bool bipartite;
int n, f[200][200], color[200];
vector<int> g[200];

void dfs(int u, int p) {
    for (int v : g[u]) {
        if (v == p) continue;
        if (color[v] != -1) {
            bipartite &= color[u] != color[v];
        }
        else {
            color[v] = color[u] ^ 1;
            dfs(v, u);
        }
    }
}

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

    cin >> n;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            f[i][j] = inf;
            char c; cin >> c;
            if (i == j) {
                f[i][j] = 0;
            }
            if (c == '1' && i != j) {
                f[i][j] = 1;
                g[i].push_back(j);
                g[j].push_back(i);
            }
        }
    }

    bipartite = true;
    memset(color, -1, sizeof color);
    color[0] = 0;
    dfs(0, -1);

    if (!bipartite) {
        cout << -1;
        return 0;
    }

    int res = 0;
    for (int k = 0; k < n; ++k) {
        for (int u = 0; u < n; ++u) {
            for (int v = 0; v < n; ++v) {
                f[u][v] = min(f[u][v], f[u][k] + f[k][v]);
            }
        }
    }

    for (int u = 0; u < n-1; ++u) {
        for (int v = u+1; v < n; ++v) {
            res = max(res, f[u][v]);
        }
    }

    cout << res + 1;

    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x[100];
	int a=1000000;
	for (int i=1;i<=n;i++)
	{
		cin>>x[i];
	}
	sort(x+1,x+1+n);
	for(int i=x[1];i<=x[n];i++)
	{
		int b=0;
		for(int j=1;j<=n;j++)
		{
			b=b+(x[j]-i)*(x[j]-i);
		}
		if(b<=a)
		{
			a=b;
		}
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi        first
#define se        second
#define pb        push_back
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
typedef pair<ll,int>  PLI;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
inline void solve()
{
	int n;
	map<int,int> mp;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int x;cin>>x;
		mp[x]++;
	}
	for(int i=1;i<=n;i++)
	cout<<mp[i]<<endl;

}
int main()
{
	IOS();
	solve();
	return 0;
}




Measured memory_bytes: 13024
import Data.Functor ((<$>))

main :: IO ()
main = do
  [n, x] <- map (read :: String -> Int) . words <$> getLine
  if n == 0 && x == 0
    then return ()
    else do
      print $ length [ (a,b,c) | a <- [1 .. n]
                               , b <- [a+1 .. n]
                               , c <- [b+1 .. n]
                               , a + b + c == x
                     ]
      main



Measured memory_bytes: 4668
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 998244353

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, S = read_values()
    A = read_list()

    dp = [[0 for _ in range(S + 1)] for _ in range(N + 1)] 
    dp[0][0] = 1

    for i, a in enumerate(A):
        for s in range(S + 1):
            dp[i + 1][s] += 2 * dp[i][s]
            dp[i + 1][s] %= mod
            if s + a <= S: 
                dp[i + 1][s + a] += dp[i][s]
                dp[i + 1][s + a] %= mod
    
    print(dp[N][S])


if __name__ == "__main__":
    main()



Measured memory_bytes: 149244
h , n = map(int,input().split())
a , b = [], []
for i in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)

INF = 10 **15
dp = [[INF]*(10**4+1) for i in range(10**3+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(h+1):
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])
        dp[i+1][min(h,j+a[i])] = min(dp[i+1][min(h,j+a[i])],dp[i+1][j]+b[i])

print(dp[n][h])

Measured memory_bytes: 122076
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    int h[n];
    rep(i,n) cin >> h[i];
    int dp[2];
    dp[0]=0;
    dp[1] = abs(h[1]-h[0]);
    REP(i,2,n)
    {
        dp[i%2] = min(dp[(i+1)%2]+abs(h[i]-h[i-1]), dp[i%2]+abs(h[i]-h[i-2]));
    }
    cout << dp[(n-1)%2] << endl;
}


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

int main() {
  int donuts, element;
  cin >> donuts >> element;

  int smallest = element;
  for (int i = 0; i < donuts; i++) {
    int weight;
    cin >> weight;

    element -= weight;
    if (weight < smallest) {
      smallest = weight;
    }
  }

  int count = donuts;
  while (element - smallest >= 0) {
    element -= smallest;
    count++;
  }

  cout << count << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    int ans=0;
    for(int x=1;x<=100;x++){
      for(int y=1;y<=100;y++){
        if(ceil(sqrt((-3*x*x)+(-3*y*y)+(-2*x*y)+(4*i)))==floor(sqrt((-3*x*x)+(-3*y*y)+(-2*x*y)+(4*i)))){
        int m=-(y+x)+sqrt((-3*x*x)+(-3*y*y)+(-2*x*y)+(4*i));
        if(m%2==0 && m/2>=1){
          ans++;
        }
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3532
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n - 1],
    }

    let mut v = vec![0; n + 1];
    for a_i in a {
        v[a_i] += 1;
    }
    for i in 1..=n {
        println!("{}", v[i]);
    }
}


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

#define int long long

#define MOD 1000000007

int pow_mod(int a, int b){
    int ans = 1;
    while(b > 0){
        if(b & 1) ans = (ans * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return ans;
}

int kai[3000010];

int f(int n, int a){
    int ans = (a+1) * kai[(n + a + 1)] % MOD;
    int ans2 = kai[a+1] * kai[n+1] % MOD;
    int ans3 = kai[a+1] * (n+1) % MOD;
    ans = (MOD + ans - ans2) % MOD;
    return ans * pow_mod(ans3, MOD-2) % MOD;
}

signed main(){
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    kai[0] = 1;

    for(int i = 1;i < 3000010;i++){
        kai[i] = kai[i-1] * i % MOD;
    }

    int ans = 0;

    for(int i = r1;i <= r2;i++){
         int tmp = (MOD + f(i, c2) - (c1 == 1 ? 0 : f(i, c1-1))) % MOD;
         tmp = tmp * pow_mod(kai[i], MOD-2) % MOD;
         ans = (ans + tmp) % MOD;
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 23680
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    map<string,int>m;
    string u,s,t;
    lli a,b;
    cin>>s>>t;
    cin>>a>>b;
    m[s]+=a;
    m[t]+=b;
    cin>>u;
    m[u]--;
    cout<<m[s]<<" "<<m[t];
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end()
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){

  int ans = -1, N;
  cin >> N;
  for(int i = 1; i <= 50000 ; i++){
    int keep = i * 1.08;
    if(keep == N){
      ans = i;
      break;
    }
  }

  if(ans == -1)
    cout << ":(" << endl;
  else
    cout << ans << endl;

  return 0;
}


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

int main(){
	/*intput*/
	int a;	cin >> a;
	string s;	cin >> s;
	/*calculaiton*/
	/*output*/
	if(a >= 3200){
		cout << s << endl;
	}else{
		cout << "red" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N, p = 0;
    cin >> N;
     
    bool poss = 1;
    for (int i = 0; i < N; i++) {
        char c; int n;
        cin >> c >> n;
        if (c == '(') {
            p += n;
        } else {
            p -= n;
        }
        if (p < 0) {
            poss = 0;
        }
    }
    if (poss && p == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
using namespace std;
int n,A,B;
int a[40],b[40],c[40];
int dp[50][500][500];
int main(){
    cin>>n>>A>>B;
    for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
    for(int i=0;i<=n;i++)for(int j=0;j<500;j++)for(int k=0;k<500;k++)dp[i][j][k]=100000;
    dp[0][0][0]=0;
    for(int i=0;i<n;i++){
        for(int ca=0;ca<=400;ca++){
            for(int cb=0;cb<=400;cb++){
                dp[i+1][ca][cb]=min(dp[i][ca][cb],dp[i+1][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
            }
        }
    }
    int ans=4000000;
    for(int i=1;i*max(A,B)<500;i++){
        ans=min(ans,dp[n][i*A][i*B]);
    }
    if(ans==100000) cout<<-1;
    else cout<<ans;
    return 0;
}

Measured memory_bytes: 41216
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	string S;
	cin >> S;
	int cnt1 = 0, cnt2 = 0;
	int color = 0;
	for (int i = 0; i < S.size(); i++) {
		if ((S[i] - '0') != color) cnt1++;
		color ^= 1;
	}
	color = 1;
	for (int i = 0; i < S.size(); i++) {
		if ((S[i] - '0') != color) cnt2++;
		color ^= 1;
	}
	cout << min(cnt1, cnt2) << endl;
}


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

const int N = 3e5+5;

int A[N];

ll preSum[N];

ll prefix[N],suffix[N];
void solve() {
    int n,k;
    scanf("%d%d",&n,&k);
    ll ret = 0;
    if(k==0) {
        ret = (ll)n*n;
        cout<<ret<<endl;
        return;
    }
    for(int b = k+1;b<=n;++b) {
        for(int a = k;a<=n;a+=b) {
            int t = a;
            int x = b - a%b;
            int lastA = t + x-1;
            lastA = min(n,lastA);
            if(t<=lastA) {
                ret += lastA-t+1;
            }
        }
    }
    printf("%lld\n", ret);
}
int main() {
   //freopen("input.txt","r",stdin);
   solve();
}


Measured memory_bytes: 256
n=int(input())
T=0
H=0
for i in range(n):
    card_t,card_h=input().split()
    if card_t==card_h:
        T+=1
        H+=1
    else:
        if card_h>card_t:
            H+=3
        else:
            T+=3
print(T,H)



Measured memory_bytes: 5596
#include <stdio.h>

int x,y;

main(){
	scanf("%d",&x);
	for(y=1;y<=x;){
		if((y%3==0)||(y%10==3)||(y%100/10==3)||(y%1000%100/10==3)||(y%1000%100%10==3)||(y%1000/100==3)){printf(" %d",y);}
		else if((y/10==3)||(y/100==3)||(y/1000==3)){printf(" %d",y);}
		if(x==y){printf("\n");}
	 y++;
	}

  return 0;
}
  

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define ll long long int 
#define fori(i,n) for(int i=0; i<n; ++i)
#define ford(i,n) for(int i=n-1; i>=0; --i)
#define vi vector<int> 
#define vs vector<string>
#define vll vector<ll>
#define di deque<int>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define mod1 1000000007
#define mod2 998244353
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gcd __gcd

//Printing template
#define pf2(a,b) cout<<a<<" "<<b<<"\n"
#define pf3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define pf4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"

#define fast_cin() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> i_set;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ll_set; 
/* new_data_set p; */
/* *p.find_by_order(3); The value at third place */
/* p.order_of_key(7); The expected index in the set in sorted order */

bool sortbysec(pair<ll,ll> &p1, pair<ll, ll> &p2){
    return (p1.se<p2.se);
}

int main(int argc, char const *argv[]){
    fast_cin();
    ll i,h, n, sum=0;
    cin>>h>>n;
    vll a(n);
    fori(i,n) cin>>a[i];
    sum = accumulate(a.begin(), a.end(), sum);
    if(sum>=h) cout<<"Yes\n";
    else  cout<<"No\n";
    return 0;
}


Measured memory_bytes: 1024
height, width = gets.split(' ').map(&:to_i)
squares = (0...height).map{ gets.chomp.each_char.to_a }

check = proc {|x, y|
  (0...height).include?(y) and
    (0...width).include?(x) and
      squares[y][x] == '#'
}
around = [[-1,0], [1,0], [0,-1], [0,1]]
invalid = squares.find.with_index do |line, y|
  line.find.with_index do |cell, x|
    cell == '#' and
      not around.find{|i,j| check.call(x+i, y+j) }
  end
end
puts(invalid ? 'No' : 'Yes')

Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int N,K,i,j,ans=0;
    cin>>N>>K;
    long long int A[N],B[N];
    for(i=0;i<N;i++)
        B[i]=INT_MAX;
    for(i=0;i<N;i++)
        cin>>A[i];

    B[N-1]=0;
    B[N-2]=abs(A[N-1]-A[N-2]);
    
    for(i=N-3;i>=0;i--)
    {
        for(j=i+1;j<=min(i+K,N-1);j++)
        {
            if(abs(A[i]-A[j])+B[j] < B[i])
                B[i]=abs(A[i]-A[j])+B[j];
        }
    }
    cout<<B[0]<<endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int64_t sum = 0, mask = 0;
  for (int i = 0; i < n; ++i) {
    sum ^= a[i];
    mask |= a[i];
  }
  int64_t res = 0, ad = 0;
  for (int bit = 59; bit >= 0; bit--) {
    if (sum >> bit & 1) {
      res += (1LL << bit);
      continue;
    }
    if ((mask >> bit & 1) == 0) continue;
    ad |= (1LL << bit);
  }
  vector<int64_t> basis;
  sum = 0;
  for (int i = 0; i < n; ++i) {
    a[i] &= ad;
    sum ^= a[i];
  }
  int pos = 0;
  for (int bit = 59; bit >= 0; --bit) {
    int p = -1;
    for (int i = pos; i < n; ++i) {
      if (a[i] >> bit & 1) p = i;
    }
    if (p == -1) continue;
    swap(a[p], a[pos]);
    for (int i = 0; i < n; ++i) {
      if (i == pos) continue;
      if (a[i] >> bit & 1) a[i] ^= a[pos];
    }
    pos++;
  }
  int64_t k = 0;
  for (int i = 0; i < n; ++i) k ^= a[i];
  cout << res + ((sum ^ k) + k) << "\n";
  return 0;
}


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)

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

const int MOD = 1e9 + 7;
const int maxn = 1;
const double EPS = 1e-8;

int N, K;

int a[55];
int mm1[55], mm2[55];
class DEqueue {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> N >> K;
		for (int i = 1; i <= N; ++i) {
			in >> a[i];
		}
		int res = 0;
		for(int i = 0; i <= N; ++i){
			for(int j = i + 1; j <= N+1; ++j){
				vector<int>v;v.clear();
				if(i + N + 1 - j <= K){
				    if(i >= 1)
					for(int k = 1; k <= i; ++k){
						v.push_back(a[k]);
					}
					for(int k = j; k <= N; ++k){
						v.push_back(a[k]);
					}
					sort(v.begin(), v.end());
					int d = K - (i + N + 1 - j);
					while(d && v.size()){
						if(v[0] < 0)v.erase(v.begin());
						else break;
						d--;
					}
					int cnt = 0;
					for (int k = 0; k < v.size(); ++k) {
						cnt += v[k];
					}
					res = max(res, cnt);
				}
			}
		}
		out << res << endl;
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	DEqueue solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#define Bobyama
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int P, Q, R;

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

  cin >> P >> Q >> R;

  cout << min(P+Q, min(R+Q, R+P)) << endl;

  return 0;
}


Measured memory_bytes: 888
X = list(map(int,input()))
sn = []
for i in range(len(X)):
  sn.append(sum(X[0:i+1]))
ssn = []
for i in range(len(X)):
  if (sn[i] != 0):
    ssn.append(sn[i]-1 + 9*(len(X)-1-i))
ssn.append(sum(X))
print(max(ssn))

Measured memory_bytes: 61808
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
inline int addmod(int x)
{
	return x>=mod?x-mod:x;
}
inline int submod(int x)
{
	return x<0?x+mod:x;
}
int fpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=1ll*ans*x%mod;
		x=1ll*x*x%mod;
		y/=2;
	}
	return ans;
}
int n,a[1005],f[1005][2],st[100005],tp,ls[100005],rs[100005],inv2;
void dfs(int u,int fa)
{
	if(!u) return;
	dfs(ls[u],u),dfs(rs[u],u);
	int v=a[u]-a[fa];
	if(!ls[u]&&!rs[u])
	{
		f[u][1]=fpow(2,v);
	//	printf("u=%d,f=%d,%d\n",u,f[u][0],f[u][1]);
		return;
	} 
	if(!ls[u]||!rs[u])
	{
		int s=ls[u]+rs[u];
		f[u][0]=2ll*addmod(f[s][0]+f[s][1])%mod;
	//	f[u][0]=submod(f[u][0]-f[s][1]);
		f[u][1]=1ll*fpow(2,v)*f[s][1]%mod;
	//	printf("u=%d,f=%d,%d\n",u,f[u][0],f[u][1]);
		return;
	}
	f[u][0]=2ll*addmod(f[ls[u]][0]+2*f[ls[u]][1]%mod)*addmod(f[rs[u]][0]+2*f[rs[u]][1]%mod)%mod;
	f[u][0]=submod(f[u][0]-2ll*f[ls[u]][1]*f[rs[u]][1]%mod);
	f[u][1]=1ll*fpow(2,v)*f[ls[u]][1]%mod*f[rs[u]][1]%mod;
	//printf("u=%d,f=%d,%d\n",u,f[u][0],f[u][1]);
}
int main()
{
	inv2=fpow(2,mod-2);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		while(tp>1&&a[st[tp-1]]>a[i])
		{
			rs[st[tp-1]]=st[tp];
			tp--;
		}
		if(tp&&a[st[tp]]>a[i]) ls[i]=st[tp],tp--;
		st[++tp]=i;
	}
	//for(int i=1;i<=n;i++)
	//	printf("i=%d,ls=%d,rs=%d\n",i,ls[i],rs[i]);
	while(tp>1)
	{
		rs[st[tp-1]]=st[tp];
		tp--;
	}
	dfs(st[tp],0);
	printf("%d",addmod(f[st[tp]][0]+f[st[tp]][1]));
	return 0;
}

Measured memory_bytes: 128
S = str(input())

N = len(S)

flag = True

for i in range(N):
    if S[i] == S[N - 1 - i]:
        pass
    else:
        print ('No')
        exit()

for i in range(N//2):
    if S[i] == S[N // 2 - 1 - i]:
        pass
    else:
        print ('No')
        exit()

count = 0
for i in range((N + 3) // 2 - 1, N):
    if S[i] == S[N - 1 - count]:
        count += 1
    else:
        print ('No')
        exit()

print ('Yes')

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      
      	int ns[] = new int[n];
      	int min;
      	int nc = 1;
      	boolean edge;
      	boolean edge2 = true;
      
      	for(int i = 0; i < n; i++) ns[i] = sc.nextInt();
      
      	min = ns[0];
      
      	if(min != 1){
      	for(int i = 0; i < n && edge2;i++){
          edge = true;
          if(ns[i] == 1){
            nc++;
            edge2 = false;  
          } else if(min > ns[i]){
            nc++;
            min = ns[i];
          }
         }
        }
        
		
      	System.out.println(nc);
        
	}
}

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int a, b, c, n;
   while (cin >> a >> b >> c, a) {
      cin >> n;
      vector<int> A(a, 2), B(b, 2), C(c, 2); // 0オリジンで格納する
      vector<int> I, J, K; // 不合格のデータを格納
      for (int l = 0; l < n; l++) {
         int i, j, k, r;
         cin >> i >> j >> k >> r;
         i = i-1, j = j-a-1, k = k-a-b-1; // 0オリジンにするため
         if (r == 1) {
            A[i] = 1, B[j] = 1, C[k] = 1;
         } else {
            I.push_back(i), J.push_back(j), K.push_back(k);
         }
      }

      for (int i = 0; i < I.size(); i++) {
         if (A[I[i]] == 1 && B[J[i]] == 1) C[K[i]] = 0;
         if (A[I[i]] == 1 && C[K[i]] == 1) B[J[i]] = 0;
         if (B[J[i]] == 1 && C[K[i]] == 1) A[I[i]] = 0;
      }

      for (int x : A) cout << x << endl;
      for (int x : B) cout << x << endl;
      for (int x : C) cout << x << endl;
   }

   return 0;
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;

int main(){
  int x;
  scanf("%d",&x);
  printf("%s",x >= 1200 ? "ARC" : "ABC");
}

Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k,x;
string s;
vector<lo> v;

int main(void){
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&x);
		while(x){
			if(x%2==0) cev++;
			else break;
			x/=2;
		}
	}
	printf("%lld\n",cev);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[sz(V)-2])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define rgiv(V,n) ((V)[((n)+sz(V))%sz(V)])
#define clv(V) (V).clear()
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define MAXN (100005)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
int gcd(int a, int b) { for(;b;a%=b,swap(a,b)); return a; }

int N, K, G, Mx;

int main() {
	scanf("%d%d", &N, &K);
	for(int c; N--;) {
		scanf("%d", &c); G = gcd(G, c); upmax(Mx, c);
	}
	puts((K % G || Mx < K) ? "IMPOSSIBLE" : "POSSIBLE");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const ll INF = 1LL << 50;
    int n,m,l;
    cin >> n >> m >> l;
    vector<vector<ll>> v1(n,vector<ll>(n,INF));
    REP(i,n) v1[i][i] = 0;
    REP(i,m) {
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        v1[a][b] = c;
        v1[b][a] = c;
    }

    REP(k,n) REP(i,n) REP(j,n) {
        v1[i][j] = min(v1[i][j], v1[i][k] + v1[k][j]);
    }

    vector<vector<ll>> v2(n,vector<ll>(n,INF));
    REP(i,n) v1[i][i] = 0;
    REP(i,n) REP(j,n) if (v1[i][j] <= l) v2[i][j] = 1;

    REP(k,n) REP(i,n) REP(j,n) {
        v2[i][j] = min(v2[i][j], v2[i][k] + v2[k][j]);
    }

    int q; cin >> q;
    vector<pii> st;
    REP(i,q) {
        int s, t;
        cin >> s >> t;
        s--;t--;
        int ans = v2[s][t] < INF ? v2[s][t]-1 : -1;
        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

#define maxx 1005
#define inf 0x7fffffff

struct Node {
	int x, y, s;
	Node() {}
	Node(int x, int y, int s) : x(x), y(y), s(s) {};
};

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

int h,w,n;
int ix, iy;
int ans;
char m[maxx][maxx];
bool a[maxx][maxx];

int bfs(char c) {
	int res;
	for(int i=0;i<h;i++) {
		for(int j=0;j<w;j++) a[i][j]=true;
	}
	queue<Node> q;
	q.push(Node(ix, iy, 0));

	while(!q.empty()) {
		Node p=q.front();
		q.pop();
		for(int i=0; i<4; i++) {
			int nx=p.x+dx[i], ny=p.y+dy[i];
			if(nx<0 || nx>=h || ny<0 || ny>=w || m[nx][ny]=='X' || a[nx][ny]==false) continue;//判断出界/碰壁
			else if(m[nx][ny]==c) {//结束条件
				ix=nx, iy=ny;
				res=p.s+1;
				return res;
			} else {
				q.push(Node(nx, ny, p.s+1));
				a[nx][ny]=false;
			}
		}
	}
}

int main() {
	scanf("%d %d %d",&h,&w,&n);
	for(int i=0; i<h; i++) {
		for(int j=0; j<w; j++) {
			cin>>m[i][j];
			if(m[i][j]=='S') ix=i, iy=j;
		}
	}
	ans=0;
	for(int i=1; i<=n; i++) {
		ans+=bfs('0'+i);
	}
	printf("%d\n",ans);

	return 0;
}


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

int main() {
  char t;
  cin >> t;
  if (t == 'A') {
    cout << "T";
    return 0;
  } else if (t == 'T') {
    cout << "A";
    return 0;
  } else if (t == 'C') {
    cout << "G";
    return 0;
  } else {
    cout << "C";
    return 0;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		int n=sc.nextInt();
		Long k=sc.nextLong();
		Long x=0L;
		Long ans=0L;
		Long a[]=new Long[n];
		String a_[]=new String[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextLong();
			String abit=Long.toBinaryString(a[i]);
			
			a_[i]=String.format("%41s",abit);
			
			
		}
		int count[]=new int[41];
		for(int j=0;j<=40;j++) {
			for(int i=0;i<n;i++) {
				if(a_[i].charAt(j)=='1') {
					count[j]++;
				}
			}
			
			if(2*count[j]<n&&(long)Math.pow(2,40-j)+x<=k) {
				x+=(long)Math.pow(2,40-j);
			}
			
		}
		for(int i=0;i<n;i++) {
			ans+=x^a[i];
		}
		System.out.println(ans);
	}
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





Measured memory_bytes: 113192
#include <iostream>
#include <cmath>

int main(int argc, char *argv[]) {
    int N;
    long long D;
    std::cin >> N >> D;
    long long x[N], y[N];
    for(int i=0; i<N; i++) {
        std::cin >> x[i] >> y[i];
    }
    int count = 0;
    long long d2 = D*D;
    for(int i=0; i<N; i++) {
        if(x[i]*x[i]+y[i]*y[i] <= d2) {
            count++;
        }
 
    }
    std::cout << count << std::endl;




    return 0;
}

Measured memory_bytes: 6648
require 'prime'
n = gets.to_i
counter = 0

arr = []
(2..n).to_a.each do |v|
  if v.odd?
    arr << v
  end
end

arr.each do |n|
  cnt = 1
  n.prime_division.each do |ar|
    cnt *= (ar[1]+1)
  end
  counter += 1  if cnt == 8
end

p counter


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

int n, p[] = { 5, 7, 5, 7, 7 }, ans;
string s[40];

int main() {
	while (true) {
		cin >> n;
		if (!n)break;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}
		ans = 0;

		for (int i = 0; i < n; i++) {
			int index = 0;
			int sum = 0;
			for (int j = i; j < n; j++) {
				sum += s[j].length();
				if (sum == p[index]) {//次に進む
					index++;
					sum = 0;
				}
				else if (sum > p[index]) {//もうあり得ない
					break;
				}

				if (index > 4) {
					ans = i + 1;
					break;
				}
			}

			if (ans > 0)break;
		}

		cout << ans << endl;
	}
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	int n, a, b;
	cin >> n;
	for (ll x =-200; x <= 200; x++) {
		for (ll y = -200; y <= 200; y++) {
			ll c = x * x * x * x * x - y * y * y * y * y;
			if (n != c) continue;
			a = (int)x;
			b = (int)y;
		}
	}
	cout << a << ' ' << b << endl;
	return 0;
}
// a^5 = n + b^5

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

int A[9],a[9]={2,5,5,4,5,6,3,7,6};
pair<int,int> dp[101010];

int main(){
  int N,M; cin>>N>>M;
  rep(i,M){
    int x; cin>>x; x--;
    A[x]=1;
  }

  rep(i,101010) dp[i]={-1,-1};
  dp[0]={0,0};
  rep(i,N) if(dp[i].first!=-1){
    rep(j,10) if(A[j]){
      int nex=i+a[j];
      if(dp[nex].first<dp[i].first+1){
        dp[nex]={dp[i].first+1,j};
      }else if(dp[nex].first==dp[i].first+1){
        if(dp[nex].second<j){
          dp[nex].second=j;
        }
      }
    }
  }
  int cur=N;
  while(cur>0){
    cout<<dp[cur].second+1;
    cur-=a[dp[cur].second];
  }
  cout<<endl;

  return 0;
}


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

int main() {
    int h1, h2, m1, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans = max(0, (h2 - h1) * 60 + m2 - m1 - k);
    cout << ans << endl;
}

Measured memory_bytes: 3640
n = int(input())
l = [int(i) for i in input().split()]

count = 0
m_count = 0
for i in range(1, len(l)):
    if l[i] <= l[i-1]:
        count += 1
    else:
        m_count = max(m_count, count)
        count = 0

m_count = max(m_count, count)
print(m_count)

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		char[] inputArray = input.readLine().toCharArray();

		for (char c : inputArray) {
			System.out.print(Character.toUpperCase(c));
		}
		System.out.println();
	}
}

Measured memory_bytes: 24200
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10



int main() {
	int N, M; cin >> N >> M;
	cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;


	return 0;
}


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

int main(){
  array<int,10> xs;
  for(int i=0;i<10;++i)scanf("%d",&xs[i]);
  sort(xs.begin(),xs.end(),greater<int>());
  for(int i=0;i<3;++i)printf("%d\n",xs[i]);
  return 0;
}

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

long long gcd(long long x, long long y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

long long lcm(long long x, long long y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int main()
{
    int N;
    cin >> N;
    vector<long> A(N), B(N), C(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++)
    {
        cin >> B[i];
    }
    sort(B.begin(), B.end());
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
    }
    sort(C.begin(), C.end());

    long ans = 0;
    for (int i = 0; i < N; i++)
    {
        auto a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        auto c = upper_bound(C.begin(), C.end(), B[i]) - C.begin();
        ans += a * (N - c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2688
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            int c = 1;
            List<string> outList = new List<string>();
            for (; (line = Console.ReadLine()) != "";)
            {
                int n = int.Parse(line);
                if(n==0)
                {
                    break;
                }

                outList.Add(string.Format("Case {0}: {1}", c, n));
                    
                c++;
            }

            foreach(var v in outList)
            {
                Console.WriteLine(v);
            }

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 10152