akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b; cin >> a >> b;
    int ans = lcm(a,b);
    ANS;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2020/7/5 19:54
# @Version : 1.1
# @Author  : Jade
# @File    : b.py
# @Software: PyCharm
#

def main():
    n = int(input())
    ac,wa,tle,re = 0,0,0,0
    for _ in range(n):
        text = input()
        if text == 'AC':
            ac += 1
        elif text == 'WA':
            wa += 1
        elif text == 'TLE':
            tle += 1
        else:
            re += 1
    print("AC x %d"%ac)
    print("WA x %d"%wa)
    print("TLE x %d"%tle)
    print("RE x %d"%re)



if __name__ == '__main__':
    main()

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

int main(){
    string s; cin >> s;
    int n = s.size();
    for(int i = 0; i < n; i++)
        if(s[i] == '?') s[i] = 'D';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ans=0;

    for(int i=1;i<=n;i++)
    {
        if(i<10 or i>99 and i<1000 or i>9999 and i<100000 or i>999999)
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    exit(0);
}


Measured memory_bytes: 3592
#pragma comment(linker,"/STACK:1024000000,1024000000")
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define ios ios::sync_with_stdio(false)
#define ll long long
#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define of(i,a,b) for(int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof a)
#define uint unsigned int
#define vr vector<int>
#define pi acos(-1)

const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll N = 1e7 + 10;



int main()
{
	int n;
	sc(n);
	int k;
	sc(k);
	int ans = 0;
	while (n--)
	{
		int x;
		sc(x);
		if (x >= k)
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
using namespace std;
const int MAXN = 100005;
int a[MAXN];
void init()
{
    for(int y =  1;y<=MAXN-5;y++)
    {
        a[y] = y;
    }
}
int Find(int fa)
{
    if(fa==a[fa])
    {
        return a[fa];
    }
    else
    {
        return a[fa] = Find(a[fa]);
    }
}
int main()
{
    init();
    int n;
    int m;
    cin>>n>>m;
    int i = 0;
    for(int y = 1;y<=m;y++)
    {
        int l;int r;
        cin>>l>>r;
        int fa1 = Find(l);
        int fa2 = Find(r);
        if(fa1==fa2)
        {
            continue;
        }
        else
        {
            a[fa1] = fa2;
            i++;
        }
    }
    cout<<n-1-i<<endl;
    return 0;
}


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

using namespace std;

int main(void)
{
    int num1,num2;
    char c;
    scanf("%d %c %d",&num1,&c,&num2);
    if(c=='+')printf("%d\n",num1+num2);
    else printf("%d\n",num1-num2);
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vl a(3 * n); REP(i, 3 * n) cin >> a[i];

	vl max_sum(3 * n, -1);
	{
		priority_queue<ll, vector<ll>, greater<ll>> q;
		ll cur_sum = 0;
		REP(i, 3 * n) {
			cur_sum += a[i];
			q.push(a[i]);
			if (q.size() == n + 1) {
				cur_sum -= q.top();
				q.pop();
			}
			if (q.size() == n) {
				max_sum[i] = cur_sum;
			}
		}
	}

	vl min_sum(3 * n, -1);
	{
		priority_queue<ll> q;
		ll cur_sum = 0;
		for(ll i = 3 * n - 1; i >= 0; --i) {
			cur_sum += a[i];
			q.push(a[i]);
			if (q.size() == n + 1) {
				cur_sum -= q.top();
				q.pop();
			}
			if (q.size() == n) {
				min_sum[i] = cur_sum;
			}
		}
	}

	ll ans = -TEN(15);
	REP(i, 3 * n - 1) {
		if (min_sum[i + 1] == -1 || max_sum[i] == -1) continue;
		ans = max(ans, max_sum[i] - min_sum[i + 1]);
	}

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


Measured memory_bytes: 9072
#include <iostream>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
int main(){
  int kazu[100001];
  rep(i,100001)kazu[i] = 0;
  int N;cin>>N;
  int a[N];
  int kekka = 0;
  rep(i,N){
    cin >> a[i];
    if(a[i] <= 100000)kazu[a[i]]++;
    else kekka++;
  }
  rep(i,100001){
    if(kazu[i] > i)kekka+=kazu[i]-i;
    else if(kazu[i] < i)kekka+=kazu[i];
  }
  cout << kekka << endl;

}

Measured memory_bytes: 1024
#定数入力
#2≦n≦10^5
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = input()

#計算
ans = 0
for i in range(n):  #O(n)
    #k回前の手は出せないことを考慮
    if i >= k:  #k回から手の制限あり
        #k回前が同じ手かどうか
        if T[i] == T[i-k]:
            #T[i]をfに書き換え
            T = T[:i] + 'f' + T[i+1:]
        else:
            pass
    else:   #0~k-1回までは手の制限なし
        pass
    #i回目のじゃんけんの点数を加算
    if T[i] == 'r': 
        ans += p
    elif T[i] == 's':
        ans += r
    elif T[i] == 'p':
        ans += s
    elif T[i] == 'f':   #手が被るので今回は勝つのをあきらめる
        pass
    else:
        pass    #void

#答えの出力
print(ans)
    



Measured memory_bytes: 3452
import math
h, w = map(int,input().split())
hw = h * w
r = hw

for i in range(math.floor(h / 3), math.ceil(h / 3) + 1):
    r1 = w * i
    for i1 in range(math.floor((h-i) / 2), math.ceil((h-i) / 2) + 1):
        r2 = i1 * w
        r3 = hw - r1 - r2
        if r3 == 0:
            pass
        
        r = r if (max(r1,r2,r3) - min(r1,r2,r3)) > r else (max(r1,r2,r3) - min(r1,r2,r3))

    for i2 in range(math.floor(w / 2), math.ceil(w / 2) + 1):
        r2 = i2 * (h - i)
        r3 = hw - r1 - r2
        if r3 == 0:
            pass
        r = r if (max(r1, r2, r3) - min(r1, r2, r3)) > r else (max(r1, r2, r3) - min(r1, r2, r3))

for j in range(math.floor(w / 3), math.ceil(w / 3) + 1):
    r1 = h * j
    for j1 in range(math.floor((w-j) / 2), math.ceil((w-j) / 2) + 1):
        r2 = j1 * h
        r3 = hw - r1 - r2
        if r3 == 0:
            pass
        r = r if (max(r1,r2,r3) - min(r1,r2,r3)) > r else (max(r1,r2,r3) - min(r1,r2,r3))
    for j2 in range(math.floor(h / 2), math.ceil(h / 2) + 1):
        r2 = j2 * (w - j)
        r3 = hw - r1 - r2
        if r3 == 0:
            pass
        r = r if (max(r1, r2, r3) - min(r1, r2, r3)) > r else (max(r1, r2, r3) - min(r1, r2, r3))

print(r)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    ll n, w;
    cin >> n >> w;
    vector<pair<ll, ll>> wv(n);
    ll sumv = 0;
    rep(i, n) {
        cin >> wv[i].first >> wv[i].second;
        sumv += wv[i].second;
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(sumv + 1, inf));
    dp[0][0] = 0;
    ll ans = 0;
    rep(i, n) {
        rep(j, sumv + 1) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if ((j < wv[i].second) || (dp[i][j - wv[i].second] == inf)) continue;
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - wv[i].second] + wv[i].first);
            if (dp[i + 1][j] <= w) ans = max(ans, j);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 80256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

struct edge{int to, cost;};


vector<edge> G[1000];
pii dfs(int prev, int v){
    pii ret = pii(0,v);
    
    for(auto elm:G[v]){
        if(elm.to==prev)continue;
        if(G[elm.to].size()==1)continue;
        pii tmp = dfs(v, elm.to);
        tmp.first += elm.cost;
        if(tmp.first>ret.first){
            ret = tmp;
        }
    }
    return ret;
}

int main(){
    int n;
    while(cin>>n&&n){
        rep(i,1000)G[i].clear();
        
        vector<int> p(n-1), d(n-1);
        rep(i,n-1)cin>>p[i];
        rep(i,n-1)cin>>d[i];
        
        rep(i,n-1){
            G[p[i]-1].pb(edge{(int)i+1,d[i]});
            G[i+1].pb(edge{p[i]-1,d[i]});
        }
        
        pii d1 = dfs(-1,0);
        pii d2 = dfs(-1,d1.second);
        
        int edge_sum = accumulate(all(d),0);
        int leave_edge_cost_sum = 0;
        rep(i,n){
            if(G[i].size()==1)leave_edge_cost_sum+=G[i][0].cost;
        }
        cout<<edge_sum + 2*(edge_sum-leave_edge_cost_sum) - d2.first<<endl;
    }
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	while(cin >> s) {
		int a[2]; a[0] = a[1] = 0;
		for(int i = 0; i < 3; i++) {
			a[s[i] - 'A']++;
		}
		string ans = "Yes";
		// cout << a[0] << " " << a[1] << endl;
		// cout << abs(a[0] - a[1]) << endl;
		if(abs(a[0] - a[1]) == 3) ans = "No";
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      _t: usize,
      mut a: [usize; n]
   }

   let mut mn = a[0];
   a[0] = 0;
   for i in 1..n {
      if a[i] > mn {
         a[i] -= mn;
      } else {
         mn = a[i];
         a[i] = 0;
      }
   }
   a.sort();
   let mut ans = 1;
   for i in (0..n - 1).rev() {
      if a[i] == a[n - 1] {
         ans += 1;
         continue;
      }
      break;
   }
   println!("{}", ans);
}


Measured memory_bytes: 4204
import java.util.*;
public class Main  {
   public static void main(String[] args) throws java.lang.Exception  {
      Scanner sc = new Scanner(System.in);
      
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();
      int e = sc.nextInt();
      int f = sc.nextInt();
      int g = sc.nextInt();
      int h = sc.nextInt();
      int i = sc.nextInt();
      
      int n = sc.nextInt();
      
      int array[] = {a, b, c, d, e, f, g, h, i};
      
      int x = 0;
      
      for (int j = 0; j < n; j++) {
         x = sc.nextInt();
         if (a == x) {
            array[0] = 101;
         }else if (b == x) {
            array[1] = 101;
         }else if (c == x) {
            array[2] = 101;
         }else if (d == x) {
            array[3] = 101;
         }else if (e == x) {
            array[4] = 101;
         }else if (f == x) {
            array[5] = 101;
         }else if (g == x) {
            array[6] = 101;
         }else if (h == x) {
            array[7] = 101;
         }else if (i == x) {
            array[8] = 101;      
         }
      }
      
      if (array[0] == array[1] && array[1] == array[2]) {
         System.out.println("Yes");
      } else if (array[3] == array[4] && array[4] == array[5]) {
         System.out.println("Yes");
      } else if (array[6] == array[7] && array[7] == array[8]) {
         System.out.println("Yes");
      } else if (array[0] == array[3] && array[3] == array[6]) {
         System.out.println("Yes");
      } else if (array[1] == array[4] && array[4] == array[7]) {
         System.out.println("Yes");
      } else if (array[2] == array[5] && array[5] == array[8]) {
         System.out.println("Yes");
      } else if (array[0] == array[4] && array[4] == array[8]) {
         System.out.println("Yes");
      } else if (array[2] == array[4] && array[4] == array[6]) {
         System.out.println("Yes");
      } else {
         System.out.println("No");
      }
      
   }  
}


Measured memory_bytes: 21972
#include<stdio.h>

void insertion(int N,int a[]);

int main(void){
  int N,s;
  scanf("%d",&N);
  if(1<=N||N<=100){
    int a[N];
    for(s=0;s<N;s++){
      scanf("%d",&a[s]);
      printf("%d",a[s]);
      s==N-1?printf("\n"):printf(" ");
    }
    insertion(N,a);
  }
  return 0;
}

void insertion(int N,int a[]){
  int i,j,k,key;
  for(i=1;i<N;i++){
    key=a[i];
    j=i-1;
    while(j>=0&&a[j]>key){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=key;
    for(k=0;k<N-1;k++){
      printf("%d ",a[k]);
    }
    printf("%d\n",a[N-1]);
  }
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    int a,b,c; cin>>a>>b>>c;
    int ans = max(0, c-(a-b));
    OUT(ans);
}


Measured memory_bytes: 256
s="abcdefghij"
n=int(input())
ans=["a"]
for i in range(2,n+1):
    temp=[]
    lookup=s[:i]
    for j in ans:
        for k in lookup:
            temp.append(j+k)
            if k not in j:
                break
    ans=temp
for i in ans:
    print(i)

Measured memory_bytes: 12936
# ARC086_B Non Decreasing
def nonDecreasing(N, A):
    Amin = min(A)
    Amax = max(A)
    Amin_index = A.index(Amin)+1
    Amax_index = A.index(Amax)+1

    res = []

    # 右をどんどん増やしていく
    # Amaxは正の数のはず
    if abs(Amax) > abs(Amin):
        for i in range(1, N):
            while A[i - 1] > A[i]:
                A[i] += Amax
                res.append((Amax_index, i+1))
                if A[i] > Amax:
                    Amax = A[i]
                    Amax_index = i+1

    # 左をどんどん減らしていく
    # Aminは負の数のはず
    else:
        for i in range(N - 1, 0, -1):
            while A[i - 1] > A[i]:
                A[i - 1] += Amin
                res.append((Amin_index, i))
                if A[i - 1] < Amin:
                    Amin = A[i - 1]
                    Amin_index = i
    return res


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = nonDecreasing(N, A)

    print(len(ans))
    for a in ans:
        print(*a)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"

ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}
ll lcm(ll a, ll b) {
  return a*b/gcd(a,b);
}

int main() {
  ll a,b,c;
  cin >> a >> b >> c;
  bool flag=false;
  int k=1;
  while(k<=b) {
    if((k*a)%b == c) {
      flag=true;
      break;
    }
    k++;
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main(){
  long long A,B,K; cin >> A >> B >> K;
  if(A > K)
    cout << A - K << " " << B <<endl;
  else if(A + B > K)
    cout << 0 << " " << B - (K - A) << endl;
  else
    cout << "0 0" << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
/*********ANISH***********ANISH*************ANISH***********ANISH******/
#define pb push_back
#define ll long long
#define ff first
#define ss second
ll max(ll a,ll b)
{
    if(a>b) return a;
    return b;
}
ll min(ll a,ll b)
{
    if(a<b) return a;
    return b;
}
/********ANISH************ANISH*************ANISH**********ANISH*********/
int n,m,a,b;
vector<int> adj[100010];
int dp[100010];
int dfs(int curr)
{
    int ans=0;
    if(dp[curr]!=-1) return dp[curr];
    for(int i:adj[curr])
    {
        ans=max(ans,1+dfs(i));
    }
    return dp[curr]=ans;
}
int main()
{
    int t;
    t=1;
    while(t--)
    {
        cin>>n>>m;
        for(int i=0;i<m;++i)
        {
           cin>>a>>b;
           adj[a].pb(b);
        }
        int ans=0;
        memset(dp,-1,sizeof(dp));
        for(int i=1;i<=n;++i)
        {
            ans=max(ans,dfs(i));
        }
        cout<<ans;
    }
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
main()
{
    char a[4];
    while(scanf("%s",&a)==1){
        if(0==strcmp(a,"SUN"))
            printf("7\n");
        else if(0==strcmp(a,"MON"))
            printf("6\n");
        else if(0==strcmp(a,"TUE"))
            printf("5\n");
        else if(0==strcmp(a,"WED"))
            printf("4\n");
        else if(0==strcmp(a,"THU"))
            printf("3\n");
        else if(0==strcmp(a,"FRI"))
            printf("2\n");
        else if(0==strcmp(a,"SAT"))
            printf("1\n");
    }
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <functional>

const int INF = 1001001000;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

typedef pair<int,int> P;

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

char c[60][60];
int f[60][60];
int sy,sx,gy,gx;
int h,w;
queue< pair<int,int> > q;

int main(){

  int x,y;
  pair< int, int > p;
  int black = 0;
  int white = 0;
  sy = 0;
  sx = 0;

  cin >> h >> w;
  gy = h-1;
  gx = w-1;
  for( int i = 0; i < h; ++i){
    for( int j= 0; j < w; ++j){
      cin >> c[i][j];
      if( c[i][j] == '#'){
        ++black;
      }
    }
  }
  white = h*w - black;


  fill( f[0], f[60], -1);

  q.push( make_pair( sy, sx));
  f[sy][sx] = 0;

  while( !q.empty()){
    p = q.front();
    q.pop();
    for( int i = 0; i < 4; ++i){
      y = p.first+dy[i];
      x = p.second+dx[i];
      if( c[y][x] == '.' && f[y][x] == -1){
        f[y][x] = f[p.first][p.second]+1;
        q.push( make_pair( y, x));
      }
    }
  }

  if( f[gy][gx] == -1){
    cout << f[gy][gx] << endl;
  }else{
    cout << white-f[gy][gx]-1 << endl;
  }


}


Measured memory_bytes: 256
program ABC171B
    implicit none
    integer(8)::N,K,i,ans=0
    integer(8),allocatable::P(:)
    read*,N,K
    allocate(P(N))
    read*,P
    call heapsort(N,P)
    do i=1,K
        ans=ans+P(i)
    end do
    print'(i0)',ans
end program ABC171B

subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
end subroutine heapsort

Measured memory_bytes: 2868
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

int gcd(int a, int b){return (a % b)? gcd(b, a % b) : b;}
int lcm(int a, int b){return a * b / gcd(a, b);}

void solve_A(){
    int s, w;
    cin >> s >> w;

    cout << (w<s? "safe":"unsafe") << endl;
}

void solve_B(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            break;
        }
    }
}

void solve_C(){
    
}

int main(void){
    solve_B();
    
    return 0;
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int H,W,N; cin >> H >> W >> N;
	int sr,sc; cin >> sr >> sc;
	string S; cin >> S;
	string T; cin >> T;

	int minr = 1, maxr = H+1, minc = 1, maxc = W+1;
	repm(i,N-1,-1){
		if(T[i] == 'L') maxc = min(maxc+1,W+1);
		if(T[i] == 'R') minc = max(minc-1,1);
		if(T[i] == 'U') maxr = min(maxr+1,H+1);
		if(T[i] == 'D') minr = max(minr-1,1);
		if(S[i] == 'L') ++minc;
		if(S[i] == 'R') --maxc;
		if(S[i] == 'U') ++minr;
		if(S[i] == 'D') --maxr;
		if(minc == maxc || minr == maxr) return cout << "NO" << endl, 0;
	}
	cout << ((minr<=sr&&sr<maxr&&minc<=sc&&sc<maxc)?"YES":"NO") << endl;
	return 0;
}


Measured memory_bytes: 776
n=int(input())
t=0
h=0
for i in range(n):
    taro,hana=map(str,input().split())
    if taro>hana:
        t+=3
    elif hana>taro:
        h+=3
    else:
        h+=1
        t+=1
print("%s %d"%(t,h))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  double n;
  cin >> n;
  if((int)n%2==0)cout<<0.5<<endl;
  else cout << fixed << setprecision(10) << (double)((n+1)/2)/(n) << endl;
  return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define MOD (LL)pow(10,9) + 7


int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    string l,r;
    bool flag = false;
    for(int i = 0; i < q; ++i){
        int t;
        cin >> t;
        if(t == 1){
            swap(l,r);
            flag = !flag;
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 1){
                l += c;
            }else{
                r += c;
            }
        }
    }

    if(flag)reverse(s.begin(),s.end());

    reverse(s.begin(),s.end());
    s += l;
    reverse(s.begin(),s.end());
    s += r;

    cout << s << endl;

    return 0;
}



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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	vector<int> alp(26, 0);

	int n = s.size();

	rep(i, n){
		int c = s[i] - 'a';
		if(alp[c] > 0){
			cout << "no" << endl;
			return 0;
		}
		
		alp[c]++;
	}

	cout << "yes" << endl;	
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a,b;
    do
    {
    scanf("%d %d",&a,&b);
    if(a==0 && b ==0)
    {
        break;
    }
    int i,j;
    for (i=a;i>0;i--)
    {
        for (j = b;j>0;j--)
        {
            printf("#");
        }
        //printf("%d",a);
        printf("\n");
    }
    printf("\n");
    }while(1);
    return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}





int main(){

  ll N;
  cin >> N;
  ll sum = 0;
  ll ans = 0;
  FOR(i,0,N){
    ll a;
    cin >> a;
    ans += sum*a;
    sum += a;
    ans %= MOD;
    sum %= MOD;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3560
#include <iostream>
#include <array>

using namespace std;

int main()
{
    int n = 10;
    int i = 0, j = 0;
    array<int, 10> arr;
    
    for (int i = 0; i < 10; i++)
    {
        cin >> arr[i];
    }
    
    for (i = 0; i < n - 1; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if (arr[i] < arr[j])
            {
                swap(arr[i], arr[j]);
            }
        }
    }
    
    for (i = 0; i < 3; i++)
    {
        cout << arr[i] << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3056
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      char[] s = sc.next().toCharArray();
      char[] t = sc.next().toCharArray();
      for(int i=0;i<n;i++){
        System.out.print(s[i]);
        System.out.print(t[i]);
      }
      System.out.println("");
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}
class Pair{
    int a,b;

    Pair(int a, int b){
      this.a = a;
      this.b = b;
    }
}

Measured memory_bytes: 21840
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

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

	int n;
	cin >> n;

	double ans;
	if (n & 1) {
		int t = n / 2;
		++t;
		ans = double(t) / n;
	}
	else {
		ans = 0.5;
	}

	cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define N 1000000007
using namespace std;
ll dp[301][301][301],n,k,h[400];

ll func(ll i, ll k, ll j)
{
    if(i == n+1)
        return 0;
    if(dp[i][k][j] != -1)
        return dp[i][k][j];

    dp[i][k][j] = max(0ll, h[i]-h[j]) + func(i+1,k,i);
    if(k > 0)
        dp[i][k][j] = min(dp[i][k][j], func(i+1, k-1,j));
    return dp[i][k][j];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll i,j,l;
    cin>>n>>k;
    for(i=1;i<=n;i++)
        cin>>h[i];
    h[0] = 0;
    for(i=0;i<=n;i++)
        for(j=0;j<=k;j++)
            for(l=0;l<=n;l++)
                dp[i][j][l] = -1;
    cout<<func(1,k,0);
    return 0;
}

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

class point {
private:
  std::int_fast64_t m_x;
  std::int_fast64_t m_y;

public:
  constexpr point() noexcept :
    point(0, 0) {
  }
  constexpr point(const std::int_fast64_t x, const std::int_fast64_t y) noexcept :
    m_x(x),
    m_y(y) {
  }

  constexpr std::int_fast64_t x() const noexcept {
    return this->m_x;
  }
  constexpr std::int_fast64_t y() const noexcept {
    return this->m_y;
  }

  friend std::istream& operator>>(std::istream& is, point& self) {
    return is >> self.m_x >> self.m_y;
  }
};

int main() {
  std::int_fast64_t n, threshold;
  std::cin >> n >> threshold;
  std::vector<point> points;
  points.reserve(n);
  std::copy_n(std::istream_iterator<point>(std::cin), n, std::back_inserter(points));

  std::vector<std::int_fast64_t> possible_xs;
  std::vector<std::int_fast64_t> possible_ys;
  {
    std::unordered_set<std::int_fast64_t> possible_x_set;
    std::unordered_set<std::int_fast64_t> possible_y_set;
    for (const point& point : points) {
      possible_x_set.insert(point.x());
      possible_y_set.insert(point.y());
    }
    std::copy(possible_x_set.begin(), possible_x_set.end(), std::back_inserter(possible_xs));
    std::copy(possible_y_set.begin(), possible_y_set.end(), std::back_inserter(possible_ys));
  }
  std::sort(possible_xs.begin(), possible_xs.end());
  std::sort(possible_ys.begin(), possible_ys.end());
  const std::int_fast64_t possible_x_count = possible_xs.size();
  const std::int_fast64_t possible_y_count = possible_ys.size();

  std::vector<std::vector<std::int_fast64_t>> cumsum(possible_x_count + 1, std::vector<std::int_fast64_t>(possible_y_count + 1, 0));
  for (std::int_fast64_t i = 0; i < possible_x_count; ++i) {
    const std::int_fast64_t possible_x = possible_xs[i];
    for (std::int_fast64_t j = 0; j < possible_y_count; ++j) {
      const std::int_fast64_t possible_y = possible_ys[j];
      cumsum[i][j] = std::count_if(points.begin(), points.end(), [&possible_x, &possible_y](const point& point) {
        return possible_x <= point.x() && possible_y <= point.y();
      });
    }
  }

  std::int_fast64_t answer = std::numeric_limits<std::int_fast64_t>::max();
  for (std::int_fast64_t i = 0; i < possible_x_count; ++i) {
    const std::int_fast64_t left = possible_xs[i];
    for (std::int_fast64_t j = i + 1; j < possible_x_count; ++j) {
      const std::int_fast64_t right = possible_xs[j];
      for (std::int_fast64_t k = 0; k < possible_y_count; ++k) {
        const std::int_fast64_t bottom = possible_ys[k];
        for (std::int_fast64_t l = k + 1; l < possible_y_count; ++l) {
          const std::int_fast64_t top = possible_ys[l];
          const std::int_fast64_t included_point_count = cumsum[i][k] - cumsum[i][l + 1] - cumsum[j + 1][k] + cumsum[j + 1][l + 1];
          if (included_point_count >= threshold) {
            answer = std::min(answer, (right - left) * (top - bottom));
          }
        }
      }
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int N;
string S;

int main(){
  cin >> N >> S;
  int E[N] = {}, W[N] = {};
  int cnt = 0;
  for (int i = 0; i < N; ++i){
    W[i] = cnt;
    if (S[i] == 'W'){
      cnt++;
    }
  }
  cnt = 0;
  for (int i = N-1; i >= 0; i--){
    E[i] = cnt;
    if (S[i] == 'E'){
      cnt++;
    }
  }
  int Min = N;
  for (int i = 0; i < N; ++i){
    Min = min(Min, E[i] + W[i]);
  }
  cout << Min << endl;
  return 0;
}

Measured memory_bytes: 3076
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
from collections import deque
#======================================================#
def main():
    n = II()
    aa = MII()
    aa.sort(reverse=True)
    dq = deque(aa)
    dq_p = deque()

    total = 0
    total += dq.popleft()
    next_point = dq.popleft()
    dq_p.append(next_point)
    dq_p.append(next_point)

    while dq:
        d = dq.popleft()
        dq_p.append(d)
        dq_p.append(d)
        total += dq_p.popleft()
    print(total)


if __name__ == '__main__':
    main()

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

using namespace std;

#define MAX 2020

int n;
int m;

vector<int> v[MAX];

vector<int> g[MAX];

vector<pair<int, int> > ed;

queue<tuple<int, int, int> > q;

set<pair<int, int> > s;

bitset<MAX> con[MAX];

bitset<MAX>  child[MAX];
bitset<MAX> par[MAX];

bitset<MAX> stk;

inline void dfs(int b, int pr = -1) {
	auto &c = child[b];
	c.set(b, 1);
	for (int go : v[b]) {
		if (go == pr)continue;
		dfs(go, b);
		c |= child[go];
	}
}

int pat[MAX][MAX];
int lca[MAX][MAX];

int dep[MAX];


inline void dfs2(int b, int pr = -1, int star = 0) {
	pat[star][b] = pr;
	lca[star][b] = b;
	if (pr != -1) {
		if (lca[star][pr] != -1) {
			if (dep[lca[star][pr]] < dep[b]) {
				lca[star][b] = lca[star][pr];
			}
		}
	}
	for (int go : v[b]) {
		if (go == pr)continue;
		dfs2(go, b, star);
	}
}
inline void dfs3(int b, int pr = -1, int d = 0) {
	stk.set(b, 1);
	par[b] = stk;
	dep[b] = d;
	for (int go : v[b]) {
		if (go == pr)continue;
		dfs3(go, b, d + 1);
	}
	stk.set(b, 0);
}
bitset<MAX> ff;
int main() {
	cin >> n >> m;
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs3(0);
	dfs(0);
	for (int i = 0; i < n; i++) {
		dfs2(i, -1, i);
	}
	int edd = 0;
	for (int i = 0; i < m; i++) {
		int c, d;
		scanf("%d%d", &c, &d);
		c--;
		d--;
		g[c].push_back(d);
		g[d].push_back(c);
		ed.push_back(make_pair(c, d));
		con[c].set(d, 1);
		con[d].set(c, 1);
		q.push(make_tuple(0, c, d));
		edd++;
	}
	bitset<MAX> full;
	for (int i = 0; i < n; i++) {
		full.set(i);
	}
	while (!q.empty()) {
		int centre, lef, rig;
		tie(centre, lef, rig) = q.front();
		q.pop();
		int A = lef;
		int B = rig;
		ff.reset();
		if (lca[A][B] == B) {
			swap(A, B);
		}
		if (lca[A][B] == A) {
			ff = child[B] ^ full^child[pat[B][A]] ^ par[B] ^ par[A];
		}
		else {
			ff = child[B] ^ child[A] ^ par[A] ^ par[B];
			ff.set(lca[A][B]);
		}
		ff &= con[A] ^ con[B];
		//the node unconnected to node B
		//connected to A
		//the node is available at the pair(A,B)
		for (int i = (int)ff._Find_first(); i < n&&i>=0; i = (int)ff._Find_next(i)) {
			if (i == A || i == B)continue;
			if (con[B].test(i)) {
				swap(A, B);
			}
			if (con[B].test(i)) {
				return 1;
			}
			q.push(make_tuple(A, i, B));
			con[i].set(B);
			con[B].set(i);
			edd++;
		}
	}
	cout << edd << endl;
	return 0;
}

Measured memory_bytes: 58164
from itertools import permutations

n,cn = map(int,input().split())
d = [list(map(int,input().split())) for _ in range(cn)]
c = [list(map(int,input().split())) for _ in range(n)]

col_count = [[0] * cn for _ in range(3)]
for i in range(n):
    for j in range(n):
        col_count[(i+j+2)%3][c[i][j]-1] += 1

ans = 1000*n*n
for c123 in permutations(range(cn),3):
    dsum = 0
    for i in range(3):
        for j in range(cn):
            dsum += d[j][c123[i]] * col_count[i][j]
    ans = min(ans,dsum)
print(ans)

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

int main(){
	char a, b;
	cin >> a >> b;

	if(a == 'H'){
		if(b == 'H')
			cout << "H\n";
		else 
			cout << "D\n";
	}else{
		if(b == 'H')
			cout << "D\n";
		else 
			cout << "H\n";
	}

	return 0;
}
		

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


using namespace std;
int incalc(int a)
{
    long long int d=0;
    long long int i = 0;
    for(i = 1;i <= sqrt(a); i++)
    {
        if(a % i == 0)
        {
            d = d + 1;
        }
    }
  //  cout<<d;
    if(d > 1)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}
int main()
{
    long long int n=0;
    cin>>n;
    while(1)
    {
        if(incalc(n))
        {
            break;
        }
        n=n+1;
    }
    cout<<n;
}

Measured memory_bytes: 256
n = int(input())
cnt = 0


def gcd(a,b,c):
    while b != 0:
        a, b = b, a % b
    while c != 0:
        a, c = c, a % c
    return a


# for i in range(1,n+1):
#     for j in range(i, n+1):
#         for k in range(j, n+1):
#             if i == j and j == k:
#                 cnt += gcd(i,j,k)
#             elif i == j or j == k or k == i:
#                 cnt += gcd(i, j, k)*3
#             else:
#                 cnt += gcd(i, j, k)*6
# print(cnt)
for i in range(1,n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            cnt += gcd(i,j,k)
print(cnt)




Measured memory_bytes: 68268
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func ni() (val int64) {
	sc.Scan()
	val, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}

func main() {
	sc.Split(bufio.ScanWords)

	n := ni()
	var sum int64
	prev := (int64)(0)
	for i := (int64)(0); i < n; i++ {
		a := ni()
		if prev == 1 && a > 1 {
			sum++
			a--
		}
		sum += a / 2
		a %= 2
		prev = a
	}
	fmt.Println(sum)
}


Measured memory_bytes: 2304
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

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


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
  int x;
  cin>>x;
  sieve(1000000);
  ll ans = x;
  while(IsPrime[ans]==false){
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}



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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 200;
int n;
string s[N];
int col[N];

void nope() {
    cout << -1 << endl;
    exit(0);
}

int bfs(int start) {
    int ret = -1;
    queue<int> q;
    q.emplace(start);
    col[start] = 1;
    while(!q.empty()) {
        int cur = q.front(); q.pop();
        int color = col[cur];
        ret = max(ret, color);

        for(int child = 0; child < n; ++child) {
            if(s[cur][child] == '0') continue;
            if(col[child] == 0) {
                q.emplace(child);
                col[child] = color+1;
            } else if(col[child] != color+1 && col[child] != color-1) {
                return -1;
            }
        }
    }
    return ret;
}

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n; ++i) cin >> s[i];

    int ans =-1;
    for(int i = 0; i < n; ++i) {
        for(int i = 0; i < n; ++i) col[i] = 0;
        int cand = bfs(i);
        ans = max(ans, cand);
    }

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


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h)cin >> s[i];
  rep(i,h)cout << s[i] << endl << s[i] << endl;




  return 0;
}

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

public class Main
{
	public static void main(String[] args)throws IOException
    {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int size = Integer.parseInt(br.readLine());
      int[] arr = new int[size];
      double sum=0.0;
      StringTokenizer tokenizer1 = new StringTokenizer(br.readLine());
      int j=0;
      while(tokenizer1.hasMoreTokens())
      {
        arr[j] = Integer.parseInt(tokenizer1.nextToken());
        j++;
      }
      double num = 0.0;
      for(int i=0;i<size;i++)
      {
        num = (double)arr[i];
        sum += (1.0/num);
      }
      double ans = 1/sum;
      System.out.println(ans);
    }
}


Measured memory_bytes: 21204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ABC126_E
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NM[0];
            var M = NM[1];

            var U = new UnionFind(N);
            for (int i = 0; i < M; i++)
            {
                var XYZ = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var X = XYZ[0];
                var Y = XYZ[1];
                var Z = XYZ[2];

                U.TryUnite(X - 1, Y - 1);
            }

            Console.WriteLine(U.GroupCount);
        }

        class UnionFind
        {
            public int Size { get; private set; }
            public int GroupCount { get; private set; }
            List<int> Sizes;
            List<int> Parent;
            public UnionFind(int count)
            {
                Size = 0;
                GroupCount = 0;
                Parent = new List<int>(count);
                Sizes = new List<int>(count);
                ExtendSize(count);
            }
            public bool TryUnite(int x, int y)
            {
                int xp = Find(x);
                int yp = Find(y);
                if (yp == xp) return false;
                if (Sizes[xp] < Sizes[yp])
                {
                    var tmp = xp;
                    xp = yp;
                    yp = tmp;
                }
                GroupCount--;
                Parent[yp] = xp;
                Sizes[xp] += Sizes[yp];
                return true;
            }
            public IEnumerable<int> AllRepresents => Parent.Where(x => x == Parent[x]);
            public int GetSize(int x) => Sizes[Find(x)];
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public int Find(int x)
            {
                while (x != Parent[x])
                {
                    Parent[x] = Parent[Parent[x]];
                    x = Parent[x];
                }
                return x;
            }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public void ExtendSize(int treeSize)
            {
                if (treeSize <= Size) return;
                Parent.Capacity = treeSize;
                Sizes.Capacity = treeSize;
                while (Size < treeSize)
                {
                    Parent.Add(Size);
                    Sizes.Add(1);
                    Size++;
                    GroupCount++;
                }
            }
        }
    }


    }


Measured memory_bytes: 18016
//2020.1.18
//s1270188 xxxmk2
//alds1_06d

#include<stdio.h>
#define N 1000
#define MAX 10000

//prototype
int partition(int,int);
void q_sort(int,int);
int cnt(void);

//global
int data[N], B[N], num, min=MAX; 

int main(){
  int i;

  //input
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&data[i]);
    if(min>data[i]) min=data[i];
  }
  
  //output
  printf("%d\n",cnt());
  
  return 0;
}

int cnt(void){
  int cnt=0;
  int V[N], T[MAX];
  int i, cur, S, m, an, v;
  int a, b;

  for(i=0;i<num;i++){
    B[i]=data[i];
    V[i]=0;
  }

  q_sort(0,num-1);

  for(i=0;i<num;i++) T[B[i]]=i;
  
  for(i=0;i<num;i++){
    if(V[i]==1) continue;
    
    cur=i;
    S=an=0;
    m=MAX;
    while(1){
      V[cur]=1;
      an++;
      v=data[cur];
      if(v<m) m=v;
      S+=v;
      cur=T[v];
      if(V[cur]) break;
    }
    a=S+(an-2)*m;
    b=m+S+(an+1)*min;
    if(a<b) cnt+=a;
    else cnt+=b;
  }

  return cnt;
}



int partition(int l,int r){
  int i, j, tmp;

  for(i=l-1,j=l;j<r;j++){
    if(B[j]<=B[r]){
      i++;
      tmp=B[i];
      B[i]=B[j];
      B[j]=tmp;
    }
  }
  tmp=B[i+1];
  B[i+1]=B[r];
  B[r]=tmp;
  
  return i+1;
}
  
void q_sort(int l,int r){
  int m;
  if(l<r){
    m=partition(l,r);
    q_sort(l,m-1);
    q_sort(m+1,r);
  }
}



Measured memory_bytes: 2112