akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;

struct UnionFind{
	vector<int> par,rank,mx;
	UnionFind(int N){
		par.assign(N,0);
		rank.assign(N,0);
		mx.assign(N,0);
		rep(i,N) par[i]=i,mx[i]=i;
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			par[x]=y;
			chmax(mx[y],mx[x]);
		}else{
			par[y]=x;
			chmax(mx[x],mx[y]);
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
};

int N,Q;
ll p[200010];

int main(){
	cin>>N;
	rep(i,N-1) cin>>p[i];

	UnionFind UF(2100000);
	vector<int> v(2100000);
	rep(i,2100000) v[i] = i;
	int s = 0;

	for(int i=N-2;i>=2;i--){
		rep(j,p[i]+1) UF.unite(v[s+p[i]+j],v[s+p[i]-j]);
		s += p[i];
	}

	cin>>Q;
	rep(i,Q){
		// cin>>p[N-1];
		// ll x = p[N-1];
		// for(int i=N-2;i>=2;i--){
		// 	x -= p[i];
		// 	x = abs(x);
		// }
		// ll ans = x + p[0] - p[1];
		// cout<<ans<<endl;
		ll a;
		cin>>a;
		if(a>=2100000){
			cout<<a-s+p[0]-p[1]<<endl;
			continue;
		}else{
			cout<<UF.mx[UF.find(a)] - s + p[0]-p[1]<<endl;
		}
	}
}


Measured memory_bytes: 36608
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define rd(a) cin>>(a)
#define RD(a,b) cin>>(a)>>(b)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[6]={-1,-1,0,0,1,1},dy[6]={0,-1,1,-1,1,0};
typedef pair<int,int> P;

int main() {
  int n,m;
  while(cin >> n >> m && (n||m)) {
    P a[m];
    rep(i,m) cin >> a[i].F >> a[i].S;
    int sx,sy;
    cin >> sx >> sy;
    int d[200][200];
    memset(d,0,sizeof(d));
    d[100][100]=1;
    rep(i,m) {
      int x=a[i].F+(100-sx),y=a[i].S+(100-sy);
      d[x][y]=MAX;
    }
    queue<P> que;
    que.push(P(100,100));
    while(!que.empty()) {
      int nx=que.front().F,ny=que.front().S;que.pop();
      if(d[nx][ny]-1==n) continue;
      for(int i=0; i<6; i++) {
	int x=nx+dx[i],y=ny+dy[i];
	if(check(200,200,x,y) && !d[x][y]) {
	  d[x][y]=d[nx][ny]+1;
	  que.push(P(x,y));
	}
      }
    }
    int ans=0;
    rep(i,200) {
      rep(j,200) {
	if(d[i][j] && d[i][j]!=MAX) ans++;
      }
    }
    pr(ans);
  }
  return 0;
}


Measured memory_bytes: 1380
#include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<ll, int> pii;
const int maxn = 1e5 + 10;

vector<pii> e[maxn];
int n;
int q, k;
ll dis[maxn];
void solve() {
    cin >> n;
    int x, y, z;
    for (int i = 0; i < n - 1; i++) {
        cin >> x >> y >> z;
        e[x].pb({y, z});
        e[y].pb({x, z});
    }
    cin >> q >> k;
    memset(dis, 13, sizeof dis);
    dis[k] = 0;
    set<pii> se = {{0, k} };
    while(!se.empty()) {
        pii t = *se.begin();
        se.erase(se.begin());
        int u = t.second; ll val = t.first;
        for (pii x : e[t.second]) {
            int v = x.first;
            if(val + x.second < dis[v]) {
                if(se.count({dis[v], v}))
                    se.erase({dis[v], v });
                dis[v] = val + x.second;
                se.insert({dis[v], v });
            }
        }
    }
    while(q--) {
        cin >> x >> y;
        cout << dis[x] + dis[y] << endl;
    }
}

int main() {
   // freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 17136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, M; cin >> N >> M;
    vector<pair<int, int>> ba(M);
    for(int i=0; i<M; i++) cin >> ba[i].second >> ba[i].first;

    sort(ba.begin(), ba.end());
    int ans = 0;
    int id = 0;
    while(id<M){
        int br = ba[id].first-1;
        while(id<M && ba[id].second <= br) id++;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

k,n = get_nums_l()
aaa = get_nums_l()
for i in range(n):
    aaa.append(aaa[i] + k)

ans = 99999999999999999999
for i in range(n):
    c = aaa[i+n-1] - aaa[i]
    ans = min(ans, c)

print(ans)

Measured memory_bytes: 88412
N = int(input())
t0 = 0
x0 = 0
y0 = 0
for i in range(0, N):
    t1, x1, y1 = map(int, input().split())
    id = (t1-t0)-abs(x1-x0)-abs(y1-y0)
    if id<0 or id%2==1:
        print("No")
        break
    elif i==N-1:
        print("Yes")
    t0 = t1
    x0 = x1
    y0 = y1


Measured memory_bytes: 3060
N = int(input())
H = list(map(int,input().split()))
ans = True
for i in range(1,N):
    if H[-i-1] <= H[-i]:
        continue
    elif H[-i-1] - H[-i] == 1:
        H[-i-1] -= 1
    else:
        ans = False
        break
if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define S second
template <typename T>
struct countmap {
    std::map<T, long long> dict;
    countmap() {
        dict = map<T, long long>();
    }
    bool contains(T key) {
        return (dict.find(key) != dict.end());
    }
    long long operator[](T key) {
        if (dict.find(key) != dict.end()) {
            return dict[key];
        } else {
            return 0;
        }
    }
    void incremntFor(T key, long long inc = 1) {
        if (dict.find(key) != dict.end()) {
            dict[key] += inc;
        } else {
            dict.emplace(key, inc);
        }
    }
    auto begin() const {
        return dict.begin();
    }
    auto end() const {
        return dict.end();
    }
};
int main() {
    int n, m;
    cin >> n >> m;
    auto dict = countmap<int>();
    rep(i,2*m){
        int x;
        cin >> x;
        dict.incremntFor(x);
    }
    for(auto &p: dict){
        if(p.S %2 ==1){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}


Measured memory_bytes: 5632
import java.util.*;

class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        int ans = 0;

        Integer n = sc.nextInt();
        TreeSet<Integer> s = new TreeSet<Integer>();
        for (int i = 0; i < n; i++) {
            s.add(sc.nextInt());
        }
        System.out.println(s.size());
        sc.close();
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, d; cin >> n >> d;
  VV<> x(n, V<>(d));
  for (auto&& v : x) for (auto&& e : v) cin >> e;
  int res = 0;
  for (int j = 0; j < n; ++j) for (int i = 0; i < j; ++i) {
    int s = 0;
    for (int k = 0; k < d; ++k) {
      s += (x[j][k] - x[i][k]) * (x[j][k] - x[i][k]);
    }
    int q = sqrt(s);
    res += q * q == s;
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int m, n, cur, cnt; !(cur = 0), !(cnt = 0), cin >> m >> n, m; cout << cnt << endl){
        vi masu(m); rep(i, m) cin >> masu[i];
        while(n --){
            int d; cin >> d;
            if(cur >= m - 1) continue;
            cur += masu[cur += d]; cnt ++;
        }
    }

    return 0;
}

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define RREP(i, n) for (int i = (i##_len - 1), i##_len = (n); i >= 0; i--)
#define RREP1(i, n) for (int i = (i##_len), i##_len = (n); i > 0; i--)
#define vsort(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;

ll hoge(ll x, bool pstv) {
    if (pstv) {
        if (x > 0) {
            return 0;
        } else {
            return 1 - x;
        }
    } else {
        if (x < 0) {
            return 0;
        } else {
            return -1 - x;
        }
    }
}

int main() {
    int n;
    cin >> n;
    vint a;
    vll r;
    r.pb(0);
    REP(i, n) {
        int t;
        cin >> t;
        a.pb(t);
        r.pb(r[i] + t);
    }
    ll x = 0, y = 0;
    ll xn = 0, yn = 0;
    // x:+-+-+-...
    // y:-+-+-+...
    REP1(i, n) {
        x += abs(hoge(r[i] + xn, i % 2));
        y += abs(hoge(r[i] + yn, !(i % 2)));
        xn += hoge(r[i] + xn, i % 2);
        yn += hoge(r[i] + yn, !(i % 2));
        // cout << x << " " << y << endl;
    }

    cout << min(x, y);
}

Measured memory_bytes: 1908
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int[][] A = new int[a][b];
		int[] B = new int[b];
		
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		
		for(int i = 0; i < b; i++){
			B[i] = sc.nextInt();
		}
		
		for(int i = 0; i < a; i++){
			int num = 0;
			for(int j = 0; j < b; j++){
				num += A[i][j] * B[j];
			}
			System.out.println(num);
		}

	}

}

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

typedef long long ll;
#define fori(n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair

ll power(ll base,ll e)
{
    ll answer=1;
    //ll e=1000000005;
    while(e)
    {
        if(e%2==1)
        {
            answer*=base;
        }
        base*=base;
       // base%=mod;
        e/=2;
       // answer%=mod;
    }
    return answer;
}

void mergearr(ll arr[], ll l,ll m, ll r)
{
    ll i,j,k;
    ll n1= m-l+1;
    ll n2 = r-m;
    ll L[n1],R[n2];
    for(i=0;i<n1;i++)
        L[i]=arr[l+i];
    for(i=0;i<n2;i++)
        R[i]=arr[m+1+i];

    i=0; j=0; k=l;
    while(i<n1 && j<n2)
    {
        if(L[i]<=R[j])
        {
            arr[k]=L[i];
            i++;
        }
        else
        {
            arr[k]=R[j];
            j++;
        }
        k++;
    }
    while(i<n1)
    {
        arr[k]=L[i]; i++; k++;
    }
    while(j<n2)
    {
        arr[k]=R[j]; j++; k++;
    }
}
void mergesort(ll arr[],ll l, ll r)
{
    if(l<r)
    {
        ll m = l+(r-l)/2;
        mergesort(arr,l,m);
        mergesort(arr,m+1,r);
        mergearr(arr,l,m,r);
    }
}


void sieveprimes(ll n)
{
        bool prime[n+1];
        memset(prime,true,sizeof(prime));

        for(ll i=2;i*i<=n;i++)
        {
            if(prime[i]==true)
            {
                for(ll j=i*i;j<=n;j+=i)
                {
                    prime[j]=false;
                }

            }

        }

        /*for (int p=2; p<=n; p++)
           if (prime[p])
              cout << p << " ";*/

    }


int main()
{

    ll n;
    cin>>n;
    string ans = "";
    while(n>0)
    {
        n-=1;
        ans += char('a'+n%26);
        n/=26;
    }
    for(int i=ans.length()-1;i>=0;i--)
        cout<<ans[i];
    /*for(int i=0;i<99;i++)
    {
        if(n<=pow(26,i))
        {
            n-=1;
            for(int j=0;j<i;j++)
            {
                cout<<char('a'+n%26);
                n/=26;
            }

            break;
        }
        else
        {
            n-=pow(26,i);
        }
    }*/
    cout<<"\n";

}




Measured memory_bytes: 3592
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll h,w,s;
    while(cin>>h>>w>>s){
        if(h==0){break;}
    vector<vector<ll>> A(h,vector<ll>(w,0));
    ll sum=0;
    for(auto &I:A){for(auto &T:I){cin>>T; sum+=T;}}
    ll X=sum-s;
    for(int i=1;i<h;i++){
        for(int j=0;j<w;j++){A[i][j]+=A[i-1][j];}
    }
    for(int i=0;i<h;i++){
        for(int j=1;j<w;j++){A[i][j]+=A[i][j-1];}
    }
    vector<vector<vector<vector<pll>>>> dp(h,vector<vector<vector<pll>>>(w,vector<vector<pll>>(h,vector<pll>(w,{-1,0}))));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int x=i;x<h;x++){
                for(int y=j;y<w;y++){
                    ll sum=A[x][y];
                    if(i!=0){sum-=A[i-1][y];}
                    if(j!=0){sum-=A[x][j-1];}
                    if(i!=0 && j!=0){sum+=A[i-1][j-1];}
                    if(sum>=X){dp[i][j][x][y]={1,sum};}
                }
            }
        }
    }
    for(int dh=0;dh<h;dh++){
        for(int dw=0;dw<w;dw++){
            for(int i=0;i+dh<h;i++){
                for(int j=0;j+dw<w;j++){
                    for(int k=0;k<dh;k++){
                        pll &L=dp[i][j][i+k][j+dw];
                        pll &R=dp[i+k+1][j][i+dh][j+dw];
                        pll &N=dp[i][j][i+dh][j+dw];
                        if(L.F==-1 || R.F==-1){continue;}
                        if(pll(L.F+R.F,min(L.S,R.S))>N){N=pll(L.F+R.F,min(L.S,R.S));}
                    }
                    for(int k=0;k<dw;k++){
                        pll &L=dp[i][j][i+dh][j+k];
                        pll &R=dp[i][j+k+1][i+dh][j+dw];
                        pll &N=dp[i][j][i+dh][j+dw];
                        if(L.F==-1 || R.F==-1){continue;}
                        if(pll(L.F+R.F,min(L.S,R.S))>N){N=pll(L.F+R.F,min(L.S,R.S));}
                    }
                }
            }
        }
    }
    cout<<dp[0][0][h-1][w-1].F<<" "<<dp[0][0][h-1][w-1].S-X<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 21052
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

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

bool isEvenStr(string ss) {
  bool res = false;
  int len = ss.size() / 2;
  if (ss.size() % 2 == 0) {
    if (ss.substr(0, len) == ss.substr(len, len)) {
      res = true;
    }
  }
  return res;
}

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel" << endl;
  else cout << "consonant" << endl;
  return 0;
}


Measured memory_bytes: 256
import math
n = int(input())

a,b = 1,n
for i in range(1,int(math.sqrt(n)+1)):
    if n%i == 0:
        q = n//i
        if abs(a-b) > abs(q-i):
            a,b = i,q

print((a-1) + (b-1))       

Measured memory_bytes: 9108
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
struct joi {
int j, o, i;
joi(){j=0;o=0;i=0;}
};
joi sum[1005][1005];
int m,n,k;
int main() {
    scanf("%d%d%d",&m,&n,&k);
    for (int i=1; i<=m; i++) {
        string row; cin>>row;
        for (int j=1; j<=n; j++) {
            sum[i][j].j=sum[i-1][j].j+sum[i][j-1].j-sum[i-1][j-1].j;
            sum[i][j].o=sum[i-1][j].o+sum[i][j-1].o-sum[i-1][j-1].o;
            sum[i][j].i=sum[i-1][j].i+sum[i][j-1].i-sum[i-1][j-1].i;
            if (row[j-1]=='J') sum[i][j].j++;
            if (row[j-1]=='O') sum[i][j].o++;
            if (row[j-1]=='I') sum[i][j].i++;
        }
    }
    int a,b,c,d;
    for (int i=0; i<k; i++) {
        scanf("%d%d%d%d",&a,&b,&c,&d);a--;b--;
        int rj=sum[c][d].j+sum[a][b].j-sum[a][d].j-sum[c][b].j;
        int ro=sum[c][d].o+sum[a][b].o-sum[a][d].o-sum[c][b].o;
        int ri=sum[c][d].i+sum[a][b].i-sum[a][d].i-sum[c][b].i;
        printf("%d %d %d\n",rj,ro,ri);
    }
    /*for (int i=0; i<m; i++) {
        for (int j=0; j<n; j++) {
            printf("(%d,%d,%d)%c",sum[i][j].j,sum[i][j].o,sum[i][j].i,j==n-1?'\n':' ');
        }
    }*/
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll T=1, n;
    while (T--){
        ll a, b, c;
        cin >> n;
        ll ans = 0;
        for (a = 1;a < n; ++a) {
            b = n/a;
            if (n%a == 0) b--;
            ans += b;
        }
         cout << ans << "\n";
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
    int ff=0,sf=0,f=0;
    int i,a,b,n;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
        if (a==b){
            if(sf){
                f=1;
                break;
            }else if(ff){
                sf=1;
            }else{
                ff=1;
            }
        }else{
            ff=0;
            sf=0;
        }
    }
    if(f){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}


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

int main(){
    int i,j,k,v,A[N];
    
    scanf("%d",&i);
    
    for(j = 0;j < i;j++){
        scanf("%d",&A[j]);
        printf("%d",A[j]);
        if(j == (i - 1)) break;
        printf(" ");
    } printf("\n");
    
    for(j = 1;j < i;j++){
        v = A[j];
        k = j - 1;
        while(k >= 0 && A[k] > v){
            A[k+1] = A[k];
            k--;
            A[k+1] = v;
        }
        for(k = 0;k < i;k++){
            printf("%d",A[k]);
            if(k == (i - 1)) break;
            printf(" ");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reve(a) reverse(a.begin(), a.end())
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
  int x, y;
  cin >> x >> y;
  if(x==0&&y<0) cout << -y+1 << endl;
  else if(x==0) cout << y << endl;
  else if(y==0&&x>0) cout << x+1 << endl;
  else if(y==0) cout << -x << endl;
  else{ 
  int m1, m2, m3, m4, m;  
  
  if(x<=y) m1 = y-x;
  else m1 = 1000000005;
  
  if(x<0&&y<0&&x>y) m2 = 2+x-y;
  else if(x>0&&y>0&&x>y) m2 = 2+x-y;
  else m2 = 1000000005;
    
  if(x<0&&y>0){
    if(-x<y) m3 = x+y+1;
    else m3 = 1-x-y;
  }  
  else if(x>0&&y<0){
    if(x<-y) m3 = -x-y+1;
    else m3 = 1+x+y;
  }
  else m3 = 1000000005;  
    
  m4 = min(m1, m2);
  m = min(m3, m4);  
  cout << m << endl;
    
  }
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }


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

    int x,y;
    cin >> x >> y;

    int b = (y - 2*x)/2;
    int a = (4*x - y)/2;
    if((abs(a) + abs(b)) == x && x < y){
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	string s,s0,s1,ans="~";
	cin>>s>>s1;
	s0=s;
	if(s.size()<s1.size())
	{
		cout<<"UNRESTORABLE";
		return 0;
	}
	for(int t=s.size()-s1.size();t>=0;t--)
    {
    	bool ok=1;
    	for(int i=t;i<t+s1.size();i++)
    	{
    		if(s[i]==s1[i-t]||s[i]=='?')
    		{
    			s0[i]=s1[i-t];
			}
			else
			{
				ok=0;
				break;
			}
		}
		if(ok)
		{
			for(int i=0;i<s.size();i++)
			{
				if(s0[i]=='?')
				{
					s0[i]='a';
				}
			}
			ans=min(ans,s0);
		}
		s0=s;
	}
	if(ans=="~")
	{
		cout<<"UNRESTORABLE";
		return 0;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3636
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

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

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    string s;
    cin >> s;
    bool good = true;
    for(int i=0;i<s.size()-1;i++){
        if(s[i] == s[i+1])
            good = false;
    }
    cout << (good ? "Good" : "Bad") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<string> vec;
    vector <string>::iterator it;

    map<string, int> ans;
    map<string, int>::iterator x;
    ans["AC"]= 0;
    ans["WA"]= 0;
    ans["TLE"]= 0;
    ans["RE"]= 0;

    int n;
    cin >> n;

    for(int i = 0 ; i < n ; i++)
    {
        string str;
        cin >> str;
        vec.push_back(str);
    }
    sort(vec.begin(),vec.end());
    int count = 1;
    for(int i = 0 ; i < n ; i++)
    {
        if(vec[i] == vec[i + 1])
        {
            count++;
        }
        else
        {
            ans[vec[i]] = count;
            count = 1;
        }
    }

    cout << "AC" << " x " << ans["AC"] << endl;
    cout << "WA" << " x " << ans["WA"] << endl;
    cout << "TLE" << " x " << ans["TLE"] << endl;
    cout << "RE" << " x " << ans["RE"] << endl;

    return 0;
}

/**
10
7 5 7 11 70 5 1 3 7 11
**/


Measured memory_bytes: 7352
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


using Graph = vector<vector<int>>;
int N, Q;
Graph G;

void dfs(int v, int p, vector<long long> &res) {
  if (p != -1) res[v] += res[p];
  for (auto e : G[v]) {
    if (e == p) continue;
    dfs(e, v, res);
  }
}

int main() {
  cin >> N >> Q;
  G.assign(N, vector<int>());
  for (int i = 0; i < N-1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<long long> val(N, 0);
  for (int i = 0; i < Q; ++i) {
    int p, x;
    cin >> p >> x;
    --p;
    val[p] += x;
  }
  dfs(0, -1, val);
  for (auto v : val) cout << v << " ";
  cout << endl;
}


Measured memory_bytes: 25092
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100010;
int a[maxn];
int main()
{
	int n, c, k, ans, i, j;
	scanf("%d%d%d", &n, &c, &k);
	for (i = 0; i < n; i ++)
		scanf("%d", a + i);
	sort(a, a + n);
	for (ans = i = 0; i < n; ans ++)
	{
		for (j = 0; i + j < n && j < c; j ++)
			if (a[i + j] - a[i] > k)
				break;
		i += j;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int ans=1;
    for(int i=1;i<=n;i++){
        if(ans*2<ans+k){
            ans=ans*2;
        }else ans=ans+k;

    }
    printf("%d\n",ans);
	return 0;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};



int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N; cin >> N;
	string s; cin >> s;
	ll res{0};
	for (auto c : s)
	{
		if (c == 'W')
			++res;
	}
	string tmp = s.substr(N-res);
	for (auto c : tmp)
	{
		if (c == 'W')
			--res;
	}
	std::cout << res << std::endl;
	return 0;
}


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

int main(){
    string week[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    int day[7] = {7,6,5,4,3,2,1};
    string s;
    cin >> s;
    int i;
    for (i=0;i<7;i++){
        if (s == week[i]){
            cout << day[i];
        }
    }
}





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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int n, m;
  cin >> n >> m;
  
  if(n == m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
  
}

Measured memory_bytes: 3504
def Count_car(n,k,S,P):
    storage = 0
    number = 1
    for i in range(n):
        weight = S[i]
        if storage + weight > P:
            storage = weight
            number += 1
        else:
            storage += weight
    if number > k:return 0
    return 1
n,k = list(map(int,input().split()))
total = 0
M = 0
S = []
for _ in range(n):
    number = int(input())
    S.append(number)
import math
P = max(max(S),math.ceil(sum(S)/k))
Q = sum(S)
while True:
    if Q - P <= 1:
        if Count_car(n,k,S,P):
            break
        else:
            P = P+1
            break
    mid = (P+Q)//2
    if Count_car(n,k,S,mid):
        Q = mid
    else:
        P = mid
print(P)


Measured memory_bytes: 9592
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
#define Maxn 100009
#define x first
#define y second
typedef long long LL;
map <int,int> k;
int n,a[Maxn];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		scanf("%d",&a[i]);
		++k[a[i]];
	}
	int x = 0, y = 0;
	for (auto i : k)
	{
		if (i.y >= 4) x = y = i.x;
		else if (i.y >= 2)
		{
			if (x < y) x = i.x;
			else y = i.x;
		}
	}
	printf("%lld\n",LL(x)*y);
	return 0;
}

Measured memory_bytes: 5376
s = input()
n = int(s)

t_count = 0
f_count = 0
over = 0

colors = []
for i in range(8):
    colors.append(False)

v = input().split()

for i in range(n):
    x = int(v[i])
    if 1 <= x <= 399:
        colors[0] = True
    elif 400 <= x <= 799:
        colors[1] = True
    elif 800 <= x <= 1199:
        colors[2] = True
    elif 1200 <= x <= 1599:
        colors[3] = True
    elif 1600 <= x <= 1999:
        colors[4] = True
    elif 2000 <= x <= 2399:
        colors[5] = True
    elif 2400 <= x <= 2799:
        colors[6] = True
    elif 2800 <= x <= 3199:
        colors[7] = True
    else:
        over += 1

for i in range(len(colors)):
    if colors[i]:
        t_count += 1

if t_count == 0:
    min_ans = 1
else:
    min_ans = t_count
max_ans = t_count + over

print(min_ans, end=' ')
print(max_ans)



Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s; cin >> s;
    int ans = 0;
    rep(i,s.size()) {
        if (s[i] == '+')
        {
            ans++;
        } else {
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	ll ans=0;
	int n=s.size();
	ll sum=0;
	for(int i=0;i<(1<<(n-1));++i){
		int k=0;
		rep(j,n-1){
			if(i&(1<<j)){
				sum=0;
				while(k<j+1){
					sum*=10;
					sum+=s.at(k)-'0';
					k++;
				}
				ans+=sum;
			}
		}
		sum=0;
		while(k<n){
			sum*=10;
			sum+=s.at(k)-'0';
			k++;
		}
		ans+=sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int G;
int CLOSE[105];
char LR[15];
map<char,int>MAP;


bool isWord(char ch){

	return ch >= 'a' && ch <= 'z';
}

string recursive(string line,int depth,int max_depth,int left,int right){

	if(line[left] == '(' && right == CLOSE[left]){

		return recursive(line,0,max_depth,left+1,right-1); //式なので0から再スタート
	}

	if(depth == max_depth+1){ //変数であるはず

		string ret = "";
		ret += line[left];

		return ret;
	}

	vector<int> vec;

	//depthの演算子があるかチェック
	int D = 0;

	for(int i = left; i <= right; i++){
		if(isWord(line[i]))continue;

		if(line[i] == '('){

			D++;
			continue;
		}else if(line[i] == ')'){

			D--;
			continue;
		}

		if(MAP[line[i]] == depth && D == 0){ //カッコの中に入っていたら不可

			vec.push_back(i);
		}
	}

	if(vec.size() == 0){

		return recursive(line,depth+1,max_depth,left,right);
	}

	string ret,work;

	if(LR[depth] == 'L'){

		ret = recursive(line,depth+1,max_depth,left,vec[0]-1);

		for(int i = 0; i < vec.size(); i++){
			ret += line[vec[i]];

			if(i == vec.size()-1){

				work = recursive(line,depth+1,max_depth,vec[i]+1,right);

			}else{

				work = recursive(line,depth+1,max_depth,vec[i]+1,vec[i+1]-1);
			}

			ret = "("+ret+work+")";
		}

	}else{ //LR[depth] == 'R'

		ret = recursive(line,depth+1,max_depth,vec[vec.size()-1]+1,right);

		for(int i = vec.size()-1; i >= 0; i--){
			ret = line[vec[i]]+ret;

			if(i == 0){

				work = recursive(line,depth+1,max_depth,left,vec[0]-1);

			}else{

				work = recursive(line,depth+1,max_depth,vec[i-1]+1,vec[i]-1);
			}

			ret = "("+work+ret+")";
		}
	}

	return ret;
}


void func(){

	MAP.clear();

	scanf("%d",&G);

	char buf[2];
	int tmp;

	for(int i = 0; i < G; i++){

		scanf("%s %d",buf,&tmp);

		LR[i] = buf[0];

		for(int k = 0; k < tmp; k++){

			scanf("%s",buf);
			MAP[buf[0]] = i;
		}
	}

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

	int max_depth;

	for(int loop = 0; loop < num_query; loop++){

		string line;
		cin >> line;

		stack<int> S;

		//カッコの対応関係
		for(int i = 0; i < line.length(); i++){
			if(line[i] == '('){

				S.push(i);
			}else if(line[i] == ')'){

				CLOSE[S.top()] = i;
				S.pop();
			}
		}

		max_depth = 0;

		for(int i = 0; i < line.length(); i++){
			if(line[i] == '(' || line[i] == ')' || isWord(line[i]))continue;

			max_depth = max(max_depth,MAP[line[i]]);
		}

		string ret = recursive(line,0,max_depth,0,line.length()-1);

		printf("%s\n",ret.c_str());
	}
}

int main(){

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

	for(int i = 0; i < num_case; i++){
		if(i > 0){

			printf("\n");
		}
		func();
	}

	return 0;
}



Measured memory_bytes: 3200
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long a,b,c,i;
    cin>>a>>b>>c;
    int S[3];
    S[0]=a;
    S[1]=b;
    S[2]=c;
    bool flug=false;
    
    if(a<=b && b<=c && flug==false)
    {
        cout<<a<<" "<<b<<" "<<c<<endl;
        flug=true;
    }
    if(a<=c && c<=b && flug==false) 
    {
        cout<<a<<" "<<c<<" "<<b<<endl;
        flug=true;
    }
    if(b<=c && c<=a && flug==false) 
    {
        cout<<b<<" "<<c<<" "<<a<<endl;
        flug=true;
    }
    if(b<=a && a<=c && flug==false) 
    {
        cout<<b<<" "<<a<<" "<<c<<endl;
        flug=true;
    }
    if(c<=a && a<=b && flug==false ) 
    {
        cout<<c<<" "<<a<<" "<<b<<endl;
        flug=true;
    }
    if(c<=b && b<=a && flug==false) 
    {
        cout<<c<<" "<<b<<" "<<a<<endl;
        flug=true;
        
    }
    return 0;
    
}



Measured memory_bytes: 3096
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

const int64_t MOD = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int d;
    cin >> d;

    vector<vector<int64_t>> dp(s.size() + 1, vector<int64_t>(d));
    int r;
    irep(i, s.size())
    {
        if (i == 0) {
            r = 0;
            rep(j, d)
            {
                dp[i][j] = 0;
            }
        } else {
            rep(j, d)
            {
                if (j == 0) {
                    dp[i][j] = 0;
                    rep(k, 10)
                    {
                        dp[i][j] += dp[i - 1][(j - k % d + d) % d];
                        dp[i][j] %= MOD;
                    }
                } else {
                    dp[i][j] = dp[i][j - 1] + (dp[i - 1][j] - dp[i - 1][(j - 10 % d + d) % d] + MOD) % MOD;
                    dp[i][j] %= MOD;
                }
            }
            int e = s[i - 1] - '0';
            rep(j, e)
            {
                dp[i][(r + j) % d]++;
                dp[i][(r + j) % d] %= MOD;
            }

            r = (r + e) % d;
        }
    }

    int64_t result = (dp[s.size()][0] + (r == 0 ? 1 : 0) - 1 + MOD) % MOD;
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    string a, b, c;
    cin >> a >> b >> c;

    int aCounter = 0;
    int bCounter = 0;
    int cCounter = 0;
   	char next = a[aCounter];
    while(true) 
    {
    	if(next == 'a')
    	{
    		if(aCounter >= a.length())
    		{
    			cout << "A" << endl;
    			break;
    		}
    		next = a[aCounter];
    		aCounter ++;
    	}
    	else if(next == 'b')
    	{
    		if(bCounter >= b.length())
    		{
    			cout << "B" << endl;
    			break;
    		}
    		next = b[bCounter];
    		bCounter ++;
    	}
    	else
    	{
    		if(cCounter >= c.length())
    		{
    			cout << "C" << endl;
    			break;
    		}
    		next = c[cCounter];
    		cCounter ++;
    	}
    }
}

Measured memory_bytes: 256
<?php
list($n) = ints();
$a = ints();
$money = 1000;
$kabu = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($i < $n - 1 && $a[$i + 1] > $a[$i]) { // 買えるだけ買う
        $kabu += intdiv($money, $a[$i]);
        $money -= $a[$i] * intdiv($money, $a[$i]);
    } else { //売れるだけ売る
        $money += $kabu * $a[$i];
        $kabu = 0;
    }
}
echo $money;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16188
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
g = A[-1]
l = A[-1]
import fractions
for i in range(2,N+1):
    a = A[-i]
    g = fractions.gcd(l,a)
    l = l*a//g
    if l//2 > M:
        print(0)
        quit()
b = l//2
f = (M-b)//l + 1
for i in range(N):
    if b%A[i] == 0:
        f = 0
        break
if M < l//2:
    ans = 0
else:
    ans = f
print(ans)


Measured memory_bytes: 14244
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
int main(){ 
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];
  vector<int> dp(h+1,INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < h; j++) {
      if (dp[j] == INF) continue;
      if (j + a[i] < h) dp[j+a[i]] = min(dp[j+a[i]], dp[j] + b[i]);
      else dp[h] = min(dp[h], dp[j] + b[i]);
    }
  }
  cout << dp[h] << endl;
  return 0;
} 

Measured memory_bytes: 256
from queue import Queue


class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = time


if __name__ == '__main__':
    n, q = map(int, input().split())
    arr = Queue()
    for _ in range(n):
        name, time = input().split()
        arr.put(Task(name, int(time)))
    all_time = 0
    while not arr.empty():
        task = arr.get()
        if task.time > q:
            arr.put(Task(task.name, task.time - q))
            all_time += q
        else:
            all_time += task.time
            print(task.name, all_time)



Measured memory_bytes: 18612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;


namespace _20180502_pra
{
    class Program
    {
        static void Main(string[] args)
        {
            var w = Console.ReadLine();
            var result = "Yes";
            

            for (int i = 0; i < w.Length; i++)
            {
                int count = 0;
                foreach (var item in w)
                {
                    if (item == w[i]) count++;
                }
                if (count % 2 != 0)
                {
                    result = "No";
                    break;
                }
            }
            Console.WriteLine(result);

        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include<cstdio>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
// #define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int toph = 0;
  int res = 0;
  rep(i, n) {
    int h;
    cin >> h;
    
    if (h >= toph) {
      ++res;
    }
    
    toph = max(h, toph);
  }
  
  cout << res;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))

int main(){
    string s;
    cin>>s;
    size_t si=s.size();
    int wc=0,bc=0;
    rep(i,0,si){//0 start
        if(i%2==0){
            if(s[i]=='0')wc++;
        }else{
            if(s[i]=='1')wc++;
        }
    }
    rep(i,0,si){//0 start
        if(i%2==0){
            if(s[i]=='1')bc++;
        }else{
            if(s[i]=='0')bc++;
        }
    }
    cout<<min(wc,bc)<<endl;
}

Measured memory_bytes: 512
import numpy as np
from collections import deque
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))

def bfs(sy, sx):
  dist = [[-1]*W for _ in range(H)]
  dist[sy][sx] = 0
  q = deque([[sy, sx]])

  while q:
    y, x = q.popleft()
    for dy, dx in moves:
      ny = y + dy
      nx = x + dx
      if 0 <= ny < H and 0 <= nx < W and dist[ny][nx] == -1 and S[ny][nx] == '.':
        dist[ny][nx] = dist[y][x] + 1
        q.append([ny, nx])

  return dist

d = bfs(0, 0)
d = np.array(d)
ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      d = bfs(i, j)
      d = np.array(d)
  
      ans = max(ans, np.max(d))
print(ans)




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

int main(){
  long long N,D;
  cin >> N >> D;
  int count=0;
  for(int i=0;i<N;i++){
    long long X,Y;
    cin >> X >> Y;
    if(X*X+Y*Y<=D*D){
      count++;
    }
  }
  cout << count << endl;
} 

Measured memory_bytes: 3616
s=input()
t=input()

s2=""
f=0
l=len(s)
for i in range(0, len(s)):
    s2+=s[i:l]
    s2+=s[0:i]
    if s2==t:
        f=1
    else:
        s2=""


if f:
    print("Yes")
else:
    print("No")


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

int main(){
  ll a; double b;
  cin >> a >> b;
  b *= 100;
  b += 0.1;
  ll c = b;
  cout << a*c/100 << endl;
  return 0;
}


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

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    // Sの中で辞書順で最小の文字の連続する個数を2倍ずつにできる
    char smallest = 'z';
    for (int i = 0; i < N; ++i) {
        smallest = min(smallest, S[i]);
    }

    string U = S;
    reverse(S.begin(), S.end());
    U += S;

    // Uの中で辞書順で最小の文字の連続する個数
    int length = 0;
    int cnt = 0;
    for (int i = 0; i < U.size(); ++i) {
        if(U[i] == smallest){
            cnt++;
        } else{
            length = max(length, cnt);
            cnt = 0;
        }
    }
    length = max(length, cnt);

    // 出力文字列でのsmallest以外の文字の数を求める
    int left = length;
    for (int i = 0; i < K - 1; ++i) {
        left *= 2;
        if(left >= N){
            for (int j = 0; j < N; ++j) {
                cout << smallest;
            }
            cout << "\n";
            return 0;
        }
    }
    for (int i = 0; i < left - length; ++i) {
        cout << smallest;
    }
    left = N - left;

    // U を反転(そのまま)して長さlength+leftの辞書順最小文字列を求めて出力すればいい
    string ans = U.substr(0, length + left);
    for (int i = 0; i <= U.size() - N; ++i) {
        string sub = U.substr(i, length + left);
        ans = min(ans, sub);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ======================================================================
    public void solve() {
    	int A = ni();
    	int B = ni();
    	int C = ni();
    	if((A == B && B != C)
        		|| (A == C && A != B)
        		|| (B == C && A != B))
    		out.println("Yes");
    	else
    		out.println("No");
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


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

int main() {

    rep(i, 10000){
        int h, w;
        cin >> h >> w;
        if(h == 0  && w == 0) break;
        rep(i, w) cout << "#";
        cout << endl;
        rep(i, h - 2){
            cout << "#";
            rep(j, w - 2){
                cout << ".";
            }
            cout << "#" << endl;
        }
        rep(i, w) cout << "#";
        cout << endl;
        cout << endl;
    }

}


Measured memory_bytes: 3084