akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int m;
    cin>>m;
    ll sum = 0;
    ll ans = 0;
    rep(i,m){
        ll c,d;
        cin>>c>>d;
        sum += c*d;
        ans += d;
    }
    cout<<ans-1+ (sum-1)/9<<endl;
}


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

using namespace std;

#define ll long long
#define up(i,j,n)	for(ll i=j;i<=n;i++)
#define down(i,j,n)	for(ll i=j;i>=n;i--)
#define cmax(a,b)	a=max(a,b)
#define cmin(a,b)	a=min(a,b)

const ll MAXN=2e5+5;
const ll oo=1LL<<60;

ll N,K,a[MAXN],num[MAXN],top=0;

namespace BIT{
	ll c[MAXN];
	ll lowbit(ll i){return i&(-i);}
	void ins(ll x){
		x=lower_bound(num+1,num+top+1,x)-num;
		for(ll i=x;i<=top;i+=lowbit(i))c[i]++;
	}
	ll qry(ll x){
		ll sum=0;
		x=lower_bound(num+1,num+top+1,x)-num;
		for(ll i=x;i>=1;i-=lowbit(i))sum+=c[i];
		return sum;
	}
}using namespace BIT;

namespace solution{
	void Prepare(){
		scanf("%lld%lld",&N,&K);
		up(i,1,N){
			scanf("%lld",&a[i]);
			a[i]=a[i]-K+a[i-1];
			num[++top]=a[i];
		}
		num[++top]=0;
		sort(num+1,num+top+1);
		top=unique(num+1,num+top+1)-(num+1);
	}
	void Solve(){
		ll ans=0;
		ins(0);
		up(i,1,N){
			ans+=qry(a[i]);
			ins(a[i]);
		}
		cout<<ans<<endl;
	}
}

int main(){
	//freopen("input.in","r",stdin);
	using namespace solution;
	Prepare();
	Solve();
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll n,m;
pll x[100005],y[100005];
ll par[100005];
ll get_par(ll x)
{
	if(par[x]==x)return x;
	return par[x]=get_par(par[x]);
}
set<pair<ll,pair<ll,ll>>>s;
int main() {
SPEED;
cin>>n;

for(int i=1;i<=n;i++)
{
	par[i]=i;
	cin>>x[i].FF>>y[i].FF;
	x[i].SS=i;y[i].SS=i;
}
sort(x+1,x+n+1);
sort(y+1,y+n+1);

for(int i=2;i<=n;i++)
{
	s.insert(mp(x[i].FF-x[i-1].FF,mp(x[i].SS,x[i-1].SS)));
	s.insert(mp(y[i].FF-y[i-1].FF,mp(y[i].SS,y[i-1].SS)));
}

ll ans=0;
for(auto j:s)
{
	ll a=j.SS.FF,b=j.SS.SS;
	if(get_par(a)!=get_par(b))
	{
		ans+=j.FF;
		par[get_par(a)]=get_par(b);
	}
}
plld(ans);
	return 0;
           }




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

int main(){
    
    int n;
    cin >> n;
    vector<int> a(n);
    long long ans = 0;
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    int first = a[0];
    for(int i=0; i<n; i++){
        if(a[i] < first){
            ans += first - a[i];
        }
        else{
            first = a[i];
        }
    }
    cout << ans << endl;       
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

ld a,b;

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

    cin >> a >> b;
    a *= b;
    cout << (ll)a << '\n';


    return 0;
}

Measured memory_bytes: 3752
from collections import deque
def MI(): return map(int, input().split())

def bfs(field,s):
  MOVE=[(0,1),(1,0),(0,-1),(-1,0)]
  q=deque([(0,s)])
  dist=[[-1]*W for _ in range(H)]
  #d,i,j=-1,-1,-1
  while q:
    d,(i,j)=q.popleft()
    if dist[i][j]!=-1:
      continue
    dist[i][j]=d
    for di,dj in MOVE:
      ni,nj=i+di,j+dj
      if not 0<=ni<H or not 0<=nj<W:
        continue
      if dist[ni][nj]!=-1:
        continue
      if field[ni][nj]=='#':
        continue
      q.append((d+1,(ni,nj)))
  return d
ans=0
H,W=MI()
field=[input() for _ in range(H)]
for i in range(H):
  for j in range(W):
    if field[i][j]=='.':
      d=bfs(field,(i,j))
      ans=max(ans,d)
print(ans)

Measured memory_bytes: 9460
#include <cstdio>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
    int q, x;
    char com[20];
    //標準ライブラリよりlistを使用
    list<int> v;
    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%s", com);
        if (com[0] == 'i')
        { //insert
            scanf("%d", &x);
            v.push_front(x);
        }
        else if (com[6] == 'L')
        { //deleteLast
            v.pop_back();
        }
        else if (com[6] == 'F')
        { //deleteFirst
            v.pop_front();
        }
        else if (com[0] == 'd')
        { //delete
            scanf("%d", &x);
            for (list<int>::iterator it = v.begin(); it != v.end(); it++)
            {
                if (*it == x)
                {
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i =0;
    for(list<int>::iterator it = v.begin(); it != v.end(); it++){
        if(i++)printf(" ");
        printf("%d", *it);
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 34028
#事前準備
n,m=[int(i) for i in input().split()]
cardlist=[int(i) for i in input().split()]
carddict={}
for card in cardlist:
    if str(card) not in carddict:
        carddict[str(card)]=1
    else:
        carddict[str(card)]+=1
# print("カードリスト",carddict)
opr=[]
for i in range(m):
    opr.append([int(i) for i in input().split()])
# print(n,m,carddict,opr)
    
#比較対象となるカードを全て集める
for operation in opr:
    times=operation[0]
    card=str(operation[1])
    if str(card) not in carddict:
        carddict[str(card)]=times
    else:
        carddict[str(card)]+=times

#カードクラスを定義
class Card:
    def __init__(self,number,howmany):
        self.number=int(number)
        self.howmany=howmany
    def __lt__(self,other):
        if self.number<other.number:
            return True
        return False
    def __gt__(self,other):
        if self.number>other.number:
            return True
        return False

#クラスを使った新しいカードリストを作成
cardlist=[]
for i,j in carddict.items():
    cardlist.append(Card(i,j))

    
#カードリストを整列
cardlist.sort()
# for i in cardlist:
#     print(i.number,i.howmany)


maxsum=0
count=0    
while cardlist:
    card=cardlist.pop()
    number=card.number
    howmany=card.howmany
    if count+howmany<=n:
        maxsum+=number*howmany
        count+=howmany
    else:
        counttime=n-count
        maxsum+=number*counttime
        break
        
print(maxsum)

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

string f(ll n){
  if(n == 0) return "";
  n--;
  return f(n/26) + string(1, 'a'+n%26);
}

int main() {
  ll n;
  cin >> n;
  string ans;
  while(n){
    n--;
    ans += 'a'+n%26;
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  //cout << f(n) << endl;
}

Measured memory_bytes: 3640
s = input()
x = []
for i in s:
    x.append(ord(i) - ord('a'))
K = int(input())
for i in range(len(x)):
    if x[i] == 0:
        continue
    d = 26 - x[i]
    if K >= d:
        x[i] = 0
        K -= d
x[-1] = (x[-1] + K) % 26
for i in x:
    print(chr(i + ord('a')), end = "")
print()

Measured memory_bytes: 55584
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 210
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int mp[maxn][maxn];
char s[maxn];
int n,m;
int bfs(int S)
{
	static int q[maxn],dis[maxn];
	for(int i=1;i<=n;i++)
		dis[i]=-1;
	int h=1,t=1; q[1]=S; dis[S]=0;
	while(h<=t){
		int now=q[h++];
		for(int i=1;i<=n;i++)
			if(mp[now][i]){
				if(~dis[i]){
					if((dis[i]+dis[now]+1)&1)return -1;
				}
				else{
					dis[i]=dis[now]+1;
					q[++t]=i;
				}
			}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=std::max(ans,dis[i]);
	return ans;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=n;j++)
			if(s[j]=='1')mp[i][j]=1;
	}
	int ans=-1;
	for(int i=2;i<=n;i++)
		ans=std::max(ans,bfs(i));
	if(~ans)writeln(ans+1);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 384
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    std::cin >> s;
    ll n = s.length();
    ll result = n;
    // std::cout << result << std::endl;
    
    vector<ll> res;
    char now = s[0];
    ll len = 1;
    for (int i =1; i < n; i++) {
        if(s[i] == now){
            len++;
        }else{
            res.push_back(len);
            len = 1;
            now = s[i];
        }
    }
    res.push_back(len);
    
    
    for (int i = 0; i < res.size()-1; i++) {
        if(res[i]%3 == 2){
            res[i]--;
            res[i+1]--;
            result--;
        }
        
        int x = (res[i]+2)/3*2;
        if(res[i]%3!=0){
            x--;
        }
        // std::cout << res[i]<<" "<<x << std::endl;
        result -= (res[i]-x);
        // std::cout << result << std::endl;
    }
    // aa bb b aa
    // a ab b a ab b
    int x = (res[res.size()-1]+2)/3*2;
    if(res[res.size()-1]%3!=0){
        x--;
    }
    // std::cout << res[res.size()-1]<<" "<<x << std::endl;
    result -= (res[res.size()-1]-x);
    
    std::cout << result << std::endl;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main(){
  int n; cin >> n;
  int c = 0;
  rep(i, n){
    int a; cin >> a;
    if(a % 2) c++;
  }
  if(c % 2) cout << "NO\n";
  else cout << "YES\n";
}

Measured memory_bytes: 256
using System;

namespace ARC058_D___いろはちゃんとマス目
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var H = read[0];
            var W = read[1];
            var A = read[2];
            var B = read[3];
            long MOD = 1000000007;

            Combination.combInit(1000000, MOD);

            long result = 0;
            var h = H - A;
            var w = B + 1;
            var c = h + w;
            while (h >= 1 && w <= W)
            {
                result = (result + Combination.combination(c - 2, h-1) * Combination.combination(H + W - c, H - h) % MOD) % MOD;
                h--;
                w++;
            }
            Console.WriteLine(result);
        }
    }
    static class Combination
    {
        static long combMax;
        static long combMOD;

        static long[] factorial;
        static long[] inverse;
        static long[] factInv;

        public static void combInit(long _max, long _mod)
        {
            combMax = _max;
            combMOD = _mod;
            factorial = new long[combMax];
            inverse = new long[combMax];
            factInv = new long[combMax];

            factorial[0] = factorial[1] = 1;
            factInv[0] = factInv[1] = 1;
            inverse[1] = 1;

            for (int i = 2; i < combMax; i++)
            {
                factorial[i] = factorial[i - 1] * i % combMOD;
                inverse[i] = combMOD - inverse[combMOD % i] * (combMOD / i) % combMOD;
                factInv[i] = factInv[i - 1] * inverse[i] % combMOD;
            }
        }

        public static long combination(int n, int k)
        {
            if (n < k) return 0;
            if (n < 0 || k < 0) return 0;
            return factorial[n] * (factInv[k] * factInv[n - k] % combMOD) % combMOD;
        }
    }
}


Measured memory_bytes: 34644
str = input()
len = len(str)
a_flg = False
c_cnt = 0
wa_flg = False

for i, s in enumerate(str):
    if i == 0 and s == 'A':
        a_flg = True
    elif 2 <= i <= len-2 and s == 'C':
        if c_cnt < 1:
            c_cnt += 1
        else:
            wa_flg = True
            break
    elif 'A' <= s <= 'Z':
        wa_flg = True
        break

if a_flg and c_cnt == 1 and not wa_flg:
    print('AC')
else:
    print('WA')


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

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

	int max = A;
	int min = A;

	for (int i = 1; i < N; ++i)
	{
		cin >> A;

		if (max > A)
			max = A;
		else if(min < A)
			min = A;
	}
  
	cout << abs(max - min) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
string S,T;
int dp[3010][3010] = {};

int main(){
	cin >> S >> T;
	int N = S.size(),M = T.size();
	for(int i=1;i<=N;i++){
		for(int j=1;j<=M;j++){
			if(S[i-1]==T[j-1]) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
			else dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
		}
	}
	string ans = "";
	int a = N,b = M,res = dp[N][M];
	for(int i=N;i>=1;i--){
		for(int j=M;j>=1;j--){
			if(res-1==dp[i-1][j-1] && S[i-1]==T[j-1]){
				ans = S[i-1] + ans; res--; break;
			}
		}
	}
	cout << ans << endl;
}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sint int32_t
#define int long long int
#define all(v) v.begin() , v.end()
#define vii vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int arr[100];
int n;


int32_t main()
{   fastio;

    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>arr[i];
    }

    int ans = 1000;
    int sum = 0;
    int cnt = 0;

    for(int i=1; i<n; i++) {
        if(arr[i]>arr[i-1]) {
            int p = arr[i-1];

            cnt = ans/p;
            sum = ans%p;

            sum += cnt*arr[i];

            ans = max(ans , sum);
            sum = 0;
        }
    }
    cout<<ans<<"\n";

}

Measured memory_bytes: 3612
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
r.sort()

tmp = p[-x:] + q[-y:]
tmp.sort()

from collections import deque
tmp = deque(tmp)

while r and tmp[0] < r[-1]:
    tmp.popleft()
    tmp.append(r.pop())

print(sum(list(tmp)))


Measured memory_bytes: 110316
import io.StdIn

object Main extends App {

  val out = new java.io.PrintWriter(System.out)
  val Array(n, q) = StdIn.readLine.split(" ").map(_.toInt)
  val djs = new DisjointSet(n)

  (0 until q).foreach { _ =>
    val Array(com, x, y) = StdIn.readLine.split(" ").map(_.toInt)
    if(com == 0) djs.unite(x, y)
    else out.println(if(djs.same(x, y)) "1" else "0")
  }

  out.flush

  class DisjointSet(size: Int) {
    var rank, p = Array.fill[Int](size)(0)

    (0 until size).foreach(i => makeSet(i))

    def makeSet(x: Int): Unit = {
      p(x) = x
      rank(x) = 0
    }
    def findSet(x: Int): Int = {
      if(x != p(x)) p(x) = findSet(p(x))
      p(x)
    }
    def unite(x: Int, y: Int): Unit = {
      def link(x: Int, y: Int): Unit = {
        if(rank(x) > rank(x)) p(y) = x
        else {
          p(x) = y
          if(rank(x) == rank(y)) rank(y) += 1
        }
      }

      link(findSet(x), findSet(y))
    }
    def same(x: Int, y: Int): Boolean = {
      findSet(x) == findSet(y)
    }
  }
}


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

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> s(n, 0);
  for (int i = 0; i < k; i++)
  {
    int d;
    cin >> d;
    for (int i = 0; i < d; i++)
    {
      int a;
      cin >> a;
      s[a - 1]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (!s[i])
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3588
#include <stdio.h>

void ans(int n){
	int a=0, b=0, c=0;
	int k=n;

	while(k/3600>0) {k-=3600; a++; }
	while(k/60>0) {k-=60; b++;}
	c=k;

	if(a<10) printf("0%d:", a);
	else printf("%d:", a);
	if(b<10) printf("0%d:", b);
	else printf("%d:", b);
	if(c<10) printf("0%d\n", c);
	else printf("%d\n", c);
}

int main(void){
	
	while(1){
		int h=0, m=0, s=0;
		scanf("%d %d %d", &h, &m, &s);
			
		if(h==-1) break;
		else{
			int rem = 2*3600 - h*3600 - m*60 - s;
			
			ans(rem);
			ans(3*rem);		
		}
	}

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
ll n,a,b;
ll h[100005];

bool check(ll x){
  ll y = 0;
  rep(i,n){
    ll tmp = h[i] - x * b;
    if(tmp <= 0) continue;
    y += (tmp+a-1)/a;
    if(y > x) return false;
  }
  return true;
}

int main(){
  cin >> n >> a >> b;
  
  a -= b;
  
  rep(i,n) cin >> h[i];
  
  ll l = 0, r = 1000000000 + 5;
  while(r-l>1){
    ll c = (l+r)/2;
    if(check(c)) r = c;
    else l = c;
  }
  
  cout << r << endl;
    
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	int day[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	int i,j,ans;
	int m,d;
	while(1){
		cin>>m>>d;
		if(m==0&&d==0)break;
		if(m==1&&d<5){
			ans=(d+2)%7;
		}
		else{
			int sum=0;
			for(i=1;i<m;i++){
				sum+=day[i];
			}
			sum+=d;
			ans=(sum-5)%7;
		}
		if(ans==0){
			cout<<"Monday"<<endl;
		}
		else if(ans==1)cout<<"Tuesday"<<endl;
		else if(ans==2)cout<<"Wednesday"<<endl;
		else if(ans==3)cout<<"Thursday"<<endl;
		else if(ans==4)cout<<"Friday"<<endl;
		else if(ans==5)cout<<"Saturday"<<endl;
		else cout<<"Sunday"<<endl;
	}
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (N % 2 == 0 && S.substr(0, N / 2) == S.substr(N / 2, N)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


signed main() {
    while(1) {
        int n,a,b,c,x;
        cin >> n >> a >> b >> c >> x;
        if(n==0&&a==0&&b==0&&c==0&&x==0) return 0;
        vector<int> y(n);
        for(int i=0; i<n; i++) cin >> y[i];
        int idx=0;
        bool flag=false;
        for(int frame=1; frame<=10001; frame++){
            if(x==y[idx]){
                idx++;
            }
            if(idx==n){
                cout << frame-1 << endl;
                flag=true;
                break;
            }
            x = (a*x+b)%c;
        }
        if(!flag) cout <<"-1"<< endl;
    }
}


Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

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

	int s, w;
	cin >> s >> w;

	if (s > w) cout << "safe" << "\n";
	else cout << "unsafe" << "\n";

	return 0;
}



Measured memory_bytes: 3636
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
  cin.tie(0);
  int y, m, d;
  char s1, s2;
  cin >> y >> s1 >> m >> s2 >> d;
  cout << (m <= 4 ? "Heisei" : "TBD") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
struct N{
  struct N *oya;
  struct N *left;
  struct N *right;
  int key;
};
typedef struct N * NODE;
NODE root;

NODE find(NODE d,int k){
  while(d!=NULL && k!=d->key){
    if(d->key > k){
      d=d->left;
    }
    else {
      d=d->right;
    }
  }
  return d;
}


void Ins(int ke){
  NODE y=NULL;
  NODE x=root;
  NODE z;
  z=malloc(sizeof(struct N));
  z->left=NULL;
  z->right=NULL;
  z->key=ke;

  while(x!=NULL){
    y=x;
    if(x->key > z->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }

  z->oya=y;

  if(y==NULL){
    root=z;
  }
  else if(y->key > z->key){
    y->left=z;
  }
  else(y->right=z);
}

void preorder(NODE a){
  if(a==NULL)return;
  printf(" %d",a->key);
  preorder(a->left);
  preorder(a->right);
}

void inorder(NODE a){
  if(a==NULL)return;

  inorder(a->left);

  printf(" %d",a->key);

  inorder(a->right);
}


int main(void){
  int i,n,j;
  char c[20];
  scanf("%d",&n);

  for(i=0;i < n;i++){

    scanf("%s",c);

    if(c[0]=='i'){
      scanf("%d",&j);
      Ins(j);
    }
    else if(c[0]=='f'){
      scanf("%d",&j);
      NODE e=find(root,j);
      if(e!=NULL)printf("yes\n");
      else printf("no\n");
    }

      
    else if(c[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 20476
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	string S;
	cin >> S;
	string A;
	A += S[0];
	int ans = 1, i = 1, j = 1;
	while (i + 1 <= S.size())
	{
		j = 1;
		while (A == S.substr(i, j))
		{
			j++;
			if (i + j > S.size())
			{
				cout << ans << endl;
				return (0);
			}
		}
		ans++;
		A = S.substr(i, j);
		i += j;
	}
	cout << ans << endl;
	return (0);
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,r;
    int k;
    int ans=0;
    cin>>a>>b>>c;
    for(int i=a;i<=b;i++){
        k=c/i;
        r=c-k*i;
        if(r==0) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3100
#include <cstdio>

#define ll long long

int main() {

    ll rez = 0;
    char ch = fgetc(stdin);
    int l = 0;

    while (ch != '\n') {
        int i;
        if(ch == 'g')
            i = 0;
        else
            i = 1;
        rez += l - i;
        l = 1 - l;
        ch = fgetc(stdin);
    }
    printf("%lld", rez);
    return 0;
}


Measured memory_bytes: 128
C = []
for i in range(3) :
    C.append(list(map(int,input().split())))
for i in range(C[0][0]+1) :
    a1 = i
    b1 = C[0][0] - i
    b2 = C[0][1] - i
    b3 = C[0][2] - i
    a2 = C[1][0] - b1
    a3 = C[2][0] - b1
    flag = 0
    if (a2+b2) == C[1][1] and (a3+b2) == C[2][1] and (a2+b3) == C[1][2] and (a3+b3) == C[2][2] :
        flag = 1
        break
if flag == 1 :
    print("Yes")
else :
    print("No")
    
    

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <ctime>

using namespace std;

#define LOCAL 0
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1& arg1){
    cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1& arg1, Args&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " /";
    __f(comma + 1, args...);
}

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

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 7;

int main() {
#if LOCAL
    freopen("CP.inp", "r", stdin);
//    freopen("CP.out", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vi a(n); fore(i, 0, n) cin >> a[i];
    vi b(n); fore(i, 0, n) cin >> b[i];
    fore(i, 0, n) maxi(a[i] -= b[i], 0);
    int ans = 0;
    fore(i, 0, n) ans += a[i];
    cout << ans << '\n';
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  string ans;
  for(int i = 0; i < n; i += 2) {
    ans += s[i];
  }
  
  cout << ans << endl;
}  


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define set multiset
#define null NULL
#define ort (b+s)/2

using namespace std;

typedef long long Lint;
typedef long double db;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair<db,db> dd;
typedef pair<int,string> is;

const int maxn = 1000020;
const int K = 320;
const int MOd = 1e9 + 7;

Lint ar[maxn], a, k;
vector<Lint> v;

Lint f( Lint x ) {
	Lint ans = 0;
	for(int i=1;i<=a;i++) {
		if( ar[i] == 0 ) {
			if( 0 <= x )
				ans += a;
		} else if( ar[i] > 0 ) {
			Lint h = x/ar[i];
			// -3/4 || -4/4
			if( x < 0 && x%ar[i] != 0 ) h--;
			int t = upper_bound( all( v ), h ) - v.begin();
			ans += t;//printf("asdasd %lld\n",h);
		} else {
			// 4, -3
			Lint h = x/ar[i];
			// -3, -2
			if( x < 0 && (-x)%(-ar[i]) != 0 ) h++;
			int t = v.end()-lower_bound( all( v ), h );
			//printf("asd %lld\n",h);
			ans += t;
		}
		if( ar[i]*ar[i] <= x ) ans--;
		//printf("%d --> %d (%lld)\n",i,ans,ar[i]);
	}
	//printf("x=%lld --> ans=%lld\n",x,ans);
	return ans/2;
}
int dn[maxn][2];
void solve() {
	string s;
	cin >> s;
	dn[s.size()][1] = 1;
	for(int i=s.size()-1;i>=0;i--) {
		s[i] -= '0';
		dn[i][0] = min( dn[i+1][1] + 1 + s[i], dn[i+1][0] + s[i] );
		dn[i][1] = min( dn[i+1][1] + 10 - s[i] - 1, dn[i+1][0] + 10 - s[i] );
		//printf("asd %d %d\n",dn[i][0],dn[i][1]);
	}
	cout << min( dn[0][0], dn[0][1] + 1 ) << endl;
}

int main(  ) {


    int n = 1;
    //scanf("%d",&n);
    while( n-- ) solve();

    return 0;
}

Measured memory_bytes: 9476
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 2000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main() {
#define int long long
	int n;
	cin >> n;
	vector<pair<int, int>> wow;
	REP(i, n) {
		int a;
		cin >> a;
		wow.push_back(make_pair(a, 0));
	}
	REP(i, n) {
		int a;
		cin >> a;
		wow.push_back(make_pair(a, 1));
	}
	sort(wow.begin(), wow.end());
	int ans = 1;
	int cnt = 1;
	int backing = wow[0].second;
	for (int i = 1;i < wow.size();++i) {
		if (backing == wow[i].second) {
			cnt++;
		}
		else {
			if (cnt != 0) {
				ans *= cnt;
				ans %= MAX_MOD;
				cnt--;
			}else{
				backing = wow[i].second;
				cnt = 1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6384
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if (A + B >= 10) {
        cout << "error" << endl;
    } else {
        cout << A + B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i

a_flag_count = 0
b_flag_count = 0
a_b_flag_count = 0
count = 0
n.times do |t|
  str = gets.chomp
  count += str.scan(/AB/).size
  a_flag = str[-1] == "A"
  b_flag = str[0] == "B"
  if a_flag && b_flag then
    a_b_flag_count += 1
  elsif a_flag then
    a_flag_count += 1
  elsif b_flag then
    b_flag_count += 1
  end
end

if a_b_flag_count > 0 then
  count += (a_b_flag_count - 1)
  if a_flag_count > 0 then
    count += 1
    a_flag_count -= 1
  end
  if b_flag_count > 0 then
    count += 1
    b_flag_count -= 1
  end
  count += [a_flag_count, b_flag_count].min
else
  count += [a_flag_count, b_flag_count].min
end

puts count



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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MAX_W = 100000;

struct Node {
    int parent = -1;
    int left = -1;
    int right = -1;

    Node() : parent(-1), left(-1), right(-1) {}
    Node(int p, int l, int r) : parent(p), left(l), right(r) {}
    Node(Node& n) {
        parent = n.parent;
        left = n.left;
        right = n.right;
    }
};

int root(vector<Node>& nodes) {
    int i = 0;
    while (nodes[i].parent != -1) { i = nodes[i].parent; }
    return i;
}

void preorder(vector<Node>& nodes, vi& a, int i) {
    a.push_back(i);
    if (nodes[i].left != -1) { preorder(nodes, a, nodes[i].left); }
    if (nodes[i].right != -1) { preorder(nodes, a, nodes[i].right); }
}

void inorder(vector<Node>& nodes, vi& a, int i) {
    if (nodes[i].left != -1) { inorder(nodes, a, nodes[i].left); }
    a.push_back(i);
    if (nodes[i].right != -1) { inorder(nodes, a, nodes[i].right); }
}

void postorder(vector<Node>& nodes, vi& a, int i) {
    if (nodes[i].left != -1) { postorder(nodes, a, nodes[i].left); }
    if (nodes[i].right != -1) { postorder(nodes, a, nodes[i].right); }
    a.push_back(i);
}

void print(const vi& a) {
    int n = a.size();
    rep(i, 0, n) {
        cout << " " << a[i];
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<Node> nodes(n);

    rep(i, 0, n) {
        int id, left, right;
        cin >> id >> left >> right;

        nodes[id].left = left;
        nodes[id].right = right;

        if (left != -1) { nodes[left].parent = id; }
        if (right != -1) { nodes[right].parent = id; }
    }

    vi pre, in, post;
    int r = root(nodes);

    preorder(nodes, pre, r);
    cout << "Preorder" << endl;
    print(pre);

    inorder(nodes, in, r);
    cout << "Inorder" << endl;
    print(in);

    postorder(nodes, post, r);
    cout << "Postorder" << endl;
    print(post);

    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

vector<pi> G[100005];
int vis[100005], color[100005];

void dfs(int u, int c) {
	vis[u] = 1;
	color[u] = c;
	for(pi p:G[u]) {
		int v = p.F, cc = p.S;
		if(!vis[v]) {
			dfs(v, c^cc);
		} 
	}
} 

int main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=0;i<n-1;i++) {
		int u, v, w;
		cin >> u >> v >> w;
		G[u].EB(v, w&1);
		G[v].EB(u, w&1);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		cout << color[i] << endl; 
}



Measured memory_bytes: 7936
#include<iostream>
#include<complex>

#define EPS 1e-10
using namespace std;

typedef complex<double> P;


double cross(P p1,P p2){
	return p1.real()*p2.imag()-p1.imag()*p2.real();
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		P p[2];
		for(int i=0;i<2;i++){
			P tp[2];
			for(int j=0;j<2;j++){
				cin>>tp[j].real()>>tp[j].imag();
			}
			p[i]=tp[1]-tp[0];
		}
		if(abs(cross(p[0],p[1]))<=EPS)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1224
import java.io.PrintWriter;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[][] h = new int[n][3];
        for (int i=0; i < n; i++) {
            h[i][0] = in.nextInt();
            h[i][1] = in.nextInt();
            h[i][2] = in.nextInt();
        }

        int[][] dp = new int[n+1][3];
        int last = -1;
        // i = day
        for (int i=0; i < n; i++) {
            // j = today's task
            for (int j=0; j < 3; j++) {
                // k = yesterday's task
                int max = 0;
                for (int k=0; k < 3; k++) {
                    if (j == k && i != 0)
                        continue;
                    if (max < dp[i][k] + h[i][k]) {
                        max = dp[i][k] + h[i][k];
                    }
                }
                dp[i+1][j] = max;
            }
        }

        int max = 0;
        for (int i=0; i < 3; i++) {
            max = Math.max(max, dp[n][i]);
        }
        // out.println(Arrays.deepToString(dp));
        out.println(max);
    }

}


Measured memory_bytes: 98840
N,M=list(map(int,input().strip().split(' ')))
Gates=[]
left=[]
right=[]
for _ in range(M):
    a,b=list(map(int,input().strip().split(' ')))
    left+=[a]
    right+=[b]
    Gates+=[(a,b)]
ans=max(min(right)-max(left)+1,0)
print(ans)




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

int main() {
  int n;
  cin >> n;
  
  string s;
  map<string, int> m;
  for(int i=0; i<n; i++) {
    cin >> s;
    m[s]++;
  }
  
  int num = 0;
  for(auto p : m) num = max(num, p.second);
  for(auto p : m) if(p.second == num) cout << p.first << endl;
  return 0;
}

Measured memory_bytes: 19208
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,m,ans=0;
    cin>>n>>m;
    long long h[n+1],a,b;
    vector <long long> j(n+1,0);
    f(i,1,n+1){
        cin>>h[i];
    }
    f(i,0,m){
        cin>>a>>b;
        if(h[a]>h[b]){
            j[b]=1;
        }
        else if(h[a]<h[b]){
            j[a]=1;
        }
        else{
            j[a]=j[b]=1;
        }
    }
    f(i,1,n+1){
        if(j[i]==0){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4780
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MAX 105
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int n,head[MAX],cnt=0,deg[MAX];
struct edge{
	int next,to;
}a[MAX<<1];
void add(int x,int y)
{
	a[++cnt].next=head[x];
	a[cnt].to=y;
	head[x]=cnt;
	deg[y]++;
}
int mxdeg[MAX],dep[MAX],ans1=INF;
long long ans2;
queue<int> q;
void solve(int x,int y)
{
	int mxdep=0;
	long long mxv;
	for(int i=1;i<=n;i++)
		mxdeg[i]=0,dep[i]=0;
	q.push(x),dep[x]=1;
	if(y) q.push(y),dep[y]=1;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		mxdeg[dep[u]]=max(mxdeg[dep[u]],deg[u]);
		mxdep=max(mxdep,dep[u]);
		for(int i=head[u];i;i=a[i].next)
		{
			int t=a[i].to;
			if(!dep[t]) q.push(t),dep[t]=dep[u]+1;
		}
	}
	mxv=mxdeg[1];
	if(y) mxv--,mxv*=2;
	for(int i=2;i<=n;i++)
	{
		if(mxdeg[i]==1) break;
		mxv=mxv*(mxdeg[i]-1);
	}
	if(mxdep<ans1||mxdep==ans1&&mxv<ans2)
		ans1=mxdep,ans2=mxv;
}
int main()
{
	n=read();
	int x,y;
	for(int i=1;i<n;i++)
		x=read(),y=read(),add(x,y),add(y,x);
	if(n==2) return puts("1 2"),0;
	for(int i=1;i<=n;i++)
	{
		solve(i,0);
		for(int j=head[i];j;j=a[j].next)
			if(a[j].to>i) solve(i,a[j].to);
	}
	printf("%d %lld",ans1,ans2);
	return 0;
}


Measured memory_bytes: 3736
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i+j)%2 == 0) printf("#");
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	string s1;
	cin>>s1;
	int count=0;
	if(s.length()==3 && s1.length()==3){
		for(int i=0;i<3;i++){
			if(s[i]==s1[i]){
				count++;
			}
		}
		cout<<count;
	}
  	return 0;
}

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

int main() {
  int n, q; cin >> n >> q;
  queue<pair<string, int> > que;
  for (int i = 0; i < n; i++) {
    string name;
    int time;
    cin >> name >> time;
    que.push(make_pair(name, time));
  }
  int cnt = 0;
  while (!que.empty()) {
    if (que.front().second <= q) {
      cnt += que.front().second;
      cout << que.front().first << " " << cnt << endl;
      que.pop();
    } else {
      que.push(make_pair(que.front().first, que.front().second - q));
      cnt += q;
      que.pop();
    }
  }
}


Measured memory_bytes: 6208
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
int main() {
	int N;
	std::cin >> N;
	std::vector<int>a(N);
	int Alise = 0, Bob = 0;
	for (int i = 0;i < N;++i) {
		std::cin >> a[i];
	}
	
	std::sort(a.begin(), a.end(), std::greater<>());
	for (int i = 0;i < N;++i) {
		if (i % 2 == 0) {
			Alise += a[i];
		}
		else {
			Bob += a[i];
		}
	}
	std::cout << Alise - Bob << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int cnt = (n + 1) / 2;

    cout.precision(10);
    cout << fixed << 1.0 * cnt / n << endl;

    return 0;
}


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

int main(){
  int n,m;
  cin>>n>>m;
  priority_queue <int> q;
  rep(i,n){
    ll a;
    cin>>a;
    q.push(a);
  }
  rep(i,m){
    ll t=q.top();
    q.pop();
    t/=2;
    q.push(t);
  }
  ll ans=0;
  while (!q.empty()){
    ans+=q.top();
    q.pop();
  }

  cout<<ans;
}


Measured memory_bytes: 892
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z;
    cin >> x >> y >> z;
    cout << (x - z) / (y + z) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int X, A, B;
  cin >> X >> A >> B;
  if(-A+B<=0){
    cout << "delicious" << endl;
  }
  else if(-A+B>X){
    cout << "dangerous" << endl;
  }
  else cout << "safe" << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools
n=int(input())
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
w=sorted(p)
p=tuple(p)
q=tuple(q)
ans=[0,0]
for a,i in enumerate(list(itertools.permutations(w))):
    if i==p:
        ans[0]=a
    if i==q:
        ans[1]=a
print(abs(ans[0]-ans[1]))


Measured memory_bytes: 8052
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, end) for (int i = begin; i > end; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N, M;
int k[20];
int s[20][20];
int p[20];

int main()
{
    cin >> N >> M;
    rep(i, 0, M)
    {
        cin >> k[i];
        rep(j, 0, k[i])
        {
            cin >> s[i][j];
        }
    }
    rep(i, 0, M)
    {
        cin >> p[i];
    }

    ll ans = 0;
    for (int sw = 0; sw < (1 << N); sw++)
    {
        int on_lump_num = 0;
        for (int i = 0; i < M; i++)
        {
            int on_num = 0;
            for (int j = 0; j < k[i]; j++)
            {
                if ((sw & (1 << (s[i][j] - 1))) != 0)
                {
                    on_num++;
                }
            }
            if (on_num % 2 == p[i])
            {
                on_lump_num++;
            }
        }
        if (on_lump_num == M)
        {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=[]
x=0
for i in range(n):
	if i%2==0:
		x+=a[i]
	else:
		x-=a[i]
ans.append(x)
for i in range(n-1):
	x=2*a[i]-x
	ans.append(x)
print(*ans)

Measured memory_bytes: 14092
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll t,n=0,k,k1,k2,b,a,m,c;
    cin>>a>>b>>c>>k;
    while(b<=a){
        b*=2;
        n++;
    }
    while(c<=b){
        c*=2;
        n++;
    }
    if(n<=k)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
    while(t--){
        ll ans=0,c=0;
        cin>>n;
        //string s;
        //cin>>s;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];

    }
    return 0;
}


Measured memory_bytes: 3620
// A Dynamic Programming based 
// C# program to find minimum 
// number operations to 
// convert str1 to str2 
using System;
using System.Collections.Generic;
using System.Linq;
class GFG
{
    static Dictionary<int, int> ans = new Dictionary<int, int>();
    public static void Main()
    {
        var input1 = Console.ReadLine().Split(' ');

        var n = int.Parse(input1[0]);
        var t = int.Parse(input1[1]);

        while (n > 0)
        {
            var input2 = Console.ReadLine().Split(' ');

            var c1 = int.Parse(input2[0]);
            var t2 = int.Parse(input2[1]);

            if (!ans.ContainsKey(c1))
                ans.Add(c1, t2);
            else
            {
                var tt = ans[c1];
                ans[c1] = Math.Min(tt, t2);
            }
            n--;
        }

        var minCost = ans.Where(x => x.Value <= t);

        if (minCost.Count() == 0)
            Console.Write("TLE");
        else
        {
            int min = int.MaxValue;
            foreach (var p in minCost)
            {
                if (p.Key < min)
                    min = p.Key;

            }
            Console.Write(min);
        }

    }


}



Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
    }
    return res;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll d,m;
    cin>>m>>d;
    ll cnt=0;
    for(int i=10;i<=d;i++){
        ll a=i%10;
        ll b=i/10;
        if((a*b)<=m && a>=2 && b>=2) cnt++;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256