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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int MOD = 1e9 + 7;
void add(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
  if (x < 0) x += MOD;
}
int mul(int a, int b) {
  return (a * 1LL * b) % MOD;
}
int bp(int a, ll n) {
  int res = 1;
  while (n) {
    if (n & 1)
      res = mul(res, a);
    a = mul(a, a); n >>= 1;
  }
  return res;
}

const int N = 1e5 + 10;

struct AHO {
  struct vertex {
    int next[11];
    int p;
    int pch;
    int link;
    bool leaf;
    int go[11];
  };

  vertex t[N];
  int sz;

  void init() {
    t[0].p = t[0].link = -1;
    memset(t[0].next, -1, sizeof t[0].next);
    memset(t[0].go, -1, sizeof t[0].go);
    sz = 1;
  }

  void addString(vector<int> s) {
    int v = 0;
    for (auto x : s) {
      if (t[v].next[x] == -1) {
        memset(t[sz].next, -1, sizeof t[sz].next);
        memset(t[sz].go, -1, sizeof t[sz].go);
        t[sz].p = v;
        t[sz].link = -1;
        t[sz].pch = x;
        t[v].next[x] = sz++;
      }
      v = t[v].next[x];
    }
    t[v].leaf = 1;
  }

  int getLink(int v) {
    if (t[v].link == -1) {
      if (v == 0 || t[v].p == 0)
          t[v].link = 0;
      else
          t[v].link = go(getLink(t[v].p), t[v].pch);
    }
    return t[v].link;
  }

  int go(int v, int c) {
    if (t[v].go[c] == -1) {
      if (t[v].next[c] != -1)
          t[v].go[c] = t[v].next[c];
      else
          t[v].go[c] = v == 0 ? 0 : go(getLink(v), c);
    }
    return t[v].go[c];
  }
} aho;

vector<int> path;
int X, Y, Z;
int dp[41][N];

void rec(int pos = 0, int sum = 0) {
  if (pos == 3) {
    aho.addString(path);
    return;
  }
  int need = (pos == 0 ? X : pos == 1 ? Y : Z);
  for (int v = 1; v + sum <= need && v <= 10; v++) {
    int nsum = sum + v;
    path.push_back(v);
    if (nsum == need) {
      rec(pos + 1, 0);
    }
    else {
      rec(pos, nsum);
    }
    path.pop_back();
  }
}

void solve() {
  aho.init();
  int n; cin >> n >> X >> Y >> Z;
  rec();
  dp[0][0] = 1;
  for (int len = 1; len <= n; len++) {
    for (int v = 0; v < aho.sz; v++) {
      for (int dig = 1; dig <= 10; dig++) {
        int nv = aho.go(v, dig);
        //cout << v << " " << dig << " " << nv << endl;
        if (aho.t[nv].leaf)
          continue;
        add(dp[len][nv], dp[len - 1][v]);
      }
    }
  }
  int ans = bp(10, n);
  for (int v = 0; v < aho.sz; v++) {
    add(ans, -dp[n][v]);
  }
  cout << ans;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


Measured memory_bytes: 12404
#include <iostream>
#include <vector>
using namespace std;
struct edge { int to, num; };

vector<edge>g[50];
int n, m, ans = 0;
bool used[50];

void search(int a, int num) {
	used[a] = true;
	//cout << "現在頂点" << a << "にいる" << endl;
	for (int i = 0; i < g[a].size(); i++) {
		if (g[a][i].num != num && !used[g[a][i].to]) {
			//cout << "g[a][i].num" << g[a][i].num << " num:" << num  << endl;
			search(g[a][i].to, num);
		}
	}
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		g[a - 1].push_back(edge{ b - 1, i });
		g[b - 1].push_back(edge{ a - 1, i });
	}

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++)used[j] = false;

		//cout << i << "本目" << endl;
		search(0, i);

		bool flag = false;
		for (int j = 0; j < n; j++)if (!used[j])flag = true;

		if (flag) {
			//cout << "橋である" << endl;
			ans++;
		}
		else {
			//cout << "橋でない" << endl;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  string S;
  cin >> S;
  ll ans = 0;
  REP(i, S.size() - 1) {
    if (S[i] != S[i + 1]) {
      ans += 2;
      S.erase(i, 2);
      
      i -= 1;
      if (-1 < i) i--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int x, y;
    cin >> x >> y;
    cout << x + y / 2;
    return 0;
}

Measured memory_bytes: 256
import sys
N, K = map(int, input().split())
if N == 1:
    print(1)
    sys.exit()
S = input()
cnt = [0]
flag = False
for c in S:
    if c == '0':
        if flag:
            cnt.append(cnt[-1])
        else:
            flag = True
            cnt.append(cnt[-1] + 1)
    else:
        cnt.append(cnt[-1])
        flag = False
ans = 0
left, right = 0, 0
while right < N:    # right を右端まで移動させる
    while right < N:
        right += 1
        # print('right was +1. left = {}, right = {}'.format(left, right))
        if right < N:
            if S[right - 1] == '1' and S[right] == '0':
                # print('right is correct')
                break
        else:
            break
    if cnt[right] - cnt[left] <= K:
        ans = max(ans, right - left)
        # print('cnt[right] - cnt[left] = {}'.format(cnt[right] - cnt[left]))
        # print('    left - right = {}'.format(right - left))
    else:
        # print('too long')
        while left < N:
            left += 1
            # print('left was +1. left = {}, right = {}'.format(left, right))
            if S[left - 1] == '0' and S[left] == '1':
                # print('left is correct')
                break
        if cnt[right] - cnt[left] <= K:
            ans = max(ans, right - left)
            # print('cnt[right] - cnt[left] = {}'.format(cnt[right] - cnt[left]))
            # print('    left - right = {}'.format(right - left))
print(ans)

Measured memory_bytes: 5624
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

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

const ll INF=1LL << 60;

ll xs[100005];

ll gcd(ll x,ll y){
  if(!(x%y))return y;
  else return gcd(y,x%y);
}

int main() {
  ll n,x;cin >> n >> x;
  rep(i,n) cin >> xs[i];
  vector<ll> diff;
  rep(i,n){
    diff.pb((ll)abs(xs[i]-x));
  }
  sort(ALL(diff));
  ll ans= diff.front();
  for(int i=1;i<n-1;i++)ans=gcd(ans,diff[i]);

  cout << ans;
}

Measured memory_bytes: 2168
/*
ABC169-D
正の整数が与えられます。Nに対して、以下の操作を繰り返す。
・はじめに、以下の条件をすべて満たす正の整数zを選ぶ
　・ある素数pと正の整数eを用いて、z=p^eと表せる
　・Nがzで割り切れる
　・以前の操作で選んだどの整数とも異なる
・NをN/zに置き換える
最大で何回操作を行うことができるか。
制約
1<=N<=10^12
方針

*/

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}


int main(){
    ll n; cin >> n;
    // 素因数分解
    vector<pair<ll, ll>> p = prime_factorize(n);
    ll ans = 0;

    rep(i,p.size()){
        int count = 0;
        // 乗数を1とする。
        //int mul = 1;
        while (p[i].second - (count+1) >= 0){
            count++;
            p[i].second -= count;
            //mul += (count+1);
        }
        ans += count;
    }

    cout << ans << endl;

}


Measured memory_bytes: 3628
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var TA = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var T = TA[0];
            var A = TA[1];
            var HList = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var output = -1;
            var diff = (double)int.MaxValue;
            for (var i = 0; i < N; i++)
            {
                var d = Math.Abs(A - (T - HList[i] * 0.006));
                if (diff > d)
                {
                    diff = d;
                    output = i + 1;
                }
            }

            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 13332
MOD = 10**9+7
N = int(input())
C = [int(input()) for i in range(N)]

dp = [0 for i in range(N)]
dp[0] = 1

color = {}
for c in C:
    color[c] = 0
color[C[0]] = 1

for i in range(1,N):
    dp[i] = dp[i-1]
    if C[i-1] != C[i]:
        dp[i] = (dp[i] + color[C[i]])%MOD
    color[C[i]] = dp[i]
print(dp[-1])

Measured memory_bytes: 30988
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

const ll INF = 10e6;

int dp[100010];

int h[100010];

int main() {
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		dp[i] = INF;
	}
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			dp[i] = 0;
			continue;
		}
		if (i == 1) {
			dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
			continue;
		}
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[N - 1] << endl;


	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
	int n, f[100000][2];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> f[i][0] >> f[i][1];
	}
	for (int i = n + 1; i >= 2; i--){
		int friends = 0;
		for (int j = 0; j < n; j++){
			if (f[j][0] <= i && f[j][1] >= i){
				friends++;
			}
		}
		if (friends >= i - 1){
			cout << i - 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1940
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        double debt = 100000.0;
        int nWeeks = new Scanner(System.in).nextInt();
        for(int i = 0; i < nWeeks; i++) {
            debt = ((int)(debt * 0.00105 + 0.99)) * 1000.0;
        }
        System.out.println((int)debt);

    }
} 

Measured memory_bytes: 17160
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b;
    rrep(i,a,b+1){
        s=to_string(i);
        int ok=1;
        rep(j,Size(s)/2){
            if(s[j]!=s[Size(s)-j-1]){
                ok=0;
                break;
            }
        }
        if(ok)ans++;
    }
    Cout(ans);
    return 0;
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	if (a <= b)
	{
		for (int i = 0; i < b; i++)
		{
			cout << a;
		}
	}
	else
	{

		for (int i = 0; i < a; i++)
		{
			cout << b;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import bisect
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


H, W, N = list(map(int, sys.stdin.buffer.readline().split()))
XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

blocked = set()
blocks = [[] for _ in range(W + 1)]
for h, w in sorted(XY):
    blocked.add((h, w))
    blocks[w].append(h)
for w in range(W + 1):
    blocks[w].append(H + 1)

# 高橋くんは毎回動く
# 青木くんが動く回数を決めたとき、先に動けるだけ動くとする
# 後から動いたほうがいい場合はもっと動く回数を少なくできるので
h, w = 1, 1
hist = []
while True:
    hist.append((h, w))
    if h + 1 <= H and (h + 1, w) not in blocked:
        h += 1
    else:
        break
    if w + 1 <= W and (h, w + 1) not in blocked:
        w += 1

ans = INF
for h, w in hist:
    hi = bisect.bisect_left(blocks[w], h + 1)
    ans = min(ans, blocks[w][hi] - 1)
    # print(h, w, blocks[w])
print(ans)


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

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

constexpr int INF = 2000000000;
constexpr ll LLINF = 9000000000000000000;

template<typename F>	// All subsets of set
void iterate_mask_subset(ll set, F f){ ll mask = set;
	do  f(mask), mask = (mask-1) & set;
	while (mask != set);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m;
	cin >> n >> m;
	vvi C(n, vi(n, 0LL));
	while (m--) {
		int a, b, c; cin >> a >> b >> c; --a; --b;
		C[a][b] = C[b][a] = c;
	}

	// Minimum connector
	int all = (1<<n) - 1;
	vi ic(1<<n, 0LL);
	vvi dp(n, vi(1<<n, -1LL));
	dp[0][1<<0] = 0LL;
	for (int mask = 0; mask < (1<<n); ++mask) {
		for (int u = 0; u < n; ++u)
			for (int v = u+1; v < n; ++v)
				if (((mask>>v)&1) && ((mask>>u)&1)) ic[mask] += C[u][v];
	}
	for (int mask = 0; mask < (1<<n); ++mask) {
		int submask = (all&~mask);
		do {
			for (int u = 0; u < n; ++u) {
				if (!((mask>>u)&1)) continue;
				if (dp[u][mask] < 0LL) continue;
				ll nc = dp[u][mask] + ic[submask|(1<<u)];
				if (nc > dp[u][mask|submask])
					dp[u][mask|submask] = nc;
			}
			submask = (submask - 1) & (all&~mask);
		} while (submask != (all&~mask));
		for (int u = 0; u < n; ++u) {
			if (!((mask>>u)&1)) continue;
			if (dp[u][mask] < 0LL) continue;
			for (int v = 0; v < n; ++v) {
				if ((mask>>v)&1) continue;
				if (C[u][v] == 0LL) continue;
				ll nc = dp[u][mask] + C[u][v];
				if (nc > dp[v][mask|(1<<v)])
					dp[v][mask|(1<<v)] = nc;
			}
		}
	}

	ll ans = 0LL;
	for (vi &c : C) for (ll v : c) ans += v;
	ans = (ans / 2) - dp[n - 1][all];
	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main()
{
    const int kMax = 1e5;
    vector<int> count(kMax + 1, 0);

    int cards;
    cin >> cards;

    auto distinct = 0;
    for (auto i = 0; i < cards; i += 1) {
        int value;
        cin >> value;

        count[value] += 1;
        distinct += (count[value] == 1 ? 1 : 0);
    }

    if (distinct % 2 == 0) {
        distinct -= 1;
    }

    cout << distinct << "\n";
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

int r,c,n;

static int chk(int a, int b)
{
    if(a==0) {
        return b;
    }
    if(b==c) {
        return c+a;    
    }
    if(a==r) {
        return c+r+(c-b);    
    }
    if(b==0) {
        return c+r+c+(r-a);
    }
    return -1;
}

void solve()
{
    scanf("%d%d%d", &r, &c, &n);
    vector<pair<int,int> > z;
    int i;
    for(i=0; i<n; i++) {
        int a,b,c,d;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        int p=chk(a,b);
        int q=chk(c,d);
        if(p>=0 && q>=0) {
            z.push_back(make_pair(p,i));
            z.push_back(make_pair(q,i));
        }
    }
    sort(z.begin(),z.end());

    if(z.size()<=2) {
        printf("YES\n"); return;
    }

    int siz=(int)z.size();
    assert(siz%2==0);
    vector<int> vv;
    for(i=0; i<siz; i++) {
        if(!vv.empty() && z[i].second==vv.back()) {
            vv.pop_back();
        }
        else {
            vv.push_back(z[i].second);
        }
    }
    if(vv.empty()) {
        printf("YES\n"); return;
    }
    printf("NO\n");

    return;
}


int main(int argc, char* argv[])
{
#if 1
	solve();
#else
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define int long long

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

struct data
{
    int h,a,d,s,u,v;
};

vector<data> vec;
data zibun;
int n;

bool possible(int cri)
{
    int tm = 0;
    int al = 0;
    rep(i,len(vec)){
        // cout << vec[i].h << " " << vec[i].a << " " << vec[i].d << " " << vec[i].s << " " << vec[i].u << " " << vec[i].v << "\n";
        if(zibun.s > vec[i].s){
            tm += vec[i].v - 1;
            al += tm*vec[i].u;
            ++tm;
        }else{
            tm += vec[i].v;
            al += tm*vec[i].u;
        }
        if(al > cri){
            return false;
        }
    }
    return true;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n+1){
        int w,x,y,z;
        cin >> w >> x >> y >> z;
        if(i == 0){
            zibun = (data){w,x,y,z,0LL,0LL};
        }else{
            if(zibun.a <= y){
                if(zibun.d < x){
                    cout << "-1\n";
                    return 0;
                }else{
                    continue;
                }
            }
            vec.pb((data){w,x,y,z,max(x-zibun.d,0LL),(ll)floor((double)(w-0.5)/(zibun.a-y))+1LL});
        }
    }
    sort(all(vec),[&](const data& x,const data& y){
        return (y.u*x.v == x.u*y.v)?(x.s > y.s):(y.u*x.v < x.u*y.v);
    });
    int l = 0,r = zibun.h-1;
    if(!possible(r)){
        cout << "-1\n";
        return 0;
    }
    if(possible(0)){
        cout << "0\n";
        return 0;
    }
    while(r-l>1){
        int mid = (l+r)/2;
        if(possible(mid)){
            r = mid;
        }else{
            l = mid;
        }
    }
    cout << r << "\n";
    return 0;
}

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

using namespace std;
const long long  mod = 1e9 + 7;
const int N = 2e3 + 10;
const int inf = 0x3f3f3f3f;
typedef unsigned long long LL;
typedef long long ll;
typedef pair<int,int> PII;
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};

LL n, k;
int a[N];

int main()
{  
    cin >> n >> k;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    LL ans = 0;
    LL c = (k - 1) * k / 2 % mod;
    for(int i = 1; i <= n; i ++)
    {
         LL re1 = 0, re2 = 0;
        for(int j = i + 1; j <= n; j ++)
        {
            if(a[i] > a[j]) re1 ++, re2 ++;
        }
        for(int j = i - 1; j >= 1; j --)
        {
            if(a[i] > a[j]) re2 ++;
        }
        ans = (ans + k * re1 % mod + c * re2 % mod) % mod;
    }
    cout << ans  << endl;
     return 0;
}

Measured memory_bytes: 256
//#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main(){
    int a,b;
    int x,y;
    cin >>x>>y;
    bool flg = false;
    for(int i =0;i<=x;i++){
        a = i;
        b =x-a;
        if(2*a+4*b==y){
            flg = true;
            break;
        }
        
    }
    
    
    if(flg == false)
           cout << "No"<<endl;
    else
        cout <<"Yes"<<endl;
           
    
}


Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABCK = Console.ReadLine().Split().Select(s=>long.Parse(s)).ToArray();
            var A = ABCK[0];
            var B = ABCK[1];
            var C = ABCK[2];
            var K = ABCK[3];
            long ans = 0;
            if(0<K)
            {
                if(K<A)
                {
                    ans += K;
                    K = 0;
                }
                else
                {
                    ans += A;
                    K -= A;
                }
            }
            if(0<K)
            {
                K -= B;
            }
            if(0<K)
            {
                ans -= K;
            }
            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 18984
N=int(input())
A=[int(i) for i in input().split()]
S=[0]
for num in A:
    S.append(S[-1]+num)
S.sort()

def combination(n):
    if n<2:
        return 0
    else:
        return int(n*(n-1)/2)
    
ans=0
cnt=1
for i in range(N):
    if S[i]==S[i+1]:
        cnt+=1
    else:
        ans+=combination(cnt)
        cnt=1
ans+=combination(cnt)
print(ans)


Measured memory_bytes: 26716
let () =
  let l = read_line () |> Str.split (Str.regexp " ") in
  let s = Stack.create () in
  let interpret_op = function "+" -> (+) | "-" -> (-) | _ -> ( * ) in
  List.iter
    (fun x -> match x with
         "+" | "*" | "-" ->
         let a,b = Stack.pop s, Stack.pop s in
         Stack.push ((interpret_op x) a b) s
       | _ -> Stack.push (int_of_string x) s)
    l;
  Printf.printf "%d\n" (Stack.pop s)

Measured memory_bytes: 2316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t a;
  cin >> a;
  int64_t n = 1;
  for(int i = 1;i<a+1;i++){
    n = fmod(n, 1000000007LL)*i; 
  }
  n = fmod(n, 1000000007LL);
  cout << n << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  t, a = map(int, input().split())
  hs = list(map(int, input().split()))
  ans = sorted([(i+1, abs( (t-0.006*h) - a )) for i, h in enumerate(hs)], key=lambda x:x[1])[0][0]
  print(ans)
  pass

if __name__=='__main__':
  main()

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&b==c){
    cout << 1 << endl;
  }else if(a==b||b==c||c==a){
    cout << 2 << endl;
  }else{
    cout << 3 << endl;
  }
}

Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	dist := make([]int, n)
	for i := 0; i < n; i++ {
		a := nextInt()
		dist[a]++
	}

	dMax := 0
	for d := n - 1; d > 0; d-- {
		if dist[d] > 0 {
			dMax = d
			break
		}
	}
	dMin := n
	for d := 1; d < n; d++ {
		if dist[d] > 0 {
			dMin = d
			break
		}
	}
	if dMin != ((dMax-1)/2)+1 {
		fmt.Println("Impossible")
		return
	}

	switch {
	case dMax%2 == 0 && dist[dMin] != 1:
		fmt.Println("Impossible")
		return
	case dMax%2 == 1 && dist[dMin] != 2:
		fmt.Println("Impossible")
		return
	}

	for d := dMin + 1; d <= dMax; d++ {
		if dist[d] < 2 {
			fmt.Println("Impossible")
			return
		}
	}
	fmt.Println("Possible")
	return
}


Measured memory_bytes: 640
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <string>

using namespace std;

int main()	{
  int n;
  string s;
  cin >> n;
  cin >> s;
  int a[n + 1];
  a[0] = 0;
  for (int i = 0; i < n; i++)	{
    a[i + 1] = a[i];
    if (s[i] == 'I')	{
      a[i + 1]++;
    }
    else	{
      a[i + 1]--;
    }
  }
  int max = 0;
  for (int i = 0; i < n + 1; i++)	{
    if (a[max] < a[i])	{
      max = i;
    }
  }
  cout << a[max] << endl;
  return 0;
}

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

const ll INF = 1LL << 60;

ll N, K;
vector<ll> v;

int main() {
    cin >> N >> K;
    v.resize(N);
    rep(i, N) cin >> v[i];

    ll ans = 0;
    for (int l = 0; l <= K; l++) {
        for (int r = 0; r <= K - l; r++) {
            if (l + r > N) continue;

            // 戻せる回数
            int d = K - (l + r);

            vector<ll> calc;
            ll tmp = 0;
            // 左からとる

            // cout << "pat1 l " << l << " r: " << r << " " << tmp << endl;
            // [0, l)
            for (int k = 0; k < l; k++) {
                calc.push_back(v[k]);
                tmp += v[k];
            }

            // 右からとる
            // cout << "pat2 l " << l << " r: " << r << " " << tmp << endl;
            // [N - r, N)
            for (int k = 0; k < r; k++) {
                calc.push_back(v[N - 1 - k]);
                tmp += v[N - 1 - k];
            }

            sort(calc.begin(), calc.end());

            // cout << "pat3 l " << l << " r: " << r << " " << tmp << endl;
            // 戻す
            for (int k = 0; k < min(d, (int)calc.size()); k++) {
                if (calc[k] > 0) break;
                tmp -= calc[k];
            }
            // cout << "l " << l << " r: " << r << " " << tmp << endl;
            ans = max(tmp, ans);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main(){
  int n;
  string s;
  cin >> n >> s;
  vector<char>a(n);
  int i=0;
  while(1){
    if(s.size()==1)
      break;
    else if(s.at(i)==s.at(i+1)){
      if(i==s.size()-2){
        s.erase(s.begin()+(i+1));
        break;
      }
      else
        s.erase(s.begin()+(i+1));
    }
    else if(i==s.size()-2)
      break;
    else
      i++;
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
main(){
  int n,l,i;
  char str[1200];

  gets(str);
  l=strlen(str);

  for(i=0;i<l-4;i++){
    if(str[i]=='a'&&str[i+1]=='p'&&str[i+2]=='p'&&str[i+3]=='l'&&str[i+4]=='e'){
      str[i]='p',str[i+1]='e',str[i+2]='a',str[i+3]='c',str[i+4]='h';
    }else if(str[i]=='p',str[i+1]=='e'&&str[i+2]=='a'&&str[i+3]=='c'&&str[i+4]=='h'){
      str[i]='a',str[i+1]='p',str[i+2]='p',str[i+3]='l',str[i+4]='e';
    }
  }

  printf("%s\n",str);
  return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  ll m,d,m2,d2;cin>>m>>d>>m2>>d2;
  if(m+1==m2 || (m==12&&m2==1)){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextInt();
        long B = sc.nextInt();
        System.out.println(A*B/gcd(A,B));
    }
    static long gcd(long m, long n) {
    		if(m < n) return gcd(n,m);
    		if(n == 0) return m;
    		return gcd(n, m%n);
    }
} 

Measured memory_bytes: 22868
a,b = map(int,input().split())

words = []
a_word = ""
b_word = ""

for i in range(a):
    b_word += str(b)
for i in range(b):
    a_word += str(a)
words.append(a_word)
words.append(b_word)
words.sort()

print(words[0])

Measured memory_bytes: 61784
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int N;
int c[100010];

int dp[2][2][5002];

int main()
{
    N = in();

    rep(i, N - 1) {
        c[i+1] = in();
    }

    rep(i, 2) rep(j, 2) rep(k, N / 2 + 1) dp[i][j][k] = inf; 
    dp[0][0][0] = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= min(i, N / 2); ++j) {
            dp[(i + 1) & 1][0][j + 1] = min(dp[i & 1][0][j], dp[i & 1][1][j] + c[i]);
            dp[(i + 1) & 1][1][j] = min(dp[i & 1][1][j], dp[i & 1][0][j] + c[i]);
        }

        dp[(i + 1) & 1][0][0] = inf;
    }

    printf("%d\n", min(dp[(N/2)%2][0][N / 2], dp[(N/2)%2][1][N / 2]));
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, m, x;
  cin >> n >> m >> x;

  vi c(n);
  vvi a(n);
  rep(i,0,n) {
    cin >> c[i];
    rep(j,0,m) {
      int k; cin >> k;
      a[i].pb(k);
    }
  }

  int ans = 1e9;
  rep(msk,0,1<<n) {
    vi tot(m);
    int cst = 0;
    rep(i,0,n) {
      if (msk&(1<<i)) {
        cst += c[i];
        rep(j,0,m) tot[j] += a[i][j];
      }
    }

    bool suc=1;
    rep(i,0,m) if(tot[i] < x) suc=false;
    if (suc) ckmin(ans, cst);
  }

  if (ans>=1e9) ans=-1;
  cout << ans << '\n';
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cctype>
#include <algorithm>
#define il inline
#define vd void
#define rg register
#define ll long long
#define mn 200005
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il ll rd(); il vd pc(char c); il vd rt(ll x); il vd flush();
template<class T> il T Max(T a,T b){return a>b?a:b;}
template<class T> il T Min(T a,T b){return a<b?a:b;}
int n,ma,mf,a[mn],f[mn];
ll k,s[mn],ans,b[mn];
il int check(ll x){
	rep(i,1,n) b[n-i+1]=x/f[i];
	ll sum=0ll;
	rep(i,1,n) if(a[i]>b[i]) sum+=a[i]-b[i];
	return sum<=k;
}
int main(){
	n=rd(),k=rd();
	rep(i,1,n) a[i]=rd(),ma=Max(ma,a[i]);
	rep(i,1,n) f[i]=rd(),mf=Max(mf,f[i]);
	sort(a+1,a+n+1),sort(f+1,f+n+1);
	ll l=0ll,r=1ll*ma*mf,ans=0ll;
	while(l<=r){
		ll mid=(l+r)>>1;
		if(check(mid)) ans=mid,r=mid-1ll; else l=mid+1ll;
	}
	rt(ans);
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il ll rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	ll f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(ll x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 8960
let lcs x y =
  let m = String.length x in
  let n = String.length y in
  let dp = Array.make_matrix (m+1) (n+1) 0 in
  for i = 1 to m do
    for j = 1 to n do
      dp.(i).(j) <- if x.[i-1] = y.[j-1] then dp.(i-1).(j-1) + 1 else if dp.(i-1).(j) > dp.(i).(j-1) then dp.(i-1).(j) else dp.(i).(j-1)
    done
  done;
  dp.(m).(n)

let () =
  let q = read_int () in
  let rec doit i =
    if i < q then begin
      let x = read_line () in
      let y = read_line () in
      Printf.printf "%d\n" (lcs x y);
      doit (i + 1)
    end
  in
  doit 0

Measured memory_bytes: 18664
#include <iostream>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
string N;
string ans;
int n;
int counter = 0;
void solve()
{
    for(int i=0;i<N.size();i++)
    {
        n = (int)(N[i]-'0');
        counter += n; 
    }
    if(stoi(N)%counter==0)
    {
        ans = "Yes";
    }
    else
    {
        ans = "No";
    }
    
}
int main()
{
    cin >> N;

    solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
int main(){
	std::string str;
	std::getline(std::cin,str);
	int h=0;
	while(h<str.size()){
		if(str[h]!=' '&&str[h]!='.')str[h]-='a'-'A';
		h++;
	}
	std::cout<<str<<std::endl;

	return 0;
}

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

int main(){
    int n,k,q,c;
    cin >> n >> k >> q;
    vector<int> a(n,-q + k);
    for(int i = 0;i < q;i++){
        cin >> c;
        a[c - 1]++; 
    }
    for(int i = 0;i < n;i++){
        cout << (a[i] > 0 ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



int main(){
	ll x;
	cin >> x;
	ll v=x%100;
	ll c=x/100;
	if(x<100){
		cout << 0 << endl;
		return 0;
	}
	if(v>c*5){
		cout << 0 << endl;
	}else{
		cout << 1 << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

struct Edge {
    ll to;
    ll cost;
    Edge(ll t, ll w) : to(t), cost(w) { }
};

ll V, d[MAX];
vector<Edge> G[MAX]; // 隣接リスト表現

void dijkstra(ll s) {
    fill(d, d + V, INF);
    d[s] = 0;  // 始点sへの最短距離は0

    priority_queue<P, vector<P>, greater<P> > que;  // 距離が小さい順に取り出せるようgreater<P>を指定
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;  // 更新した頂点の中で距離が最小の頂点v
        if (d[v] < p.first) {
            continue;
        }
        for (auto e : G[v]) {  // 頂点vから出る辺eを走査
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}


int main(){
  ll M; cin >> V >> M;
  ll r; cin >> r;
  rep(i,M){
    ll a, b, c; cin >> a >> b >> c;
    G[a].pb(Edge(b,c));
  }
  dijkstra(r);
  rep(i,V){
    if(d[i] == INF) cout << "INF" << endl;
    else cout << d[i] << endl;
  }


}



Measured memory_bytes: 29032
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h.at(i);
  int mx = 0, co = 1;
  rep2(i, 1, n){
    if(h.at(i-1) < h.at(i)){
      mx = max(mx, co);
      co = 1;
    }else co++;
  }
  mx = max(mx, co);
  cout << mx-1 << endl;
  return 0;
}

Measured memory_bytes: 3772
#include <stdio.h>

void Counting_Sort(int A[], int B[], int n, int k) {
  int i, j;
  int C[10001];
  for(i = 0; i <= k; ++i)
    C[i] = 0;
  for(j = 1; j <= n; ++j)
    C[A[j]] = C[A[j]]+1;
  /* C[i] now contains the number of elements equal to i */
  for(i = 1; i <= k; ++i)
    C[i] = C[i] + C[i-1];
  /* C[i] now contains the number of elements less than or equal to i */
  for(j = n; j >= 1; --j) {
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]]-1;
  }
}
int A[2000001], B[2000001];
int main() {
  int i;
  int n, k;
  k = 0;
  scanf("%d", &n);
  for(i = 1; i <= n; ++i) {
    scanf("%d", A+i);
    k = A[i] > k ? A[i] : k;
  }
  Counting_Sort(A,B,n,k);
  for(i = 1; i <= n; ++i) {
    if(i-1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 15000
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007LL
#define REP(i, n) for(int i=0;i<(n);++i)
typedef long long ll;

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

	int n; string s; cin >> n >> s;
	stack<int> sta;
	string ans = "";
	REP(i, n){
		if(s[i] == '('){
			sta.push(i);
			ans += s[i];
			continue;
		}
		if(!sta.empty()){
			sta.pop();
			ans += ')';
		}	else {
			ans = '('+ans+')';
		}
	}
	while(!sta.empty()){
		sta.pop();
		ans += ')';
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    for (int i = k; i < n; i++) {
        int f = a[i-k];
        int l = a[i];
        if (f < l)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    
    return 0;
}


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

int main() {

  int N;
  cin >> N;

  vector<int> num(100010);
  for(int i = 0;i < N;i++) {
    int A;
    cin >> A;
    num.at(A)++;
  }

  sort(num.begin(),num.end(),greater<int>());
  int sum = 0,i = 0;
  while(num.at(i)) {
    sum++;
    i++;
  }

  if(sum % 2 == 0) {
    cout << sum-1 << endl;
  }else {
    cout << sum << endl;
  }
  
}

Measured memory_bytes: 640
Module Module1

    Sub Main()
        Dim ans As String = ""

        Dim input() As String = Console.ReadLine.Split(" "c)

        Dim value(input.Length - 1) As Integer

        For i As Integer = 0 To input.Length - 1
            value(i) = CInt(input(i))
        Next

        Dim eightpermin As Integer = CInt(System.Math.Ceiling(value(0) / 0.08))
        Dim eightpermax As Integer = CInt(System.Math.Ceiling((value(0) + 1) / 0.08)) - 1
        Dim tenpermin As Integer = CInt(System.Math.Ceiling(value(1) / 0.1))
        Dim tenpermax As Integer = CInt(System.Math.Ceiling((value(1) + 1) / 0.1)) - 1

        If (tenpermin < eightpermin AndAlso tenpermax < eightpermin) OrElse (tenpermin > eightpermax AndAlso tenpermax > eightpermax) Then
            ans = "-1"
        Else

            If eightpermin <= tenpermin Then
                ans = tenpermin.ToString
            Else
                ans = eightpermin.ToString
            End If

        End If



            Console.WriteLine(ans)
        Console.ReadKey()




    End Sub




End Module


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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    ll N, M, A, B;
    cin >> N >> M;
    vector<ll> co(N, -1);
    vector<vector<ll>> edge(N, vector<ll>());
    rep(i, M) {
        cin >> A >> B;
        A--;
        B--;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }
    vector<int> c(N, -1);
    co[0] = 0;
    queue<int> q;
    rep(i, edge[0].size()) {
        int j = edge[0][i];
        q.push(j);
        co[j] = 1;
    }
    while (!q.empty()) {
        int i = q.front();
        q.pop();
        rep(j, edge[i].size()) {
            int k = edge[i][j];
            if (co[k] == -1) {
                q.push(k);
                co[k] = 1 - co[i];
                continue;
            }
            if (co[i] != co[k]) continue;
            //rep(i, N) cout << co[i];
            //cout << endl;
            cout << N * (N - 1) / 2 - M << endl;
            return 0;
        }
    }
    ll d[2] = {0, 0};
    rep(i, N) {
        d[co[i]]++;
    }
    //cout << d[0] << " " << d[1] << endl;
    cout << N * (N - 1) / 2 - d[0] * (d[0] - 1) / 2 - d[1] * (d[1] - 1) / 2 - M << endl;
}

Measured memory_bytes: 7552
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define LL long long
using namespace std;
int n,m,v,p,a[N+5];LL s[N+5];
I bool cmp(CI x,CI y) {return x>y;}//从大到小排序
int main()
{
	RI i;for(scanf("%d%d%d%d",&n,&m,&v,&p),i=1;i<=n;++i) scanf("%d",a+i);
	for(sort(a+1,a+n+1,cmp),i=1;i<=n;++i) s[i]=s[i-1]+a[i];//排序后求前缀和
	for(i=n;i>p;--i) if(a[i]+m>=a[p])//枚举答案，首先要使得加上m后大于等于第p个数
		if(1LL*max(v-p-(n-i),0)*m<=1LL*(a[i]+m)*(i-p)-(s[i-1]-s[p-1])) break;//用1去填平中间的坑
	return printf("%d",i),0;//输出答案（若始终没break则最后i恰好等于p）
}

Measured memory_bytes: 4984
#B - Picture Frame 
H,W = map(int,input().split())
a = []
for _ in range(H):
    ai = list(map(str,input()))
    a.append(ai)

b = ['#']*(W+2)

for i in range(H):
    a[i].insert(0,'#')
    a[i].append('#')
print(''.join(b))
for j in a:
    print(''.join(j))
print(''.join(b))

Measured memory_bytes: 9128
import numpy as np

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

persons = [list(map(int, input().split())) for _ in range(N)]

positions = [list(map(int, input().split())) for _ in range(M)]

for person in persons:
    distance_min=4*10**8+1
    number=0
    for i, position in enumerate(positions):
        distance_pp = np.abs(person[0]-position[0])+np.abs(person[1]-position[1])
        if distance_min> distance_pp:
            distance_min= distance_pp
            number=i+1
    print(number)


Measured memory_bytes: 12496