akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
template<class T> inline void printb(T a) {
    if(a==0){
        cout << 0 << endl;
        return;
    }
    int cnt = sizeof(T)*8-1;
    bool flg = false;
    while(cnt>=0){
        if(!flg&&a>>cnt&1){
            flg = true;
        }
        if(flg){
            cout << (a>>cnt&1);
        }
        cnt--;
    }
    cout << "\n";
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x,y,z;cin>>n>>x>>y>>z;
    int mask = (1<<x+y+z)-1;
    vector<vector<ll> > dp(n+1,vector<ll>(mask+5,0));
    rep(i,10){
        dp[0][(1<<i)&mask]+=1;
    }
    int checkbit = (1<<z-1) + (1<<z+y-1) + (1<<x+y+z-1); 
    DEBUG{
        printf("checkbit: ");
        printb(checkbit);
        printf("mask: ");
        printb(mask);
    }
    rep(i,n-1){
        rep(j,mask+1){
            rep(k,10){
                int tmp = j;
                tmp<<=1;tmp++;
                tmp<<=k;
                tmp&=mask;
                if((tmp&checkbit) != checkbit){
                    dp[i+1][tmp] += dp[i][j];
                    dp[i+1][tmp] %= MOD;
                }
            }
        }
    }
    ll res = 1;
    rep(i,n){
        res *= 10;
        res %= MOD;
    }
    DEBUG{
        printf("res %lld\n",res);
    }
    rep(i,mask+1){
        res += (MOD-dp[n-1][i]);
        res %= MOD;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 43392
#include<stdio.h>
#include<string.h>

int main(){
  int i,j,k;
  char S[1000000];
  j = k = 0;
  scanf("%s",S);
  
  for(i=0;i<strlen(S);i++){
    if(i%2==0){
      if(S[i]=='0')
        j++;
    }
    else
      if(S[i]=='1')
        j++;
  }
  
  for(i=0;i<strlen(S);i++){
    if(i%2==0){
      if(S[i]=='1')
        k++;
    }
    else
      if(S[i]=='0')
        k++;
  }
  
  
  if(j > k)
    printf("%d\n",k);
  else
    printf("%d\n",j);
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a =  Integer.parseInt(sc.next());
		int b =  Integer.parseInt(sc.next());
		
		if(a > 9 || b > 9) {
			System.out.println(-1);
		}else {
			System.out.println(a*b);
		}
		
		
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 5e3 + 100;
const ll mod = 1e9 + 7;

ll n, m, k, t;

ll C[2];

string s;

ll dp0[maxn][2];

ll dp[maxn][2];

inline ll step(ll a, ll x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return step(a, x - 1) * a % mod;
    }
    ll t = step(a, x / 2);
    return t * t % mod;
}

inline ll del(ll a, ll b) {
    return a * step(b, mod - 2) % mod;
}

void count_dp0() {
    ll q, w, e;
    // dp0[0][0] = dp0[0][1] = 1;
    for (q = 0; q < n; q++) {
        /// last are 0s;
        // dp0[q][0] = 1;
        for (w = C[0]; w <= q; w++) {
            dp0[q][0] += dp0[q - w][1];
            dp0[q][0] %= mod;
        }

        /// last are 1s;
        dp0[q][1] = 1;
        for (w = 1; w <= q; w++) {
            dp0[q][1] += dp0[q - w][0];
            dp0[q][1] %= mod;
        }
    }
}

// set <ll> S;

ll getcnt(ll len, bool f) {
    // if (S.find(len) == S.end()) {
    //     cout << "DP0 " << len << " " << dp0[len - 1][1] << endl;
    // }
    // S.insert(len);
    ll ans = dp0[len - 1][1];
    if (f) {
        ans += dp0[len - 1][0];
    }
    ans %= mod;
    return ans;
}

void count_dp() {
    ll q, w, e;
    for (q = 0; q < n; q++) {
        /// last are 0s;
        if (q + 1 < C[0]) {
            dp[q][0] = 1;
        }
        for (w = 1; w < C[0] && w <= q; w++) {
            dp[q][0] += dp[q - w][1];
            dp[q][0] %= mod;
        }
        /// last are pseudo-1s;
        if (q + 1 < C[1]) {
            dp[q][1] = getcnt(q + 1, 1);
        }
        for (w = 1; w < C[1] && w <= q; w++) {
            dp[q][1] += dp[q - w][0] * getcnt(w, q == (n - 1));
            dp[q][1] %= mod;
        }
    }
}

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c;
    cin >> n >> a >> b;
    if (a > b) {
        swap(a, b);
    }
    C[0] = a;
    C[1] = b;
    count_dp0();
    count_dp();
    // cout << dp[n - 1][0] << " " << dp[n - 1][1] << " DPS" << endl;
    ll cnt_bad = dp[n - 1][0] + dp[n - 1][1];
    // cout << "CNT_BAD " << cnt_bad << endl;
    ll ans = (step(2, n) - cnt_bad % mod + mod) % mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3768
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
p_min = 0
p_max = N
for l, r in LR:
    p_min = max(p_min, l)
    p_max = min(p_max, r)
ret = p_max-p_min+1
if ret < 1:
    ret = 0
print(ret)


Measured memory_bytes: 27332
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <iostream>

class Game {
  size_t n, m;
  std::vector<std::vector<std::vector<int>>> board;
  int turn=0;
  const int black=1, white=-1;

public:
  Game(size_t n, size_t m):
    n(n), m(m), board(n, std::vector<std::vector<int>>(n, std::vector<int>(n)))
  {}

  bool put(size_t x, size_t y) {
    ++turn;
    int cur=(turn%2? black:white);
    size_t z=0;
    for (; z<n; ++z) {
      if (board[x][y][z] == 0) {
        board[x][y][z] = cur;
        break;
      }
    }
    if (z == n) throw 0;
    // put (x, y, z)

    for (size_t k=0; k<3*3*3; ++k) {
      size_t dx=(k%3)-1;
      size_t dy=(k/3%3)-1;
      size_t dz=(k/9%3)-1;

      if (dx == 0 && dy == 0 && dz == 0) continue;

      size_t seq=1;
      for (size_t i=1; true; ++i) {
        size_t nx=x+i*dx, ny=y+i*dy, nz=z+i*dz;
        if (!(nx < n && ny < n && nz < n)) break;
        if (board[nx][ny][nz] != cur) break;
        ++seq;
      }
      for (size_t i=1; true; ++i) {
        size_t nx=x-i*dx, ny=y-i*dy, nz=z-i*dz;
        if (!(nx < n && ny < n && nz < n)) break;
        if (board[nx][ny][nz] != cur) break;
        ++seq;
      }
      if (seq >= m) return true;
    }
    return false;
  }
};

int testcase_ends() {
  size_t n, m, p;
  std::cin >> n >> m >> p;
  if (n == 0) return 1;

  std::vector<size_t> x(p), y(p);
  for (size_t i=0; i<p; ++i) {
    std::cin >> x[i] >> y[i];
    --x[i];
    --y[i];
  }

  Game game(n, m);
  for (size_t i=1; i<=p; ++i) {
    if (game.put(x[i-1], y[i-1])) {
      // true if matched
      printf("%s %zu\n", i%2? "Black":"White", i);
      return 0;
    }
  }
  printf("Draw\n");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int arr[3][3];
    int marked[3][3]={{0,0,0},{0,0,0},{0,0,0}};
    for (int i=0;i<3;i++){
        for (int j=0;j<3;j++){
            cin >> arr[i][j];
        }
    }
    bool bingo = false;
    int n,b;
    cin >> n;
    for(int k=0;k<n;k++){
        cin >> b;
        for (int i=0;i<3;i++){
            for (int j=0;j<3;j++){
                if(arr[i][j]==b){
                    marked[i][j]=1;
                }
            }
        }
    }
    int r=1,c=1;
    if(marked[r][c] == 1){
        if(marked[r+1][c+1] == 1 && marked[r-1][c-1] == 1)
            bingo = true;
        else if(marked[r+1][c-1] == 1 && marked[r-1][c+1] == 1)
            bingo = true;
        else if(marked[r][c-1] == 1 && marked[r][c+1] == 1)
            bingo = true;
        else if(marked[r+1][c] == 1 && marked[r-1][c] == 1)
            bingo = true;
    }
    if(marked[0][0] == 1 &&marked[0][1] == 1&&marked[0][2] == 1)
                bingo = true;
    if(marked[0][0] == 1 &&marked[1][0] == 1&&marked[2][0] == 1)
                bingo = true;
    if(marked[2][0] == 1 &&marked[2][1] == 1&&marked[2][2] == 1)
                bingo = true;
    if(marked[0][2] == 1 &&marked[1][2] == 1&&marked[2][2] == 1)
                bingo = true;

    if(bingo)
    cout << "Yes\n";
    else
    cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
long long a[105];
int main()
{
    int n;scanf("%d",&n);
    a[0]=2;a[1]=1;
    for(int i=2;i<=n;i++) a[i]=a[i-1]+a[i-2];
    printf("%lld\n",a[n]);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
//#include <functional>


int main(){
    int32_t N;
    std::cin >> N;

    std::vector<int64_t> A(N+1);
    //Nive: streamingly calc B-A... order 10^5 x 2. looks ok.
    for(auto& i : A){
        std::cin >> i;
    }
    int64_t sum = 0;
    int64_t Btmp = 0;
    for(int32_t i = 1; i < N + 1; i++){
        std::cin >> Btmp;
        if(A[i-1] < Btmp){
            sum += A[i - 1];
            Btmp -= A[i - 1];
            A[i -1] = 0; //unnecessary
            if(A[i] < Btmp){
                sum += A[i];
                A[i] = 0;
            }
            else{
                sum += Btmp;
                A[i] -= Btmp;
            }
        }
        else{
            sum += Btmp;
            A[i - 1] -= Btmp; //unnecessary
        }
    }
    std::cout << sum;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

int main() {
    int N, u, v; cin >> N >> u >> v; --u, --v;
    vector<vector<int>>G(N);
    rep(i, N - 1) {
        int a, b; cin >> a >> b;--a, --b;
        G[a].pb(b);
        G[b].pb(a);
    }
    vector<int> distAoki(N, INF), distTakahashi(N, INF);
    distAoki[v] = 0, distTakahashi[u] = 0;
    queue<int> Q;
    Q.push(v);
    while(!Q.empty()) {
        int q = Q.front(); Q.pop();
        for(int next : G[q]) {
            if(distAoki[next] == INF) Q.push(next), distAoki[next] = distAoki[q] + 1;
        }
    }
    Q.push(u);
    while(!Q.empty()) {
        int q = Q.front(); Q.pop();
        for(int next : G[q]) {
            if(distTakahashi[next] == INF) Q.push(next), distTakahashi[next] = distTakahashi[q] + 1;
        }
    }
    int maxv = 0;
    rep(i, N) {
        if(distAoki[i] > distTakahashi[i])
            maxv = max(distAoki[i] - 1, maxv);
    }
    cout << maxv << endl;
}


Measured memory_bytes: 6656
#include <iostream>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

void solve()
{
	string str;
	while(cin >> str)
	{
		if(str == "0000")
		{
			break;
		}
		else if(atoi(str.c_str()) % 1111 == 0)
		{
			cout << "NA" << endl;
			continue;
		}
		int count = 0;
		while(str != "6174")
		{
			sort(str.begin(), str.end());
			string small = str;
			string large;
			for(int i = str.size() - 1; i >= 0; --i)
			{
				large += str[i];
			}
			int num = atoi(large.c_str()) - atoi(small.c_str());
			stringstream ss;
			ss << num;
			str = ss.str();
			if(str.size() < 4)
			{
				string buffer = str;
				str.clear();
				for(int i = 0; i < 4 - buffer.size(); ++i)
				{
					str += "0";
				}
				str += buffer;
			}
			++count;
		}
		cout << count << endl;
	}
}

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

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

ll powmod(ll a, ll k, ll m) {
  if (k == 0) return 1;
  ll t = powmod(a, k / 2, m);
  t = (t * t) % mod;
  if (k % 2 == 1) t = (t * a) % mod;
  return t;
}

int vis[1 << 17];
long pre[1 << 17];

int main() {
  ll n;
  ll x, m;
  cin >> n >> x >> m;
  map<ll, int> mp;
  vector<ll> val;
  int idx = 0;
  auto it = mp.end();
  ll idxsum = 0;
  while ((it = mp.find(x)) == mp.end() && n > 0) {
    val.push_back(x);
    mp[x] = idx++;
    idxsum += x;
    x = (x * x) % m;
    n--;
  }
  if (n == 0) {
    cout << idxsum << endl;
    return 0;
  }
  int loop = idx - it->second;
  //n -= idx;
  ll loopsum = 0;
  for (int i = it->second; i < idx; i++) {
    loopsum += val[i];
  }
  ll mult = n / loop;
  n -= loop * mult;
  ll modsum = 0;
  for (int i = it->second; --n >= 0; i++) {
    modsum += val[i];
  }

  ll ans = idxsum + loopsum * mult + modsum;
  cout << ans << endl;

  return 0;
}


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

#define mod 1000000007
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define deb(x) cout<<"\n"<<#x<<"="<<x<<"\n";
#define deb2(x,y) cout<<"\n"<<#x<<"="<<x<<"\n"<<#y<<"="<<y<<"\n";
#define ideb int _p_;cin>>_p_;
typedef long long int ll;
typedef unsigned long long int ull;
long long power(long long x,long long n){long long result=1;while(n>0){if(n % 2 ==1)result=(result * x);x=(x*x);n=n/2;}return result;}

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

ll ans=n-1;
 
for(ll i=2;i<=sqrt(n);i++)
{
    if(n%i==0)
    {
        ans=min(ans,n/i+i-2);
    }
}
cout<<ans;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P=pair<int64_t,int64_t>;

vector<int64_t> ds(vector<int64_t>dis,vector<vector<pair<int64_t,int64_t>>> g,int start,int goal){
    int n=dis.size();
    priority_queue<pair<int64_t,int64_t>,vector<pair<int64_t,int64_t>>,greater<pair<int64_t,int64_t>>> Q;
    dis[start]=0;
    Q.push(make_pair(0,start));

    while(!Q.empty()){
        int pos=Q.top().second;Q.pop();
        for(int i=0;i<g.at(pos).size();i++){
            int to=g.at(pos).at(i).first;
            int cost=g.at(pos).at(i).second;
            if(dis[to]==-1 || dis[to]>dis[pos]+cost){
                dis[to]=dis[pos]+cost;
                Q.push(make_pair(dis[to],to));
            }
        }
    }
    return dis;
}

int main(){
    string s;
    cin>>s;
    cout<<s.substr(0,3)<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int n,a,b;
     cin>>n>>a>>b;
     cout<<min(n*a,b)<<endl;
     time();
     return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN,"%s",$str);
$result = "";
for($i=0; $i <strlen($str); $i++)
{
    if($str[$i] == 'B')
    {
        $result = substr($result, 0, strlen($result)-1);
    }
    else
    {
        $result .= $str[$i];
    }
}

echo($result);

Measured memory_bytes: 3828
#include <stdio.h>
#include <stdlib.h>


int main()
{   int N,i,j=0;

scanf("%d",&N);
for(i=0;i<N;i++)
{int p[N];
  scanf("%d",&p[i]);
  {
   if(p[i]!=i+1)
   {
       j++;
   }
  }


}if(j>2)
  {
    printf("NO\n");
  }
else
  {
    printf("YES\n");
  }


    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d", &n);
    vector<long long> fib;
    fib.push_back(1);
    fib.push_back(1);
    for(int i = 2; i < 45; i++){
        long long val = fib.at(i - 1) + fib.at(i - 2);
        fib.push_back(val);
    }
    cout << fib.at(n) << endl;
}


Measured memory_bytes: 3216
#include<stdio.h>

int main(void)
{
  int w, n, i, a, b, temp;
  int ww[31];
  
  scanf("%d",&w);
  scanf("%d",&n);
  for(i=0;i<w;i++)
    {
      ww[i] = i + 1;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d,%d",&a,&b);
      a--;
      b--;
      temp = ww[a];
      ww[a] = ww[b];
      ww[b] = temp;
    }
  for(i=0;i<w;i++)
    {
      printf("%d\n",ww[i]);
    }
  return 0;
}

Measured memory_bytes: 596
def main():
	a, b = [int(x) for x in input().split(' ')]
	# a, b = 1, 1
	if b % a == 0:
		print(a + b)
	else:
		print(b - a)

if __name__ == '__main__':
	main()


# If 
# A
#  is a divisor of 
# B
# , print 
# A
# +
# B
# ; otherwise, print 
# B
# −
# A
# .



Measured memory_bytes: 2940
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    int x;
    scanf("%d", &x);
    int ans = 0;
    ans += (x / 500 * 1000);
    x %= 500;
    ans += (x / 5 * 5);
    printf("%d\n", ans);
}


Measured memory_bytes: 128
//Intersection Determination
#include<bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;    // 許容誤差。問題によって変える
typedef complex<double> P;  // Point
#define X real()
#define Y imag()
double norm(P &p1, P &p2){
    return (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y);
}
namespace std{
    bool operator<(const P p1, const P p2){
        return p1.X != p2.X ? p1.X < p2.X : p1.Y < p2.Y;
    }
    P operator+(const P p1, const P p2) { return P(p1.X + p2.X, p1.Y + p2.Y); }
    P operator-(const P p1, const P p2) { return P(p1.X - p2.X, p1.Y - p2.Y); }
    P operator*(const P p, double k) { return P(p.X * k, p.Y * k); }
    P operator/(const P p, double k) { return P(p.X / k, p.Y / k); }
} 

//Segment/Line
struct Segment{
    P p1, p2;
    Segment() {}
    Segment(P p1, P p2) : p1(p1), p2(p2) {}
};
typedef Segment Line;

//外積cross(a,b) = |a||b|sinθ=a1b2+a2b1
double cross(const P &a, const P &b){
    return (conj(a) * b).Y;
}
//内積dot(a,b) = |a||b|cosθ=a1b1+a2b2
double dot(const P &a, const P &b){
    return (conj(a) * b).X;
}

//位置関係判定(線分abを軸にcがどちら側にあるか)
int ccw(P a, P b, P c){
    b -= a;
    c -= a; //aからの向きを考える
    if (cross(b, c) > EPS)
        return +1; //clockwise
    else if (cross(b, c) < -EPS)
        return -1; //counter clockwise
    else if (dot(b, c) < -EPS)
        return +2; //c-a-b
    else if (norm(b) < norm(c))
        return -2; //a-b-c
    else
        return 0; //他
}

//Intersection Determination
bool intersectLL(const Line &l, const Line &m){
    return abs(cross(l.p2 - l.p1, m.p2 - m.p1)) > EPS; // && // non-parallel
                                                       //    abs(cross(l.p2 - l.p1, m.p1 - l.p1))  < EPS;   // same line
}
bool intersectLS(const Line &l, const Line &s){
    return cross(l.p2 - l.p1, s.p1 - l.p1) * // s.p1 is left of l
               cross(l.p2 - l.p1, s.p2 - l.p1) <EPS; // s.p2 is right of l
}
bool intersectLP(const Line &l, const P &p){
    return abs(cross(l.p2 - p, l.p1 - p)) < EPS;
}
bool intersectSS(const Line &s, const Line &t){
    return ccw(s.p1, s.p2, t.p1) * ccw(s.p1, s.p2, t.p2) <= 0 &&
           ccw(t.p1, t.p2, s.p1) * ccw(t.p1, t.p2, s.p2) <= 0;
}
bool intersectSP(const Line &s, const P &p){
    return abs(s.p1 - p) + abs(s.p2 - p) - abs(s.p2 - s.p1) < EPS; // triangle inequality
}

//Verify
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A&lang=jp
int main(){
    int q;
    cin>>q;
    for (int i = 0; i < q;i++){
        double x0,x1,x2,x3,y0,y1,y2,y3;
        cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
        P p0 = P(x0, y0), p1 = P(x1, y1), p2 = P(x2, y2), p3 = P(x3, y3);
        const Line l1 = Line(p0, p1), l2 = Line(p2, p3);
        if (!intersectLL(l1, l2) )
            cout << "2" << endl;
        else if(dot(l1.p2-l1.p1,l2.p2-l2.p1)==0)
            cout << "1" << endl;
        else
            cout << "0" << endl;
    }
    return 0;
}



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

int IsMiddle(int a,int b,int c) 
{
	int ret = 0;
	if(((a<b)&&(b<c))||((a>b)&&(b>c)))
	{
		ret = 1;
	}
	else
	{
		ret = 0;
	}
	return ret;
}

int main()
{
	int n,count=0,i;
	cin>>n;
	int p[21];
	
	for(i=0;i<n;i++)
	{
		cin>>p[i];	
	} 	
	
	for(i = 0;i<n-2;i++)
	{
		count += IsMiddle(p[i],p[i+1],p[i+2]);
	}
	cout<<count;
}

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

int main()
{
  long N, T;
  cin >> N >> T;
  long t[200005] = {};
  for (int n = 1; n <= N; n++)
  {
    cin >> t[n];
  }
  
  long total_time = T * N;
  for (int i = 2; i <= N; i++)
  {
    long dt = t[i] - t[i - 1];
    total_time -= max(T - dt, (long)0);
  }
  
  cout << total_time << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#define N 100

int bubbleSort(int *, int);

int main(){
  int i, n, A[N], count;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);

  count = bubbleSort(A, n);

  for(i=0; i<n; i++){
    printf("%d", A[i]);
    if(i == n-1)printf("\n");
    else printf(" ");
  }
  printf("%d\n", count);

  return 0;
}

int bubbleSort(int *A, int n){
  int i, a, count=0, flag=1;

  while(flag){
    flag = 0;
    for(i=n-1; i>0; i--){
      if(A[i] < A[i-1]){
	a = A[i];
	A[i] = A[i-1];
	A[i-1] = a;
	flag = 1;
	count++;
      }
    }
  }

  return count;
}



Measured memory_bytes: 2036
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<math.h>
#include<climits>
#include<set>
#define debug(x) cout <<#x<<" = "<<x<<endl
#define debug2(x, y) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<endl
#define gg cout <<"---------------QAQ---------------"<<endl
#define rep(i,n) for(int i=1;i<=n;i++)
#define fi first
#define SZ(x) (int)x.size()
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, ll> Pii;
template<class T> inline void read(T &x){
    x=0; char c=getchar(); int f=1;
    while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
    while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 2e5+10, maxn = 1e6+5;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}
const ll mod =  998244353 ;

int n, m, ans;
int a, b, c, d;

void solve()
{
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int f = 0;
    while(1)
    {
        f ^= 1;
        if(a<=0) {puts("No"); return ;}
        if(c<=0) {puts("Yes"); return ;}
        if(f) c-=b;
        else a-=d;
    }
}


int main()
{
//    int _; scanf("%d", &_); while(_--)
//    while(~scanf("%d", &n))
//    while(scanf("%d", &n)&&n)
    solve();
    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int h,a;
    cin>>h>>a;
    cout<<(h+a-1)/a<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();

		boolean[] color = new boolean[8];
		int pro = 0;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			for (int j = 0; j < color.length; j++) {
				if (a < (j + 1) * 400) {
					color[j] = true;
					break;
				}
			}
			if (3200 <= a) {
				pro++;
			}
		}

		int count = 0;
		for (int i = 0; i < color.length; i++) {
			if (color[i]) {
				count++;
			}
		}

		out.println(Math.max(count, 1) + " " + (count + pro));
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

}

Measured memory_bytes: 21204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		int idx = partition(a, 0, a.length - 1);
		StringBuilder sb = new StringBuilder();
		if (idx == 0) {
			sb.append("[");
		}
		sb.append(a[0]);
		if (idx == 0) {
			sb.append("]");
		}
		for (int i = 1; i < n; i++) {
			sb.append(' ');
			if (idx == i) {
				sb.append("[");
			}
			sb.append(a[i]);
			if (idx == i) {
				sb.append("]");
			}
		}
		System.out.println(sb.toString());
	}

	private static int partition(int[] a, int p, int r) {
		int x = a[r];
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (a[j] <= x) {
				i++;
				swap(a, i, j);
			}
		}
		swap(a, i + 1, r);
		return i + 1;
	}
	
	private static void swap(int[] a, int i, int j) {
		int temp = a[i];
		a[i] = a[j];
		a[j] = temp;
	}
}


Measured memory_bytes: 38972
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

def renketu(Town):
    cnt = 0
    for i in range(1,len(Town.par)):
        for j in range(1,i):
            if not Town.same_check(i,j):
                return True
    return False

if __name__ == '__main__':
    N,M = list(map(int,input().split()))
    # print(Town.par)
    bridge = [list(map(int,input().split())) for i in range(M)]
    cnt = 0
    for kesu in range(M):
        Town = UnionFind(N)
        for i,(x,y) in enumerate(bridge):
            if i != kesu:
                Town.union(x,y)
        if renketu(Town):
            cnt += 1
    print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INT long long
#define oo 987654321
using namespace std;
 
int main()
{
	ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s.size() < 4) return cout<<"No"<<endl, 0;
    if( s.substr(0,4) == "YAKI" ) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
A = list(map(int, input().split()))

flag = True
if N%2 == 0:
    if 0 in A or len(set(A)) != N//2:
        flag = False
else:
    if len([0 for a in A if a == 0]) != 1 or len(set(A)) != N//2 + 1:
        flag = False

if  flag:
    print(2**(math.floor(N/2))%(10**9+7))
else:
    print(0)


Measured memory_bytes: 20468
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;

int main(){
    int r,d,x;cin>>r>>d>>x;
    rep(i,0,10){
        x = x*r-d;
        cout<<x<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    set<int>ans;
    for (int i = 0; i < K; i++) {
        if(A+i<=B)ans.insert(A + i);
    }
    for (int i = 0; i < K; i++) {
        if (B-i>=A)ans.insert(B - i);
    }

    for (auto itr = ans.begin(); itr != ans.end(); itr++)cout << *itr << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int dis[1001];
int e[1001][1001];
bool bfs(int s)
{
	memset(dis,0,sizeof(dis));
	queue<int>q;
	q.push(s);
	dis[s]=1;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int i=1;i<=n;i++)
			if(e[u][i])
			{
				if(!dis[i])
				{
					dis[i]=dis[u]+1;
					q.push(i);
				}
				else if(abs(dis[i]-dis[u])!=1)
					return false;
			}
	}
	return true;
}
signed main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			scanf("%1d",&e[i][j]);
		}
	int ans=-1;
	for(int i=1;i<=n;i++)
	{
		if(bfs(i))
			for(int j=1;j<=n;j++)
				ans=max(ans,dis[j]);
	}
	printf("%d",ans);
	return 0;
}
/*
aqsqqsqqwww
10
*/

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){
    ll n;
    cin>>n;
    ll ans=0;
    f(i,1,n+1){
      if(i%3!=0&&i%5!=0&&i%15!=0){
          ans+=i;
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CIN(int, K);

    cout << (N-K+1) << "\n";
    return 0;
}

Measured memory_bytes: 256
import math

def main():
    max_len = 10 ** 5 + 1
    sosuu_hantei = [0 for i in range(max_len)]

    for i in range(2, max_len):
        flg = 1
        for j in range(int(i ** 0.5) + 1):
            if sosuu_hantei[j]:
                if i % j == 0:
                    flg = 0
                    break
        if flg:
            sosuu_hantei[i] = 1

    # print(sosuu_hantei[:10])

    for i in range(max_len)[::-1]:
        if sosuu_hantei[i] == 0:
            continue
        if sosuu_hantei[(i + 1) // 2]:
            pass
        else:
            sosuu_hantei[i] = 0

    # print(sosuu_hantei[:10])

    now_count = 0
    for i in range(max_len):
        if sosuu_hantei[i]:
            now_count += 1
        sosuu_hantei[i] = now_count

    # print(sosuu_hantei[:10])

    num = int(input())
    for i in range(num):
        a, b = map(int, input().split())
        print(sosuu_hantei[b] - sosuu_hantei[a - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 4376
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int N;
  cin >> N;

  string S;
  map<string,int>m;
  for (int i = 0; i < N; i++) {
    cin >> S;
    m[S] = 1;
  }

  int ans = 0;

  for(auto i = m.begin(); i != m.end(); i++) {
    ans += i->second;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 19220
/*input
x
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=500005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
string s,t;

int main()
{
	IOS;
	cin>>s;
	REP(i,SZ(s)) if(s[i]!='x')t.pb(s[i]);

	{
		string rev=t;
		reverse(ALL(rev));
		if(rev!=t){
			cout<<"-1\n";
			return 0;
		}
	}
	s="c"+s;
	s.pb('c');

	int l=0;
	vector<int> v;
	REP(i,SZ(s)) if(i){
		if(s[i]!='x'){
			v.pb(i-l-1);
			l=i;
		}
	}
	int ans=0;
	for(int i=0,j=SZ(v)-1;i<j;i++,j--){
		ans+=abs(v[i]-v[j]);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1260
package main
import(
  "fmt"
)
func main(){
  var n, i int
  ans:=0
  con:=1
  fmt.Scan(&n)
  a:=make([]int, n)
  for i=0;i<n;i++{
    fmt.Scan(&a[i])
  }
  for i=0;i<n;i++{
    if con==a[i]{
      ans++
      con++
    }
  }
  if ans==0{
    fmt.Println(-1)
  }else{
    fmt.Println(n-ans)
  }
}


Measured memory_bytes: 6912
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

r, c, k = LI()
maze = [[0] * (c+1) for _ in range(r+1)]
for _ in range(k):
    R, C, V = LI()
    maze[R][C] = V

dp1 = [[0] * (c+1) for _ in range(r+1)]
dp2 = [[0] * (c+1) for _ in range(r+1)]
dp3 = [[0] * (c+1) for _ in range(r+1)]

for i in range(1, r+1):
    for j in range(1, c+1):
        dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + maze[i][j], dp2[i-1][j] + maze[i][j], dp3[i-1][j] + maze[i][j])
        dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1] + maze[i][j])
        dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1] + maze[i][j])
ans = max(dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)

Measured memory_bytes: 359408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    ll x,sum=0;
    cin >>x;
    int p5=x%500;
    sum+= (p5/5)*5;
    sum+= (x/500)*1000;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
namespace VainZero.Procon.FSharp

open System
open System.Collections.Generic

[<AutoOpen>]
module Operators =
  let read f = Console.ReadLine().Split([|' '|]) |> Array.map f

module Program =
  [<EntryPoint>]
  let main _ =
    let [|n; a; b|] = read int64
    let n = int n
    let hs =
      [|
        for _ in 0..(n - 1) ->
          Console.ReadLine() |> int64
      |]

    let calc () =
      let isOk k =
        // i 番目の敵を中心に xs.[i] 回攻撃するとする。
        // 敵を全滅させなければいけないので、すべての敵 i について、
        // hs.[i] <= (敵 i に与えるダメージ) = (a - b) * xs.[i] + b * k
        // が成り立つ必要がある。これが各 xs.[i] の下限を定める。
        // また、k 回の攻撃で全滅させなければいけないので、xs の総和は k 以下でなければいけない。
        let xs =
          [|
            for i in 0..(n - 1) ->
              (hs.[i] - b * k + (a - b - 1L)) / (a - b) |> max 0L
          |]
        Array.sum xs <= k

      // [めぐる式2分探索](https://twitter.com/meguru_comp/status/697008509376835584)
      let rec loop ok ng =
        if abs (ok - ng) <= 1L then
          ok
        else
          let k = (ok + ng) / 2L
          if isOk k then
            loop k ng
          else
            loop ok k
      loop (Array.max hs) 0L

    printfn "%d" (calc ())

    0


Measured memory_bytes: 35588
#include <stdio.h>

#define MAX 10000

void initary( long long int num[MAX] )
{
	for ( int i = 0 ; i < MAX ; i++ ) {
		num[i] = 0;
	}
	return;
}

void sort( long long int num[MAX], int n )
{
	long long int tmp;
	for ( int i = 0 ; i < n ; i++ ) {
		for ( int j = i+1 ; j < n ; j++ ) {
			if ( num[i] > num[j] ) {
				tmp = num[i];
				num[i] = num[j];
				num[j] = tmp;
			}
		}
	}
	return;
}
int main()
{
	int n = 0, i = 0;
	long long int ans, sagyou[MAX] = {}, mati[MAX] = {};

	while ( scanf( "%d", &n ) == 1 ) {
		if ( n == 0 ) { break; }
	
		initary( sagyou );
		initary( mati );
		for ( i = 0 ; i < n ; i++ ) {
			scanf( "%lld", &sagyou[i] );
		}

		sort( sagyou, n );

		ans = 0;
		// 各人の待ち時間を計算する
		for ( i = 0 ; i < n ; i++ ) {
			mati[i] = ans;
			ans += sagyou[i];
		}
		ans = 0;
		for ( i = 0 ; i < n ; i++ ) {
			ans += mati[i];
		}
		printf( "%lld\n", ans );
	}
	return 0;
}



Measured memory_bytes: 2108
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    h, n = LI()
    a = LI()
    print("Yes" if h <= sum(a) else "No")
    return


#main
if __name__ == '__main__':
    solve()


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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       s.find(x) != s.end()

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
ll a[SZ];
//ll b[SZ];



int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
    //    ll a, b, d;
    string s, s1, s2;

    cin2(n, k);
    for1(i, n) cin1(a[i]);

    sort(a+1, a+n+1);

    for1(i, k) c += a[i];

    cot1(c);

    return 0;
}



Measured memory_bytes: 3656
/**
 * File              : A - Bulletin Board.cpp
 * Author            : horcrux2301 <khajuriaharsh729@gmail.com>
 * Date              : 12.01.2019 17:34:07
 * Last Modified Date: 12.01.2019 17:34:54
 */
#include <bits/stdc++.h>
#define ll long long
#define mp(a, b) make_pair(a, b)
#define newline cout << endl;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p)
{
    out << '(' << p.ff << ", " << p.ss << ')';
    return out;
}

template <typename T> ostream& operator<<(ostream& out, vector<T> const& v)
{
    int l = v.size();
    for (int i = 0; i < l - 1; i++)
        out << v[i] << ' ';
    if (l > 0)
        out << v[l - 1];
    return out;
}

template <typename T> void trace(const char* name, T&& arg1) { cout << name << " : " << arg1 << endl; }

template <typename T, typename... Args> void trace(const char* names, T&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    trace(comma + 1, args...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    clock_t tStart = clock();
    int test;
    test = 1;
    // cin >> test;
    while (test--) {
        ll a, b, c;
        cin >> a >> b >> c;
        ll ans = 0;
        ans = (a - b + 1) * (a - c + 1);
        cout << ans << endl;
    }
#ifdef LOCAL_DEFINE
    printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
#endif
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3

from collections import defaultdict


def main():
    #Read stdin

    fl = input().split(" ")
    V = int(fl[0])
    E = int(fl[1])
    R = int(fl[2])
    #Adjacency list
    G = defaultdict(list)
    for i in range(int(E)):
        s, t, w = [int(x) for x in input().split(" ")]
        G[s].append((t,w))
    #initialized
    d = {}
    INF = float('inf')
    #INF = 10001
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = [R]
    while q:
        u = q.pop(0)
        for v in G[u]:
            if d[v[0]] > d[u] + v[1]:
                d[v[0]] = d[u] + v[1]

                q.append(v[0])

    for k in range(V):
        if d[k] == float('inf'):
            
            print("INF")
        else:
            print(d[k])



if __name__ == '__main__':
    main()

Measured memory_bytes: 106856
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int n, mx;
string s;
map<string, int> mp;
int main() {
	cin >> n;
	while(n--) {
		cin >> s;
		mp[s]++;
		mx = max(mx, mp[s]);
	}
	for(auto x:mp) {
		if(x.second==mx) cout << x.first << endl;
	}
	return 0;

}

Measured memory_bytes: 25216
import sys

def test(N):
    answer = 0
    for i in range(1, 10**N):
        s = ("%0" + str(N) +"d") % i
        if "0" in s and "9" in s:
            #print(s)
            answer += 1
    return answer

def solve(N):
    MOD = 10**9+7
    dp = [[0, 0, 0, 0] for i in range(N+1)]
    dp[0] = [1, 0, 0, 0]
    A = 0
    B = 1
    C = 2
    D = 3
    for i in range(1, N+1):
        # 0 
        dp[i][A] = (dp[i-1][A]*8) % MOD
        dp[i][B] = (dp[i-1][A]   + dp[i-1][B]*9) % MOD
        dp[i][C] = (dp[i-1][A]   + dp[i-1][C]*9) % MOD
        dp[i][D] = (dp[i-1][B]   + dp[i-1][C]    + dp[i-1][D]*10) % MOD
        #print(i, dp[i], sum(dp[i]))
    return dp[N][D]

N = int(input())
print(solve(N))


Measured memory_bytes: 239088