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

class dice {
    public:
    int A,B,C,D,E,F;
    
    dice (int a, int b, int c, int d, int e, int f) {
        A = a;
        B = b;
        C = c;
        D = d;
        E = e;
        F = f;
    }
    int right (int top, int front) {
        if (top == A) {
            if (front == B) return C;
            if (front == C) return E;
            if (front == E) return D;
            if (front == D) return B;
        }
        if (top == B) {
            if (front == F) return C;
            if (front == C) return A;
            if (front == A) return D;
            if (front == D) return F;
        }
        if (top == C) {
            if (front == A) return B;
            if (front == B) return F;
            if (front == F) return E;
            if (front == E) return A;
        }
        if (top == D) {
            if (front == A) return E;
            if (front == E) return F;
            if (front == F) return B;
            if (front == B) return A;
        }
        if (top == E) {
            if (front == A) return C;
            if (front == C) return F;
            if (front == F) return D;
            if (front == D) return A;
        }
        if (top == F) {
            if (front == B) return D;
            if (front == D) return E;
            if (front == E) return C;
            if (front == C) return B;
        }
    }
};

int main() {
    int a, b, c, d, e, f, num, top, front;
    cin >> a >> b >> c >> d >> e >> f >> num;
    dice yili(a, b, c, d, e, f);
    for (int i=0;i<num;i++) {
        cin >> top >> front;
        cout << yili.right(top, front) << endl;
    }
}


Measured memory_bytes: 3084
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto nk = readints;
    int n = nk[0], k = nk[1];
    auto xs = readints;

    int[] pos, neg;
    foreach (x; xs) {
        if (x >= 0) pos ~= x;
        else neg ~= x;
    }
    neg.reverse();

    long ans = long.max;
    for (int i = 0; i < pos.length; i++) {
        long p = pos[i];

        int rest = k - i - 1;
        if (rest == 0) ans = min(ans, pos[i]);
        if (rest < 0) break;
        if (0 < rest && rest <= neg.length) {
            ans = min(ans, 2 * pos[i] + neg[rest-1] * -1);
        }
    }

    for (int i = 0; i < neg.length; i++) {
        int rest = k - i - 1;
        if (rest == 0) ans = min(ans, -neg[i]);
        if (rest < 0) break;
        if (0 < rest && rest <= pos.length) {
            ans = min(ans, 2 * -neg[i] + pos[rest-1]);
        }
    }

    writeln(ans);


}


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

long long is_prime(long long n) {
  if (n == 1) return 0;
  if (n == 2) return 1;
  if (n % 2 == 0) return 0;
  for (long long i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) return 0;
  }
  return 1;
}

int main() {
  long long n, m;
  cin >> n >> m;
  if (is_prime(m) == 1) {
    cout << 1 << endl;
    return 0;
  }
  while (m % n > 0) n++;
  cout << m / n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    int n, c[500], s[500], f[500];
    cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        cin >> c[i] >> s[i] >> f[i];
    }
    for (int j = 1; j <= n - 1;j++) {
        int t = 0;
        for (int i = j; i <= n - 1; i++) {
            t = max(((t - 1) / f[i] + 1)*f[i], s[i]) + c[i];
        }
        cout << t << endl;
    }
    cout << 0 << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
#include <thread>
using namespace std;

int main(int argc, char *argv[]) {
	long long int a, b, c;
	cin >> a >> b >> c;
	// (c - a - b)^2 > 4ab 
	if (c - a - b > 0 && (c - a - b) * (c - a - b) > 4 * a * b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}









Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <cmath>
#include <numeric>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main() {
  LL N, K;
  cin >> N >> K;
  N %= K;
  cout << min(N, K - N) << endl;
} 

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

struct UnionFind{
    vector<int> parents;
    vector<int> ranks;
    int N;

    UnionFind(int N): N(N){
        parents = vector<int>(N,-1);
        ranks = vector<int>(N,0);
    }

    int find(int a){
        if(parents[a] == -1)return a;
        int root = find(parents[a]);
        parents[a] = root;
        return root;
    }

    bool connect(int a, int b){
        int root_a = find(a);
        int root_b = find(b);
        if(root_a==root_b)return false;
        if(ranks[a]>ranks[b]){
            parents[root_b] = root_a;
        }else if(ranks[a]<ranks[b]){
            parents[root_a] = root_b;
        }else{
            parents[root_a] = root_b;
            ranks[root_b]++;
        }
        return true;
    }
};
using city = pair<int,int>;
struct Edge{
    int from;
    int to;
    ll cost;
};
int main(){
    int N;cin>>N;
    vector<city> cities;
    vector<Edge> graph;
    for(int i = 0;i < N;i++){
        int x,y;cin>>x>>y;
        cities.push_back(city{x,y});
    }
    vector<int> width(N);
    vector<int> height(N);
    for(int i = 0;i < N;i++)width[i]=i;
    for(int i = 0;i < N;i++)height[i]=i;
    sort(width.begin(),width.end(),[&cities](int const& left, int const& right){
        return cities[left].first < cities[right].first;
    });
    sort(height.begin(),height.end(),[&cities](int const& left, int const& right){
        return cities[left].second < cities[right].second;
    });
    for(int i = 0;i < N-1;i++){
        int ca = width[i];
        int cb = width[i+1];
        int cost = min(abs(cities[cb].first - cities[ca].first), abs(cities[cb].second - cities[ca].second));
        graph.push_back(Edge{ca,cb,cost});
    }
    for(int i = 0;i < N-1;i++){
        int ca = height[i];
        int cb = height[i+1];
        int cost = min(abs(cities[cb].first - cities[ca].first), abs(cities[cb].second - cities[ca].second));
        graph.push_back(Edge{ca,cb,cost});
    }
    sort(graph.begin(), graph.end(), [](const Edge& left, const Edge& right){
        return left.cost < right.cost;
    });
    UnionFind uf = UnionFind(N);
    ll res = 0;
    for(int i = 0;i < graph.size();i++){
        Edge e = graph[i];
        if(!uf.connect(e.from,e.to))continue;
        res += e.cost;
    }
    cout<<res<<endl;

    
}

Measured memory_bytes: 8048
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <deque>
using namespace std;
typedef long long ll;
const int N=1e9+7;
const ll M=1e9+7;
int main()
{
   int a,p;
   while(scanf("%d %d",&a,&p)!=-1)
   {
       cout<<(a*3+p)/2<<endl;
   }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define MAX 300000
using namespace std;
int main(){
  bool prime[MAX]={1,1,0};
  for(int i=3;i<MAX;i+=2){
    if(prime[i])continue;
    for(int j=3*i;j<MAX;j+=2*i)prime[j]=1;
  }
  int n;
  while(cin>>n,n){
    int co=0;
    for(int i=n+1;i<=2*n;i++){
      if(i!=2&&i%2==0)continue;
      if(prime[i]==0)co++;
      //cout<<i<<endl;
    }
    cout<<co<<endl;
  }
}

Measured memory_bytes: 1460
import itertools

n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
z = []
c = 0
d = 0

for i in range(n):
    z.append(i + 1)

Lst = list(itertools.permutations(z))

for i in range(len(Lst)):
    if Lst[i] == a:
        c = i
    if Lst[i] == b:
        d = i

print(abs(c - d))


Measured memory_bytes: 8052
n,s = map(int,input().split())
a = tuple(map(int,input().split()))

mod = 998244353

dp = [[0]* (s+1) for _ in range(n+1)]

for i in range(1,n+1):
    a_t = a[i-1]
    for j in range(s+1):
        dp[i][j] = dp[i-1][j]
        if(j == 0)|(j == a_t):
            dp[i][j] += 1
        if(j >= a_t):
            dp[i][j] += dp[i-1][j-a_t]
        dp[i][j] %= mod

ans = 0
for i in range(n+1):
    ans = (ans + dp[i][-1]) % mod
print(ans)

Measured memory_bytes: 112860
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h,w;
ll direction2[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
bool valid(int a,int b)
{
    if(a>=1&&a<=h&&b>=1&&b<=w)return true;
    else return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll dp[100005];
    dp[0]=0;
    for(int i=1;i<=100000;i++)dp[i]=1e7;
    for(int i=0;i<=100000;i++){
        dp[i+1]=min(dp[i+1],dp[i]+1);
        for(int j=6;i+j<=100000;j*=6){
            dp[i+j]=min(dp[i+j],dp[i]+1);
        }
        for(int j=9;i+j<=100000;j*=9){
            dp[i+j]=min(dp[i+j],dp[i]+1);
        }
    }
    cout<<dp[n];
}


Measured memory_bytes: 4428
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define eps     	            1e-8
#ifdef Lollipop
    #define line                    cout << "\n===================\n"
    #define trace(...)              __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...);
    }
#else
    #define line
    #define trace(...)
#endif

const int nax = 2e5 + 5;
int ara[nax];
double e[1005];
int n, k;

void pre_cal()
{
    for (int p = 1; p <= 1000; p++){
        double cur = 1;
        for (int i = 1; i < p; i++){
            cur += ((i * 1.0) / p);
        }
        e[p] = cur;
    }
}

int main ()
{
    #ifdef Lollipop
        freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    //fastRead;
    pre_cal();
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> ara[i];
    }
    double res = 0;
    double cur = 0;
    for (int i = 1; i <= k; i++){
        cur += e[ara[i]];
    }
    res = cur;
    for (int i = k + 1, j = 1; i <= n; i++, j++){
        cur += e[ara[i]];
        cur -= e[ara[j]];
        if (cur - eps > res){
            res = cur;
        }
    }
    cout << setprecision(10) << res << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll H, W, K; cin >> H >> W >> K;
  string c[H]; rep(i,H) cin >> c[i];

  ll result = 0;
  rep(i,1<<H) rep(j,1<<W) {
    ll count = 0;    
    rep(h,H) rep(w,W) {
      if ((i&(1<<h))&&(j&(1<<w))&&c[h][w]=='#') count++;
    }
    if (count==K) result++;
  }
  cout << result << endl;
  return 0;
}

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

long long dp[51][51][2501]={0};

int main(){
    int n,a,x[50];
    scanf("%d %d",&n,&a);
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=2500;k++){
                if(!i && !j && !k){
                    dp[i][j][k]=1;
                }
                else if(i && k<x[i-1]){
                    dp[i][j][k]=dp[i-1][j][k];
                }
                else if(i && j && k>=x[i-1]){
                    dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]];
                }
                else {
                    dp[i][j][k]=0;
                }
            }
        }
    }
    long long result=0;
    for(int i=1;i<=n;i++){
        result+=dp[n][i][i*a];
    }
    printf("%lld\n",result);
}


Measured memory_bytes: 51072
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    char c;
    cin >> c;
    cout << ++c << el;
}



Measured memory_bytes: 256
def solve():
    can_positive = False
    if len(P) > 0:
        if k < n: can_positive = True
        else: can_positive = len(M)%2 == 0
    else: can_positive = k%2 == 0

    if not can_positive: return sorted(P+M, key=lambda x:abs(x))[:k]
    P.sort()
    M.sort(reverse=True)
    a = [P.pop()] if k%2 else [1]
    while len(P) >= 2: a.append(P.pop() * P.pop())
    while len(M) >= 2: a.append(M.pop() * M.pop())
    return a[:1] + sorted(a[1:], reverse=True)[:(k-k%2)//2]

n, k = map(int, input().split())
P, M = [], []
for a in map(int, input().split()):
    if a < 0: M.append(a)
    else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)


Measured memory_bytes: 32208
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int n;
int l[2010];


signed main(){
    cin >> n;
    rep(i, 0, n) cin >> l[i];

    sort(l, l+n);

    int ans = 0;
    rep(i, 0, n) rep(j, i+1, n){
        int a = l[i], b = l[j];
        int c1 = ub(l+j+1, l+n, b-a)-l;
        int c2 = lb(l+j+1, l+n, a+b)-l;
        if(c2-c1 > 0) ans += c2-c1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define inf 0x3f3f3f
#define PI acos(-1.0)
using namespace std;

typedef long long ll;

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(c>=a&&c<=b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

ll n,m;

int main(){
  scanf("%lld %lld",&n,&m);
  if(n==2 || m== 2) printf("0\n");
  else{
    printf("%lld\n",max(n-2,1ll)*max(m-2,1ll));
  }
}



Measured memory_bytes: 256
#64
import math
a,b,C=map(int,input().split())
S=(1/2)*a*b*math.sin(math.radians(C))
h=S*2/a
L=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C)))+a+b
print(S)
print(L)
print(h)



Measured memory_bytes: 5708
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;

int main()
{
	int V, E;
	cin >> V >> E;
	vector<vector<int>> dp(1 << V, vector<int>(V, INF)), edge(V,vector<int>(V, INF));
	for (int i = 0, s, t, d; i < E; i++) {
		cin >> s >> t >> d;
		edge[s][t] = d;
	}
	dp[0][0] = 0;
	for (int i = 1; i < (1 << V); i++) {
		for (int j = 0; j < V; j++) {
			if (i & (1 << j)) {
				for (int k = 0; k < V; k++) {
					dp[i][j] = min(dp[i][j], dp[i - (1 << j)][k] + edge[k][j]);
				}
			}
		}
	}
	if (dp[(1 << V) - 1][0] == INF)
		cout << -1 << endl;
	else
		cout << dp[(1 << V) - 1][0] << endl;
	return 0;
}

Measured memory_bytes: 6236
#include <iostream>
#include <vector>
#include <string>
#include <map>
 
using namespace std;
 
int main(){
  int N,W;
  cin >>N>>W;
  vector<long long>w(N),v(N);
  map<long long,long long>m[2];
  for (int i = 0; i < N; i++) {
    cin >>w[i]>>v[i];
  }
  m[0][0]=0;
  for(int i=0;i<N;i++){
    for(auto &&it:m[0]){
      if(m[1][it.first+w[i]]<(it.second+v[i]) &&(it.first+w[i])<=W ){
        m[1][it.first+w[i]] = (it.second+v[i]);
      }
    }
    for(auto &&it:m[1]){
      m[0][it.first]=it.second;
    }
  }
  long long val = 0;
  for(auto &&it:m[0]){
    if(it.second>val )val = it.second;
  }
  cout <<val <<endl;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var K = input[0];
            var N = input[1];

            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var ans = new int[N];

            ans[0] = A[0] + K - A[N - 1];
            for (int i = 0; i < N - 1; i++)
            {
                ans[i + 1] = A[i + 1] - A[i];
            }

            Console.WriteLine(ans.Sum() - ans.Max());
        }
    }
}


Measured memory_bytes: 32740
#include <stdio.h>

int main(void){     

int a,b,c,x,y,z;     

scanf("%d%d%d",&a,&b,&c);     

if(a > b){    

x = a;    

a = b;    

b = x;  

}     

if(b > c){    

y = b;   

b = c;    

c = y;   }     

if(a > b){    

z = a;    

a = b;    

b = z;  

}     

printf("%d %d %d\n",a,b,c);     

return 0;

}
 

Measured memory_bytes: 596
#include <iostream>
#include <cstring>
#include <sstream>
#include <cctype>
#include <cmath>
#include <cstdio>
using namespace std;

void input(int* a,int n){
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
}

int main(){

	int n,a[10001];
	cin >> n;
	input(a, n);

	int count = 0;
	for (int i = 0; i < n; i++){
		bool flag=true;
		for (int j = 2; j <= sqrt(a[i]); j++){
			if (a[i] % j == 0){
				flag = false; break; 
			}
		}
		if (flag)count++;
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3100
MOD = 10 ** 9 + 7
L = gets.chomp
N = L.size

dp1 = Array.new(N + 1, 0)
dp2 = Array.new(N + 1, 0)

dp1[0] = 1
dp2[0] = 2

L[1..-1].chars.map(&:to_i).each_with_index do |l, i|
  if l == 1
    dp1[i + 1] = dp1[i] * 3 + dp2[i]
    dp2[i + 1] = dp2[i] * 2
  else
    dp1[i + 1] = dp1[i] * 3
    dp2[i + 1] = dp2[i] * 1
  end

  dp1[i + 1] %= MOD
  dp2[i + 1] %= MOD
end

puts (dp1[N - 1] + dp2[N - 1]) % MOD


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

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

const int MAXN = 1e5;

int N, L, A[MAXN+10];

int main()
{
    int i, j;

    scanf("%d%d", &N, &L);
    for(i=1; i<=N; i++) scanf("%d", &A[i]);

    int pos=-1;
    for(i=1; i<N; i++) if(A[i]+A[i+1]>=L) { pos=i; break; }
    if(pos==-1) return !printf("Impossible");

    printf("Possible\n");
    for(i=1; i<pos; i++) printf("%d\n", i);
    for(i=N-1; i>=pos; i--) printf("%d\n", i);
}


Measured memory_bytes: 1152
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

A.sort()

MOD = 10 ** 9 + 7

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]


def cmb(n, k, p):
    global fact, factinv
    if (k < 0) or (n < k):
        return 0
    r = min(k, n - k)
    return fact[n] * factinv[k] * factinv[n - k] % p


for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)


masum = 0
misum = 0
ans = 0

for i in range(N - (K - 1)):
    x = cmb(N - i - 1, K - 1, MOD)
    ans += A[-i - 1] * x
    ans -= A[i] * x
    ans %= MOD

print(ans)





Measured memory_bytes: 25824
S = input()
N = len(S)

a = (N-1) // 2
b = (N+3) // 2

#print(S[0:a])
#print(''.join(list(reversed(S[0:a]))))
#print(S[b-1:])
#print(''.join(list(reversed(S[b-1:]))))

if S == ''.join(list(reversed(S))):
  if S[0:a] == ''.join(list(reversed(S[0:a]))):
    if S[b-1:] == ''.join(list(reversed(S[b-1:]))):
      print('Yes')
      exit()

print('No')


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        Integer[] A = new Integer[N];
        Integer[] B = new Integer[M];
        for (int i=0;i<N;i++) A[i] = sc.nextInt();
        for (int i=0;i<M;i++) B[i] = sc.nextInt();
        Arrays.sort(A);
        Arrays.sort(B);

        long ans = 1L;

        for (int i=0;i<N-1;i++) {
            if (A[i]==A[i+1]) ans = 0L;
        }
        for (int i=0;i<M-1;i++) {
            if (B[i]==B[i+1]) ans = 0L;
        }
        int mod = 1_000_000_007;
        for (int i=N*M;i>0;i--) {
            int pos_A = Arrays.binarySearch(A, i);
            int pos_B = Arrays.binarySearch(B, i);
            if (pos_A>=0 && pos_B>=0) {
                continue;
            } else if (pos_A>=0 && pos_B<0) {
                int tmp = ~Arrays.binarySearch(B, i, (o1, o2)->o1>=o2?1:-1);
                ans = ans*(M-tmp)%mod;
            } else if (pos_B>=0 && pos_A<0) {
                int tmp = ~Arrays.binarySearch(A, i, (o1, o2)->o1>=o2?1:-1);
                ans = ans*(N-tmp)%mod;
            } else { // pos_A<0 && pos_B<0
                int tmp_1 = ~Arrays.binarySearch(A, i, (o1, o2)->o1>=o2?1:-1);
                int tmp_2 = ~Arrays.binarySearch(B, i, (o1, o2)->o1>=o2?1:-1);
                ans = ans*Math.max(0, (N-tmp_1)*(M-tmp_2)-(N*M-i))%mod;
            }
        }
        System.out.println(ans);
    }
}

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

int main(){
	int n;
	cin >> n;
	vector<int> city(n+1);
	vector<int> hero(n);
	rep(i, n+1) cin >> city.at(i);
	rep(i, n) cin >> hero.at(i);

	ll ans = 0;
	rep(i, n){
		int left = min(city.at(i), hero.at(i));
		ans += left;
		city.at(i) -= left;
		hero.at(i) -= left;

		int right = min(city.at(i+1), hero.at(i));
		ans += right;
		city.at(i+1) -= right;
		hero.at(i) -= right;
	}

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

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

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

const std::string YES = "YES";
const std::string Yes = "Yes";
const std::string NO = "NO";
const std::string No = "No";

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

// 4近傍（右, 下, 左, 上）
const std::vector<int> dy = { 0, -1, 0, 1 };
const std::vector<int> dx = { 1, 0, -1, 0 };

using namespace std;


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

    while (true) {
        int m;
        cin >> m;
        if (m == 0) { break; }
        vector<int> A(m), B(m);
        FOR(i, 0, m) {
            cin >> A[i] >> B[i];
        }

        vector<int> dp(1001, 0);
        dp[0] = 1;
        FOR(i, 0, m) {
            for(int j = 1000; j >= 0; --j){
                FOR(k, 1, B[i] + 1) {
                    int c = j + A[i] * k;
                    if(c <= 1000) {
                        dp[c] += dp[j];
                    }
                }
            }
        }

        int g, n;
        cin >> g;
        FOR(i, 0, g) {
            cin >> n;
            cout << dp[n] << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 3036
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

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

  int N;
  cin >> N;
  vector<int> a(N + 1, 0);
  rep(i, N) cin >> a.at(i + 1);
  vector<int> b(N + 1, 0);

  for (int i = (N / 2) + 1 ; i <= N ; i++) {
    b.at(i) = a.at(i);
  }

  for (int i = (N / 2)  ; i >= 1 ; i--) {
    int sum = 0;
    for (int j = 2 * i ; j <= N; j += i) {
      sum += b.at(j);
    }
    sum &= 1;
    if (sum != a.at(i)) b.at(i) = 1;
  }

  int M = 0;
  rep(i, N) {
    if (b.at(i + 1) == 1) M++;
  }

  cout << M << endl;
  rep(i, N) {
    if (b.at(i + 1) == 1) cout << i + 1 << " ";
  }

  cout << endl;

}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
typedef pair<int,int> pii;

int a[100005];

int main(){
    int n,k,r,s,p;
    cin >> n>>k>>r>>s>>p;
    string t;
    cin >>t;
    ll ans = 0;
    rep(i,n){
        if(t[i]=='s'){
            a[i]=r;
            ans +=r;
        }else if(t[i]=='p'){
            a[i]=s;
            ans +=s;
        }else if(t[i]=='r'){
            a[i]=p;
            ans +=p;
        }
    }

    rep(i,k){
        for(int j=0;j<n;j+=k){
            if(j+i+k>n) break;
            if(t[i+j]==t[i+j+k]){
                ans =ans-a[i+j];
                j+=k;
            }
        }
    }
    cout << ans<<endl;
}

Measured memory_bytes: 896
#include <stdio.h>

int main(){
  int n, s = 0;
  scanf("%d", &n);
  int t = n;
  while(t != 0){
    s += t%10;
    t /= 10;
  }
  if(n%s == 0) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize "03"
#pragma GCC target("sse4")

#define ll long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;a<n?i<n:i>=n;a<n?i+=1:i-=1)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int>	vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
// const ll N = 1e6+5;	
// ll a[N], b[N], dp[N], in[N], out[N], level[N], vis[N];
// vl g[N];
ll n, m;


void solve() {
	ll x, y, z, p, q, r;
	string s, t;
	cin >> s >> t;
	n = s.size(), m = t.size();
	ll dp[n+1][m+1];
	f(i, n+1){
		f(j, m+1){
			if(i == 0 || j == 0){
				dp[i][j] = 0;
			}else if(s[i-1] == t[j-1]){
				dp[i][j] = 1 + dp[i-1][j-1];
			}else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	
	string ans = "";
	ll i = n, j = m;
	while (i > 0 && j > 0) {
		if(s[i-1] == t[j-1]) {
			ans = s[i-1] + ans;
			i--, j--;
		} else if (dp[i-1][j] > dp[i][j-1]) {
			i--;
		} else {
			j--;
		}
	}
	cout << ans;
}

int32_t main() {
	IOS
	ll T;
	// cin >> T;
	// while(T--)
		solve();
	cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'; 
	return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin>>s;
    int sum=700;
    for(int i=0;i<3;i++){
        if(s[i]=='o'){
            sum+=100;
        }
        else if(s[i]=='x'){
            
        }
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  double n,k;
  cin >> n >> k;
  cout << (int)(ceil(n/k)-floor(n/k)) << endl;
}



Measured memory_bytes: 384
//eratosurenesu
#include<stdio.h>
#define MAX_V 10000
int prime[MAX_V+1];
int main(){
	int i,k,v;
	for(i=2;i<=MAX_V;i++){
		prime[i]=1;
	}
	for(i=2;i*i<=MAX_V;i++){
		if(prime[i]){
			for(k=2*i;k<=MAX_V;k+=i){
				prime[k]=0;
			}
		}
	}
	while(1){
		scanf("%d",&v);
		if(v==0)	break;
		for(i=v;i>=2;i--){
			if(prime[i]==1 && prime[i-2]==1){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1768
n=int(input())
s=input()
re=s[1:].count('E')
ans=re
a=ans
lw=0
for i in range(1,n):
  if s[i]=='E':
    a-=1
  if s[i-1]=='W':
    a+=1
  ans=min(a,ans)

print(ans)


Measured memory_bytes: 3672
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;


int graph[10][10] = {};

int main() {

	string s;
	cin >> s;

	if ((s[0] == s[1] && s[0] == s[2]) || (s[1] == s[2] && s[1] == s[3])) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main()
{
	int an = 0;
	int count[26] = { 0 };
	char S[5];
	scanf("%s", S);
	int i = 0;
	while (S[i] != '\0') {	
		count[S[i] - 'A']++;
		i++;
	}
	for (int i = 0; i < 26; i++) {
		if (count[i] != 0) {
			an++;
		}
	}
	if (an == 2) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair< P , int > PP;
struct edge{int to,cost,type,id;};
int m,n,T,cnt,si,ti;
string str;
vector< edge > G[300005];
P d[300005];
int v[100005],w[100005];
edge p[200005];
map<string,int> mp;

int change(string &str){
  if(mp.count(str))return mp[str];
  else return mp[str]=mp.size();
}

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin>>m>>T;
  cin>>str;si=change(str);
  cin>>str;ti=change(str);
  for(int i=0;i<m;i++){
    cin>>n;
    for(int j=0;j<n;j++){
      cin>>str;
      v[j]=change(str);
    }
    for(int j=0;j+1<n;j++){
      cin>>w[j];
      G[v[j]].push_back((edge){v[j+1],w[j],i,++cnt});
      p[cnt]=G[v[j]].back();
    }
    for(int j=n-2;j>=0;j--){
      G[v[j+1]].push_back((edge){v[j],w[j],i,++cnt});
      p[cnt]=G[v[j+1]].back();
    }
  }
  int C=mp.size();
  fill(d,d+300005,P(1e9,1e9));
  d[0]=P(0,0);  
  priority_queue<PP,vector<PP>,greater<PP> > Q;
  Q.push(PP(P(-T,-1),1));
  P ans=P(-1,-1);
  while(!Q.empty()){
    PP q=Q.top();Q.pop();
    if(q.first>d[q.second])continue;
    P cost=q.first;
    int pos=q.second;
    if(pos==ti){
      ans=cost;
      break;
    }
    if(q.second<=C){
      for(int i=0;i<(int)G[pos].size();i++){
        edge e=G[pos][i];
        P ncost=cost;
        ncost.first+=(e.cost+T);
        ncost.second++;
        if(ncost<d[e.id+C]){
          d[e.id+C]=ncost;
          Q.push(PP(ncost,e.id+C));
        }
      }
    }else{
      edge f=p[pos-C];
      if(cost<d[f.to]){
        d[f.to]=cost;
        Q.push(PP(cost,f.to));
      }
      for(int i=-1;i<=1;i+=2){
        if(f.id+i<=0||cnt<f.id+i)continue;
        edge e=p[f.id+i];
        if(e.type!=f.type)continue;
        P ncost=cost;
        ncost.first+=e.cost;
        if(ncost<d[e.id+C]){
          d[e.id+C]=ncost;
          Q.push(PP(ncost,e.id+C));
        }
      }
    }
  }
  if(ans.first==-1)cout<<-1<<endl;
  else cout<<ans.first<<' '<<ans.second<<endl;
  return 0;
}

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


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

    if(a%2==0 && a==b && b==c){ cout << -1 << endl; return 0;}

    ll cnt=0, sum = a+b+c;
    while(a%2==0 && b%2==0 && c%2==0){
        cnt++;
        a = (sum-a)/2;
        b = (sum-b)/2;
        c = (sum-c)/2;
    }
    cout << cnt << endl;
}

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

using namespace std;

const int N=20,M=33005,inf=0x3F3F3F3F;

int n,m,ec[N][N],ans=inf,U;
int dp[M][N],sc[N][M],g[M];
bool ok[N][M];

int find(int*fa,int x){return fa[x]==x?x:fa[x]=find(fa,fa[x]);}
bool judge(int u,int S){
	if(S>>u&1)return -1;
	static int fa[N];
	static bool vi[N],ok[N];
	for(int i=0;i<n;i++)fa[i]=i,vi[i]=ok[i]=0;
	for(int i=0;i<n;i++)if(S>>i&1)for(int j=i+1;j<n;j++)if(S>>j&1)fa[find(fa,i)]=find(fa,j);
	for(int i=0;i<n;i++)if(S>>i&1){int k=find(fa,i);vi[k]=true;if(!ec[u][i])continue;ok[k]=true;}
	for(int i=0;i<n;i++)if(vi[i]&&!ok[i])return false;
	return true;
}

inline void upd(int&x,int y){x<y?:x=y;}

inline int sumcost(int S,int T){
	int res=0;
	for(int i=0;i<n;i++)if(T>>i&1)res+=sc[i][S];
	return res;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,u,v,c;i<=m;i++)scanf("%d%d%d",&u,&v,&c),u--,v--,ec[u][v]=ec[v][u]=c;
	U=(1<<n)-1;
	for(int i=0;i<n;i++)for(int j=0;j<=U;j++)ok[i][j]=judge(i,j);
	for(int i=0;i<n;i++)for(int j=0;j<=U;j++)for(int k=0;k<n;k++)if(j>>k&1)sc[i][j]+=ec[i][k];
	memset(dp,0x3F,sizeof(dp));
	for(int S=1;S<=U;S+=2)if(ok[0][S^1])dp[S][0]=0;
	for(int S=0;S<=U/2;S++)for(int u=0;u<n;u++)if(dp[S][u]!=inf){
		for(int K=U-S,T=K;T;T=(T-1)&K)g[T]=sumcost(S,T);
		for(int v=0;v<n;v++)if(~S>>v&1){
			if(!ec[u][v])continue;
			int T=U-S-(1<<v),cur=sc[v][S^(1<<u)];
			for(int z=T;z;z=(z-1)&T)if(ok[v][z])
				upd(dp[S|1<<v|z][v],dp[S][u]+cur+g[z]);
			upd(dp[S|1<<v][v],dp[S][u]+cur);
		}
	}
	for(int S=U/2+1;S<=U;S++)if(dp[S][n-1]!=inf)upd(ans,dp[S][n-1]+sumcost(S,U^S));
	printf("%d\n",ans);
	return 0;
}

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

struct process
{
    string name;
    int time;
};

int main()
{
    int n, q;
    queue<process> pq;
    cin >> n >> q;

    int global_time = 0;
    for (int i = 0; i < n; i++)
    {
        process p;
        cin >> p.name >> p.time;
        pq.push(p);
    }

    while (!pq.empty())
    {
        process p;
        p = pq.front();
        pq.pop();
        if (p.time <= q)
        {
            global_time += p.time;
            cout << p.name << " " << global_time << endl;
        }
        else
        {
            p.time -= q;
            global_time += q;
            pq.push(p);
        }
    }

    return 0;
}


Measured memory_bytes: 6260
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    int n, taro=0, hanako=0;
    string T, H;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> T >> H;
        if(T == H){
            taro++; hanako++;
        }
        else if(T < H) hanako += 3;
        else taro += 3;
    }
    cout << taro << " " << hanako << endl;
    return 0;
}
 

Measured memory_bytes: 3112
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,m = MI()
py = LI(m)

py_new = []
no = 0
for i in range(m):
    no += 1
    p = py[i][0]
    y = py[i][1]
    py_new.append([no,p,y])

py_new = mysort(py_new,2,False)

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

no = 0
py_now = []
for i in range(m):
    no = py_new[i][0]
    p = py_new[i][1] - 1
    y = py_new[i][2]
    x = len(g[p]) + 1
    py_now.append([no,p,y,x])
    g[p].append(y)

py_now = mysort(py_now,0,False)

for i in range(m):
    p = str( py_now[i][1] + 1 )
    x = str( py_now[i][3] )
    p = p.zfill(6)
    x = x.zfill(6)
    a = p + x
    print(a)
exit()

Measured memory_bytes: 104536
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //


void solve(){
	int w = read.to!int;
	int h = read.to!int;
	
	long[] ps, qs;
	foreach(i; 0 .. w) ps ~= read.to!long;
	foreach(j; 0 .. h) qs ~= read.to!long;
	
	S[] xs;
	foreach(p; ps) xs ~= S(0, p);
	foreach(q; qs) xs ~= S(1, q);
	
	xs.sort!"a.value > b.value"();
	
	long ans;
	int icnt, jcnt;
	foreach(x; xs){
		if(! x.isJ){
			ans += (jcnt + 1) * x.value;
			icnt += 1;
		}
		else{
			ans += (icnt + 1) * x.value;
			jcnt += 1;
		}
		log("x:", x, "icnt:", icnt, "jcnt:", jcnt, "ans:", ans);
	}
	
	ans.writeln;
}
/*
コストの高い経緯度は道路が少ない方がよい。
コストの高い経緯度から順に埋めていく。
（逆に切り離していくというイメージ）
その際、縦横それぞれいくつすでに作ったかによって
この経緯度に何本道路を引く必要があるか決まる。

*/

struct S{
	bool isJ;
	long value;
}

Measured memory_bytes: 9980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, a[112345];

    cin >> n;
    REP(i, n)
    cin >> a[i];

    sort(a, a + n);

    V p, m;

    ll res = 0;

    for (int i = 0; i < n; i++)
    {
        if (a[i] < 0)
        {
            res -= a[i];
            m.push_back(a[i]);
        }
        else
        {
            res += a[i];
            p.push_back(a[i]);
        }
    }

    if (p.size() == 0)
    {
        res += m[m.size() - 1] * 2;
        p.push_back(m[m.size() - 1]);
        m.pop_back();
    }

    if (m.size() == 0)
    {
        res -= p[0] * 2;
        m.push_back(p[0]);
        p.erase(p.begin());
    }

    cout << res << endl;

    while (true)
    {
        if (p.size() == 1)
        {
            cout << p[0] << " " << m[m.size() - 1] << endl;

            p[0] = p[0] - m[m.size() - 1];
            m.pop_back();
        }
        else
        {
            cout << m[0] << " " << p[p.size() - 1] << endl;

            m[0] = m[0] - p[p.size() - 1];
            p.pop_back();
        }

        if (p.size() + m.size() == 1)
            return 0;
    }

    return 0;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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

int N, M;
vector<vector<int> > G;

int dp[100100];
int rec(int v) {
    if(dp[v] != -1) return dp[v];

    int rsl = 0;
    for(auto nv : G[v]) chmax(rsl, rec(nv) + 1);
    return dp[v] = rsl;
}

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

    cin >> N >> M;
    G.assign(N, vector<int>());
    rep(i, 0, M) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
    }

    rep(i, 0, N) dp[i] = -1;

    int rsl = 0;
    rep(i, 0, N) chmax(rsl, rec(i));
    cout << rsl << endl;

}


Measured memory_bytes: 8192
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int n, q, cnt=0;
    cin >> n >> q;
    int sum[100010] = {0};
    string s;
    cin >> s;
    char l, r;
    for (int i = 0; i < n-1; i++) {
        l = s[i], r = s[i+1];
        if(l=='A' && r=='C')cnt++;
        sum[i+1] = cnt;
    }
    int le, ri;
    for (int i = 0; i < q; i++) {
        cin >> le >> ri;
        le--;
        ri--;
        cout << sum[ri] - sum[le] << endl;
    }
    return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

int main() {
    string S;
    cin >> S;
    unordered_map<char, int> alp;

    for (int n = 0; n < 26; n++) {
        alp[char('a' + n)] = 0;
    }


    string::iterator i;
    for (i = S.begin(); i != S.end(); i++) {
        alp[*i]++;
    }

    for (int n = 0; n < 26; n++) {
        char key = char('a' + n);
        if (alp[key] == 0) {
            cout << key << endl;
            return 0;
        }
    }

    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
n,m = map(int,input().split())
py = []
p_y = [[] for i in range(n)]
for _ in range(m):
    p,y = map(int,input().split())
    py.append((p,y))
    p_y[p-1].append(y)
ans = {}
for i, tmp in enumerate(p_y):
    cnt = 1
    p_y[i] = tmp.sort()
    for j, jj in enumerate(tmp):
 
        ans[(i+1, jj)] = str(i+1).zfill(6) + str(j+1).zfill(6)
 
 
for i, tmp in enumerate(py):
    print(ans[tmp])

Measured memory_bytes: 92448