akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

bool isPrime(int n) {
    bool f = true;
    for (int i = 2; i < n; i++) {
        if (n % i == 0) {
            f = false;
            break;
        }
    }
    return f;
}

int main() {
    int a[55];
    int tmp = 2;
    for (int i = 0; i <= 55; i++) {
        while (true) {
            tmp++;
            if (isPrime(tmp) && tmp % 5 == 1) {
                a[i] = tmp;
                break;
            }
        }
    }
    int n;
    cin >> n;
    imfor(i, n) {
        cout << a[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
N,W=map(int,input().split())
WV=[]
for i in range(N):
    WV.append(list(map(int,input().split())))
dp=[[0 for i in range(W+1)] for j in range(N+1)]
for i in range(N+1):
    for j in range(W+1):
        if i>0:
            if j-WV[i-1][0]>=0:
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-WV[i-1][0]]+WV[i-1][1])
            else: 
                dp[i][j]=dp[i-1][j]
print(dp[N][W])

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

#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, s, n) for(int i = s; i < n; i++)
#define MOD 1e9+7
void max_self(int &a, int b) { a=a>b?a:b; }
void min_self(int &a, int b) { a=a<b?a:b; }

using namespace std;

int h, n;
int damage;
int cost;

// H health
// N spells
// a value
// b cost

// dp[i] - minimum mana at health i, and minimum
// minimise the amount of magic points


int main() {

    cin >> h >> n;

    vector<int> dp(h+1, 2e9);
    dp[0]=0;

    rep(_, n) {
        scanf("%d%d", &damage, &cost);

        rep(i, h+1) {
            min_self(dp[min(i+damage, h)], dp[i]+cost);
        }

    }

    cout << dp[h] << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b;
vector<int> v,u;
int main(void){
    while(1){
    cin>>n>>m;
    if(n==0&&m==0)return 0;
    for(int i=n;i>0;i--){
        v.push_back(i);
    }
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--;
        for(int i=n-1;i>a+b-1;i--)u.push_back(v[i]);
        for(int i=a-1;i>=0;i--)u.push_back(v[i]);
        for(int i=a+b-1;i>=a;i--)u.push_back(v[i]);
        v={};
        for(int i=n-1;i>=0;i--)v.push_back(u[i]);
        u={};
    }
    cout<<v[0]<<endl;
    v={};
    }
}



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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=1e5+5;
ll sz[mxn];
vi adj[mxn];
ll dis[mxn];

void dfs(int u, int p=-1){
	for(auto v:adj[u]){
		if(v==p)continue;
		dis[v]=dis[u]+1LL;
		dfs(v,u);
	}
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n;
	cin >> n;
	pll dist[n];
	map<ll,int>vis;
	map<ii,bool>ans;
	for(int i=0; i<n; i++){
		cin >> dist[i].fi;
		dist[i].se=(ll)i;
		sz[i]=1LL;
		vis[dist[i].fi]=i;
	}
	sort(dist,dist+n);
	for(int i=n-1; i>0; i--){
		auto ind = dist[i].se;
		auto next = dist[i].fi-n+2*sz[ind];
		if(vis.find(next)==vis.end()||next>=dist[i].fi){
			cout << -1 << endl;
			return 0;
		}
		auto ptr = vis[next];
		if(ptr==ind){
			cout << -1 << endl;
			return 0;
		}
		sz[ptr] += sz[ind];
		adj[ind].eb(ptr);
		adj[ptr].eb(ind);
		ans[ii(ptr,ind)]=1;
	}
	bool ok=0;
	for(int i=0; i<n&&!ok; i++){
		if(sz[i]==n)ok=1;
	}
	dfs(dist[0].se);
	ll sum=0;
	for(int i=0; i<n; i++)sum += dis[i];
	if(sum!=dist[0].fi)ok=0;
	if(!ok)cout << -1 << endl;
	else{
		for(auto x:ans){
			cout << x.fi.fi+1 << ' ' << x.fi.se+1 << endl;
		}	
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 24832
#include <iostream>
using namespace std;
int main(void) {
    int n,total = 100000,plus = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        plus = 0.05 * total;
        if (plus % 1000)     plus = (plus / 1000 + 1) * 1000;
    total += plus;
    }
    cout << total << endl;
}


Measured memory_bytes: 3004
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=5e6+10;
const int mod=1e9+7;
int arr[N],iarr[N];
int logi(int n){int p=0;while(n/2){n=n/2;p++;}return p;}
int poww(int x,int y){int pro=1;while(y){if(y&1)pro=((pro%mod)*(x%mod)%mod);y=y>>1;x=((x%mod)*(x%mod)%mod);}return pro;}
int poww2(int x,int y){int pro=1;while(y){if(y&1)pro=pro*x;y=y>>1;x=x*x;}return pro;}
double poww1(double x,int y){double pro=1.000000000;while(y){if(y&1)pro=((pro)*(x));y=y>>1;x=((x)*(x));}return pro;}
map<int,int> mp1,mp2;
set<int> st;
int arr1[1000001],arr2[1000001];

int solve()
{
	int k,n;
	cin>>k>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	int t1=0,t2=0;
	sort(v.begin(),v.end());
	for(int i=1;i<n;i++)
	{
		t1+=v[i]-v[i-1];
		t2=max(t2,v[i]-v[i-1]);
	}
	int t3=k-v[n-1]+v[0];
	if(t2>t3)
	{
		t1=t1-t2+t3;
	}
	cout<<t1;
}
int32_t main()																																	
{
	//fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

using namespace std;


int main() {
    int n;
    scanf("%d",&n);
    int a[n+1];
    map < int , int >m;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        m[a[i]]++;
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if(m[a[i]]%2==1){
            sum++;
            m[a[i]]=0;
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'

int main()
{
    fastio;
    int n;
    cin>>n;
    vinput(a,n);
    vector<lli> b;

    int f=1;
    rep(l,n,1){
        if(a[l]<a[l-1]){
            f=0;
            break;
        }
    }
    if(f){
        cout<<"YES"<<endl;
        return 0;
    }

    rep(i,n,0){
        rep(j,n,i+1){
            b=a;
            swap(b[i],b[j]);
            f=1;
            rep(l,n,1){
                if(b[l]<b[l-1]){
                    f=0;
                    break;
                }
            }
            if(f){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ci const int&
#define pi pair<int,int>
#define f first
#define s second
using namespace std;
int n,p[200010],tg[200010],mx,t1,t2,n1,n2,l1,l2,tt,nm1,nm2,tmp;
struct BIT{
	int val[200010],tim;
	vector<pi>chg[200010];
	void Ins(int x,ci v){
		x=n-x+1;
		while(x<=n)val[x]<v?chg[tim].push_back((pi){x,val[x]}),val[x]=v:0,x+=(x&-x);
	}
	void Back(){
		for(int i=(int)chg[tim].size()-1;i>=0;--i)val[chg[tim][i].f]=chg[tim][i].s,chg[tim].pop_back();
		--tim;
	}
	int Que(int x){
		x=n-x+1;
		int ret=-1e9;
		while(x)ret=max(ret,val[x]),x-=(x&-x);
		return ret;
	}
}od,ev;
bool Check(){
	tmp=n1+tt-n2;
	if(tmp>=0&&(((tmp&1)&&od.Que(nm2)>=tmp)||(!(tmp&1)&&ev.Que(nm2)>=tmp)))return 1;
	tmp=n2+tt-n1;
	if(tmp>=0&&(((tmp&1)&&od.Que(nm1)>=tmp)||(!(tmp&1)&&ev.Que(nm1)>=tmp)))return 1;
	return 0;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&p[i]),p[i]>mx?mx=p[i],tg[i]=1,++tt:0;
	for(int i=1;i<=n;++i)od.val[i]=-1e9;
	for(int i=n;i>=1;--i){
		++od.tim,++ev.tim;
		if(tg[i])od.Ins(p[i],od.Que(p[i])+2),ev.Ins(p[i],ev.Que(p[i])+2);
		else t1=od.Que(p[i]),t2=ev.Que(p[i]),od.Ins(p[i],t2+1),ev.Ins(p[i],t1+1);
	}
	nm1=nm2=1;
	if(!Check())return puts("-1"),0;
	for(int i=1;i<=n;++i){
		tt-=tg[i],od.Back(),ev.Back();
		n1+=(p[i]>=nm1);
		if(Check())putchar('0'),nm1=max(nm1,p[i]);
		else n1-=(p[i]>=nm1),n2+=(p[i]>=nm2),nm2=max(nm2,p[i]),putchar('1');
	}
	return 0;
}

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

#define MAX(X,Y) (((X)>(Y))?(X):(Y))

int main () {
	int A, B;
	cin >> A >> B;
	if (B>0)
		cout << MAX(A+B,A*B) << endl;
	else
		cout << MAX(A-B,A*B) << endl;
	return 0;
}

Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep(i,n)    for(ll i=0; i<n; i++)
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll i,j,x,n,d,ans;
    cin>>n>>d>>x;
    ans=x+n;
    ll a[n];
    rep(i,n)
    cin>>a[i];
    rep(i,n)
    {
        ll cnt=1,choc=0;
        while((a[i]*cnt)+1<=d){
            choc++;cnt++;
        }
        ans+=choc;
    }


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





Measured memory_bytes: 3624
from collections import deque
def main():
    s = list(input())
    q = int(input())
    query = []
    que = deque(s)
    f = False
    for i in range(q):
        query.append(input().split(" "))
    for i in range(q):
        if query[i][0] == '1':
            f = not f
        else:
            if f:
                if query[i][1] == '2':
                    que.appendleft(query[i][2])
                else:
                    que.append(query[i][2])
            else:
                if query[i][1] == '1':
                    que.appendleft(query[i][2])
                else:
                    que.append(query[i][2])
    if f:
        que.reverse()
    print("".join(que))

if __name__ == "__main__":
    main()

Measured memory_bytes: 48344
#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)
#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

int main ()
{
    #ifdef Lollipop
        //freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    //fastRead;
    string s;
    cin >> s;
    int len = s.size();
    for (int i = 0; i < len; i++){
        cout << 'x';
    }
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
from collections import Counter

N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]

s_count = Counter(s)
t_count = Counter(t)

s_count.subtract(t_count)

res = max(s_count.values())

if res > 0:
    print(res)
else:
    print(0)

Measured memory_bytes: 3316
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
vector<vector<int>> vt;
int visited[5], ch,cnt;
void dfs(int here,int cc)
{
	cnt++;
	visited[here] = 1;
	int zz = 0;
	for (int i = 0; i < vt[here].size(); i++)
	{
		int next = vt[here][i];
		if (!visited[next])
		{
			dfs(next,cc);
			zz++;
		}
	}
	if (zz > 1) 
		ch = 1;
}
int main()
{
	vt.resize(5);
	for (int i = 0; i < 3; i++)
	{
		int q, w;
		scanf("%d %d", &q, &w);
		vt[q].push_back(w);
		vt[w].push_back(q);
	}
	for (int i = 1; i <= 4; i++)
	{
		memset(visited, 0, sizeof(visited));
		cnt = 0, ch = 0;
		dfs(i,i);
		if (cnt == 4 && ch==0)
		{
			puts("YES");
			return 0;
		}
	}
	puts("NO");
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll a, b, x;

ll f(ll q) {
	if (q==-1) return 0;
	else return q/x + 1;
}

int main() {
	cin >> a >> b >> x;
	cout << f(b) - f(a-1) << ln;
}

Measured memory_bytes: 256
x, y = map(int, input().split())

ans = 1 << 35
 
# x to y
if x <= y: ans = min(ans, y - x)
# -x to y
if -x <= y: ans = min(ans, 1 + y - (-x))
# x to -y
if x <= -y: ans = min(ans, -y - x + 1)
# -x to -y
if -x <= -y: ans = min(ans, 1 + -y - (-x) + 1)

print(ans)



Measured memory_bytes: 38384
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    /////////////////////
    // Write code below /
    /////////////////////
    int sumOfPeople  = 0;
    int numberOfGroup;
    cin >> numberOfGroup;
    for (int indexOfGroup = 0; indexOfGroup < numberOfGroup; indexOfGroup++) {
        int startSeat, endSeat;
        cin >> startSeat >> endSeat;
        int numberOfPerson = endSeat - startSeat + 1;
        sumOfPeople += numberOfPerson;
    }
    
    cout << sumOfPeople << endl;
    
    return 0;
}


Measured memory_bytes: 256
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (k (read))
         (s (make-array n :element-type 'bit))
         (cumul (make-array (1+ n) :fill-pointer 0 :element-type 'uint32)))
    (declare (uint31 n k))
    (dotimes (i n)
      (setf (aref s i) (- (read-byte *standard-input*) 48)))
    (vector-push 0 cumul)
    (loop with base = 0
          with base-bit = (aref s 0)
          for i below n
          unless (= base-bit (aref s i))
          do (vector-push (- i base) cumul)
             (setf base i
                   base-bit (aref s i))
          finally (vector-push (- i base) cumul))
    (dotimes (i n)
      (incf (aref cumul (1+ i)) (aref cumul i)))
    (println
     (loop with len = (length cumul)
           for l below (- len 1)
           for width = (if (zerop (aref s 0))
                           (if (evenp l)
                               (* 2 k)
                               (+ (* 2 k) 1))
                           (if (evenp l)
                               (+ (* 2 k) 1)
                               (* 2 k)))
           for r = (min (- len 1) (+ l width))
           maximize (- (aref cumul r) (aref cumul l))))))

#-swank(main)


Measured memory_bytes: 13540
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<vector<int>> a(n,vector<int>(n-1));
    rep(i,0,n) rep(j,0,n-1){
        cin>>a[i][j];
        a[i][j]--;
    }
    
    int ans=0;
    vector<int> now_index(n,0);
    bool  finish=false;
    while(true){
        finish=true;
        
        vector<int> add(n,0);
        rep(i,0,n){
            if(now_index[i]>=n-1) continue;
            
            int now=a[i][now_index[i]];
            
            if(a[now][now_index[now]]==i){
                add[i]++;
                finish=false;
            }
        }
        rep(i,0,n){
            now_index[i]+=add[i];
        }
        
        
        if(finish) break;
        ans++;
        if(ans>=100000){
            cout<<n*(n-1)/2<<endl;
            return 0;
        }
    }
    
    rep(i,0,n){
        if(now_index[i]<n-1) ans=-1;
    }
    cout<<ans<<endl;
}


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

typedef long long ll;
ll k, c1, c2;
string s;
int main()
{
	ll i;
	cin >> s >> k;
	if (k % 2) {
		for (i = 1; i < s.size(); i++) {
			if (s[i] == s[i - 1]) c1++, i++;
		}
		if (i == s.size() && s[s.size() - 1] == s[0]) c1++, i = 2;
		else i = 1;
	} else {
		i = 1;
	}
	s += s;
	for (; i < s.size(); i++) {
		if (s[i] == s[i - 1]) c2++, i++;
	}
	c2 *= k / 2;
	if (i == s.size() && s[s.size() - 1] == s[0]) c2 += k / 2 - 1;
	cout << c1 + c2 << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

const int maxn = (int) 1e3 + 10;

int ifact[maxn], inv[maxn];

void precalc() {
  ifact[0] = 1;
  for (int i = 1; i < maxn; ++i) {
    inv[i] = myPower(i, mod - 2);
    ifact[i] = mult(ifact[i - 1], inv[i]);
  }
}


int n, a, b, c, d;

int read() {
  if (scanf("%d%d%d%d%d", &n, &a, &b, &c, &d) < 5) {
    return 0;
  }
  return 1;
}

int dp[maxn];

void solve() {
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int k = a; k <= b; ++k) {
    for (int x = n; x >= 0; --x) {
      int cur = dp[x];
      if (!cur) {
        continue;
      }
      for (int cnt = 0; cnt <= d; ++cnt) {
        if (!cur) {
          break;
        }
        int nx = x + cnt * k;
        if (nx > n) {
          break;
        }
        //eprintf("x = %d, k = %d, cnt = %d, cur = %d\n", x, k, cnt, cur);
        if (cnt >= c) {
          add(dp[nx], cur);
        }
        cur = mult(cur, ifact[k]);
        cur = mult(cur, inv[cnt + 1]);
      }
    }
  }
  int res = dp[n];
  for (int i = 1; i <= n; ++i) {
    res = mult(res, i);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main()
{
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;
    long long r, g, b;
    r = g = b = 0;
    for (int i = 0; i < n; i++) {
        switch (s[i]) {
        case 'R': r++; break;
        case 'G': g++; break;
        default: b++; break;
        }
    }
    long long ans = r * g * b;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int k = 2 * j - i;
            if (k >= n || j >= k)
                continue;
            if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k])
                ans--;
        }
    }

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


Measured memory_bytes: 3580
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N;
    cin >> N;

    int ans = 0;

    for (int i = 1; i <= N; i++) {
        if (i % 2 == 0) continue;
        int c = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) c++;
        }
        if (c == 8) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// Last Change: 04/03/2019 21:58:43.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

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

  if (R < 1200) {
    cout << "ABC";
  } else if (R < 2800) {
    cout << "ARC";
  } else {
    cout << "AGC";
  }
  cout << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	vector<lli> d(n);
	REP(i,0,n){
		cin>>d[i];
		if(d[i]>12)d[i] = 24-d[i];
	}

	sort(d.begin(),d.end());

	vector<lli> ans;

	REP(i,0,n){
		if(i%2==0)ans.push_back(d[i]);
		else ans.push_back(24-d[i]);
	}

	sort(ans.begin(),ans.end());

	lli cnt = min(ans[0],24LL-ans[n-1]);
	REP(i,1,n){
		cnt = min(abs(ans[i]-ans[i-1]),cnt);
	}
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
// #include <unordered_map>
#include <set>
#include <utility>
#include <bitset>
#include <limits>
#include <climits>
using namespace std;

#ifdef DEBUG
#define NDEBUG
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 11
char _buf[INTSPACE*1000000 + 3];  // ここ要確認

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

int solve(int N, vector<int>& a) {
    vector<int> st(100000, 0);
    rep(i, N){
        ++st[ a[i] ];
    }

    int sum = st[0]+st[1]+st[2];
    int maxsum = sum;
    for (int i=3; i<=99999; ++i) {
        // (0 1 2) 3]
        // (99996 99997 99998) 99999]
        sum = sum + st[i] - st[i-3];
        maxsum = max(maxsum, sum);
    }
    return maxsum;
}

int main() {
    int N = loadint();
    vector<int> a(N);
    loadvec(a, N);
    int ans = solve(N, a);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1664
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii>
using vec = vector<T>;

const ll INF = 1e18, MOD = 1e9 + 7;

const int MAX = 1e6;

vii factors(const int n) {
    vii res;
    for (int i = 1; ll(i) * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (ll(i) * i != n) {
                res.push_back(n / i);
            }
        }
    }
    sort(res.begin(), res.end(), greater<int>());
    return res;
}

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    int n, k;
    cin >> n >> k;
    vii v(n);
    for (int &e : v) {
        cin >> e;
    }
    auto check = [=] (const int x) {
        vii arr(n);
        for (int i = 0; i < n; i++) {
            arr[i] = v[i] % x;
        }
        sort(arr.begin(), arr.end());
        int moves = 0;
        for (int i = 0, j = n - 1; i < j;) {
            const int d = min(x - arr[j], arr[i]);
            moves += d;
            arr[j] += d;
            arr[i] -= d;
            if (arr[j] == x) j--;
            if (arr[i] == 0) i++;
        }
        return moves <= k;
    };
    const int sum = accumulate(v.begin(), v.end(), 0);
    for (int f : factors(sum)) {
        if (check(f)) {
            cout << f << '\n';
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAX_N = 100;

int bubble_sort(int *a, int n);

int main() {
    int n;
    int a[MAX_N];

    cin >> n;

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

    int count = bubble_sort(a, n);

    for (int i = 0; i < n; i++) {
        cout << a[i];
        if (i < n - 1) {
            cout << " ";
        }
    }

    cout << endl;
    cout << count << endl;
}

int bubble_sort(int *a, int n) {
    
    bool flag = true;
    int i = 0;
    int count = 0;
    int temp;

    while (flag) {
        flag = false;

        for (int j = n - 1; j > i; j--) {
            if (a[j] < a[j - 1]) {
                temp = a[j];
                a[j] = a[j - 1];
                a[j - 1] = temp;
                flag = true;
                count++;
            }
        }
        i++;
    }

    return count;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e: a) {
        char t;
        cin >> t;
        e = t - '1';
    }

    vector<int> prev(n), next;
    prev = a;
    for (int l = 1 << 30; l > 0; l /= 2) {
        if (prev.size() <= l) continue;
        next.resize(prev.size() - l);
        for (int i = 0; i < next.size(); ++i) {
            next[i] = prev[i] ^ prev[i + l];
        }
        next.swap(prev);
    }

    assert(prev.size() == 1);
    int s = prev.front(), ans;
    if (s & 1) {
        ans = 1;
    } else {
        // 0 or 2
        if (count(a.begin(), a.end(), 1) > 0) {
            ans = 0;
        } else {
            ans = s;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
#define int long long int
using namespace std;

signed main()
{ 
    int t;
    bool arr[6] = {0};
    for(int i=1;i<=5;i++)
    {
        cin>>t;
        arr[t]=1;
    }

    for(int i=1;i<=5;i++)
    {
        if(arr[i]==0)
        {
            cout<<i;
            break;
        }
    }

    return 0;
}


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

void dfs(int t,vector<pair<int,int> >&v1,vector<int>&v2,int fill,int p,int q)
{
  for(int i=0;i<v1.size();i++){
    int x,y;
    x=v1[i].first-v1[t].first;
    y=v1[i].second-v1[t].second;
    if(p==x && q==y){
      v2[i]=fill;
      dfs(i,v1,v2,fill,p,q);
    }
  }
}

int main()
{
  int N;
  int ans=99999999;
  cin >> N;
  if(N==1){
    cout << 1 << endl;
    return 0;
  }
  vector<pair<int,int> >v1(N);
  vector<int>v2(N,-1);
  for(int i=0;i<N;i++){
    int a,b;
    cin >> a >> b;
    v1[i]=make_pair(a,b);
  }


  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++){
      if(i==j)
        continue;
      int p,q;
      p=v1[i].first-v1[j].first;
      q=v1[i].second-v1[j].second;
      int z=0;
      for(int k=0;k<N;k++){
        if(v2[k]==-1)
          z++;
          dfs(k,v1,v2,z,p,q);
          dfs(k,v1,v2,z,-p,-q);
      }
      if(ans>z)
        ans=z;
      fill(v2.begin(),v2.end(),-1);

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

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
  int N;
  scanf("%d", &N);
  
  for (int i=0; i<10; i++) {
    if (0<=N && N<=1000) {
      printf("%d",1000-N);
      return 0;
    }
    N -= 1000;
  }
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mod 1000000007
//#define mod 998244353
using namespace std;
int check(string s,int l,int r)
{
	int n=r-l+1,i,flag=1;
	for(i=0;i<n/2;i++)
	{
		if(s[i+l]!=s[r-i])
		{
			flag=0;
			break;
		}
	}
	return flag;
}


int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    ll l;
    cin>>l;
    float x=l*l*l*1.0,y=27.0,ans;
    ans=x*1.0/y;
    cout<< setprecision(10) <<ans;
    
    
    
    
    
    
    

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct Dice {
	static const int tbl[6][4];
	int t, f;
	Dice(int top, int front) : t(top), f(front) {}
	int top() { return t; }
	int front() { return f; }
	int right() {
		for (int i = 0; i < 4; i++)
			if (tbl[t - 1][i] == f)
				return tbl[t - 1][(i + 1) % 4];
		return -1;
	}
	int bottom() { return 7 - top(); }
	int left() { return 7 - right(); }
	int rear() { return 7 - front(); }
};
const int Dice::tbl[6][4] = {
	{ 5, 4, 2, 3 },
	{ 3, 1, 4, 6 },
	{ 6, 5, 1, 2 },
	{ 1, 5, 6, 2 },
	{ 1, 3, 6, 4 },
	{ 3, 2, 4, 5 },
};

const int dx[4] = { 0, 1, 0, -1 };
const int dy[4] = { -1, 0, 1, 0 };
Dice next(int top, int front, int dir) {
	Dice d(top, front);
	switch (dir) {
	case 0: return Dice(d.front(), d.bottom());
	case 1: return Dice(d.left(), d.front());
	case 2: return Dice(d.rear(), d.top());
	case 3: return Dice(d.right(), d.front());
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int n; cin >> n&&n;) {
		using P = pair<int, int>;
		map<P, int> h;
		map<P, int> top;
		rep(i, 0, n) {
			int t, f; cin >> t >> f;
			dump(i, t, f);
			int x = 0, y = 0;
			while (true) {
				int dir = -1, mini = INF;
				rep(k, 0, 4) {
					int nx = x + dx[k], ny = y + dy[k];
					if (h[P(nx, ny)] >= h[P(x, y)])
						continue;
					Dice res = next(t, f, k);
					if (res.top() < 4 && chmin(mini, res.top()))
						dir = k;
				}
				if (dir == -1)
					break;
				Dice res = next(t, f, dir);
				t = res.top(), f = res.front();
				x += dx[dir], y += dy[dir];
				dump(t, f, x, y);
			}
			dump(t, f, x, y);
			h[P(x, y)]++;
			top[P(x, y)] = t;
		}
		vector<int> ans(6);
		for (auto e : top) {
			ans[e.second - 1]++;
		}
		cout << ans[0]; rep(i, 1, ans.size()) { cout << " " << ans[i]; } cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s1, s2;
	cin >> s1 >> s2;
	s1 = s1+s1;  // 环的处理，拼起来 
	if(s1.find(s2, 0)!=s1.npos)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int dijk(int n, Vec<Vec<int> >& table) {
    Vec<int> answer((1 << n), INF);
    priority_queue<PII, Vec<PII>, std::greater<PII> > pq;

    for (int i = 0; i < n; i++) {
        pq.push(make_pair(table[i][0], 1 << i));
        answer[1 << i] = table[i][0];
    }

    while (!pq.empty()) {
        int now_cost = pq.top().first;
        int now_have = pq.top().second;
        pq.pop();


        for (int i = 0; i < n; i++) {
            if ((now_have & (1 << i)) == 0) {
                int min_cost = table[i][0];
                for (int j = 0; j < n; j++) {
                    if ((now_have & (1 << j)) != 0) {
                        min_cost = min(min_cost, table[i][j + 1]);
                    }
                }
                int update_cost = now_cost + min_cost;
                int update_have = (now_have | (1 << i));
                if (update_cost < answer[update_have]) {
                    answer[update_have] = update_cost;
                    pq.push(make_pair(update_cost, update_have));
                }
                /*
                cout << "HERE = " << now_have << " " << i + 1 << endl;
                cout << "MIN_COST = " << min_cost << endl;
                cout << update_cost << " " << update_have << endl;
                */
            }
        }
    }
    return answer[(1 << n) - 1];
}

int main(void) {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        Vec<Vec<int> > table(n, Vec<int>(n + 1));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n + 1; j++) {
                cin >> table[i][j];
            }
        }
        int ans = dijk(n, table);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout<<(x)<<"\n"
#define REP(i, n) for(int i=0;i<n;i++)
#define endl "\n"
using G = vector<vector<int>>;
using P = pair<int,int>;
using ll = long long;
const int INF = 1e9;

int n,m;
vector<vector<P>> g(100010);

void dfs() {
  queue<P> q;
  vector<int> dist(n, INF);

  // 全ての点について矛盾がないか調べる
  // グラフが連結していないケースがあるためするためnまでループして調べる
  REP(i,n) {
    if (dist[i] != INF) continue; // チェック済み

    q.push({ i, 0 });
    dist[i] = 0;
    while(!q.empty()) {
      auto v = q.front(); q.pop();
      int p = v.first;

      for(auto x: g[p]) {
        int np = x.first;
        int nd = dist[p] + x.second;

        if (dist[np] == INF) {
          dist[np] = nd;
          q.push(x);
        } else {
          // 矛盾しているため終了
          if (dist[np] != nd) { COUT("No"); return; }
        }
      }
    }
  }
  COUT("Yes");
}

int main() {
  cin >> n >> m;

  // m == 0 の場合はそもそも矛盾しない
  if (m == 0) { COUT("Yes"); return 0; }

  vector<int> l(m),r(m),d(m);
  REP(i,m) {
    cin >> l[i] >> r[i] >> d[i];
    l[i]--; r[i]--;
  }

  REP(i,m) {
    g[l[i]].push_back({r[i], d[i]});
    g[r[i]].push_back({l[i], -d[i]});
  }

  dfs();
  return 0;
}

Measured memory_bytes: 14820
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

string f(int x) {
    string res;
    int keta = 0;
    int ix = x;
    while (ix > 0) {
        keta++;
        ix /= 10;
    }
    int z = 6-keta;
    rep(i,z) res += '0';
    res += to_string(x);
    return res;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> s(m);
    vector<vector<P>> t(n);
    rep(i,m) {
        int p, y;
        cin >> p >> y;
        s[i] += f(p);
        p--;
        t[p].emplace_back(y,i);
    }
    rep(i,n) {
        sort(t[i].begin(), t[i].end());
    }
    rep(i,n) {
        rep(j,t[i].size()) {
            int id = t[i][j].second;
            s[id] += f(j+1);
        }
    }
    rep(i,m) {
        cout << s[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 12004
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

ll mod;

ll powmod(ll a, ll e) {
  ll sum = 1;
  ll cur = a;
  while (e > 0) {
    if (e % 2) {
      sum = sum * cur % mod;
    }
    cur = cur * cur % mod;
    e /= 2;
  }
  return sum;
}
ll powmod(ll a, ll e, ll mod) {
  ll sum = 1;
  ll cur = a;
  while (e > 0) {
    if (e % 2) {
      sum = sum * cur % mod;
    }
    cur = cur * cur % mod;
    e /= 2;
  }
  return sum;
}

void add(ll &x, ll y) {
  x = (x + y) % mod;
}

const int N = 3010;
ll s2[N][N];
ll comb[N][N];
ll dp[N][N];
ll invfac[N];

void init(void) {
  comb[0][0] = 1;
  REP(i, 1, N) {
    REP(j, 0, N) {
      if (j > 0) add(comb[i][j], comb[i - 1][j - 1]);
      add(comb[i][j], comb[i - 1][j]);
    }
  }
  dp[0][0] = 1;
  REP(i, 1, N) {
    REP(j, 0, N) {
      if (j > 0) add(dp[i][j], dp[i - 1][j - 1]);
      add(dp[i][j], dp[i - 1][j]);
      dp[i][j] = dp[i][j] * j % mod;
      add(dp[i][j], dp[i - 1][j]);
    }
  }
  if (0) {
    REP(i, 0, 5) {
      REP(j, 0, 5) {
	cerr << " " << dp[i][j];
      }
      cerr << endl;
    }
  }
  invfac[0] = 1;
  REP(i, 1, N) {
    invfac[i] = invfac[i - 1] * powmod(i, mod - 2) % mod;
  }
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n >> mod;
  init();
  ll tot = 0;
  REP(i, 0, n + 1) {
    ll fac = powmod(2, powmod(2, n - i, mod - 1));
    ll tis = powmod(2, n - i);
    ll ani = 0;
    ll accfac = 1;
    REP(j, 0, i + 1) {
      ll tmp = dp[i][j] * accfac % mod;
      accfac = accfac * tis % mod;
      tmp = tmp * invfac[j] % mod;
      add(ani, tmp);
    }
    ani = ani * fac % mod;
    ani = ani * comb[n][i] % mod;
    if (i % 2 == 1) ani = (mod - ani) % mod;
    add(tot, ani);
  }
  cout << tot << endl;
}


Measured memory_bytes: 143616
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		N = ri();
		int NN = N * 2;
		int[] q = new int[N];
		
		q = Enumerable.Range(0,N).ToArray();
		char[] ss = new char[NN];
		ss[0] = Query(q);
		if(ss[0] == 'R'){
			ss[N] = 'B';
		} else {
			ss[N] = 'R';
		}
		
		int l = 0;
		int r = N;
		while(r - l > 1){
			int c = (r + l) / 2;
			q = Enumerable.Range(c, N).ToArray();
			var ch = Query(q);
			ss[c] = ch;
			if(ch == ss[l]){
				l = c;
			} else {
				r = c;
			}
		}
		
		char[] ans = new char[NN];
		for(int i=0;i<NN;i++) ans[i] = '?';
		
		
		for(int i=0;i<N-1;i++) q[i] = r + i;
		for(int i=0;i<NN;i++){
			if(i >= r && i < r + N - 1) continue;
			q[N - 1] = i;
			ans[i] = Query(q);
		}
		int cr = 0;
		int cb = 0;
		int idx = 0;
//Console.WriteLine("{0} {1}",r,r+N-1);
//Console.WriteLine("{0}",new String(ans));
		for(int i=0;i<NN;i++){
			if(i >= r && i < r + N - 1) continue;
			if(ans[i] == 'R'){
				cr++;
				if(cr <= (N - 1) / 2){
					q[idx++] = i;
				}
			}
			if(ans[i] == 'B'){
				cb++;
				if(cb <= (N - 1) / 2){
					q[idx++] = i;
				}
			}
		}
		
		for(int i=r;i<r+N-1;i++){
			q[N - 1] = i;
			ans[i] = Query(q);
		}
		
		Ans(ans);
	}
	
	int qcnt = 0;
	char Query(int[] a){
		Debug.Assert(a.Length == N);
		qcnt++;
		if(qcnt > 210){
			throw new Exception("ovfl");
		}
		
		for(int i=0;i<N;i++){
			if(!(a[i] >= 0 && a[i] < N * 2)){
				throw new Exception("query");
			}
			for(int j=i+1;j<N;j++){
				if(a[i] == a[j]){
					throw new Exception("query");
				}
			}
		}
		
		
		
		Console.WriteLine("? {0}",String.Join(" ", a.Select(v => v + 1)));
		Console.Out.Flush();
		var ret = rs();
		return ret[0];
	}
	void Ans(char[] ans){
		Debug.Assert(!ans.Contains('?'));
		var di = new Dictionary<char, int>();
		foreach(var c in ans){
			if(!di.ContainsKey(c)) di.Add(c, 0);
			di[c]++;
		}
		if(di['R'] != N) throw new Exception("R");
		if(di['B'] != N) throw new Exception("B");
		
		Console.WriteLine("! {0}", new String(ans));
		Console.Out.Flush();
	}
	
	int N;
	public Sol(){
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13736
import java.util.Scanner;
public class Main {

  public static int partition(int[] a, int p, int r) {
    int x = a[r];
    int i = p - 1;
    for (int j = p; j < r; j++) {
      if (a[j] <= x) {
        i++;
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
      }
    }
    int temp = a[i+1];
    a[i+1] = a[r];
    a[r] = temp;
    return i+1;
  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int[] A = new int[n];
    for (int i = 0; i < n; i++) {
      A[i] = s.nextInt();
    }
    s.close();
    int result = partition(A, 0, n-1);
    for (int i = 0; i < n; i++) {
      if (i == result)
        System.out.print("[");
      System.out.print(A[i]);
      if (i == result)
        System.out.print("]");
      if (i != n-1)
        System.out.print(" ");
    }
    System.out.println();
  }
}


Measured memory_bytes: 72136
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i = 0;i < N;i++)cin >> A[i];

  double sum = 0;
  for(int i = 0;i < N;i++){
    sum += 1.0/A[i];
  }

  cout << 1/sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int num;
    cin>>num;
    int flag=0;
    for(int i=1; i<=9; i++){
    	if(num%i==0 && num/i<=9){
    		flag=1;
    		break;
		}
	}
	if(flag)
	 cout<<"Yes";
	else
	 cout<<"No";
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	string S; cin >> S;

	int ans = 0;
	REP(i,S.length()){
		if(S[i] == '+') ans++;
		else ans--;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256