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

int main(){
    long long int n,m;
    cin >> n >> m;
    long long ans = 0;
    if(n==1&&m==1){
        cout << 0 << endl;
    }
    else{
        if(n>=m/2) ans += m/2;
        else{
            ans += n;
            m -= 2*n;
            ans += m/4;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
<?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$D) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$ans=0;
for($i=0;$i<$N;$i++) {
  list($X,$Y) = array_map('intval',explode(" ",trim(fgets(STDIN))));
  if (sqrt($X**2+$Y**2)<=$D) {
    $ans++;
  }
}
printf("%d\n",$ans);


Measured memory_bytes: 16136
#include<stdio.h>
int main(){
  int A,a,i,cou,h,d,n;
  while(1){
    scanf("%d %d %d",&a,&d,&n);
    if(a==0&&d==0&&n==0)break;
    cou=0;
    h=a;
    for(i=2;i*i<=a;i++){
      if(h%i==0)break;
    }
    if(i*i>h){
      cou++;
      A=a;
    }
    if(A==1)cou=0;
    while(cou!=n){
      h+=d;
      for(i=2;i*i<=h;i++){
	if(h%i==0)break;
      }
      if(i*i>h){
	cou++;
	A=h;
      }
    }
    printf("%d\n",A);
  }
  return 0;
}
    

Measured memory_bytes: 1028
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

static ArrayList<Integer[]> list=new ArrayList<>();
static ArrayList<Integer[]> set=new ArrayList<>();


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

   String nyuA=sc.nextLine();
   String nyuB=sc.nextLine();
 
 //   String[] s=sc.nextLine().split(" ");
//     String[] e=sc.nextLine().split(" ");

//int N=Integer.parseInt(nyuA);

int N=Integer.parseInt(nyuA);
int K=Integer.parseInt(nyuB);

int res=1;

for(int i=0;i<N;i++){
if(res<K){
res*=2;
}else{
res+=K;
}
}
System.out.println(res);


	}

}

Measured memory_bytes: 21844
#include<stdio.h>
#define MAX 101

int main(void)
{
	int N,K,i,j,sum,check;
	int S[MAX], B[MAX][MAX];
	
	while(scanf("%d %d",&N,&K))
	{
		if(N==0&&K==0)
		break;
		else
		{
			for(i=0;i<K;i++)
			{
				scanf("%d ",&S[i]);
			}
			for(i=0;i<N;i++)
			{
				for(j=0;j<K;j++)
				{
					scanf("%d ",&B[i][j]);
				}
			}
			sum = 0;
			check = 0;
			for(i=0;i<K;i++)
			{
				for(j=0;j<N;j++)
				{
					sum = sum + B[j][i];
				}
				if(sum>S[i])
				{
					check = 1;
					break;
				}
				sum = 0;
			}
			if(check==0)
			printf("Yes\n");
			else
			printf("No\n");
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n, p;
    while (cin >> n >> p, n) {
        int m = 0, q = p, st[50] = {};
        while (1) {
            if (p == 0) {
                p += st[m];
                st[m] = 0;
            } else {
                p--;
                st[m]++;
                if (p == 0 && st[m] == q) {
                    break;
                }
            }
            m = (m + 1) % n;
        }
        cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
long long int big[60][2] = {};
long long hand(long long int  a, long long int b) {
	if (a == 0) {
		return 1;
	}

	if (b == 1) {
		return 0;
	}
	if (b == big[a - 1][0]+big[a-1][1] + 2) {
		return 1+big[a-1][0];
	}
	if (b == (big[a - 1][0] + big[a - 1][1])*2 + 3) {
		return big[a - 1][0]*2 + 1;
	}

	if (b > big[a-1][0] + big[a-1][1]+2) {
		return hand(a - 1, b - big[a - 1][0]-big[a-1][1]-2) + 1 + big[a - 1][0];
	}
	else {
		return hand(a - 1, b - 1);
	}
}
int main() {
	long long int n;
	long long int x;
	cin >> n>>x;
	big[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		big[i][0] = big[i - 1][0] * 2 + 1;
		big[i][1] = big[i - 1][1] * 2 + 2;
	}
	cout << hand(n,x);
}

Measured memory_bytes: 256
n,k=gets.split.map(&:to_i)
ans=n*n
(1..n).each do |m|
  # p [m, '=', (n/m)*[k,m].min, [k-1, n%m].min]
  ans -= (n/m)*[k,m].min + [0,[k-1, n%m].min].max
end
p ans


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

ll n,m,x,ans=INF;
vector<ll> c;
vector<bool> want;
vector<vector<ll>> a;


void dfs(ll num,bool need,vector<bool> want){
    if(num==n){
        bool can=true;
        ll sum=0;
        vector<ll> understand(m,0);
        for(int i=0;i<n;i++){
            if(want[i]){    
                for(int j=0;j<m;j++){
                    understand[j]+=a[i][j];
                }
                sum+=c[i];
            }
        }
        for(int i=0;i<m;i++){
            if(understand[i]<x){can=false;}
        }

        if(can){ans=min(ans,sum);}
        return;
    }

    want[num]=need;
    dfs(num+1,false,want);
    dfs(num+1,true,want);

    return;
}

int main(){
    cin>>n>>m>>x;//aをall x以上
    a.assign(n,vector<ll>(m,0));
    c.assign(n,0);
    want.assign(n,false);

    for(ll i=0;i<n;i++){
        cin>>c[i];
        for(ll j=0;j<m;j++){
            cin>>a[i][j];
        }
    }

    dfs(0,false,want);
    dfs(0,true,want);

    if(ans!=INF){cout<<ans<<endl;}
    else{cout<<-1<<endl;}
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
using namespace std;
int now[100000];
int failure[100000];
bool ok[100000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)ok[i]=false;
		bool zero=false;
		for(int i=0;i<b;i++){
			int c;
			scanf("%d",&c);
			if(c==0)zero=true;
			else ok[c-1]=true;
		}
		now[0]=1;
		if(ok[0])failure[0]=1;
		else failure[0]=0;
		for(int i=1;i<a;i++){
			if(ok[i]){
				failure[i]=failure[i-1]+1;
				now[i]=now[i-1]+1;
			}else{
				failure[i]=0;
				now[i]=failure[i-1]+1;
			}
		}
		int ret=0;
		for(int i=0;i<a;i++)ret=max(ret,zero?now[i]:failure[i]);
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 0
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<ctime>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 200500
#define inf 1152921504606846976
#define ll long long
#define mm 1000000007
#define eps 1e-9
#define low(x) x&(-x)
#define pb push_back
#define mp make_pair
#define PII pair<int,int>
using namespace std;

ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
struct data{int obj,pre;
}e[maxn*2];
int head[maxn],s[maxn],fa[maxn][22],bin[22],dep[maxn],n,tot;
void insert(int x,int y){
	e[++tot].obj=y; e[tot].pre=head[x]; head[x]=tot;
}

void dfs(int u){
	s[u]=1;
	rep(i,1,20) fa[u][i]=fa[fa[u][i-1]][i-1];
	for (int j=head[u];j;j=e[j].pre){
		int v=e[j].obj;
		if (v==fa[u][0]) continue;
		dep[v]=dep[u]+1; fa[v][0]=u; 
		dfs(v);
		s[u]+=s[v];
	}
}
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	bin[0]=1; rep(i,1,20) bin[i]=bin[i-1]*2;
	n=read();
	rep(i,1,n-1){
		int x=read(),y=read();
		insert(x,y); insert(y,x);
	}
	dep[1]=1; dfs(1);
	int del=(dep[n]-2)/2;
	int x=n;
	down(i,20,0) if (bin[i]&del) x=fa[x][i];
	if (s[x]>=n-s[x]) puts("Snuke");
	else puts("Fennec");
    return 0;
}

Measured memory_bytes: 20864
#include <stdio.h>
#include <string>
#include <iostream>
using std::cin;
using std::string;

int main(void) {
	string s;

	cin >> s;

	if (s[0] == s[1]) {
		if (s[2] == s[3]) {
			if (s[2] != s[0]) { printf("Yes"); }
			else { printf("No"); }
		}
		else { printf("No"); }
	}
	else if (s[0] == s[2]) {
		if (s[1] == s[3]) {
			if (s[1] != s[0]) { printf("Yes"); }
			else { printf("No"); }
		}
		else { printf("No"); }
	}
	else if (s[0] == s[3]) {
		if (s[1] == s[2]) {
			if (s[1] != s[0]) { printf("Yes"); }
			else { printf("No"); }
		}
		else { printf("No"); }
	}
	else { printf("No"); }
}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int l;
  string s,t;
  cin>>l>>s>>t;
  
  Int n=s.size(),m=t.size();
  auto calc=[&](Int a,Int f){
    Int b=(l-a*n)/m;
    assert(a*n+b*m==l);
    string res;
    if(f) for(Int i=0;i<a;i++) res+=s;
    for(Int i=0;i<b;i++) res+=t;    
    if(!f) for(Int i=0;i<a;i++) res+=s;
    return res;
  };
  
  Int x=l+1,y=-1;
  for(Int i=0;i*n<=l;i++){
    Int a=i,b=(l-a*n)/m;
    if(a*n+b*m==l){
      chmin(x,a);
      chmax(y,a);
    }
  }
  //cout<<x<<" "<<y<<endl;
  string ans=calc(x,0);
  chmin(ans,calc(x,0));
  chmin(ans,calc(x,1));
  chmin(ans,calc(y,0));
  chmin(ans,calc(y,1));
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1220
n=int(input())
alist=list(map(int,input().split()))
alist.sort()
nolist=[False]*(10**6+1)

counter=0
for i,a in enumerate(alist):
    if not nolist[a]:
        for j in range(10**6 // a):
            nolist[a*(j+1)] = True

        if i == n-1:
            counter += 1
        elif alist[i+1] != a:
            counter += 1
print(counter)

Measured memory_bytes: 117200
n, x = [int(i) for i in input().split()]

# L0 =           1
# L1 =        0, 1, 2, 3, 3
# L2 =     0, 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 7, 7
# L3 =  0, 0, 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 7, 7, 8,
#          8, 8, 9,10,11,11,12,12,13,14,15,15,15,   15

# まずLnの長さ,Pの数を算出
length = [[0, 0] for i in range(n+1)]
length[0] = [1, 1]
for i in range(1, n+1):
    length[i][0] = length[i - 1][0] * 2 + 3
    length[i][1] = length[i - 1][1] * 2 + 1
    # print("L[{}]:{}".format(i, length[i]))


def search(i, x):
    pat = 0
    if i == 0:
        # print("i:{} x:{} pat:{}".format(i, x, 1))
        return 1
    # xが先頭の時
    elif x == 0:
        # print("i:{} x:{} pat:{}".format(i, x, 0))
        return 0
    # xが真ん中の時
    elif x == 1 + int((length[i][0] - 3) / 2):
        # print("i:{} x:{} pat:{}".format(i, x, length[i - 1][1] + 1))
        return length[i - 1][1] + 1
    # xが末尾の時
    elif x == length[i][0] - 1:
        # print("i:{} x:{} pat:{}".format(i, x, length[i][1]))
        return length[i][1]
    # xが中心より小さいとき
    elif x < 1 + int((length[i][0] - 3) / 2):
        pat = search(i - 1, x - 1)
    # xが中心より大きいとき
    elif x > 1 + int((length[i][0] - 3) / 2):
        pat = length[i - 1][1] + 1\
              + search(i - 1, x - 2 - int((length[i][0] - 3) / 2))
    # print("i:{} x:{} pat:{}".format(i, x, pat))
    return pat


print(search(n, x - 1))


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<string.h>

int n;
char a[1000];
int temp[1000], temp2[1000], temp3[1000];

int main()
{
        std::cin >> n;
	
	while( n-- ){
		memset( temp, -1, sizeof( temp ) );
		memset( temp2, -1, sizeof( temp2 ) );
		memset( temp3, 0, sizeof( temp3 ) );
		
		std::cin >> a;
		
		for( int i = 0; i < strlen( a ); i++ ){
			temp[strlen( a ) - i - 1] = a[i] - '0';
		}
		
		std::cin >> a;
		
		for( int i = 0; i < strlen( a ); i++ ){
			temp2[strlen( a ) - i - 1] = a[i] - '0';
		}
		
		int p = 0, f = 0;
		while( 1 ){
		 	if( temp[p] != -1 && temp2[p] != -1 ){
			 	temp3[p] = ( temp[p] + temp2[p] + f ) % 10;
				f = ( temp[p] + temp2[p] + f ) / 10;
			}
			else if( temp[p] != -1 ){
				temp3[p] = ( temp[p] + f ) % 10;
				f = ( temp[p] + f ) / 10;
			}
			else if( temp2[p] != -1 ){
				temp3[p] = ( temp2[p] + f ) % 10;
				f = ( temp2[p] + f ) / 10;
			}
			else break;
			
			p++;
		}
		
		if( p + f > 80 ){
			std::cout << "overflow" << std::endl;
			continue;
		}
		
		if( f )std::cout << -temp[p];
		
		for( int i = p - 1; i >= 0; i-- ){
		 	std::cout << temp3[i];
		}
		std::cout << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1176
input()
A = list(map(int, input().split(" ")))
A.sort()
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
rtn = 0
for i in range(0,len(A)-1):
    A[i+1] = gcd(A[i], A[i+1])
print(A[-1])

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

//#define int long long

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin>>S;
    int ok[101010] = {};
    ok[0] = 1;
    int L = S.size();
    REP(i,L) if(ok[i])
    {
        if(i+5 <= L && S.substr(i,5) == "dream") ok[i+5] = 1;
        if(i+7 <= L && S.substr(i,7) == "dreamer") ok[i+7] = 1;
        if(i+5 <= L && S.substr(i,5) == "erase") ok[i+5] = 1;
        if(i+6 <= L && S.substr(i,6) == "eraser") ok[i+6] = 1;

    }
    if(ok[L] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    dump(L)

    REP(i,20)
    {
        dump(i)
        dump(ok[i])
    }


}

Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

int main(){
	int h,w;
	cin >> h >> w;
	string s[h];
	REP(i,h) cin >> s[i];
	int cnt[h][w] = {};
	REP(i,h){
		REP(j,w){
			if(s[i][j] == '#'){
				REP(k,8){
					if(0 <= i + dy[k] && i + dy[k] < h && 0 <= j + dx[k] && j + dx[k] < w){
						cnt[i + dy[k]][j + dx[k]]++;
					}
				}
			}
		}
	}
	REP(i,h){
		REP(j,w){
			if(s[i][j] == '#') cout << s[i][j];
			else cout << cnt[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,m,k,p[maxn],d,s1,tmp,inv[maxn],fac[maxn];
const ll mod=1000000007;

inline ll pw(ll a,ll b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1) ans=(ans*base)%mod;
		base=(base*base)%mod; b>>=1;
	}
	return ans;
}

inline ll C(int N,int M)
{
	return ((fac[N]*inv[M])%mod*inv[N-M])%mod;
}

inline ll Mul(ll a,ll b){return (a%mod*b%mod)%mod;}

int main()
{
	cin>>n>>m>>k; fac[0]=1; inv[0]=1;
	for(int i=1;i<=200000;i++) fac[i]=(fac[i-1]*i)%mod;
	for(int i=1;i<=200000;i++) inv[i]=pw(fac[i],mod-2);
	ll ans=0;
	for(ll i=1;i<n;i++) ans=(ans+Mul((n-i)*i,m*m))%mod;
	for(ll i=1;i<m;i++) ans=(ans+Mul((m-i)*i,n*n))%mod;
	ans=(ans*C(n*m-2,k-2))%mod; cout<<ans<<endl;
	return 0;
}

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

const int MAXN = 1005;
string t[MAXN];
long long dp[MAXN][MAXN];
int main()
{
    int n, m;
    cin >> n >> m;
    dp[0][0] = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
        for (int j = 0; j < m; j++)
        {
            if (t[i][j] == '#') continue;
            if (j && t[i][j-1] != '#') dp[i][j] += dp[i][j-1];
            if (i && t[i-1][j] != '#') dp[i][j] += dp[i-1][j];
            dp[i][j] %= 1000000007;
        }
    }
    cout << dp[n-1][m-1];\
    return 0;
}


Measured memory_bytes: 9216
N=int(input())

import heapq
def dijkstra_heap(s):
  #始点sから各頂点への最短距離
  #indexが1～Nの場合はNの代わりにN+1
  size_v=N+1
  dist=[float("inf")]*size_v
  used=[False]*size_v
  dist[s]=0
  used[s]=True

  hq_edge=[]
  for v,w in edge[s]:
    heapq.heappush(hq_edge,(w,v))

  while len(hq_edge):
    min_w,min_v=heapq.heappop(hq_edge)
    #まだ使われてない頂点の中から最小の距離のものを探す
    if used[min_v]:
      continue

    dist[min_v]=min_w
    used[min_v]=True
    for v,w in edge[min_v]:
      if not used[v]:
        heapq.heappush(hq_edge,(min_w+w,v))

  return dist

edge=[[] for _ in range(N+1)]
for _ in range(N-1):
  a,b,c=map(int,input().split())
  edge[a].append((b,c))
  edge[b].append((a,c))
#print(edge)

Q,K=map(int,input().split())

dist=dijkstra_heap(K)
#print(dist)

for _ in range(Q):
  x,y=map(int,input().split())
  print(dist[x]+dist[y])

Measured memory_bytes: 46764
S = input()
c = []
cnt = []
for i in range(4):
  x = S[i]
  if not x in c:
    c.append(x)
    cnt.append(1)
  else:
    idx = c.index(x)
    cnt[idx] += 1
if len(c) == 2 and cnt[0] == 2 and cnt[1] == 2:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
N = int(input())
S = input()
r = []
for c in S:
  if c == "(":
    r.append(1)
  else:
    r.append(-1)
ruiseki = [0]
for er in r:
  ruiseki.append( ruiseki[-1] + er )

age = 0
if min(ruiseki) < 0:
  age = abs(min(ruiseki))
  S = "("*abs(min(ruiseki)) + S
if ruiseki[-1] + age > 0:
  S = S + ")"*(ruiseki[-1] + age)
print(S)

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int main() {
	int N, H;
	cin >> N >> H;
	vector<int> v;
	int max_a = 0;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		max_a = max(max_a, a);
		v.push_back(b);
	}
	sort(v.rbegin(), v.rend());
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (v[i] > max_a) H -= v[i], ans++;
		if (H <= 0) break;
	}
	if (H > 0) ans += (H + max_a - 1) / max_a;
	cout << ans << endl;
}

Measured memory_bytes: 892
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		long a=1;
		long x=1;
		for(int i=0;i<9;i++) {
			x *=10;
		}
		for(int i=1;i<=c;i++) {
			a = a*i;
			a =  a % (x+7);
		}
		System.out.print(a);
		sc.close();
	}
}

Measured memory_bytes: 19924
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int INF = 1 << 29;
int dp[800][800];
string s[800];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int h, w, k;
int ans = INF;
queue<P> que;
bool fl;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> k;
    rep(i, h)
    {
        rep(j, w)
        {
            dp[i][j] = INF;
        }
    }
    rep(i, h)
    {
        cin >> s[i];
        rep(j, w)
        {
            if (s[i][j] == 'S')
            {
                que.push(P(i, j));
                if (i == 0 || j == 0 || i == h - 1 || j == w - 1)
                {
                    fl = true;
                }
                dp[i][j] = 0;
            }
        }
    }
    while (!que.empty())
    {
        P p = que.front();
        ans = min(ans, min(min(h - 1 - p.first, p.first), min(w - 1 - p.second, p.second)));
        que.pop();
        if (dp[p.first][p.second] == k)
            continue;
        rep(i, 4)
        {
            if (p.first + dy[i] < 0 || p.first + dy[i] >= h)
                continue;
            if (p.second + dx[i] < 0 || p.second + dx[i] >= w)
                continue;
            if (s[p.first + dy[i]][p.second + dx[i]] == '#')
                continue;
            if (dp[p.first + dy[i]][p.second + dx[i]] != INF)
                continue;
            dp[p.first + dy[i]][p.second + dx[i]] = dp[p.first][p.second] + 1;
            que.push(P(p.first + dy[i], p.second + dx[i]));
        }
    }
    if (fl)
        cout << 0 << endl;
    else
        cout << (ans + k - 1) / k + 1 << endl;
}


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

int main() {
    int n;
    cin >> n;
    int d = 0;
    for (int i = 1; i <= n; i++) {
        int p;
        cin >> p;
        if (p != i) d++;
    }

    cout << (d <= 2 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Solver {
    void solve(Scanner sc) {
        String s = sc.next();

        int sum = 1;
        int head = 0, tail = 1;
        for (int i = 1; i < s.length(); i++) {
            int h = tail, t = i + 1;
            if (tail - head == t - h && s.charAt(i - h + head) == s.charAt(i)) continue;

            sum += 1;
            head = h;
            tail = t;
        }

        System.out.println(sum);
    }
}

class Main {
    public static void main(String... args) {
        Scanner in = new Scanner(System.in);

        new Solver().solve(in);

        in.close();
    }
}

Measured memory_bytes: 26660
#include<bits/stdc++.h>
using namespace std;
const int oo=-10;
int n,m,a[100][100];
char c;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cin>>c;
            if(c=='#')
            {
                a[i][j]=oo;
                a[i-1][j-1]++;
                a[i-1][j]++;
                a[i-1][j+1]++;
                a[i][j-1]++;
                a[i][j+1]++;
                a[i+1][j-1]++;
                a[i+1][j]++;
                a[i+1][j+1]++;
            }
        }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            if(a[i][j]<0)cout<<"#";
            else cout<<a[i][j];
        cout<<endl; 
    }
	return 0;   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[3010][3010],n,t;
pair<int,int>arr[3010];
int solve(int pos,int T)
{
	if(T>=t)return 0;
	if(pos==n)return 0;
	if(dp[pos][T]!=-1)return dp[pos][T];
	int sum = max(solve(pos+1,T),arr[pos].second+solve(pos+1,T+arr[pos].first));
	return dp[pos][T] = sum;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> t;
	for(int i=0;i<n;i++){
		cin >> arr[i].first >> arr[i].second;
	}
	sort(arr,arr+n);
	memset(dp,-1,sizeof dp);
	cout << solve(0,0)<<"\n";
}


Measured memory_bytes: 35840
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n, c, k = 0, s = 0;
  cin >> n >> c;
  int a[n], b[n];
  for(int i = 0; i < c; i++){
    cin >> a[i];
  }
  for(int i = 0; i < c; i++){
    if(i < c - 1){
	    b[i] = a[i + 1] - a[i];
          if(s < b[i]){
    	  s = b[i];
          }
    }
    if(i == c - 1){
      b[i] = (n + a[0]) - a[i];
      if(s < b[i]){
        s = b[i];
      }
    }
  }
  k = n - s;
  cout << k << "\n";
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  char n;
  cin >> n;
  if(islower(n))
    cout << "a\n" ;
  else
    cout << "A\n" ;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>

#define LEN 100005

using namespace std;


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

class Queue
{
private:
	P Q[LEN + 1];
	int head, tail, n;

public:
	Queue()
	: head(0)
	, tail(0)
	, n(0) {}

	void enqueue(P x) {
		Q[tail++] = x;
		if(sizeof(Q) / sizeof(Q[0]) == tail) {
			tail = 0;
		}
		if(sizeof(Q)/sizeof(Q[0]) > n) {
			n++;
		}
		else{
			head = head < sizeof(Q) / sizeof(Q[0]) - 1 ? head + 1 : 0;
		}
	}

	P dequeue() {
		P front = {"", 0};
		if(0 < n) {
			n--;
			front = Q[head++];
			if(sizeof(Q) / sizeof(Q[0]) == head) {
				head = 0;
			}
		}
		return front;
	}

	bool isEmpty() {
		return 0 == n;
	}
};

void executeProcesses(Queue& processList, const int q);

int main() {
	ios::sync_with_stdio(false);

	int elaps = 0, c;
	int q, n;
	P u;
	Queue queue;

	cin >> n >> q;
	for(int i = 0; i < n; i++) {
		cin >> u.name >> u.t;
		queue.enqueue(u);
	}

	executeProcesses(queue, q);

	return 0;
}

void executeProcesses(Queue& processList, const int q) {
	int elaps = 0;

	while(!processList.isEmpty()) {
		P tmp = processList.dequeue();
		if(q < tmp.t) {
			elaps += q;
			tmp.t -= q;
			processList.enqueue(tmp);
		} else {
			elaps += tmp.t;
			cout << tmp.name << " " << elaps << endl;
		}
	}
}


Measured memory_bytes: 13184
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    s, c = ns()

    if c % 2:
        c -= 1

    if s >= c // 2:
        ans = c // 2
    else:
        x = (c - 2 * s) // 2
        ans = (c - x) // 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5076
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, k; cin >> n >> k;
	vi dp(k + 1), a(n); rep(i, n) cin >> a[i];
	
	for(int i = 1; i <= k; i++){
		bool f = 0;
		for(int j : a) if(j <= i && !dp[i - j]){
			f = 1; break;
		}
		dp[i] = f;
	}
	cout << (dp[k] ? "First" : "Second") << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

class unionfind{
  public:
  int Num;
  vector<int> par; //親の番号
  vector<int> height; //木の高さ(ランク)
  vector<int> members; //橋を通って行き来できる他のnode数(自身も含めて)

  unionfind(int N):
    par(vector<int>(N, 0)), height(vector<int>(N, 0)), members(vector<int>(N, 0)), Num(N) {}


  //初期化
  void init(){
    REP(i, Num){
      par[i] = i;
      height[i] = 0;
      members[i] = 1;
    }
  }

  //xの親番号を返す、再帰処理あり
  int root(int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  LL mem(int x){
    x = root(x);
    LL y = members[x];
    return y;
  }

  //xとyの親番号が同一か判定する
  bool same(int x, int y){
    return root(x) == root(y);
  }

  //xとyのある木を結合する
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y) return; //親が同一なら結合済み。

    if(height[x] < height[y]) {
      par[x] = y;
      members[y] += members[x];
    }
    else {
      par[y] = x;
      members[x] += members[y];
      if(height[x] == height[y]) height[x]++;
    }
  }
};

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

  int a[m], b[m];
  REP(i, m) {
    cin>>a[i]>>b[i];
    --a[i];
    --b[i];
  }
  LL ans[m];
  ans[m-1]=(LL)n*(n-1)/2;
  unionfind uf(n);
  uf.init();

  for(int i=m-1; i>0; --i){
    if(uf.root(a[i]) != uf.root(b[i])) ans[i-1]=ans[i] - uf.mem(a[i]) * uf.mem(b[i]);
    else ans[i-1]=ans[i];
    uf.unite(a[i], b[i]);
    //cout<<uf.root(a[i])<<" "<<uf.root(b[i])<<endl;;
  }

  REP(i, m) cout<<ans[i]<<endl;

  return 0;
}

Measured memory_bytes: 4096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int[] h = new int[N];
            for (int i = 0; i < N; i++) {
                h[i] = in.nextInt();
            }
            Arrays.sort(h);

            long min = h[N - 1] - h[0];
            for (int i = 0; i <= N - K; i++) {
                min = Math.min(min, h[i + K - 1] - h[i]);
            }
            out.println(min);
        }

    }
}



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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    string s;
    stack<ll> st;
    ll sum;

    while(cin >> s){
        if(s=="+" || s=="*" || s=="-"){
            ll a=st.top(); st.pop();
            ll b=st.top(); st.pop();
            if(s=="+")b+=a;
            if(s=="-")b-=a;
            if(s=="*")b*=a;
            st.push(b);
        }else{
            int n=stoi(s);
            st.push(n);
        }
//        cout << st.top() << endl;
    }
    cout << st.top() << endl;
}



Measured memory_bytes: 3196
#include <utility>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define REP(i, n)  for(int i=0;i<(int)(n);++i)
#define FOR(i, b, n)  for(int i=b;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()
#define PB(c) push_back(c)
#define SS size()
#define ST first
#define ND second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

vi cnt(5);


ll dfs(int at, int need) {
    if (at>4 && need<=0) return 1;
    if (at>4 && need>0) return 0;
    if (need==0) return 1;
    //take
    ll ans = cnt[at] * dfs(at+1,need-1);
    //skip
    ans += dfs(at+1,need);
//    printf("dfs(%i,%i)=%i\n", at, need, ans);
    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    int n; cin >> n;
    string s;
    string t = "MARCH";
    REP(i,n) {
        cin >> s;
        REP(j,5) if (s[0]==t[j]) cnt[j]++;
    }

    ll ans = dfs(0,3);
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	int n,ans=200000000,a;
	string s;
	cin>>n;
	for(a=1;a<n;a++){
		int ke=0;
		int b=n-a;
		s=to_string(a);
		for(int i=0;i<s.size();i++)ke+=(s[i]-'0');
		s=to_string(b);
		for(int i=0;i<s.size();i++)ke+=(s[i]-'0');
		ans=min(ans,ke);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int A, B;
    cin>>A>>B;

    int num = 1;
    int cnt = 0;
    while (num < B) {
        num = num - 1 + A;
        cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a string
	var b string
	fmt.Scanf("%s", &a)
	fmt.Scanf("%s", &b)

	total := 0
	for i, _ := range a {
		if a[i] == b[i] {
			total++
		}
	}
	fmt.Printf("%d", total)
}

Measured memory_bytes: 512
# A - ABC/ARC
#
# 現在のレートが 1200 未満ならば AtCoder Beginner Contest (ABC) に、
# そうでなければ AtCoder Regular Contest (ARC) に参加

# 現在のレート x が与えられる。

# 参加するコンテストが ABC ならば ABC
# そうでなければ、 ARC と出力

# x を標準入力から得る
x = int(input())
# print(x)

# x が 1200 未満なら ABC
# そうでなければ ARC
if x < 1200:
    answer = "ABC"
else:
    answer = "ARC"

# 結果を出力
print(answer)


Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const int N=200001;
ll n,a[N],ans=0;
ll dp[N];
ll did[N];

int main(){
	cin>>n;
	cin>>a[0];
	if(a[0]!=0){
		cout<<-1<<endl;
		return 0;
	}
	FOR(i,1,n){
		cin>>a[i];
		if(a[i]>a[i-1]+1){
			cout<<-1<<endl;
			return 0;
		}
	}
	FOR(i,0,n-1){
		if(a[i+1]<=a[i]){
			ans+=a[i];
		}
	}
	ans+=a[n-1];
	cout<<ans<<endl;

	return 0;
}

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

int main() {
  
  bool flag = true;
  
  while (flag) {
    
    int a, b; string op; cin >> a >> op >> b;
    
    if (op == "?") {
      flag = false;
      continue;
    }
    
    if (op == "+") cout << a + b << endl;
    
    if (op == "-") cout << a - b << endl;
    
    if (op == "*") cout << a * b << endl;
    
    if (op == "/") cout << a / b << endl;
    
  }
  
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
const double pi = acos(-1.0);

int p[101];

int main()
{
    int x, n;
    cin >> x >> n;
    rep(i, n) cin >> p[i];
    rep(i, 100000) {
        int y = x - i;
        bool ok = true;
        rep(j, n) if(p[j] == y) ok = false;
        if(ok) {
            cout << y << endl;
            return 0;
        }
        y = x + i;
        ok = true;
        rep(j, n) if(p[j] == y) ok = false;
        if(ok) {
            cout << y << endl;
            return 0;
        }
    }
    return 0;
}




Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
long long n;
long long dp[100001][2];

long long func(long long k,long long f,long long *a){
    if(k<a[1])
        return !f;
    if(dp[k][f]!=-1)
        return dp[k][f];
    dp[k][f]=!f;
    for(long long i=1;i<n+1;i++){
        if(k>=a[i]&&func(k-a[i],!f,a)==f){
            dp[k][f]=f;
            break;
        }
    }return dp[k][f];
}

int main() {
	long long k;
	
	cin>>n>>k;
	memset(dp,-1,sizeof(dp));
	long long a[n+1];
	for(long long i=1;i<=n;i++){
	    cin>>a[i];
	    
	}
	if(func(k,1,a)){
	    cout<<"First";
	}else{
	    cout<<"Second";
	}
    
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed_=(b);i<=_ed_;++i)
#define DREP(i,a,b) for(int i=(a),_ed_=(b);i>=_ed_;--i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)((x).size())
typedef long long ll;
typedef pair<int,int> pii;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

int n,f[50][30];

int main(){
    //freopen("in.in","r",stdin);
    n=read();ll ans=0;
    REP(i,1,n){
	static char s[20];
	scanf("%s",s+1);int m=strlen(s+1);
	ll w=0;int n1=0,n2=0;
	int p=0;while(p<m&&s[p+1]!='.')++p;
	++p;
	REP(i,1,p-1)w=w*10+s[i]-'0';
	REP(i,p+1,m)w=w*10+s[i]-'0';
	if(s[p]!='.')w=w*1000000000;
	else REP(i,m-p+1,9)w=w*10;
	while(~w&1)++n1,w>>=1;
	while(!(w%5))++n2,w/=5;
	++f[n1][n2];
	// cerr<<n1<<' '<<n2<<endl;
    }
    REP(a,0,46)REP(b,0,21)if(f[a][b])REP(c,0,46)REP(d,0,21)if(f[c][d])if(min(a+c,b+d)>=18)ans+=1ll*f[a][b]*f[c][d];
    REP(a,0,46)REP(b,0,21)if(min(a,b)>=9)ans-=f[a][b];
    ans>>=1;
    printf("%lld\n",ans);
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<pll> B(N);
    REP(i, N){
    	B[i].first = A[i];
    	B[i].second = i+1;
    }
    sort(B.begin(), B.end());
    REP(i, N) cout << B[i].second << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  long long dp[110][2][5] = {0};
  dp[0][0][0] = 1;
  for(int i = 0;i < N.size();i++) {
    for(int j = 0;j < 2;j++) {
      for(int k = 0;k <= K;k++) {
        int n = N[i]-'0';
        for(int d = 0;d < 10;d++) {
          if(d > n && j == 0) continue;
          int nk = k;
          if(d != 0) nk++;
          dp[i+1][j||d < n][nk] += dp[i][j][k];
        }
      }
    }
  }

  cout << dp[N.size()][0][K]+dp[N.size()][1][K] << endl;

}


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

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


Measured memory_bytes: 3016
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		String s = sc.next();
		sc.close();
		boolean ebishu = true;
		for(int i = 0 ; i < (s.length() - 1) / 2 && ebishu ; i++){
			if(s.charAt(i) != s.charAt(s.length() - i - 1)) ebishu = false;
			if(s.charAt(i) != s.charAt((s.length() - 1) / 2 - i - 1)) ebishu = false;
			if(s.charAt((s.length() - 1) / 2 + 1 + i) != s.charAt(s.length() - 1 - i)) ebishu = false;
		}
		if(ebishu) ou.print("Yes\n");
		else ou.print("No\n");
		ou.flush();
    }
}

Measured memory_bytes: 35672
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
    return x>y;
}
const int N=10005;
const int mod=1e9+7;

int main()
{
    std::ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if((a+b+c)%17==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int M=100*1000;
int dp[100][100][2];
int w,h;
int main() {
while(1){
	cin >> w >> h;
	if(w==0&&h==0)return 0;
	if(w==1||h==1){
		cout << 1 << endl;
		continue;
	}
	for(int i=0;i<w;i++){
		dp[0][i][0]=dp[0][i][1]=1;
	}
	for(int i=0;i<h;i++){
		dp[i][0][0]=dp[i][0][1]=1;
	}
	for(int i=1;i<h;i++){
		for(int j=1;j<w;j++){
			dp[i][j][0]=dp[i][j-1][0];
			if(i-2>=0){
				dp[i][j][0]+=dp[i-2][j][1];
			}
			dp[i][j][1]=dp[i-1][j][1];
			if(j-2>=0){
				dp[i][j][1]+=dp[i][j-2][0];
			}
			dp[i][j][0]%=M;
			dp[i][j][1]%=M;
		}
	}
	cout << (dp[h-2][w-1][1] + dp[h-1][w-2][0])%M << endl;
}
}

Measured memory_bytes: 1236
#include <stdio.h>

int main(){

  int i,x,y,m;
  for(i=1;i<=3000;i++){
    scanf("%d%d",&x,&y);
    if(x==0&&y==0) break;
    if(x>y){
      m=y;
      y=x;
      x=m;
    }
    printf("%d %d\n",x,y);
  }
  return 0;
}
  

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

ll power(ll a,ll n){ll ret=1;for(;n>0;n>>=1,a=a*a%MOD)if(n%2==1)ret=ret*a%MOD;return ret;}

void solve() {
  VAR(int, N);
  VEC(int, A, N);
  map<int, int> mp;
  rep(i, 0, N) {
    mp[A[i]]++;
  }
  if (N % 2) {
    if (mp[0] != 1) {
      print(0);
      return;
    }
    mp[0]++;
  }
  each(x, mp) {
    if (x.second != 2) {
      print(0);
      return;
    }
  }
  print(power(2, (N / 2)));
}


Measured memory_bytes: 3584
//#define _GLIBCXX_DEBUG

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

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

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

int main(){
  int N;cin>>N;
  int k=0;
  for (int i=1;i<=N+5;++i){
    if((i*(i-1))/2==N){k=i;break;}
  }
  if(k==0){cout << "No"<< endl;}
  else{
    cout << "Yes" << endl;
    cout << k << endl;

    vi ans[k+1];
    int count=0;
    for (int i=1;i<k;++i){
      for (int j=i+1;j<=k;++j){
        count++;
        ans[i].push_back(count);
        ans[j].push_back(count);
      }
    }

    for (int i=1;i<=k;++i){
      cout << k-1 << ' ';
      for (int j=0;j<k-1;++j){
        cout << ans[i][j] << ' ';
      }
      cout << endl;
    }
  }

  return 0;
}

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

long modPow(long x, long n, long mod);
long nCk(long n, long k, long mod);

int main() {
    const long MOD = 1000000007;
    long n, a, b, ans;
    cin >> n >> a >> b;
    ans = modPow(2, n, MOD) - 1;
    ans -= nCk(n, a, MOD);
    ans -= nCk(n, b, MOD);
    while(ans < 0) ans += MOD;
    cout << ans << endl;
}

long modPow(long x, long n, long mod) {
    long temp = 1;
    while(n > 0) {
        if(n & 1) temp = temp * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return temp;
}

long nCk(long n, long k, long mod) {
    long temp = 1;
    k = min(k, n - k);
    for(int i = 2; i <= k; i++) {
        temp *= i;
        temp %= mod;
    }
    temp = modPow(temp, mod - 2, mod);
    for(int i = n - k + 1; i <= n; i++) {
        temp *= i;
        temp %= mod;
    }
    return temp;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int N,A;
    scanf("%d%d",&N,&A);
    if(N<500)
    {
    if(N>A)
        printf("No");
    else if(N<=A)
        printf("Yes");
    }
    else if(N>=500)
    {
        if(N%500>A)printf("No");
        else
            printf("Yes");
    }
    return 0;
}


Measured memory_bytes: 128
def main():
    N = int(input())
    S = list(input())
    S = list(map(lambda x: 0 if x == "W" else 1, S))

    E = 0
    W = sum(S[1:N])

    p = W
    for i in range(1, N):
        E += 1 - S[i-1]
        W -= S[i]
        ss = E + W
        if ss < p:
            p = ss

    print(p)


main()


Measured memory_bytes: 8268
def main():

    N, M = map(int, input().split())

    cand = {1}
    count = dict()
    for i in range(1, N+1):
        count[i] = 1
    for _ in range(M):
        a, b = map(int, input().split())
        if a in cand:
            cand.add(b)
        if count[a] == 1 and a in cand:
            cand.remove(a)
        count[a] -= 1
        count[b] += 1
    return len(cand)



if __name__ == '__main__':
    print(main())

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

//Data
const int N=2e5;
int n,k,a[N+7];

//Fenwicktree
int c[2][N+7];
void add(int c[],int x,int y){
	for(int i=x;i<=n;i+=i&-i) c[i]+=y;
}
int sum(int c[],int x){
	int y=0;
	for(int i=x;i>=1;i-=i&-i) y+=c[i];
	return y;
}

//Main
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int j=1;j<=k;j++){
		fill(c[j&1]+1,c[j&1]+n+1,0);
		for(int i=1;i<=n;i++)
			add(c[j&1],max(i-a[i],1),1),add(c[j&1],min(i+a[i],n)+1,-1);
		int cnt=0;
		for(int i=1;i<=n;i++){
			a[i]=sum(c[j&1],i);
			if(a[i]==n) cnt++;
		}
		if(cnt==n) break;
	}
	for(int i=1;i<=n;i++) printf("%d ",a[i]);putchar(10);
	return 0;
}

Measured memory_bytes: 5584