akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<list>
#include<algorithm>
#include<cstdio>
using namespace std;


int main(){
    
    int n,t;
    cin>>n;
    list<int> V;
    string com;
    for(int i=0;i<n;i++){
        
        cin>>com;
        
        if(com[0]=='i'){
            cin>>t;
            V.push_front(t);
            
        }else if(com[6]=='F'){
                V.pop_front();
                //deleteLast
        }else if(com[6]=='L'){
                V.pop_back();
        }else if(com[0]=='d'){
                scanf("%d",&t);
                for(list<int>::iterator it = V.begin();it!=V.end();it++){
                    if(*it==t){
                        V.erase(it);
                        break;
                    }
                }
            }
    }
    int i=0;

    for(list<int>::iterator it = V.begin();it != V.end();it++){
       if(i++) printf(" ");
        printf("%d",*it);
        }
        
    
    printf("\n");




return 0;
}



Measured memory_bytes: 34620
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 0.0000000000001
//priority_queue<int,vector<int>, greater<int> > q2;

long double nai(int a, int b, int c, int d) {
	return a * c + b * d;
}
int oo(int a, int b) {
	return a * a + b * b;
}
long double ooo(int a, int b) {
	double res = oo(a, b);
	return pow(res, 0.5);
}
int gai(int a, int b, int c, int d) {
	return a * d - b * c;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
	int vx = x1 - x0, vy = y1 - y0;
	;
	int Q; cin >> Q;
	while (Q--) {
		int x2, y2; cin >> x2 >> y2;
		int vvx = x2 - x0, vvy = y2 - y0;

		if ((vx == 0 && vy == 0) || (vvx == 0 && vvy == 0)) {
			cout << "ON_SEGMENT" << endl;
			continue;
		}

		long double ans = nai(vx, vy, vvx, vvy);
		//cout << ans << endl;
		ans /= ooo(vx, vy);
		ans /= ooo(vvx, vvy);
		//cout << ans << endl;
		//printf("%.10lf\n",ans);
		if (-eps < ans  + 1.0L && ans + 1.0L < eps) {
			cout << "ONLINE_BACK" << endl;
		}
		else if(-eps < ans - 1.0L && ans - 1.0L < eps){
			//cout << "K" << endl;
			if (oo(vvx,vvy) > oo(vx,vy)) {
				cout << "ONLINE_FRONT" << endl;
			}
			else {
				cout << "ON_SEGMENT" << endl;
			}
		}
		else {
			if (gai(vx, vy, vvx, vvy) > 0) {
				cout << "COUNTER_CLOCKWISE" << endl;
			}
			else {
				cout<< "CLOCKWISE" <<endl;
			}
		}
	}

	return 0;
}




Measured memory_bytes: 3344
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
//#define int long long


using namespace std;

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


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[9] = { 0, 0,0,1,1,1,-1,-1,-1 };
int dyy[9] = { 0, 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

long long power_mod(long long x, long long n, long long m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return power_mod(x * x % m, n / 2, m);
	else
		return x * power_mod(x, n - 1, m) % m;
}

long long power(long long a, long long n) {//aのn乗を計算します。
	long long x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}



long long nCr(long long n, long long r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	long long i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}



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

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool arr[100000100];
vector<ll>sosuu;
void Eratosthenes() {
	ll N = 10000010;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (ll i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (ll i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu.pb(i);
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}

ll stoL(string s) {
	ll n = s.length();
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += power(10, n - i - 1)*(ll)(s[i] - '0');
	}
	return ans;
}




int main() {
	int A, B; cin >> A >> B;
	if (B%A == 0)print(A + B)
	else print(B - A);
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		int ans=0;
		var hs=new HashSet<string>();
		for(int i = 0;i<n;i++) {
			var t=sc.S;
			if(!hs.Contains(t)){hs.Add(t);ans++;}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 47092
n, m ,l = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for j in range(m)]
c = [[sum(ak*bk for ak, bk in zip(ai, bj)) for bj in zip(*b)] for ai in a]

for ci in c:
    print(*ci)

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

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string s;
    cin>>s;
    string prev,p;
    long long count=1;
    prev=s[0];
    for(int i=1;i<s.length();i++)
    {
        p=s[i];
        if(p!=prev)
        {
            count++;
            prev=p;
        }
        else if(i!=s.length()-1 && p==prev)
        {
            prev=p+s[i+1];
            i++;
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5100000;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  vi a(3);
  int s = 0;
  rep(i,3){
    cin >> a[i];
    s += a[i];
  }
  string ans;
  if(s >= 22) ans = "bust";
  else ans = "win";
  cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
H = list(map(int, input().split()))

L = [[] for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    L[a].append(b)
    L[b].append(a)

ans = 0

for i in range(n):
    h_self = H[i]
    is_good = True
    for j in L[i]:
        if H[j] >= h_self:
            is_good = False
            break
    if is_good:
        ans += 1

print(ans)

Measured memory_bytes: 29516
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    n, m, le = map(int, input().split())
    g1 = (le + 1) * np.zeros((n, n))
    for _ in range(m):
        a, b, c = map(int, input().split())
        if c <= le:
            g1[a - 1, b - 1] = c
            g1[b - 1, a - 1] = c

    fw1 = floyd_warshall(g1, directed=False)

    g2 = 1000 * np.zeros((n, n))
    g2[fw1 <= le] = 1

    fw2 = floyd_warshall(g2, directed=False)

    q = int(input())
    res_list = [-1] * q
    for i in range(q):
        s, t = map(int, input().split())
        res = fw2[s - 1, t - 1]
        if res <= n:
            res_list[i] = int(res - 1)

    for r in res_list:
        print(r)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18204
#include<algorithm> // sort,reverse,min,lower_bound
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

void make_fact(vector<li>& fact,vector<li>& ifact,vector<li>& inv){
  int n=inv.size();
  fact.at(0)=ifact.at(0)=1; inv.at(0)=0;
  fact.at(1)=ifact.at(1)=inv.at(1)=1;
  repa(i,2,n){
    fact.at(i)=fact.at(i-1)*i%MOD;
    inv.at(i)=(MOD-(MOD/i))*inv.at(MOD%i);
    inv.at(i)%=MOD;
    ifact.at(i)=ifact.at(i-1)*inv.at(i)%MOD;
  }
}


void print(vector<li>& v){
  for(li x: v) printf("%ld ",x);
  printf("\n");
}
void print(vector<vector<li>>& v){
  for(vector<li> v0: v){
    for(li x:v0){
      printf("%ld ",x);
    }
    printf("\n");
  }
}

int main(){
  if(df) printf("*debug mode*\n");
  int n,k; cin >>n >>k;
  vector<li> a(n,0),inv(n+1,0),fact(n+1,0),ifact(n+1,0);
  for(li& x:a) cin >>x;
  sort(a.begin(),a.end());
  int m=a.at(0); for(li& x:a) (x-=m)%=MOD;
  make_fact(fact,ifact,inv);
  auto binom=[=](li n,li r)
	     {
	       li s=fact.at(n);
	       (s*=ifact.at(r))%=MOD;
	       (s*=ifact.at(n-r))%=MOD;
	       //	       if(s<0)while(1)printf("err");
	       return s;
	     };
  if(df){
    print(a);
    print(fact);
    print(ifact);
    print(inv);
    rep(i,n){
      rep(j,i+1){
	printf("%ld ",binom(i,j));
      }
      printf("\n");
    }
  }


  
  li plus=0,minus=0;
  rep(i,n-k+1){
    (minus+=a.at(i)*binom(n-i-1,k-1)%MOD)%=MOD;
    //    if(minus<0)while(1)printf("err");
    if(df)printf("minus:%ld",minus);
    (plus+=a.at(n-i-1)*binom(n-i-1,k-1)%MOD)%=MOD;
    //    if(plus<0)while(1)printf("err");
    if(df)printf(" plus:%ld\n",plus);
  }
  printf("%ld",(plus+MOD-minus)%MOD);
}

/// confirm df==0 ///


Measured memory_bytes: 4992
#include <iostream>

#define MAX 1000001

bool is_prime[MAX];

int main(int argc,char* argv[]){
  
  for(int i = 0; i < MAX; i++){
    is_prime[i] = true;
  }

  is_prime[0] = is_prime[1] = false;

  for(int i = 2; i <= 1000; i++){
    if(is_prime[i]){
      for(int j = 2*i; j < MAX; j += i){
	is_prime[j] = false;
      }
    }
  }


  while(true){
    int a,d,n;

    std::cin >> a >> d >> n;

    if(a == 0 && d == 0 && n == 0){
      break;
    }

    int count = 0;
    for(int i = a; i < MAX; i += d){
      if(is_prime[i]){
	count++;
	if(count == n){
	  std::cout << i << std::endl;
	  break;
	}
      }
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 2132
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	int n, k;
	cin >> n >> k;
	int ans = 1<<n;
	for(int i=0;i<=n;i++)
	{
			ans = min(ans,(1<<(n-i)) + k*i);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

const int mod = 998244353;
const int maxn = 500010;
typedef long long ll;

int N, K;
int jc[maxn], ijc[maxn], inv[maxn];

int C(int n, int m) {
    if (n < m) return 0;
 	return 1ll*jc[n]*ijc[m]%mod*ijc[n-m]%mod;   
}

int cal(int n, int m, int T) {
 	return ((C(n+m, n)-C(n+m,m-T-1))%mod+mod)%mod;   
}

int main() {
    scanf("%d%d", &N, &K);
   	inv[1] = 1; jc[0] = ijc[0] = jc[1] = ijc[1] = 1;
    for (int i = 2; i <= K; i++) {
     	inv[i] = mod-1ll*(mod/i)*inv[mod%i]%mod;
        jc[i] = 1ll*jc[i-1]*i%mod;
        ijc[i] = 1ll*ijc[i-1]*inv[i]%mod;
    }
    int ans = 0;
    for (int R = 0; R <= K; R++) {
        int B = K-R;
        if (R == B) {
            if (K >= 2*N) {
                ans = (ans + cal(R, B-1, (K-2*N)/2))%mod;
            }
        } else if (R > B) {
            if (R-B >= N) {
                ans = (ans + C(B+R, B))%mod;
            } else if (R >= N) {
             	ans = (ans + cal(R, B, R-N))%mod;   
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)); return a; }

const ll INF = numeric_limits<ll>::min();

ll n, k;
ll p[5001];
ll c[5001];

int cache[5001];

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

	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> p[i];
	for (int i = 1; i <= n; i++) cin >> c[i];

	ll ans = INF;

	for (int i = 1; i <= n; i++)
	{
		if (cache[i]) continue;

		vector <ll> cv;
		cv.push_back(0);
		ll sum = 0;

		ll sz = 0;
		int v = i;
		while (!cache[v])
		{
			cache[v] = 1;
			v = p[v];

			cv.push_back(c[v]);
			sum += c[v];
			sz++;
		}

		for (int i = 1; i <= sz; i++) cv.push_back(cv[i]);
		for (int i = 1; i < cv.size(); i++) cv[i] += cv[i - 1];

		ll res = INF;
		for (int len = 1; len <= min(k, (ll)cv.size() - 1); len++)
		{
			for (int st = 0; st + len < cv.size(); st++)
			{
				ll cSum = cv[st + len] - cv[st];
				ll rm = (k - len) / sz;

				if (sum > 0) cSum += rm * sum;

				res = max(res, cSum);
			}
		}

		ans = max(ans, res);
	}

	cout << ans;
}

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

const int SIZE = 1000;
int c[SIZE+1][SIZE+1][3];

const char *JOI = "JOI";

int main() {
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < 3; j++) {
            c[i][0][j] = c[0][i][j] = 0;
        }
    }
    int m, n;
    while (cin >> m >> n) {
        int k;
        cin >> k;
        for (int i = 1; i <= m; i++) {
            string s;
            cin >> s;
            for (int j = 1; j <= n; j++) {
                for (int k = 0; k < 3; k++) {
                    c[i][j][k] = c[i][j-1][k] + c[i-1][j][k] - c[i-1][j-1][k] + (s[j-1] == JOI[k]);
                }
            }
        }
        for (int i = 0; i < k; i++) {
            int x[2], y[2];
            cin >> y[0] >> x[0] >> y[1] >> x[1];
            for (int j = 0; j < 3; j++) {
                if (j > 0) {
                    cout << " ";
                }
                cout << c[y[1]][x[1]][j] - c[y[1]][x[0]-1][j] - c[y[0]-1][x[1]][j] + c[y[0]-1][x[0]-1][j];
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 12864
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsProgramSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] u = (Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray());
            Console.WriteLine(string.Format("{0} {1} {2:F5}", u[0] / u[1], u[0] % u[1], (double)u[0] / u[1]));
        }
    }
}


Measured memory_bytes: 18440
using System;
 
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int x = int.Parse(input[0]);
    int a = int.Parse(input[1]);
    int b = int.Parse(input[2]);
    
    int xa, xb;
    
    if(x < a) xa = a - x;
    else xa = x - a;
    
    if(x < b) xb = b - x;
    else xb = x - b;
    
    if(xa < xb) Console.WriteLine("A");
    else Console.WriteLine("B");
  }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int ch[54];
ll n;
ll a[51],b[51];
ll p[51];
bool check()
{
	for (int i = 0; i < n; i++) {
		memset(p, 0, sizeof(p));
		p[a[i]] = 1;
		for (int y = a[i]; y >= 0; y--)
		{
			if (p[y]) {
				for (int z = 1; z <=y; z++)
				{
					if (!ch[z]) {
						p[y%z] = 1;
					}
				}
			}
		}
		if (p[b[i]] == 0)return 0;
	}
	return 1;
}
int main()
{
	scanf("%lld", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	for (int i = 0; i < n; i++)
		scanf("%lld", &b[i]);
	if (!check())
	{
		puts("-1");
		return 0;
	}
	ll dap = 0;
	for (ll i = 50; i >= 0; i--)
	{
		ch[i] = 1;
		if (!check()) {
			ch[i] = 0;
			dap += ((ll)1 << i);
		}
	}
	printf("%lld\n", dap);
}

Measured memory_bytes: 128
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int happynesspoint,k,j;
		if(n>=0){
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	}
}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 998244353;

template <int MOD = 1000000007>
struct Mint {
    int x;

    Mint() : x(0) {}
    Mint(long long t) {
        x = t % MOD;
        if (x < 0) x += MOD;
    }

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n, s;
    cin >> n >> s;
    int a[n];
    rep(i, n) {
        cin >> a[i];
    }
    Mint<MOD> dp[n + 1][s + 1];
    dp[0][0] = 1;
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= s; j++){
            dp[i + 1][j] += dp[i][j] * 2;
            if (j - a[i] < 0) continue;
            dp[i + 1][j] += dp[i][j - a[i]];
        }
    }
    cout << dp[n][s] << endl;
    return 0;
}

Measured memory_bytes: 38756
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(){
int N ;
cin >> N ;
vector<vector<int> > task(N,vector<int>(2)) ;
for (int i = 0; i < N; i++)
{
    // !!! 締め切りを要素1,所要時間を要素2に入れている
    cin >> task.at(i).at(1) >> task.at(i).at(0) ;
}
vector<pair<int, int> > pairs(N);
for (int i = 0; i < N; i++) {
    pairs[i] = make_pair(task.at(i).at(0), task.at(i).at(1));
  }
sort(pairs.begin(),pairs.end()) ;
for (int i = 0; i < N; i++)
{
    task.at(i).at(0) = get<0>(pairs[i]) ;
    task.at(i).at(1) = get<1>(pairs[i]) ;
}
bool ans = true ;
int time = 0 ;
for (int i = 0; i < N; i++)
{
    time += task.at(i).at(1) ;
    if (time > task.at(i).at(0))
    {
        ans = false ;
        break ;
    }
    
}
if (ans == false)
{
    cout << "No" << endl;
}
if (ans == true)
{
    cout << "Yes" << endl;
}

}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define MOD (long long)(1e9+7)
typedef long long int ll;
typedef unsigned long long int ull;

ll modularExponentiation(ll x, ll y, ll  p){
  ll res = 1;
  x = x % p;
  while (y > 0){
      if (y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
  }
  return res;
}

bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t=1;
  // cin>>t;
  while(t--){
    ll n, x, y;
    cin>>n>>x>>y;
    vector<ll> ans(n, 0);

    for(int j=1;j<n+1;j++){
      for(int i=j+1;i<n+1;i++){
        if(abs(i-j)>(abs(x-j)+1+abs(i-y))) ans[abs(x-j)+1+abs(i-y)]++;
        else ans[i-j]++;
      }
    }
    for(int i=1;i<n;i++){
      cout<<ans[i]<<endl;
    }
  }
  return 0;
}


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

using namespace std;
typedef long long ll;

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

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

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

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

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

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

int n,m;
int a[50],b[50];

bool graph[50][50];
bool visited[50];

void dfs(int v){
  visited[v] = true;
  for(int i = 0; i < n; i++){
    if(graph[v][i]==false) continue;
    else if(visited[i]==true) continue;
    dfs(i);
  }
}

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

Measured memory_bytes: 256
#アンバランスな文字列からアンバランスでない文字列を取り除くと、
#アンバランスな文字列が残るはず。ということは、両側から文字を削り取ることで「どの部分列をとってもアンバランスな文字列」が存在するはず
#すなわちそれは、両側に「ax」が存在しない文字列で、「axa」または「aa...aa」
#aaがある時点でアンバランス確定なので「axa」「aa」のどちらかを探せばよし
import re
s=input()
alphabet="abcdefghijklmnopqrstuvwxyz"
for i in alphabet:
    ba=s.find(i+i)
    if ba!=-1:
        print(str(ba+1)+" "+str(ba+2))
        break
    A=re.compile(i+"."+i)
    axa=A.search(s,0)
    if axa:
        ba=axa.start()
        print(str(ba+1)+" "+str(ba+3))
        break
    if i=="z":
        print("-1 -1")

Measured memory_bytes: 3316
#https://atcoder.jp/contests/abc076/tasks/abc076_c
import re
def solve(s,t):
    sc = s.replace("?",".")
    if lt > ls:
        return "UNRESTORABLE"
    ans = []
    s = s.replace("?","a")    
    for i in range(ls-lt+1):
        if re.match(sc[i:i+lt], t) is None:
            continue
        ans.append(s[:i]+ t + s[i+lt:])
    if not ans:
        return "UNRESTORABLE"
    return min(ans) 

S = input()
T = input()
ls = len(S)
lt = len(T)

print(solve(S,T))


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

using namespace std;

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

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n;
	string s, t;
	cin >> n >> s;
	for(char c : s){
		if(t == "" || t[t.size() - 1] != c) t += c;
	}
	cout << t.size() << endl;
	
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	ll N, M, ans=0;

	cin >> N >> M;

	if( N > M ) swap(N, M);

	if( N == 1 && M == 1 ){
		cout << 1 << endl;
	}else if( N == 1 ){
		cout << M-2 << endl;
	}else{
		cout << (N-2)*(M-2) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
// numeric_limits<int>::max()

int main(void)
{
    string S;
    cin >> S;
    int first = (S[0] - 48) * 10 + S[1] - 48;
    int second = (S[2] - 48) * 10 + S[3] - 48;
    bool isFirstMonth = (first >= 1 && first <= 12);
    bool isSecondMonth = (second >= 1 && second <= 12);
    if (isFirstMonth && isSecondMonth)
        cout << "AMBIGUOUS" << endl;
    else if (isFirstMonth)
        cout << "MMYY" << endl;
    else if (isSecondMonth)
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    static Scanner scanner;

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

        long N=gl();
        long all=modpow(10, N, 1000000007);
        long nz=modpow(9, N, 1000000007);
        long nr=modpow(8, N, 1000000007);
        long ty = (all -nz -nz + 1000000007 *2 + nr) % 1000000007;
        long ans = (all + 1000000007 - ty) % 1000000007;

        System.out.println(ty);
    }

 // a^nをmodで割ったあまり
    public static long modpow(long a, long n, long mod) {
        long res=1;
        while(n>0) {
            if((n & 1) == 1) res=res*a%mod;
            a=a*a%mod;
            n=n>>1;
        }

        return res;
    }

    // 文字列として入力を取得
    public static String gs() {
         return scanner.next();
    }

    // intとして入力を取得
    public static int gi() {
         return Integer.parseInt(scanner.next());
    }

    // longとして入力を取得
    public static long gl() {
         return Long.parseLong(scanner.next());
    }

    // doubleとして入力を取得
    public static double gd() {
         return Double.parseDouble(scanner.next());
    }
}

Measured memory_bytes: 35580
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nx = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        for (var i = 0; i < nx[0]; i++)
            ar[i] = Abs(nx[1] - ar[i]);
        var gc = 0;
        for(var i = 0; i < nx[0]; i++)
        {
            if (gc == 0 && ar[i] != 0) gc = ar[i];
            else if (gc != 0 && ar[i] != 0) gc = Calculation.GCD(gc, ar[i]);
        }
        WriteLine(gc);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}
public class Calculation
{
  public static int GCD(int num1, int num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }
}

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

int main(){
	int n, m=200005, cnt=0;
	cin>>n;
	int a[n];
	for (int i=0; i<n; i++)
		cin>>a[i];
	for (int i=0; i<n; i++){
		if (a[i]<m)
			cnt++;
		m=min(a[i],m);
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
  int S,h,m,s,a,b;

  scanf("%d",&S);

  if(S<0 || 86400<S){
    printf("Error!!\n");
  }else{
    h=S/3600;
    a=h*3600;
    
    m=(S-a)/60;
    b=m*60;
    
    s=(S-a-b);
    printf("%d:%d:%d\n",h,m,s);
  }   
  return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
 
ll n;
ll a[1000009];
ll dp[1000009];
ll bt(ll pos)
{
    if(pos== n*3-2 ||pos==n*3-1 ||pos==n*3)
        return 0;
   
     if(dp[pos]!=-1)
        return dp[pos];
 ll ans=0;
    if(pos==0)
    {ans=max(bt(1)+a[1],bt(2)+a[2]);
        ans=max(ans,bt(3)+a[3]);
        return ans;
    }
 
 
    if(pos%3==1)
    {
        ans=max(bt(pos+5)+a[pos+5],bt(pos+4)+a[pos+4]);
        dp[pos]=ans;
    }
    else if(pos%3==2)
    {
        ans=max(bt(pos+2)+a[pos+2],bt(pos+4)+a[pos+4]);
        dp[pos]=ans;
 
    }
    else
 
    {
        ans=max(bt(pos+1)+a[pos+1],bt(pos+2)+a[pos+2]);
        dp[pos]=ans;
 
    }
 
    return ans;
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=1; i<=n*3; i++)
        cin>>a[i];
    cout<<bt(0)<<endl;
}

Measured memory_bytes: 13568
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    int sum;
    int minv=1000000007;
    for(int p=1;p<=100;p++){
        sum=0;
        for(int i=0;i<n;i++){
            sum+=(x[i]-p)*(x[i]-p);
        }
        minv=min(minv,sum);
    }
    cout<<minv<<'\n';
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> arr(n), res(n, 1e9);
    res[0] = 0;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        for (int j = i - 1; j >= 0 && j >= i - k; --j)
            res[i] = min(res[i], res[j] + abs(arr[i] - arr[j]));
    }
    cout << res[n - 1];
    return 0;
}


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

int cmp(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a > b ? -1 : a < b;
}

int main(void) {
	int N, K;
	int l[64];
	int i;
	int sum = 0;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &l[i]) != 1) return 1;
	}
	qsort(l, N, sizeof(*l), cmp);
	for (i = 0; i < K; i++) sum += l[i];
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int main(){
    double l, r, v;
    cin >> l;
    r = l / 3.0;
    v = r * r * r;
    cout << fixed << setprecision(8) <<  v << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
int main(){
	fast;
	ll t,n,k; cin>>n>>k;
	vector<ll> arr(n);
	for(auto &it:arr)cin>>it;
	sort(arr.begin(), arr.end());
	ll s=0;
	for(auto i=0;i<k;++i)s+=arr[i];
	cout<<s<<'\n';
	return 0;
}

Measured memory_bytes: 3620
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	n = len(l)
	

N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
d = dict(Counter(l))
if(len(d) == N):
	print("YES")
else:
	print("NO")


Measured memory_bytes: 40520
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000
vector<vector<int>> E;
vector<int> X;

int dfs(int now){
	if(E[now].size()==0)return 0;
	bitset<5001> B;
	B[0] = true;
	int sum = 0,sum2= 0;
	for(int i=0;i<E[now].size();i++){
		int to = E[now][i];
		int a = X[to];
		int b = dfs(to);
		if(b==-1)return -1;
		sum += min(a,b);
		sum2+=abs(a-b);
		B |= B<<abs(a-b);
	}
	if(sum>X[now])return -1;
	for(int i=0;i<=5000;i++){
		if(B[i]){
			if(sum+(sum2-i)<=X[now])return i;
		}
	}
	return 5001;
}

int main(){
	
	int N;
	cin>>N;
	
	E.resize(N,vector<int>());
	
	for(int i=0;i<N-1;i++){
		int p;
		cin>>p;
		E[p-1].push_back(i+1);
	}
	
	X.resize(N);
	for(int i=0;i<N;i++)cin>>X[i];
	
	int t = dfs(0);
	
	if(t==-1)cout<<"IMPOSSIBLE"<<endl;
	else cout<<"POSSIBLE"<<endl;
	
	return 0;
}

Measured memory_bytes: 4508
#include <bits/stdc++.h>
using namespace std;
int main () {
  long X;
  cin >> X;
  long ans = X, sum;
  for(long i = 1; i <= X; i++) {
    sum = i * (i + 1) / 2;
    if(X <= sum) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
require 'pp'

###################

inputType = :singleLine
# inputType = :2Lines
# inputType = :nLines
  
def main(query)
  n = query[0]
  s = 0
  n.chars.map { | x | s = s + x.to_i}
  if s % 9 == 0 then
    return ["Yes"]
  else
    return ["No"]
  end
end

###################

TEST=false

def tois(l)
  l.map { | x | x.to_i}
end

def ppp(msg, val)
  if (TEST) then
    print msg
    pp val
  end
end

target = nil
if (ARGV.size == 0) then
  f = STDIN
end
if (ARGV.size > 0) then
  f = open(ARGV[0])
end
if (ARGV.size > 1) then
  target = ARGV[1].to_i
end

t = 1
ng = []
while true
  query = []
  if (inputType == :singleLine) then
    a = f.gets
    if ! a then
      exit
    end
    a.chomp!
    query.push a
  elsif (inputType == :l2Lines) then
    a = f.gets
    if ! a then
      exit
    end
    a.chomp!
    query.push a
    b = f.gets.chomp
    query.push b
  elsif (inputType == :l3Lines) then
    a = f.gets
    if ! a then
      exit
    end
    a.chomp!
    query.push a
    b = f.gets.chomp
    query.push b
    c = f.gets.chomp
    query.push c
  elsif (inputType == :nLines) then
    a = f.gets
    if ! a then
      exit
    end
    a.chomp!
    query.push a    

    n = a.split(" ")[2].to_i

    query = n.times { | i |
      query.push f.gets.chomp
    }    
  end
  
  aa = f.gets
  if ! aa then
    r = main(query) 
    r.each { | x | puts x }
    exit
  elsif ( aa.chomp == "---") then
    oks = []
    while true
      s = f.gets.chomp
      if (s == "===") then
        break
      end
      oks.push s
    end

    if (target == nil || t == target) then
      if target then
        TEST = true
      end

      puts "--- " + t.to_s + " ---"
      r = main(query)    

      if r.join('\n') == oks.join('\n') then
        puts "RESULT:"
        r.each { | x | puts x }
        puts "OK"
      else
        puts "RESULT:NG"
        r.each { | x | puts x }
        puts "NG!!!!!!!!!"
        ng.push t
      end
    end
  end
  t = t + 1
end
puts "---"
puts "NG targes = " + ng.to_s


Measured memory_bytes: 26164
#include<bits/stdc++.h>
#include<unistd.h>
#define int long long
const int inf=8938103643641919514ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int a,b,c,d;
int p[800][800],q[800][800];
int kyori(pair<int,int> x){
	int n=x.first;
	n=min(n,x.second);
	n=min(n,a-x.first-1);
	n=min(n,b-x.second-1);
	return n;
}
signed main(){
	int i,j;
	for(i=0;i<800;i++)
		for(j=0;j<800;j++)
			q[i][j]=inf;
	int u,v;
	cin>>a>>b>>c;
	for(i=0;i<a;i++){
		string s;
		cin>>s;
		for(j=0;j<b;j++){
			if(s[j]=='#')
				p[i][j]=1;
			if(s[j]=='S'){
				u=i;
				v=j;
			}
		}
	}
	queue<pair<int,int> > que;
	vector<pair<int,int> > ve;
	que.push({u,v});
	q[u][v]=0;
	while(!que.empty()){
		auto x=que.front();
		que.pop();
		int z=q[x.first][x.second];
		if(z>c)
			break;
		ve.push_back(x);
		for(i=0;i<4;i++){
			int uu=x.first+dd[i];
			int vv=x.second+dd[i+1];
			if(uu>=0&&uu<a&&vv>=0&&vv<b&&p[uu][vv]==0&&q[uu][vv]>z+1){
				q[uu][vv]=z+1;
				que.push({uu,vv});
			}
		}
	}
	int ans=inf;
	for(auto x:ve)
		ans=min(ans,1+(kyori(x)+c-1)/c);
	cout<<ans<<endl;
}

Measured memory_bytes: 28008
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const [target, needle] = content.trim().split('\n');
  console.log(ringedIncludes(target, needle) ? 'Yes' : 'No'); 
});

const ringedIncludes = (target, needle) => {
  for (let i = 0; i < target.length; i++) {
    const includes = ringed(target, i, needle.length) === needle;
    if (includes) {
      return true;
    }
  }

  return false;
};

const ringed = (s, offset, size) => {
  if (s.length >= offset + size) {
    return s.substring(offset, offset + size);
  } else {
    return s.substring(offset) + ringed(s, 0, size - s.length + offset);
  }
};



Measured memory_bytes: 19360
N,M= map(int,input().split())
X = list(map(int,input().split()))

if M < N:
    print(0)
    exit()

X = sorted(X)

if N == 1:
    print(X[M-1]-X[0])
    exit()

distance = []
for i in range(M-1):
    distance.append(X[i+1] - X[i])

distance = sorted(distance,reverse=True)

sum = 0
for j in range(N-1):
    sum = sum + distance[j]

print(X[M-1]-X[0]-sum)

Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1<<30

int main()
{
    ll n,k,x,y;
    cin>>n>>k>>x>>y;
    ll total=0;
    if(n<=k)
    {
        cout<<n*x;
    }
    else if(n>k)
    {
        cout<<k*x+(abs(n-k)*y);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
using ll = long long;

int n;

vector<pair<int, int>> number(vector<int> v){
	vector<pair<int, int>> ans(2);
	int  now = 0, len = 0;
	for (int i = 0; i < n / 2; i++){
		if (v[i] != now){
			if (ans[0].first < len)swap(ans[0], ans[1]),ans[0].first = len, ans[0].second = now;
			else if (ans[1].first < len)ans[1].first = len, ans[1].second = now;
			len = 0, now = v[i];
		}
		len++;
	}
	if (ans[0].first < len)swap(ans[0], ans[1]),ans[0].first = len, ans[0].second = now;
	else if (ans[1].first < len)ans[1].first = len, ans[1].second = now;

	return ans;
}

int main(){
	cin >> n;
	vector<int> p(n/2), q(n/2);
	for (int i = 0; i < n; i++){
		if (i % 2 == 0)cin >> p[i/2];
		else cin >> q[i/2];
	}
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	vector<pair<int, int>> a = number(p), b = number(q);
	if (a[0].second != b[0].second)cout << n - a[0].first - b[0].first << endl;
	else if (a[1].first > b[1].first)cout << n - a[1].first - b[0].first << endl;
	else cout << n - a[0].first - b[1].first << endl;
}

Measured memory_bytes: 828
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    X = SS()

    # 一回の操作でnはN以下になる
    # 2回目以降の操作はメモ化再帰
    # 初回popcountは2種類しかない Xのpopcountから足し引きすればよい

    pc_X = X.count('1')

    if pc_X == 0:
        for i in range(N):
            print(1)
    elif pc_X == 1:
        for i in range(N):
            if i == X.index('1'):
                print(0)
            else:
                # 1が2つある場合、最後の位が1の場合、奇数
                if i == N - 1 or X.index('1') == N - 1:
                    print(2)
                else:
                    print(1)
    else:
        next_X_m1 = 0
        next_X_p1 = 0
        pc_m1 = pc_X - 1
        pc_p1 = pc_X + 1
        for i in range(N):
            if X[i] == '1':
                next_X_m1 += pow(2, N - 1 - i, pc_m1)
                next_X_p1 += pow(2, N - 1 - i, pc_p1)
        dp = [-1] * N
        dp[0] = 0

        def dfs(n):
            if dp[n] == -1:
                dp[n] = 1 + dfs(n % bin(n).count('1'))
            return dp[n]

        for i in range(N):
            next = 0
            if X[i] == '0':
                next = (next_X_p1 + pow(2, N - 1 - i, pc_p1)) % pc_p1
            else:
                if pc_m1 >= 1:
                    next = (next_X_m1 - pow(2, N - 1 - i, pc_m1)) % pc_m1
                else:
                    next = next_X_m1 - pow(2, N - 1 - i)

            if pc_X == 1 and X[i] == '1' and i == N - 1:
                ans = 0
            else:
                ans = dfs(next) + 1
            print(ans)
    # print(dp)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 12024
#include <iostream>
#include <map>
using namespace std;
int main() {
    int n, a;
    cin >> n;
    map<int, int> mp;
    while (cin >> a) {
        mp[a] = (mp[a] + 1) % 2;
    }
    int cnt = 0;
    for (auto iter=mp.begin(); iter!=mp.end(); iter++) {
        cnt += iter->second;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 8112
while 1:
    n = int(raw_input())
    if not n: break
    cnt = 0
    m = cnt
    t = []
    for i in xrange(n):
        a = raw_input().split()
        t.append((a[0],2))
        t.append((a[1],1))
    t.sort()
    for i in xrange(len(t)):
        #print t[i]
        if t[i][1] is 2: cnt += 1
        else: cnt -= 1

        m = max(m, cnt)

    print m

Measured memory_bytes: 6804
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int n;
ll a[100001];
ll c[100001];
ll s[100001];

ll solve(bool plus,ll ans){
		if(plus==1){
				if(a[0]<=0){ans=1-a[0];a[0]=1;s[0]=1;}
				else s[0]=a[0];
		}else{
				if(a[0]>=0){ans=a[0]+1;a[0]=-1;s[0]=-1;}
				else s[0]=a[0];
		}
		for(int i=0;i<n-1;i++){
				ll t=s[i]+a[i+1];
				if(s[i]*t>=0){
						if(s[i]<0){
								ll b=a[i+1];
								s[i+1]=1;
								a[i+1]=s[i+1]-s[i];
								ans+=(a[i+1]-b);
						}else if(s[i]>0){
								ll b=a[i+1];
								s[i+1]=-1;
								a[i+1]=s[i+1]-s[i];
								ans+=(b-a[i+1]);
						}
				}else{
						s[i+1]=t;
				}
		}
		//for(int i=0;i<n;i++)cout<<s[i]<<endl;
		//cout<<ans<<endl;
		return ans;
}

int main(){
		cin>>n;
		for(int i=0;i<n;i++){cin>>a[i];c[i]=a[i];}
		ll ans1=solve(1,0);
		for(int i=0;i<n;i++){a[i]=c[i];}
		ll ans2=solve(0,0);
		cout<<min(ans1,ans2)<<endl;
		return 0;
}


Measured memory_bytes: 2560