akhauriyash/Code-Regression huggingface dataset:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

ss=list(S)
count=1
for i in range(1,len(ss)):
    if ss[i-1]!=ss[i]:
        count+=1
print(count)

Measured memory_bytes: 4084
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HBonsai
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CEnergyDrinkCollector solver = new CEnergyDrinkCollector();
        solver.solve(1, in, out);
        out.close();
    }

    static class CEnergyDrinkCollector {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            List<Pair> stores = new ArrayList<>();

            for (int i = 0; i < N; i++) {
                stores.add(new Pair(in.nextLong(), in.nextLong()));
            }
            stores.sort((x, y) -> x.first - y.first == 0 ? 0 : x.first - y.first > 0? 1:-1);

            long ans = 0;
            long remain = M;
            out:
            for (int i = 0; i < N; i++) {
                Pair store = stores.get(i);
                for (long j = store.second; j > 0; j--) {
                    ans += store.first;
                    remain--;
                    if (remain <= 0) break out;
                }
            }
            out.println(ans);
        }

        class Pair {
            public long first;
            public long second;

            public Pair(long first, long second) {
                this.first = first;
                this.second = second;
            }

        }

    }
}



Measured memory_bytes: 85204
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	long long int x;

	cin >> x;
	if (x % 11 == 0) {
		cout << (x / 11) * 2 << endl;
	}
	else {
		if (x % 11 <= 6) {
			cout << (x / 11) * 2 + 1 << endl;
		}
		else {
			cout << (x / 11) * 2 + 2 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  map<ll,int>mp;
  rep(i,n){
    ll a;
    cin >> a;
    mp[a]++;
  }
  int q;
  cin >> q;
  int cnt=0;
  rep(i,q){
    ll b;
    cin >> b;
    if(mp[b])cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 12388
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let k: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut xv = vec![0i64; n];
    for i in 0..n - 1 {
        xv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    xv[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut yv = vec![0i64; n];
    for i in 0..n {
        yv[i] = (xv[i] - xv[0]).abs();
    }

    let mut ans = xv[0].abs() + (xv[n - 1] - xv[0]).abs();
    for i in 0..n - k + 1 {
        ans = min(
            ans,
            min(
                xv[i].abs() + (xv[i + k - 1] - xv[i]).abs(),
                (xv[i + k - 1] - xv[i]).abs() + xv[i + k - 1].abs(),
            ),
        );
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9 + 7;
#define MAXN 21
int n;
int a[MAXN][MAXN];
lli dp[1 << MAXN][MAXN];
lli solve(int pos, int msk)
{
	if (pos == n) {
		if (msk == (1 << n) - 1)
			return 1ll;
		return 0ll;
	}
	if (dp[msk][pos] != -1) return dp[msk][pos];
	lli ans = 0ll;
	for (int i = 0; i < n; i++) {
		if (a[i][pos] == 1 && (msk & (1 << i)) == 0) {
			ans = (ans + solve(pos + 1, (msk | (1 << i))) % mod ) % mod;
		}
	}
	return dp[msk][pos] = ans % mod;
}

int main() {
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	memset(dp, -1, sizeof(dp));
	cout << solve(0, 0) % mod << endl;
	return 0;
}


Measured memory_bytes: 344320
#include <stdint.h>

#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

int val[400000 + 1];
int count[400000 + 1];

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  int64_t sum_case = 0;
  for(int i = 0; i < n; i++){
    int v;
    std::cin >> v;
    val[i] = v;
    sum_case += count[v];
    count[v]++;
  }

  for(int i = 0; i < n; i++){
    std::cout << (sum_case - (count[val[i]] - 1)) << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main(void){
    string S;
    char cur;
    int st = 0;
    int ans = 0;
    
    cin >> S;
    
    cur = S[0];
    ++st;
    for(int i = 1 ; i < S.size() ; ++i){
        if(st == 0){
            cur = S[i];
            ++st;
        }
        else if(S[i] == cur)
            ++st;
        else{
            --st;
             ans += 2;
        }
    }
    
    cout << ans <<endl;
    
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}


int main(){
    fastio
    int h,w,m,x,y;
    cin >> h >> w >> m;
    set<vector<int>> have;
    vector<int> rows(h), cols(w);
    for(int i=0;i<m;i++) {
        cin >> x >> y;
        x--; y--;
        have.insert({x,y});
        rows[x]++; cols[y]++;
    }
    vector<int> toprow, topcol;
    int r=0,c=0;
    for(int i=0;i<h;i++) {
        if(rows[i] > r) {
            toprow.clear();
            r = rows[i];
        }
        if(rows[i] == r) toprow.push_back(i);
    }


    for(int i=0;i<w;i++) {
        if(cols[i] > c) {
            topcol.clear();
            c = cols[i];
        }
        if(cols[i] == c) topcol.push_back(i);
    }
    bool found = false;
    for(auto x : toprow) {
        for(auto y : topcol)
            if(!have.count({x,y})) found = true;
        if(found) break;
    }
    int res = r+c;
    if(!found) res--;
    cout << res;
}


Measured memory_bytes: 37800
#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++)
typedef long long ll;
using namespace std;
const ll mod=1e+7+7;
int main(void){
    string s;cin>>s;
    reverse(s.begin(),s.end());
    s+='0';
    int n=s.size();
    int dp[n+3][2];//右はsより大きいことが確定してるかどうか
    rep(i,n+1) dp[i][0]=dp[i][1]=mod;
    dp[0][0]=0;
    //dp[0][1]=0;
    rep(i,n)rep(j,2){
        int now=s[i]-'0';
        int ni=i+1;
        now+=j;
        rep(a,10){
            int nj=0;
            int b=a-now;
            if(b<0){
                nj=1;
                b+=10;
            }
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+a+b);
        }
    }
    int res=min(dp[n][0],dp[n][1]);
    //rep(i,n+1)cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
    cout<<res<<endl;
}


Measured memory_bytes: 9220
#include<stdio.h>
#include<math.h>
int main(){
    int n,ax,ay,bx,by,cx,cy;
    double t,x,y;
    scanf("%d%d%d%d",&ax,&ay,&bx,&by);
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&cx,&cy);
        t=((ax-bx)*(ax-cx)+(ay-by)*(ay-cy))/(pow(ax-bx,2)+pow(ay-by,2));
        x=ax+t*(bx-ax);
        y=ay+t*(by-ay);
        printf("%.10f %.10f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);

        if(a==b){
                printf("%d\n",c);
        }else if(a==c){
                printf("%d\n",b);
        }else if(c==b){
                printf("%d\n",a);
        }

        return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#define LEN 1000000
  
typedef struct pp{
  char name[100];
  int t;
}P;
 
P Q[LEN+1];
  
int main(){
  int n, i, q, sum =0, last, cnt=0;
  scanf("%d %d", &n, &q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  i = 1;
  last = n;
  while(1){
    if(Q[i].t > q){
      sum += q;
      strcpy(Q[last+1].name, Q[i].name);
      Q[last+1].t = Q[i].t - q;
      last++;
    } else {
      sum += Q[i].t;
      printf("%s %d\n", Q[i].name, sum);
      cnt++;
    }
    i++;
    if(cnt == n) break;
  }   
  return 0;
}

Measured memory_bytes: 21828
#include<stdio.h>
#include<string.h>
int n;
int h; 
int max;
char s[105];
int main()
{
	int i;
	scanf("%d",&n);
	scanf("%s",s);
	for(i=0;i<n;i++)
	{
		if(s[i]=='I')
		  h++;
		else h--;
		if(h>max)
		  max=h;
	}
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
using namespace std;

int main()
{
	int K, S;
	cin >> K >> S;
	int count = 0;
	for (int X = 0; X <= K; X++) {
		for (int Y = 0; Y <= K; Y++) {
			int Z = S - X - Y;
			if (Z >= 0 && Z <= K) count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

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

  bool approved = true;
  
  for (int n=0; approved && n<N; ++n) {
    int A;
    cin >> A;
    if (A%2)
      continue;
    approved = (A%3==0 || A%5==0);
  }

  cout << (approved ? "APPROVED" : "DENIED") << endl;

  return 0;
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

signed main() {
    
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a<=c && c <= b) Yes;
    else No;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if ((a+b)>(c+d)){
  cout<<"Left"<<endl;}
  else if ((a+b)==(c+d)){
  cout<<"Balanced"<<endl;}
  else if ((a+b)<(c+d)){
  cout<<"Right"<<endl;}
}

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

int main() 
{
    long int n;
    cin>>n;
    long int a[n],i,j,count=0,countmain=0;
    vector<int>c(1000001,0);
    for(i=0;i<n;i++)
    {
      cin>>a[i];
      c[a[i]]++;
    }
     vector<int>v(1000001,0);
    for(i=1;i<1000001;i++)
    {
      if(c[i]==0 || v[i]==1)
      continue;
      if(c[i]==1 && v[i]==0)
      count++;
      for(j=i;j<=1000000;j+=i)
      v[j]=1;
    }
    cout<<count<<endl;
    
}

Measured memory_bytes: 12692
#include <bits/stdc++.h>
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define ALL(V) V.begin(),V.end()
#define f1(a,b) for(int a=1;a<=b;a++)
#define f0(a,b) for(int a=0;a<b;a++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define de(x) cout<<#x<<": "<<x<<endl
using namespace std;
const LL N=1e6+69, base=1024*1024,mod=1e9+7;
int32_t main(void) {
    boost;
    LL a,b,c,k;
    cin>>a>>b>>c>>k;
    k%=2;
    LL wyn=a-b;
    if(k==1) wyn*=-1;
    cout<<wyn<<endl;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())
k = [0] * N
for i in range(N):
    if S[i] == "R":
        k[i] = 2
    elif S[i] == "G":
        k[i] = 3
    else:
        k[i] = 5
a = k.count(2)
b = k.count(3)
c = N - a - b
ans = a*b*c
for i in range (1,(N + 1)//2):
    for j in range (N - 2 * i):
        if k[j] * k[j + i] * k[j + 2 * i] == 30:
            ans = ans - 1
print(ans)

Measured memory_bytes: 9256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include <numeric>
#include<vector>

#define LL long long
#define MOD 1000000007

using namespace std;

LL gcd(LL C, LL D) {
	if (C < D) gcd(D, C);

	if (C%D == 0)return D;
	else gcd(D, C%D);
}
int main() {

	int N, L;
	int idealpie;
	cin >> N >> L;
	if (N % 2 == 0) {
		idealpie = (L + N - 1 + L)*(N / 2);
	}
	else {
		idealpie = (L + N - 1 + L)* (N / 2) + (L + N - 1 + L) / 2;
	}

	if (L + N - 1 < 0) {
		cout << idealpie - (L + N - 1) << endl;
	}
	else if (L > 0) {
		cout << idealpie - L << endl;
	}
	else {
		cout << idealpie << endl;
	}
}





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

using namespace std;

const long long inf = (long long) 1e18;

const int N = 1234567;

int p[N];
long long best[N];
pair < long long, pair <int, int> > e[N];

int find_set(int x) {
  if (x != p[x]) {
    p[x] = find_set(p[x]);
  }
  return p[x];
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    best[i] = inf;
  }
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    e[i] = make_pair(z, make_pair(x, y));
    best[x] = min(best[x], z + 1LL);
    best[y] = min(best[y], z + 2LL);
  }
  for (int it = 0; it < 2; it++) {
    for (int i = 0; i < n; i++) {
      if (best[i] + 2 < best[(i + 1) % n]) {
        best[(i + 1) % n] = best[i] + 2;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    e[m + i] = make_pair(best[i], make_pair(i, (i + 1) % n));
  }
  sort(e, e + m + n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
  }
  long long ans = 0;
  for (int i = 0; i < m + n; i++) {
    int x = e[i].second.first;
    int y = e[i].second.second;
    int fx = find_set(x);
    int fy = find_set(y);
    if (fx != fy) {
      ans += e[i].first;
      p[fx] = fy;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int max(int a, int b)
{ return (a > b) ? a : b; }
int min(int a, int b)
{ return (a > b) ? b : a; }

const int MAXN = 2031;
const int INF = 1000000000;

vector<int> e[MAXN];
vector<int> color;

vector<int> st;
vector<int> cycle;

bool used[MAXN];
int nextV[MAXN];

void find_ans()
{
	reverse(cycle.begin(), cycle.end());
	int st = cycle[0];
	for (int i = 0; i < cycle.size(); i++)
	{
		nextV[cycle[i]] = cycle[(i + 1) % cycle.size()];
		used[cycle[i]] = true;
	}
	bool removed;
	do {
		removed = false;
		//cerr << "new_iter" << "\n";
		int cur = st;
		do {
			//cerr << cur << "\n";
			for (int v : e[cur])
			{
				if (used[v] && nextV[cur] != v)
				{
					int p = nextV[cur];
					while (p != v)
					{
						used[p] = false;
						p = nextV[p];
					}
					nextV[cur] = v;
					//cerr << "!";
					removed = true;
					st = v;
					break;
				}
			}
			if (removed) break;
			cur = nextV[cur];
		} while (cur != st);
	} while (removed);
	
	vector<int> ans;
	int cur = st;
	do
	{
		ans.emplace_back(cur);
		cur = nextV[cur];
	} while (cur != st);
	
	cout << ans.size() <<  "\n";
	for (int x : ans) {
		cout << x + 1 << "\n";
	}
	exit(0);
}

void dfs(int u)
{
	st.push_back(u);
	color[u] = 1;
	for (int v : e[u])
	{
		if (color[v] == 1)
		{
			while (st.back() != v)
			{
				cycle.push_back(st.back());
				st.pop_back();
			}
			cycle.push_back(v);
			find_ans();
		}
		if (color[v] == 0) dfs(v);
	}

	color[u] = 2;
	st.pop_back();
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	
	std::random_device rd;
    std::mt19937 g(rd());
 
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		x--, y--;
		e[x].emplace_back(y);
	}
	
	for (int i = 0; i < n; i++)
	{
		 std::shuffle(e[i].begin(), e[i].end(), g);
	}
	
	color.assign(n, 0);
	
	for (int i = 0; i < n; i++)
	{
		if (color[i] == 0) dfs(i);
	}
	cout << "-1";

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
int main(void)
{
    int A = 0;
    int B = 0;
    int tap_num = 0;

    std::cin >> A >> B;

    if(B == 1){
        std::cout << tap_num;
        return 0;
    }

    while(1){
        tap_num++;
        if(A >= B)
            break;
        B = B - (A - 1);
    }
    std::cout << tap_num;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAXLEN = 10; 
static const int MAXN = 100005;

typedef struct {
	char name[MAXLEN];
	int time;
} Process;

typedef struct {
	Process data[MAXN];
	int front;
	int rear;
} Queue;

void enqueue(Queue * Q, Process p)
{
	Q->data[Q->rear] = p;
	Q->rear = (Q->rear + 1) % MAXN;
}

Process dequeue(Queue * Q)
{
	Process ret_val = Q->data[Q->front];
	Q->front = (Q->front + 1) % MAXN;
	
	return ret_val;
}

void initialize(Queue * Q)
{
	Q->front = 0;
	Q->rear = 0;
}

bool isEmpty(Queue * Q)
{
	if (Q->front == Q->rear)
		return true;
		
	return false;
}
Queue Q;

int main()
{
	int totalTime = 0;
	int n;
	int q;

	Process p;
	
	cin >> n;
	cin >> q;
	initialize(&Q);
	for (int i = 0; i < n; i++) {
		cin >> p.name;
		cin >> p.time;
		enqueue(&Q, p);
	}
	while (isEmpty(&Q) == false) {
		p = dequeue(&Q);
		if (p.time > q) {
			totalTime += q;
			p.time -= q;
			enqueue(&Q, p);
		}
		else {
			totalTime += p.time;
			cout << p.name << " " << totalTime << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 4640
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int nxt[200010];

void init() {
    fill(nxt, nxt + 200010, -1);

    auto dfs = [&](auto &&self, int val) -> int {
        if(val == 0) return nxt[val] = 0;
        if(nxt[val] != -1) return nxt[val];
        int cnt = __builtin_popcount(val);
        return nxt[val] = self(self, val % cnt) + 1;
    };
    
    for(int i=1; i<200010; i++) {
        dfs(dfs, i);
    }
}

int main() {
    init();
    int N; cin >> N;
    string s; cin >> s;
    reverse(s.begin(), s.end());

    int cnt = count(s.begin(), s.end(), '1');
    int cnt1 = cnt + 1, cnt2 = cnt - 1;
    ll val1 = 0, val2 = 0;
    vector<int> pow1(N), pow2(N);
    if(cnt1 > 0) {
        pow1[0] = 1 % cnt1;
        for(int i=0; i<N; i++) {
            if(i > 0) {
                pow1[i] = pow1[i-1] * 2 % cnt1;
            }
            (val1 += (s[i] - '0') * pow1[i]) %= cnt1;
        }
    }
    if(cnt2 > 0) {
        pow2[0] = 1 % cnt2;
        for(int i=0; i<N; i++) {
            if(i > 0) {
                pow2[i] = pow2[i-1] * 2 % cnt2;
            }
            (val2 += (s[i] - '0') * pow2[i]) %= cnt2;
        }
    }

    vector<int> res(N);
    for(int i=0; i<N; i++) {
        int n_cnt = cnt - (s[i] == '1') + (s[i] == '0');
        if(n_cnt == 1) res[N-1-i] = 1;
        else if(n_cnt == 0) res[N-1-i] = 0;
        else if(n_cnt == cnt1) {
            int ans = val1;
            if(s[i] == '1') {
                ans -= pow1[i];
                if(ans < 0) ans += cnt1;
            }
            if(s[i] == '0') {
                ans += pow1[i];
                ans %= cnt1;
            }
            res[N-1-i] = nxt[ans] + 1;
        }
        else if(n_cnt == cnt2) {
            int ans = val2;
            if(s[i] == '1') {
                ans -= pow2[i];
                if(ans < 0) ans += cnt2;
            }
            if(s[i] == '0') {
                ans += pow2[i];
                ans %= cnt2;
            }
            res[N-1-i] = nxt[ans] + 1;
        }
    }

    for(int i=0; i<N; i++) cout << res[i] << endl;
    return 0;
}


Measured memory_bytes: 6704
import java.util.*;

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

      int n = sc.nextInt();
      long k = sc.nextLong();

      double s = Math.pow(10,9);

      int x = (int)s + 7;

      int[] a = new int[n];
      for(int i=0;i<n;i++){
        a[i] = sc.nextInt();
      }

      int cnt1=0;
      for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
          if(a[i]>a[j]){
            cnt1++;
          }
        }
      }
      long ans1 = (cnt1*k) % x;

      int cnt2=0;
      for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
          if(a[i]>a[j]){
            cnt2++;
          }
        }
      }
      long c = (k*(k-1)/2) % x;

      long ans2 = (cnt2*c) % x;

      long ans = (ans1+ans2) % x;


      System.out.println(ans);
    }
}


Measured memory_bytes: 26184
//In the name of God
#include <bits/stdc++.h>
using namespace std;

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

const ll maxn = 2e6 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second

ll n, l, t, h[maxn], a[2][maxn], ans;

string s;

void upd(ll v){
    if(h[v] == (ll)s.size()){
        return;
    }
    ll x = ll(s[h[v]] - '0');
    if(a[x][v] == 0){
        t++;
        a[x][v] = t;
        h[t] = h[v] + 1;
    }
    upd(a[x][v]);
    return;
}

void solve(ll v){
    //cout << "# " << v << " " << h[v] << '\n';
    if((a[0][v] == 0) ^ (a[1][v] == 0)){
        ans ^= (l - h[v]) & (h[v] - l);
    }
    if(a[0][v]){
        solve(a[0][v]);
    }
    if(a[1][v]){
        solve(a[1][v]);
    }
    return;
}

int main(){
    fast_io;

    cin >> n >> l;
    for(ll i = 0; i < n; i++){
        cin >> s;
        upd(0);
    }
    solve(0);
    if(ans){
        cout << "Alice";
    }
    else{
        cout << "Bob";
    }

    return 0;
}


Measured memory_bytes: 7516
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  
  for (int i=0; i<N; i++) {
    string Si;
    cin>>Si;
    
    if (Si=="Y") {
      cout<<"Four"<<endl;
      break;
    }
    
    if (i==N-1) {
      cout<<"Three"<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

using namespace std;
using ll = long long;
using P = pair<int,int>;


int main()
{


    int n; cin>>n;
    while(n){

        if(n%10 == 7)
        {
            cout << "Yes"<<endl;
            return 0;
        }
        n/=10;
    }
    cout <<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3636
W, H, N = map(int, input().split())
square = [0, W, 0, H]

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and square[a - 1] < x:
        square[a - 1] = x
    elif a == 2 and square[a - 1] > x:
        square[a - 1] = x
    elif a == 3 and square[a - 1] < y:
        square[a - 1] = y
    elif a == 4 and square[a - 1] > y:
        square[a - 1] = y

print(max((square[1] - square[0]), 0) * max((square[3] - square[2]), 0))

Measured memory_bytes: 3064
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,m;
  cin >> n >> m;
  vector<int>a(n);
  vector<int>b(m);
  rep(i,m){
    int s, k;
    cin >> s >> k;
    a.at(s-1)++;
    a.at(k-1)++;
  }
  rep(i,n){
    cout << a.at(i) << endl;
  }
}

Measured memory_bytes: 256
import bisect
from itertools import accumulate

n, m, k = map(int, input().split())
a = tuple(accumulate(map(int, input().split())))
b = tuple(accumulate(map(int, input().split())))

cnt = 0
for i, j in enumerate(a):
    if j <= k:
        cnt = max(cnt, i + bisect.bisect_right(b, k - j) + 1)

for i, j in enumerate(b):
    if j <= k:
        cnt = max(cnt, i + bisect.bisect_right(a, k - j) + 1)

print(cnt)

Measured memory_bytes: 48624
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int main() {
  int Q;
  int q[SIZE], a[SIZE], b[SIZE];

  scanf("%d", &Q);

  priority_queue<int> pqS, pqL;

  ll sumS = 0, sumL = 0, sumB = 0;


  for (int i=0; i<Q; i++) {
    scanf("%d", q+i);

    if (q[i] == 1) {
      scanf("%d%d", a+i, b+i);
      sumB += b[i];

      if (pqS.empty() || pqS.top() >= a[i]) {
        sumS += a[i];
        pqS.push(a[i]);
      } else {
        sumL += a[i];
        pqL.push(-a[i]);
      }

      debug(pqS.size());
      debug(pqL.size());

      while (pqS.size() > pqL.size() + 1) {
        int p = pqS.top();
        sumS -= p;
        sumL += p;
        pqL.push(-p);
        pqS.pop();
      }

      while (pqL.size() > pqS.size()) {
        int p = -pqL.top();
        sumS += p;
        sumL -= p;
        pqS.push(p);
        pqL.pop();
      }

    } else {
      int x = pqS.top();
      ll s = pqS.size(), t = pqL.size();

      ll res = (x * s - sumS) + (sumL - x * t) + sumB;
      printf("%d %lld\n", x, res);
    }
  }

  return 0;
}


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

int main() {
  string str;
  while(getline(cin, str)) {
    int before = 0;
    int now;
    int ans = 0;
    for(int i = 0; i < str.length(); i++) {
      switch(str[i]) {
      case 'I': now = 1; break;
      case 'V': now = 5; break;
      case 'X': now = 10; break;
      case 'L': now = 50; break;
      case 'C': now = 100; break;
      case 'D': now = 500; break;
      case 'M': now = 1000; break;
      }
      if(now > before) {
	ans = ans - before + (now - before);
      } else {
	ans += now;
      }

      before = now;
    }


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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int m;
	cin>>m;
	string s;
	cin>>s;
	map<int,int> rpos,gpos,bpos;
	for(int i=0;i<m;i++)
	{
		if(s[i] == 'R')rpos[i] = 12345;
		if(s[i] == 'G')gpos[i] = 12345;
		if(s[i] == 'B')bpos[i] = 12345;
	}
	ll sum = 0;
	for(map<int,int>::iterator it = rpos.begin();it!=rpos.end();it++)
	{
		for(map<int,int>::iterator j = gpos.begin();j!=gpos.end();j++)
		{
			int k = min(it->first,j->first);
			int m1 = max(it->first,j->first);
			sum+=bpos.size();
			int cha = m1-k;
			int w1 = k-cha;
			int w2 = m1+cha;
			int w3 = (k+m1)/2;
			int d = 0;
			if(bpos.count(w1))sum--;
			if(bpos.count(w2))sum--;
			if(bpos.count(w3)&&w3*2 == (k+m1))sum--;
		}
	 } 
	cout<<sum<<endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int n, a, b, ans[nax];

int main () {
    cin >> n >> a >> b;

    for (int i = 1 ; i < n;  ++ i) {

        for (int j = i + 1 ; j <= n;  ++ j) {
            int dist = j - i ;
            dist = min(dist, abs(i - a) + abs(b - j) + 1);
            ans[dist] ++;
        }
    }

    for (int i = 1 ; i < n ; ++ i)
        printf("%d\n", ans[i]);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int m,f,r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		if(m==-1||f==-1){
			puts("F");
		}
		else if(m+f>=80){
			puts("A");
		}
		else if(m+f>=65){
			puts("B");
		}
		else if(m+f>=50||r>=50){
			puts("C");
		}
		else if(m+f>=30){
			puts("D");
		}
		else{
			puts("F");
		}
	}
	return 0;
}


Measured memory_bytes: 2108
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        _n: usize, k: usize1,
        s: chars
    }

    let mut s2 = s.clone();
    s2[k] = s[k].clone().to_lowercase() .collect::<Vec<_>>()[0];

    println!("{}", s2.into_iter() .collect::<String>());
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
using ll = long long;

int main()
{
  int cards[3];
  int nums[3] = {1,0,-1};
  int K;
  for(int i = 0; i < 3; ++i ){
    cin >> cards[i];
  }
  cin >> K;
  int result = 0;

  for(int i=0; i<3; ++i){
    if(cards[i]-K>=0){
      result += K*nums[i];
      break;
    }else{
      result += cards[i]*nums[i];
      K = K - cards[i];
    }
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
#define ll long long
#define PI 3.1415926535897932384626433832795l
#define MAX_NUM 1000000006
#define line printf("-----------------\n");
using namespace std;
int SET(int N, int pos) { return N = N | (1 << pos); }
int RESET(int N, int pos) { return N = N & ~(1 << pos); }
bool CHECK(int N, int pos) { return (bool)(N & (1 << pos)); }
template <typename T>
inline T __lcm(T a, T b)
{
    return (a * b) / __gcd(a, b);
}
struct node
{
    ll x, y, i;
};
int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};





void solve()
{
    ll x,n;
    cin>>x>>n;
    set<ll> st;
    for(ll i=1;i<=n;i++)
    {
        ll temp;
        cin>>temp;
        st.insert(temp);
    }
    ll temp = x;
    ll ans;
    while(1)
    {
        if(st.find(temp)==st.end())
        {
            ans=temp;
            break;
        }
        else
        {
            temp--;
        }
    }
    temp = x;
    while(1)
    {
        if(st.find(temp)==st.end())
        {
            if((temp-x)<(x-ans))
            {
                ans=temp;
            }
            break;
        }
        else
        {
            temp++;
        }
    }
    cout<<ans<<endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("inputf.txt", "r", stdin);
    //freopen("outputf.txt", "w", stdout);
#endif // ONLINE_JUDGE
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
typedef long long ll;
inline ll read() {ll x = 0;char ch = getchar(), w = 1;while(ch < '0' || ch > '9') {
if(ch == '-') w = -1;ch = getchar();}while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0';
ch = getchar();}return x * w;}
void write(ll x) {if(x < 0) putchar('-'), x = -x;if(x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(ll x) {write(x);puts("");}
void setIO() {
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
using namespace std;
const int N = 2e5 + 66;
char s[N], t[N];
int nxt[N][31], n, m;

int main() {
	scanf("%s%s", s + 1, t + 1);
	n = strlen(s + 1);
	m = strlen(t + 1);
	for(int i = 1; i <= n; ++i) s[i] -= 'a';
	for(int i = 1; i <= m; ++i) t[i] -= 'a';
	for(int i = 0; i < 26; ++i) {
		int p = 1, q = n;
		while(p <= n && s[p] != i) ++p;
		while(q >= 1 && s[q] != i) --q;
		if(p > n) continue;
		for(int j = 1; j <= p; ++j) nxt[j][i] = p;
		for(int j = q; j <= n; ++j) nxt[j][i] = p;
		int t = q;
		for(int j = q - 1; j >= p; --j) {
			nxt[j][i] = t;
			if(s[j] == i) t = j;
		}
	}
	ll ans = 0;
	int p = 1;
	while(s[p] != t[1] && p <= n) ++p;
	if(s[p] != t[1]) {
		puts("-1");
		return 0;
	}
	ans = p;
	for(int i = 2; i <= m; ++i) {
		if(nxt[p][t[i]]) {
			if(nxt[p][t[i]] <= p) ans += n - p + nxt[p][t[i]];
			else ans += nxt[p][t[i]] - p;
			p = nxt[p][t[i]];
		} else {
			puts("-1");
			return 0;
		}
	}
	writeln(ans);
	return 0;
}

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

int main() {
  string s;cin>>s;
  int n=s.size();
  int cnt0=0,cnt1=0;
  rep(i,n){
    if(s[i]=='0')cnt0++;
    else cnt1++;
  }
  int ans=min(cnt0,cnt1)*2;
  cout<<ans<<endl;
}

Measured memory_bytes: 3684
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
D = LIST()
M = INT()
T = LIST()
a = Counter(D)
b = Counter(T)
# print(a)
for d in T:
    if a[d] == 0:
        print("NO")
        exit()
    else:
        # print(d)
        # print(a[d])
        a[d] -= 1
print("YES")



Measured memory_bytes: 58812
#include <stdio.h>


int main(void){
  int q;
  scanf("%d",&q);

  double x1,y1,x2,y2,x3,y3,x4,y4;
  double x,y;//直線の交点
  double det;//行列式
  for(int i=0;i<q;i++){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
    det=(x2-x1)*(y4-y3)-(y2-y1)*(x4-x3);
    x=((x3-x4)*(x1*y2-x2*y1)+(x2-x1)*(x3*y4-x4*y3))/det;
    y=((y3-y4)*(x1*y2-x2*y1)+(y2-y1)*(x3*y4-x4*y3))/det;
    printf("%.16lf %.16lf\n",x,y);
  }
  return 0;
}



Measured memory_bytes: 2056
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])
city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if p in city:
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).zfill(6))

Measured memory_bytes: 30076
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	string s;
	int c[26] = {};

	cin >> s;
	rep(i,0,sz(s))c[s[i]-'a']++;
	rep(i,0,26){
	    if(c[i] <= 0){
	        P((char)('a'+i));
	        ret 0;
	    }
	}
	P("None");
	return  0;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[][] a = new int[n][2];
		for (int i = 0; i < n; i++) {
			a[i][0] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			a[i][1] = sc.nextInt();
		}

		int dp[][] = new int[1 << n][51];
		for (int i = 0; i < 1 << n; i++) {
			Arrays.fill(dp[i], Integer.MAX_VALUE / 3);
		}

		int[][] swap = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				swap[i][j] = (i % 2) == (j % 2) ? a[j][0] : a[j][1];
			}
		}

		dp[0][0] = 0;
		for (int mask = 0; mask < (1 << n); mask++) {
			int x = Integer.bitCount(mask);

			for (int val = 0; val < 51; val++) {
				if (dp[mask][val] == Integer.MAX_VALUE / 3) continue;

				int cost = 0;
				for (int i = 0; i < n; i++) {
					if ((mask & (1 << i)) > 0) continue;
					if (swap[x][i] >= val) {
						dp[mask | (1 << i)][swap[x][i]] = Math.min(
								dp[mask | (1 << i)][swap[x][i]],
								dp[mask][val] + cost);
					}
					cost++;
				}
			}
		}

		int answer = Integer.MAX_VALUE;
		for (int i = 0; i < 51; i++) {
			answer = Math.min(answer, dp[(1 << n) - 1][i]);
		}

		if (answer == Integer.MAX_VALUE / 3) {
			System.out.println(-1);
		} else {
			System.out.println(answer);
		}
	}
}


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

#define FOR( i, m, n )   for( int i = m; i < n; i++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

int msprime[300001];

int main(){
  int cnt = 1;
  msprime[0] = 6;

  FOR( i, 7, 300001 ){
    if( i % 7 == 1 || i % 7 == 6 ){
      REP( j, cnt ){
	if( i % msprime[j] == 0 ) break;
	if( i % msprime[j] != 0 && j == cnt - 1 ) {
	  msprime[cnt] = i;
	  cnt++;
	}
      }
    }
  }
  msprime[cnt] = 300001;
  
  
  int x;
  while( 1 ){
    cin >> x; if( x == 1 ) break;
    
    cout << x << ":";
    for( int i = 0; msprime[i] <= x; i++ ){
      if( x % msprime[i] == 0 ){
	cout << " " << msprime[i];
      }
    }
    cout << endl;
  }
  
}



Measured memory_bytes: 3132
#include <iostream>
#include <vector>

using namespace std;
int a[100001] = {0};
int main()
{
    int n, t;
    scanf("%d", &n);
    int cnt = 0;
    vector<int> val;
    for(int i = 0; i < n; i++){
        scanf("%d", &t);
        if(!a[t]){
            val.push_back(t);
        }
        a[t]++;
    }
    int l = val.size();
    for(int i = 0; i < l; i++){
        if(!(a[val[i]] % 2)) cnt++;
    }
    if(cnt % 2){
        printf("%d", l - 1);
    }
    else{
        printf("%d", l);
    }
    return 0;
}


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

int main()
{
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> a(n);
  for(int i=0;i<n;++i){
    cin >> a.at(i).first >> a.at(i).second;
  }
  sort(a.begin(),a.end());//バイトを待ち日数順にソート
  
  int ans=0;
  int i=0;
  priority_queue<int> qa;//実行できるバイトの報酬一覧
  for(int d=1;d<=m;++d){//最終日から遡っていく
    //まずその日実行できるバイトの報酬をすべて一覧に追加
    for(;i<n;++i){
      if(a.at(i).first<=d){
        qa.push(a.at(i).second);
      }else{
        break;
      }
    }
    //次に一覧の中で最も報酬の高い仕事を実行。一覧が空ならスキップ
    if(!qa.empty()){
      ans+=qa.top();
      qa.pop();
    }
  }
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  vector<char> ans(0);
  rep(i,tx-sx){
    ans.pb('R');
  }
  rep(i,ty-sy){
    ans.pb('U');
  }
  rep(i,tx-sx){
    ans.pb('L');
  }
  rep(i,ty-sy){
    ans.pb('D');
  }
  ans.pb('D');
  rep(i,tx-sx+1){
    ans.pb('R');
  }
  rep(i,ty-sy+1){
    ans.pb('U');
  }
  ans.pb('L');
  ans.pb('U');
  rep(i,tx-sx+1){
    ans.pb('L');
  }
  rep(i,ty-sy+1){
    ans.pb('D');
  }
  ans.pb('R');
  rep(i,sz(ans)){
    cout<<ans[i];
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int n,r=0,b=0;
  cin>>n;
  string s;
  cin>>s;
  fr(i,n){
    if(s[i]=='R') r++;
    else b++;
  }
  cout<<(r>b?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0;i<N;i++)
    cin >> L.at(i);
  sort(L.begin(),L.end());
  
  int ans=0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      auto itr = lower_bound(L.begin(),L.end(),L.at(i)+L.at(j));
      int a =distance(L.begin(),itr)-j-1;
      ans+=a;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256