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

void draw_rectangle(int h, int w)
{
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cout << '#';
		}
		cout << endl;
	}
}

int main()
{
	int h, w;

	while(true) {
		cin >> h >> w;
		draw_rectangle(h, w);
		if(h == 0 && w == 0)
			break;
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin>> n;
   	string s="abcdefghijklmnopqrstuvwxyz";
   	
   	vector<int> vec(12,-1);
   	
   	int i=11;
   	
   	while(n>0){
   	    vec[i]=(n-1)%26;
   	    
   	    n=(n-1)/26;
   	    
   	    i--;
   	}
   	for(int j=0;j<12;j++){
   	    if(vec[j]!=-1)cout << s[vec[j]];
   	}
   	cout << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(void)
{
    int r,c,i,j,sum;
    int s[101][101];
    
    scanf("%d %d",&r,&c);
    
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&s[i][j]);
        }
    }
    
    for(i=0;i<r;i++){
        sum=0;
        for(j=0;j<c;j++){
            sum+=s[i][j];
        }
        s[i][c]=sum;
    }
    
    for(i=0;i<=c;i++){
        sum=0;
        for(j=0;j<r;j++){
            sum+=s[j][i];
        }
        s[r][i]=sum;
    }
    
    for(i=0;i<=r;i++){
        for(j=0;j<=c;j++){
            if(j) printf(" ");
            printf("%d",s[i][j]);
        }
        printf("\n");
    }
    
    return 0;
    
}


Measured memory_bytes: 2128
H,W = map(int,raw_input().split())
count = 0
c = []
d = 0
e = []
for i in range(H):
  count += 1
  a = raw_input().split()
  b = []
  for j in range(W):
    b.append(int(a[j]))
  for k in range(W-1):
    if b[k]%2 == 1:
      d += 1
      f = [count,k+1,count,k+2]
      e.append(f)
      b[k] -= 1
      b[k+1] += 1
  c.append(b[W-1])
count = 0
for i in range(H-1):
  count += 1
  if c[i]%2 == 1:
    d += 1
    f = [count,W,count+1,W]
    e.append(f)
    c[i] -= 1
    c[i+1] +=1
print d
for i in range(d):
  x = e[i]
  print x[0],x[1],x[2],x[3]

Measured memory_bytes: 27132
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }

int gcd(int a,int b){
    if (a%b==0) return b;
    else return gcd(b,(a%b));
}

int main(){
    int n,x0; cin >> n >> x0;
    
    vector <int> x(n);
    rep(i,n) cin >> x[i];
    
    int d=abs(x[0]-x0);
    rep(i,n) d=gcd(abs(x[i]-x0),d);
    
    cout << d << endl;
}

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

ll Inverse(ll x, int mod){
    ll res = 1;
    int n = mod - 2;
    while(n > 0){
        if(n & 1){
            res = res * x % mod;
        }
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

// 多項式vを (x-t) で割る (F_p 上)
// 次数を1下げて返す
vector<int> divPoly(vector<int> v, int t, int p){
    vector<int> res(v.size()-1);
    for (int i = v.size() - 2; i >= 0; --i) {
        res[i] = v[i+1];
        v[i+1] -= res[i]; // = 0
        v[i] += res[i] * t;
        v[i] %= p;
    }
    return res;
}

int main() {
    int p;
    cin >> p;
    vector<int>a(p);
    for (int i = 0; i < p; ++i) {
      cin >> a[i];
    }

    // a[i] = 1 の時に
    // 0 <= k <= p-1 (k != i) の整数を零点に持ち, f(i) = 1 となるp-1次多項式fを求めて
    // 全て足せば求めるp-1次多項式が得られる
    // 体F_p上の多項式環として考えられるので割り算は逆元を掛けることで計算可能
    vector<int>pi(p+1, 0); // \prod_{0}^{p-1} (x-i) , x^k の係数が pi[k]
    pi[1] = 1; // pi[0] = 0
    for (int i = 1; i < p; ++i) {
        for (int j = p; j > 0; --j) {
            pi[j] = pi[j] * (p-i) + pi[j-1];
            pi[j] %= p;
        }
    }

    vector<int>ans(p, 0);
    for (int i = 0; i < p; ++i) {
        if(a[i] == 1){
            vector<int> v(divPoly(pi, i, p));
            ll coefficient = 0; // v に x=i を代入した時の値
            int modPow = 1;
            for (int j = 0; j < p; ++j) {
                coefficient += v[j] * modPow;
                coefficient %= p;
                modPow *= i;
                modPow %= p;
            }
            int normalizer = Inverse(coefficient, p);
            for (int j = 0; j < p; ++j) {
                ans[j] += v[j] * normalizer;
                ans[j] %= p;
            }
        }
    }

    for (int i = 0; i < p; ++i) {
        cout << ans[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int time,hour = 0,minute = 0,second = 0;

        time = sc.nextInt();

        while(time - 3600 >= 0){
            hour += 1;
            time -= 3600;
        }
        while(time - 60 >= 0){
            minute += 1;
            time -= 60;
        }
        second = time;

        System.out.println(hour+":"+minute+":"+second);
    }
}


Measured memory_bytes: 26308
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;



int main() {
    string s;
    cin >> s;
    vector<ll> vv(26);
    rep(i, s.size()) {
        vv[s[i]-'a']++;
    }

    ll ans = 0LL;
    rep(i, 26) {
        ans += (s.size()-vv[i])*vv[i];
    }
    ans /= 2LL;
    ++ans;

    cout << ans << endl;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
# i段目に到達するまでの組み合わせをまとめた配列
possible_count = [0 for n in range(N + 1)]
for _ in range(M):
  i = int(input())
  possible_count[i] = -1

possible_count[0] = 1
for i in range(N):
  if possible_count[i] == -1:
    continue

  if i + 2 > N:
    possible_count[i+1] += possible_count[i] if possible_count[i+1] != -1 else 0
    continue

  possible_count[i+1] += possible_count[i] if possible_count[i+1] != -1 else 0
  possible_count[i+2] += possible_count[i] if possible_count[i+2] != -1 else 0

print(possible_count[len(possible_count) - 1] % 1000000007)





Measured memory_bytes: 462744
#include<iostream>
#include<algorithm>

using namespace std;
int num[1050];
int main(){
    int a, b;
    while(cin >> a >> b){
	if(a == 0 && b == 0)return 0;
	fill(num, num + a, 1);
	int now = 0;
	for(int i = 0;i < a - 1;i++){
	    for(int j = 1;j < b;j++){
		while(!num[(++now)%=a]);
	    }
	    num[now] = 0;
	    while(!num[(++now)%=a]);
	}
	cout << now + 1 << endl;
    }
}

Measured memory_bytes: 1164
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GLAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim(){
    int u, minv;
    int d[MAX], p[MAX], color[MAX];
    
    for (int i = 0; i < n; i++){
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    
    while(1){
        minv = INFTY;
        u = -1;
        for(int i = 0;i<n;i++){
            if(minv > d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u == -1) break;
        color[u] = BLACK;
        for(int v = 0; v<n; v++){
            if(color[v] !=BLACK && M[u][v] != INFTY){
                if(d[v]>M[u][v]){
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GLAY;
                }
            }
        }
    }
    int sum = 0;
    for(int i = 0;i < n; i++){
        if(p[i] != -1) sum += M[i][p[i]];
    }
    
    return sum;
}

int main(){
    cin >> n;
    
    for( int i = 0;i < n;i++){
        for( int j = 0; j < n; j++){
            int e; cin >> e;
            M[i][j] = (e == -1) ? INFTY : e;
        }
    }

    cout << prim() << endl;
    
    return 0;
    
}


Measured memory_bytes: 3128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			Map<Integer, Integer> map = new HashMap<>();
			int n = in.nextInt();
			for (int i = 0; i < n; i++) {
				int ai = in.nextInt();
				map.merge(ai, 1, Integer::sum);
			}

			boolean ok = true;

			int count = 0;
			if (n % 2 == 0) {
				for (int key : map.keySet()) {
					if (map.get(key) == 2) continue;
					ok = false;
					break;
				}
			} else {
				for (int key : map.keySet()) {
					if (key == 0 && map.get(key) == 1 && count == 0) {
						count++;
					} else if (map.get(key) == 2) {
						continue;
					} else {
						ok = false;
						break;
					}
				}
			}

			if (!ok) {
				out.println(0);
				return;
			}

			if (n % 2 == 1) n--;
			out.println(power(2, n/2, MOD));

		}

		static long power(long a, long e, long modP) {
			long ret = 1;
			for (; e > 0; e /= 2) {
				if (e % 2 != 0) {
					ret = (ret * a) % modP;
				}
				a = (a * a) % modP;
			}
			return ret;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 47168
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using lld=long double;
#define all(c) (c).begin(), (c).end()
#define rep( i, a, n ) for( int i=a; i<n; i++ )
#define repp( i, a, n, p ) for( int i=a; i<n; i+=p )
#define per( i, a, n ) for( int i=n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define acc accumulate

bool isPalin ( ll n ) {
    string s = to_string (n);
    string t = s;
    reverse ( all (s) );
    return s == t;
}

int main () {
    ll a, b;
    ll count=0;
    cin >> a >> b;
    rep (i, a, b+1 ) { 
        if ( isPalin ( i ) ) { 
            count++;
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 384
<?php


while (1) {
    $s = trim(fgets(STDIN));
    $s = explode(' ', $s);
    if ($s[0] == 0 && $s[1] == 0) {
      break;
    }
    
    asort($s);
    echo implode(' ', $s) . PHP_EOL;
}

exit;
?>

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

//積が奇数なら Odd と、 偶数なら Even と出力せよ。
int main() {
	int a,b;
	cin >> a >> b;

	int x = a * b;
	if (x % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

const int MAX_LEN = 100;
char S[3][MAX_LEN+1]; // SA, SB, SC
int  I[3] = {};       // SA_i, SB_i, SC_i

void _main() {
  rep(i, 0, 3) cin >> S[i];

  char last = 'a';
  while (true) {
    int i = last - 'a';
    if (S[i][I[i]] == '\0') break;
    last = S[i][I[i]];
    I[i]++;
  }

  char ans = last - 32;
  cout << ans << "\n";
}

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

using namespace std;

int main() {
    while (true) {
        string s;
        cin >> s;
        if (s == "-") {
            break;
        }
        int m;
        cin >> m;
        int count = 0;
        for (int i = 0; i < m; i++) {
            int h;
            cin >> h;
            count += h;
            count %= s.length();
        }
        string ans = s.substr(count) + s.substr(0, count);
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); 
	int n,a[60],m,sum=0; cin >> n>>m;
	for (int i = 0; i <n; i++){
		cin >> a[i];
	}
	sort(a, a+n,greater<int>());
	for (int i = m-1; i >=0; i--){
		sum += a[i];
	}
	cout << sum << endl;
	return 0;
}




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

inline int isPrime(int x){
  if(x<=1)return 0;
  for(int i=2;i*i<=x;i++){
    if(x%i==0)return 0;
  }
  return 1;
}

int p[1001000];
int main(){
  for(int i=1;i<1000000;i++){
    p[i] = p[i-1] + isPrime(i);
  }

  int n;
  while(cin >> n){
    cout << p[n] << endl;
  }
}

Measured memory_bytes: 5064
import math
MOD = 10**9+7
n,m = map(int,input().split())
#大きい順に並べる
if n < m:
  n,m = m,n

# mがn-1より小さいとどこかで犬・サル同士が隣り合う
if n-1 > m:
  print(0)
  exit()
  
if n == m:
  ans = (math.factorial(n)%MOD) * (math.factorial(m)%MOD)*2
  print(ans%MOD)
  
elif n-1 == m:
  ans = (math.factorial(n)%MOD) * (math.factorial(m)%MOD)
  print(ans%MOD)
    
  

Measured memory_bytes: 4096
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B&lang=jp
#include <bits/stdc++.h>
using namespace std;

struct TopologicalSort {
  TopologicalSort () {}
  TopologicalSort (int n) : n(n), G(n), used(n, 0) {}

  int n;
  vector<vector<int>> G;
  vector<int> order, used;

  void add_edge(int u, int v) {
    G[u].push_back(v);
  }

  void dfs(int v) {
    if (used[v]) return;
    used[v] = true;
    for (auto to : G[v]) dfs(to);
    order.push_back(v);
  }

  void build() {
    for (int i = 0; i < n; ++i) dfs(i);
    reverse(order.begin(), order.end());
  }
};

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

  TopologicalSort ts(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    ts.add_edge(u, v);
  }

  ts.build();

  for (int i = 0; i < n; ++i) {
    cout << ts.order[i] << (i + 1 == n ? "\n" : " ");
  }
}

Measured memory_bytes: 3724
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a * b // gcd(a,b)


a,b,c,d=map(int,input().split())
e=lcm(c,d)
print((b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e))

Measured memory_bytes: 3060
n=int(input())
ans='No'
daice=[]
for i in range(n):
  daice.append(list(map(int,input().split())))
for j in range(n-2):
  if daice[j][0]==daice[j][1]:
    if daice[j+1][0]==daice[j+1][1]:
      if daice[j+2][0]==daice[j+2][1]:
        ans='Yes'
print(ans)

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

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

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int n;
  cin >> n;

  vector<int> vec;
  rep(i, n) {
    int d;
    cin >> d;
    vec.push_back(d);
  }

  sort(all(vec), greater<>());
  vec.erase(unique(all(vec)), vec.end());

  cout << vec.size() << "\n";

  return 0;
}

Measured memory_bytes: 256
/*
 * Author : Sadi
 * Mon 06/07/2020
 * 16:30:21.13
 */
#include <iostream>
#include <cstdio>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

	int l, r;
	const int year = 2019;
	cin >> l >> r;
	if(r - l >= year) {
		cout << 0 << endl;
	}
    else {
    	int ans = 1e9;
    	for(int i = l; i < r; ++i) {
    		for(int j = i + 1; j <= r; ++j) {
    			int result = ((i % year) * (j % year)) % year;
    			ans = min(ans, result);
    		}
    	}
    	cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3544
<?php
$n = (int)fgets(STDIN);
for($i = 0; $i < $n; $i++){
    $map[] = trim(fgets(STDIN));
}
$count = 0;
for($i = 0; $i < $n; $i++){
    $flag = true;
    for($x = 0; $x < $n; ++$x){
        $X = ($x+$i) % $n;
        $mapX = $map[$X];
        for($y = $x + 1; $y < $n; ++$y){
            if($mapX[$y] != $map[($y+$i)%$n][$x])$flag = false;
        }
    }
    $count+=$flag;
}
echo $count*$n,"\n";


Measured memory_bytes: 4984
#!/usr/bin/python

def main():
    s = int(input())

    if s == 22:
        print ("Christmas Eve Eve Eve\n")
    elif s == 23:
        print ("Christmas Eve Eve\n")
    elif s == 24:
        print ("Christmas Eve\n")
    elif s == 25:
        print ("Christmas\n")

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

int main() {
    ll N, M;
    cin >> N >> M;
    if(N == 1 && M == 1) cout << 1 << endl;
    if(N == 1 && M >= 2) cout << M - 2 << endl;
    if(M == 1 && N >= 2) cout << N - 2 << endl;
    if(N >= 2 && M >= 2) cout << N * M - (N * 2 + M * 2 - 4) << endl;
}

Measured memory_bytes: 3516
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, M;
  cin>>N>>M;
  vector<tuple<ll, ll, ll> > arr(M);
  ll L, R;
  ll C;
  for(ll i=0;i<M;++i) {
    cin>>L>>R>>C;
    L--;
    R--;
    arr[i] = make_tuple(L, C, R);
  }
  sort(arr.begin(), arr.end());
  bool can = true;
  vector<ll> ans(N);
  for(ll i=0;i<N;++i) ans[i] = big;
  ans[0] = 0;
  ll index;
  for(ll i=0;i<M;++i) {
    L = get<0>(arr[i]);
    C = get<1>(arr[i]);
    R = get<2>(arr[i]);
    if(ans[L]>=big) {
      can = false;
      break;
    }
    index = lower_bound(ans.begin()+L, ans.begin()+R, ans[L]+C) - ans.begin();
    for(ll j=index;j<=R;++j) {
      ans[j] = min(ans[j], ans[L]+C);
    }
  }
  if(can && ans[N-1]<big) cout<<ans[N-1]<<endl;
  else cout<<-1<<endl;
}



Measured memory_bytes: 6412
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vii vector<int,int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define all(a) a.begin(),a.end()
const int mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void dfs(int node,vi adj[],bool chk[],int dp[]){
    chk[node]=true;
    for(int i=0;i<adj[node].size();i++){
        if(!chk[adj[node][i]]){
            dfs(adj[node][i],adj,chk,dp);
        }
        dp[node]=max(dp[node],1+dp[adj[node][i]]);
    }
}
void addEdge(vi adj[],int u,int v){
    adj[u].pb(v);
}
int longestPath(vi adj[],int n){
    bool chk[n+1];
    int dp[n+1];
    memset(chk,false,sizeof chk);
    memset(dp,0,sizeof dp);
    for(int i=1;i<=n;i++){
        if(!chk[i]){
            dfs(i,adj,chk,dp);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dp[i]);
    }
    return ans;
}
int main(){
    fast;
    int n,m;
    cin>>n>>m;
    int a,b;
    vi adj[n+1];
    while(m--){
        cin>>a>>b;
        addEdge(adj,a,b);
    }
    cout<<longestPath(adj,n);
}

Measured memory_bytes: 9600
#include <stdio.h>
int main(void) {
  int N;
  scanf("%d", &N);
  char S[N];
  scanf("%s", S);
  int cnt = 0;
  for (int i = 0; i < N - 2; i++) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
      cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}

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

using namespace std;

int main()
{
  int a, b, somma=0;
  char s[3];

  for(int c=0; c<3; c++)
    cin>>s[c];

  if(s[0] == s[1] && s[1]==s[2])
    cout<<"No";
  else
    cout<<"Yes";
}


Measured memory_bytes: 256
import numpy as np
N = int(input())

C = np.zeros(4)
for i in range(N):
  S = input()
  if S == 'AC':
    C[0] += 1
  elif S == 'WA':
    C[1] += 1
  elif S == 'TLE':
    C[2] += 1
  elif S == 'RE':
    C[3] += 1
print('AC x', int(C[0]))
print('WA x', int(C[1]))
print('TLE x', int(C[2]))
print('RE x', int(C[3]))

Measured memory_bytes: 27172
#include<iostream>
#include<algorithm>
#define N 2

using namespace std;
void output_array_int(int*,int,char);
void input_array_int(int*,int);

////////////////////////////////////////////////////////////////////////////////

int main(){
  int a,b,c,i,s;
  s=0;
  cin>>a>>b>>c;
  for(i=a;i<=b;i++){
    if(c%i==0){
      s++;
    }
  }

  cout<<s<<endl;

  return 0;
}

////////////////////////////////////////////////////////////////////////////////

void output_array_int(int * a,int n,char ch){
  int i;

  for(i=0;i<n;i++){
    cout<<*(a+i);
    if(i<(n-1)){
      cout<<ch;
    }
  }

  cout<<endl;

  return;
}

void input_array_int(int *a,int n){
  int i;

  for(i=0;i<n;i++){
    cin>>*(a+i);
  }
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;string s;cin>>n>>s;
    if(n%2!=0){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[i+n/2]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    if(S=="hi"||S=="hihi"||S=="hihihi"||S=="hihihihi"||S=="hihihihihi"){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }    
}

Measured memory_bytes: 256
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():

    n=int(input())
    s=str(input())

    print(max(len(set(s[:i])&set(s[i:])) for i in range(n)))

resolve()


Measured memory_bytes: 2940
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);
        Console.WriteLine((a <= 8 && b <= 8) ? "Yay!" : ":(");
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }
    int a, b;
    cin >> a >> b;

    int ans = 0;
    if (a < 10 && b < 10)
        ans = a * b;
    else
        ans = -1;
    cout << ans << endl;
    return;
}

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


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

vector<vector<ll>> com(51,vector<ll>(51));

void pas(){
	rep(i,51){
		com[0][i]=1;
	}
	for(int i=1;i<51;++i){
		for(int j=1;j<=i;++j){
			com[i][j]=com[i-1][j-1]+com[i-1][j];
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,p;cin >> n >> p;
	vector<int> a(n);
	int even=0,odd=0;
	rep(i,n){
		cin >> a.at(i);
		if(a.at(i)%2==0) even++;
		else odd++;
	}
	pas();
	ll ans1=0,ans2=0;
	for(int i=0;i<=even;++i){
		ans1+=com[even][i];
	}
	if(p){
		for(int i=1;i<=odd;i+=2){
			ans2+=com[odd][i];
		}
		cout << ans1*ans2 << endl;
	}
	else{
		for(int i=0;i<=odd;i+=2){
			ans2+=com[odd][i];
		}
		cout << ans1*ans2 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

ll MOD = 1000000007;
ll n;

ll Pow(ll m){ //m^nを返す
  ll ret = 1;
  rep(i,n){
    ret *= m;
    ret %= MOD;
  }
  ret %= MOD;
  //cout << "m=" << m << ",ret = " << ret << endl;
  return ret;
}

int main() {
  cin>>n;
  ll ans = Pow(10);
  ans %= MOD;
  //cout << ans << endl;
  ans -= (2*Pow(9));
  ans %= MOD;
  if (ans < 0) ans += MOD;
  ans %= MOD;
  ans += (Pow(8))%MOD;
  ans %= MOD;
  cout << ans << endl;
}



Measured memory_bytes: 3612
//
//  main.cpp
//  atcoder - Independant Set
//
//  Created by r on 6/2/19.
//  Copyright © 2019 r. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007


long long N;
vector<long long> adj[100010];
bool visited[100010];
long long dp[100010][2];

long long f(long long u, long long last, long long lb) {
    if (adj[u].size() == 0) {
        return 2;
    }
    if (adj[u].size() == 1 && adj[u][0] == last) {
        if (lb) {
            return 1;
        } else {
            return 2;
        }
    }
    if (dp[u][lb] != -1) {
        return dp[u][lb];
    }
    long long cnt1 = 1;
    long long cnt2 = 1;
    for (auto v: adj[u]) {
        if (v != last) {
            cnt1=(cnt1*f(v, u, 0))%MOD;
            if (!lb) {
                cnt2=(cnt2*f(v, u, 1))%MOD;
            } else {
                cnt2 = 0;
            }
        }
    }
    dp[u][lb] = (cnt1+cnt2)%MOD;
    return (cnt1+cnt2)%MOD;
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    memset(dp, -1, sizeof(dp));
    cin >> N;
    for (long long i = 0; i<N-1; i++) {
        long long a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cout << f(1, 0, 0)%MOD << endl;
    return 0;
}





Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,z,s=1;
	cin>>a;
	int q[a];
	for(int i=0;i<a;i++) cin>>q[i];
	for(int i=0;i<a;i++)
	{
		if(q[i]==s){
			z++;
			s++;
		}
	}
	if(z==0) cout<<"-1";
	else cout<<a-z;
}

Measured memory_bytes: 1024
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		int[] cnt = new int[N + 1];
		int[] cum = new int[2 * N + 1];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			++cnt[A[i]];
		}
		for (int i = 1; i <= N; ++i) {
			for (int j = 0; j < cnt[i]; ++j) {
				++cum[i - j + N];
			}
		}

		int ans = 0;
		for (int i = 1; i <= N; ++i) {
			if (cum[i + N] == 0)
				++ans;
		}
		for (int i = 0; i < M; ++i) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			--x;
			int tmp = x;
			x = A[x];
			A[tmp] = y;
			--cum[N + x - (cnt[x] - 1)];
			if (cum[N + x - (cnt[x] - 1)] < 0) {
				throw new AssertionError();
			}
			if (x - (cnt[x] - 1) >= 1 && cum[N + x - (cnt[x] - 1)] == 0) {
				++ans;
			}
			--cnt[x];
			++cnt[y];
			++cum[N + y - (cnt[y] - 1)];
			if (y - (cnt[y] - 1) >= 1 && cum[N + y - (cnt[y] - 1)] == 1) {
				--ans;
			}
			System.out.println(ans);
		}

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

int main (){
  int N;
  cin >> N;
  
  vector<int> B(N);
  for (int i=0;i<N;i++){
    int a;
    cin >> a;
   B[a-1] = i+1;
  }
  
  for(int i=0;i<N-1;i++){
    cout << B[i] << ' ';
  }
  cout << B[N-1] << endl;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int N=1e5+7;
int a[N],n;
long long ans;
inline int f(int p,int q){
	return p>=q?p-q:q-p;
}
int main(){
	scanf("%d",&n);
	for(int i = 1;i<=n;i++){
		scanf("%d",&a[i]);
		ans+=f(a[i],a[i-1]);
	}
	ans+=f(0,a[n]);
	for(int i = 1;i<=n;i++){
		cout<<ans-abs(a[i]-a[i+1])-abs(a[i]-a[i-1])+abs(a[i-1]-a[i+1])<<endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()
vector<ll> divisors;//約数を格納する配列
#define PB push_back //挿入
void make_divisors(ll n){
    FOR(i,1,sqrt(n)){
        if(n%i==0){
            divisors.PB(i);
            if(i!=n/i){
                divisors.PB(n/i);
            }
        }
    }
    //約数の小さい順にソートしたい場合
    //sort(ALL(divisors));
    //約数の大きい順にソートしたい場合
    sort(ALL(divisors),greater<ll>());
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k,s;
    cin>>n>>k;
    s=0;
    ll arr[n];
    fr(i,n){
        ll a;
        cin>>a;
        arr[i]=a;
        s+=a;
    }
  make_divisors(s);
  fr(i,divisors.size()){
      ll x=0;
      ll ar[n];
      ll ans=100000000000000000;
     fr(l,n){
         ar[l]=arr[l]%divisors[i];
         x+=divisors[i]-ar[l];
     }
     sort(ar,ar+n);
     int w=0;
     ll ans2=0;
     while(x!=0){
         x=x-divisors[i];
         
         ans2+=ar[w];
         ++w;
     }
     ans=min(ans,ans2);
     if(ans<=k){
         cout<<divisors[i];
         exit(0);
     }
  }
}

Measured memory_bytes: 3640
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process(int test_number)throws IOException
    {
        int n = ni();
        long arr[] = new long[n + 1];
        for(int i  = 1; i <= n; i++) arr[i] = ni();

        long mx = arr[1], res = 0l;
        for(int i = 2; i <= n; i++){
            res += Math.max(0, mx - arr[i]);
            mx = Math.max(mx, arr[i]);
        }
        pn(res);
    }
 
    static final long mod = (long)1e9+7l;
    
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc = new FastReader();
 
        long s = System.currentTimeMillis();
        int t = 1;
       // t = ni();
        for(int i = 1; i <= t; i++)
            process(i);
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }

    static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
    static void pn(Object o){ out.println(o); }
    static void p(Object o){ out.print(o); }
    static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
    static long nl()throws IOException{ return Long.parseLong(sc.next()); }
    static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
    static String nln()throws IOException{ return sc.nextLine(); }
    static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }
    static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }
    
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 58916
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int a, b;
   cin >> a >> b;
   rep(i, 0, 10005) {
      if (i * 8 / 100 == a && i * 10/100 == b) {
         cout << i << endl;
         return 0;
      }
   }
   cout << "-1" << endl;
   return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N, M, K = map(int, input().split())
    for y in range(N + 1):
        for x in range(M + 1):
            a = y * M + x * N - y * x * 2
            if a == K:
                print("Yes")
                return
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 4336
#include <iostream>

using namespace std;

const int kMaxN = 25;
const int NIL = -1;

struct Node {
    int p;
    int l;
    int r;
};

Node T[kMaxN];
int n;

void preParse(int u) {
    if (u == NIL) {
        return;
    }
    cout << " " << u;
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u) {
    if (u == NIL) {
        return;
    }
    inParse(T[u].l);
    cout << " " << u;
    inParse(T[u].r);
}

void postParse(int u) {
    if (u == NIL) {
        return;
    }
    postParse(T[u].l);
    postParse(T[u].r);
    cout << " " << u;
}

int main() {
    cin >> n;
    int v, l, r, root;
    Node node;

    for (int i = 0; i < n; i++) {
        T[i].p = NIL;
    }

    for (int i = 0; i < n; i++) {
        cin >> v >> l >> r;
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) {
            T[l].p = v;
        }
        if (r != NIL) {
            T[r].p = v;
        }    
    }

    for (int i = 0; i < n; i++) {
        if (T[i].p == NIL) {
            root = i;
        }
    }

    cout << "Preorder" << endl;
    preParse(root);
    cout << endl;
    cout << "Inorder" << endl;
    inParse(root);
    cout << endl;
    cout << "Postorder" << endl;
    postParse(root);
    cout << endl;
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    set<int> s;
    rep(i,3){
        int n; cin >> n;
        s.insert(n);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 256
//  Created by conan1024hao on 2019/11/24.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //------------------------------
    int n;
    cin>>n;
    vector<vector<int>>a(n);
    vector<pair<int,int>>vp;
    int dp[1005][1005];
    
    for(int i=0;i<n-1;i++){
        int c,d;
        cin>>c>>d;
        c--;d--;
        a[c].push_back(d);
        a[d].push_back(c);
        vp.emplace_back(c,d);
    }
    int cnt=0;
    map<pair<int,int>,int> I;
    vector<int> color(n,0);
    vector<int> used(n,0);
    queue<int> que;
    used[0]=1;
    que.emplace(0);
    for(int i=0;i<n;i++){
        chmax(cnt,a[i].size());
    }
    while(!que.empty()){
        int v=que.front();que.pop();
        int now=1;
        for(int i:a[v]){
            if(used[i])
                continue;
            if(now==color[v])
                now++;
            color[i]=I[make_pair(i,v)]=I[make_pair(v,i)]=now++;
            used[i]=1;
            que.emplace(i);
                
        }
    }
    map<int,int>MAP;
    cout<<cnt<<endl;
    for(auto p:vp)cout<<I[p]<<endl;
    //cout<<dp[5][0]<<" "<<dp[4][5]<<endl;
    //cout<<dp[5][0]<<" "<<dp[5][1]<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 20088
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
int test(int a){
    return (((a-1)/10+1)*10);
}
int main()
{
    vector<int> v;
    int minm=643;
    rep(i,5){
        int enter;
        cin>>enter;
        v.push_back(enter);
    }
    sort(v.begin(),v.end());
    do{
        minm=min(minm,test(v[0])+test(v[1])+test(v[2])+test(v[3])+v[4]);
    }while(next_permutation(v.begin(),v.end()));
  cout<<minm<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int A[3];
    cin >> A[0] >> A[1] >> A[2];
    
    if(A[0] + A[1] + A[2] >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << 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++)
typedef pair<int, int> P;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    ll d = 1;
    rep(j, 50)
    {
        d *= 2;
        rep(i, n)
        {
            if (a[i] % d)
            {
                cout << j<< endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
    int a,b,c,temp;
    scanf("%d %d %d",&a,&b,&c);

    if (a>b) {
      temp = a;
      a = b;
      b = temp;
    }
    if (a>c) {
      temp = a;
      a = c;
      c = temp;
    }
    if (b>c) {
      temp = b;
      b = c;
      c = temp;
    }
    
    printf("%d %d %d\n",a,b,c);

    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define PI 3.14159265359

int main(){
    int n; cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t[i];

    int m; cin >> m;
    vector<int> p(m);
    vector<int> x(m);
    rep(i, m) cin >> p[i] >> x[i];
    int result[101] = {};

    rep(i, m){
        rep(j, n){
            if(j == p[i]-1){
                result[i] += x[i];
            }else{
                result[i] += t[j];  
            }
        }
        cout << result[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s.size() <  6 || !((s[2]==s[3])&&s[4]==s[5])){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

string s[200];
int n, a[200];

void dfs(int x) {
    rep(j, n) {
        if (s[x][j] == '1') {
            if (!a[j]) {
                a[j] = -a[x];
                dfs(j);
            }
            else if (a[j] == a[x]) {
                cout << -1 << endl;
                exit(0);
            }
        }
    }
}

int bfs(int x) {
    vector<int> b(n);
    b[x] = 1;
    queue<int> q;
    q.push(x);
    while(q.size()) {
        int t = q.front();
        q.pop();
        rep(j, n) {
            if (s[t][j] == '1' && !b[j]) {
                b[j] = b[t] + 1;
                q.push(j);
            }
        }
    }
    return *max_element(all(b));
}

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

    cin >> n;
    rep(i, n) cin >> s[i];
    a[0] = 1;
    dfs(0);
    int ans = 0;
    rep(i, n) {
        ans = max(ans, bfs(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import numpy as np
(n,m),*d = [list(map(int, s.split())) for s in open(0)]

inf = 100000000
dp = np.full([2]*n, inf, dtype=np.int)
dp[tuple([0]*n)] = 0

for i in range(m):
    a = d[2*i][0]
    b = d[2*i][1]
    c = d[2*i+1]
    
    l0 = [slice(None)]*n
    l1 = [slice(1,2)]*n
    for x in c:
        l0[x-1] = slice(0,1)
        l1[x-1] = slice(None)
    dp = np.minimum(np.minimum(dp[tuple(l1)], dp[tuple(l0)]+a), dp)
    
ans = dp[tuple([1]*n)]
if ans == inf:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 12772
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
		tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
		tree_order_statistics_node_update> indexed_multiset;


int n ;
long long ans;
vector<int>b,a,ab;
bool vis[10004];
int main(){	
	cin>>n;
	for(int i = 0; i < n ; i++){
		string s ;cin>>s;
		for(int j = 1 ; j<(int)s.size() ;j++){
			if(s[j]=='B'&& s[j-1]=='A'){
				ans++;
			}
		}
		if(s[0]=='B' &&s[(int)s.size() - 1]=='A')
			ab.push_back(i);
		else if(s[0]=='B')b.push_back(i);
		else if(s[(int)s.size() - 1] == 'A')a.push_back(i);
	}
	int aa = a.size() , bb = b.size() , aabb = ab.size();
	if(aa){
		aa--;
		while(aabb){
			aabb--;
			ans++;
		}
		// last = a
		if(bb){
			bb--;
			ans++;
		}
		//last = b;
		while(aa&&bb){
			aa--;bb--;
			ans++;
		}
	}else{
		if(aabb){
			ans+=(aabb-1);
			if(bb)ans++;
		}
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 384