akhauriyash/Code-Regression huggingface dataset:
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?(テァツクツョテ・ツーツ湘ァツ可?

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;
constexpr int T = 40;

int N, M, s, g;

// cur, prev, speed, prevsテ」ツ??、ツクツュティツコツォテ」ツ?ッテヲツ卍づゥツ鳴?
double dist[40][40][T][4];

struct Edge {
    int to; double cost; int lim;
};

struct Elem {
    int cur, prev, speed, prevs;
};

bool operator<(const Elem &a, const Elem &b) {
    return dist[a.cur][a.prev][a.speed][a.prevs] > dist[b.cur][b.prev][b.speed][b.prevs];
}

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

signed main() {
    while(cin >> N >> M, N || M) {
        N++;
        cin >> s >> g;
        vector< vector<Edge> > G(N);
        rep(i,0,M) {
            int x, y; double d; int c; cin >> x >> y >> d >> c;
            G[x].push_back(Edge{y, d, c});
            G[y].push_back(Edge{x, d, c});
        }

        rep(i,0,N) rep(j,0,N) rep(k,0,T) rep(l,0,4) dist[i][j][k][l] = INF;
        dist[s][0][1][0] = 0.0;

        priority_queue<Elem> q;
        q.push(Elem{s, 0, 1, 0});

        double ans = INF;
        while(!q.empty()) {
            Elem t = q.top(); q.pop();
            rep(i,1,4) {
                int sp = t.speed + dx[i];
                if(sp == 0) continue;
                for(auto x : G[t.cur]) {
                    if(x.lim < t.speed || x.to == t.prev) continue;
                    double c = x.cost / t.speed;
                    // cur, prev, speed, prevs
                    if(dist[x.to][t.cur][sp][i] > dist[t.cur][t.prev][t.speed][t.prevs] + c) {
                        dist[x.to][t.cur][sp][i] = dist[t.cur][t.prev][t.speed][t.prevs] + c;
                        if(x.to == g && t.speed == 1) {
                            chmin(ans, dist[x.to][t.cur][sp][i]);
                        }
                        q.push(Elem{x.to, t.cur, sp, i});
                    }
                }
            }
        }
        if(ans == INF) cout << "unreachable" << endl;
        else printf("%.12f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 6172
parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    S = readline()
    S = S[1:length(S)-1]
    T = ""
    for i in 1:length(S)
        if S[i]==','
            T = string(T,' ')
        else
            T = string(T,S[i])
        end
    end
 	println(T)
end

main()


Measured memory_bytes: 108056
N = int(input())
a = list(map(int, input().split()))
    
l = [1]
for i in range(1,len(a)):
  if a[i] == a[i-1]:
    l[-1] += 1
  else:
    l.append(1)

print(sum(map(lambda x: x // 2, l)))

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>

using namespace std;
const int maxn=100010;
long long h,w,n,tot;
int dx[3]={-2,-1,0};
int dy[3]={-2,-1,0};

struct node{
	long long x,y;
}e[maxn];
struct nodd{
	int x,y;
	long long t;
}p[maxn*9];
long long ans[10];
bool cmp(nodd a,nodd b)
{
    if(a.x!=b.x)return a.x<b.x;
    else return a.y<b.y;
}


int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%d%d",&h,&w,&n);
	int i,j,k,x1,x2,y1,y2;
	tot=0;
	for(i=1;i<=n;i++){
		scanf("%d%d",&e[i].x,&e[i].y);
		//cout<<e[i].x<<' '<<e[i].y<<endl;
		for(j=0;j<3;j++){
			for(k=0;k<3;k++){
				x1=e[i].x+dx[j];
				y1=e[i].y+dy[k];
				x2=x1+2;
				y2=y1+2;
				if(x1>=1&&y1>=1&x2<=h&&y2<=w){
					p[++tot].x=x1;
					p[tot].y=y1;
					p[tot].t=1;
				}
			}
		}
	}
	//for(i=1;i<=tot;i++)cout<<p[i].x<<' '<<p[i].y<<' '<<p[i].t<<endl;
	sort(p+1,p+1+tot,cmp);
	//for(i=1;i<=tot;i++)cout<<p[i].x<<' '<<p[i].y<<' '<<p[i].t<<endl;
	i=1;
	while(i<=tot){
		j=i;
		while(p[j].x==p[i].x&&p[j].y==p[i].y)j++;
		ans[j-i]++;
		i=j;
	}
	
	/*
	for(i=1;i<=tot;i++)
		if(p[i].t==1){
			//p[i].t=0;
			for(j=i+1;j<=tot;j++){
				if(p[j].t==0)continue;
				else if(p[j].x==p[i].x&&p[j].y==p[i].y){
					p[j].t=0;
					p[i].t++;
				}
			}
		}
	}*/
	/*
	for(i=1;i<=tot;i++){
		if(p[i].t>0)ans[p[i].t]++;
	}*/
	for(i=1;i<=9;i++)ans[0]+=ans[i];
	ans[0]=(h-2)*(w-2)-ans[0];
	for(i=0;i<=9;i++)printf("%lld\n",ans[i]);
	return 0;
}


Measured memory_bytes: 15872
fun main(args:Array<String>) {
    val studentCount = readLine()!!.toInt()
    val students = readLine()!!.split(" ").map { it.toInt() }.let { a->a.indices.map { Pair(it + 1, a[it]) } }.sortedBy { it.second }
    println(students.map { it.first }.joinToString(" ") )

}




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

int main() {
  int N;
  cin >> N;
  
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    int a,b;
    cin >> a >> b;
    count += b - a + 1;
  }

  cout << count << endl;
}
    
    

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

int main() {
  int l, sum = 0, p, a[20] = {};
  vector<pair<pair<int, int>, int> > e;
  cin >> l;
  for (int i = 0; i < 19; i++) {
    e.push_back({{i + 1, i + 2}, 0});
  }
  p = 0;
  a[0] = 0;
  for (int i = 0; i < 19; i++) {
    if (sum + (1 << i) < l) {
      e.push_back({{19 - i, 20 - i}, (1 << i)});
      sum += (1 << i);
    }
    a[i + 1] = a[i] + (1 << i);
  }
  for (int i = 18; i >= 0; i--) {
    if (sum + 1 + a[i] < l) {
      e.push_back({{1, 20 - i}, sum + 1});
      sum += (1 << i);
    }
  }
  cout << 20 << " " << e.size() << endl;
  for (int i = 0; i < e.size(); i++) {
    cout << e[i].first.first << " " << e[i].first.second << " " << e[i].second
         << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct Unionfind{
  vector<int>d;
  vector<int>r;
  Unionfind(int n){
    d.resize(n,-1);
    r.resize(n,1);
  }
  
  int find(int x){
     if(d[x]<0) return x;
     else return d[x]=find(d[x]);
  }
  
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(r[x]>r[y]) swap(x,y);
    if(r[x]==r[y]){
       r[y]++;
    }
    d[x]=y;
  }
};

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m),b(m);
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
  }
  int bridge=0;
  for(int j=0;j<m;j++){
    Unionfind uf(n);
    bool ok=true;
    for(int i=0;i<m;i++){
      if(i!=j) uf.unite(a[i],b[i]);
    }
    for(int i=0;i<n-1;i++){
        if(uf.find(i)!=uf.find(i+1)) ok=false;
    }
    if(!ok) bridge++;
  }
    cout<<bridge<<endl;
    return 0;
}


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

int main(){
//int n;cin>>n;
int a,b,c;cin>>a>>b>>c;
if(a*c<b)cout<<c;
else cout<<b/a;
}


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

int main() {

	int N;
	cin >> N;
	string c;
	cin >> c;

	int cntR = 0;
	for (int i = 0; i < N; i++) {
		if (c[i] == 'R') cntR++;
	}
	int ans = 0;
	for (int i = 0; i < cntR; i++) {
		if (c[i] == 'W') ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef long double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Pol;
D inf=1e50,eps=1e-8,EPS=1e-8;
int N,M,B;
P o[101],v[101];
D T[102];				//T[i]~T[i+1]  p=o[i]+t*v[i]
Pol pol;
D cro(P a,P b){return imag(conj(a)*b);}
D verlen(L l,P p){return cro(l.fs-l.sc,p-l.sc)/abs(l.fs-l.sc);}
bool onL(L l,P p){
	if(abs(l.fs-p)<eps) return true;
	if(abs(l.sc-p)<eps) return true;
	return abs(l.fs-l.sc)>abs(l.fs-p)&&abs(l.fs-l.sc)>abs(l.sc-p);
}
D gett(P p,P v,L l){
	if(abs(cro(l.sc-l.fs,v))<eps) return inf;
	D l0=verlen(l,p),l1=verlen(l,p+v);
	D tt=l0/(l0-l1);
	P pt=p+v*tt;
	if(onL(l,pt)) return tt;
	return inf;
}
int main(){
	while(true){
		cin>>N>>M>>B;
		if(N==0) break;
		pol.clear();
		rep(i,N){
			int x,y;
			cin>>x>>y;
			pol.pb(P(x,y));
		}
		o[0]=P(0,0);
		rep(i,M){
			int vx,vy;
			cin>>T[i+1]>>vx>>vy;
			v[i]=P(vx,vy);
			o[i+1]=o[i]+v[i]*(T[i+1]-T[i]);
		}
		rep(i,M) o[i]-=T[i]*v[i];
		T[M+1]=inf;
		v[M]=P(0,0);
		vector<D> ans;
		rep(b,B){
			D tt,x,len,vx,vy;
			cin>>tt>>x>>vx>>vy>>len;
			P vv=P(vx,vy);
			P oo=P(x,0)-tt*vv;
			D mn=inf;
			rep(i,M+1){
				rep(j,N){
					D it=gett(oo,vv-v[i],L(o[i]+pol[j],o[i]+pol[(j+1)%N]));
					if(T[i]-EPS<it&&it<T[i+1]+EPS) mn=min(mn,it);
					it=gett(oo-vv/abs(vv)*len,vv-v[i],L(o[i]+pol[j],o[i]+pol[(j+1)%N]));
					if(T[i]-EPS<it&&it<T[i+1]+EPS) mn=min(mn,it);
					it=gett(o[i]+pol[j],v[i]-vv,L(oo,oo-vv/abs(vv)*len));
					if(T[i]-EPS<it&&it<T[i+1]+EPS) mn=min(mn,it);
				}
			}
			if(mn<inf) ans.pb(mn);
		}
		sort(all(ans));
		cout<<ans.size()<<endl;
		rep(i,ans.size()) printf("%.8f\n",(double)ans[i]);
	}
}

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

int main(){
	int N; cin>>N;
	vector<int> A(N); rep(i, N) cin>>A[i];
	int64_t s = 0;
	int maxA = 0;
	rep(i, N){
		maxA = max(maxA, A[i]);
		s += maxA - A[i];
	}
	cout<< s <<endl;
}


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

int main()
{
	int N, K;
	string S;
	cin >> N >> K >> S;
	vector<int> sum(N);
	for (int i = 1; i < N; i++) {
		sum[i] = sum[i - 1] + (S[i] != S[i - 1]);
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		int id = -1;
		if (S[i] == '0') {
			id = upper_bound(sum.begin(), sum.end(), sum[i] + K * 2 - 1) - sum.begin();
		}
		else {
			id = upper_bound(sum.begin(), sum.end(), sum[i] + K * 2) - sum.begin();
		}
		res = max(res, id - i);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cctype>

int main(void)
{
	int ch;
	int chCounts[26] = {};
	while ((ch = getchar()) != EOF) {
		if ('a' <= ch && ch <= 'z') {
			chCounts[ch - 'a']++;
		}
		else if ('A' <= ch && ch <= 'Z') {
			chCounts[ch - 'A']++;
		}
	}
	for (int i = 0; i < 26; i++) {
		printf("%c : %d\n", 'a' + i, chCounts[i]);
	}
	return 0;
}

Measured memory_bytes: 2708
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1))

node=[{} for _ in range(n)]
d=deque()
ans=[None]*n
for pair in v:
    node[pair[0]][pair[1]]=pair[2]+1
    node[pair[1]][pair[0]]=pair[2]+1
q,k=map(int,input().split())
d.append(k-1)
res=[-1]*n
res[k-1]=0
while True:
    if not d:
        break
    a=d.pop()
    for x in node[a]:
        if res[x]==-1:
            res[x]=node[a][x]+res[a]
            d.append(x)
for i in range(q):
  x,y=map(int,input().split())
  print(res[x-1]+res[y-1])

Measured memory_bytes: 135752
#include <stdio.h>
const int N=3e2+10;
int n;
double f[N][N][N];
double dp(int a,int b,int c){
  if(a<0||b<0||c<0)return 0;
  if(a==0&&b==0&&c==0)return 0;
  if(f[a][b][c]>=0)return f[a][b][c];
//printf("f[%d][%d][%d]=%lf\n",a,b,c,f[a][b][c]=(double)a/(double)n*dp(a-1,b,c)+(double)b/(double)n*dp(a+1,b-1,c)+(double)c/(double)n*dp(a,b+1,c-1)+(double)n/(double)(a+b+c));
  return f[a][b][c]=(double)a/(double)(a+b+c)*dp(a-1,b,c)+(double)b/(double)(a+b+c)*dp(a+1,b-1,c)+(double)c/(double)(a+b+c)*dp(a,b+1,c-1)+(double)n/(double)(a+b+c);
} 
int main(){
  int a=0,b=0,c=0,temp;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&temp);
	if(temp==1)a++;
    else if(temp==2)b++;
    else if(temp==3)c++;
  }
  for(int i=0;i<=n;i++)for(int j=0;j<=b+c;j++)for(int k=0;k<=c;k++)f[i][j][k]=-1;
  printf("%.20lf\n",dp(a,b,c));
}
  


Measured memory_bytes: 227456
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool is_unbalance(const string& s, int a, int b){
	const int len = b - a + 1;

	char temp[len];
	for (int i = 0; i < len; i++){
		temp[i] = s[i + a];
	}
	sort(temp, temp + len);
	return (temp[len / 2] == temp[0] || temp[(len - 1) / 2] == temp[len - 1]);
}

int main(){
	string s;
	cin >> s;

	if (s.size() < 2){
		cout << "-1 -1" << endl;
		return 0;
	}

	for (int i = 0; i < s.size() - 1; i++){
		if (s[i] == s[i + 1]){
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
	}
	for (int i = 0; i < s.size() - 2; i++){
		if (s[i] == s[i + 2]){
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}

	// for (int a = 0; a < s.size(); a++){
	// 	for (int b = a + 1; b < s.size(); b++){
	// 		if (is_unbalance(s, a, b)){
	// 			cout << a + 1 << " " << b + 1 << endl;
	// 			return 0;
	// 		}
	// 	}
	// }

	cout << "-1 -1" << endl;
	return 0;
}


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

int main() {
	int n, k, x, y;
	cin >> n;
	cin >> k;
	cin >> x;
	cin >> y;
	if (n < k) cout << n * x;
	else cout << x * k + y * (n - k); 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,c,d,a1,b1,c1,d1,i,j;
  while(cin>>a1>>b1>>c1>>d1,a1){
    int t[55][2]={0},q[51][11]={0};
  while(d1--){
    cin>>a>>b>>c>>d;
    if(d){
      q[b][c]++;
    }
    else{
      if(q[b][c])t[b][1]+=20*q[b][c];
      t[b][1]+=a;
      t[b][0]++;
  }
  }
  int w,pre=-9,pr=-2,max,lp=0;
  for(i=1;i<b1+1;i++){
    max=w=-1;
    for(j=b1;j>0;j--){
      if(max<t[j][0]){max=t[j][0];w=j;}
      else if(max==t[j][0]){
	if(t[j][1]<t[w][1]){max=t[j][0];w=j;}
      }
    }
    if(lp){
      if(pre==t[w][0]&&pr==t[w][1])cout<<'='<<w;
      else cout<<','<<w;
    }
    else cout<<w;
    pre=t[w][0];
    pr=t[w][1];
    t[w][0]=-1;
    lp++;
  }
  cout<<endl;
  }
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int K;
    cin >> K;

    vector<ll> a;
    for (int i = 0; i < 10; ++i)
        a.push_back(i);

    int scnt = 1, tcnt = 10;
    while (a.size() <= K) {
        for (int i = scnt; i < tcnt; ++i) {
            int num = a[i] % 10;
            if (num > 0)
                a.push_back(a[i] * 10 + num - 1);
            a.push_back(a[i] * 10 + num);
            if (num < 9)
                a.push_back(a[i] * 10 + num + 1);
        }
        scnt = tcnt;
        tcnt = a.size();
    }

    cout << a[K] << endl;
    return 0;
}


Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).OrderBy(elem => elem).ToArray();
            var table = Enumerable.Range(1, A.Last()).ToDictionary(elem => elem, elem => true);
            foreach (var i in Enumerable.Range(0, N))
            {
                if (table[A[i]] == false)
                {
                    continue;
                }

                for (var j = 2 * A[i]; j <= A.Last(); j += A[i])
                {
                    table[j] = false;
                }
            }

            var answer = new Dictionary<int, int>();
            foreach (var i in Enumerable.Range(0, N))
            {
                if (table[A[i]])
                {
                    if (answer.ContainsKey(A[i]))
                    {
                        answer[A[i]]++;
                    }
                    else
                    {
                        answer[A[i]] = 1;
                    }
                }
            }

            Console.WriteLine(answer.Count(elem => elem.Value == 1));
        }
    }
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll dp[111111][2];

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

	REP(i, 111111)REP(j, 2)dp[i][j] = - LLINF;
	dp[0][0] = 0;

	ll n;cin >> n;
	vector<ll> v(n);REP(i, n)cin >> v[i],dp[0][0] += v[i];

	REP(i, n-1) {
		REP(j, 2){
			ll now = v[i] + v[i+1] - j * 2 * v[i];
			dp[i+1][0] = max(dp[i+1][0], dp[i][j]);
			dp[i+1][1] = max(dp[i+1][1], dp[i][j] - 2 * now);
		}
	}

	cout << max(dp[n-1][0], dp[n-1][1]) << endl;

	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	string s;
  	cin >> s;
  	int q;
  	cin >> q;
  	
  	int hanten = 0;
  	string sentou, matsubi;
  	
  	rep(i,q){
      	int t;
    	cin >> t;
      	if(t==1){
        	hanten ^= 1;
        }
      	else if(t==2){
        	int f; char c;
          	cin >> f >> c;
          	f--;
          	if(hanten ^ f == 0) sentou.push_back(c);
          	else matsubi.push_back(c);
        }
    }
  	
  	if(hanten == 1){
      	reverse(all(matsubi));
      	reverse(all(s));
    	cout << matsubi << s << sentou << endl;
    }
  	else{
      	reverse(all(sentou));
    	cout << sentou << s << matsubi << endl;
    }
  
	return;
}

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

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string S; cin >> S;
  deque<char> deq;
  for (char c : S) { deq.push_back(c); }
  ll Q; cin >> Q;
  ll ord = true;
  for (ll q = 0; q < Q; q++) {
    ll t; cin >> t;
    if (t == 1) {
      ord = !ord;
    }else {
      ll f; cin >> f;
      char c; cin >> c;
      if ((f == 1) == ord) {
	deq.push_front(c);
      }else {
	deq.push_back(c);
      }
    }
  }
  string ans;
  for (char c: deq) { ans += c; }
  if (!ord) {
    reverse(ans.begin(), ans.end());
  }
  cout << ans << endl;

  return 0;
}



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

int R, G, H;
int main()
{
	scanf("%d %d", &R, &G);
    if ((R >= 0) && (G <= 4500))
    {
    	H = 2 * G - R;
		printf("%d", H);
	}
	else
		printf("error");
}


Measured memory_bytes: 128
s = list(input())
n = len(s)

ans = 0
cnt_g = 0
cnt_p = 0
for i in range(n):
    if cnt_p + 1 <= cnt_g:
        cnt_p += 1
        if s[i] == 'g':
            ans += 1
    else:
        cnt_g += 1
        if s[i] == 'p':
            ans -= 1

print(ans)


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int D[57];
    cin >> N;
    D[0]=0;
    REP(i,N){
        cin >> D[i+1];
    }
    int Ans=INF;
    sort(D,D+N+1);
    REP(i,N+1){
        if(i%2==1)D[i]=24-D[i];
        if(D[i]==24)D[i]=0;
        //cout << D[i] << endl;
    }
    REP(i,N+1){
        REP(j,N+1){
            if(i==j)continue;
            int d=abs(D[i]-D[j]);
            Ans=min(Ans,d);
            Ans=min(Ans,24-d);
        }
    }
    cout << Ans << endl;
    return 0;
}



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

bool compare_by_second(pair<ll, ll> a,pair<ll, ll> b)
{
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }    
}

int main()
{
    ll N,M,elm,ans=0;
    cin>>N>>M;

    vector<ll> A(N);
    vector<pair<ll,ll>> p(M);
    for(ll i=0;i<N;i++)
        cin>>A[i];
    for(ll i=0;i<M;i++)
        cin>>p[i].first>>p[i].second;
    sort(p.begin(),p.end(),compare_by_second);
    sort(A.begin(),A.end());
    auto ite=A.begin();
    for(int i=0;i<M;i++)
    {
        auto newite=upper_bound(ite,A.end(),p[i].second);
        elm=int(newite-ite);
        if(elm>=p[i].first)
        {
            ans += p[i].first*p[i].second;
            ite += p[i].first;
        }
        else
        {
            elm = elm>0?elm:0;
            ans += elm*p[i].second;
            ite = newite;
        }
    }
    for(ll i=int(ite-A.begin());i<N;i++)
        ans+=A[i];

    cout << ans <<endl;
}

Measured memory_bytes: 2560
class Node:
    def __init__(self, key, prev=None, next=None):
        self.key = key
        self.prev = prev
        self.next = next


class DoublyLinkedList:
    def __init__(self):
        self.head = None
        self.tail = None

    def insert(self, key):
        node = Node(key)

        if self.head is None:
            self.head = self.tail = node
        else:
            node.next = self.head
            self.head.prev = node
            self.head = node

    def deleteKey(self, key):
        node = self.head

        while node:
            if node.key == key:
                if node.prev is None and node.next is None:
                    self.head = self.tail = None
                else:
                    # prevの処理
                    if node.prev is not None:  # 先頭でないなら
                        node.prev.next = node.next
                    else:  # 先頭なら
                        self.head = self.head.next

                    # nextの処理
                    if node.next is not None:  # 最後でないなら
                        node.next.prev = node.prev
                    else:  # 最後なら
                        self.tail = self.tail.prev
                break
            node = node.next

    def deleteFirst(self):
        if self.head is self.tail:
            self.head = self.tail = None
        else:
            self.head.next.prev = None
            self.head = self.head.next

    def deleteLast(self):
        if self.head is self.tail:
            self.head = self.tail = None
        else:
            self.tail.prev.next = None
            self.tail = self.tail.prev

    def createAnswerList(self):
        ret = []
        node = self.head

        while node:
            ret.append(node.key)
            node = node.next

        return " ".join(ret)


if __name__ == "__main__":
    from sys import stdin

    count = int(input())

    linked_list = DoublyLinkedList()

    for i in range(count):
        order = stdin.readline().strip().split()
        if order[0] == "insert":
            linked_list.insert(order[1])
        elif order[0] == "delete":
            linked_list.deleteKey(order[1])
        elif order[0] == "deleteFirst":
            linked_list.deleteFirst()
        elif order[0] == "deleteLast":
            linked_list.deleteLast()

    print(linked_list.createAnswerList())



Measured memory_bytes: 227800
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



const long long MOD = 100000007;
const int MAX_C = 2000;
long long Com[MAX_C][MAX_C];

void calc_com() {
    memset(Com, 0, sizeof(Com));
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i) {
        Com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j) {
            Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]) % MOD;
        }
    }
}



int r, c, a1, a2, b1, b2;

int main() {
    calc_com();
    
    while (cin >> r >> c >> a1 >> a2 >> b1 >> b2) {
        int fx = 1, fy = 1;
        int x1 = abs(a1 - b1), x2 = r - x1, y1 = abs(a2 - b2), y2 = c - y1;
        if (x1 == x2) ++fx;
        if (y1 == y2) ++fy;
        
        int x = min(x1, x2), y = min(y1, y2);
        
        long long res = (Com[x+y][x] * fx * fy) % MOD;
        cout << res << endl;
    }
    
    return 0;
}


Measured memory_bytes: 32416
import datetime

def main():
    date = datetime.datetime.strptime(input(), '%Y/%m/%d')
    base = datetime.datetime.strptime('2019/04/30', '%Y/%m/%d')
    if date <= base :
        print('Heisei')
    else:
        print('TBD') 

if __name__ == "__main__":
    main()


Measured memory_bytes: 4336
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, D):
    if D[0] != 0:
        return 0
    C = Counter(D)
    if C[0] != 1:
        return 0
    ans = 1
    M = Mod(998244353)
    for i in range(max(D)):
        ans = M.mul(ans, M.pow(C[i], C[i+1]))
    return ans


def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()


Measured memory_bytes: 83104
N = int(input())
a, b = [], []
for i in range(N):
    a.append(list(map(int, input().split())))
for i in range(N):
    b.append(list(map(int, input().split())))
b.sort()
ans = 0
ls = []
for y in b:
    c = []
    for x in a:
        if x[0] < y[0] and x[1] < y[1] and not x in ls:
            c.append(x)
    if len(c) != 0:
        c.sort(reverse=True, key=lambda x: x[1])
        ls.append(c.pop(0))
        ans += 1
print(ans)


Measured memory_bytes: 3064
def factorization(n):
    def sieve(n):
        is_prime = [True for _ in range(n+1)]
        is_prime[0] = False

        for i in range(2, n+1):
            if is_prime[i-1]:
                j = 2 * i
                while j <= n:
                    is_prime[j-1] = False
                    j += i
        table = [ i for i in range(1, n+1) if is_prime[i-1]]
        return table
    arr = []
    temp = n
    for i in sieve(int(n**0.5)):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
cnt=1
n,p= map(int, input().split())
a=factorization(p)
for x in a:
    cnt*=x[0]**(x[1]//n)
print(cnt)

Measured memory_bytes: 13964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	rep(i,m) cin >> a[i] >> b[i];
	vector<int> c;
	vector<int> d;
	rep(i,m){
		if(b[i]==n) c.pb(a[i]);
		if(a[i]==1) d.pb(b[i]);
	}
	if(c.size()==0 || d.size()==0){
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	sort(c.begin(),c.end());
	sort(d.begin(),d.end());
	rep(i,d.size()){
		int l=0,r=c.size()-1;
		if(c[l]==d[i] || c[r]==d[i]){
			cout << "POSSIBLE" << endl;
			return 0;
		}
		while(r-l>1){
			int mid=(r+l)/2;
			if(c[mid]==d[i]){
				cout << "POSSIBLE" << endl;
				return 0;
			}
			else if(c[mid]<d[i]) l=mid;
			else r=mid;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  vector<char> s(n+1);
  for (int i = 1; i <= n; i++) cin >> s[i];
  
  for (int i = a + 1; i < max(c, d); i++) {
    if (s[i] == '#' && s[i+1] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }
  
  if (c < d) {
    cout << "Yes" << endl;
    return 0;
  }
  
  for (int i = b - 1; i <= d - 1 ; i++) {
    if (s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') break;
    if (i == d - 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}

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

#define exec_time() (1.0 * clock()/CLOCKS_PER_SEC)
#define fst first
#define snd second

typedef long long LL;
typedef std::pair<int, int> Pii;

template <typename T> inline bool maximum(T &a, T b) { return a < b? a = b, 1 : 0; }
template <typename T> inline bool minimum(T &a, T b) { return a > b? a = b, 1 : 0; }
template <typename T>
T read(T &x, T f = 0)
{
	char c = getchar(); x = 0;
	for(; !isdigit(c); c = getchar())
		f |= c == '-';
	for(;  isdigit(c); c = getchar())
		x = x*10 + c-'0';
	return x = f? -x : x;
}

const int N = 1e2 + 1;

int A, B;
int d[N + 5][N + 5], f[N + 5][N + 5];

void Init()
{
	read(A), read(B);
	for(int x = 1; x <= A; ++x)
		for(int y = 1; y <= B; ++y) read(d[x][y]);

	return ;
}

bool check()
{
	for(int x = 1; x <= A; ++x)
		for(int y = 1; y <= B; ++y){
			int dist = ~0U >> 1;

			for(int a = 0; a < N; ++a)
				for(int b = 0; b < N; ++b)
					minimum(dist, f[a][b] + x*a + y*b);

			if(dist != d[x][y]) return false;
		}
	return true;
}

void Exec()
{
	for(int x = 1; x <= A; ++x)
		for(int y = 1; y <= B; ++y)
			for(int a = 0; a < N; ++a)
				for(int b = 0; b < N; ++b)
					maximum(f[a][b], d[x][y] - x*a - y*b);
	if(!check()) puts("Impossible");
	else
	{
		puts("Possible");
		printf("%d %d\n", N*2, 2*(N-1) + N*N);
		for(int i = 1; i < N; ++i){
			printf("%d %d X\n", i, i + 1);
			printf("%d %d Y\n", i + N + 1, i + N);
		}
		for(int a = 0; a < N; ++a)
			for(int b = 0; b < N; ++b)
				printf("%d %d %d\n", a + 1, N + b + 1, f[a][b]);
		printf("%d %d\n", 1, N + 1);
	}

	return ;
}

int main()
{
	Init();
	Exec();

	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

const ll INF=1e10+100;

int main()
{
    ll n;
    cin >> n;
    vector<ll> s;
    ll sum_ten=0;
    ll sum_other=0;
    rep(i,n){
        ll x;
        cin >> x;
        if(x%10==0){
            sum_ten+=x;
        }
        else{
            s.push_back(x);
            sum_other+=x;
        }
    }
    if(s.size()==0){
        cout << 0 << endl;
        return 0;
    }
    
    sort(s.begin(),s.end());
    if(sum_other%10==0){
        cout << sum_other+sum_ten-s[0] << endl;
    }
    else{
        cout << sum_other+sum_ten << endl;
    }
    
    return 0;
} 

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

int gates[9];
int jackey[9];

int win() {
    int a=0,b=0;
    for(int i=0; i<9; ++i) {
        if(gates[i] > jackey[i]) a += gates[i]+jackey[i];
        else b += gates[i]+jackey[i];
    }
    return a-b;
}

int main() {
    int n;
    cin>>n;
    while(n--) {
        for(int i=0; i<9; ++i) cin>>gates[i];
        for(int i=0; i<9; ++i) cin>>jackey[i];

        sort(jackey, jackey+9);
        int tot = 0,wins = 0,drow = 0;
        do {
            tot++;
            int a = win();
            if(a == 0) drow++;
            else if(a > 0) wins++;
        }while(next_permutation(jackey, jackey+9));

        double p = (double)wins/tot;
        double p2 = (double)(tot-drow-wins)/tot;
        cout<<p<<" "<<p2<<endl;
    }
}

Measured memory_bytes: 924
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    int N, X;
    cin >> N >> X;
    vl A(N);
    rep(i, N) {
        cin >> A[i];
    }
    vl sum(N - 1);
    rep(i, N - 1) {
        sum[i] = A[i] + A[i + 1];
    }

    ll cnt = 0;
    rep(i, N - 1) {
        if (sum[i] > X) {
            sum[i + 1] -= min(sum[i] - X, A[i + 1]);
            cnt += sum[i] - X;
            // cout << "i: " << i << ", sum[i]: " << sum[i] << ", a: " << a << endl;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 4844
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ct = 0;
		while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
			int tmpa = a;
			int tmpb = b;
			int tmpc = c;
			a = tmpb / 2 + tmpc / 2;
			b = tmpa / 2 + tmpc / 2;
			c = tmpa / 2 + tmpb / 2;
			ct++;
			if( a == b && b == c && a == c){
				ct = -1;
				break;
			}
		}
		System.out.println(ct);
	}
}

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

int main()
{
  int n;
  cin >> n;
  vector<string> w(n);
  int i, j;
  bool ok = true;
  for(i = 0; i < n; i++)
  {
    cin >> w.at(i);
    for(j = 0; j < i; j++)
    {
      if(w.at(j) == w.at(i))
      {
        ok = false;
        break;
      }
    }
    if(i > 0)
    {
      if(w.at(i-1).at(w.at(i-1).length()-1) != w.at(i).at(0))
      {
        ok = false;
      }
    }
    if(!ok) break;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
  int n,m;
  int d[300][4];
  int dp[3][301];
  string tmp;

  while(cin >> n >> m){
    for(int i=0;i<n;i++){
      cin.ignore();
      getline(cin,tmp);
      for(int j=0;j<4;j++)cin >> d[i][j];
    }

    

    for(int i=0;i<3;i++){
      for(int j=0;j<=m;j++)dp[i][j] = 0;
    }

    for(int i=0;i<n;i++){
      for(int j=0;j<3;j++){
	dp[j][d[i][0]] = max(dp[j][d[i][0]],d[i][j+1]);
      }
    }

    for(int i=0;i<3;i++){
      for(int j=1;j<=m;j++){
	for(int k=0;k<=j;k++){
	  dp[i][j] = max(dp[i][j],dp[i][k]+dp[i][j-k]);
	}
      }
    }

    int ans = 0;
    for(int i=0;i<3;i++)ans = max(ans,dp[i][m]);
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int g[10][10];

int main() {
  int h, w;
  cin >> h >> w;

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> g[i][j];
    }
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int t;
      cin >> t;
      if (t != -1) {
        ans += g[t][1];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  vector<int> P = {2, 3, 5};
  for (int n = 7; n <= N; n += 2)
  {
    bool ok = true;
    for (int i = 0; i < P.size(); i++)
    {
      int p = P.at(i);
      if (n % p == 0)
      {
        ok = false;
        break;
      }
      if (p * p > n) break;
    }
    if (ok) P.push_back(n);
  }

  vector<int> PP(P.size(), 0);
  for (int n0 = 2; n0 <= N; n0++)
  {
    int n = n0;
    for (int i = 0; i < P.size(); i++)
    {
      int p = P.at(i);
      while (n % p == 0)
      {
        n /= p;
        PP.at(i)++;
      }
    }
  }
  
  int ans = 1;
  for (int i = 0; i < P.size(); i++)
  {
    ans *= PP.at(i) + 1;
    ans %= MOD;
  }
  
  cout << ans << endl;
}

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

using namespace std;

/**/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/**/

const int MAXN = 100005;

char s[MAXN];
int  v[MAXN];

int main () {

	scanf("%s", s);
	int n  = strlen (s);

	int j = 0;

	for (int i = 0; i < n; i = j) {
		int p = i;
		
		while (s[i] == 'R') ++i;
		
		j = i;
		
		while (s[j] == 'L') ++j;

		int L = i - p;
		int R = j - i;

		v[i] = (R + 1) / 2 + L / 2;
		v[i - 1] = (L + 1) / 2 + R / 2;

	}

	for (int i = 0; i < n; ++i)
		printf("%d%c", v[i], " \n"[i == n - 1]);
	

	return 0;
}



Measured memory_bytes: 896
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
N, K = map(int, input().split(' '))
sunuke = []
for i in range(K):
    d = input()
    sunuke.extend(input().split(' '))


sunuke = set(sunuke)
print(N-len(sunuke))


Measured memory_bytes: 9740
/* 
  ╔╗         ╔╗              ╔═══╗                                  
  ║║        ╔╝╚╗             ║╔═╗║                                  
  ║║╔╗╔╗╔══╗╚╗╔╝    ╔══╗     ║╚═╝║╔═╗╔══╗╔══╗╔═╗╔══╗ ╔╗╔╗╔╗╔╗╔══╗╔═╗
╔╗║║║║║║║══╣ ║║     ╚ ╗║     ║╔══╝║╔╝║╔╗║║╔╗║║╔╝╚ ╗║ ║╚╝║║╚╝║║╔╗║║╔╝
║╚╝║║╚╝║╠══║ ║╚╗    ║╚╝╚╗    ║║   ║║ ║╚╝║║╚╝║║║ ║╚╝╚╗║║║║║║║║║║═╣║║ 
╚══╝╚══╝╚══╝ ╚═╝    ╚═══╝    ╚╝   ╚╝ ╚══╝╚═╗║╚╝ ╚═══╝╚╩╩╝╚╩╩╝╚══╝╚╝ 
                                         ╔═╝║                       
                                         ╚══╝                       */


//Header files
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#ifndef ONLINE_JUDGE
#include<Personal/debug.h>
#else
#define debug(x...)
#endif

//Short data-types declaration
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<vector<int> > vii;  
typedef vector<vector<long long> >vll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vbb;

//Macros
#define MK make_pair
#define EB emplace_back
#define PB push_back
#define F first
#define S second
#define rep(i,start,end) for(int i=(int)start;i<(int)end;i++)
#define repr(i,start,end) for(int i=(int)start;i>(int)end;i--)
#define all(x) (x).begin(), (x).end()

//Constants
const int mod = 1e9+7;

//Some useful functions
ll binpow(ll num,ll pow);
inline int mul(int a,int b) {return (a*1ll*b)%mod;}
inline int add(int a,int b) {return (a+0ll+b)%mod;}
inline int sub(int a,int b) {return ((a+0ll-b)%mod+mod)%mod; }
/*------------------------------------------------------Code Starts------------------------------------------------------*/
inline void solve()
{
	int n;
	cin>>n;
	cout<<(1000-n%1000)%1000<<'\n';
}

int main()
{
	auto start = high_resolution_clock::now();
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start); 
	cerr<<duration.count()<<" microseconds\n";
	return 0;
}
/*------------------------------------------------------Code ends------------------------------------------------------*/
ll binpow(ll num,ll pow)
{
	if(pow==0)
		return 1;
	ll val=binpow(num,pow/2);
	val*=val;
	if(pow&1) val*=num;
	return val;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int calc(int n){
	int sum = 0;
	while(n){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

signed main(){
	int n,mi = INF;
	cin >> n;
	for(int i = 1;i <= n - 1;i++){
		chmin(mi,calc(i) + calc(n - i));
	}
	cout << mi << endl;
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
const int M = 10010;
vector<int> p(M),r(M);

int findSet(int a) {
  if(a != p[a]) {
    p[a] = findSet(p[a]);
  }
  return p[a];
}
bool same(int a,int b) {
  return findSet(a) == findSet(b);
}

void link(int a,int b) {
  if(r[a] < r[b]) {
    p[a] = b;
  }else {
    p[b] = a;
    if(r[a] == r[b]) r[a]++;
  }
}

void unite(int a,int b) {
  link(findSet(a),findSet(b));
}

int main() {
  
  int n,q;
  cin >> n >> q;

  for(int i = 0;i < M;i++) {
    p.at(i) = i;
    r.at(i) = 0;
  }

  for(int i = 0;i < q;i++) {
    int com,x,y;
    cin >> com >> x >> y;
    if(com == 0) {
      unite(x,y);
    }else {
      if(same(x,y)) cout << 1 << endl;
      else cout << 0 << endl;
    }
  }

  
}





Measured memory_bytes: 3188
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define int long long
#define ll long long
#define str string
#define db double
#define ac() cout<<"Yes"<<endl;
#define wa() cout<<"No"<<endl;
#define ddd cout<<"---debug---"<<endl;
#define ff(a,b) for(signed long long (a)=1;(a)<=(b);(a)++)
#define fff(a,b) for(signed long long (a)=0;(a)<(b);(a)++)
#define re readdd()
#define pr(a) printtt(a)
#define pee puts("");
#define eee putchar(' ');
#define pss(a) push_back(a)
#define ps(a) push(a)
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;
if(x>=10)printtt(x/10);putchar(x%10+'0');}
bool addd(int a,int b){return a>b;};
//
const int maxm=2e5+5;
int a[maxm];
int cnt[maxm];
signed main(){
    int n=re;
    ff(i,n)a[i]=re,cnt[a[i]]++;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(cnt[i]>=2){
            ans+=cnt[i]*(cnt[i]-1)/2;
        }
    }
//    pr(ans);pee;
    for(int i=1;i<=n;i++){
        int t=ans-(cnt[a[i]]-1);
        pr(t);pee;
    }
    return 0;
}


Measured memory_bytes: 4736
'use strict'

function solve(N, A) {
  var dp = new Array(N+1).fill(0).map(e => new Array(N+1).fill(0))
  var row = 1
  var col = 1
  while (col <= N) {
    var c = col
    for (var r = row; r <= N; r++) {
      if (c > N) {
        break
      }
      if (c === r) {
        dp[r][c] = A[r-1]
      } else if (c === (r+1)) {
        dp[r][c] = Math.max(A[r-1], A[c-1])
      } else {
        dp[r][c] = Math.max(A[r-1] + Math.min(dp[r+1][c-1], dp[r+2][c]), A[c-1] + Math.min(dp[r+1][c-1], dp[r][c-2]))
      }
      c++
    }
    col++
  }
  var taro = dp[1][N]
  var sum = A.reduce((acc, current) => acc + current)
  return taro - (sum - taro)
}

function main(input) {
  var lines = input.split("\n")
  var N = parseInt(lines[0])
  var A = lines[1].split(' ').map(l => parseInt(l))
  var ans = solve(N, A)
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 181284