akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

// 右, 下, 左, 上(時計回り)
const int dx[4]={1,  0, -1,  0};
const int dy[4]={0,  1,  0, -1};
const int INF = 10000000;

int W, H;
int s[55][55];
int c[55];
int dist[55][55][4];

struct State {
  int x;
  int y;
  int cost;
  int direct;

  bool operator<(const State &state) const {
    return cost < state.cost;//年齢を比較
  };

  bool operator>(const State &state) const {
    return cost > state.cost;//年齢を比較
  };
};

inline bool inArea(int x, int y, int W, int H) {
  return (0 <= x && x < W && 0 <= y && y < H);
}

void init(){
  for(int i = 0; i < 55; i++) {
    for(int j = 0; j < 55; j++) {
      for(int k = 0; k < 4; k++) {
	dist[i][j][k] = INF;
      }
    }
  }
}

void dijkstra() {
  init();
  priority_queue<State, vector<State>, greater<State>> que;
  que.push({0, 0, 0, 0});
  while(que.size()) {
    State state = que.top(); que.pop();
    int x = state.x, y = state.y, cost = state.cost, direct = state.direct;
    for(int i = 0; i < 4; i++) {
      int next_direct = (direct + i) % 4;
      int nx = x + dx[next_direct], ny = y + dy[next_direct];
      if(!inArea(nx, ny, W, H)) continue;
      if(i == s[y][x]) {
	if(cost < dist[ny][nx][next_direct]) {
	  dist[ny][nx][next_direct] = cost;
	  que.push({nx, ny, cost, next_direct});
	}
      } else {
	if(cost + c[i] < dist[ny][nx][next_direct]) {
	  dist[ny][nx][next_direct] = cost + c[i];
	  que.push({nx, ny, cost + c[i], next_direct});
	}
      }
    }
  }
}

int main(){
  while(cin >> W >> H) {
    if(W == 0 && H == 0) break;
    for(int i = 0;  i < H; i++) {
      for(int j = 0; j < W; j++) {
	cin >> s[i][j];
      }
    }
    for(int i = 0; i < 4; i++) {
      cin >> c[i];
    }

    dijkstra();

    int ans = INF;
    for(int i = 0; i < 4; i++) {
      ans = min(ans, dist[H - 1][W - 1][i]);
    }
    cout << ans << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3256
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 21:04:18 2019

@author: Yamazaki Kenichi
"""

N, K = map(int,input().split())
ans = 0
for i in range(1,N+1):
    c = i
    counta = 0
    while c < K:
        counta += 1
        c *= 2
    ans += pow(1/2,counta)/N
print(ans)

Measured memory_bytes: 3060
import sys
from collections import defaultdict as dd
from bisect import bisect_right as br
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
cs = [0] * (N + 1)
res = 0
for i in range(N): cs[i + 1] = cs[i] + a[i]
d = dd(list)

for i in range(N + 1): d[cs[i]].append(i)
for i in range(N):
  s = cs[i]
  j = br(d[s], i)
  res += len(d[s]) - j
print(res)

Measured memory_bytes: 117580
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
pair<int,int> p[maxn];
int n;
int L1,R1,L2,R2;
int L[maxn],R[maxn];

void solve(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d%d",&p[i].first,&p[i].second);
    }
    sort(p+1,p+n+1);

    L1=p[1].first;R1=p[1].second;
    L[n]=p[n].first;R[n]=p[n].second;

    for(int i=n-1;i>1;--i){
        R[i]=min(R[i+1],p[i].second);
        L[i]=max(L[i+1],p[i].first);
    }
    int ans=max(R1-L1+1,0)+max(R[2]-L[2]+1,0),res=0;
    for(int i=3;i<=n;++i){
        L1=max(L1,p[i-1].first);
        R1=min(R1,p[i-1].second);
        ans=max(max(R1-L1+1,0)+max(R[i]-L[i]+1,0),ans);
    }
    for(int i=1;i<=n;++i)res=max(res,p[i].second-p[i].first+1);
	int maxl=INT_MIN,minr=INT_MAX;
	for(int i=1;i<=n;++i){
		maxl=max(maxl,p[i].first);
		minr=min(minr,p[i].second);
	}
	res+=max(0,minr-maxl+1);
    printf("%d\n",max(ans,res));
}
int main(){
    solve();

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int g = a[0];
    REP(i, 1, n) g = __gcd(g, a[i]);
    cout << g << endl;
    return 0;
}

Measured memory_bytes: 640
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        k: u32,
        s: u32,
    }

    let mut ans = 0;
    for x in 0..k + 1{
        // println!("x: {}", x);
        if x > s {
            break;
        }

        let yz = s - x;
        // println!("y + z = {}", yz);
        if yz <= k {
            ans += yz + 1;
        } else if yz <= 2 * k{
            ans += (yz + 1) - 2 * (yz - k);
        }
        // println!("ans: {}", ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int main() {
	ll N, K, Q; cin >> N >> K >> Q;
	vector<ll> A(Q);
	for (int i = 0; i < Q; i++)cin >> A[i];

	ll cnt[N+1] = {};
	for (int i = 0; i < Q; i++) {
		cnt[A[i]]++;
	}

	for(int i = 1; i <= N; i++){
		if (K - (Q - cnt[i]) > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 2176
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

ll vec[3000];
ll dp[3000][3000][2];

ll go(int l, int r, int tu) {
	if (l > r) return 0;
	if (dp[l][r][tu] > -1e17) return dp[l][r][tu];

	ll ret;
	if (tu == 0) ret = max(go(l, r - 1, tu ^ 1) + vec[r], go(l + 1, r, tu ^ 1) + vec[l]);
	else ret = min(go(l, r - 1, tu ^ 1) - vec[r], go(l + 1, r, tu ^ 1) - vec[l]);

	return dp[l][r][tu] = ret;
}

int main() {
	memset(dp, -0x3f, sizeof(dp));


	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%lld", &vec[i]);

	printf("%lld", go(0, n - 1, 0));
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vi d(4, 0);
	REP(i, 3) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		d[a]++;
		d[b]++;
	}
	if (*max_element(ALL(d)) == 3)cout << "NO" << endl;
	else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		100000									// 最大配列数

// 内部変数
static int si1Array[D_ARRAY_MAX + 5];							// 配列
static int siACnt;												// 配列数
static int si1Grp[D_ARRAY_MAX + 5];								// グループ番号

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// グループ番号(TOP)取得
int
fGetGNo(
	int piVal					// <I> 値 1～
)
{
	// TOPかチェック
	if (si1Grp[piVal] == piVal) {
		return piVal;
	}

	// グループ番号取得・更新 
	si1Grp[piVal] = fGetGNo(si1Grp[piVal]);

	return si1Grp[piVal];
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 配列数・ペア数取得
	int liPCnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &siACnt, &liPCnt);

	// 配列取得
	for (i = 1; i <= siACnt; i++) {
#ifdef D_TEST
		fscanf(szpFpT, "%d", &si1Array[i]);
#else
		fscanf(stdin, "%d", &si1Array[i]);
#endif
	}
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif

	// グループ初期化
	for (i = 1; i <= siACnt; i++) {
		si1Grp[i] = i;
	}

	// ペア取得
	for (i = 0; i < liPCnt; i++) {
		int liVal1, liVal2;
#ifdef D_TEST
		fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
		fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
		sscanf(lc1Buf, "%d%d", &liVal1, &liVal2);

		// グループ番号取得
		int liGNo1 = fGetGNo(liVal1);
		int liGNo2 = fGetGNo(liVal2);

		// 比較
		if (liGNo1 == liGNo2) {						// 同一グループ
			continue;
		}

		// グループ番号更新
		si1Grp[liGNo2] = liGNo1;
	}

	// 配列の一致チェック
	int liMCnt = 0;
	for (i = 1; i <= siACnt; i++) {

		// 一致チェック
		if (si1Array[i] == i) {						// 一致
			liMCnt++;
			continue;
		}

		// グループ番号取得
		int liGNo1 = fGetGNo(si1Array[i]);
		int liGNo2 = fGetGNo(i);

		// 一致チェック
		if (liGNo1 == liGNo2) {						// 一致
			liMCnt++;
			continue;
		}
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liMCnt);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define YESNO(i) puts((i)?"YES":"NO");
#define YesNo(i) puts((i)?"Yes":"No");
#define yesno(i) puts((i)?"yes":"no");
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin>>a>>b;
  print((a-1)*(b-1));
  return 0;
}

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

using namespace std;

#define N 3001

int n;
int vis[N][N] = {0};
double dp[N][N], a[N], ans = 0;
int n1;

double solve(int n, int c)
{
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= c; j++)
		{
			if (i == 0)
			{
				if (n - j > n / 2)
					dp[i][j] = 1;
				else
					dp[i][j] = 0;
			}
			else
				dp[i][j] = a[i - 1] * dp[i - 1][j - 1] + (1 - a[i - 1]) * dp[i - 1][j];
		}
	}
	return dp[n][c];
}

int main()
{
	cin >> n;
	n1 = n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ans = solve(n, n);
	cout << setprecision(10) << ans << endl;
	return 0;
}


Measured memory_bytes: 71936
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag() 
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

typedef vector< vector<int> > Graph;
int dp[100010];
int dfs(Graph &G, int p, int par=-1) {
    if(dp[p] != -1) return dp[p];

    bool leaf = true;
    vector<int> v;
    int mi = INF;
    rep(i,0,G[p].size()) {
        int to = G[p][i];
        if(to == par) continue;
        int ad = dfs(G, to, p);
        v.push_back( ad );
        mi = min(mi, ad);
        leaf = false;    
    }
    if(leaf) return dp[p] = 0;
    sort(v.begin(), v.end(), greater<int>());

    int n = v.size();
    int ret = 0;
    rep(i,0,n) ret = max(ret, v[i] + i + 1);
    return dp[p] = ret;
}

signed main() {
    int n; cin >> n;
    Graph G(n);
    rep(i,1,n) {
        int inp; cin >> inp;
        inp--;
        G[i].push_back(inp);
        G[inp].push_back(i);
    }
    memset(dp, -1, sizeof(dp));
    cout << dfs(G, 0) << endl;
    rep(i,0,n) {
        // printf("debug: dp[%lld] = %lld", i, dp[i]);
        // cout << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define Max(x, y)(max(decltype(x)(0), max((x), (y))))
#define Min(x, y)(max(decltype(x)(0), min((x), (y))))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool _max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool _min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, a;

    cin >> n;
    cin >> a;

    if (n < 500 && n <= a) {
        Out("Yes");
    } else if (n < 500 && a < n) {
        Out("No");
    } else {
        int x = n % 500;

        if (x <= a) Out("Yes");
        else Out("No");
    }

    return 0;
}


Measured memory_bytes: 256
//Author: xiaowuga
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAX INT_MAX
#define mem(s,ch) memset(s,ch,sizeof(s))
const long long N=100000; 
const long long mod=1e9+7; 
typedef long long LL;
typedef int II;
typedef unsigned long long ull;
#define nc cout<<"nc"<<endl
#define endl "\n"
vector<int>G[N];
int dfn[N]={0},low[N]={0},vis[N]={0},tot=0;
int ct=0;
stack<int>s;
void tarjan(int u,int fa){
    dfn[u]=low[u]=++tot;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i];
        if(v==fa) continue;
        if(!dfn[v]){
            tarjan(v,u); 
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]) ct++;
        }
        else low[u]=min(low[u],dfn[v]);
    } 
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        G[x].push_back(y); 
        G[y].push_back(x); 
    }
    for(int i=1;i<=n;i++){
        if(!dfn[i]) tarjan(i,-1); 
    }
    cout<<ct<<endl;
	return 0;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  for(ll i=K; i<=N+1; i++) {
    (ans += (N-(i-1)+N)*i/2 - (i-1)*i/2 + 1) %= mod;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3616
def main():
    N, Q = map(int, input().split())
    tl = [] # イベントタイムライン
    for _ in range(N):
        S, T, X = map(int, input().split())
        tl.append((S-X, 1, X)) # insert
        tl.append((T-X, 0, X)) # erase
    for _ in range(Q):
        D = int(input())
        tl.append((D, 2, 0)) # min
    tl.sort()
    working = set() # 工事中
    wcur = 0 # 工事中の区域の数
    curmin = -1
    flag = False
    for t, c, x in tl:
        if c == 0: # erase
            wcur -= 1
            working.remove(x)
            if x <= curmin:
                curmin = x
                flag = True
        elif c == 1: # insert
            wcur += 1
            working.add(x)
            if curmin < 0 or curmin >= x:
                curmin = x
                flag = False
        else: # min
            if wcur == 0:
                curmin = -1
                flag = False
            elif flag:
                curmin = min(working)
                flag = False
            print(curmin)
    return
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 88936
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	int n;
	cin>>n;

	int ans=1;
	bool zero=0;
	bool neg=0;
	
	vector<int> v(n);
	for(int i=0;i<n;i++){
		int aux;
		cin>>aux;
		if(!aux){
			zero=1;
			ans=0;
			neg=0;
		}

		else if(!zero && !neg && aux <= (int)(1000000000000000000)/ans){
			ans = ans * aux;
		}
		else{
			neg=1;
			ans=(-1);
		}
	}
	if(ans>(1000000000000000000))ans=(-1);
	if(zero)ans=0;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3960
#pragma warning disable
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections;
using static System.Math;

class E { static void Main() => new J(); }
class J
{
	int F() => int.Parse(Console.ReadLine());
	int[] G() => Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		var a = G();
		int N = a[0], K = a[1];
		a = G();
		Array.Sort(a);
		Console.WriteLine(FirstBinary(0, N, c =>
		{
			var dp = new bool[K];
			dp[0] = true;
			for (var i = 0; i < N; i++)
			{
				if (i == c) continue;
				for (var s = K - 1; s >= a[i]; s--) dp[s] |= dp[s - a[i]];
			}
			for (var i = K - 1; i >= 0; i--) if (dp[i]) return i + a[c] >= K;
			return false;
		}));
	}
	static int FirstBinary(int min, int max, Predicate<int> pred)
	{
		while (min < max)
		{
			var mid = (min + max) / 2;
			if (pred(mid)) max = mid;
			else min = mid + 1;
		}
		return min;
	}
}

Measured memory_bytes: 13408
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	std::vector<int> a(5);
	rep(i,5) std::cin >> a[i];
	rep(i,5) {
		if(a[i]==0) {
			print(i+1);
			return 0;
		}
	}
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#define N_MAX 1000
#define M 1000000007
using namespace std;
typedef long long ll;
 
ll func(int);
 
int N,s,t;
string n[N_MAX];
vector<int> edge[N_MAX];
 
int main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>n[i];
  for(int i=0;i<N-1;i++) cin>>s>>t,edge[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
  return 0;
}
 
ll func(int x){
  ll res=0,res2=1;
  if(!edge[x].size()){
    if(n[x]=="E") return 1;
    if(n[x]=="E?") return 2;
    return 0;
  }
  if(n[x]=="E"){
    for(int i=0;i<edge[x].size();i++) res2*=func(edge[x][i]);
    return res2%M;
  }
  if(n[x]=="E?"){
    for(int i=0;i<edge[x].size();i++) res2*=func(edge[x][i]);
    return (res2+1)%M;
  }
  if(n[x]=="A"){
    for(int i=0;i<edge[x].size();i++) res+=func(edge[x][i]);
    return res%M;
  }
  if(n[x]=="A?"){
    for(int i=0;i<edge[x].size();i++) res+=func(edge[x][i]);
    return (res+1)%M;
  }
  if(n[x]=="R?"){
    for(int i=0;i<edge[x].size();i++){
      /*if(n[edge[x][i]]=="E?") res2*=func(edge[x][i]);
	else*/ res2*=(1+func(edge[x][i]));
    }
    return res2%M;
  }
  if(n[x]=="R"){
    for(int i=0;i<edge[x].size();i++){
      /*if(n[edge[x][i]]=="E?") res2*=func(edge[x][i]);
	else*/ res2*=(1+func(edge[x][i]));
    }
    /*for(int i=0;i<edge[x].size();i++)
      if(n[edge[x][i]]=="E?") return res2%M;*/
    return (res2-1)%M;
  }
}

Measured memory_bytes: 1340
#include <iostream>
using namespace std;
int main(void){
    int X, Y;
    cin >> X >> Y;
    if(X == Y){
        cout << "-1" <<endl;
    }else if(X > Y){
        if(X%Y == 0){
            cout << "-1" <<endl;
        }else{
            cout << X <<endl;
        }
    }else{
        cout << X <<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int N;

int getScore(int A[])
{
	int maxA, minA, lenA, total {};
	lenA = N - 2;
	maxA = *std::max_element(A, A + N);
	minA = *std::min_element(A, A + N);
	for (int i {}; i < N; ++i)
		total += A[i];
	total = total - minA - maxA;
	
	int score;
	score = total / lenA;
	return score;
}

int main()
{
	while (std::cin >> N && N > 0)
	{
		int a[N];
		for (int i {}; i < N; ++i)
			std::cin >> a[i];
		std::cout << getScore(a) << std::endl;
	}
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int x,y;
	 cin>>x>>y;
	 string ans="No";
	 for(int crane=0;crane<=x;crane++)
	 {
		 int legs=crane*2+(x-crane)*4;
		 if(legs==y)
		 {
			 ans="Yes";
           break;
		 }
	 }
	 cout<<ans;
	 return 0;
}


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

#define slld(longvalue) scanf("%lld", &longvalue)
#define plld(longvalue) printf("%lld\n", longvalue)

#define slf(longvalue) scanf("%lf", &longvalue)
#define plf(longvalue) printf("%lf\n", longvalue)
#define sc(letter) scanf("%c", &letter)
#define pc(letter) printf("%c", letter)

#define ss(name) scanf("%s", name)
#define ps(name) printf("%s", name)

#define pnew printf("\n")

#define ll long long

#define printcase(indexing,ans) printf("Case %lld: %lld\n", indexing, ans)

#define pb(x) push_back(x)

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 1000000009


using namespace std;

int main()
{
    ll i, j, k, l, m, n, o;
    ll testcase;
    ll input, flag, tag, ans;

    // freopen("in.txt", "r", stdin);


   ll w, a, b;

   cin >> w >> a >> b;

   if(a > b) swap(a,b);

   if(a == b || (a+w >= b))
   {
       cout << 0 << endl;
       return 0;
   }

   ans = abs(a + w - b);

   cout << ans << endl;


}





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

int main()
{
    int n; cin >> n;
    long long num = 1;
    long long sum = 0;
    while (num <= n) {
        if (num % 3ll != 0 && num % 5ll != 0) sum += num;
        num++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3584
from fractions import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)
if n > 1:
    ans.add(n)

print(len(ans)+1)




Measured memory_bytes: 5048
#include<stdio.h>
int main(void)
{
	int h,w,i,j,flg,x[101][101];
	char c[10];
	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++){
		flg=0;
		for(j=0;j<w;j++){
			scanf(" %c",&c[0]);
			//s[i][j]=c[0];
			if(c[0]=='c'){
				if(flg==1) x[i][j]=0;
				else{
					flg=1; x[i][j]=0;
				}
			}
			else{
				if(flg==0) x[i][j]=-1;
				else x[i][j]=x[i][j-1]+1;
			}
		}
	}
	for(i=0;i<h;i++){
		printf("%d",x[i][0]);
		for(j=1;j<w;j++) printf(" %d",x[i][j]);
		printf("\n");
	}
	/*for(i=0;i<h;i++){
		printf("%s\n",s[i]);
	}*/
	return 0;
}

Measured memory_bytes: 2716
#include <iostream>
#include <vector>
int INF = 1e9;
int main(){
    int H, W;
    std::cin >> H >> W;
    std::vector<std::vector<int>> c(10, std::vector<int> (10)),A(H, std::vector<int> (W));
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++) std::cin >> c[i][j];
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) std::cin >> A[i][j];
    }
    for(int k = 0; k < 10; k++){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                c[i][j] = std::min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    int ans =0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(A[i][j] != -1){
                ans += c[A[i][j]][1];
            }
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
	int x[4][4];
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cin >> x[i][j];
		}
	}
	if(x[0][0] - x[0][1] == x[1][0] - x[1][1] && x[0][1] - x[0][2] == x[1][1] - x[1][2] && x[1][0] - x[1][1] == x[2][0] - x[2][1] &&
	 x[1][1] - x[1][2] == x[2][1] - x[2][2]) cout << "Yes";
	 else cout << "No";
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))

int main()
{
    int N, X, i = 0;
    int count,D = 0;
    
    scanf("%d%d",&N ,&X);
    int L[N+1];
    count = 1;    
    for(i = 1; i <= N; i++){
        scanf("%d", &L[i]);
    }
    
    for(i = 2; i <= N+1; i++){
        D = D + L[i - 1];
        if(D > X) break;
        count++;        
    }
    printf("%d\n", count);
    
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  double t, a;
  cin >> t >> a;
  int ans = 0;
  double tmp = 100000;
  double h;
  for(int i = 0; i < n; i++) {
    cin >> h;
    if(abs(a - t + 0.006 * h) < tmp) {
      ans = i + 1;
      tmp = abs(a - t + 0.006 * h);
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

int main() {
int N, M;
  cin >> N >> M ;
  
  int sum = 0;
  
 vector<int> A(M);
for (int i = 0; i < M; i++) {
  cin >> A.at(i);
  sum += A.at(i);
}
  
if(N >= sum){
cout << N - sum << endl;
}

else{
cout << -1 << endl;
}
  

}


Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    int x,k,d;cin>>x>>k>>d;
    x=abs(x);
    int r=x/d;int mo=min(r,k);
    x=x-mo*d;
    k-=mo;
    if(k>0)
    {
        if(k%2==0)
            cout<<x;
        else
            cout<<min(abs(x-d),x+d);
    }
    else
        cout<<x;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std ;
int main()
{
	int n ;
	int a ,b ,c ,d ;
	cin >> n ;
	int t[ 101 ] = { 0 } ;
	for( int i = 0 ; i < n * ( n - 1 ) / 2  ; i++ )
	{
		cin >> a >> b >> c >> d ;
		
		if( c == d )
		{
			t[ a ]++ ;
			t[ b ]++ ;
			continue ;
		}
		t[ c > d ? a : b ] += 3 ;
	}
	for( int i = 1 ; i <= n ; i++ )
	{
		int juni = 1 ;
		for( int j = 1 ; j <= n ; j++ )
		{
			if( i == j )
				continue ;
			if( t[ i ] < t[ j ] )
			{
				juni++ ;
			}
		}
		cout << juni << endl ;
	}
	return 0 ;
}

Measured memory_bytes: 3100
str = gets.chomp!
str = gets.chomp!

str = str.split(' ').map(&:to_i)
str.sort!
str = [0,0,0,0] + str

i = -1

while str[i] != str[i-1]
    i -= 1
end

j = i - 2
while str[j] != str[j-1]
    j -= 1
end

puts str[i]*str[j]

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

int main(){
	int A, B; cin >> A >> B;

	int ans = 0;
	int socet = 1;
	while (socet < B)
	{
		socet = (socet - 1) + A;
		ans++;
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<stack>
#include<string>
#include<cstdlib>
#include<stdio.h>
using namespace std;
int n,a[50];
int solve(int i,int m){
    if(m==0)return 1;
    if(i>=n)return 0;
    int res=solve(i+1,m)||solve(i+1,m-a[i]);
    return res;
}
int main(){
    int q,m,i;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>a[i];
    }
    cin>>q;
    for(i=0; i<q; i++){
        cin>>m;
        if(solve(0,m))cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  int a;cin >> a;
  cout << a+a*a+a*a*a;
}


Measured memory_bytes: 3632
N, K, Q = list(map(int, input().split()))
point = {}
for i in range(Q):
    player = int(input())
    point[player] = point.get(player, 0) + 1

for n in range(N):
    point_key = point.keys()
    if Q - K < 0:
        print("Yes")
    elif (n + 1) in point_key and point[n + 1] > Q - K:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 9060
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{BufWriter, Write};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut a = a;
    let mut x = std::f64::MAX;
    let mut mid = 0;
    a.sort();
    //数列の中でn/2に近い数
    for i in 0..a.len() {
        let mut y = a[n - 1] as f64 / 2f64 - a[i] as f64;
        if y < 0f64 {
            y = y * (-1f64);
        }
        if x  > y {
            mid = i;
            x = y;
        }
    }
    puts!("{} {}\n", a[n - 1], a[mid]);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
tenants = readlines.map(&:split)
  tenants.shift
  
  building = []
  4.times do
    flor = []
    3.times do
      flor << Array.new(10){0}
    end
    building << flor
  end

  for tenant in tenants
    building[((tenant[0].to_i)-1)][((tenant[1].to_i)-1)][((tenant[2].to_i)-1)] += tenant[3].to_i
  end

  building.each_with_index do |build,buildnum|
    for bud in build
      puts " " + bud.join(" ")
    end
    puts "####################" if buildnum < 3
  end


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

//////////////////
// Union-Find木 //
//////////////////

// 0-indexed
class UnionFind {
private:
	std::vector<int> parent_, size_;
public:
	UnionFind(const int size)
		:parent_(size), size_(size, 1)
	{
		for (int i{}; i < size; i++) parent_[i] = i;
	}
	int calcRoot(const int index)
	{
		int &parent{parent_[index]};
		if (parent == index) return index;

		parent = calcRoot(parent);
		return parent;
	}
	bool areConnected(const int index1, const int index2)
	{
		return calcRoot(index1) == calcRoot(index2);
	}
	void unite(const int index1, const int index2)
	{
		const int root1{calcRoot(index1)}, root2{calcRoot(index2)};
		if (root1 == root2) return;
		if (size_[root1] <= size_[root2])
		{
			size_[root2] += size_[root1];
			parent_[root1] = root2;
		}
		else
		{
			size_[root1] += size_[root2];
			parent_[root2] = root1;
		}
		return;
	}
	int calcSize(const int index)
	{
		return size_[calcRoot(index)];
	}
};

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<std::array<int64_t, 3>> xy(N);
	for (auto& e: xy) scanf("%lld%lld", &e[0], &e[1]);
	for (int i{}; i < N; i++) xy[i][2] = i;
	UnionFind uf(N);
	std::sort(xy.begin(), xy.end());
	for (int i{1}; i < N; i++)
		if (xy[i - 1][0] == xy[i][0])
			uf.unite(xy[i - 1][2], xy[i][2]);
	std::sort(xy.begin(), xy.end(), [](auto& a, auto& b) { return a[1] < b[1]; });
	for (int i{1}; i < N; i++)
		if (xy[i - 1][1] == xy[i][1])
			uf.unite(xy[i - 1][2], xy[i][2]);
	std::sort(xy.begin(), xy.end(), [](auto& a, auto& b) { return a[2] < b[2]; });	

	std::vector<std::set<int64_t>> x(N), y(N);
	for (int i{}; i < N; i++)
		x[uf.calcRoot(i)].insert(xy[i][0]);
	for (int i{}; i < N; i++)
		y[uf.calcRoot(i)].insert(xy[i][1]);
	int64_t ans{};
	for (int i{}; i < N; i++)
		if (uf.calcRoot(i) == i)
			ans += (int64_t)x[i].size() * y[i].size();
	ans -= N;
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
typedef long long ll;
const ll MAX = (ll)1e5 + 55;
vector<vector<ll>> dp(MAX, vector<ll>(2, -1));

int func(ll k, ll c, vector<ll> &ar, int n)
{
    if (k <= 0)
    {
        return 1 - c;
    }
    if (dp[k][c] != -1)
    {
        return dp[k][c];
    }
    for (int x = 0; x < n; x++)
    {
        if (ar[x] > 0 && k >= ar[x])
            if (func((k - ar[x]), 1 - c, ar, n) == c)
            {
                return dp[k][c] = c;
            }
    }
    return dp[k][c] = 1 - c;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> ar(n);
    for (int x = 0; x < n; x++)
    {
        cin >> ar[x];
    }
    if (func(k, 0, ar, n) == 1)
    {
        cout << "Second\n";
    }
    else
    {
        cout << "First\n";
    }
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	int N;cin>>N;
  int ac=0, wa=0, tle=0, re=0;
  rep(n,N){
    string s;cin>>s;
    if(s=="AC")ac++;
    if(s=="WA")wa++;
    if(s=="TLE")tle++;
    if(s=="RE")re++;
  }

  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,m,t,a,b;
	cin>>n>>m>>t;
	b=-m;
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>a;
		ans+=max(0,a-b-(2*m));
		b=a;
	}
	ans+=max(0,t-a-m);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
    int n,m;
    cin>>n>>m;
    priority_queue<int,vector<int>,greater<int>> que;
    rep(i,n){
        int a;
        cin>>a;
        que.push(a);
    }
    pair<int,int> ChangeCard[100009];
    rep(i,m){
        int b,c;
        cin>>b>>c;
        ChangeCard[i]=make_pair(c,b);
    }
    sort(ChangeCard,ChangeCard+m,greater<pair<int,int>>());
    
    bool ifend=false;
    rep(i,m){
        int b=ChangeCard[i].second,c=ChangeCard[i].first;
        rep(j,b){
            int a=que.top();
            if(a>=c){
                ifend=true;
                break;
            }
            a=c;
            que.pop();
            que.push(a);
        }
        if(ifend) break;
    }
    
    long long ans=0;
    rep(i,n){
        ans+=que.top();
        //cout<<que.top();
        que.pop();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1532
#include<iostream>
using namespace std;
int main(){
  int n,ma=0,mi=1000000001;
  cin>>n;
  for(int i=0;i<n;++i){
    int a;
    cin>>a;
    if(a<mi)
      mi=a;
    if(a>ma)
      ma=a;
  }
  if(ma==mi)
    cout<<0<<endl;
  else
    cout<<abs(ma-mi)<<endl;
}

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

int main()
{
  string tmp;
  string s;
  cin >> tmp >> s;
  
  cout << "A" << s[0] << "C" << endl;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class mainClass
{
	static Scanner sc;
	static bool defret = false;
	public static void Main(string[] args)
	{
		sc = new Scanner();
		while (pre()) solve();
	}
	static bool pre()
	{
		defret = !defret;
		return defret;
	}
	static void solve()
	{
		const int mod = (int)1e9 + 7;
		var a = sc.nextIntArray();
		int N, K;
		N = a[0]; K = a[1];
		a = sc.nextIntArray();
		int[,,] dp = new int[N + 1, N + 1, 256];
		dp[0, 0, 0] = 1; dp[0, 1, a[0]] = 1;
		for (int i = 0; i < N - 1; i++)
		{
			for (int j = 0; j < N; j++)
			{
				for (int k = 0; k < 256; k++)
				{
					int nxt = a[i + 1] ^ k;
					//Console.WriteLine(nxt);
					dp[i + 1, j, k] += dp[i, j, k];
					dp[i + 1, j, k] %= mod;
					dp[i + 1, j + 1, nxt] += dp[i, j, k];
					dp[i + 1, j + 1, nxt] %= mod;
				}
			}
		}
		var ans = 0L;
		var fact = new long[256];
		fact[0] = 1;
		for (int i = 1; i < 256; i++)
		{
			fact[i] = fact[i - 1] * i % mod;
		}
		for (int i = 0; i <= N; i++)
		{
			var buf = dp[N - 1, i, K] * fact[i] % mod;
			ans += buf;
			ans %= mod;
		}
		Console.WriteLine(ans);
	}
}

public class Scanner
{
	public Scanner() { }
	public string next()
	{
		return Console.ReadLine();
	}
	public int nextInt()
	{
		return int.Parse(next());
	}
	public double nextDouble()
	{
		return double.Parse(next());
	}
	public long nextLong()
	{
		return long.Parse(next());
	}
	public string[] nextArray()
	{
		return next().Split(' ');
	}
	public int[] nextIntArray()
	{
		return Array.ConvertAll(nextArray(), e => int.Parse(e));
	}
	public long[] nextLongArray()
	{
		return Array.ConvertAll(nextArray(), e => long.Parse(e));
	}
	public double[] nextDoubleArray()
	{
		return Array.ConvertAll(nextArray(), e => double.Parse(e));
	}
}


Measured memory_bytes: 12760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[70] = {};
int main() {
    ll n;
    cin >> n;
    vector<int> v;
    a[1] = 1;
    for (int i = 2; i < 70; i++) {
        a[i] = a[i-1] + i;
    }
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            int cnt = 0;
            while (n % i == 0) {
                n /= i;
                cnt++;
            }
            v.push_back(cnt);
        }
    }
    if (n > 1) v.push_back(1);
    sort(v.begin(), v.end());
    int ans = 0;
    int p = 1;
    for (int i = 0; i < (int)v.size(); i++) {
        while (a[p] <= v[i]) p++;
        ans += p - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

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

		

		while (sc.hasNext()) {
            int ans = 0;
			int n = sc.nextInt();

			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					for (int k = 0; k < 10; k++) {
						for (int l = 0; l < 10; l++) {
							int sum = i + j + k + l;
							if (sum == n) {
								ans++;
							}
						}
					}
				}
			}
			System.out.println(ans);
		}

	}

}

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

int k, m, n, h, w;
ll t[1 << 17], d[1 << 17];

int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        string s;
        cin >> s;
        string ans = "";
        int ind = -1;
        if (s[0] == 'c')
            ind = 0, ans = "0";
        else
            ans = "-1";
        for (int j = 1; j < w; j++)
        {
            if (s[j] == 'c')
            {
                ind = 0;
                ans = ans + " 0";
            }
            else
            {
                if (ind == -1)
                    ans = ans + " -1";
                else
                    ind++, ans = ans + " " + to_string(ind);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
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;}
int const INF = 1 << 30;


int main()
{
    int n; ll L;
    cin >> n >> L;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    vector<int> res;
    rep(i,n-1) {
        if(a[i]+a[i+1] >= L) {
            res.push_back(i);
            break;
        }
    }

    if(res.empty()) {
        cout << "Impossible\n";
        return 0;
    }

    for(int i = res[0] + 1; i < n-1; ++i) res.push_back(i);
    for(int i = res[0] - 1; i >= 0; --i) res.push_back(i);
    cout << "Possible\n";
    drep(i,n-1) cout << res[i]+1 << "\n";
    return 0;
}

Measured memory_bytes: 4648
#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> a(n);
  rep(i, n) cin >> a.at(i);
  vector<int> ans(n);
  ll sum = 0;
  rep(i, n) sum += a.at(i);
  ll mi = 0;
  for(int i = 1; i < n; i += 2){
    mi += a.at(i);
  }
  ans.at(0) = sum - 2 * mi;
  rep(i, n-1) ans.at(i+1) = 2 * a.at(i) - ans.at(i);
  rep(i, n){
    if(i != 0) cout << " ";
    cout << ans.at(i);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3964
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := n; i > 0; i-- {
		if int(float64(i)*1.08) == n {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(":(")
}


Measured memory_bytes: 512