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

int main() {
  
  int n,i,j;
  cin >> n;

  for(i=0;i<n;i++){
    string str1,str2,temp;
    int kuriagari=0;
    cin >> str1 >> str2;
    
    if (str1.size()<str2.size()){
      temp = str1;
      str1 = str2;
      str2 = temp;
    }
    int goukei[str1.size()+1];
    
    for(j=0;j<str1.size()+1;j++){
      
      if (j==str1.size()){
	goukei[0] = kuriagari;
      }else if (j<str2.size()){
	goukei[str1.size()-j] = str2[str2.size()-1-j] + str1[str1.size()-1-j] + kuriagari -'0' - '0';
	if (goukei[str1.size()-j] >= 10) {
	  goukei[str1.size()-j] -= 10;
	  kuriagari = 1;
	}else{
	  kuriagari = 0;
	}
      }else{
	goukei[str1.size()-j] = str1[str1.size()-1-j] + kuriagari -'0';
	if (goukei[str1.size()-j] >= 10) {
	  goukei[str1.size()-j] -= 10;
	  kuriagari = 1;
	}else{
	  kuriagari = 0;
	}
      }
    }
    if ((str1.size()>=81)||( (str1.size()==80)&&(goukei[0]==1) )){
      cout << "overflow" <<endl;
    }else{
      if (goukei[0]!=0)
	cout << goukei[0] ;
      for(j=0;j<str1.size();j++)
	cout << goukei[j+1];
      cout <<endl;
    }
  }
      
  return 0;
  
}

Measured memory_bytes: 1216
N, M = map(int, input().split())
keys = []
for i in range(M):
    a, b = map(int, input().split())
    c = sum([2 ** (c - 1) for c in list(map(int, input().split()))])
    keys.append([a, c])


# dp[bs] := 鍵の集合bsを手に入れるのに必要な最小費用
dp = [float('inf')] * (1 << N)
dp[0] = 0

for i, (cost, key) in enumerate(keys):
    for bs in range(1 << N):
        dp[bs | key] = min(dp[bs | key], dp[bs] + cost)

print(dp[-1] if dp[-1] != float('inf') else -1)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)

const int INF = 114514810;

int main() {
    int n, m;
    cin >> n >> m;
    static int d[111][111];
    rep(i, 111) rep(j, 111) if (i != j) d[i][j] = INF;

    int a[1111], b[1111], c[1111];
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
    }

    rep(k, n) rep(i, n) rep(j, n) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    int cnt = 0;
    rep(i, m) {
        if (d[a[i]][b[i]] != c[i]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

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

int N;
vector<int> p, q;

int main() {
    cin >> N;
    vector<int> p(N), q(N);
    for (int i = 0; i < N; ++i) cin >> p[i], --p[i];
    for (int i = 0; i < N; ++i) cin >> q[i], --q[i];

    // 各順列が何番目かを求める
    map<vector<int>, int> ord;
    int iter = 0;

    // スタートとなる順列
    vector<int> v(N);
    for (int i = 0; i < N; ++i) v[i] = i;

    // 順番に
    do {
        ord[v] = iter++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(ord[p] - ord[q]) << endl;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;

int main()
{
    int p, q, r, a, b;
    cin >> p >> q >> r;
    if (q > r)
        swap(q, r);
    if (p > q)
        swap(p, q);
    if (q > r)
        swap(q, r);

    cout << p + q << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
vector<ll> C(26);
vector<vector<ll>> S;

ll change_evaluation(vector<ll>& T,ll day) {
  day -= 1;
  vector<ll> last(26, -1);
  vector<ll> next(26, T.size());
  ll old = T.at(day) - 1;
  for (ll i = 0; i < day; ++i) {
    last.at(T.at(i) - 1) = i;
  }
  for (ll i = T.size() - 1; i > day; --i) {
    next.at(T.at(i) - 1) =  i;
  }
  ll max_t = 0, max_score = -INF;
  for (ll t = 0; t < 26; ++t) {
    ll score = S.at(day).at(t) - S.at(day).at(old);
    score += (next.at(t) - day) * (day - last.at(t)) * C.at(t);
    score -= (next.at(old) - day) * (day - last.at(old)) * C.at(old);
    if (score > max_score) {
      max_score = score;
      max_t = t;
    }
  }
  return max_t;
}

ll evaluation(ll t, ll day, vector<ll>& last) {
  ll score = 0;
  ll delay = 3;
  score += S.at(day).at(t);
  for (ll j = 0; j < 26; ++j) {
    score -= delay * (delay - 1) / 2 * C.at(j);
    if (j == t) {
      continue;
    }
    score -= (day + delay + 1 - last.at(j)) * C.at(j);
  }
  return score;
}

ll whole_evaluation(vector<ll>& T) {
  ll D = T.size();
  vector<ll> last(26, 0);
  ll score = 0;
  for (ll i = 0; i < D; ++i) {
    ll contest = T.at(i) - 1;
    last.at(contest) = i + 1;
    score += S.at(i).at(contest);
    for (ll j = 0; j < 26; ++j) {
      score -= (i + 1 - last.at(j)) * C.at(j);
    }
  }
  return score;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  //-----------input-------------
  ll D;
  cin >> D;
  vector<ll> T(D);
  S = vector<vector<ll>>(D, vector<ll>(26));
  for (ll i = 0; i < 26; ++i) {
    cin >> C.at(i);
  }
  for (ll i = 0; i < D; ++i) {
    for (ll j = 0; j < 26; ++j) {
      cin >> S.at(i).at(j);
    }
  }
  //--------------------------------------
  vector<ll> last(26, 0);
  for (ll day = 0; day < D; ++day) {
    ll max_contest = 0;
    ll max_score = -INF;
    for (ll contest = 0; contest < 26; ++contest) {
      ll temp_score = evaluation(contest, day, last);
      if (temp_score > max_score) {
        max_score = temp_score;
        max_contest = contest + 1;
      }
    }
    last.at(max_contest - 1) = day;
    T.at(day) = max_contest;
  }

  // random_device rnd;
  // mt19937 mt(rnd());
  // uniform_int_distribution<> rand(1, T.size());
  // uniform_int_distribution<> rand_evn(1, 26);
  // double persent = 1.0003;
  // double persent_now = 1;
  // for (ll i = 0; i < 100000; ++i) {
  //   ll random = rand(mt);
  //   if (random / 3.65 < 20 / persent_now) {
  //     ll event = rand_evn(mt);
  //     T.at(random - 1) = event;
  //   }
  //   else {
  //     ll max_t = change_evaluation(T, random);
  //     // cout << max_t << " rand" << "\n";
  //     T.at(random - 1) = max_t + 1;
  //   }
  //   persent_now *= persent;
  // }

  // ll score = whole_evaluation(T);
  // cout << score << "\n";

  for (ll i = 0; i < D; ++i) {
    cout << T.at(i) << "\n";
  }

  // vector<ll> ans = evaluation(C, S, T);
  // for (ll i = 0; i < ans.size(); ++i) {
  //   cout << ans.at(i) << "\n";
  // }
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    REP(i, N) {
        cin >> H[i];
    }
    vector<vector<int>> v(N);
    REP(i, M) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        v[A].push_back(B);
        v[B].push_back(A);
    }

    int res = 0;
    REP(i, N) {
        bool p = true;
        for(auto j : v[i]) {
            p = p && H[j] < H[i];
        }
        if(p) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


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

int main() {
  int A,B,C,K;
  cin >>A>>B>>C>>K;
  int i=0,j=0;
  while(A>0&&K>0){
    A--;
    K--;
    i++;
  }
  while(B>0&&K>0){
    B--;
    K--;
  }
  while(C>0&&K>0){
    C--;
    K--;
    j++;
  }
  cout<<i-j<<endl;
}


Measured memory_bytes: 3612
n = int(input())
a_b = []
for i in range(n):
    a_b.append(list(map(int, input().split())))
a_b = sorted(a_b, key=lambda x: x[1])
a_sum = 0
for i in range(n):
    a_sum += a_b[i][0]
    if a_sum > a_b[i][1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 89816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var s = sc.intarr;
        int a = s[0];
        int b = s[1];

        if (a > b) wr.wri(a - 1);
        else wr.wri(a);

    }


}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int main()
{
    int n,a=0;
    cin>>n;
    if(n>=1000000000){
        a=2*n;}
    else{
    while(n>=500){
        n=n-500;
        a=a+1000;}
    while(n>=5){
        n-=5;
        a+=5;}}
    cout<<a;


    return 0;
}


Measured memory_bytes: 256
n = input()
N = len(n)
n = int(n)
count = 0

if N%2 == 0:
    N = N-2
    while(N>=0):
        count = count + 9*(10**N)
        N = N-2
else:
    count = count + n-(10**(N-1))+1
    N = N-3
    while(N>=0):
        count = count + 9*(10**N)
        N = N-2 

print(count)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
 
 
def divide(n):
    c1, c2 = 0, 0
    while (n%2 == 0):
        c1 += 1
        n //= 2
    while (n%5 == 0):
        c2 += 1
        n //= 5
    return (c1, c2)
    
 
def main():
    n = int(input())
    a = [None]*n
    for i in range(n):
        sub = input().replace("\n", "")
        if "." in sub:
            x, y = map(str, sub.split("."))
            s = int(x)*1000000000+10**(9-len(y))*int(y)
        else:
            s = int(sub)
            s *= 1000000000
        a[i] = divide(s)
 
    dp = [[0]*100 for _ in range(100)]
    for i in range(n):
        c1, c2 = a[i]
        dp[c1][c2] += 1
    
    for i in range(98, -1, -1):
        for j in range(98, -1, -1):
            dp[i][j] += dp[i+1][j]+dp[i][j+1]-dp[i+1][j+1]
 
    ans = 0
    for i in range(n):
        c1, c2 = a[i]
        if (c1 >= 9 and c2 >= 9):
            ans -= 1
        if c1 >= 18 and c2 >= 18:
            ans += dp[0][0]
            continue
        if c1 >= 18:
            ans += dp[0][18-c2]
            continue
        if c2 >= 18:
            ans += dp[18-c1][0]
            continue
        ans += dp[18-c1][18-c2]
        
    print(ans//2)
    
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

map<int, int> prime_factors(int n) {
	map<int, int> res;
	if(n == 1) { // n=1 の素因数分解は n^1
		res[n] = 1;
		return res;
	}
	for(int i = 2, _n = n; i*i <= _n; ++i) {
		while(n % i == 0) {
			++res[i]; // 素数i^{res[i]}
			n /= i;
			}
		}
	if(n != 1) res[n] = 1;
	return res;
}

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

    int n; cin >> n;
	map<int, int> pfs = prime_factors(n);
    cout << n << ":";
	for(const auto& p: pfs) {
        rep(i, p.second) {
            cout << " " << p.first;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main(){
    int H, N; cin >> H >> N;
    vector<int> dp(H+1, INF);
    dp[0] = 0;
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        for(int j=0; j<H; j++){
            int nj = min(j+a, H);
            dp[nj] = min(dp[nj], dp[j]+b);
        }
    }
    cout << dp[H] << endl;
}


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

const int mod = 1e9 + 7;

void add_self (int & a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}

void sub_self (int & a, int b) {
	a -= b;
	if (a < 0) a += mod;
}

int mul (int a, int b) {
	return (int) (((ll) a * b) % mod);
}

int power (int a, int k) {
	int ans = 1;
	while (k >= 1) {
		if (k & 1) ans = mul (ans, a);
		a = mul (a, a);
		k >>= 1;
	}
	return ans;
}

int inverse (int a) {
	return power (a, mod - 2);
}

int choose (int n, int r) {
	int ans = 1;
	int k = 1;
	while (k <= r) {
		ans = mul (ans, mul (n, inverse (k)));
		n--; k++;
	}
	return ans;
}

int f (int r, int c) {
	add_self (r, c);
	add_self (r, 2);
	add_self (c, 1);
	return choose (r, c);
}

int main() {
	int r1, r2, c1, c2;
	//cout << choose (1, 1) << " " << choose (1, 2) << " " << choose (10, 3) << endl;
	scanf ("%d %d %d %d", &r1, &c1, &r2, &c2);
	int a = f (r2, c2);
	int b = f (r2, c1 - 1);
	int c = f (r1 - 1, c2);
	int d = f (r1 - 1, c1 - 1);
	//cout << a << " " << b << " " << c << " " << d << endl;
	int ans = a;
	sub_self (ans, b);
	sub_self (ans, c);
	add_self (ans, d);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
#include <functional>
#include <vector>

using namespace std;

struct edge {
    int from, to;
    int dist;
    int cost;
    edge(int from, int to, int dist, int cost) : 
        from(from), to(to), dist(dist), cost(cost){}
};

#define INF (1<<28)
#define MAX_N 10001
int N, M;
vector<edge> graph[MAX_N];
vector<edge> prevs[MAX_N];
int dist[MAX_N];

void dijkstra() {
    fill(dist, dist+N, INF);
    for (int i = 0; i < N; i++) prevs[i].clear();
    typedef pair<int, int> P; // 最短距離, 頂点番号
    priority_queue< P, vector<P>, greater<P> > q;
    dist[0] = 0;
    q.push(P(0, 0));

    while (!q.empty()) {
        P p = q.top(); q.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0; i < graph[v].size(); i++) {
            edge e = graph[v][i];
            if (dist[e.to] > dist[v] + e.dist) {
                //printf("%d ", e.to);
                dist[e.to] = dist[v] + e.dist;
                prevs[e.to].clear(); prevs[e.to].push_back(e);
                q.push(P(dist[e.to], e.to));
            } else if (dist[e.to] == dist[v] + e.dist) {
                //printf("%d ", e.to);
                prevs[e.to].push_back(e);
            }
        }
    }
}

int cost(int v) {
    int min_cost = INF;
    for (int i = 0; i < prevs[v].size(); i++) {
        min_cost = min(min_cost, prevs[v][i].cost);
    }
    return min_cost;
}

int main() {
    while (scanf("%d %d", &N, &M), N || M) {
        for (int i = 0; i < N; i++) graph[i].clear();
        for (int i = 0; i < N; i++) prevs[i].clear();
        for (int i = 0; i < M; i++) {
            int u, v, d, c;
            scanf("%d %d %d %d", &u, &v, &d, &c);
            u--, v--;
            graph[u].push_back(edge(u, v, d, c));
            graph[v].push_back(edge(v, u, d, c));
        }
        dijkstra();

        int total = 0;
        for (int i = 1; i < N; i++) {
            total += cost(i);
        }
        printf("%d\n", total);
    }
    return 0;
}

Measured memory_bytes: 4128
sx,sy,tx,ty=map(int,input().split())
u=tx-sx
r=ty-sy
r1=''
for i in range(r):
  r1+='U'
for j in range(u):
  r1+='R'
r2=r1.replace('U','D').replace('R','L')
r3='LU'+r1+'RD'
r4='RD'+r2+'LU'
print(r1+r2+r3+r4)

Measured memory_bytes: 3060
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

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

map<string,int>st;
vector<string>vt;
int main() {

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        int n;
        cin>>n;
        vt.pb("AC");
        vt.pb("WA");
        vt.pb("TLE");
        vt.pb("RE");
        for(int i=1;i<=n;++i){
            string s;
            cin>>s;
            st[s]++;
        }
        for(int i=0;i<(int)vt.size();++i){
            cout<<vt[i]<<" x "<<st[vt[i]]<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3664
# 2020/08/15
# AtCoder Beginner Contest 175 - A

# Input
s = input()

# Calc
cnt = 0
for i in range(len(s)):
    if s[i] == 'R':
        cnt = cnt + 1

if cnt == 3:
    ans = 3
elif cnt == 2:
    if s[1] == 'S':
        ans = 1
    else:
        ans = 2
elif cnt == 1:
    ans = 1
else:
    ans = 0

# Output
print(ans)


Measured memory_bytes: 9040
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    cin >> N;
    priority_queue<pair<i64, i64>> q;
    for(int i = 0; i < N; i++) {
        i64 p;
        cin >> p;
        q.push({p, i});
    }
    set<i64,    less<i64>> sr;
    set<i64, greater<i64>> sl;
    i64 ans = 0;
    for(int j = 0; j < N; j++) {
        i64 p, i;
        tie(p, i) = q.top();

        i64 l1 = -1, r1 = -1, l2 = -1, r2 = -1;
        {
            auto itor = sr.upper_bound(i);
            if (itor != sr.end()) {
                r1 = *itor;
                itor = sr.upper_bound(r1);
                if (itor != sr.end()) {
                    r2 = *itor;
                }
            }
            itor = sl.upper_bound(i);
            if (itor != sl.end()) {
                l1 = *itor;
                itor = sl.upper_bound(l1);
                if (itor != sl.end()) {
                    l2 = *itor;
                }
            }
        }
        if(r1 >= 0 && r2 < 0) r2 = N;
        if(r1 < 0) r1 = N;

        if(l1 >= 0) {
            ans += (r1 - i) * (l1 - l2) * p;
        }
        if(r1 < N) {
            ans += (i - l1) * (r2 - r1) * p;
        }
        sl.insert(i), sr.insert(i);
        q.pop();
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,k;
    cin >> n >> k;
    string a;
    cin >> a;
    a[k-1] = char(int(a[k-1])+32);
    cout << a << endl;
    cin >> a;
}


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

long long int sum(int n) {
	return ((long long int)n * (n+1)) / 2;
}

int main() {
	int n;
	cin >> n;
	int n3 = n/3;
	int n5 = n/5;
	int n15 = n/15;
	long long int ans = sum(n) - 3*sum(n3) - 5*sum(n5) + 15*sum(n15);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p(n+5);
    rep(i,n+5) p[i]=i;
    for(int i=2; i*i<=n; ++i){
        if(p[i]==i){
            for(int j=i; j<=n; j+=i){
                if(p[j]==j) p[j]=i;
            }
        }
    }
    function<int(int)> che=[&](int x){
        map<int,int> mp;
        while(x!=1){
            mp[p[x]]++;
            x/=p[x];
        }
        int res=1;
        for(auto &v: mp){
            //cout<<v.first<<" "<<v.second<<endl;
            res*=(v.second+1);
        }
        return res;
    };
    //cout<<che(3)<<endl;
    ll ans=0;
    rep(i,n){
        ans+=(ll)(i+1)*(ll)che(i+1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 42244
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << 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; }
#define int long long

void solve() {
	int n, m; cin >> n >> m;
    string s; cin >> s;
    // vector<int> dp(n + 1, INF);
    // dp[n + 1] = 0;
    // for(int i = n; i >= 0; --i) {

    // }

    vector<int> num(n + 1, -1);
    for(int i = n; i >= n - m ; --i) {
        if(s[i] == '0') num[n] = i;
    }
    int cnt = 0;
    int p = num[n];
    for(int i = n - 1; i >= 0; --i) {
        if(i - m >= 0 && s[i - m] == '0') {
            p = i - m;
        }
        if(s[i] == '1') {num[i] = -1;  cnt ++;  if(cnt >= m) { cout << - 1 << endl; return; } continue;}
        else cnt = 0;
        num[i] = p;
    }
    vector<int> ans;
    int now = n;
    while(now != 0) {
        int next = num[now];
        int q = now - next;
        ans.pb(q);
        now = next;
    }
    reverse(all(ans));
    for(auto t: ans) {
        cout << t << " ";
    }
    cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 2248
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
  long long target;

  cin >> target;

  long long crt = 100;

  for (int i = 1; true; i++) {
    crt *= 1.01;

    if (crt >= target) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 3192
C = [[0 for j in range(51)] for i in range(51)]
for i in range(51):
    C[i][0] = 1
for i in range(1, 51):
    for j in range(1, 51):
        C[i][j] = C[i - 1][j - 1] + C[i - 1][j]
n, a, b = map(int, input().split())
*V, = map(int, input().split())
V.sort(reverse=True)
print(sum(V[:a]) / a)
if V[0] == V[a - 1]:
    x = V.count(V[a - 1])
    print(sum([C[x][y] for y in range(a, b + 1)]))
else:
    x = V.count(V[a - 1])
    y = a - len([v for v in V if v > V[a - 1]])
    print(C[x][y])


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if(x - r < 0 || y - r < 0 || x + r > W || y + r > H){
		printf("No\n");
	}else{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A ,B, K;
    cin >> A >> B >> K;
    ll tmp = A - K;
    if(tmp > 0){
        cout << tmp << " " << B << endl;
    }
    else{
        K -= A;
        B = max(0LL, B - K);
        cout << 0 << " " << B << endl;
    }

}

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

int main()
{
  	unsigned long long n;
  	cin>>n;
  	unsigned long long L0=2;
  	unsigned long long L1=1;
  	if(n==1)
    {
    	cout<<L1<<endl;
      	return 0;
    }  
  	unsigned long long L2=0;
  	for(unsigned long long i=2 ; i<=n ; ++i)
    {
    	L2=L0+L1;
      	L0=L1;
      	L1=L2;
    }
  	cout<<L2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
	int X = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
	return w ? -X : X;
}
int main()
{
	int n;
	cin>>n;
	vector<long long> a,b;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		a.push_back(t);
		b.push_back(t);
  	}
  	sort(a.begin(),a.end(),greater<long long>());
  	sort(b.begin(),b.end(),greater<long long >());
  	int w=n-1;
  	for(int i=1;i<a.size();i++)
  	{
		if(a[i]<=0)
		{
		  	w=i;
		  	break;
		}
  	}
  	for(int i=1;i<b.size()-1 and i<w;i++)
  	{
		b[n-1]=b[n-1]-b[i];
  	}
  	for(int i=w;i<b.size();i++)
  	{
		b[0]-=b[i];
  	}
  	cout<<b[0]<<endl;
  	for(int i=1;i<a.size()-1 and i<w;i++)
  	{
		cout<<a[n-1]<<" "<<a[i]<<endl;
		a[n-1]=a[n-1]-a[i];
  	}
  	for(int i=w;i<a.size();i++)
  	{
		cout<<a[0]<<" "<<a[i]<<endl;
		a[0]-=a[i];
  	}
  	return 0;
}


Measured memory_bytes: 3692
from itertools import groupby as gb
s = input()
g = gb(s)
flag = False
if s[0]=='W':
    flag = True
BW = []
for k,v in g:
    if flag:
        flag = False
        continue
    BW.append(len(list(v)))
if len(BW)%2==0:
    BW.append(0)
tmp = 0
res = 0
for i in range(0,len(BW)-1,2):
    a,b = BW[i]+tmp, BW[i+1]
    res += a * b
    BW[i+2] += a
    #print(a,b,i)
print(res)
#print(BW)


Measured memory_bytes: 5676
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

bool check(int x) {  
        if (x < 0)   return false;//¸ºÊý²»Îª»ØÎÄ  
      
        int leftDiv = 1;//¼ÆËã×ó±ßµÄ×î´ó³ýÊý  
        for (int i = x; i > 9; i /= 10){  
            leftDiv *= 10;  
        }  
      
        int rightDiv = 10;  
        while (rightDiv <= leftDiv){//ÅÐ¶ÏÊÇ·ñÊÇ»ØÎÄ  
            if (x%rightDiv != x / leftDiv){//·Ç»ØÎÄ  
                return false;  
            }  
            else{  
                x = (x%leftDiv) / rightDiv;    
                leftDiv /= 100;  
            }  
        }  
        return true;  
    }  

int main(){
	int A,B;
	cin>>A>>B;
 	int i;
 	int ans = 0;
    for (i = A; i <= B; i++){
        if (check(i)) ans++;
    }
    printf("%d\n",ans);
    return 0;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    vector<char> c(W);
    REP(i, W) cin >> c[i];
    REP(i, 2) {
      for(int i = 0; i < W; i++) {
        cout << c[i];
      }
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
integer a,b,c,answer
read*,a,b,c
answer=3
if(a==b)then
	answer=answer-1
endif
if(b==c)then
	answer=answer-1
endif
if(c==a)then
	answer=answer-1
endif
if(a==b.and.b==c)then
	answer=answer+1
endif
print"(i0)",answer
end

Measured memory_bytes: 384
#include <stdio.h>
#define SPACE 0
#define WHITE 1
#define BLACK 2

int main(void){
    int f[9];
    char buf[16];
    char mark[]="sox";
    
    while (scanf("%s", buf) != EOF){
        for (int i=0; i<9; i++){
            switch(buf[i]){
                case 's': f[i]=SPACE; break;
                case 'o': f[i]=WHITE; break;
                case 'x': f[i]=BLACK; break;
            }
        }
        if (f[0]==f[1] && f[1]==f[2] && f[0]!=SPACE){
            printf("%c\n", mark[f[0]]);
        }else if (f[3]==f[4] && f[4]==f[5] && f[3]!=SPACE){
            printf("%c\n", mark[f[3]]);
        }else if (f[6]==f[7] && f[7]==f[8] && f[6]!=SPACE){
            printf("%c\n", mark[f[6]]);
        }else if (f[0]==f[3] && f[3]==f[6] && f[0]!=SPACE){
            printf("%c\n", mark[f[0]]);
        }else if (f[1]==f[4] && f[4]==f[7] && f[1]!=SPACE){
            printf("%c\n", mark[f[1]]);
        }else if (f[2]==f[5] && f[5]==f[8] && f[2]!=SPACE){
            printf("%c\n", mark[f[2]]);
        }else if (f[0]==f[4] && f[4]==f[8] && f[0]!=SPACE){
            printf("%c\n", mark[f[0]]);
        }else if (f[2]==f[4] && f[4]==f[6] && f[2]!=SPACE){
            printf("%c\n", mark[f[2]]);
        }else{
            printf("d\n");
        }
    }
    return 0;
}

Measured memory_bytes: 976
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        int[] A = new int[N];
        for (int i=0; i<N; i++) A[i] = reader.nextInt();
        int cnt = 0;
        int cur = 1;
        for (int i=0; i<N; i++) {
            if (A[i] == cur) {
                cur++;
            } else {
                cnt++;
            }
        }
        if (cnt == N) cnt = -1;
        System.out.println(cnt);
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 22476
n = int(input())
preorder = list(map(int, input().split(' ')))
inorder = list(map(int, input().split(' ')))
postorder = []
pos = 0

def solve():
    global pos
    pos = 0
    reconstruction(0, len(preorder))
    for i in range(n):
        if i: print(' ', end='')
        print(postorder[i], end='')
    print()

def reconstruction(left, right):
    global inorder, preorder, postorder, pos
    if left >= right: return None
    root = preorder[pos]
    pos += 1
    mid = inorder.index(root)
    reconstruction(left, mid)
    reconstruction(1 + mid, right)
    postorder.append(root)

solve()


Measured memory_bytes: 5604
N = int(input())
word_bank = set()
last_char = ''

for n in range(N):
  new_word = input()
  if new_word in word_bank:
    print('No')
    exit(0)
  elif n != 0 and new_word[0] != last_char:
    print('No')
    exit(0)
  else:
    word_bank.add(new_word)
    last_char = new_word[-1]

print('Yes')

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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

string fast(string s){
	vi a;
	{
		int last=-1;
		for(auto c:s){
			int x=c-'A';
			if(x!=last)
				a.pb(x);
			last=x;
		}
	}
	int ans,m;
	{
		int cnt[3]{};
		for(auto v:a)cnt[v]++;
		m=min_element(cnt,cnt+3)-cnt;
		ans=cnt[m];
		for(auto&v:a){
			if(v==0)v=m;
			else if(v==m)v=0;
		}
	}
	string res;
	if(ans){
		int x[2]{},y[2]{},cur[2]{};
		vc<array<int,3>> w;
		bool f=true;
		int head=-1;
		const auto upd=[&](){
			rep(k,2)
				if(cur[k]){
					x[k]++;
					if(cur[k^1]==0&&!f)
						y[k]++;
				}
			f=false;
			w.pb({cur[0],cur[1],head});
			cur[0]=cur[1]=0;
			head=-1;
		};
		for(auto v:a){
			if(v==0)
				upd();
			else{
				cur[v-1]++;
				if(head==-1)
					head=v-1;
			}
		}
		f=true;
		upd();
		
		rep(k,2)
			if(x[k^1]<y[k])
				ans-=y[k]-x[k^1];
		
		rep(k,2){
			vc<array<int,3>> tmp;
			rep(i,w.size()){
				if(x[k^1]<y[k]){
					if(0<i&&i<int(w.size())-1&&w[i][k^1]==0){
						x[k]--;
						y[k]--;
						continue;
					}
				}
				tmp.pb(w[i]);
			}
			w=tmp;
		}
		
		int len=w.size();
		int cnt[2]{};
		for(auto e:w)
			rep(k,2)
				cnt[k]+=e[k];
		rep(k,2){
			rep(i,len){
				if(0<i&&i<len-1&&w[i][k^1]==0)continue;
				if(cnt[k]>cnt[k^1]&&w[i][k]>w[i][k^1]){
					w[i][k]--;
					cnt[k]--;
				}
				if(cnt[k]>cnt[k^1]&&w[i][k]==w[i][k^1]&&w[i][k]>0){
					w[i][k]--;
					cnt[k]--;
				}
			}
		}
		assert(cnt[0]==cnt[1]);
		vi idx;
		rep(i,len){
			while(cnt[0]>=len){
				int g=w[i][0]+w[i][1];
				if(g<=1)break;
				if(0<i&&i<len-1&&g==2)break;
				rep(k,2){
					cnt[k]--;
					w[i][k]--;
				}
			}
			int of=w[i][2];
			rep(k,2)if(w[i][k]>w[i][k^1])of=k;
			rep(j,w[i][0]+w[i][1])
				idx.pb((j+of)%2+1);
			if(i<len-1)
				idx.pb(0);
		}
		for(auto v:idx){
			if(v==0)v=m;
			else if(v==m)v=0;
			res+='A'+v;
		}
	}
	assert(int(res.size())==ans*3);
	return res;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	string s;
	cin>>s;
	
	cout<<fast(s)<<endl;
}


Measured memory_bytes: 40092
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if (n % 2 == 0) {
			System.out.println(n);
		} else {
			System.out.println(n * 2);
		}
	}
}

Measured memory_bytes: 23764
#include<stdio.h>
int selectionSort(char mk[],char N[],int n){
    int i,j,minj;
    char p;
    for(i=0;i<n;i++){
        minj=i;
        for(j=i;j<n;j++){
            if(N[j]<N[minj]){
                minj=j;
            }
        }
        p=N[i];
        N[i]=N[minj];
        N[minj]=p;
        p=mk[i];
        mk[i]=mk[minj];
        mk[minj]=p;
    }
    return 0;
}

int bubbleSort(char mk[],char N[],int n){
    int i,j;
    char p;
    for(i=0;i<n;i++){
        for(j=n-1;i<j;j--){
            if(N[j]<N[j-1]){
                p=N[j];
                N[j]=N[j-1];
                N[j-1]=p;
                p=mk[j];
                mk[j]=mk[j-1];
                mk[j-1]=p;
            }
        }
    }
    return 0;
}
int main(){
    int i,n;
    char num[36],mk[36],num1[36],num2[36],mk1[36],mk2[36];
    char str[2];
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",str);
        mk1[i]=str[0];
        num1[i]=str[1];
        mk[i]=str[0];
        num[i]=str[1];
    }
    
    bubbleSort(mk1,num1,n);
    for(i=0;i<n-1;i++){
        printf("%c%c ",mk1[i],num1[i]);
    }
    printf("%c%c\n",mk1[n-1],num1[n-1]);
    printf("Stable\n");
    
    for(i=0;i<n;i++){
        mk2[i]=mk[i];
        num2[i]=num[i];
    }
    
    selectionSort(mk2,num2,n);
    for(i=0;i<n-1;i++){
        printf("%c%c ",mk2[i],num2[i]);
    }
    printf("%c%c\n",mk2[n-1],num2[n-1]);
    
    if((strncmp(num1,num2,n)==0) && (strncmp(mk1,mk2,n)==0)){
        printf("Stable\n");
    }
    else{
        printf("Not stable\n");
    }
    return 0;
}


Measured memory_bytes: 2068
n, m = gets.chomp.split.map(&:to_i)
arr = gets.chomp.split.map(&:to_i)
max = [arr[0] - 1, n - arr[-1]].max
prev = arr[0]
arr[1..-1].each{|x|
    max = (x - prev) / 2 if max < (x - prev) / 2
    prev = x
}
puts max


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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

map<int,bool> ada;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x,n;
    cin >> x >> n;
    for (int i = 1 ; i <= n ; i++)
    {
        int ta;
        cin >> ta;
        ada[ta] = 1;
    }
    int mn = INF;
    int ans = INF;
    for (int i = -1000 ; i <= 1000 ; i++) if (!ada[i])
    {
        int diff = abs(i - x);
        if (mn == diff)
        {
            ans = min(ans,i);
        }
        else
        if (diff < mn)
        {
            ans = i;
            mn = diff;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3748
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef vector<int> VI;


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


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

	REP(i, 3) {
		if (str[i] == '1') {
			str[i] = '9';
		}
		else {
			str[i] = '1';
		}
		cout << str[i];
	}
	cout << endl;


	return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, input().split())

if (N >= K):
  amari = N%K
  other = abs(amari - K)
  if(amari < other):
    print(amari)
  else:
    print(other)
else:
  if(N < abs(N-K)):
    print(N)
  else:
    print(abs(N-K))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <utility>
#include <queue>

int r, c;
int arr[11][10010];

int main() {
    while(std::cin >> r >> c, r + c) {

    for(int i = 0; i < r; ++i) {
        for(int j = 0; j < c; ++j) {
            std::cin >> arr[i][j];
        }
    }

    int max = 0;
    for(int i = 0; i < (1 << r); ++i) {
        int sum = 0;
        for(int x = 0; x < c; ++x) {
            int cnt = 0;
            for(int y = 0; y < r; ++y) {
                cnt += arr[y][x] == !!((1 << y) & i);
            }
            sum += std::max(r - cnt, cnt);
        }
        max = std::max(max, sum);
    }

    std::cout << max << std::endl;
    }
}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n,k;
  cin>>n>>k;
  long long x[n];
  REP(i,n){
    cin>>x[i];
  }
  long long ans=INF;
  for(int i=0;i<n-k+1;i++){
    if(x[i+k-1]<=0){
      ans = min(ans,abs(x[i]));
    }else if(x[i]>=0){
      ans = min(ans,x[i+k-1]);
    }else{
      if(abs(x[i])<=x[i+k-1]){
        ans = min(ans,2*abs(x[i])+x[i+k-1]);
      }else{
        ans = min(ans,abs(x[i])+2*x[i+k-1]);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char s[200005];
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main() {
	int n=read(),a=read(),b=read(),c=read(),d=read();
	scanf("%s", s+1);
	for (int i=a; i<c; i++) {
		if (s[i]=='#' && s[i+1]=='#') {
			printf("No\n");
			exit(0);
		}
	}
	for (int i=b; i<d; i++) {
		if (s[i]=='#' && s[i+1]=='#') {
			printf("No\n");
			exit(0);
		}
	}
	if (c>d) {
		bool flag=false;
		int cnt=0;
		for (int i=b-1; i<=d+1 && !flag; i++) {
			if (s[i]=='.') {
				++cnt;
				if (cnt>=3) flag=true;
			}
			else cnt=0;
		}	
		if (!flag) {
			printf("No\n");
			exit(0);
		}
	}
	printf("Yes\n");
	return 0;
}

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

int main(){
 int H,W,i,j;
 string C[100];
 cin>>H>>W;
 for(i=0;i<H;i++){
 	cin>>C[i];
 }
 
 for(i=0;i<H;i++){
 	for(j=0;j<2;j++){
		cout<<C[i]<<endl;
	}
 }
 
}

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

int main(){
	string S;
	int Q;
	cin >> S >> Q;
	int p = 1;
	vector<char> f, b;
	rep(i,Q) {
		int T;
		cin >> T;
		if (T == 1) {
			p *= -1;
		}
		else {
			int F;
			char C;
			cin >> F >> C;
			if ( F == 1) {
				if (p == 1)	f.push_back(C); 
				else b.push_back(C);
			}
			else {
				if (p == 1) b.push_back(C);
				else f.push_back(C);
			}
		}
	}
	if (p == 1) {
		for (int i = f.size()-1; i >= 0; i--) cout << f[i];
		cout << S;
		for (int i = 0; i < b.size(); i++) cout << b[i];
		cout << endl;
	}
	else {
		for (int i = b.size()-1; i >= 0; i--) cout << b[i];
		reverse(S.begin(), S.end());
		cout << S;
		for (int i = 0; i < f.size(); i++) cout << f[i];
		cout << endl;
	}


	return 0;
}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



ll a[1111][1111];

int main(void) {
  ll i, j, k;
  ll N;
  cin >> N;
  
  for(i=0; i<N; i++) {
    for(j=0; j<N-1; j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  
  ll pos[1111]={};
  queue<ll> q;
  for(i=0; i<N; i++) q.push(i);
  
  for(ll d=0; d<=N*(N-1)/2; d++) {
    ll used[1111]={};
    ll upd=0;
    
    queue<ll> tq;
    
    while(q.size()) {
      ll u=q.front(); q.pop();
      if(used[u]) continue;
      
      ll e=a[u][pos[u]];
      if(used[e]) continue;
      
      if(a[e][pos[e]]==u) {
        used[u]=1; used[e]=1;
        pos[u]++; pos[e]++;
        upd=1;
        
        if(pos[u]<N-1) tq.push(u);
        if(pos[e]<N-1) tq.push(e);
      }
    }
    
    while(tq.size()) {
      q.push(tq.front());
      tq.pop();
    }
    
    
    if(!upd) {
      pt(-1);
      return 0;
    }else {
      if(q.empty()) {
        pt(d+1);
        return 0;
      }
    }
    
    
  }
  
  
}



Measured memory_bytes: 8960
#include<iostream>
#include<string>

using namespace std;

int nxt[100000 + 10][10];//nxt[i][j] := i文字目より後ろの文字jが初めて現れる場所

int main() {
	int N;
	string S;

	cin >> N >> S;

	for (int i = 0; i <= 9; i++)nxt[S.size()][i] = -1;
	for (int i = S.size(); i >= 1; i--) {
		for (int j = 0; j <= 9; j++) {
			nxt[i - 1][j] = nxt[i][j];
		}
		nxt[i - 1][S[i - 1] - '0'] = i;
		
	}

	int ans = 0;
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			for (int k = 0; k <= 9; k++) {
				string s;
				s += ('0' + i);
				s += ('0' + j);
				s += ('0' + k);

				int idx = nxt[0][s[0] - '0'];
				if (idx == -1)continue;
				idx = nxt[idx][s[1] - '0'];
				if (idx == -1)continue;
				idx = nxt[idx][s[2] - '0'];
				if (idx == -1)continue;
				ans++;
			}
		}
	}

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

Measured memory_bytes: 1536