akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
	int check(int,int,int,int) ,c, n[4];
	scanf("%d %d %d %d",&n[0], &n[1], &n[2], &n[3]);
	
	if(n[0]!=1 && n[0]!=7 && n[0]!=9 && n[0]!= 4){
		c = 0;
	}else if((n[1]!=1 && n[1]!=7 && n[1]!=9 && n[1]!= 4)||(n[0]==n[1])){
		c = 0;
	}else if((n[2]!=1 && n[2]!=7 && n[2]!=9 && n[2]!= 4)||(n[2]==n[1])||(n[2]==n[0])){
		c = 0;
	}else if((n[3]!=1 && n[3]!=7 && n[3]!=9 && n[3]!= 4)||(n[3]==n[1])||(n[3]==n[0])||(n[3]==n[2])){
		c = 0;
	}else c = 1;
	
	if(c==1) printf("YES");
	else printf("NO");
}


		

	

Measured memory_bytes: 128
#include <stdio.h>
 
int main(){
    int sum = 0;
    char ch;
 
    while(true)
    {
        while((ch = getchar()) != '\n'){
            sum += ch - '0';
        }
        if(sum == 0)
            break;
        else{
            printf("%d\n",sum);
            sum = 0;
        }
    }
}


Measured memory_bytes: 2616
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		boolean twoCol;
		int size;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int m = in.nextInt();
			List<Integer>[] adj = new List[n];
			for (int i = 0; i < n; i++) {
				adj[i] = new ArrayList();
			}
			for (int i = 0; i < m; i++) {
				int a = in.nextInt() - 1;
				int b = in.nextInt() - 1;
				adj[a].add(b);
				adj[b].add(a);
			}
			int[] col = new int[n];
			long numNonTwoCol = 0;
			long numTwoCol = 0;
			long numSizeOne = 0;
			List<Integer> sizes = new ArrayList<>();
			List<Boolean> twoC = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				if (col[i] == 0) {
					twoCol = true;
					size = 0;
					dfs(i, 1, col, adj);
					sizes.add(size);
					twoC.add(twoCol);
					if (size == 1) {
						++numSizeOne;
					} else if (twoCol) {
						++numTwoCol;
					} else {
						++numNonTwoCol;
					}
				}
			}
			long ans = 0;
			for (int i = 0; i < sizes.size(); i++) {
				int size = sizes.get(i);
				boolean tc = twoC.get(i);
				if (size == 1) {
					ans += n;
					continue;
				}
				if (tc) {
					ans += numNonTwoCol + numSizeOne * size + 2 * numTwoCol;
				} else {
					ans += numNonTwoCol + numSizeOne * size + numTwoCol;
				}
			}
			out.println(ans);
		}

		private void dfs(int v, int c, int[] col, List<Integer>[] adj) {
			col[v] = c;
			++size;
			for (int u : adj[v]) {
				if (col[u] == 0) {
					dfs(u, 3 - c, col, adj);
				} else if (col[u] != 3 - c) {
					twoCol = false;
				}
			}
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 82608
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vector<ll> A = {1,
                    1,
                    1,
                    2,
                    1,
                    2,
                    1,
                    5,
                    2,
                    2,
                    1,
                    5,
                    1,
                    2,
                    1,
                    14,
                    1,
                    5,
                    1,
                    5,
                    2,
                    2,
                    1,
                    15,
                    2,
                    2,
                    5,
                    4,
                    1,
                    4,
                    1,
                    51};

    print(A[N - 1]);

    return 0;
}

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

int main(void){
  long int cookie = 1,a,k,b;
  cin >> k >> a >> b;
  if(b - a <= 2){
    cout << k + 1 << endl;
    return 0;
  }
  else{
    while(k != 0){
      if(cookie >= a && k >= 2){
        cookie += (b - a);
        k -= 2;
      }
      else{
        cookie++;
        k--;
      }
    }
  }
  cout << cookie << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define timesave ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

void solve()
{
    int n, k;

    cin >> n >> k;

    int sum = 0;

    int arr[n+5];
    for(int i = 1; i <= n; i++) cin >> arr[i];

    sort(arr+1, arr+n+1);

    for(int i = 1; i <= k; i++) sum += arr[i];

    cout << sum << "\n";
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //timesave; 

    int tc = 1;
    //cin >> tc;
    while(tc--	) solve();
 
    return 0;
}

Measured memory_bytes: 3632
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
import random

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

a,b,c = map(int, input().split())
print(int(a*b/2))
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#


Measured memory_bytes: 14296
#include<stdio.h>

int gcd(long a,long b);

int main()
{
  long A,B;
  long g,ans;

  scanf("%ld",&A);
  scanf("%ld",&B);

  if(A > B){
    g = gcd(A,B);
  }
  else{
    g = gcd(B,A);
  }
 
  ans = (A*B)/g;

  printf("%ld",ans);

}

int gcd(long a,long b){
  int s;
  while(a%b != 0){
    s = b;
    b = a%b;
    a = s;
  }
    
  return b;
}
  
  


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

int main(){
    string s;
    int n,k;

    cin >> n>>k>>s;
    k--;
    if(s[k]=='A')s[k]='a';
    if(s[k]=='B')s[k]='b';
    if(s[k]=='C')s[k]='c';

    cout << s <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;
const int inf = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<double> p(N);
    cin >> p;
    vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= i + 1; j++) {
            int ni = i + 1;
            dp[ni][j] += dp[i][j] * p[i];
            dp[ni][j + 1] += dp[i][j] * (1 - p[i]);
        }
    }
    double ans = 0;
    for (int i = 0; i < ((double)N / 2); i++) {
        ans += dp[N][i];
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 70656
import copy
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
dic = {}
q = copy.copy(p)
q.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[q[i][0]] += 1
    dic[q[i][1]] = cnt[q[i][0]]
for i in range(m):
    print(str(p[i][0]).zfill(6)+str(dic[p[i][1]]).zfill(6))

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

void solve(
        vector<vector<char>> &grid,
        vector<vector<int>> &res,
        int top,
        int bottom,
        int &num) {
    int H = (int)grid.size(), W = (int)grid[0].size();
    vector<int> columns;
    for (int i = top; i <= bottom; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '#') columns.push_back(j);
        }
    }

    sort(columns.begin(), columns.end());
    for (int i = 0; i < columns.size(); i++) {
        int left = 0, right = W - 1;
        if (i >= 1) left = columns[i - 1] + 1;
        if (i < columns.size() - 1) right = columns[i];

        num++;
        for (int row = top; row <= bottom; row++) {
            for (int col = left; col <= right; col++) {
                res[row][col] = num;
            }
        }
    }
}

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> grid(H, vector<char>(W));
    vector<int> cnt(H);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> grid[i][j];
            if (grid[i][j] == '#') cnt[i]++;
        }
    }

    vector<vector<int>> res(H, vector<int>(W));

    vector<int> rows;
    for (int i = 0; i < H; i++) {
        if (cnt[i]) rows.push_back(i);
    }

    int num = 0;
    for (int i = 0; i < rows.size(); i++) {
        int top = 0, bottom = H - 1;
        if (i >= 1) top = rows[i - 1] + 1;
        if (i < rows.size() - 1) bottom = rows[i];

        solve(grid, res, top, bottom, num);
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

#define ll long long
const int INF = 1e9;
const int MAXN = 1000005;


class BIT {
private:
	int n;
	vector<int> t;

public:
	BIT(int _n) {
		n = _n;
		t.assign(n, 0);
	}

	int sum(int pos) {
		int result = 0;
		for(int i = pos; i >= 0; i = (i & (i+1)) - 1) {
			result += t[i];
		}
		return result;
	}

	int sum(int le, int ri) {
		return sum(ri) - (le > 0 ? sum(le-1):0);
	}

	void update(int pos, int delta) {
		for(int i = pos; i < n; i = (i | (i+1))) {
			t[i] += delta;
		}
	}
};



class TaskF {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int n, q;
		cin >> n >> q;
		vector<int> nums(n);
		vector<vector<int>> all(n+1);
		vector<int> currPos(n, 0);
		for(int i = 0; i < n; i++) {
			cin >> nums[i];
			all[nums[i]].push_back(i);
		}
		vector<int> x(q), y(q);
		vector<vector<int>> queries(n);
		vector<int> ans(q);
		for(int i = 0; i < q; i++) {
			cin >> x[i] >> y[i];
			x[i]--; y[i]--;
			queries[x[i]].push_back(i);
		}
		BIT bit(n);
		for(int i = 1; i <= n; i++) {
			if(!all[i].empty()) {
				bit.update(*all[i].begin(), +1);
				currPos[i]++;
			}
		}
		for(int i = 0; i < n; i++) {
			for(int queryPos : queries[i]) {
				ans[queryPos] = bit.sum(x[queryPos], y[queryPos]);
			}
			bit.update(all[nums[i]][currPos[nums[i]]-1], -1);
			if(currPos[nums[i]] < all[nums[i]].size()) {
				bit.update(all[nums[i]][currPos[nums[i]]], +1);
				currPos[nums[i]]++;
			}
		}
		for(int i = 0; i < q; i++) {
			cout << ans[i] << endl;
		}

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	srand(time(NULL));
	ios_base::sync_with_stdio(false);
	TaskF solver;
	solver.solve();
	return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  
  vector<int> dp(N, INF);
  dp.at(0) = 0;
  for (int i = 1; i < N; i++) {
    for (int j = 1; j <= K; j++) {
      if (i - j < 0) break;
      dp.at(i) = min(dp.at(i), dp.at(i - j) + abs(h.at(i) - h.at(i - j)));
    }
  }
  
  cout << dp.at(N - 1) << endl;
  
  return 0;
}

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

#define right true
#define left false

int main(){
  map<char, bool> a;
  a['q'] = right;
  a['w'] = right;
  a['e'] = right;
  a['r'] = right;
  a['t'] = right;
  a['a'] = right;
  a['s'] = right;
  a['d'] = right;
  a['f'] = right;
  a['g'] = right;
  a['z'] = right;
  a['x'] = right;
  a['c'] = right;
  a['v'] = right;
  a['b'] = right;
  a['y'] = left;
  a['u'] = left;
  a['i'] = left;
  a['o'] = left;
  a['p'] = left;
  a['h'] = left;
  a['j'] = left;
  a['k'] = left;
  a['l'] = left;
  a['n'] = left;
  a['m'] = left;
  string s;
  while(cin >> s, s != "#"){
    int count = 0;
    bool flag = a[s[0]];
    for(unsigned int i = 1; i < s.size(); ++i){
      if(flag != a[s[i]]){
        flag = !flag;
        count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main(){
  long long N, A, B, div, a, out;
  cin >> N >> A >> B;
  div = N / (A + B);
  a = N % (A+B);
  out = div*A + min(a, A);
  cout << out << endl;
}

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

int main(){
    string s;
    cin >> s;
    if(s == "zyxwvutsrqponmlkjihgfedcba")cout << -1 << endl;
    else if(s.size() == 26){
        int cnt = 1;
        for(int i=s.size()-2;i>=0;--i){
            if(s[i] > s[i+1])cnt++;
            else break;
        }
        bool used[28] = {0};
        for(int i=0;i<s.size()-cnt;++i){
            used[s[i]-'a'] = true;
        }
        for(int i=0;i<s.size()-cnt-1;++i)cout << s[i];
        for(char c='a';c<='z';++c){
            if(!used[c-'a'] && s[s.size()-cnt-1] < c){
                cout << c << endl;
                break;
            }
        }
    }else{
        bool used[28] = {0};
        for(int i=0;i<s.size();++i){
            used[s[i]-'a'] = true;
        }
        cout << s;
        for(char c='a';c<='z';++c){
            if(!used[c-'a']){
                cout << c << endl;
                break;
            }
        }
    }

    return 0;
}


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

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

int main() {
  ull X,Y;
  ull ans = 0;
  cin>>X>>Y;
  ull a = X;
  DUMP(X);
  DUMP(Y);
  DUMP(a);

  while(a <= Y){
    a *= 2;
    ans++;
  }

  cout<<ans<<endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

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

  string s;
  cin >> s;

  if (n%2 != 0) {
    cout << "No" << endl;
    return 0;
  }

  string a, b;
  for (ll i = 0; i < n/2; ++i) {
    a+= s[i];
  }
  for (ll i = n/2; i < n; ++i) {
    b+= s[i];
  }

  if (a == b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl; 
  }

  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define REP(i, n) for (LL i = 0; i < (LL)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(),0)
#define vLL(v,n) vector<LL> v(n); REP(i,n)cin>>v[i];
#define vstr(v,n) vector<string> v(n); REP(i,n)REP(i,n)cin>>v[i];
LL INF = 1e9 + 1;
LL MOD = 1e9+7;
  LL a,b,c,d,e,n,m,l,r,x,y,z,ans=-INF,ans2=0,count;
string s,S,t;
int main() {
cin >> a >> b >> c >>d;
cout << max(a*c,max(max(a*d,c*b),b*d));
  return 0;
}

Measured memory_bytes: 3564
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	cout<<"case #" << x << ": " << endl
#define DEBUG 0
const int inf = 1e9;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };

int main() {
	int k;	cin >> k;
	vector<ll> a(k);
	rep(i, k)	cin >> a[i];
	ll sml = 2, big = 2;
	rrep(i, k) {
		// sml以上でa[i]の倍数となる最小の数
		sml += sml%a[i] == 0 ? 0 : a[i] - (sml%a[i]);
		// big以下でa[i]の倍数となる最大の数+(a[i]-1)
		big += (a[i] - 1) - (big%a[i]);
		if (big < sml) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << sml << " " << big << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
using namespace std;
int a[200001],b[200001],c[200001];
int main(void){
	int n,m,k,root[100001],size[100001],bu[100001],i,j,gyo,x,y;
	cin>>n>>m>>k;
	for(i=1;i<=n;i++){
		root[i]=i; size[i]=1; bu[i]=0;
	}
	for(i=1;i<=k;i++) cin>>a[i]>>b[i]>>c[i];
	gyo=0;
	for(i=1;i<=k;i++){
		if(a[i]==1){
			x=root[b[i]]; y=root[c[i]];
			while(root[x]!=x) x=root[x];
			while(root[y]!=y) y=root[y];
			if(bu[x]!=bu[y]&&bu[x]!=0&&bu[y]!=0){
//				cout<<"1 "<<i<<endl;
				gyo=i;
				break;
			}
			else if(x!=y){
				if(size[x]>size[y]){
					root[y]=x;
					if(bu[y]!=0) bu[x]=bu[y];
				}
				else if(size[x]<size[y]){
					root[x]=y;
					if(bu[x]!=0) bu[y]=bu[x];
				}
				else {
					root[x]=y;
					size[y]++;
					if(bu[x]!=0) bu[y]=bu[x];
				}
			}
		}
		if(a[i]==2){
			x=root[b[i]];
			while(root[x]!=x) x=root[x];
			if(bu[x]==0) bu[x]=c[i];
			else if(bu[x]!=c[i]){
//				cout<<"2 "<<i<<endl;
				gyo=i;
				break;
			}
		}
	}
	cout<<gyo<<endl;
	return 0;
}

Measured memory_bytes: 6580
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e5;
int nd=2;
string s;vector<int>v;
vector<pair<int,int> >ed;
void inv(void)
{
  cout<<-1<<endl,exit(0);
}
void dfs(int node,int sz,int pt)
{
  if(sz==1)return ;sz--;
  while(sz)
  {
    while(pt>=0&&v[pt]<=sz)
    {
      ++nd;ed.push_back({node,nd});
      dfs(nd,v[pt],pt-1);sz-=v[pt];
    }
    pt--;
  }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  cin>>s;
  if(s.back()=='1'||s[0]=='0')inv();
  for(int i=0;i<s.size()-1;i++)
  {
    if(s[i]=='0')continue;
    if(s[s.size()-i-2]!='1')inv();
    v.push_back(i+1);
  }
  ed.push_back({1,2});
  dfs(2,v.back(),v.size()-2);
  for(auto x:ed)
  {
    cout<<x.first<<" "<<x.second<<endl;
  }
  return 0;
}


Measured memory_bytes: 9028
def calc(A):
    # 10 ** 12 <= 2進数 40桁くらい
    A += 1
    cnt = 0
    ans = 0
    # i桁目の偶奇を調べる
    for i in range(50):
        # 0桁目 => 周期2 0,1,0,1
        # 1桁目 => 周期4 0,0,1,1,0,0,1,1
        # 2桁目 => 周期8 0,0,0,0,1,1,1,1
        loop = pow(2,i+1)

        # まず割り切れる部分のみを計算する
        cnt = (A // loop) * (loop // 2)

        # 端数部分を計算する
        if (A % loop) - (loop // 2) > 0:
            cnt += (A % loop) - (loop // 2)
        
        # 計算した桁数の1の数が奇数だったら足し算
        if cnt % 2 == 1:
            ans += 1 << i
    return ans


def main():
    A, B = map(int, input().split())

    print(calc(A-1)^calc(B))


main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
int main()
{
    using namespace std;

    int n,k;
    string s;
    cin >> n;
    cin >> s;
    cin >> k;
    for(int i=0;i<n;i++){
        if(s[i] != s[k-1]){
            cout << "*";
            continue;
        }
        cout << s[i];
    }
    cout << "\n";

    return 0;
}

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

using namespace std;

const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;
int n, m;

char s[maxn];

int sum[maxn];
int last[maxn];

long long dp[maxn][maxn], res;

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

    cin >> n >> m;

    cin >> s + 1;

    for(int i=1;i<=n;++i)
    {
        sum[i] = sum[i-1];
        if( s[i] == '1' ) sum[i] ++;
    }

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

    for(int i=1;i<=m;++i)
    {
        int x, y;
        cin >> x >> y;
        last[x] = max(last[x], y);
    }
    for(int i=1;i<=n;++i) last[i] = max(last[i], last[i-1]);

    dp[0][0] = 1;

    for(int i=1;i<=n;++i)
    {
        int tung = last[i];
        if(tung - i + 1 > sum[tung] )  dp[i][0] = dp[i-1][0] % mod;

        for(int j=1;j<=i;++j)
        {
            if( tung - i + 1 > sum[tung] - j ) dp[i][j] = dp[i-1][j] % mod;
            if( sum[tung] >= j ) dp[i][j] = ( dp[i][j] + dp[i-1][j-1] ) % mod;
        }
    }

    for(int i=1;i<=n;++i) res = ( res + dp[n][i] ) % mod;

    cout << res;
}


Measured memory_bytes: 49760
from numba import njit
k = int(input())

l = 0
if k % 7 == 0:
    l = 9 * k // 7
else:
    l = 9 * k

@njit
def fun():
    m = 1
    for i in range(1, l + 1):
        m = m * 10 % l
        if m == 1:
            print(i)
            break
    else:
        print(-1)

fun()


Measured memory_bytes: 108764
from collections import Counter
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
if (len(c) == 1 and c[0] == n) or (len(c) == 2 and c[0] == n//3 and c[max(c.keys())] == 2*n//3) or (len(c) == 3 and reduce(lambda x, y: x^y, c.keys()) == 0 and set(c.values()) == set([n//3])):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 60784
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] d = new int[N];
		for(int i = 0; i < N; i++)
			d[i] = sc.nextInt();
		Arrays.sort(d);
		int ans = d[N/2] - d[N/2-1];
		System.out.println(ans <= 0 ? 0 : ans);

	}

}


Measured memory_bytes: 51904
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a,b;
	char A,B;
	string ans="No";
	cin>>a>>b;
	int c[50][50]={},d[50][50]={};
	lp2(i,a){
		lp2(j,a){
			cin>>A;
			if(A=='#')c[i][j]=1;
			else c[i][j]=2;
		}
	}
	lp2(i,b){
		lp2(j,b){
			cin>>B;
			if(B=='#')d[i][j]=1;
			else d[i][j]=2;
		}
	}
	lp2(i,a){
		lp2(j,a){
			if(c[i][j]==d[0][0]){
				int cnt=1;
				lp3(k,0,b){
					if(k==0){
						lp3(l,1,b){
						if(c[i+k][j+l]==d[k][l])cnt++;
						}
					}
					else{
					lp3(l,0,b){
						if(c[i+k][j+l]==d[k][l])cnt++;
					}
				}
				}
				if(cnt==b*b){
					ans="Yes";
					break;
				}
			}
		}
		if(ans=="Yes")break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
const long long INF = 1LL <<60;  
 
int main(void){
  long long res=0;
  long long x;
  long long tmp1,tmp2;

  cin>>x;
  tmp1=x/11;
  res=2*tmp1;
  tmp2=x%11;
  if(tmp2==0){
  }
  else if(tmp2<=6){
    res+=1;
  }
  else{
    res+=2;
  }
  
  
  
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3632
module priority_queue
    use,intrinsic :: iso_fortran_env
    type heap
        integer(int64):: i
        integer(int64), allocatable:: v(:)
    end type
    private
    public:: heap
    public:: init_heap
    public:: append_heap
    public:: pop_heap

contains
    subroutine init_heap(h)
        type(heap):: h
        h%i=0
        allocate(h%v(1))
    end subroutine

    subroutine append_heap(h,x)
        type(heap):: h
        integer(int64):: x
        if (h%i+1 >= size(h%v)) call add(h)
        h%i=h%i+1
        h%v(h%i) = x
        call heap_up(h,h%i)
    end subroutine

    function pop_heap(h) result(v)
        type(heap):: h
        integer(int64):: v
        v=h%v(1)
        h%v(1) = h%v(h%i)
        h%i=h%i-1
        call heap_down(h,1_8)
    end function

    subroutine add(h)
        type(heap):: h
        integer(int64):: l
        integer(int64), allocatable:: tmp(:)
        l = size(h%v)
        allocate(tmp(l))
        tmp(:) = h%v(:)
        deallocate(h%v)
        allocate(h%v(l*2))
        h%v(1:l) = tmp(:)
        deallocate(tmp)
    end subroutine

    recursive subroutine heap_up(h,self)
        type(heap):: h
        integer(int64):: self
        if (self == 1) return

        if (h%v(self) > h%v(self/2))then
            call swap(h%v(self),h%v(self/2))
            call heap_up(h,self/2)
        end if
    end subroutine

    recursive subroutine heap_down(h,self)
        type(heap):: h
        integer(int64):: self,c1,c2

        c1 = self*2
        c2 = c1+1
        if (c2 <= h%i) then
            if (h%v(c1) >= h%v(c2)) then
                if (h%v(c1) > h%v(self)) then
                    call swap(h%v(c1),h%v(self))
                    call heap_down(h,c1)
                end if
            else
                if (h%v(c2) > h%v(self)) then
                    call swap(h%v(c2),h%v(self))
                    call heap_down(h,c2)
                end if
            end if
        else if (c1 <= h%i) then
            if (h%v(c1) >= h%v(self)) then
                call swap(h%v(c1),h%v(self))
                call heap_down(h,c1)
            end if
        else
            return
        end if
    end subroutine

    subroutine swap(x,y)
        integer(int64):: x,y,t
        t=x; x=y; y=t
    end subroutine
end module

program abc141
    use,intrinsic :: iso_fortran_env
    use priority_queue
    implicit none
    integer(int64):: n,m,i,ans
    integer(int64), allocatable:: ia(:)
    type(heap):: a

    call init_heap(a)
    read*, n,m
    allocate(ia(n))
    read*, ia(:)
    do i=1,n
        call append_heap(a,ia(i))
    end do

    do i=1,m
        call append_heap(a,pop_heap(a)/2)
    end do
    
    ans=0
    do i=1,n
        ans=ans+pop_heap(a)
    end do
    print'(i0)', ans
    
end program abc141

Measured memory_bytes: 2648
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        //System.setIn(Main.class.getResourceAsStream("input"));
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        long h = sc.nextLong();
        long monsters = 1;
        long attacks = 0;
        while(h > 0) {
            attacks += monsters;
            monsters <<= 1;
            h >>= 1;
        }
        System.out.println(attacks);
    }

    private static int nextInt(Scanner sc) {
        return Integer.valueOf(sc.nextLine());
    }

    private static int[] toArray(String text) {
        return Arrays.stream(text.split("\\s")).mapToInt(Integer::valueOf).toArray();
    }

}

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

using namespace std;

#define ll          long long int
#define endl        '\n'
#define pii         pair <int, int>
#define mk          make_pair

static const int maxn = 2e5 + 5;

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);


      int n, m;
      cin >> n >> m;
      int sum = 0;
      for (int i = 0; i < m; i++)
      {
            int x;
            cin >> x;
            sum += x;
      }
      int ans = n - sum;
      cout << max(-1, ans) << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#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 pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    int n, m, q;
    string poyo = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    while (cin >> n >> m >> q && n) {
        VVI a(n, VI(m,1));
        VI l(m);
        while (q--){
            string s, t;
            cin >> s >> t;
            REP(j,m){
                int x = t[j] - '0';
                x ^= l[j];
                l[j] = (t[j] - '0');
                REP(i,n){
                    int y = s[i] - '0';
                    y ^= (x ^ 1);
                    a[i][j] &= y;
                }
            }
        }
        REP(j,m){
            char c;
            int p = 0;
            REP(i,n){
                if (a[i][j]){
                    c = poyo[i];
                    p++;
                }
            }
            if (p == 1) cout << c;
            else cout << '?';
        }
        cout << endl;
    }

    return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1000000007;

int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, q, x, K;
string s, t;
// <------------- Implement Functions Here ----------> //

ll val(ll k) {
	ll cou = 0;
	while(k%2==0) {
		cou++;
		k/=2;
	}
	return cou;
}

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	vll a(n);
	for(ll i=0;i<n;i++) {
		cin>>x;
		a[i] = val(x);
	}	 	
	sort(all(a));
	cout<<accumulate(all(a),0);
}


int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3708
#include <cstdio>
#include <algorithm>

using namespace std;

int step;

int gcd(int x, int y)
{
	if (x < y) swap(x, y);
	if (y == 0) return (x);
	step++;
	return (gcd(y, x % y));
}

int main()
{
	int a, b;
	
	while (scanf("%d %d", &a, &b) && a){
		step = 0;
		int ans = gcd(a, b);
		printf("%d %d\n", ans, step);
	}
	return (0);
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << 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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ld pi = 3.14159265358979;
  ld a, b, x;
  cin >> a >> b >> x;
  if(2*x<=a*a*b){
    ld c = 2 * x / (a * b);
    ld d = b/c;
    ld e = atan(d);
    ld angle=(ld)180 * e / pi;
    cout << fixed << setprecision(10) << angle << endl;
  }
  else{
    x = a * a * b - x;
    ld c = 2 * x / (a * a);
    ld d = c/a;
    ld e = atan(d);
    ld angle=(ld)180 * e / pi;
    cout << fixed << setprecision(10) << angle << endl;
  }
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ld e[307][307][307];
int main()
{
    int n;
    cin>>n;
    int a[n];
    int cnt[4];
    for(int i=0;i<4;i++)cnt[i]=0;
    for(int i=0;i<n;i++){
            cin>>a[i];
            cnt[a[i]]++;
    }
    for(int i=0;i<307;i++){
        for(int j=0;j<307;j++){
            for(int k=0;k<307;k++){
                e[i][j][k]=0;
            }
        }
    }
    for(int k=0;k<303;k++){
        for(int j=0;j<303;j++){
            for(int i=0;i<303;i++){
                    ld s=i+j+k;
                    if(k!=0)e[i][j][k]+=k/s*e[i][j+1][k-1];
                    if(j!=0)e[i][j][k]+=j/s*e[i+1][j-1][k];
                    if(i!=0)e[i][j][k]+=i/s*e[i-1][j][k];
                    if(s!=0)e[i][j][k]+=n/s;
            }
        }
    }
    cout<<fixed<<setprecision(14)<<e[cnt[1]][cnt[2]][cnt[3]];
}


Measured memory_bytes: 452352
use std::io::{self, BufRead};

fn main() {
    println!("{}", if solve() { "Yes" } else { "No" });
}

fn solve() -> bool {
    let mut r = io::BufReader::new(io::stdin());

    let mut buf = String::new();

    let mut a: Vec<Vec<usize>> = Vec::with_capacity(3);
    for _ in 0..3 {
        buf.clear();
        let _ = r.read_line(&mut buf).unwrap();
        a.push(buf.split(" ").map(|a| a.trim().parse().unwrap()).collect());
    }

    let _ = {
        buf.clear();
        r.read_line(&mut buf).unwrap()
    };

    let mut bs = [false; 101];
    for i in r.lines().map(|a| a.unwrap().trim().parse::<usize>().unwrap()) {
        bs[i] = true;
    }

    for i in 0..3 {
        if bs[a[i][0]] && bs[a[i][1]] && bs[a[i][2]] {
            return true;
        }
    }

    for j in 0..3 {
        if bs[a[0][j]] && bs[a[1][j]] && bs[a[2][j]] {
            return true;
        }
    }

    if bs[a[0][0]] && bs[a[1][1]] && bs[a[2][2]] {
        return true;
    }

    if bs[a[0][2]] && bs[a[1][1]] && bs[a[2][0]] {
        return true;
    }

    return false;
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

long long k,a,b;

int main()
{
    cin>>k>>a>>b;
    long long x=k-(a-1);
    if(b<=a or x<=0)
    {
        cout<<k+1<<endl;
        return 0;

    }
    cout<<max(k+1,a+(long long)((long long)x/(long long)2)*(b-a)+(long long)x%(long long)2);


    return 0;
}


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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int ans = 0;
  ans += min(A, K);
  K -= min(A, K);
  K -= min(B, K);
  ans -= min(C, K);
  K -= min(C, K);
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 3752
import java.io.*;

public class Main {
 public static void main (String[ ] args) {
  String buf;
  InputStreamReader isr = new InputStreamReader(System.in);
  BufferedReader br = new BufferedReader(isr);
  try {
   buf = br.readLine();
  } catch(Exception e) {
   buf = null;
  }

  buf = buf.replace(',', ' ');
  System.out.println(buf);
 }
}

Measured memory_bytes: 8276
#include <iostream>

using namespace std;

long long int N, A, B;
long long int c = 0;
long long int ans=0;

int main() {
	cin >> N >> A >> B;
	if (N > 1) {
		if (A <= B) {
			cout << (A + B*(N - 1) - A*(N - 1) - B + 1) << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	else
	{
		if (A < B) {
			cout << 0 << endl;
		}
		else if (A == B) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
}

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

int x[25][25];

int main(){
    int n,d; cin >> n >> d;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin >> x[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int sum=0;
            for(int k=0;k<d;k++){
                sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            for(int k=1;k<=1000;k++){
                if(k*k==sum)ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long n,a,b;
  cin >> n >> a >> b;
  long long x=n/(a+b);
  long long ans=a*x;
  if((a+b)*x+a<=n){
    ans+=a;
  }
  else{
    ans+=(n-(a+b)*x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>

int ans = 2100000000,n,k;
void dfs(int layer,int value) {
	if(layer == n) {
		if(value < ans) {
			ans = value;
		}
		return;
	}
	dfs(layer + 1,value + k);
	dfs(layer + 1,value << 1);
} 
int main(){
	scanf("%d", &n);
	scanf("%d", &k);
	dfs(0,1);
	printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
chomp (my ($n, $m) = split / /, <STDIN>);
my @p;
for my $i (0..$m-1) {
  chomp (my @in = split / /, <STDIN>);
  $p[$i] = [$i, @in];
}
@p = sort {$$a[1]<=>$$b[1] || $$a[2]<=>$$b[2]} @p;
my ($pref, $cnt) = (0, 0);
for my $i (0..$m-1) {
  if ($pref == $p[$i][1]) {
    $cnt++;
  } else {
    $pref = $p[$i][1];
    $cnt = 1;
  }
  $p[$i][3] = sprintf("%06s", $p[$i][1]) . sprintf("%06s", $cnt);
}
@p = sort {$$a[0]<=>$$b[0]} @p;
print $$_[3], "\n" for @p;

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

vector<int> vec;

void solve(int num, int nk, string str){
	if(num == -1){
		if(nk == 0){
			bool flag = false;
			for(int i = 0;i < str.size();i++){
				if(str[i] != '0'){
					flag = true;
				}
				if(flag) cout << str[i];
			}
			cout << endl;
			exit(0);
		}
		return;
	}
	
	solve(num-1, nk-vec[num], str + '+');
	solve(num-1, nk+vec[num], str + '-');
	solve(num-1, nk, str + '0');
	return;
}
	

int main(){
	int w;
	cin >> w;
	
	int n = 0;
	int three = 1;
	int now = 1;

	while(1){
		vec.push_back(now);
		three *= 3;
		now *= 3;

		if((three - 1) / 2 >= w){
			break;
		}
		n++;
	}

	solve(n, w, "");

	return 0;
}


Measured memory_bytes: 3196
N, *AS = $stdin.read.split.map(&:to_i) 

# 最大バイナリヒープ + 合計値計算 (https://beta.atcoder.jp/contests/abc062/submissions/2384957)
class Heap
  def initialize
    @a = []
    @sum = 0
  end
  attr_reader :sum

  def size
    @a.size
  end

  def push(x)
    @sum += x
    i = size
    while i > 0 do
      p = (i - 1) / 2
      break if @a[p] <= x
      @a[i] = @a[p]
      i = p
    end
    @a[i] = x
    self
  end

  # 最小の要素を取り出して返す
  def pop
    return nil if size == 0
    newsize = size - 1
    ret = @a.first
    x = @a.last
    i = 0
    while i * 2 + 1 < newsize do
      a = i * 2 + 1
      b = a + 1
      if b < newsize && @a[b] < @a[a]
        a = b
      end
      break if @a[a] >= x
      @a[i] = @a[a]
      i = a
    end
    @a[i] = x
    @a.pop
    @sum -= ret
    return ret
  end
end

try = Array.new(N+1){ [nil, nil] }

a = Heap.new; AS.first(N).each{|x| a.push(x)}
b = Heap.new; AS.last(N).each{|x| b.push(-x)}
try[0][0] = a.sum
try[N][1] = -b.sum
#p a: a, b: b
N.times do |i|
  a.push(AS[N+i])
  a.pop
  b.push(-AS[(N*2-1)-i])
  b.pop
#  p i: i, a: a, b: b
  try[i+1][0] = a.sum
  try[(N-1)-i][1] = -b.sum
end
#p try: try
p try.map{|x, y| x-y}.max


Measured memory_bytes: 32328
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define srep(i) for (int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
    using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int n, w;
int weight[105] = {}, value[105] = {};

int dp[105][10005] = {};

int main()
{
    int n,k,x,ans=0;
    cin >> n >> k;
    rep(i,0,n){
        cin>>x;
        ans += min(x*2, (k-x)*2);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.root = [-1] * (n + 1)
            self.rnk = [0] * (n + 1)

        def find_root(self, x):
            while self.root[x] >= 0:
                x = self.root[x]
            return x

        def unite(self, x, y):
            x = self.find_root(x)
            y = self.find_root(y)
            if x == y:
                return
            elif self.rnk[x] > self.rnk[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rnk[x] == self.rnk[y]:
                    self.rnk[y] += 1

        def isSameGroup(self, x, y):
            return self.find_root(x) == self.find_root(y)

        def size(self, x):
            return -self.root[self.find_root(x)]

    N, M = map(int, input().split())
    UF = UnionFind(N)
    for _ in range(M):
        a, b = map(int, input().split())
        UF.unite(a, b)

    ans = 0
    for i in range(1, N+1):
        ans = max(ans, UF.size(i))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73712
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
    int N;
    cin >> N;
    int B[N-1];
    for(int i=0;i<N-1;i++) cin >> B[i];

    int sum = 0;
    sum += B[0]+B[N-2];

    for(int i=1;i<=N-2;i++){
        sum += min(B[i-1], B[i]);
    }
    cout << sum <<endl;
    
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main() {
  int n;
  cin>>n;
  int a[200005];
  for (int i=1; i<=n; i++) {
    cin>>a[i];
  }
  int b[200005];
  for (int i=n; i>=1; i--) {
    int j=i+i;
    int sum=0;
    while (j<=n) {
      sum+=b[j];
      j+=i;
    }
    b[i]=abs(sum%2-a[i]);
  }
  int m=0;
  for (int i=1; i<=n; i++) {
    if (b[i]) m++;
  }
  cout<<m<<endl;
  for (int i=1; i<=n; i++) {
    if (b[i]) cout<<i;
    if (i==n) cout<<endl;
    else cout<<' ';
  }
  return 0;
}



Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>

int n, m;
long long int X[1000], Y[1000], Z[1000];

int main(){
  int i, j;
  long long int r;
  scanf("%d%d", &n, &m);
  for(i=0;i<n;i++) scanf("%lld%lld%lld", X+i, Y+i, Z+i);

  r = 0;
  for(j=0;j<8;j++){
    long long int W[1000];
    long long int s;
    for(i=0;i<n;i++) W[i] = (1-2*(j&1))*X[i] + (1-2*((j>>1)&1))*Y[i] + (1-2*((j>>2)&1))*Z[i];
    std::sort(W, W+n);
    s = 0;
    for(i=n-m;i<n;i++) s += W[i];
    r = std::max(r, s);
  }
  printf("%lld\n", r);
  return 0;
}


Measured memory_bytes: 128
/* Arthur Conmy / arthurconmy */
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
#include <chrono>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<int,int> pii;
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define REPb(j, d, c) for (int j = int(d); j >= int(c); j--)
#define ff first
#define ss second
#define pb push_back
#define len(x) int((x).size())
#define endl "\n"

bool is_sq[int(2e5)];

int main() // LL OR INT??
{
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	REP(i,0,1000)
	{
		if(i*i >= int(2e5)) break;
		is_sq[i*i]=1;
	}

	int n, d;
	cin>>n>>d;

	vvi coords;

	REP(i,1,n)
	{
		vi cur;

		REP(j,1,d)
		{
			int x;
			cin>>x;
			cur.pb(x);
		}

		coords.pb(cur);
	}

	int ans=0;

	REP(i,0,n-1)
	{
		REP(j,i+1,n-1)
		{
			int dis=0;

			REP(k,0,d-1)
			{
				dis += (coords[i][k]-coords[j][k])*(coords[i][k]-coords[j][k]);
			}

			if(is_sq[dis]) ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=104;
char ss[N];
bool f=true;
int main() {
	scanf("%s",ss+1);
	int n=strlen(ss+1);
	for (int i=1;i<=n;i+=2)
		if ((ss[i]^'R')&&(ss[i]^'U')&&(ss[i]^'D')) {
			f=false;
			break;
		}
	for (int i=2;i<=n;i+=2)
		if ((ss[i]^'L')&&(ss[i]^'U')&&(ss[i]^'D')) {
			f=false;
			break;
		}
	puts(f?"Yes":"No");
	return 0;
}

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

int main(int argc, char **argv)
{
	string str; cin >> str;

	ll numw{0};
	ll res{0};
	for (ll i = 0; i < (int)str.size(); ++i)
	{
		if (str[i] == 'W')
		{
			res += i - numw;
			++numw;
		}
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 640