akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n;
ll k;
map<int,ll>mp;
int main(){
	scanf("%d%lld",&n,&k);
	for(int i=1,x,y;i<=n;i++){
		scanf("%d%d",&x,&y);
		mp[x]+=y;
	}
	ll s=0;
	for(auto p:mp){
		if(s+p.se<k) s+=p.se;
		else {
			printf("%d",p.fi);
			break;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    cout<<setprecision(6)<<fixed;
    int len;
    double p1=0, p2=0, p3=0, pI=0, aux;
    cin>>len;
    double vect1[len], vect2[len];
    for(int i = 0; i<len; i++)
        cin>>vect1[i];
    for(int i = 0; i<len; i++)
        cin>>vect2[i];
    for(int i = 0; i<len; i++)
    {
        aux = abs(vect1[i] - vect2[i]);
        p1 += aux;
        p2 += pow(aux, 2);
        p3 += pow(aux, 3);
        pI = max(pI,aux);
    }
    cout<<p1<<endl;
    cout<<sqrt(p2)<<endl;
    cout<<cbrt(p3)<<endl;
    cout<<pI<<endl;
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    if(A+B > C+D){
        cout << "Left" << endl;
    }
    else if(A+B == C+D){
        cout << "Balanced" << endl;
    }
    else{
        cout << "Right" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def to_isp(i, s):
    sp = s.split(' ')
    return (i+1, sp[0], int(sp[1]))

def main():
    N = i2n()
    SP = [to_isp(i, s) for i, s in enumerate(ii2ss(N))]
    SP.sort(key=lambda v: v[2])
    SP.reverse()
    SP.sort(key=lambda v: v[1])
    for i, s, p in SP:
        print(i)

main()


Measured memory_bytes: 38384
s1=input()
s2=input()
l1,l2=len(s1),len(s2)
dp=[[0]*(l2+1) for _ in range(l1+1)] #s1のi文字目、s2のj文字目までの編集距離をdp[i][j]とする
for i in range(l1+1):
    dp[i][0]=i
for j in range(l2+1):
    dp[0][j]=j
for i in range(1,l1+1):
    for j in range(1,l2+1):
        dp[i][j]=min(dp[i][j-1]+1,dp[i-1][j]+1,dp[i-1][j-1]+(s1[i-1]!=s2[j-1]))
print(dp[l1][l2])


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)

using namespace std;

struct Data{
  int x,y,dir,P,Q,cost,px,py;
  Data(int x=IINF,int y=IINF,int dir=IINF,int P=IINF,int Q=IINF,int cost=IINF,int px=IINF,int py=IINF):x(x),y(y),dir(dir),P(P),Q(Q),cost(cost),px(px),py(py){}
  bool operator < (const Data& a)const{
    return P+Q < a.P+a.Q;
  }
};

int H,W,A,sp_x,sp_y;
char field[101][101];
int mincost[101][101][11][11][4];
int dx[] = {1,0,-1,0}; // 右、下、左、上
int dy[] = {0,1,0,-1};

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

inline int getType(int c_dir,int n_dir){
  if( c_dir == 0 ){
    if( n_dir == 3 ) return 0; // P -> 0, Q -> 1
    if( n_dir == 1 ) return 1;
  } else if( c_dir == 1 ){
    if( n_dir == 2 ) return 0;
    if( n_dir == 0 ) return 1;
  } else if( c_dir == 2 ){
    if( n_dir == 1 ) return 0;
    if( n_dir == 3 ) return 1;
  } else{
    if( n_dir == 0 ) return 0;
    if( n_dir == 2 ) return 1;
  }
  return -1;
}

int main(){
  cin >> H >> W >> A;
  rep(i,H)rep(j,W){
    cin >> field[i][j];
    if( field[i][j] == 'S' ) sp_x = j, sp_y = i;
  }

  rep(i,H)rep(j,W)rep(k,A+1)rep(l,A+1)rep(m,4)mincost[i][j][k][l][m] = IINF;
  priority_queue<Data> Q;
  if( isValid(sp_x+dx[1],sp_y+dy[1]) && field[sp_y+dy[1]][sp_x+dx[1]] != '#' ){
    Q.push(Data(sp_x+dx[1],sp_y+dy[1],3,A,A,1,sp_x,sp_y));
    mincost[sp_y][sp_x][A][A][3] = 1;
  }
  while(!Q.empty()){
    Data data = Q.top(); Q.pop();
    int x = data.x, y = data.y;
    if( field[y][x] == 'G' ){
      cout << 2*A-(data.P+data.Q) << endl;
      return 0;
    }
    rep(i,4){
      if( i == data.dir ) continue;
      int nx = x + dx[i], ny = y + dy[i];
      if( field[ny][nx] == 'S' && i == 3 ) continue;
      if(!isValid(nx,ny))continue;
      if(field[ny][nx] == '#')continue;
      int next_P = data.P, next_Q = data.Q;
      int type = getType(data.dir,i);
      if( type == 0 ) next_P--;
      if( type == 1 ) next_Q--;
      if( type != -1 && field[y][x] == 'S' ) continue;
      if( next_P < 0 || next_Q < 0) continue;
      if(mincost[ny][nx][next_P][next_Q][i] > data.cost+1){
	mincost[ny][nx][next_P][next_Q][i] = data.cost+1;
	Q.push(Data(nx,ny,(i+2)%4,next_P,next_Q,data.cost+1,x,y));
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 19444
import scala.io.StdIn
import scala.collection.mutable.{ Map => MMap }

object Main {
  def main(args: Array[String]) = {
    val Seq(n, m, _*) = StdIn.readLine.split(" ").map(_.toInt).toSeq
    val coins = StdIn.readLine.split(" ").map(_.toInt)
    val dp = MMap[Int, Int]()
    val result = coin(n, dp, coins)
    println(result)
  }

  def coin(n: Int, dp: MMap[Int, Int], coins: Seq[Int]): Int = {
    if (coins contains n) {
      dp(n) = 1
      return 1
    }
    if (dp contains n) {
      return dp(n)
    }
    val res = coins.map(n - _).filter(_ > 0).map(coin(_, dp, coins)).min + 1
    dp(n) = res
    res
  }
}



Measured memory_bytes: 446448
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a==b&&b==c)cout<<"No";
	else if(a==b||a==c||b==c)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(ll i=k;i<n;i++)
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define xx first
#define yy second
#define MOD 1000000007
#define pb push_back
typedef long long ll;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}


int t[100000];
int dp[100000];
int n;

int slv(int i){
	int & ret = dp[i];
	if(ret != -1) return ret;
	if(i == n-1){
		return ret = 0;	
	}
	if(i == n - 2){
		return ret = abs(t[i] - t[i+1]); 
	}
	return ret = min(abs(t[i] - t[i+1]) + slv(i+1),abs(t[i] - t[i+2]) + slv(i+2));
}

int main(){
	FAST
	cin >> n;
	rep(i,n) cin >> t[i];
	memset(dp,-1,sizeof(dp));
	cout << slv(0) << endl;
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

int gcd(int a,int b){
   if(a%b==0) return b;
   return gcd(b,a%b);
}
int digit(int num){
   int cnt=0;
   while(num!=0){
      cnt+=num%10;
      num=num/10;
   }
   return cnt;
}
int main(void){
   long long A,B,C;
   cin>>A>>B>>C;
   if(A+B>=C){
      cout<<B+C<<endl;
   }else{
      cout<<B+(B+A+1)<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
#define MAX 10010
using namespace std;
int N,M;
struct P
{
  int to,d,c;
  P(int to=-1,int d=-inf,int c=-inf):to(to),d(d),c(c){}
};

struct Pox
{
  int p,cost;
  Pox(int p=-1,int cost=-inf):p(p),cost(cost){}
  bool operator < (const Pox &a)const
  {
    return cost > a.cost;
  }
};

vector<vector<P> > G(MAX);
int mincost[MAX];
int mixico[MAX];

int dijkstra()
{
  rep(i,N)mincost[i] = mixico[i] = inf;
  mincost[0] = 0;
  priority_queue<Pox> Q;
  Q.push(Pox(0,0));
  while(!Q.empty())
    {
      Pox pox = Q.top(); Q.pop();

      rep(i,G[pox.p].size())
	{
	  P p = G[pox.p][i];

	  if(mincost[p.to] >= pox.cost + p.d)
	    {
	      if(mincost[p.to] == pox.cost + + + + + + + + + + + + + + + + + + + + + + -  - p.d)
		mixico[p.to] = min(mixico[p.to],p.c);
	      else 
		mixico[p.to] = p.c;
	      mincost[p.to] = pox.cost + p.d;
	      
	      Q.push(Pox(p.to,pox.cost+p.d));
	    }
	}
    }
  //rep(i,N)cout << mincost[i] << " : " << mixico[i] << endl;

  int sum = 0;
  REP(i,1,N)sum += mixico[i];
  return sum;
}

int main()
{
  //cout << 1 - - + + + + - 1 << endl;
  while(cin >> N >> M,N|M)
    {
      rep(i,N)G[i].clear();

      rep(i,M)
	{
	  int u,v,d,c;
	  cin >> u >> v >> d >> c;	 
	  u = u - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1;
	  v = v - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1;
	  G[u].push_back(P(v,d,c));
	  G[v].push_back(P(u,d,c));
	}  

      cout << dijkstra() << endl;
    }
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int A, B, C;
    cin >> A >> B >> C;
    if(C > A - B) {
        cout << C - (A - B) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


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

int A[2000001],H;

void maxheapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;
  if(l<=H && A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest]) largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxheapify(largest);
  }
}
  
int main(){
  cin>>H;
  for(int i=1;i<=H;i++) cin>>A[i];
  for(int i=H/2;i>=1;i--) maxheapify(i);
  for(int i=1;i<=H;i++){
    cout<<" "<<A[i];
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 5000
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

itn main() {
	std::ios::sync_with_stdio(false);

	string s;

	cin >> s;

	REP(i, s.size()) {
		s[i] = 'x';
	}

	cout << s << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h, w;cin>>h>>w;
	string s[h];
	for(int i = 0; i < h;++i) cin>>s[i];
	int L[h][w], R[h][w], D[h][w], U[h][w];
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w;++j){
			if(s[i][j]=='#'){
				L[i][j] = 0;
				R[i][j] = 0;
				D[i][j] = 0;
				U[i][j] = 0;
			}
			else{
				if(j==0){
					L[i][j] = 1;
				} else{
					L[i][j] = L[i][j-1] + 1;
				}
				if(i==0){
					U[i][j] = 1;
				} else{
					U[i][j] = U[i-1][j] + 1;
				}
			}
		}
	}
	for(int i = h - 1; i >=0;--i){
		for(int j = w - 1; j>=0; --j){
			if(s[i][j]=='.'){
				if(j==w-1){
					R[i][j] = 1;
				} else{
					R[i][j] = R[i][j + 1] + 1;
				}
				if(i==h-1){
					D[i][j] = 1;
				} else{
					D[i][j] = D[i+1][j] + 1;
				}
			}
		}
	}
	int mx = 0;
	for(int i =0; i < h;++i){
		for(int j = 0; j < w; ++j){
			mx = max(mx, L[i][j] + R[i][j] + U[i][j] + D[i][j]);
		}
	}
	cout<<mx - 3<<endl;
	return 0;
}



Measured memory_bytes: 67072
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int n,m; 

int dist(int a, int b)
{
	return min(abs(a-b),n-abs(a-b));
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m;
	int hf = (n-1)/2;
		vector<ii> pairs(hf);
		set<int> S;
		int diff=1;
		set<int> S2;
		for(int i=hf-1;i>=0;i--)
		{
			if(n%2==1)
			{
				pairs[i].fi=i;
				pairs[i].se=2*hf-1-i;
			}
			else
			{
				pairs[i].fi=i;
				pairs[i].se=2*hf-1-i;
				/*
				if(i==(hf-3)/2)
				{
					diff=2;
				}
				if(i<=(hf-3)/2)
				{
					pairs[i].se=(i-diff+n*100)%n;
				}
				diff+=2;
				*/
				if(i<hf/2) pairs[i].se++;
			}
			//cerr<<pairs[i].fi<<' '<<pairs[i].se<<'\n';
			S.insert(dist(pairs[i].fi,pairs[i].se));
			S2.insert(pairs[i].fi);S2.insert(pairs[i].se);
		}
		assert(S.size()==hf);
		assert(S2.size()==hf*2);
		//cerr<<"Case "<<n<<" complete\n";
	
	
	for(int i=0;i<m;i++)
	{
		cout<<pairs[i].fi+1<<' '<<pairs[i].se+1<<'\n';
	}
	
}


Measured memory_bytes: 17124
#include<iostream>
using namespace std;
int main(){
  int a,b,c,many,n;
  while(cin >> a >> b >> c, a){
    many = a+b+c;
    int parts[many];
    for(int i=0;i<many;i++){
      parts[i]=2;
    }
    cin >> n;

    int res[1000][4];
    bool state[1000];    
    for(int i=0;i<n;i++){ //表入力
      cin >> res[i][0] >> res[i][1] >> res[i][2] >> state[i];
      res[i][0]--;
      res[i][1]--;
      res[i][2]--;
      if(state[i]){
	parts[res[i][0]]=1;
	parts[res[i][1]]=1;
	parts[res[i][2]]=1;
      }
    }
    
    for(int i=0;i<n;i++){ //故障品探し(一回全部のデータを取り込んでからやるらしい)
      if(!state[i]){
	if(parts[res[i][0]]==1 && parts[res[i][1]]==1) parts[res[i][2]]=0;
	if(parts[res[i][1]]==1 && parts[res[i][2]]==1) parts[res[i][0]]=0;
	if(parts[res[i][0]]==1 && parts[res[i][2]]==1) parts[res[i][1]]=0;
      }
    }
    
    for(int i=0;i<many;i++){
      cout << parts[i] << endl;
    }
  }
}

Measured memory_bytes: 1176
using System;
        using System.Linq;
 
        public class Program
        {
            public static void Main(string[] args)
            {
            	string input = Console.ReadLine();
            Console.WriteLine(input == "A" ? "T": input == "T" ? "A": input == "C" ? "G" : input == "G" ? "C": "NO");            }
        }

Measured memory_bytes: 13140
n = int(input())
x = list(range(n))
y = list(range(n))
h = list(range(n))

for i in range(n):
  x[i], y[i], h[i] = map(int, input().split())
  if h[i] != 0:
    X = x[i]
    Y = y[i]
    H = h[i]

flag=0
i = 0
while(flag==0 and i < 101):
  j = 0
  while(flag==0 and j < 101):
    ans_h = abs(i-X)+abs(j-Y)+H
    for k in range(n):
      h_ = max(ans_h-abs(i-x[k])-abs(j-y[k]), 0)
      if h_ != h[k]:
        break
      if k == n-1:
        ans_x = i
        ans_y = j
        flag=1
        break
    j+=1
  i+=1

print(ans_x, ans_y, ans_h)

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

const ll INF=LLONG_MAX;

int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<ll,ll>> stu(n);
  vector<pair<ll,ll>> check(m);
  rep(i,n){
    ll a,b; cin>>a>>b;
    stu[i]=make_pair(a,b);
  }
  rep(i,m){
    ll c,d; cin>>c>>d;
    check[i]=make_pair(c,d);
  }
  for(auto x : stu){
    ll dist=INF;
    int tmp=0;
    int ans;
    for(auto y : check){
      tmp++;
      ll now_dist=abs(x.first-y.first)+abs(x.second-y.second);
      if(now_dist<dist) {ans=tmp; dist=now_dist;}
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3632
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		for ( int i=0; i<=1000; i++ ) {
			int c = (int)(i*1.08);
			int d = (int)(i*1.10);
			if ( c == i+a && d == i+b ) {
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
	}
}

Measured memory_bytes: 25172
#include <stdio.h>
#include <set>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
const int N = 2e5+5;
vector<pair<int,int> >lft,rgt;
long long Change(vector<pair<int,int> > a) {
    int n = a.size();
    long long res = 0;
    set<int> pos;
    for (int i = 1;i<= n;i++)
    	pos.insert(i);
    for(auto x:a) {
        auto it = pos.upper_bound(x.second);
        if(it!=pos.begin()) {
            it--;
            res += x.first;
            pos.erase(it);
        }
    }
    return res;
}
void solve() {
	int n;
	scanf("%d",&n);
	lft.clear();
	rgt.clear();
	int l,r,k;
	long long ans = 0;
	for (int i = 1;i<= n;i++) {
		scanf("%d%d%d",&k,&l,&r);
		if (l > r) ans += r,lft.push_back(make_pair(l-r,k));
		else ans += l,rgt.push_back(make_pair(r-l,n-k));
	}
	sort(lft.begin(),lft.end());
	reverse(lft.begin(),lft.end());
	sort(rgt.begin(),rgt.end());
	reverse(rgt.begin(),rgt.end());
	printf("%lld\n",ans+Change(lft)+Change(rgt));
}
int main()
{
	int cas;
	scanf("%d",&cas);
	while (cas--)
		solve();
	return 0;
}

/*
10110111001011011001110
6002382
 */

Measured memory_bytes: 10776
#include <iostream>
#include <queue>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
  char cmd[2]; // command
  int digit; // digit to insert
  priority_queue<int> Q;
  while (true) {
    scanf(" %s", cmd);
    if (cmd[0] == 'e' && cmd[1] == 'n') break;
    if (cmd[0] == 'i') {
      scanf(" %d", &digit);
      Q.push(digit);
    } else {
      cout << Q.top() << endl;
      Q.pop();
    }
  }
}

Measured memory_bytes: 7256
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;

int search(int A[],int n,int key){
    int left =0;
    int right=n;
    int mid;
    while(left<right){
        mid = (left + right) / 2;
        if(A[mid] == key) return 1;
        else if(key < A[mid])right = mid;
        else left = mid + 1;
    }
    return 0;
}


int main(){
    int n, A[100000],q,key,sum=0;
    cin >> n;
    for(int i=0;i<n;i++)cin >> A[i];
    

    cin >> q;
    for(int i =0;i<q;i++){
        cin >> key;
        if(search(A,n,key)) sum++;
         
    }
    cout << sum <<endl;
    return 0;
}


Measured memory_bytes: 3464
N,A,B=map(int,input().split())
C=A
D=B
ans=0
a=abs(A-B)
if a%2==0:
    print(a//2)
else:
    nb=N-B
    ans+=nb
    A+=nb
    B=N
    A+=1
    ans+=1
    ab=abs(A-B)
    ans+=ab//2

    A=C
    B=D
    val=0
    na=A-1
    B=B-na
    A=1
    val+=na
    B=B-1
    #print(B)
    val+=1
    na=abs(A-B)
    #print(na)
    val+=na//2
    ans=min(ans,val)
    print(ans)

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

typedef long long LL;

int n, a, b;

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


    cin >> n;
    int a = n % 10;
    n /= 100;
    if(a == n)
        cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>


using namespace std;


int gcd2(int a,int b){
  if(b==0)return a;
  else return gcd2(b,a%b);
}

int gcd(int a,int b,int c){
  return gcd2(gcd2(a,b),c);
}

  
int main() {
  int k;
  cin>>k;
  int ans = 0;
  for(int i = 1;i<=k;i++){
    for(int j = 1;j<=k;j++){
      for(int t = 1;t<=k;t++){
	ans += gcd(i,j,t);
      }
    }
  }
    cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int a,b,k;
	bool flag=0;
	scanf("%d%d%d",&a,&b,&k);
	for(int i=a;i<a+k;i++)
	{
		if(i==b)
		{
			printf("%d\n",b);
			flag=1;
			break;
		}	
		printf("%d\n",i);
	}
	if(flag)	return 0;
	for(int i=b-k+1;i<=b;i++)
	{
		if(i<a+k)	continue;
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s;
	cin>>s;
	int l=s.size();
	int ans;
    ans=l/2;
    string s1,s2;
    
	if (l%2==0){
		s1=s.substr(0,l/2);
		s2=s.substr(l/2,l/2);
		
	//	cout<<s1<<endl<<s2<<endl;
		
		for (int i=0;i<l/2;i++){
			if (s2[i]==s1[l/2-i-1]) {
				ans++;
			}
			else{
				break;
			}
		}
	
		cout<<ans<<endl;
	}else{
		ans++;
		s1=s.substr(0,l/2);
		s2=s.substr(l/2+1,l/2);
		//cout<<s1<<endl<<s2<<endl;
		
		if (s[l/2]!=s[l/2-1]||s[l/2]!=s[l/2+1]) cout<<ans<<endl;
		else{
			for (int i=0;i<l/2;i++){
				if (s2[i]==s1[l/2-i-1]) {
					ans++;
				}
				else{
					break;
				}
			}
			
			
			cout<<ans<<endl;
		}
	} 

}


/*
l        k
1        1
2        1

3              111   3
               110   2
			   101   2
			   
			   
1        000     0     000        0
			   
			   
k=l        改不了 
k=l-1      改得了头尾  
k=l-2      改得了头尾，改得了 第二倒二
k=l-3       



*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a;
  cin >> b;
  a=a%500;
  b=b-a;
  if (b>=0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp  make_pair
#define pb  push_back
using namespace std;

typedef long long  LL;
typedef pair <LL,LL>  PLL;
const int mo=int(1e9+7);
LL x,y,ans;
vector <PLL> a[100];

void prepare()
{
	a[0].pb(mp(1,1));
	for (int i=1; i<100; i++)
		{
			for (int j=0; j<a[i-1].size(); j++)
				a[i].pb(mp(a[i-1][j].second,a[i-1][j].first+a[i-1][j].second));
			a[i].pb(mp(a[i-1][0].second,a[i-1][0].first+2*a[i-1][0].second));
		}
}

void work()
{
	scanf("%lld %lld",&x,&y),ans=0;
	if (x>y)  swap(x,y);
	for (int i=1; i<100; i++)
		if ((x<a[i+1][0].first)||(y<a[i+1][0].second))
			{
				if (i==1)  {printf("%d %lld\n",i,x*y%mo);  return;}
				for (int j=0; j<a[i-1].size(); j++)
					{
						LL p=a[i-1][j].first,q=a[i-1][j].second;
						if ((q<=x)&&(p+q<=y))  ans=(ans+(y-p)/q)%mo;
						if ((q<=y)&&(p+q<=x))  ans=(ans+(x-p)/q)%mo;
					}
				printf("%d %lld\n",i,ans);
				return;
			}
}

int main()
{
	int t;
	scanf("%d",&t),prepare();
	while (t--)  work();
	return 0;
}


Measured memory_bytes: 4096
import numpy as np
from collections import deque

N = int(input())

# 枝の構造
branched = np.zeros((N,2), dtype="int")

branch_add = np.zeros(N, dtype="int")

ans = np.zeros(N - 1)

# 頂点から見た辺の個数の計算
appeard = np.zeros(N, dtype="int")

# メモリの都合上pythonの多重リストを選択
branch_list = [[] for _ in range(N)]

for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    branched[i, 0] = a
    branched[i, 1] = b
    branch_add[i] = a + b
    appeard[a] += 1
    appeard[b] += 1
    # 頂点の接続先の情報
    branch_list[a].append(i)
    branch_list[b].append(i)

color_num = np.max(appeard)

start_node = (np.where(appeard == color_num)[0])[0]

# 幅優先探索で色塗りを行う。変数は順番に「色を塗る辺がある頂点、色を塗った辺、その色」
color_queue = deque()

for c, i in enumerate(branch_list[start_node]):
    color_queue.append([branch_add[i] - start_node, i, c])
    ans[i] = c

while len(color_queue) > 0:
    next_queue = color_queue.popleft()
    node = next_queue[0]
    colored_branch = next_queue[1]
    color = next_queue[2]
    color_index = 0
    for i in branch_list[node]:
        if i == colored_branch:
            continue
        # 同じ色では塗らない
        if color_index == color:
            color_index += 1
        color_queue.append([branch_add[i] - node, i, color_index])
        ans[i] = color_index
        color_index += 1

print(color_num)

for i in range(N - 1):
    print(int(ans[i] + 1))

Measured memory_bytes: 33652
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');

            int X = int.Parse(strs[0]);
            int A = int.Parse(strs[1]);

            if (X < A)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(10);
            }
        }
    }
}


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

using namespace std;
typedef int long long ill;
typedef long long ll;

int main(){

    int X, N; cin >> X >> N;
    vector<int> pp(110,0);
    int ans;

    if (N == 0) cout << X << endl;
    else
    {
        
        for (int i = 0; i < N; i++)
        {
            int p;
            cin >> p;
            pp[p] = 1;
        }

        for (int i = 0; i < 110; i++)
        {
            if (pp[X - i] == 0)
            {
                ans = X-i;
                break;
            }
            else if (pp[X + i] == 0)
            {
                ans = X+i;
                break;
            }
            
        }
        
        cout << ans << endl;
    }
    
}


Measured memory_bytes: 3628
import sys
input = lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
wa=[0]*n
ac=[0]*n
for _ in range(m):
    x,y=map(str,input().split())
    x=int(x)
    if y=='WA':
        if ac[x-1]==0:
            wa[x-1]+=1
    if y=='AC':
        ac[x-1]=1
for i in range(n):
    if ac[i]==0: wa[i]=0
print(sum(ac),sum(wa))
    

Measured memory_bytes: 42476
#include<iostream>

using namespace std;

int main(){
  char s[4];
  char t[4];
  
  cin >> s >> t;
  int count=0;
  for(int i=0;i<3;i++){
    if(s[i]==t[i])count++;
  }
  cout<<count;
  return 0;
}
      

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
using namespace std;

int main(void)
{
	int n, now = 0, flag[101];
	long ans = 0, an[100][100], min[100];

	cin >> n;

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin >> an[i][j];
		}
		min[i] = LONG_MAX;
		flag[i] = 0;
	}

	/* ???????則?????????即?????属????????? */
	do {
		flag[now] = 1;
		flag[100] = 0;
/*
		cout << "\n??? " << now << " ????則???????????????????" << endl;
		cout << "?????贈?????? : ";
		for(int i = 0; i < n; i++) {
			if(flag[i] == 1) {
				cout << i << " ";
			}
		}
		cout << endl;
		cout << "?????即???????属?????????則" << endl;
		for(int i = 0; i < n; i++) {
			if(flag[i] == 0) {
				cout << "??? " << i << " : " << min[i] << endl;
			}
		}
*/
		/* min?????卒??属 */
		for(int j = 0; j < n; j++) {
			if(an[now][j] != -1 && an[now][j] < min[j] && flag[j] == 0) {
/*				cout << "??? " << j <<" ???????属?????????卒??属??????????????? : "<< min[j] << " ??? " << an[now][j] << endl; */
				min[j] = an[now][j];
			}
		}
/*
		cout << "?????即???????属?????????則" << endl;
		for(int i = 0; i < n; i++) {
			if(flag[i] == 0) {
				cout << "??? " << i << " : " << min[i] << endl;
			}
		}
*/
		/* ?測??????蔵?卒蔵???min????属???? */
		long key = LONG_MAX, key_j;

		for(int j = 0; j < n; j++) {
			if(flag[j] == 0 && min[j] < key) {
				key = min[j];
				key_j = j;
			}
		}
/*
		cout << "?則???????????賊??????????????????? : ??? " << key_j << endl;
*/
		/* ?則?????????? */
		now = key_j;
		ans += key;

		/* ??????????????贈????????? */
		for(int i = 0; i < n; i++) {
			if(flag[i] == 1) {
				flag[100]++;
			}
		}
	
	}while(flag[100] != n - 1);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		
	if(A%3 == 0|| B%3 ==0){
		System.out.println("Possible");
	}else if((A+B)%3 == 0){
		System.out.println("Possible");
	}else{
		System.out.println("Impossible");
	}

	}

}


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

int d, e;

void solve(int d, int e){
	double res = 1e9;
	for(int i=0; i<=d/2; ++i)
		res = min(res, abs(e - sqrt(i*i + (d-i)*(d-i))));
	printf("%.5lf\n", res);
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		cin >> d >> e;
		if(d == 0 && e == 0) return 0;
		solve(d, e);
	}
}


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int n, k;
	cin >> n >> k;
	deque<ll> d;
	FOR(i, 1, n) {
		int v;
		cin >> v;
		d.push_back(v);
	}
	ll res = 0;
	int lim = min(k, n);
	FOR(i, 0, lim) {
		FOR(j, 0, i) {
			deque<ll> d2 = d;
			vector<ll> jw;
			FOR(left, 1, j) {
				jw.push_back(d2.front());
				d2.pop_front();
			}
			FOR(right, 1, i - j) {
				jw.push_back(d2.back());
				d2.pop_back();
			}
			sort(ALL(jw));
			FOR(index, 0, k - i - 1) {
				if (index <= i - 1 && jw[index] < 0) {
					jw[index] = 0;
				}
			}
			ll tmp = accumulate(ALL(jw), 0LL);
			res = max(res, tmp);
		}
	}

	pv(res)
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>

#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,n) for(int i=0;i<(n); ++i)
#define rep2(i,n) for(int i=1;i<=(n);++i)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int NMAX = 100000;
const int MMAX = 100000;
const int k = 200000;
static const int INF = 1<<21;
static const int NIL = -1;
static const int mod = 1e9+7;

double dp[3000][3000]={0};
ll gcd(ll a, ll b){
if(a<b) swap(a,b);
    if(b==0) return a;
    return gcd(b, a%b);
}

vector<vi> pre(NMAX+1);
vi dist(NMAX+1);
vector<bool> visited(NMAX+1);


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


    int N;
    cin >> N;
    double a[N+1];
    rep2(i,N){
        cin >> a[i];
    }
    dp[1][1]=a[1];
    //dp[1][j]の初期化
    for(int j=2;j<=N;j++){
        dp[1][j]=dp[1][j-1]*a[j];
    }

    dp[1][0]=1.0;

    for(int i=2;i<=N;i++){
        for(int j=1;j<=N;j++){
            dp[i][j]=dp[i-1][j-1]*(1-a[j])+dp[i][j-1]*a[j];
        }
    }
    double sum=0.0;
    rep2(i,N/2 + 1){
        sum+=dp[i][N];
    }
    cout << setprecision(10)<< sum << endl; //有効数字調整
    return 0;
}

Measured memory_bytes: 73344
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
	int N,A,Alice=0,Bob=0;
	priority_queue<int> a;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A;
		a.push(A);
	}
	for(int i=0;i<N;i++){
		if(i%2==0){
			Alice+=a.top();
		}else{
			Bob+=a.top();
		}
		a.pop();
	}
	cout<<Alice-Bob<<endl;
}


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

int main()
{    
    int n;
    cin >> n;
    double inv_sum = 0;
    rep(i,n){
        double ai;
        cin >> ai;
        inv_sum += 1/ai;
    }
    cout << fixed << setprecision(12) << 1/inv_sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000
#define N 550

vector<vector<ll>> adj={{0,1},{1,0},{0,-1},{-1,0}};
vector<vector<ll>> seats(N,vector<ll>(N,-1));
vector<vector<ll>> vacant(N,vector<ll>(N,0));

void dfs(ll x, ll y){
    if (vacant[x][y]==1) seats[x][y]--;
    REP(i,4)if (seats[x+adj[i][0]][y+adj[i][1]]>seats[x][y]) dfs(x+adj[i][0],y+adj[i][1]);
    if (vacant[x][y]==0) seats[x][y]--;
}

int main(){
    ll n, p, ind, ans; cin >> n;
    ind=1; ans = 0;
    while(ind<=n+1-ind){
        FOR(i,ind,n+1-ind)FOR(j,ind,n+1-ind) seats[i][j]=ind-1;
        ind++;
    }
    REP(i,n*n){
        cin >> p;
        ll h = (p-1)/n+1; ll w = (p-1)%n+1;
        ans+=seats[h][w];
        vacant[h][w]=1;
        REP(j,4) if (seats[h+adj[j][0]][w+adj[j][1]]>seats[h][w]) dfs(h+adj[j][0],w+adj[j][1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 23856
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  int N;
  string S;
  string tmpS;
  cin >> N >> S;
  rep(i, N)
  {
    char tmp;
    if (i == 0)
    {
      tmp = S.at(i);
      //cout << tmp;
      tmpS += tmp;
    }
    else if (S.at(i) != tmp)
    {
      tmp = S.at(i);
      //cout << tmp;
      tmpS += tmp;
    }
    //cout << tmp;
  }
  cout << tmpS.size() << "\n";
}

Measured memory_bytes: 512
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <utility>
using namespace std;

int main() {
	int n,ans=0;
	float t, a,MIN=1000000;
	cin >> n;
	cin >> t >> a;
	vector<float>h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		h[i] = t - (h[i] * 0.006);
		h[i] = abs(h[i] - a);
		if (MIN > h[i]) {
			MIN = h[i];
			ans = i + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#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
#define double long double
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 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M; cin >> N >> M;
	int K; cin >> K;
	VI A(N), B(M);
	VI asum(N + 1, 0), bsum(M + 1, 0);
	REP(i, N) {
		cin >> A[i];
		asum[i + 1] += asum[i] + A[i];
	}
	REP(i, M) {
		cin >> B[i];
		bsum[i + 1] += bsum[i] + B[i];
	}

	int ans = 0;
	REP(i, N+1) {
		int cnt = i;
		int R = K - asum[i];
		if (R < 0)break;


		cnt += UB(bsum, R) - bsum.begin();
		cnt--;



		chmax(ans, cnt);
	}


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



Measured memory_bytes: 9480
#include <iostream>

using namespace std;

int main() {
	int N;
	while ( cin >> N, N ) {
		int ans = 0;
		for (int k = 1; k <= N; ++k) {
			for (int l = 2; l < N; ++l) {
				int s = (k-1)*l + l*(l+1)/2;
				if (s == N) {
					++ans;
				}
				if (s >= N) {
					break;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<list>

int main() {
	std::list<int> cars;
	int n;
	while (std::cin >> n) {
		if (n != 0) {
			cars.push_back(n);
		}
		else {
			std::cout << cars.back() << std::endl;
			cars.pop_back();
		}
	}
	return 0;
}

Measured memory_bytes: 3092
# ARC063D - 高橋君と見えざる手 / An Invisible Hand (ABC047D)
def main():
    N, T, *A = map(int, open(0).read().split())
    cur, cand = A[0], []
    for i in A:
        if i < cur:  # buy at the most inexpensive place
            cur = i
        else:
            cand += [i - cur]  # sell at higher places
    x = max(cand)  # the highest profits
    # count the number of pairs which produce x
    ans = sum(i == x for i in cand)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14052
//#pagma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

//#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod= 998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;
const int N = 1e5 + 233;
int n;
int dp[N] , f[N] , a[N] , mx, cnt[N];
int get(int a, int b){             
	return powmod(a , b , mod);
}
main(){
	scanf("%d" , &n);
	f[0] = 1;
	for(int i = 1 ; i < N ; i++)
		f[i] = 1ll * f[i - 1] * 1ll * i % mod;
	
	int cnt1 = 0;
	for(int i = 1 ; i <= n ; i++){
	 	scanf("%d" , a + i);
	 	cnt1 += a[i] == 0;
	 	cnt[a[i]]++;
	 	mx = max(mx , a[i]);
	}
	if(a[1] != 0 or cnt1 > 1)
		ret(0);
	dp[0] = 1;
	for(int i = 1 ; i <= mx; i++){
		if(cnt[i] == 0)ret(0);
		dp[i] = 1ll*dp[i - 1] * get(cnt[i - 1] , cnt[i]) % mod;
	}
	cout << dp[mx];
}
                              

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#if LOCAL
#include "../cout.hpp"
#endif
using namespace std;

#define forn(i,n) for (unsigned i = 0; i < n; ++i)
#define pb push_back

#define MOD 1000000007

typedef unsigned long long ull;

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

    int n;
    cin >> n;

    string s1, s2;
    cin >> s1 >> s2;

    ull result;
    int i;
    bool prev_single;

    if(n >= 2 && s1[0] == s1[1]) {
	prev_single = false;
	i = 2;
	result = 6;
    } else {
	prev_single = true;
	i = 1;
	result = 3;
    }

    while(i < n) {
	if(prev_single) {
	    result *= 2;
	}
	if(i + 1 < n && s1[i] == s1[i + 1]) {
	    if(!prev_single) {
		result *= 3;
	    }
	    prev_single = false;
	    i += 2;
	}
	else {
	    prev_single = true;
	    i++;
	}
	result %= MOD;
    }
    cout << result;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, K;

int main(){
	getint(N), getint(K);
	return printf("%d\n", K == 1 ? 0 : N - K), 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
box = set([])
for i in range(n,0,-1):
  cnt = 0
  for j in range(1,n//i+1):
    if i*j in box:
      cnt += 1
  if cnt%2 != a[i-1]:
    box.add(i)
print(len(box))
print(*box)

Measured memory_bytes: 19780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n); i >= 0; i--)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int main(){
	int N, M;
	cin >> N;
	bool JD = true;
	priority_queue<ll> D;
	priority_queue<ll> T;
	rep(i, N){
		ll A;
		cin >> A;
		D.push(A);
	}
	cin >> M;
	rep(i, M){
		ll A;
		cin >> A;
		T.push(A);
	}
	if(N < M){
		JD = false;
	} else {
		rep(i, N){
			if(!T.empty()){
				ll d = D.top();
				ll t = T.top();
				D.pop();
				if(d == t){
					T.pop();
				} else if(d > t){
					continue;
				} else {
					JD = false;
					break;
				}
			}
		}
	}
	cout << ((JD) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 4848
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  int i;
  int m,b;
  while(str!="-"){
    cin >> m;
    for(i=0;i<m;i++){
      cin >> b;
      str=str.substr(b,str.size()-b)+str.substr(0,b);
    }
    cout << str << endl;
    cin >> str;
  }
  
}



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

int main(){

  int rankb=1;
  int n,A,B;
  int sum=0;
  char c;

  cin >> n >> A >> B;

  for(int i=0; i<n; i++){
    cin >> c;
    if(c=='a'){
      if(sum < A+B){
	sum++;
	cout << "Yes" << endl;
      } 
      else cout<<"No" << endl;
    }
    else if(c=='b'){
      if(sum < A+B && rankb<=B){
	sum++;
	rankb++;
	cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }
    else cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
	long long int n,m,sum=0;
	cin >> n;
	m=n;
	while(m>0){
		sum+=m%10;
		m=m/10;
	}
	if(n%sum==0){
		puts("Yes");
	}else{
		puts("No");
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long

int N;
ll T[100];

ll gcd(ll u, ll v){
	ll r;
  	while (0 != v) {
    	r = u % v; u = v; v = r; 
  	}
  	return u;
}

ll lcm(ll u, ll v){
	return (u/gcd(u,v))*v;
}

int solve(){
	ll ans=T[0];
	for(int i=1; i<N;i++){
		ans = lcm(ans,T[i]);
	}
	cout << ans << endl;
	return 0;
}

int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> T[i];
	}
	solve();
	return 0;
}


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

int solve(string s) {
  string t = s;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  return atoi(t.c_str()) - atoi(s.c_str());
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    string str;
    cin >> str;
    cout << solve(str) << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007
 
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
 
int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};
 
int n, x[101], ans, sum;
 
int main(){
	ans = INF;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x[i];
	}
	for(int p = 1;p <= 100;p++){
		sum = 0;
		for(int j = 0;j < n;j++){
			sum += (x[j]-p)*(x[j]-p);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  long long Q;
  cin >> Q;
  int rev = 0;
  string left,right;
  
  for (long long i = 0; i < Q; i++){
    long long T;
    cin >> T;
    if (T == 1){
      rev = 1 - rev;
    }
    else {
      long long F;
      cin >> F; 
      char C;
      cin >> C;
      if (F == 1){
        if (rev == 0){
          left.push_back(C);
        }
        else {
          right.push_back(C);
        }
      }
      else {
        if (rev == 0){
          right.push_back(C);
        }
        else {
          left.push_back(C);
        }
      }
    }
  }
  
  if (rev == 0){
    for (int i = left.size(); i > 0; i--){
      cout << left.at(i - 1);
    }
    cout << S;
    for (int i = 0; i < right.size(); i++){
      cout << right.at(i);
    }
  }
  else {
    for (int i = right.size(); i > 0; i--){
      cout << right.at(i - 1);
    }
    for (int i = S.size(); i > 0; i--){
      cout << S.at(i - 1);
    }
    for (int i = 0; i < left.size(); i++){
      cout << left.at(i);
    }
  }
}  



Measured memory_bytes: 1088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main() {
	std::string s; std::cin >> s;
	for (int i = 1; i < s.size() - 2; ++i) {
		for (int j = i; j < s.size(); ++j){
			if (s.substr(0, i) + s.substr(j, s.size() - 1) == "keyence") {
				std::cout << "YES" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "NO" << std::endl;
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if((A > 8) || (B > 8)) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
  return 0;
}
  

Measured memory_bytes: 3580
K = int(input())
def gcd(a, b):
    if a < b:
        return gcd(b, a)
    elif a % b == 0:
        return b
    else:
        r = a % b
        return gcd(b, r)

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            n = gcd(a, b)
            n = gcd(n, c)
            ans += n

print(ans)

Measured memory_bytes: 83556
from bisect import bisect_left
from string import ascii_lowercase


def main():
    s = input()
    t = input()

    set_s = set(tuple(s))
    set_t = set(tuple(t))

    if not(set_t <= set_s):
        print(-1)
        exit()

    ans = 0
    d = {c:[] for c in ascii_lowercase}
    
    for i, c in enumerate(s):
        d[c].append(i+1)
    
    now = 0
    for c in t:
        
        idx = bisect_left(d[c], now+1)

        if idx == len(d[c]):
            ans += len(s)
            now = 0
            idx = bisect_left(d[c], now+1)
            
        now = d[c][idx]

    ans += now
    print(ans)

        
if __name__ == "__main__":
    main()

Measured memory_bytes: 8548
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1010;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
struct node{
	int x,y;
	int dep;
};
node q[maxn*maxn];
int a[maxn][maxn],vis[maxn][maxn];
int x[10],y[10];
int h,w,n;
int bfs(int s,int t){
	memcpy(vis,a,sizeof(a));//vis=a;
	q[0]=(node){x[s],y[s],0};
	vis[x[s]][y[s]]=1;
	int head=0,tail=1;
	while(head<tail){
		node cur=q[head++];
		if(cur.x==x[t]&&cur.y==y[t]) return cur.dep;
		for(int i=0;i<4;i++){
			int xx=cur.x+dx[i],yy=cur.y+dy[i];
			if(xx>=0&&xx<h&&yy>=0&&yy<w&&!vis[xx][yy]){
				q[tail++]=(node){xx,yy,cur.dep+1};
				vis[xx][yy]=1;
			}
		}
	}
}
int main(){
	cin>>h>>w>>n;
	memset(a,0,sizeof(a));
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++){
			char ch;
			cin>>ch;
			if(ch=='S') {x[0]=i;y[0]=j;}
			if(ch=='X') a[i][j]=1;
			if(ch>='1'&&ch<='9'){x[ch-48]=i;y[ch-48]=j;}
		}
	int ans=0,s;
	for(int i=0;i<n;i++) ans+=bfs(i,i+1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15496