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

vector<int> ori;
vector<int> res;
bool flag = true;

void check(int N) {
    // KEEP MOVING UNTIL ORIGINAL VECTOR IS EMPTY
    while(ori.empty() == false && flag == true) {
        // CHECK FROM THE BACK FOR THE RIGHT-MOST (THAT IS IN CORRECT POSITION)
        for(int i=ori.size()-1; i>=0; i--) {
            if(ori[i] == i) {
                res.push_back(i);
                ori.erase(ori.begin()+i);
                break;
            }
            else if(ori[i] > i) {
                flag = false;
            }
        }
    }
}

void output(int N) {
    // check for impossible case (-1)
    if(flag == false) cout << -1 << endl;
    else {
        reverse(res.begin(), res.end());
        for(int i=0; i<res.size(); i++) {
            cout << res[i] + 1 << endl;
        }
    }
}

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

    for(int i=0; i<N; i++) {
        cin >> num;
        ori.push_back(num-1);
    }
    check(N);
    output(N);
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  cout << (n == m ? "Yes" : "No") << '\n';
  return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int h,w; cin >> h >> w;
  char v[100][100];
  for(int i = 0; i < h; ++i)for(int j = 0; j < w; ++j)cin >> v[i][j];
  ll a[100][100] = {};
  a[0][0] = 0;
  if(v[0][0] == '#')a[0][0] = 1;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(i==0&&j==0)continue;
      int x = (i?a[i-1][j]:1001001001);
      int y = (j?a[i][j-1]:1001001001);
      if(v[i][j] == '.')a[i][j] = min(x,y);
      else {
	if(i&&v[i-1][j] == '.')x++;
	if(j&&v[i][j-1] == '.')y++;
	a[i][j] = min(x,y);
      }
    }
  }
  cout << a[h-1][w-1] << endl;
  return 0;
}


Measured memory_bytes: 384
import sys
from collections import defaultdict, deque
input = sys.stdin.readline
N,M= map(int,input().split())
g = defaultdict(list)

for i in range(M):
    u,v = list(map(int,input().split()))
    g[u].append(N + v)
    g[N + u].append(2*N + v)
    g[2*N + u].append(v)
S,T= map(int,input().split())

dq = deque([S])
inf = 10**15
d = [inf for i in range(3*N+1)]
d[S] = 0

while dq:
    v = dq.popleft()
    for nv in g[v]:
        if d[nv] > d[v] + 1:
            d[nv] = d[v] + 1
            dq.append(nv)

if inf == d[T]:
    print(-1)
else:
    print(d[T]//3)





Measured memory_bytes: 81152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;



int main(){
    ll X, Y;
    cin>>X>>Y;
    bool Z=true;
    if(X*2>Y)Z=false;
    if(X*4<Y)Z=false;
    if(Y%2)Z=false;
    Yes(Z);
}

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

const int MAXV = 3e5;
num fact[MAXV], ifact[MAXV];

void precomp() {
	fact[0] = 1;
	for (int i = 1; i < MAXV; i++) {
		fact[i] = fact[i-1] * i;
	}
	ifact[MAXV-1] = fact[MAXV-1].inv();
	for (int i = MAXV-2; i >= 0; i--) {
		ifact[i] = ifact[i+1] * (i+1);
	}
}

num binom(int a, int b) {
	assert(a >= b && b >= 0);
	return fact[a] * ifact[b] * ifact[a-b];
}

num grid(int a, int b) {
	return binom(a+b-2, a-1);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	precomp();
	int X, Y, A, B; cin >> X >> Y >> A >> B;
	num ans = grid(X, Y);
	for (int y = 1; y <= B; y++) {
		ans -= grid(X-A, y) * grid(A, Y-y+1);
	}
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector <pair<int, int>> v;
int n,m, ans;

int main() {
	cin >> n >> m;
	
	v.resize(m);
	for (int i = 0; i < m; i++) {
		cin >> v[i].second >> v[i].first;
	}

	sort(v.begin(), v.end());
	int t = 0;

	for (int i = 0; i < m; i++) {
		if (t <= v[i].second) {
			ans++;
			t = v[i].first;
		}
	}

	cout << ans << endl;

}

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

int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<int>x(N), y(M);
	for (int i = 0; i < N; i++) cin >> x[i];
	for (int i = 0; i < M; i++) cin >> y[i];
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	for (int i = X+1; i <= Y; i++) {
		if (x[x.size() - 1] < i && i <= y[0]) {
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=9;i++)
	{
		if(n%i)continue;
		if(n/i<10)
		{
			printf("Yes");return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		
		char[][] map = new char[h][w];
		int[][] cost = new int[h][w];
		for(int i=0;i<h;i++){
			map[i] = sc.next().toCharArray();
			Arrays.fill(cost[i], Integer.MAX_VALUE);
		}
		
		ArrayDeque<Integer> x = new ArrayDeque<Integer>();
		ArrayDeque<Integer> y = new ArrayDeque<Integer>();
		
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]=='S'){
					x.offer(j);
					y.offer(i);
					cost[i][j] = 0;
					i = h;
					j = w;
				}
			}
		}
		
		int p, q;
		int sum = 0;
		int cnt = 1;
		int[] a = new int[]{0,0,-1,1};
		int[] b = new int[]{-1,1,0,0};
		while(true){
			p = x.poll();
			q = y.poll();
			if(map[q][p]==(char)(cnt+48)){
				sum += cost[q][p];
				if(cnt==n) break;
				else{
					cnt++;
					for(int i=0;i<h;i++){
						for(int j=0;j<w;j++){
							cost[i][j] = Integer.MAX_VALUE;
						}
					}
					cost[q][p] = 0;
					x.clear();
					y.clear();
				}
			}
			
			for(int i=0;i<4;i++){
				if((i==0 && p!=0) || (i==1 && p!=w-1) || (i==2 && q!=0) || (i==3 && q!=h-1)){
					if(map[q+a[i]][p+b[i]]!='X' && cost[q][p]+1<cost[q+a[i]][p+b[i]]){
						x.offer(p+b[i]);
						y.offer(q+a[i]);
						cost[q+a[i]][p+b[i]] = cost[q][p]+1;
					}
				}
			}
		}
		System.out.println(sum);
	}	
}

Measured memory_bytes: 69572
n, k = map(int, input().split())
s = list(map(int, list(input()))) + [-1]
ls = []
stand_ls = []

tmp, cnt = s[0], 0
for x in s:
    if x != tmp:
        ls.append((tmp, cnt))
        if tmp == 0: stand_ls.append(len(ls)-1)
        cnt = 0
        tmp = x
    cnt += 1
    
if len(ls) == 1 and ls[0][0] == 1: print(ls[0][1]); exit()

def cumsum(s):
    n = len(s)
    cs = [0] * (n+1)
    for i in range(n):
        cs[i+1] = cs[i] + s[i][1]
    return cs

cum = cumsum(ls)

ans = 0
k = min(k, len(stand_ls))
for i in range(len(stand_ls) - (k-1)):
    l, r = stand_ls[i], stand_ls[i+k-1]
    if l > 0: l -= 1
    if r < len(ls)-1: r += 1
    ans = max(ans, cum[r+1] - cum[l])
print(ans)


Measured memory_bytes: 17616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++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(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    deque<char>s;
    string tmp;
    cin >> tmp;
    REP(i,tmp.size())s.push_back(tmp[i]);
    int rev = 0;
    int q;
    cin >> q;
    int onecount=0;
    REP(i,q){
        int t;
        cin >> t;
        if(t==1){
            rev ^= 1;
            onecount++;
        }else{
            int f;char c;
            cin >> f >> c;
            if((rev==0 and f == 1) or (rev==1 and f == 2)){
                s.push_front(c);
            }else{
                s.push_back(c);
            }
        }
    }
    string answer;
    REP(i,s.size()){
        answer.push_back(s.at(i));
    }
    
    if(onecount%2)reverse(ALL(answer));
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 4300
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <unordered_map>
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

int main(void)
{
    ll l, r;

    cin >> l >> r;

    if (r - l + 1 >= 2019)
    {
        cout << 0 << endl;
        ;
    }
    else
    {
        ll min_mod = 2019;

        for (ll i = l; i < r; i++)
        {
            for (ll j = l + 1; j <= r; j++)
            {

                min_mod = min(min_mod, ((i % 2019) * (j % 2019)) % 2019);
            }
        }

        cout << min_mod << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  ll cnt=0;
  for(ll i=1;i<=3500;i++){
    for(ll j=1;j<=3500;j++){
      if(4*i*j <= n*(i+j)){
        //puts("!");
        //cnt++;
        continue;
      }
      if((n*i*j)%(4*i*j-n*(i+j))==0){
        printf("%lld %lld %lld\n",i,j,(n*i*j)/(4*i*j-n*(i+j)));
        //cout << cnt << endl;
        return 0;
      }
    }
  }
  return 1;
}

Measured memory_bytes: 256
N, A, B = list(map(int, input().rstrip().split(' ')))
LIST_RESULT = []

for i in range(1, N+1):
    str_i = str(i)
    l = len(str_i)

    sum_tmp = 0
    for x in range(l):
        sum_tmp += int(str_i[x])
    if A <= sum_tmp and sum_tmp <= B:
        LIST_RESULT.append(i)

sum_result = sum(LIST_RESULT)
print(sum_result)


Measured memory_bytes: 3292
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;


typedef struct {
    int id;			// ????????????
    int parent;			// ??????????????????
    int depth;			// ??±???
    string type;		// ??????????¨????
    vector<int> l;			// ???????????????
} Node;


void calcDepth( int id, int depth );

#define MAX_N (100010)
Node node[MAX_N];
int n;
int root_id;

int main()
{
    scanf("%d", &n);

    // ?????????
    for ( int i = 0; i < n; i++ ) {
	node[i].parent = -1;
	node[i].depth  = -1;
	node[i].type   = "internal node";
    }
    
    for ( int i = 0; i < n; i++ ) {
	int k;
	int id;
	scanf("%d %d", &id, &k);
	node[id].id = id;
	if ( k == 0 ) {
	    node[id].type = "leaf";
	}
	else {
	    for ( int j = 0; j < k; j++ ) {
		int child;
		scanf("%d", &child);
		node[id].l.push_back( child );
		node[child].parent = id;
	    }
	}
    }

    // ??????????????????
    for ( int i = 0; i < n; i++ ) {
	if ( node[i].parent == -1 ) {
	    root_id = i;
	    node[i].type = "root";
	    break;
	}
    }

    calcDepth( root_id, 0 );

    for ( int i = 0; i < n; i++ ) {
	printf("node %d: parent = %d, depth = %d, %s, ", node[i].id, node[i].parent, node[i].depth, node[i].type.c_str() );
	printf("[");
	for ( int j = 0; j < node[i].l.size(); j++ ) {
	    printf("%d", node[i].l[j]);
	    if ( j < node[i].l.size() - 1 ) {
		printf(", ");
	    }
	}
	printf("]\n");
    }
    
    return 0;
}


void calcDepth( int id, int depth )
{
    node[id].depth = depth;
    if ( node[id].l.size() ) {
	for ( int i = 0; i < node[id].l.size(); i++ ) {
	    calcDepth( node[id].l[i], depth + 1 );
	}
    }
    
    return;
}

Measured memory_bytes: 11252
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] s=br.readLine().split(" ");
        int X=Integer.parseInt(s[0]);
        int Y=Integer.parseInt(s[1]);
        int A=Integer.parseInt(s[2]);
        int B=Integer.parseInt(s[3]);
        int C=Integer.parseInt(s[4]);
        PriorityQueue<Integer> a=new PriorityQueue<Integer>(1,Collections.reverseOrder());
        PriorityQueue<Integer> b=new PriorityQueue<Integer>(1,Collections.reverseOrder());
        PriorityQueue<Integer> c=new PriorityQueue<Integer>(1,Collections.reverseOrder());
        StringTokenizer st1=new StringTokenizer(br.readLine()," ");
        while(st1.hasMoreTokens()) a.add(Integer.parseInt(st1.nextToken()));
        StringTokenizer st2=new StringTokenizer(br.readLine()," ");
        while(st2.hasMoreTokens()) b.add(Integer.parseInt(st2.nextToken()));
        StringTokenizer st3=new StringTokenizer(br.readLine()," ");
        while(st3.hasMoreTokens()) c.add(Integer.parseInt(st3.nextToken()));
        for(int i=0;i<X;i++) c.add(a.poll());
        for(int i=0;i<Y;i++) c.add(b.poll());
        long sum=0;
        for(int i=0;i<X+Y;i++) sum+=c.poll();
        System.out.println(sum);
    }
}

Measured memory_bytes: 60712
#include <bits/stdc++.h>
#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)

using namespace std;

int main(){

	int w,a,b;
	cin >> w >> a >> b;

	if(a < b){
		cout << max(0,b-a-w) << endl;
	}
	else{
		cout << max(0,a-b-w) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAX 100000

using namespace std;

int s[MAX];

int binarysearch(int *s, int key, int n){
	int left,right,mid;
	left=0;
	right=n;
	while(left<right){
		mid=(left+right)/2;
		if(s[mid]==key)
		return 1;
		else if(key<s[mid])
		right=mid;
		else
		left=mid+1;
	}
	return 0;
}

int main(){
	int n,q,temp,cnt=0;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&s[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d",&temp);
		if(binarysearch(s,temp,n)){
			cnt++;
		}
	}
	printf("%d\n",cnt);
}

Measured memory_bytes: 3520
import numpy as np

n = int(input())
h = list(map(int, input().split()))

h_copy = h.copy()
h_copy.pop(0)
h_copy.append(-1)
h = np.array(h)
h_copy = np.array(h_copy)

hh = h - h_copy
hh[n-1] = -1

ans = 0
temp = 0
for i in range(n):
    if hh[i] >=0:
        temp += 1
    else:
        ans = max(ans, temp)
        temp = 0
    
print(ans)

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

bool match(char c1, char c2) { return (c1 == '?' || c2 == '?' || c1 == c2); }

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    const int OFS = 50000;
    const int LIM = 2000;
    int alen = a.length();
    int blen = b.length();
    int clen = c.length();
    vector<bool> ab(2 * OFS, true);
    vector<bool> ac(2 * OFS, true);
    vector<bool> bc(2 * OFS, true);
    for (int i = 0; i < alen; i++) {
        for (int j = 0; j < blen; j++) {
            if (!match(a[i], b[j])) ab[i - j + OFS] = false;
        }
    }
    for (int i = 0; i < alen; i++) {
        for (int j = 0; j < clen; j++) {
            if (!match(a[i], c[j])) ac[i - j + OFS] = false;
        }
    }
    for (int i = 0; i < blen; i++) {
        for (int j = 0; j < clen; j++) {
            if (!match(b[i], c[j])) bc[i - j + OFS] = false;
        }
    }

    int ans = 3 * LIM;
    for (int i = -2 * LIM; i <= 2 * LIM; i++) {
        for (int j = -2 * LIM; j <= 2 * LIM; j++) {
            if (ab[i + OFS] && ac[j + OFS] && bc[j - i + OFS]) {
                int l = min({0, i, j});
                int r = max({alen, blen + i, clen + j});
                ans = min(ans, r - l);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(x) cout << (x) << endl;
const int INF = 1e+8+7;
ll n,m;
string s,t;
int d[100],dp1[500][500],dp2[500][500];

int main(){
  ll ans = 1;
  cin >> n >> m;
  rep(i,0,n){
    ans += fmin(pow(2,i),m);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
    
  int F = 0;
  
  string color,result;
  
  for (int i =1; i <= N; i++){
  cin >> color;
  
    if(color == "Y"){
      F = 1;
  }
  }
  
  if(F == 0){
    result = "Three";
  }
  else{
    result = "Four";
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1000000007;
int n,top,i,dep[505],vis[505],j,k,ans;
int g[505][505];
void dfs(int i)
{
	int j;
	vis[i]=1;
	for(j=1;j<=n;j++)
		if(g[i][j]==0&&!vis[j])
		{
			dep[j]=dep[i]^1;
			dfs(j);
		}
}
int main()
{
	scanf("%d",&n);
	ans=n*(n-1)/2;
	for(i=1;;i++)
	{
		memset(dep,0,sizeof(dep));
		memset(vis,0,sizeof(vis));
		for(j=1;j<=n;j++)
			if(vis[j]==0)
				dfs(j);
		for(j=1;j<=n;j++)
			for(k=j+1;k<=n;k++)
				if(g[j][k]==0&&dep[j]^dep[k])
				{
					g[j][k]=g[k][j]=i;
					ans--;
				}
		if(ans==0)
			break;
	}
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
			printf("%d ",g[i][j]);
		printf("\n");
	}
}


Measured memory_bytes: 1536
import sys
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
maxmatch=n*(n-1)
day=0
q=[i for i in range(n)]
nq=[]
match=[0]*(n+1)
check=[0]*(n+1)
while q:
  day+=1
  for i in q:
    if match[i]==n-1 or check[i]==day:
      continue
    else:
      vs=a[i][match[i]]-1
      if check[vs]!=day and check[i]!=day and a[vs][match[vs]]-1==i and a[i][match[i]]-1==vs:
        match[i]+=1
        match[vs]+=1
        match[n]+=2
        check[i]=day
        check[vs]=day
        check[n]=day
        nq.append(i)
        nq.append(vs)
      
    if i==q[-1]:
      if check[n]!=day:
        print(-1)
        sys.exit()
  if match[n]==maxmatch:
    break
  q=nq[:]
  nq=[]
        
print(day)


Measured memory_bytes: 35072
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  string s;
  cin>>s;
  
  for(int i = 0; i < 12; i++)
  {
    cout << s[i];
    if(i == 3) cout << " ";
  }
  cout << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s;
  cin >> s;
  int n=s.size();
  if((n%2==0&&s[0]!=s[n-1])||(n%2==1&&s[0]==s[n-1]))cout << "Second" << endl;
  else cout << "First" << endl;
 
}


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int ans = 0, rain = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'R') {
			rain++;
		} else {
			rain = 0;
		}
		ans = max(ans, rain);
	}
	cout << ans;
}



Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K, count;
  cin >> N >> K;
 
  int h[N];
  for(int i = 0; i < N; i++) {
    cin >> h[i];
  }
  
  
  for(int i = 0; i < N; i++) {
    if(h[i] >= K) count++;
  }
  
  cout << count <<  endl;

  return 0;
}

Measured memory_bytes: 640
n,m=map(int,input().split())
a=[int(x) for x in input().split()]
l=list([0])

b=0
for i in range(0,n):
  b += a[i]
  l.append(b%m)
l.append(m)

l.sort()
t,c=0,1
for i in range(1,n+2):
  if l[i]==l[i-1]:
    c+=1
  else:
    if c!=1:
      t += c*(c-1)//2
      c=1
print(t)


Measured memory_bytes: 14224
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int x, y, z, k;
ll a[1010], b[1010], c[1010];

vector<ll>ans;


int main() {
	cin >> x >> y >> z >> k;
	for (int i = 0; i < x; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < y; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < z; i++) {
		cin >> c[i];
	}
	sort(a, a + x, greater<ll>());
	sort(b, b + y, greater<ll>());
	sort(c, c + z, greater<ll>());
	vector<ll>d;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			d.push_back(a[i] + b[j]);
		}
	}
	sort(d.begin(), d.end(), greater<ll>());
	for (int i = 0; i < min(k, x * y); i++) {
		for (int j = 0; j < z; j++) {
			ans.push_back(d[i] + c[j]);
		}
	}
	sort(ans.begin(), ans.end(), greater<ll>());
	for (int i = 0; i < k; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 43364
N = int(input())
count = 0
a = list(map(int, input().split()))
flag = False
while True:
    for i in range(len(a)):
        if a[i] == 0:
            flag = True
        if a[i]%2 == 1:
            flag = True
        if a[i]%2 == 0:
            a[i] = a[i]/2
    if flag == True:
        break
    count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define elif else if
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    VI a(n);
    FOR(i, 0, n) {
        int x, y; cin >> x >> y;
        a[i] = (x == y);
    }
    FOR(i, 0, n - 2)if (a[i] + a[i + 1] + a[i + 2] == 3) {
        print("Yes");
        return 0;
    }
    print("No");

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define ll long long

const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

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

    mint ans(m);
    ans = ans.pow(n);

    cout << ans.x << endl;
}



Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int result = 0;

        for(int i = 1; i <= n; i++){
            int res1 = i / 10000;
            int res2 = (i % 10000) / 1000;
            int res3 = (i % 1000) / 100;
            int res4 = (i % 100) / 10;
            int res5 = i % 10;

            int sum = res1 + res2 + res3 + res4 + res5;
            if(sum >= a && sum <= b){
                result = result + i;
            }
        }

        System.out.println(result);
        sc.close();
    }

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///////////////////////////////////////////////
int main(){
	int H,W; SCD2(H,W); getchar();
	static int dp[1002][1002] = {};
	static char grid[1002][1002] = {};
	FORq(i,1,H){
		FORq(j,1,W){
			scanf("%c",&grid[i][j]);
		}
		getchar();
	}

	FORq(i,1,H){
		FORq(j,1,W){
			if (grid[i][j] == '.'){
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
			}
			dp[1][1] = 1;
		}
	}

	PRINTD(dp[H][W]);
}


Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 105
using namespace std;
int X;
unsigned long long f[maxn];
inline int read()
{int x,t=1;
 char c;
 while(c=getchar(),c<'0'||c>'9')  
  if(c=='-')  
   t=-1;
 x=c-'0';
 while(c=getchar(),c>='0'&&c<='9') 
  x=x*10+c-'0';
 return x*t;
}
inline void work()
{memset(f,0,sizeof(f));
 f[0]=2;
 for(register int i=1;i<=X;i++)
  f[i]=f[i-1]*2+2;
 return;
}
int main()
{X=read();
 work();
 cout<<f[X]<<endl;
 return 0;
} 

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

int main(void){

    int n, a, b;
    cin>>n>>a>>b;
    
    int sum=0;
    
    for(int i=1; i<=n; i++){
        int t=i;
        int tsum=t%10;
        
        while(t>=10){
            t/=10;
            tsum+=t%10;
        }
        
        if(tsum>=a&&tsum<=b){
            sum+=i;
        }
    }
    
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#define N 21

using namespace std;

typedef unsigned long long ull;

int main(){
  int n, x;
  ull data[N], data_[N];
  cin >> n;
  for(int i=0; i<N; ++i) data[i] = 0;
  for(int i=0; i<n-1; ++i){
    cin >> x;
    if(i == 0){
      data[x] = 1;
      continue;
    }
    for(int j=0; j<N; ++j) data_[j] = 0;
    for(int j=0; j<N; ++j){
      if(j-x >= 0 && j-x <= 20) data_[j-x] += data[j];
      if(j+x >= 0 && j+x <= 20) data_[j+x] += data[j];
    }
    for(int j=0; j<N; ++j) data[j] = data_[j];
  }
  cin >> x;
  cout << data[x] << endl;
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    int a,b,c,e=0,z,d,f,g;
    cin>>a>>b>>c;
    z=min((a+b),(b+c));
    z=min(z,(c+a));
    cout<<z;
    return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    string s;
    cin >> s;
    int N = s.size();
    int zer, one;
    zer = one = 0;

    for (int i=0; i<N; i++){
        if (s[i] == '0')zer++;
        else one++;
    }
    if (zer ==0 or one == 0)cout << 0 << endl;
    else cout << min(zer,one)*2 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える


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

	vector<ll> a(n), b(n), c(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) cin >> c[i];

	ll count = 0;

	sort(all(a));
	sort(all(b));
	sort(all(c));

	//jを固定するとa[i] < b[j] && b[j] < c[k]　なるi, k の積ikが部分解
	rep(j, n) {
		ll key = b[j];

		//itr_a はb[j] <= a[i] なるmin_iだからそれより右はすべてa[i] < b[j]
		ll itr_a = lower_bound(all(a), key) - a.begin();
		ll itr_b = upper_bound(all(c), key) - c.begin();

		count += itr_a * (n - itr_b);
	}

	cout << count << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int cnt = 0;
    while(a >= b)b *= 2, cnt++;
    while(b >= c)c *= 2, cnt++;
    if(cnt <= k)cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const int MOD = 1e+9 + 7;

int main()
{
    int N, X, Y, Z;
    cin >> N >> X >> Y >> Z;

    long long ans = 1;
    REP(i, N) ans = ans*10 % MOD;

    int S = (1<<(X+Y+Z))-1;  // X+Y+Z-1 個前までの状態を保持しておけば十分
	int C = (1<<(Z-1))|(1<<(Y+Z-1))|(1<<(X+Y+Z-1));

    // dp[i][j]: i-1まで見たとき、直前が j で XYZ を含まない数列の数
    vector<vector<long long>> dp(N+1, vector<long long>((1<<(X+Y+Z))+1));
	dp[0][0] = 1;
    FOR(i, 1, N+1){
        REP(s, S+1){ // s: 直前の状態
            if(dp[i-1][s] == 0) continue; 
            FOR(j, 1, 11){  // i 番目が j のとき
                int sn = (s<<j)|(1<<(j-1));
                sn &= S;  // sn の bit 桁数を S 未満にする
                if((sn&C) != C){
                    dp[i][sn] += dp[i-1][s];
                    dp[i][sn] %= MOD;
                }
            }
        }
    }

    REP(i, S+1) ans = (ans-dp[N][i]) % MOD;
    cout << (ans+MOD)%MOD << endl;


    return 0;
}

Measured memory_bytes: 43520
#include<stdio.h>
int a,s,d[1001],f[1001],g[1001][1001],h,j,i;
int main(void)
{
	scanf("%d %d",&a,&s);
	for(i=0;i<a;i++){
		scanf("%d",&d[i]);
	}
	for(i=0;i<s;i++){
		scanf("%d",&f[i]);
	}
	for(i=0;i<=s;i++){
		for(j=0;j<=a;j++){
			g[i][j]=200000000;
		}
	}
	g[0][0]=0;
	for(i=0;i<s;i++){
		for(j=0;j<=a;j++){
			if(g[i][j]<g[i+1][j]){
				g[i+1][j]=g[i][j];
			}
			if(g[i+1][j+1]>g[i][j]+d[j]*f[i]&&a>=j){
				g[i+1][j+1]=g[i][j]+d[j]*f[i];
			}
		}
	}
	printf("%d\n",g[s][a]);
	return 0;
}

Measured memory_bytes: 4944
#include <iostream>
#include <string>
#include <vector>

using namespace std;


int main(void) {
	int n, m;
	cin >> n >> m;
	int ans1, ans2;
	
	ans1 = n * (n - 1) / 2;
	ans2 = m * (m - 1) / 2;


	cout << ans1 + ans2;
	return 0;
}

Measured memory_bytes: 256
package main

// 某DP, 再帰でやったらTLEになる原因がメモ化再帰しか浮かばないんだけどループでやるDPってやったことないので練習のため来ました
// ループはできたのでこっちは再帰で

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

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

var n, k int
var h []int

var dp []int

func rec(i int) int {
	if dp[i] < math.MaxInt64 {
		return dp[i]
	}
	if i == 1 {
		// 最後の一手しかない
		dp[i] = abs(h[i], h[i-1])
		return dp[i]
	}
	ret := math.MaxInt64
	// いまのとこから0を下回らないかぎり-1~-kして再帰的に答えを集める
	for j := 1; j <= k; j++ {
		if i-j < 0 {
			break
		}
		ret = min(ret, abs(h[i], h[i-j])+rec(i-j))
	}
	dp[i] = ret
	return dp[i]
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	n, k = nextInt(), nextInt()
	h = nextInts(n)
	dp = make([]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = math.MaxInt64
	}
	dp[0] = 0
	fmt.Fprint(out, rec(n-1))
}

func abs(a, b int) (ret int) {
	if a < 0 {
		a *= -1
	}
	if b < 0 {
		b *= -1
	}
	ret = a - b
	if ret < 0 {
		ret *= -1
	}
	return
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 17536
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n,p;
    cin >> n >> p;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        if(tmp%2 == 0) cnt++;
    } 
    if(cnt == n && p == 1) cout << 0 << endl;
    else if(cnt == n && p == 0) cout << (1ll << n) << endl;
    else cout << (1ll << n-1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io
    
    int n;
    cin>>n;
    int s[n];
    ll ans=0;
    int tmin=100;
    rep(i,n){
        cin>>s[i];
        ans+=s[i];
        if(s[i]%10!=0){
            tmin=min(tmin, s[i]);
        }
    }
    if(ans%10==0){
        if((ans-tmin)%10==0){
            cout<<0<<endl;
            return 0;
        }
        cout<<ans-tmin<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    int d[k];
    rep(i, k) {
        cin >> d[i];
    }

    for(int i = n; i <= 10*n; i++) {
        int flag = 0;
        int t = i;

        while(0 < t) {

            rep(j, k) {
                if(t%10 == d[j]) {
                    flag = 1;
                }
            }

            if(flag == 1) {
                break;
            }

            t /= 10;
        }

        if(flag == 0) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 764
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int MAX_V = 100001; const ll INF = 1e+15;
struct edge {int to; ll cost;};
typedef pair<ll, int> P; // 距離, 頂点
int N; ll d[MAX_V]; vector<edge> G[MAX_V];

void dijkstra(int s) {
  fill(d, d+N+1, INF); d[s] = 0;
  priority_queue<P, vector<P>, greater<P>> q;
  q.push(P(0, s));
  while(!q.empty()) {
    P p = q.top(); q.pop();
    int now = p.second;
    if(d[now] < p.first) continue;
    for(int i = 0; i < G[now].size(); ++i) {
      edge e = G[now][i];
      if(d[e.to] > d[now] + e.cost) {
        d[e.to] = d[now] + e.cost;
        q.push(P(d[e.to], e.to));
      }
    }
  }
}
int main() {
  scanf("%d", &N);
  for(int i = 1, u, v, w; i < N; ++i) {
    scanf("%d %d %d", &u, &v, &w);
    edge e1 = {v, w}; G[u].push_back(e1);
    edge e2 = {u, w}; G[v].push_back(e2);
  }
  dijkstra(1);
  for(int i = 1; i <= N; ++i) {
    printf("%d\n", d[i]%2);
  }
}

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

using Graph = vector<vector<int>>;
using I = long long;
using P = pair<I, I>;
const I INF = 1e18;

vector<I> bfs(const auto& G, auto r, auto p) {
  vector<I> res;
  queue<P> q;
  q.emplace(r, p);
  while(!q.empty()) {
    res.emplace_back(0);
    queue<P> nq;
    res.back() = 1;
    if(res.size()==1 && r==p) res.back() = G[r].size();
    while(!q.empty()) {
      auto cur = q.front().first;
      auto pre = q.front().second;
      q.pop();
      res.back() = max<I>(res.back(), G[cur].size() - 1);
      for(auto nex: G[cur]) if(nex != pre) nq.emplace(nex, cur);
    }
    swap(q, nq);
  }
  return res;
}

P solve(const auto& G, auto v) {
  auto d = bfs(G, v, v);
  I color = d.size(), leaf = 1;
  for(auto i: d) leaf *= i;
  return {color, leaf};
}

P solve(const auto& G, auto u, auto v) {
  auto d1 = bfs(G, u, v);
  auto d2 = bfs(G, v, u);
  I color = max(d1.size(), d2.size()), leaf = 2;
  vector<I> d(color);
  for(auto i=0; i<color; ++i) {
    if(i < d1.size()) d[i] = max(d[i], d1[i]);
    if(i < d2.size()) d[i] = max(d[i], d2[i]);
  }
  for(auto i: d) leaf *= i;
  return {color, leaf};
}

int main() {
  int N;
  cin >> N;
  Graph G(N);
  for(auto i=1; i<N; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  P res(INF, INF);
  for(auto v=0; v<N; ++v) res = min(res, solve(G, v));
  for(auto u=0; u<N; ++u) for(auto v: G[u]) res = min(res, solve(G, u, v));
  cout << res.first << " " << res.second << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans=LINF,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    pos=accumulate(a,a+n,0LL);
    sum=0;
    rep(i,n-1){
        sum+=a[i];
        ans=min(ans,abs(sum-(pos-sum)));
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

D,G = inpl()

flags = []
for i in range(2**D):
	t = format(i,'010b')
	flags.append(list(t[10-D:10]))

pp = [0]
cc = [0]
Comp = [0]
for i in range(1,D+1):
	p,c = inpl()
	pp.append(p)
	cc.append(c)
	Comp.append(p*i*100+c)

ans = INF
for flag in flags:
	SUM  = num = 0
	for i,fl in enumerate(flag):
		if fl == '1':
			SUM += Comp[i+1]
			num += pp[i+1]

	if SUM >= G:
		ans = min(ans,num)
	else:
		nn = -1
		delta = G - SUM
		for i in reversed(range(D)):
			if flag[i] == '1':
				continue
			else:
				nn = i+1
				break
		if nn != -1:
			if nn*100*pp[nn] >= delta:
				num += (delta-1)//(nn*100) + 1
				ans = min(ans,num)

print(ans)

Measured memory_bytes: 4456
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;

namespace AtCorder
{
    public static class Program
    {
        static public void Main(string[] args)
        {
            string str1 = "";
            string str2 = "";
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            for (int i = 1; i <= input[1]; i++)
            {
                str1 = str1 + input[0].ToString();
            }
            for (int i = 1; i <= input[0]; i++)
            {
                str2 = str2 + input[1].ToString();
            }

            if (string.Compare(str1, str2) >= 0)
            {
                Console.WriteLine(str2);
            }
            else
            {
                Console.WriteLine(str1);
            }
        }
    }
}




Measured memory_bytes: 11484