akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

int main() {
    ll N;
    ll A, B;
    ll total = 0;
    string ans = "Yes";
    cin >> N;

    vector<pair<ll, ll>> pairs(N);

    for (ll i = 0; i < N; i++) {
        cin >> A >> B;
        pairs[i] = make_pair(B, A);
    }

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

    for (ll i = 0; i < N; i++) {
        total += pairs[i].second;
        if (total > pairs[i].first) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

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

// 桁数を数える
int countDigit(int n){
    int ans = 1;
    while(n / 10 != 0){
        n /= 10;
        ans++;
    }

    return ans;
}

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

    int ans = 0;
    for(int i = 1; i <= n; ++i){
        if(countDigit(i) % 2 != 0){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h> 
 #include <ctype.h> 
 
 
 int main(){ 
     char ch; 
     while(1){ 
         scanf("%c", &ch); 
         if(ch=='\n'){ 
             printf("\n"); 
             break; 
         }else if(islower(ch)){ 
             printf("%c", toupper(ch)); 
         }else if(isupper(ch)){ 
             printf("%c", tolower(ch)); 
         }else{ 
             printf("%c", ch); 
         } 
     } 
 
     return 0; 
 } 



Measured memory_bytes: 2068
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define endl "\n"
#define mt make_tuple
#define mp make_pair

template <typename T1, typename T2>
bool umax(T1 &a, const T2&b) { return a < b ? a = b, 1 : 0;}
template <typename T1, typename T2> 
bool umin(T1 &a, const T2 &b) {return a > b ? a = b, 1 : 0;}
template <typename T>
T sqr(T a) {return a * a;}
const int mod = 1000000007;
template <typename T1, typename T2>
void modadd(T1 &a, const T2 &b) {
    a += b;

    if (a >= mod)
        a -= mod;
}

mt19937 rng(20010709);
const int INF = 1000000001;
const int N = 1 << 21;

int n, a[22][22], dp[N], bit[22];
vector <int> e[22], mask[22];
vector <pii> cur;

ll get(int l, int r);

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

    cin >> n;

    for (int i = 0; i < n; i++)
        bit[i] = 1 << i;

    dp[0] = 1;

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

            if (a[i][j])
                e[i].push_back(j);
        }

        for (int mask = (1 << n) - 1; mask > -1; mask--) {
            if (!dp[mask]) continue;

            for (auto jt : e[i]) {
                if (!((mask >> jt) & 1))
                    modadd(dp[mask | bit[jt]], dp[mask]);
            }

            dp[mask] = 0;
        }
    }

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

    return 0;
}

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

using namespace std;

#define endl '\n'

vector<int> adjList[100002];
vector<int> dist(100002, -1);

int dfs(int s) {
  int deep = 0;
  for (int i = 0; i < (int)adjList[s].size(); i++) {
    int next = adjList[s][i];
    if (dist[next] == -1) deep = max(deep, dfs(next) + 1);
    else deep = max(deep, dist[next] + 1);
  }
  return dist[s] = deep;
}

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

  int n, m, u, v;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    adjList[u].push_back(v);
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    if (dist[i] == -1) ans = max(ans, dfs(i));
  }
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 11060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
ll a,b;

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

  cin >> a >> b;
  ll _a = 0,_b=0;
  rep(i, b) _a = 10*_a+a;
  rep(j, a) _b = 10*_b+b;

  ll ans = a>b?_b:_a;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

    int res = 0;
    int tmp = 1;
    while (true) {
        if (N < tmp) {
            break;
        }
        tmp *= K;
        res++;
    }

    cout << res;
}


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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
const int N = 1e5;

int n, m, s, t;

vector<int> conn[N];
int dist[N], ans = -1;
set<int> loc[N];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		conn[b].push_back(a);
	}
	cin >> s >> t;
	--s, --t;
	queue<int> q;
	q.push(t);
	
	
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		
		queue<pair<int, int>> tq;
		tq.push({cur, 0});
		while (!tq.empty()) {
			pair<int, int> v = tq.front();
			tq.pop();
			if (v.second == 3) {
				if (!dist[v.first] && v.first != t) {
					dist[v.first] = dist[cur] + 1;
					q.push(v.first);
					if (v.first == s) {
						tq = {};
						q = {};
						break;
					}
				}
			} else {
				for (int u : conn[v.first]) {
					if (loc[u].insert(v.second + 1).second) tq.push({u, v.second + 1});
				}
			}
		}
	}
	
	dist[s] ? cout << dist[s] : cout << -1;
}


Measured memory_bytes: 28268
#include <stdio.h>

int main(){
  int d,i,j,k,l,m,n,x[200],y[200],xmax,xmin,ymax,ymin;
  int xm[4]={-1,0,1,0},ym[4]={0,1,0,-1};

  x[0]=0;y[0]=0;
  while(scanf("%d\n",&n),n!=0){
    xmax=0;xmin=0;ymax=0;ymin=0;
    for(i=1;i<n;i++){
      scanf("%d %d\n",&m,&d);
      x[i]=x[m]+xm[d];
      y[i]=y[m]+ym[d];
      if(x[i]>xmax) xmax=x[i];
      if(x[i]<xmin) xmin=x[i];
      if(y[i]>ymax) ymax=y[i];
      if(y[i]<ymin) ymin=y[i];
    }
    printf("%d %d\n",xmax-xmin+1,ymax-ymin+1);
  }
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
#include <math.h>

using namespace std;
typedef long long ll;
///定義場所///
int i, j, k, l, m, n;
int N, M, K, H, W;
ll MOD = 1000000007;
int ans = 0;
//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<int ,int> firstElof, pair<int,int> secondElof)
{
	return firstElof.second > secondElof.second;
}
int Keta(ll F) {
	int keta = 1;
	while (F/10 > 0) {
		keta++;
		F /= 10;
	}
	return keta;
}
//////////////

int main()
{
	int X, A;
	cin >> X >> A;
	if (X < A) {
		cout << 0;
	}
	else {
		cout << 10;
	}
}

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

int main() {
    ll x;
    cin >> x;
    ll money = 100;
    int count = 0;
    while (money < x) {
        money *= 1.01;
        count++;
    }
    printf("%d\n",count);
    return 0;
}

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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) int(pow(x,y))
const long long mod = 1000000007;

int main() {
    long long int N, K;
    cin >> N >> K;
    vector<long long int> original (N);
    long long int plus = 0;
    long long int minus = 0;
    for(long long int i = 0;i < N;i++){
        cin >> original.at(i);
        if(original.at(i) < 0){
            minus++;
        }
        else{
            plus++;
        }
    }
//    cout << "CIN is end" << endl;
    vector<long long int> vec1 (plus+1,0);
    vector<long long int> vec2 (minus+1,0);
    long long int a = 1;
    long long int b = 0;
    vec1.at(0) = 0;
    for(long long int i = 0;i < N;i++){
//        cout << i << "/" << N << endl;
        if(original.at(i) < 0){
            vec2.at(b) = abs(original.at(i));
            b++;
        }
        else{
            vec1.at(a) = original.at(i);
            a++;
        }
    }
    REV(vec2);
//    cout << "PLUS is end" << endl;
/*
    cout << "PREVIEW" << endl;
    for(long long int i = 0;i < vec1.size();i++){
        cout << vec1.at(i) << endl;
    }
    cout << "-----------" << endl;
    for(long long int i = 0;i < vec2.size();i++){
        cout << vec2.at(i) << endl;
    }
    cout << "PLUS = " << plus << " , MINUS = " << minus << endl;
    cout << "PREVIEW is end" << endl;
*/
    long long int answer = 9999999999;
    for(long long int i = 0;i <= K;i++){
        if(K-i <= minus && i <= plus){
//            cout << K-i << "~" << i << endl;
//            cout << vec1.at(i)*2+vec2.at(K-i) << endl;
//            cout << vec1.at(i)+vec2.at(K-i)*2 << endl;
            answer = min(answer,min(vec1.at(i)*2+vec2.at(K-i),vec1.at(i)+vec2.at(K-i)*2));
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 1792
s = input()
n = len(s)
forward = [0]*(n+1)
backward = [0]*(n+1)
for i in range(n):
    if s[i] == "<":
        forward[i+1] = forward[i] + 1

for i in range(n-1,-1,-1):
    if s[i] == ">":
        backward[i] = backward[i+1] + 1


ans = sum([max(x,y) for x,y in zip(forward,backward)])
print(ans)

Measured memory_bytes: 86092
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  ll s;
  while (cin >> s) {
    set<ll> S;
    S.insert(s);
    ll a = s;
    for (int i = 2;; i++) {
      if (a % 2 == 0) {
        a = a / 2;
      } else {
        a = 3 * a + 1;
      }
      if (S.count(a)) {
        cout << i << endl;
        break;
      }
      S.insert(a);
    }
  }
  return 0;
}


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

typedef unsigned long long ll;

ll md = 1000000007;

int main(int, char**) 
{
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a.begin(), a.end());

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

	return 0;
}


Measured memory_bytes: 3200
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readLong()
    var i = 1
    var ans = Long.MAX_VALUE
    while (i <= Math.sqrt(n.toDouble()) + 1) {
        val tmp = n / i
        if (tmp * i == n) {
            ans = Math.min(ans, i + tmp - 2)
        }

        i++
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;

    bool ok = false;
    repl(i, 1, b + 1) {
        if ((a * i) % b == c) {
            ok = true;
            break;
        }
    }
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
-- 時刻の差分 >= xの差 + yの差 AND 時刻の差分 と xの差 + yの差の遇機が一致

analyze :: [(Integer, Integer, Integer)] -> (Integer, Integer, Integer) -> Bool
analyze [] _ = True
analyze ((time, x, y):rem) (prtime, prx, pry) =
  (time - prtime >= dx + dy &&
    (time - prtime) `mod` 2 == (dx + dy) `mod` 2) &&
    analyze rem (time, x, y)
  where dx = abs $ x - prx; dy = abs $ y - pry
  
main = do
  [a, b, c] <- (map read . words <$> getLine :: IO [Integer])
  let r = c - a - b
  let res = (r * r > a * b * 4) && (r >= 0)
  putStrLn $ if res then "Yes" else "No"
  

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

typedef long long int ll;
typedef long double ld;

using namespace std;


int main()
{
    ld x,ans, pi = 3.141592653589793239;
    cin>>x;
    ans= 2*pi*x;
    cout<<ans<<endl;

    //cout<<"Case "<<cn<<": "<<"good"<<endl;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}



int main()
{
    fast;
    ll t;
    //~ cin>>t;
    t=1;
    while(t--){
			ll n,a;
			cin>>n>>a;
			cout<<ceil((1.0*n)/a);
    }
    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify

obj = input().strip().split(' ')
N, M = map(int, obj)

obj = input().strip().split(' ')
val_list = [-1 * item for item in list(map(int, obj))]

heapify(val_list)

for _ in range(M):
    val = (-1) * ((heappop(val_list) * (-1)) // 2)
    heappush(val_list, val)

print(-1 * sum(val_list))


Measured memory_bytes: 73128
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }

  vector<ll> b(n, 0), c(n, 0);
  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      if (a[i] > a[j])
        b[i]++;
    }
  }
  for (int i = 0; i < n; i++){
    for (int j = i; j < n; j++){
      if (a[i] > a[j])
        c[i]++;
    }
  }
  ll ans = 0;
  for (int i = 0; i < n; i++){
    ans = (ans + c[i] * k % MOD + b[i] * (k * (k - 1) / 2 % MOD) % MOD) % MOD;
  }
  cout << ans << endl;
  
  

  

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;

int ans;
int n,c[11111];
vector<vector<int>> v(11111);
int j=0;
int p[11111],f[11111];
void dfs(int i){
    f[i]=1;
    p[i]=c[j];
    j++;
    for(auto x:v[i]){
        if(!f[x])dfs(x);
    }
}


signed main(){

    
    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }
    rep(i,n){
        cin>>c[i];
    }
    sort(c,c+n,greater<>());
    dfs(0);
    rep(i,n)if(i>0)ans+=c[i];
    cout<<ans<<endl;
    rep(i,n)cout<<p[i]<<" ";
    cout<<endl;

}


Measured memory_bytes: 1408
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M, K = [int(x) for x in input().split()]

    for i in range(N + 1):
        for j in range(M + 1):
            if M * i + (N - i) * j - i * j == K:
                print("Yes")
                return

    print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 9116
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 5;
int lst[Max];
int ls[Max];
ll sum1[Max], sum2[Max];

int main()
{
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> lst[i];
		sum1[i] = sum1[i - 1] + lst[i];
	}
	for (int i = 1;i <= n;i++)
	{
		cin >> lst[i];
		sum2[i] = sum2[i - 1] + lst[i];
	}
	ll ans = 0;
	for (int i = 1;i <= n;i++)
	{
		ans = max(ans, sum1[i] + sum2[n] - sum2[i - 1]);
	}
	cout << ans;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


const int MOD = 1e+9 + 7;
// dp[i][j][k]: i桁目まで決まってi桁目がjのときに余りがkとなる場合の数
long long dp[100001][10][13] = {};

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

    int N = S.size();

    // initialization
    if(S[N-1] == '?'){
        for(int i = 0; i < 10; ++i) dp[0][i][i] = 1;
    }else{
        int num = S[N-1]-'0';
        dp[0][num][num] = 1;
    }

    long long tmp = 1;
    for(int i = 1; i < N; ++i){
        tmp = (10*tmp) % 13;
        if(S[N-1-i] == '?'){
            for(int j = 0; j < 10; ++j){
                int r = j*tmp % 13;
                for(int k = 0; k < 13; ++k){
                    for(int l = 0; l < 10; ++l){
                        if(k-r < 0) dp[i][j][k] += dp[i-1][l][13+k-r] % MOD;
                        else dp[i][j][k] += dp[i-1][l][k-r] % MOD;
                        dp[i][j][k] %= MOD;
                    }
                }
            }
        }else{
            int num = S[N-1-i]-'0';
            int r = num*tmp % 13;
            for(int k = 0; k < 13; ++k){
                for(int l = 0; l < 10; ++l){
                    if(k-r < 0) dp[i][num][k] += dp[i-1][l][13+k-r] % MOD;
                    else dp[i][num][k] += dp[i-1][l][k-r] % MOD;
                    dp[i][num][k] %= MOD;
                }
            }
        }
    }
    long long ans = 0;
    for(int j = 0; j < 10; ++j) ans += dp[N-1][j][5] % MOD;
    cout << ans%MOD << endl;
    
    return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  
  for (int i=0;i<N;i++) {
    string S;
    cin >> S;
    if(S == "Y") {
      cout << "Four"<< endl;
      break;
    }
    else if(i == N-1) {
      cout << "Three" << endl;
      break;
    }
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
template<class T> inline void read(T &x){
	x=0; register char c=getchar(); register bool f=0;
	while(!isdigit(c))f^=c=='-',c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar(); if(f)x=-x;
}
template<class T> inline void print(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)print(x/10); putchar(x%10+'0');
}
template<class T> inline void print(T x,char c){print(x),putchar(c);}

const int N=1e5+10,M=400,mod=998244353;
int n,lim,max,m[3],sg[N];
std::vector<int> G[3][N];

struct z {
	int x;
	z(int x=0):x(x){}
	friend inline z operator*(z a,z b){return (long long)a.x*b.x%mod;}
	friend inline z operator-(z a,z b){return (a.x-=b.x)<0?a.x+mod:a.x;}
	friend inline z operator+(z a,z b){return (a.x+=b.x)>=mod?a.x-mod:a.x;}
}ans,pw[N],f[3][N],g[N];
inline z fpow(z a,int b){z s=1;for(;b;b>>=1,a=a*a)if(b&1)s=s*a;return s;}

void SG(int m,std::vector<int> G[N],int sg[N]){
	static bool vis[N];
	for(int i=n;i>=1;i--){
		for(int j:G[i])vis[sg[j]]=1;
		sg[i]=0;
		while(vis[sg[i]])sg[i]++;
		for(int j:G[i])vis[sg[j]]=0;
	}
}

void fwt(z *a){
	for(int len=1;len<lim;len<<=1)
		for(int i=0;i<lim;i+=(len<<1))
			for(int j=0;j<len;j++){
				z x=a[i+j],y=a[i+j+len];
				a[i+j]=x+y,a[i+j+len]=x-y;
			}
}

int main(){
#ifdef memset0
	freopen("1.in","r",stdin);
#endif
	read(n),lim=sqrt(n);
	for(int i=0;i<3;i++){
		read(m[i]);
		for(int u,v,j=1;j<=m[i];j++){
			read(u),read(v);
			// G[i][u].push_back(v);
			G[i][std::min(u,v)].push_back(std::max(u,v));
			// G[i][std::max(u,v)].push_back(std::min(u,v));
		}
	}
	pw[0]=1,pw[1]=fpow(10,18);
	for(int i=2;i<=n;i++)pw[i]=pw[i-1]*pw[1];
	for(int i=0;i<3;i++){
		SG(m[i],G[i],sg);
		for(int j=1;j<=n;j++){
			max=std::max(max,sg[j]);
			f[i][sg[j]]=f[i][sg[j]]+pw[j];
		}
		// for(int j=1;j<=n;j++){
		// 	printf("%d%c",sg[j]," \n"[j==n]);
		// }
	}
	lim=1; while(lim<=max)lim<<=1;
	// for(int i=0;i<lim;i++)
	// 	for(int j=0;j<lim;j++)
	// 		for(int k=0;k<lim;k++){
	// 			g[i^j^k]=g[i^j^k]+f[0][i]*f[1][j]*f[2][k];
	// 			// if(f[0][i].x&&f[1][j].x&&f[2][k].x){
	// 			// 	printf("%d %d %d : %d\n",i,j,k,f[0][i]*f[1][j]*f[2][k]);
	// 			// }
	// 		}
	for(int i=0;i<3;i++)fwt(f[i]);
	for(int i=0;i<lim;i++)g[i]=f[0][i]*f[1][i]*f[2][i];
	fwt(g);
	z invlim=fpow(lim,mod-2);
	for(int i=0;i<lim;i++)g[i]=g[i]*invlim;
	// for(int i=0;i<lim;i++){
	// 	printf("%d : %d\n",i,g[i]);
	// }
	printf("%d\n",g[0]);
}

Measured memory_bytes: 14976
[<EntryPoint>]
let main argv =
    let input = stdin.ReadLine().Split(' ') |> Array.map int64
    let h = input.[0]
    let w = input.[1]
    let count =
        if  h = 1L || w = 1L then 1L
        else (h * w + 1L) / 2L
    count |> printfn "%d"
    0


Measured memory_bytes: 11996
#include <bits/stdc++.h>
#define MAX 100001
using namespace std;

typedef pair<double,double> P;
const int INF=1000000000;
int n;
P v[MAX];
 
bool compare_y(P a, P b) {
  return a.second < b.second;
}
 
double closest_pair(P *a, int n) {
  if(n<=1) return INF;
  int m=n/2;
  double x=a[m].first;
  double d=min(closest_pair(a,m),closest_pair(a+m,n-m));
  inplace_merge(a,a+m,a+n,compare_y);
  vector<P> b;
  for(int i=0; i<n; i++) {
    if(fabs(a[i].first-x)>=d) continue;
    for(int j=0; j<b.size(); j++) {
      double dx=a[i].first-b[b.size()-1-j].first;
      double dy=a[i].second-b[b.size()-1-j].second;
      if(dy>=d) break;
      d=min(d, sqrt(dx*dx+dy*dy));
    }
    b.push_back(a[i]);
  }
  return d;
}

int main() {
  cin >> n;
  for(int i=0; i<n; i++) {
    double x,y;
    cin >> x >> y;
    v[i]=P(x,y);
  }
  sort(v,v+n);
  double ans=closest_pair(v,n);
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 6040
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	int n=inputValue();
	vector<int> h;
	inputVector(&h,n);
	int judge=1;

	repd(i,1,n){
		rep(j,i){
			if(h[i]<h[j]){
				break;
			}
			if(j==i-1){
				judge++;
			}
		}
	}

	cout << judge << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    ll d = b - a;
    if (d % 2 == 0) {
        cout << d / 2LL << endl;
    } else {
        cout << min(a, n - b + 1LL) + (d - 1LL) / 2LL << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
	int n,y,b,t,r,i,j,ans;
	float kotae,max,pas;
	while(1){
		cin>>n;
		if(n==0)break;
		cin>>y;
		max=0.0;
		ans=0;
		for(i=0;i<n;i++){
			cin>>b>>r>>t;
			pas=(float)r/100.0;
			if(t==1){
				kotae=1.0+(float)y*pas;
			if(kotae>max){
				max=kotae;
				ans=b;
			}
			}
			else{
				kotae=(float)(pow((float)(1.0+(float)r/100),y));
			if(kotae>max){
				max=kotae;
				ans=b;
			}
			}
		}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3404
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	long mod = 1_000_000_000 + 7;
	void run() {
		int n = sc.nextInt();
		int x =  sc.nextInt();
		
		int s[] = new int[n];
		for(int i =0 ; i < n;i++) {
			s[i] = sc.nextInt();
		}
		
		Arrays.sort(s);
		
		long res = rec(s,n-1,x);
		System.out.println(res);
	}
	Map<String,Long> memo = new HashMap<String,Long>();
	
	long rec(int[] s, int t, int now){
		if(now ==0 ) {
			return 0;
		}
		String key = t+"_"+now;
		if(memo.containsKey(key)) {
			return memo.get(key);
		}
		if(t == -1) {
			return now;
		}
		long res = 0 ;
		
		if(s[t] <= now) {
			res += rec(s, t-1, now % s[t]) % mod;
			res += rec(s, t-1, now) * t%mod;
		}else {
			res += rec(s, t-1, now) * (t+1)%mod;
		}
		
		res = res%mod;
		memo.put(key,res);
		return res ;
	}
	
}

Measured memory_bytes: 194476
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};

ll xorr(ll x){
  	if(x <= 0) return 0;
    ll k = x / 2;
    if(x % 2 != 0) k++;
    if(k % 2 == 0){
        if(x % 2 == 0) return x;
        else return 0;
    }else{
        if(x % 2 == 0) return x + 1;
        else return 1;
    }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
    ll a,b; cin >> a >> b;
    ll ans = xorr(a-1) ^ xorr(b);
  //cout << xorr(a-1) << " " << xorr(b) << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e3+20;

int main()
{
	ll a,b,c;
	while(cin>>a>>b>>c)
	{
		ll x,y,z,cnt=0;	
		if(a==b&&b==c&&a%2==0)
		{
			puts("-1");
			continue;
		}
		while(true)
		{
			if(a%2||b%2||c%2)
				break;
			
			x=a/2,y=b/2,z=c/2;
			a=y+z,b=x+z,c=x+y;
			cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
k, n = map(float, input().split())
m = list(map(float, input().split()))
half_k = k / 2
min = float(1000000)
for i in range(int(n)):
    first = m[i]
    last = m[i-1]
    len = last - first
    if len < 0:
        len = len + k
    if min > len:
        min = len
print(int(min))

Measured memory_bytes: 24780
#include<iostream>
#include<algorithm>
using namespace std;
int n,q,r,x[100010];
int d[17][100010];
int Pow2[20];
void PRE(){
	int k=1;
	for(int i=0;i<20;i++){
		Pow2[i]=k;
		k*=2;
	}
	return;
}
int main(){
	PRE();
	cin>>n;
	for(int i=0;i<n;i++)cin>>x[i];
	x[n]=1145141919;
	cin>>r>>q;
	for(int i=0;i<n;i++){
		d[0][i]=upper_bound(x,x+n+1,x[i]+r)-x;
		d[0][i]--;
	}
	d[0][n-1]=n;
	for(int i=1;i<17;i++){
		for(int j=0;j<n;j++){
			if(d[i-1][j]<n)
			d[i][j]=d[i-1][d[i-1][j]];
			else d[i][j]=114514;
		}
	}
	for(int i=0;i<q;i++){
		int a,b;cin>>a>>b;
		a--,b--;if(a>b)swap(a,b);
		int ans=0;
		while(true){
			if(a>=b)break;
			int h=d[0][a],w=1;
			for(int j=1;j<17;j++){
				if(d[j][a]<=b)h=d[j][a],w=Pow2[j];
			}
			ans+=w;
			a=h;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 7808
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)

	a := nextInt() // r0
	b := nextInt() // r1

	x, y, u, v := 1, 0, 0, 1
	for b != 0 {
		// fmt.Println(x, y, u, v)
		// fmt.Printf("%v = %v x %v + %v\n", a, a/b, b, a%b)
		k := a / b
		a, b = b, a%b
		x, y, u, v = u, v, x-k*u, y-k*v
		// fmt.Println(x, y, u, v)
	}

	fmt.Println(x, y)
}



Measured memory_bytes: 1120
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    int A,B;
    cin >> A >> B;
    if(A+B<10) cout << A+B << endl;
    else cout << "error" << endl;
	return 0;
}

Measured memory_bytes: 256
from operator import itemgetter

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

l.sort(key=itemgetter(2), reverse=True)

for x in range(101):
    for y in range(101):
        h = l[0][2] + abs(l[0][0]-x) + abs(l[0][1]-y)
        for i in range(1, n):
            d = abs(l[i][0]-x) + abs(l[i][1]-y)
            h_i = l[i][2] + d
            if l[i][2] == 0:
                if max(h-d, 0) == 0:
                    continue
                else:
                    break
            if h != h_i:
                break
        else:
            ans = list(map(str, [x, y, h]))
            print(" ".join(ans))
            exit()

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k,l; cin>>n>>k>>l;
  UnionFind uf1(n);
  rep(i,k){
    ll a,b; cin>>a>>b;
    a--,b--;
    uf1.connect(a,b);
  }
  UnionFind uf2(n);
  rep(i,l){
    ll a,b; cin>>a>>b;
    a--,b--;
    uf2.connect(a,b);
  }
  map<pll,ll> m;
  rep(i,n){
    pll p={uf1.root(i), uf2.root(i)};
    m[p]++;
  }
  rep(i,n){
    pll p={uf1.root(i), uf2.root(i)};
    cout<<m[p]<<endl;
  }
}

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



void solve(){
    int n;
    cin >> n;
    int l[n+10];
    int sum=0;
    int m = 0;
    rep(i,n){
        cin >> l[i];
        sum += l[i];
        m = max(m, l[i]);
    }
    if(m < sum-m) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ab[26], abb[26];
  for (int i = 0; i < 26; ++i) {
    abb[i] = 50;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 26; ++j) {
      ab[j] = 0;
    }
    string s;
    cin >> s;
    int si = s.size();
    for (int j = 0; j < si; ++j) {
      ab[s[j]-'a']++;
    }
    for (int j = 0; j < 26; ++j) {
      abb[j] = min(ab[j], abb[j]);
    }
  }
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < abb[i]; ++j) {
      cout << (char)('a'+i);
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
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 int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

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

    map<int, int> m;
    repq(a,1,N) {
        int n = a;
        for(int i=2; i*i<=n; i++) {
            if(n % i == 0) {
                while(n % i == 0) {
                    m[i]++;
                    n /= i;
                }
            }
        }
        if(n != 1) m[n]++;
    }
    int ans = 1;
    for(auto x : m) {
        (ans *= (x.second + 1)) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# coding:utf-8

N, M, X, Y = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

xlist.append(X)
ylist.append(Y)
xSorted = sorted(xlist)
ySorted= sorted(ylist)

xMax = xSorted[-1]
yMin = ySorted[0]

if xMax < yMin:
    print('No War')
else:
    print('War')


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

int main () {
	int N;
	cin >> N;
	int x;
	for (int i=1; i<=9; ++i) {
		x = i*100 + i*10 + i;
		if (N <= x) {
			break;
		}
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc133/tasks/abc133_b


N, D = gets.split.map(&:to_i)
Xss = Array.new(N) { gets.split.map(&:to_i) }

d2s = Xss.combination(2).map do |xs1, xs2|
  xs1.zip(xs2).reduce(0) { |memo, (y, z)| memo + (y - z) ** 2 }
end

ans = d2s.count do |d2|
  d = Math.sqrt(d2).floor
  d ** 2 == d2
end

puts ans


Measured memory_bytes: 1788
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    // idx, P, Y
    int[][] city = new int[M][3];
    for (int i = 0; i < M; i++) { 
      city[i][0] = i;
      city[i][1] = sc.nextInt();
      city[i][2] = sc.nextInt();
    }
    
    Arrays.sort(city, (a, b) -> a[2] - b[2]);

    String[] ans = new String[M];
    // P vs cityCount
    int[] cityCount = new int[N+1];
    for (int i = 0; i < M; i++) {
      int cityIdx = city[i][0];
      int p = city[i][1];
      cityCount[p]++;
      
      ans[cityIdx] = genCityId(p, cityCount[p]);
    }

    for (int i = 0; i < M; i++) {
      System.out.println(ans[i]);
    }
  }
  
  private static String genCityId(int p, int count) {
    return String.format("%06d%06d", p, count);
  }
}

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

signed main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int X=x2-x1,Y=y2-y1;
  int x3=x2-Y,y3=y2+X;
  int x4=x1-Y,y4=y1+X;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+100;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)
#define pb push_back

int n,a[N];
char sgn[N];
ll f[N][2];
ll ans;
ll ssum[N];
/*
5
1 - 20 - 13 + 14 - 5
*/

int main(){
   ios::sync_with_stdio(false);
   ans = -0x3f3f3f3f;
   cin >> n;
   fr(i,1,n){
      if(i > 1)cin >> sgn[i]; cin >> a[i];
      if(sgn[i] == '-')a[i] = -a[i];
   }

   ssum[n+1] = 0;
   nfr(i,n,1)ssum[i] = ssum[i+1]+abs(a[i]);

   memset(f,0xf7,sizeof f);
   f[0][0] = 0;
   fr(i,1,n){
      f[i][0] = max(f[i-1][0]+a[i],f[i-1][1]+a[i]);
      f[i][1] = f[i-1][1]-a[i];
      if(sgn[i] == '-')f[i][1] = max(f[i][1],f[i-1][0]+a[i]);
      if(sgn[i] == '-' )ans = max(ans,f[i-1][1]+ssum[i]);
   }
   ans = max(ans,max(f[n][0],f[n][1]));
   printf("%lld\n",ans);
   return 0;
}


Measured memory_bytes: 3072
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

// ModInt
// region
class ModInt(x: Long) {

    companion object {
        const val MOD = 1000000007L
        //const val MOD = 998244353L
    }

    val x = (x % MOD + MOD) % MOD

    operator fun plus(other: ModInt): ModInt {
        return ModInt(x + other.x)
    }

    operator fun minus(other: ModInt): ModInt {
        return ModInt(x - other.x)
    }

    operator fun times(other: ModInt): ModInt {
        return ModInt(x * other.x)
    }

    operator fun div(other: ModInt): ModInt {
        return this * other.inv()
    }

    fun pow(exp: Long): ModInt {
        if (exp == 0L) return ModInt(1L)
        var a = pow(exp shr 1)
        a *= a
        if (exp and 1L == 0L) return a
        return this * a
    }

    fun inv(): ModInt {
        return this.pow(MOD - 2)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ModInt

        if (x != other.x) return false

        return true
    }

    override fun hashCode(): Int {
        return x.hashCode()
    }

    override fun toString(): String {
        return "$x"
    }

}

val fac = mutableListOf<ModInt>()
val invfac = mutableListOf<ModInt>()

fun fact(n: Long, b: Boolean): ModInt {
    if (fac.count() == 0) {
        fac.add(ModInt(1))
        invfac.add(ModInt(1))
    }
    while (fac.count() <= n) {
        fac.add(fac.last() * ModInt(fac.count().toLong()))
        invfac.add(fac.last().inv())
    }
    return if (b) {
        fac[n.toInt()]
    } else {
        invfac[n.toInt()]
    }
}

fun comb(n: Long, k: Long): ModInt {
    return fact(n, true) * fact(k, false) * fact(n - k, false)
}

fun comb2(n: Long, k: Long): ModInt {
    var ans = ModInt(1)
    for (i in 0 until k) {
        ans = ans * ModInt(n - i) / ModInt(k - i)
    }
    return ans
}
// endregion

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextLong()
    val k = sc.nextLong()
    for (i in 1..k) {
        if (n - k >= i - 1) {
            println(comb(k - 1, i - 1) * comb(n - k + 1, i))
        } else {
            println(0)
        }
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 38136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL<<60;
#define REP(i,n) for(int i=0;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int n,m;
    cin >> n>>m;
    int A[m];
    int ans=0;
    REP(i,m){
        cin>>A[i];
        ans += A[i];
    }
    if(n-ans>=0){
        cout<<n-ans<<endl;
    }else{
        cout<<-1<<endl;
    }
    

}

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

int main(void) {
	string C[3];
	for (int j = 0; j < 3; ++j)
		cin >> C[j];

	string ans = "   ";
	for (int i = 0; i < 3; ++i)
		ans[i] = C[i][i];

	cout << ans << '\n';
	return 0;
}


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

int main() {
  int a[3]; cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  int sum = a[1] - a[0] + a[2] - a[1];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = tuple(map(lambda n: int(n) - 1, input().split()))

costs = [-1] * N
loc = 0

if K <= N:
    for i in range(K):
        loc = A[loc]
    print(loc + 1)

else:
    costs[loc] = 0
    for i in range(1, K):
        loc = A[loc]

        if costs[loc] >= 0:
            break

        costs[loc] = i

    offset = costs[loc]
    loop = i - offset

    K -= i
    K %= loop

    for _ in range(K):
        loc = A[loc]
    print(loc + 1)

Measured memory_bytes: 32292
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N=100005;
const int MOD=1e9+7;
int add (int x,int y)   {x=x+y;return x>=MOD?x-MOD:x;}
int mul (int x,int y)   {return (LL)x*y%MOD;}
int dec (int x,int y)   {x=x-y;return x<0?x+MOD:x;}
int Pow (int x,int y)
{
	if (y==0) return 1;
	if (y==1) return x;
	int lalal=Pow(x,y>>1);
	lalal=mul(lalal,lalal);
	if (y&1) lalal=mul(lalal,x);
	return lalal;
}
char ss[N];
int n;
int main()
{
	scanf("%s",ss+1);n=strlen(ss+1);
	int ans=0;
	int sum=1;
	for (int u=1;u<=n;u++)//从这一位开始比他小 
	{
		if (ss[u]=='0') continue;
		ans=add(ans,mul(sum,Pow(3,n-u)));
		sum=add(sum,sum);
	}
	ans=add(ans,sum);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#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
#define pb push_back
#define eb emplace_back
#define mp make_pair

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

bool cmp(Pll x, Pll y){
    if(x.fi == 0) {
        if(y.fi == 0) return x.se > y.se;
        else return true;
    }
    if(y.fi == 0){
        return false;
    }
    if(x.se == 0) {
        if(y.se == 0) return x.fi < y.fi;
        else return false;
    }
    if(y.se == 0){
        return true;
    }
    if(x.se - x.fi == y.se - y.fi){
        return x.se > y.se;
    }
    return x.se - x.fi > y.se - y.fi;
}

void Main(){
    int n;
    cin >> n;
    vector<Pll> kakko(n, P(0,0));
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, s.size()){
            if(s[j] == '('){
                kakko[i].se++;
            }else{
                if(kakko[i].se > 0) kakko[i].se--;
                else kakko[i].fi++;
            }
        }
    }
        
    stable_sort(all(kakko), cmp);
    
    /*
    for(auto [x,y] : kakko){
        cout << x << " " << y << endl;
    }
    cout << endl;
    //*/

    Pll ans = Pll(0,0);
    rep(i,n){
        if(ans.se >= kakko[i].fi) {
            ans.se -= kakko[i].fi;
        }else{
            ans.fi += kakko[i].fi;
        }
        ans.se += kakko[i].se;
        if(ans.fi > 0){
            puts("No");
            return;
        }
        // cout << i << ": " << ans.fi << ", " << ans.se << endl;
    }

    if(ans.fi == 0 && ans.se == 0) puts("Yes");
    else puts("No");
    return;
}

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

Measured memory_bytes: 34244