akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

int main() {
    int n,m;
    cin >> n >> m;
    cout << n*(n-1)/2+m*(m-1)/2 << endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    int c,d;
    d = 0;
    for(int i = 0; i< n; i++) cin >> h[i];
    for(int i = 0; i< n;) {
        int a = h[i];
        c = 0;
        for(int j = i+1; j< n; j++) {
            if(a >= h[j]) c++;
            else break;
            a = h[j];
        }
        if(d <= c) d = c;
        i+=c+1;
    }
    cout << d << endl;
}

Measured memory_bytes: 640
N,W=map(int,input().split())
#0で初期化されたj*iの二次元配列を作る
DP= [[0 for j in range(W+1)] for i in range(N+1)]
v=[0]*(N+1)
w=[0]*(N+1)
for i in range(1,N+1):
    v[i],w[i]=map(int,input().split())
for i in range(1,N+1):
    for j in range(1,W+1):
        if w[i]>j:
            DP[i][j]=DP[i-1][j]
        else:
            DP[i][j]=max(v[i]+DP[i-1][j-w[i]], DP[i-1][j])
print(DP[N][W])


Measured memory_bytes: 42268
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cstring>

#define MOD 998244353

using namespace std;

int main()
{
	int n;
	long long s;

	scanf("%d %lld", &n, &s);

	vector<long long> arr(3001);

	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &arr[i]);
	}

	long long sol = 0;
	long long dp[2][5001] = { 0, };

	for (int i = 0; i < n; i++)
	{
		for (int j = 1; j <= s; j++)
		{
			dp[i % 2][j] = dp[!(i % 2)][j];
		}

		if (arr[i] == s)
		{
			sol = (sol + (long long)(i + 1) * (long long)(n - i) % MOD) % MOD;
		}

		else if (arr[i] < s)
		{
			dp[i % 2][arr[i]] = (dp[i % 2][arr[i]] + (long long)(i + 1)) % MOD;

			for (int j = 1; j < s - arr[i]; j++)
			{
				dp[i % 2][j + arr[i]] = (dp[i % 2][j + arr[i]] + dp[!(i % 2)][j]) % MOD;
			}

			if (s - arr[i] > 0)
			{
				sol = (sol + dp[!(i % 2)][s - arr[i]] * (long long)(n - i) % MOD) % MOD;
			}
		}
	}

	printf("%lld\n", sol);

	return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
using namespace std;
int  gcd(int a,int b) {
	if (a < b) gcd(b, a);
	int r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
long long nibun(int t,long long bound) {
	long long lb = 1;
	long long ub = 1000000000;
	while (ub - lb > 1) {
		long long mid = (ub + lb) / 2;
		long long tmp = 1;
		for (int i = 0; i < t; i++) {
			tmp *= mid;
			if (tmp > bound)break;
		}
		if (tmp > bound)ub = mid;
		else lb = mid;
	}
	return lb;
}
long long nibun2(int t, long long bound) {
	long long lb = 1;
	long long ub = 1000000000;
	while (ub - lb > 1) {
		long long mid = (ub + lb) / 2;
		long long tmp = 1;
		for (int i = 0; i < t; i++) {
			tmp *= mid;
			if (tmp >= bound)break;
		}
		if (tmp >= bound)ub = mid;
		else lb = mid;
	}
	return lb;
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	long long ans = 0;
	int num=0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B')num += 1;
		if (s[i] == 'W')ans += num;
	}
	cout << ans;
}

Measured memory_bytes: 720
class UnionFind():
    # nはノードの数
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n  # 根のノードは限らないので注意

    # xはノードの番号
    def find(self, x):  # あるノードの親を探すためのメソッド
        if self.parents[x] < 0:  # 親の場合、そのグラフの要素の個数を負の値で保持している
            return x
        else:
            # 再帰的に親を探しにいき、得られた値を格納する
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # x, yはノードの番号
    def union(self, x, y):
        x = self.find(x)  # 根の番号を取得
        y = self.find(y)  # 根の番号を取得
        if x == y:
            return  # 同じ親ならば合体させる必要はない

        # ※ それぞれ要素の個数が負の値で格納されている
        if self.parents[x] > self.parents[y]:
            # yのグループの方が要素の個数が多い場合 (yの方が値が小さいということは、負の世界では値が大きいため)
            # 必ずxの方が要素が多い状態にする
            x, y = y, x

        self.parents[x] += self.parents[y]  # 負の値同士だが、これで良い
        self.parents[y] = x  # yは親ではなくなったため、新しい親であるxの値を正でもつ

    # xはノードの番号
    def size(self, x):
        # 親まで辿ればグループの大きさが負の値で格納されているため、それにマイナスをつけてreturnする
        return -self.parents[self.find(x)]

    # x, yはノードの番号
    def same(self, x, y):
        # 親が同じ = 同じグループに属するならTrueがreturnされる
        return self.find(x) == self.find(y)

    # xはノードの番号
    def members(self, x):
        root = self.find(x)  # 親の値を取得する
        # findで再帰的に親の値が獲得できる
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        # 親となっているノードの番号をリストでreturnする
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_counts(self):
        # グループの数をreturnする
        return len(self.roots())

    def all_group_members(self):
        # 親のノードの番号をキーにして、子のノードの番号を対応させた辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        # printした時の表記
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
uf = UnionFind(N)
for _ in range(M):
    x, y = map(lambda x: int(x)-1, input().split())
    uf.union(x, y)

ans = 0
for i in range(N):
    if uf.same(i, P[i]):
        ans += 1
print(ans)


Measured memory_bytes: 13940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template <class c
#define ris return *this
#define dor > debug& operator<<
#define eni(x)                                                                 \
    sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(   \
              c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c&) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mem(a, s) memset(a, s, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; --i)
typedef vector<int> vi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;
int _x[] = {0, 0, -1, 1, -1, 1, -1, 1};
int _y[] = {-1, 1, 0, 0, 1, -1, -1, 1};
void solve();
void pre();
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    int t = 1;
    // cin >> t;
    rep(i, 1, t) {
        // cout << "Case # " << i << ": ";
        solve();
    }
    return 0;
}
const int mod = 1e9 + 7;
void pre() {}
void solve() {
    int n;
    cin >> n;
    int ans = 0;
    rep(i, 1, n) {
        ans += n / i;
        if (n % i == 0)
            ans--;
    }
    cout << ans;
}


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

int gcd(int a,int b){
    if(b==0)
        return a;
    return gcd(b, a % b);
}
 
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) { cin >> a[i]; }

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

    int res = a[0];
    for (int i = 1; i < N;i++){
        res = gcd(res, a[i]);
    }
        cout << res;
    return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Main {

    private static List<List<Integer>> subsets;
    private static int count = 0;
    private static BigInteger thirteen = new BigInteger("13");
    private static BigInteger five = new BigInteger("5");
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);

        int n = in.nextInt();
        PriorityQueue<Double> q = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            q.add(in.nextDouble());
        }

        while (q.size() > 1) {
            double first = q.poll();
            double second = q.poll();
            q.add((first+second)/2);
        }
        out.println(q.peek());
        out.flush();
    }

    static double gcd(double a,double b) {
        return b == 0 ? a : gcd(b,a%b);
    }
}

class InputReader extends BufferedReader {
    StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    }

    public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    }
    public Integer nextInt() {return Integer.valueOf(next());}
    public Long nextLong() {return  Long.valueOf(next());}
    public Double nextDouble() {return Double.valueOf(next());}

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    }
}

Measured memory_bytes: 21576
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
  char a[4];
  for (int i=0; i<4; i++) {
    cin >> a[i];
  }
  sort(a, a+4);
  string res = "No";
  if (a[0]==a[1] and a[2]==a[3] and a[0]!=a[3]) res = "Yes";
  cout << res << endl;
}

Measured memory_bytes: 256
import itertools
N, M = map(int, input().split())
l = []
seq = []
for i in range(1,N+1):
  seq.append(i)
  i+=1
for _ in range(M):
    A = list(map(int, input().split()))
    l.append(A)
cnt = 0
for i in list(itertools.permutations(seq)):
  if i[0]!=1:
    continue
  for j in range(N-1):
    if sorted([i[j],i[j+1]]) in l:
      if j == N-2:
        cnt += 1
    else:
      break
print(cnt)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define ll long long
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;

int main() {
  INIT;
  
  string a,b,c;
  cin >> a >> b >> c;
  cout << "A" << b[0] << "C" << endl;
  return 0;
}

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

int main()
{
  int T, D;
  int tA, tB, dA, dB;

  cin >> T >> D;
  cin >> tA >> tB;
  cin >> dA >> dB;

  double ret = 1e9;
  for(int A = 0; A <= D; A += dA) {
    for(int B = 0; A + B <= D; B += dB) {
      if(A == 0 && B == 0) continue;
      ret = min(ret, fabs(T - (double)(tA * A + tB * B) / (A + B)));
    }
  }
  cout << fixed << setprecision(10) << ret << endl;
  return(0);
}

Measured memory_bytes: 1240
#include <stdio.h>
#include <stdlib.h>

#define MAX 2000001
#define VMAX 10000

int main()
{
  unsigned short *A, *B;
  
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i = 0 ; i <= VMAX ; i++)
    {
      C[i]=0;
    }

  for(i = 0 ; i < n ; i++)
    {
      scanf("%d",&A[i+1]);
      C[A[i+1]]++;

    }

  for(i = 1 ; i <= VMAX ; i++)
    {
      C[i] = C[i] + C[i - 1];
    }

  for(j = 0 ; j <= n ; j++)
    {
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }

  for(i = 1 ; i <= n ; i++)
    {
      if(i > 1) printf(" ");

      printf("%d",B[i]);
    }
  printf("\n");

  return 0;
}



Measured memory_bytes: 9576
#include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;

int main() {
    int N;
    cin>>N;
    vector<vector<int> > graph(N);
    int u, k, tmp;
    for(int i=0;i<N;++i){
        cin>>u>>k;
        for(int j=0;j<k;++j){
            cin>>tmp;
            tmp--;
            graph[i].push_back(tmp);
        }
    }
    queue<int> que;
    queue<int> passque;
    que.push(0);
    passque.push(0);
    int node, pass;
    vector<int> ans(N);
    for(int i=0;i<N;++i){
        ans[i] = -1;
    }
    map<int, int> past;
    past[0]++;
    while(!que.empty()){
        node = que.front();que.pop();
        pass = passque.front();passque.pop();
        ans[node] = pass;
        for(int i=0;i<graph[node].size();++i){
            if(past[graph[node][i]]==0){
                que.push(graph[node][i]);
                passque.push(pass + 1);
            }
            past[graph[node][i]]++;
        }
    }
    for(int i=0;i<N;++i){
        cout<<i+1<<" "<<ans[i]<<endl;
    }
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
int n,k,i,j,l,t,vis[105],ans;
int main(){
	scanf("%d%d",&n,&k);
	for(i=1;i<=k;i++){
		scanf("%d",&l);
		for(j=1;j<=l;j++){
			scanf("%d",&t);
			vis[t]=1;
		}
	}
	for(i=1;i<=n;i++){
		if(vis[i]==0){
			ans++;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 3824
def g(x, n): #g(x, n): xの倍数(< n)の和
  y = n // x
  return x * y * (y + 1) // 2

n = int(input())

sum = 0
for i in range(1, n + 1):
  k = n // i
  sum += g(i, n)
  
print(sum)
  

Measured memory_bytes: 63812
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 60);
int n,m,a,b,d; ll ans = 0; string s;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}ll dp[1 << 16][16],G[16][16];
ll rec(ll S, int v) {
    if (dp[S][v] > -1) return dp[S][v];
    if (S == (1 << n) - 1 && v == 0)return dp[S][v] = 0;
    ll res = INF;
    rep(u, n) if (!(S >> u & 1)) res = min(res, rec(S | 1 << u, u) + G[v][u]);
    return dp[S][v] = res;
}
int main() {
    cin >> n >> m;
    Fill(G, INF), Fill(dp, -1);
    rep(i, m) {
        cin >> a >> b >> d;
        G[a][b] = d;
    }ans = rec(0, 0);
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 11360
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long MOD = 2019;

int main(){
    ll l, r;
    cin >> l >> r;
    ll ans = MOD;
    if ((l - 1) / MOD != r / MOD) ans = 0LL;
    else {
        for (ll i=l; i<=r-1; ++i) {
            for (ll j=i+1; j<=r; ++j) {
                ans = min(ans, i * j % MOD);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/********************/
/* Author: eddysboy */
/* Time: 2019-03-09 */
/********************/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,m;
pii a[100010];
int rest,ans;
signed main(){
	cin>>n>>m;
	rest=m;
	for(int i=1;i<=n;i++)cin>>a[i].F>>a[i].S;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		// cout<<a[i].F<<a[i].S<<endl;
		int nxt=rest-a[i].S;
		if(nxt<=0){
			ans+=rest*a[i].F;
			break;
		}else ans+=a[i].S*a[i].F,rest=nxt;
		// cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int X=sc.nextInt();
		int b=0;
		int c=0;
		int a[]=new int [N+1];
		for(int i=0;i<M;i++) {
			b=sc.nextInt();
			a[b]=1;
		}
		for(int i=X;i>0;i--) {
			c=c+a[i];
		}
		b=c;
		c=0;
		for(int i=X;i<N;i++) {
			c=c+a[i];
		}
		if(b>c) {
			b=c;
		}
		System.out.println(b);
	}
}

Measured memory_bytes: 22868
/*
 * atcoder/dp_3rd/s.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/* Mod */
#define MOD 1000000007
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}

const int MAX = 10100;
string K;
int D, N;

// dp[l][n][d] := n桁目までみて制限状態lでこれまでの和がdである通りの数
// dp[l and k == K[n]][n+1][d+k] = dp[l][n][d] for k in [0:K[n]]
mint dp[2][MAX][110] = {0};

void input() {
  cin >> K >> D;
  N = K.size();
}

mint rec(int n = 0, int d = 0, bool l = true) {
  mint &cc = dp[l][n][d];
  if (cc.x >= 0) return cc;
  if (n==N) return cc = d == 0;
  int k_u = l ? K[n] - '0' : 9;
  mint ways = 0;
  for (int k=0; k<=k_u; k++) {
    ways += rec(n+1, (d+k)%D, l and k == k_u);
  }
  return cc = ways;
}

void memoRec() {
  memset(dp, -1, sizeof(dp));
  cout << rec() - 1 << endl;
}

mint give() {
  for (int k=0; k<=(K[0]-'0'); k++) dp[1][0][k] = 1;
  for (int n=0; n<N; n++) {
    for (int d=0; d<D; d++) {
      for (int l=0; l<=1; l++) {
        int k_upper = l ? K[n] - '0' : 9;
        for (int k=0; k<=k_upper; k++) {
          dp[l and k==k_upper][n+1][(d+k)%D] += dp[l][n][d];
        }
      }
    }
  }
  return dp[0][N][0] + dp[1][N][0] - 1;
}

void solve() {
  cout << give() << endl;
}

int main() {
  // cout.precision(15);
  input();
  // solve();
  memoRec();
  return 0;
}


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

int main() {
    int N; cin >> N;
    priority_queue<Tuple, vector<Tuple>, greater<Tuple>> que;
    auto input = [&](int t) {
        int a, b;
        cin >> a >> b;
        que.emplace(a, b, t);
    };
    rep(i, N) input(0);
    rep(i, N) input(1);
    set<int> st;
    int ans = 0;
    while(!que.empty()) {
        auto[x, y, t] = que.top(); que.pop();
        if(t == 0) {
            st.insert(y);
        } else {
            auto it = st.lower_bound(y);
            if(it == st.begin()) continue;
            st.erase(prev(it));
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3636
X, N = map(int, input().split())
p_list = sorted(list(map(int, input().split())), reverse = True)



if (not X in p_list) or (N == 0):
    ans = X
else:
    p_min, p_max = p_list[-1], p_list[0]
    if X < p_min:
        ans = p_min - 1
    else:
        m = min(abs(X - p_min), abs(X - p_max))
        for i in range(1, m + 2):
            if not X - i in p_list:
                ans = X - i
                break
            if not X + i in p_list:
                ans = X + i
                break

print(ans)







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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
    string s;
    cin >> s;
    int n = s.size();

    bool is = true;
    if( s[n-1] == '1' || s[0] != '1' || s[n-2] != '1' ) is = false;
    REP(i, n / 2)
    {
        if( s[i] != s[n-2-i] ) is = false;
    }

    if( !is ) cout << -1 << endl;
    else
    {
        REP( i, n - 1 )
        {
            int j = i;
            for(; s[j] != '1'; ++j ) 
                cout << i + 1 << " " << j + 2 << endl;
            cout << i + 1 << " " << j + 2 << endl;
            i = j;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
from collections import deque

S = input()
d = deque(S)
Q = int(input())
is_order = True
for i in range(Q):
    tmp = input()
    if len(tmp) == 1:
        t = 1
        is_order = not is_order
    else:
        t,f,c = tmp.split()
        f = int(f)
        if f == 1:
            if is_order:
                d.appendleft(c)
            else:
                d.append(c[::-1]) 
        else:
            if is_order:
                d.append(c)
            else:
                d.appendleft(c[::-1])
if is_order:
    print("".join(d))
else:
    print("".join(reversed(d)))

Measured memory_bytes: 102660
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    cin >> s;
    int cnt[3] = {};
    int n = s.length();
    for (char c : s){
        cnt[c - 'a']++;
    }
    sort(cnt, cnt+3);

    bool ok = false;
    if (n % 3 == 0){
        if (cnt[0] == cnt[1] && cnt[1] == cnt[2]) ok = true;
    }else if (n % 3 == 1){
        if (cnt[0] == cnt[1] && cnt[1] == cnt[2] - 1) ok = true;
    }else{
        if (cnt[0] == cnt[1] - 1 && cnt[1] == cnt[2]) ok = true;
    }
    cout << (ok ? "YES" : "NO") << endl;


    return 0;
}





Measured memory_bytes: 512
import Foundation

let N = Int(readLine()!)!

var money = 0.0
for _ in 0..<N {
    let input = readLine()!.componentsSeparatedByString(" ")
    if input[1] == "JPY" {
        money += Double(input[0])!
    } else {
        money += Double(input[0])! * 380000.0
    }
}

print(money)

Measured memory_bytes: 8036
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x;
    cin >> n >> m >> x;
    vector<ll> a(m);
    cins(all(a));
    int c1 = 0,c2 = 0;
    rep(i,m){
        if (a[i] < x) c1++;
        else c2++;
    }
    PRINT(min(c1,c2));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int size = S.size();
  map<char, int> count;
  for (int i = 0; i < size; i++) {
  	char tmp= S[i];
    count[tmp] += 1;
  }

  bool flag = true;
  for (auto p : count) {
    auto value = p.second;
    if (value != 2) {
      flag = false;
      break;
    }
  }
  if (flag) {
  	cout << "Yes" << endl;
  } else {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 3556
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

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

	s := scanText()

	fmt.Println(s[:4],s[4:])
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,W;
  cin >> n >> W;
  vec w(n),v(n);
  for(ll i=0;i<n;i++) cin >> w[i] >> v[i];
  ll tw=w[0];
  for(ll i=n-1;i>=0;i--) w[i]-=tw;
  mat dp(n+1,vec(3000));
  for(ll i=0;i<n;i++) {
    for(ll j=n-1;j>=0;j--) {
      for(ll k=0;k<=300;k++) {
        if(k+w[i]<=300) {
          dp[j+1][k+w[i]]=max(dp[j+1][k+w[i]],dp[j][k]+v[i]);
        }
      }
    }
  }
  ll ans=0;
  for(ll i=1;i<=n;i++) {
    if(W-i*tw<0) break;
    ans=max(ans,dp[i][min(300LL,W-i*tw)]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)
#define MAX ((ull)(1e9)+1)

int main(){
	int a, b;
	cin >> a >> b;
	if(b%a==0) cout << a+b << endl;
	else cout << b-a << endl;
	return 0;
}

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

int main() 
{
  int n,sum;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    int l,r;
    cin>>l>>r;
    sum+=r-l+1;
  }
  cout<<sum<<endl;
}
	

Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

const int N = 100500;

int c[300][300];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b, n = 100, m = 100;
    cin >> a >> b;
    cout << 100 << " " << 100 << "\n";
    a--, b--;
    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            if (i < 50)
            {
                c[i][j] = 0;
                if (b && i % 2 == j % 2 && i % 2 == 1)
                    c[i][j] = 1, b--;
            }
            else
            {
                c[i][j] = 1;
                if (i > 70 && a && i % 2 == j % 2 && i % 2 == 1)
                    c[i][j] = 0, a--;
            }
        }
    }
    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            if (c[i][j] == 0) cout << ".";
            else cout << "#";
        }
        cout << "\n";
    }
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;int f,Q,T;char S[1<<20],*x=S+(1<<18),*y;main(){for(cin>>x>>Q,y=strlen(x)+x;Q--&&cin>>T;)if(T&1)f^=1;else cin>>T,cin>>*(T-1^f?y++:--x);reverse(x,f?y:x);cout<<x;}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pip pair<int,pii>
#define F first
#define S second
#define pb push_back
#define INF 1e18
#define MOD 1000000007
#define N 1000005
#define BB(V) V[V.size()-2]
#define ex(V) return printf(V),0
using namespace std;
int a[305][305];
int chk[305][305];
vector<pip>v;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%d",a[i]+j);
		}
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(a[i][j]>a[i][k]+a[k][j])ex("-1");
				if(a[i][j]==a[i][k]+a[k][j]&&i!=k&&j!=k){
					chk[i][j]=1;
				}
			}
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(!chk[i][j])ans+=a[i][j];
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
		int i,c=0;
		char s[17];
		char t[17]="CODEFESTIVAL2016";
		scanf("%s",s);
		for(i=0;i<16;i++){
				if(s[i]!=t[i])c++;
		}
		printf("%d\n",c);
		return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    ans += (n / 500) * 1000;
    n %= 500;
    ans += (n / 5) * 5;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc173/tasks/abc173_d
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    // 降順にソートして、大きい要素から並べる
    std::sort(A.begin(), A.end(), std::greater<ll>());
    ll ans = A[0];
    if (N == 2)
    {
        cout << ans << endl;
        return 0;
    }

    for (int i = 2; i < N; ++i)
    {
        ans += A[i / 2];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A[110];
  cin >> N;
  for(int i=0; i<N; i++){
    A[i] = i + 1;
  }
  
  int a = 1,b = 0;
  for(int i=0; i<N; i++) {
    int s = 0,t = A[i];
    while ( true ){
      if ( t%2 == 1 ) break;
        t/=2;
        s++;
    }
    if( b < s) {
      a =  A[i];
      b = s;
    }
  }
  
  cout << a << endl;
  return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 0; i < 1000; i++) {
    vector<int> num = {i/100, (i%100)/10, i%10};
    int cnt = 0;
    for (int j = 0; j < N; j++) {
      if ('0'+num[cnt] == S[j]) cnt++;
      if (cnt == 3) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int n;
int main(){
    char c;
    cin>>c;
    c+=1;
    cout<<c<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {

	int a, b;
	int d, r;
	double f;

	cin >> a >> b;

	d = a / b;
	r = a%b;
	f = 1.00000 * a / b;

	printf("%d %d %.5lf\n", d, r, f);
}

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

int main(){

  int N, a;
  cin >> N;
  
  a = N / 100;
  
  if(a * 111 >= N) cout << a * 111 << endl;
  else cout << (a + 1) * 111 << endl;
  
  return 0;
  
}

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

using namespace std;

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

	int count = 0;

	for(int i=a;i<=b;i++)
	{
		string s;
		s = to_string(i);
		string sr = s;
		reverse(sr.begin(),sr.end());

		if(s==sr)count++;
	}

	cout << count << endl;
}

Measured memory_bytes: 256
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;

inline double sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
// }}}


signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	vector<pii> vec(m);
	rep(i,m){
		cin >> vec[i].first >> vec[i].second;
	}
	map<pii,string> mp;
	auto py = vec;
	sort(all(py));
	vector<int> cnt(n+1);
	rep(i,m){
		string s;
		int a = py[i].first;
		++cnt[a];
		int b = cnt[a];
		for(int j = 0;j < 6-to_string(a).size();++j){
			s += "0";
		}
		s += to_string(a);
		for(int j = 0;j < 6-to_string(b).size();++j){
			s += "0";
		}
		s += to_string(b);
		mp[make_pair(py[i].first,py[i].second)] = s;
	}
	rep(i,m){
		cout << mp[make_pair(vec[i].first,vec[i].second)] << '\n';
	}



	return 0;	
}


Measured memory_bytes: 17152
n = int(input())
s = input()
P = [0]

for k in s:
    P.append(P[-1] + (k=="W"))

ans = n

for i in range(n):
    temp = (n-i-1) - (P[n] - P[i+1])
    temp += P[i]
    ans = min(ans,temp)
    
print(ans)


Measured memory_bytes: 15520
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(double &x){
  int k;
  int m=0;
  int p=0;
  double r = 1;
  x = 0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m = 1;
      break;
    }
    if(k=='.'){
      p = 1;
      break;
    }
    if('0'<=k&&k<='9'){
      x = k - '0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k=='.'){
      p = 1;
      continue;
    }
    if(k<'0'||k>'9'){
      break;
    }
    if(p){
      r *= 0.1;
      x += r * (k - '0');
    }
    else{
      x = x * 10 + k - '0';
    }
  }
  if(m){
    x = -x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
  return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
  WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
  const int d = WRITER_DOUBLE_DIGIT;
  int k;
  int r;
  double v;
  if(x!=x || (x==x+1 && x==2*x)){
    my_putchar_unlocked('E');
    my_putchar_unlocked('r');
    my_putchar_unlocked('r');
    return;
  }
  if(x < 0){
    my_putchar_unlocked('-');
    x = -x;
  }
  x += 0.5 * pow(0.1, d);
  r = 0;
  v = 1;
  while(x >= 10*v){
    v *= 10;
    r++;
  }
  while(r >= 0){
    r--;
    k = floor(x / v);
    if(k >= 10){
      k = 9;
    }
    if(k <= -1){
      k = 0;
    }
    x -= k * v;
    v *= 0.1;
    my_putchar_unlocked(k + '0');
  }
  if(d > 0){
    my_putchar_unlocked('.');
    v = 1;
    for(r=(0);r<(d);r++){
      v *= 0.1;
      k = floor(x / v);
      if(k >= 10){
        k = 9;
      }
      if(k <= -1){
        k = 0;
      }
      x -= k * v;
      my_putchar_unlocked(k + '0');
    }
  }
}
int main(){
  double R;
  rd(R);
  wt_L(2*PI*R);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200430-1

// --- original code ---
// {
//   double R;
//   rd(R);
//   wt(2*PI*R);
// }


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

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

  vector<int> A(N);

  vector<vector<int>> x(N,vector<int>(N,0));

  vector<vector<int>> y(N,vector<int>(N,0));

  rep(i,N){
    cin >> A.at(i);
    rep(j,A.at(i)){
      cin >> x.at(i).at(j)>>y.at(i).at(j);
    }
  }//入力終了

  int ans=0;

  for(int bit=0;bit<(1<<N);bit++){//bit全探索
    vector<bool> honest(N,false);//正直者かどうか

    for(int i=0;i<N;i++){//正直者を定義
      if(bit&(1<<i))honest.at(i)=true;
    }

    bool con=true;//矛盾が起きないか

    for(int i=0;i<N;i++){//正直者の証言が矛盾しないかどうか確認
      if(honest.at(i)==false) continue;//正直者でない(不親切な人)場合はスルー
      for(int j=0;j<A.at(i);j++){//正直者の証言をすべて照らし合わせる
        int X=x.at(i).at(j)-1,Y=y.at(i).at(j);//1.2.3...番目を0.1.2...番目に変換
        if(honest.at(X)!=Y) con=false;
      }
     
    }
    
    if(con){
    int count=0;//正直者の数

    for(int i=0;i<N;i++){//正直者の数をカウント
      if(honest.at(i)) count++;
    }
    
    ans=max(ans,count);
    }

  }

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

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

#define db(x) if(debug) cout << x << endl

bool debug = true;

using namespace std;

int A[100];
int m, n;
int total;

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

	
	cin >> n >> m;
	total = 0;
	for(int i = 0; i < n; i++){
		cin >> A[i];
		total += A[i];
	}
	int popular = 0;
	for(int i = 0; i < n; i++){
		if(A[i] * m * 4 >=  total)	popular++;
	}

	if(popular >= m){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int K = scanner.nextInt();
    for (int i = 0; i < K; i++) {
      if (i % 2 == 0) {
        B += A / 2;
        A /= 2;
      } else {
        A += B / 2;
        B /= 2;
      }
    }
    System.out.printf("%d %d\n", A, B);
  }
}


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

// main
int main(){
    string str;
    cin >> str;
    int count = 0;

    if(str[0] == '1')count++;
    if(str[1] == '1')count++;
    if(str[2] == '1')count++;

    cout << count << "\n";

    return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())
left = ""
right = ""


def s_add(r, f):
    if r % 2 == 0:
        if f == 1:
            return True
        else:
            return False
    else:
        if f == 1:
            return False
        else:
            return True


cnt = 0
for _ in range(q):
    query = input()
    if query == "1":
        cnt += 1
    else:
        z, f, c = query.split()
        if s_add(cnt, int(f)):
            left += c
        else:
            right += c

if cnt % 2 == 0:
    print(left[::-1] + s + right)
else:
    print(right[::-1] + s[::-1] + left)


Measured memory_bytes: 4412