akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back
#define fi first
#define se second
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
#define INF (ll)1e18
#define ll long long
#define P pair<ll, ll>
#define vll vector<ll>
#define vvll vector<vll>

ll n, m, st;
vector<vector<P> > g;

void solve1(void) {
    vll dist(n, INF);
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(0, st)); 
    dist[st] = 0; // "見た"
    while (q.size()) { 
        // q = {(d, v)} : 頂点vに距離dで到達できる（dは最適とは限らない）
        // dist[v] : 今までに見た中で、vに到達するための最短距離
        //
        // vの初出がここに来た時点で、dist[v]が最適であることは保証されている！
        // あとは、d = dist[v]のものだけ遷移すれば良い
        P st = q.top(); q.pop();
        ll d = st.fi, v = st.se;
        if (d > dist[v]) continue; // 同じvに異なる距離dで到達可能だが、最適なものだけを見ればよい
        rep(i, g[v].size()) {
            P edge = g[v][i];
            ll u = edge.fi, cost = edge.se;
            if (dist[v] + cost >= dist[u]) continue;
            dist[u] = dist[v] + cost; // "見た"
            q.push(P(dist[v] + cost, u));
        }
    }
    rep(i, n) {
        if (dist[i] == INF) 
            cout << "INF" << endl;
        else
            cout << dist[i] << endl;
    }
}

void solve2(void) {
    vll dist(n, INF); 
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(0, st));  
    while (q.size()) { 
        // q = {(d, v)}: vにdで到達できる（dは最適とは限らない）
        // dist[v]: 今までに"見た"中で、vに到達するための最短距離
        P st = q.top(); q.pop();
        ll d = st.fi, v = st.se;
        if (d >= dist[v]) continue; 
        chmin(dist[v], d); // "見た"
        rep(i, g[v].size()) {
            P edge = g[v][i];
            ll u = edge.fi, cost = edge.se;
            q.push(P(dist[v] + cost, u));
        }
    }
    rep(i, n) {
        if (dist[i] == INF) 
            cout << "INF" << endl;
        else
            cout << dist[i] << endl;
    }
}

void solve3(void) {
    vll dist(n, INF); 
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(0, st));  
    while (q.size()) { 
        // q = {(d, v)}: vにdで到達できる（dは最適とは限らない）
        // dist[v]: 今までに"見た"中で、vに到達するための最短距離
        P st = q.top(); q.pop();
        ll d = st.fi, v = st.se;
        if (dist[v] != INF) continue; 
        chmin(dist[v], d); // "見た"
        rep(i, g[v].size()) {
            P edge = g[v][i];
            ll u = edge.fi, cost = edge.se;
            q.push(P(dist[v] + cost, u));
        }
    }
    rep(i, n) {
        if (dist[i] == INF) 
            cout << "INF" << endl;
        else
            cout << dist[i] << endl;
    }
}

int main(void) {
    cin >> n >> m >> st;
    g.resize(n);
    rep(i, m) {
        ll u, v, d; cin >> u >> v >> d;
        g[u].pb(P(v, d));
    }
//    solve1();
//    solve2();
    solve3();

    return 0;
}



Measured memory_bytes: 21560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll n; cin >>n;
    ll ans = n*(n-1)/2;

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


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

using namespace std;
#define ll long long
int n,m;
int dp[1005][1005];
string a[1005];
int solve(int i,int j)
{
    if(i==n-1&&j==m-1) return a[i][j]=='#';
    int &ret=dp[i][j];
    if(~ret) return ret;
    ret=n*m*2;
    if(j+1<m) ret=min(ret,solve(i,j+1)+(a[i][j]!=a[i][j+1]));
    if(i+1<n) ret=min(ret,solve(i+1,j)+(a[i][j]!=a[i+1][j]));
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>a[i];
    memset(dp,-1,sizeof dp);
    int ans=solve(0,0)+(a[0][0]=='#');
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>

using namespace std;

#define rep(i,n) for(int i = 0; i<n ; i++)

#define INF 1001001001
#define LLINF 1001001001001001001LL

typedef pair<int,int> P;

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

//------------------HEAD---------------------

int main(void){
    // Here your code !
    int toppings[100];
    int n,a,b,c;
    cin>>n>>a>>b>>c;
    rep(i,n){
        int t;
        cin>>t;
        toppings[i]=t;
    }
    sort(toppings,toppings+n);
    reverse(toppings,toppings+n);
    int cal=c;
    int price=a;
    int ans=cal/price;
    rep(i,n){
        cal+=toppings[i];
        price+=b;
        ans=max(ans,cal/price);
        //cerr<<i<<" "<<cal<<" "<<price<<" "<<cal/price<<endl;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3148
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i, a, n) for(LL i = (a), i##_max = (n); i < i##_max; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##min = (a); i >= i##min; --i)
#define ALL(arr) (arr).begin(), (arr).end()
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
template <class T>
T Next() { T buf; cin >> buf; return buf; }

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "BinaryMatrix.h"
#include "BIT.h"
#include "Factorization.h"
#include "FlowSolver.h"
#include "Graph.h"
#include "LazySegmentTree.h"
#include "Math.h"
#include "Matrix.h"
#include "MinMax.h"
#include "Position.h"
#include "Range.h"
#include "Rational.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "SuffixArray.h"
#include "Tree.h"
#include "UnionFind.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
// template <class T>
// auto Is(const T& value) { return [value](const auto& comparand) -> bool { return comparand == value; }; }
#endif

int main() {
	int n;
	cin >> n;
	cout << (n - 2) * 180 << endl;
	return 0;
}


Measured memory_bytes: 256
# 操作を逆順に考える
# j番目の数がjなら取り除ける
# 取り除けるものが複数ある場合、最も右のを取り除かないと、番号がズレて取り除けなくなる
# 1,2,3
# 1を取り除くと
# 2,3になってダメ
# 順番に操作して、逆順に出力

N=int(input())
b=list(map(int,input().split()))

ans=[]
while len(b)>0:
  for i in range(len(b)-1,-1,-1):
    if b[i]==i+1:
      ans.append(i+1)
      del b[i]
      break
  else:
    print(-1)
    exit(0)
for i in range(len(ans)-1,-1,-1):
  print(ans[i])

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  char s[5];
  scanf("%s", s);

  int ans = 0;
  rep(i, 0, 4) {
    if (s[i] == '+') ans++;
    else ans--;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
MOD = int(1e9 + 7)
n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(62):
    cnt = 0
    for a in A:
        if a & 1<<i:
            cnt += 1
    ans += (1<<i % MOD) * cnt % MOD * (n - cnt) % MOD
print(ans % MOD)


Measured memory_bytes: 117932
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

map<lint,int> p_factorization(lint n){
    map<lint,int> soinsu;
    for(int i=2;i<=sqrt(n);i++){
        while(n%i==0){
            n/=i;
            soinsu[i]++;
        }
    }
    if(n!=1)soinsu[n]++;
    return soinsu;
}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    bool pairwise=true;
    vector<int> vec(1000000);
    int n,x,tmp;cin>>n;
    cin>>tmp;
    map<lint,int> dic=p_factorization(tmp);
    for(auto p:dic){
        vec[p.first]=1;
    }
    for(int i=1;i<n;i++){
        cin>>x;tmp=__gcd(tmp,x);
        if(!pairwise)continue;
        map<lint,int> dic=p_factorization(x);
        for(auto p:dic){
            if(vec[p.first]==1){
                pairwise=false;
            }
            vec[p.first]=1;
        }
    }
    if(pairwise)cout<<"pairwise coprime"<<endl;
    else if(tmp==1)cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
}


Measured memory_bytes: 7148
c = gets.chomp
# array でa~zの配列をつくる
array = ("a".."z").to_a
# find で条件に一致した要素を取り出す
# オブジェクト.find{ |要素| ブロック処理}

index = array.find_index(c)

puts array[index + 1]




Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str1=sc.next();
        String str2=sc.next();
        String result="YES";
        char[] in =str1.toCharArray();
        char[] out=str2.toCharArray();
        for(int i=0;3>i;i++){
            if(in[i]!=out[2-i]){
                result ="NO";
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<pair<pair<int,int>,int>> viii;
typedef vector<pair<pair<ll,ll>,ll>> viiil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000
#define MOD 1000000007;

void solve() {
    int n, k;
    cin >> n >> k;
    
    vi a(n);
    rep(i, n) cin >> a[i];
    
    for (int i = k ; i < n ; i++) {
        if (a[i] > a[i - k]) {
            cout << "Yes" << '\n';
        }
        else {
            cout << "No" << '\n';
        }
    }
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    //querySolve();
    solve();

}


Measured memory_bytes: 4048
#include <stdio.h>
#include <string.h>

int main(){
  char s[200001];
  int len,i,n=0;
  
  scanf("%s",s);
  len=strlen(s);
  
  for(i=0;i<len;i++){
    n+=s[i]-'0';
  }
  
  if(n%9==0){
    printf("Yes");
  } else {
    printf("No");
  }
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
vector<int> topo;
int visited[100001];
vector<int> adj[100001];
const ll INF = 1E18+5;
void dfs(int u)
{
//    cout<<u<<" ";
    visited[u] = 1;
    for(auto i:adj[u])
        if(!visited[i])
            dfs(i);
    visited[u] = 2;
    topo.pb(u);
}
int main(){
    int n, m;
    cin>>n>>m;
    int i, j;
    for(i = 0; i < m; ++i)
    {
        int u,v;
        cin>>u>>v;
        adj[u-1].pb(v-1);
    }
    memset(visited,0,sizeof(visited));
    int ans = 0;
    for(i=0;i<n;i++)
    {
        if(!visited[i])
            dfs(i);
    }
    reverse(topo.begin(),topo.end());
    vector<int> dp(n,0);
    for(j=0;j<topo.size();j++)
    {
//            cout<<topo[i]<<" ";
        for(auto k:adj[topo[j]])
            dp[k] = max(dp[k],dp[topo[j]]+1);
    }
    for(j=0;j<n;j++)
        ans = max(ans,dp[j]);
    cout<<ans;
}




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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep1(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p)
{
    return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc)
{
    o << "sz = " << vc.size() << endl
      << "[";
    for (const T& v : vc)
        o << v << ",";
    o << "]";
    return o;
}
using ll = long long;
constexpr ll MOD = 1000000007;

constexpr int MAX = 100000;

int n;
ll b, a;
ll h[MAX];

bool ok(int cnt)
{
    ll count = 0;
    const ll sa = a - b;
    for (int i = 0; i < n; i++) {
        const ll rest = h[i] - cnt * b;
        if (rest <= 0) {
            continue;
        }
        count += (rest + (sa - 1)) / sa;
    }
    return count <= cnt;
}

int main()
{
    cin >> n >> a >> b;
    rep(i, n)
    {
        cin >> h[i];
    }

    int inf = 0;
    int sup = 1e9;
    while (inf < sup) {
        const int mid = (inf + sup) / 2;
        if (ok(mid)) {
            sup = mid;
        } else {
            if (inf == mid) {
                break;
            }
            inf = mid;
        }
    }
    cout << sup << endl;

    return 0;
}


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

using namespace std;

int main() {
    int n, k;
    vector<int> v;
    string s;
    cin >> n >> k >> s;
    if (s[0] == '0') v.push_back(0);
    char prev = s[0];
    int count = 0;
    for (auto c : s) {
        if (c != prev) {
            prev = c;
            v.push_back(count);
            count = 0;
        }
        ++count;
    }
    v.push_back(count);
    if (s[n - 1] == '0') v.push_back(0);
    int value = 0;
    for (int i = 0, size = v.size(); i < k * 2 + 1 && i < size; ++i) {
        value += v[i];
    }
    int answer = value;
    for (int i = 0, size = v.size(); i + 2 * k + 1 < size; i += 2) {
        value -= v[i] + v[i + 1];
        value += v[i + 2 * k + 1] + v[i + 2 * k + 1 + 1];
        answer = max(answer, value);
    }
    cout << answer << endl;
}


Measured memory_bytes: 1020
#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
const int INF = 0x3f3f3f3f;
#define int long long

using Weight = int;
struct Edge {
	int s, d; Weight w;
	Edge() {};
	Edge(int s, int d, Weight w) :s(s), d(d), w(w) {};
};
bool operator<(const Edge& e1, const Edge& e2) { return e1.w == e2.w ? (e1.s == e2.s ? e1.d < e2.d : e1.s < e2.s) : e1.w < e2.w; }
bool operator>(const Edge& e1, const Edge& e2) { return e2 < e1; }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph& g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph& g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

auto dijkstra = [&](const Graph& g, int s, Array& dist) {
	int n = g.size();
	vector<bool> vis(n);
	vector<int> prev(n, -1);
	dist.assign(n, INF); dist[s] = 0;
	using State = tuple<Weight, int, int>;
	priority_queue<State, vector<State>, greater<State>> pq;
	pq.emplace(0, s, -1);
	while (pq.size()) {
		Weight d; int v, p; tie(d, v, p) = pq.top(); pq.pop();
		if (dist[v] < d)continue;
		vis[v] = true;
		prev[v] = p;
		for (auto& e : g[v]) {
			if (vis[e.d])continue;
			if (dist[e.d] > dist[v] + e.w) {
				dist[e.d] = dist[v] + e.w;
				pq.emplace(dist[e.d], e.d, v);
			}
		}
	}
	return prev;
};

signed main() {
	for (int N, M, H, K; cin >> N >> M >> H >> K && N;) {
		vector<int> a(M), b(M), c(M), h(M), r(M);
		rep(i, 0, M) {
			cin >> a[i] >> b[i] >> c[i] >> h[i] >> r[i];
			a[i]--; b[i]--;
			r[i]--;
		}
		int S, T; cin >> S >> T; S--, T--;
		int P; cin >> P;
		vector<int> l(P), d(P);
		vector<vector<int>> k(P);

		vector<int> dp(1 << K, INF);
		dp[0] = 0;

		rep(i, 0, P) {
			cin >> l[i] >> d[i];
			int mask = 0;
			rep(j, 0, l[i]) {
				int _k; cin >> _k; _k--;
				k[i].push_back(_k);
				mask |= 1 << _k;
			}
			dp[mask] = d[i];
		}

		rep(mask1, 0, 1 << K) rep(mask2, 0, 1 << K) {
			if (dp[mask1] == INF || dp[mask2] == INF)continue;
			if (mask1 == mask2)continue;
			int nmask = mask1 | mask2;
			dp[nmask] = min(dp[nmask], dp[mask1] + dp[mask2]);
		}

		//rep(mask, 0, 1 << K) {
		//	cerr << bitset<4>(mask) << " " << dp[mask] << endl;
		//}

		auto id = [&](int i, int h) {
			return i * (H + 1) + h;
		};

		int ans = INF;

		rep(mask, 0, 1 << K) {
			if (dp[mask] == INF)continue;
			Graph g(N * (H + 1));
			rep(i, 0, M) {
				if ((mask >> r[i]) & 1) {
					rep(j, 0, H) {
						if (j + h[i] > H)break;
						addArc(g, id(a[i], j), id(b[i], j + h[i]), 0);
						addArc(g, id(b[i], j), id(a[i], j + h[i]), 0);
					}
				}
				else {
					rep(j, 0, H) {
						if (j + h[i] > H)break;
						addArc(g, id(a[i], j), id(b[i], j + h[i]), c[i]);
						addArc(g, id(b[i], j), id(a[i], j + h[i]), c[i]);
					}
				}
			}
			Array dist;
			dijkstra(g, id(S, 0), dist);

			rep(i, 0, H + 1) {
				ans = min(ans, dp[mask] + dist[id(T, i)]);
			}
		}

		cout << (ans == INF ? -1 : ans) << endl;
	}

}


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

typedef pair<long long, long long> P;
int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    vector<int> ju(N, 0);
    vector<long long> r(1e6 + 1, 0);
    for(int i = 1; i < N; i++){
        if(A[i] == A[i - 1]){
            ju[i] = -1;
            ju[i - 1] = -1;
        }
    }
    for(int i = 0; i < N; i++){
      	if(r[A[i]] != 0) continue;
        long long t = A[i];
        long long res = 2;
        while(t*res <= A[N - 1]){
            r[t*res]++;
            res++;
        }
    }
    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(r[A[i]] == 0 && ju[i] == 0) ans++;
    }
    cout << ans << endl;
}


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

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

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

bool solve(vector<int> &H) {
  int N = H.size();
  REP(i, N) {
    if(!i || H[i] > H[i - 1]) --H[i];
    if(i && H[i] < H[i - 1]) return false;
  }
  return true;
}

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  REP(i, N) cin >> H[i];
  cout << (solve(H) ? "Yes" : "No") << endl;
  return 0;
}



Measured memory_bytes: 640
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
if ($key->A[0]<1200)
  printf("ABC\n");
else
  printf("ARC\n");


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
#define endl '\n'
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fori(z,n) for(int i=z;i<n;i++)
#define forii(z,n) for(int i=z;i<=n;i++)
int maxElement(int arr[],int n)
{
    int maxi=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]>maxi)
            maxi=arr[i];
    }
    return maxi;
}
int minElement(int arr[],int n)
{
    int mini=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]<mini)
            mini=arr[i];
    }
    return mini;
}
string trim(const string& str)
{
    int first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() 
{ 
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    ll h[n+1];
    fori(1,n+1)cin>>h[i];
    ll dp[n+1];
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    fori(3,n+1)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n]<<endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        boolean hasY = false;
        for (int i = 0; i < n; i++) {
            char ch = sc.next().charAt(0);
            if (ch == 'Y') {
                hasY = true;
                break;
            }
        }
        
        System.out.println(hasY ? "Four" : "Three");
    }
}

Measured memory_bytes: 23252
N, K = map(int, input().split())
S = input()

ans = 0
for i in range(N):
    if S[i] == 'L':
        if i - 1 < 0:
            continue
        if S[i - 1] == 'L':
            ans += 1
    else:
        if i + 1 >= N:
            continue
        if S[i + 1] == 'R':
            ans += 1


X = min(len([s for s in S.split('L') if s != '']), len([s for s in S.split('R') if s != '']))
ans += min(X, K) * 2
print(min(ans, N - 1))


Measured memory_bytes: 4596
n,m = map(int,input().split())
h_list = list(map(int,input().split()))
ans = [True for i in range(n)]
for i in range(m):
  a,b = map(int,input().split())
  if h_list[a-1] < h_list[b-1]:
    ans[a-1] = False
  elif h_list[a-1] > h_list[b-1]:
    ans[b-1] = False
    
  if h_list[a-1] == h_list[b-1]:
    ans[a-1] = False
    ans[b-1] = False
print(ans.count(True))    
    
    


Measured memory_bytes: 19992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        ABC101_C solver = new ABC101_C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC101_C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            int[] array = new int[n];
            int minIndex = 0;
            for (int i = 0; i < n; i++) {
                array[i] = in.nextInt();
                if (array[i] == 1) {
                    minIndex = i;
                }
            }

            int ans = 0;

            while ((k - 1) * ans + 1 < n) {
                ans++;
            }


//        if (minIndex <= k - 1) {
//            ans++;
//            minIndex = k - 1;
//        } else {
//            ans += minIndex / (k - 1);
//            if ((minIndex % (k - 1)) != 0) {
//                ans++;
//                minIndex += minIndex % (k - 1);
//            }
//        }
//
//        if (minIndex != n - 1) {
//            ans += (n - 1 - minIndex) / (k - 1);
//            if ((n - 1 - minIndex) % (k - 1) != 0) {
//                ans++;
//            }
//        }

            out.print(ans);
        }

    }
}



Measured memory_bytes: 51032
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    inf=10**10
    to = defaultdict(list)
    n, m = map(int, input().split())
    for _ in range(m):
        l, r, d = map(int, input().split())
        l, r = l - 1, r - 1
        to[l].append([r, d])
        to[r].append([l, -d])
    pos = [inf] * n
    for root in range(n):
        if pos[root] != inf: continue
        pos[root] = 0
        stack = [[root, 0]]
        while stack:
            u, p = stack.pop()
            for v, d in to[u]:
                if pos[v] == inf:
                    stack.append([v, p + d])
                    pos[v] = p + d
                else:
                    if pos[v] != p + d:
                        print("No")
                        exit()
    print("Yes")

main()


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

ll n, k;

int main(){
  cin >> n >> k;
  vector<int> h(n);
  rep (i,n) cin >> h.at(i);
  sort(h.begin(), h.end());
  //k = min(n,k)はポイント
  k = min(n,k);
  ll ans = 0;
  rep(i,k){
    h.pop_back();
  }
  rep(i,h.size()) ans += h.at(i);
  cout << ans << endl;
  return 0;
  }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n,x,f[4];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        f[x%4]++;
    }
    if(f[0]<f[1]+f[3]+f[2]%2-1)puts("No");
    else puts("Yes");
}


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

int main(){
    int N,M,ans=0;
    cin >> N >> M;
    int A[M];
    for(int i=0; i<M; i++) {
      cin >> A[i];
      ans += A[i];
    }
    ans = N - ans;
    if(ans<0) cout << "-1" << endl;
    else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int cnt[3];
int main(){
	int n;char ch;int f=0;
	cin>>n;
	for(int i=0;i<n;++i)
		cin>>ch,f=(ch=='2'?1:f),cnt[ch-'0'-1]+=(((n-1)&i)==i);
	if(cnt[1]&1) puts("1");
	else if(cnt[2]%2==1 && f==0) puts("2");
	else puts("0");
	return 0;
}

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

int main(){
	int A, B;
	cin >> A >> B;
	int MI = min(A, B), MX = max(A, B);	
	for(int i=MI;i<=MX;i++){
		if(abs(A - i) == abs(B - i)){
			cout << i << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3608
N = int(input())
d = dict()
for i in range(N):
    S = input()
    S = ''.join(sorted(list(S)))
    if S in d.keys():
        d[S] += 1
    else:
        d[S] = 1

ans = 0
for n in d.values():
    ans += n*(n-1)//2
print(ans)


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

int main() {
  string s;
  cin >> s;
  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  char ans = '0';
  
  rep(i,26) {
    ans = alphabet[i];
    rep(j,s.size()) {
      if (s[j] == alphabet[i]) {
        ans = '0';
        break;
      }
    }
    if (ans != '0') break;
  }
  
  if (ans == '0') cout << "None" << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='o')ans++;
    }

    cout<<700+ans*100<<endl;
return 0;
}


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

using lint = long long;

vector<int> lp, primes, pw;
vector<lint> cnt;
void run_sieve(int n) {
	lp.resize(n+1); cnt.resize(n+1, 2); pw.resize(n+1, 1);
	int p;
	cnt[1] = 1;
	iota(lp.begin(), lp.end(), 0);
	for (int i = 2; i <= n; ++i){
		if (lp[i] == i)  primes.push_back(i);
		for (int j = 0; j < primes.size() && (p = primes[j]*i) <= n; ++j) {
			lp[p] = primes[j];
			cnt[p] = 2 * cnt[i];
			pw[p] = 1;
			if (i % primes[j] == 0) { 
				pw[p] = pw[i] + 1;
				cnt[p] = cnt[i]/pw[p] * (pw[p] + 1);
				break;
			}
		} 
	}	
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    run_sieve(n+10);
    lint res = 0;
    for (int i = 1; i <= n; ++i) {
    	res += i * cnt[i];
    }
    cout << res << '\n';
}

Measured memory_bytes: 163652
N,M = map(int,input().split())
a = []
for i in range(M):
    a.append(int(input()))

if M == 0:
    a = [-1]

inf = 1000000007
index = 0
n_way = [0 for i in range(N+2)]
n_way[0] = 1

for i in range(N):
    if a[index] == i:
        index += 1
        index = min(index,len(a)-1)
    else:
        n_way[i+1] += n_way[i]
        n_way[i+1] = n_way[i+1]%inf
        n_way[i+2] += n_way[i]
        n_way[i+2] = n_way[i+2]%inf

print(n_way[N])



Measured memory_bytes: 8840
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


int main(){
    
    string s; cin>>s;
    REP(i,s.size()){
        cout<<(s[i]==','?' ':s[i]);
    }
    cout<<endl;
    
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> BA(N);
    for(int i =0; i < N; i++){
        int a, b;
        cin >> a >> b;
        BA.at(i).first = b;
        BA.at(i).second = a;
    }
    sort(BA.begin(), BA.end());
    long long deadline = 0;
    long long time = 0;
    for(int i =0; i < N; i++){
        deadline = BA.at(i).first;
        time += BA.at(i).second;
        if(time > deadline){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;    
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cout << ((j <= a) ^ (i <= b));
    }
    cout << '\n';
  }
  return 0;
}

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

int main() {
    unsigned long long k, a, b;
    cin >> k >> a >> b;
    if ((a >= b-2) || (k <= a) ) {
        cout << 1+k << endl;
    } else{
        unsigned long long output;
        output = b + ((k-a-1)/2 )*(b-a) + (k-a-1) % 2;
        cout << output << endl;
    } 
}

Measured memory_bytes: 256
//
// Created by Tetsuya Shiota on 2019-01-27.
//

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it,o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl


typedef long long ll;

using namespace std;

//ハマったらチェックリスト見ろ!!

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << ' ' <<max(A+B - N, 0) <<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        String res = "";

        switch (d) {
            case 25:
                res = "Christmas";
                break;
            case 24:
                res = "Christmas Eve";
                break;
            case 23:
                res = "Christmas Eve Eve";
                break;
            case 22:
                res = "Christmas Eve Eve Eve";
                break;
            default:
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <map>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (int &x: A) {
    std::cin >> x;
  }
  std::map<int, int> count;
  int64_t ans = 0;
  for (int i: range(0, N)) {
    auto it = count.find(i - A[i]);
    if (it != count.end()) {
      ans += it -> second;
    }
    ++count[A[i] + i];
  }
  std::cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 13396
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

bool isEqual(db a, db b) {
	return abs(a - b) < 1e-8;
}
db in[105][2];

db getv(db v) {
	db rv = atan(v);
	return (rv + PI / 2) / (2 * PI);
}
int main() {
	int N, i, j, k;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lf %lf", &in[i][0], &in[i][1]);

	for (i = 1; i <= N; i++) {
		db ymn = -LL_INF, ymx = LL_INF;

		db mn1 = -LL_INF, mx1 = LL_INF;
		db mn2 = -LL_INF, mx2 = LL_INF;
		for (j = 1; j <= N; j++) {
			if (i == j) continue;

			db x1 = in[i][0], y1 = in[i][1];
			db x2 = in[j][0], y2 = in[j][1];

			if (isEqual(y1, y2)) {
				if (x1 < x2) ymx = 0;
				else ymn = 0;
			}
			else {
				db v = (x2 - x1) / (y1 - y2);
				
				if (y1 > y2) {
					mn1 = max(mn1, v);
					mn2 = max(mn2, -v);
				}
				else {
					mx1 = min(mx1, v);
					mx2 = min(mx2, -v);
				}
			}
		}
		db ans = 0;

		if (ymn < -LL_INF / 2 && mx2 > mn2) ans += getv(mx2) - getv(mn2);
		if (ymx > LL_INF / 2 && mx1 > mn1) ans += getv(mx1) - getv(mn1);
		printf("%.20lf\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
def selection_sort(A, N):
	cnt = 0
	for i in range(N):
		minj = i
		for j in range(i, N):
			if A[j] < A[minj]:
				minj = j
		A[i], A[minj] = A[minj], A[i]
		if minj!=i:
			cnt += 1

	return A, cnt

N = int(input())
A = list(map(int, input().split()))

A, cnt = selection_sort(A, N)
print(' '.join(map(str, A)))
print(cnt)


Measured memory_bytes: 5600
//
//  sublime text 3,
//  emre yazicioglu
//

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
typedef vector <pll> vpll;
#define pb push_back
#define fi first
#define se second
#define INF (ll) (1e18 + 7)
#define MOD (ll) (1e9 + 7)

const int N = 3e3 + 7;
ll mn = INF, mx = -INF;
ll n, m, k, s, q, t;
ll a, b, c, d, e;
ll ans, cur, sum, cnt;
ll w[N], v[N], dp[N][N][2];
string str; bool h[N];
pll pp[N];

ll f(ll cur, ll rem, bool type) {
  if(cur == n + 1)
    return 0;
  if(rem == 0)
    return 0;
  ll &r = dp[cur][rem][type];
  if(r != -1)
    return r;
  r = -INF;
  if(!type)
    r = max(r, f(cur + 1, rem - 1, 1) + v[cur]);
  if(rem >= w[cur])
    r = max(r, f(cur + 1, rem - w[cur], type) + v[cur]);
  r = max(r, f(cur + 1, rem, type));
  return r;
}

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

  // freopen("../in.txt","r",stdin);
  // freopen("../out.txt","w",stdout);

  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
    cin >> w[i] >> v[i];
  cout << f(1, k, 0);
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<T> a(m);
    rep(i,m) {
        int p, y;
        cin >> p >> y;
        a[i] = make_tuple(p,y,i);
    }
    sort(all(a));
    vector<P> ans(m);
    int i = 0;
    while (i < m) {
        int j = 0;
        while (get<0>(a[i]) == get<0>(a[i+j])) {
            ll value = get<0>(a[i])*pow(10,6)+j+1;
            ans[i+j] = make_pair(get<2>(a[i+j]),value);
            j++;
        }
        i = i+j;
    }
    sort(all(ans));
    rep(i,m) printf("%012lld\n",ans[i].second);
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n,m;
	cin>>n;
	vector<ll> vec(n+1,0);
	map<ll,ll> map;
	for(ll i=2;i<=n;i++){
		cin>>vec[i];
		map[vec[i]]++;
	}
	
	std::map<ll,ll> ::iterator it;
	for(ll i=1;i<=n;i++){
		cout<<map[i]<<endl;
	}
	
	
}

Measured memory_bytes: 17252
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    a,b=input().split()
    a,b=a*int(b),b*int(a)
    print(min(a,b))

main()


Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
const int MOD = 1000000007;
 
long long my_pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}
 
vector<long long> fact_inv, inv, Com;
 
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int n, int SIZE) {
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
    Com.resize(SIZE + 5);
    Com[0] = 1;
    for (int i = 1; i < SIZE + 5; i++) {
        Com[i] = Com[i - 1] * ((n - i + 1) * inv[i] % MOD) % MOD;
    }
}
long long nCk(int k) {
    assert(!(k < 0));
    return Com[k];
}
 

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    ll ans;
    ll ca, cb;
    init_nCk(n, max(a, b));
    ca = nCk(a);
    cb = nCk(b);
    ans = (my_pow(2,n) - ca - cb -1)%MOD;
    if (ans < 0) {
        ans += MOD;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 7924
# -*- coding: utf-8 -*-
N = input()
N = int(N)
A = list(map(int, input().split()))

for i in range(len(A)):
	A[i] = [A[i], i]
A.sort()
for j in range(len(A)):
	A[j] = str(A[j][1]+1 )
print(' '.join(A))

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

int main(){
  string s;
  cin >> s;
  bool ans=true;
  for(int i=0,l=s.size();i<l/2;i++)
    if(s.at(i)!=s.at(l-i-1))
      ans=false;
  for(int i=0,l=s.size();i<l/4+1;i++)
    if(s.at(i)!=s.at(l/2-i-1))
      ans=false;
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 3624
a,b = map(int,input().split())

def gcd(a,b):
    if a>b:
        a,b = b,a
    if b%a == 0:
        return a
    return gcd(a,b%a)

n = gcd(a,b)
m = n
ans = 1

if m%2==0:
    ans += 1
    while m%2==0:
        m //= 2
f = 3

while f*f <= n:
    if m%f==0:
        ans += 1
        while m%f==0:
            m //= f
    f+=2

if m!=1:
    ans += 1

print(ans)


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

int main(){

    string s;
    cin>>s;
    int i,j;
    int c=0;
        for(i=0,j=s.size()-1;i<j;i++,j--)
        {
            if(s[i]!=s[j])
                c++;
        }

        cout<<c<<endl;

    return 0;
}


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

int main(){
  string s; cin >> s;
  int cnt = 0;
  for(int i = 0; i < s.size() - 1; i++){
    if(s.at(i) != s.at(i+1)) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string c;
  cin >> c;
  if ( c == "a" || c == "e" || c == "i" || c == "o" || c == "u" ) {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
k_n = list(map(int, input().split()))
a = list(map(int, input().split()))

k = k_n[0]
n = k_n[1]


l = 0
l_min = float('inf')

for i in range(n):
  #右回り
  if i == 0:
    l_right = a[0] + a[n-1]
  else:
  	l_right = k - (a[i]-a[i-1])
    
  #左回り
  if i == n-1:
    l_left = a[n-1] - a[0] 
  else:
    l_left = k - (a[i+1]-a[i])
  
  if l_right <= l_left:
    l = l_right
  else:
    l = l_left
    
  if l < l_min:
    l_min = l
  else:
    pass
    
print(l_min)




Measured memory_bytes: 26444
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int x, a, b;
    cin >> x >> a >> b;

    if (b - a <= 0) {
        cout << "delicious" << endl;
    } else if (b - a <= x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

typedef long long ll;
using namespace std;

int main(){
  int k,s,count=0;
  cin >> k >> s;
  for (int x=0;x<=k;x++){
    for (int y=0;y<=k;y++){
      if (s-x-y >= 0 && s-x-y <= k){
	count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main()
{
    int n, m, X, Y;
    scanf("%d%d%d%d", &n, &m, &X, &Y);
    int x[100], y[100];
    int i;

    int maxx = -100;
    for (i=0; i<n; i++)
    {
        scanf("%d", &x[i]);
        if (x[i] > maxx) maxx = x[i];
    }
    int miny = 101;
    for (i=0; i<m; i++)
    {
        scanf("%d", &y[i]);
        if (y[i] < miny) miny = y[i];
    }

    bool f = false;
    if (!(X<Y)) f = true;
    if (!(maxx < miny && maxx<Y && X<miny)) f = true;

    if (f) printf("War\n");
    else printf("No War\n");

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define pb push_back
#define pf push_front
#define Mid ((l+r)/2)
#define pi pair<int,int>
#define pii pair<int,pi>
#define deb(x) cout<<#x<<"="<<x<<endl;
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int f[10];
int main()
{
    go;
    for(int i=0;i<5;i++)
    {
        int x;
        cin>>x;
        f[x]++;
    }
    for(int i=1;i<=5;i++)
        if(!f[i])
        cout<<i;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N)
  {
    cin >> p[i];
  }
  SORT(p);
  int ans = 0;
  rep(i, K)
  {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)



int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	sort(a,a+3);

	if(a[0]==5 && a[1]==5&&a[2]==7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;




}

Measured memory_bytes: 256