akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val sc = (1..M).map {
        val (s, c) = readLine()!!.split(" ").map(String::toInt)
        Pair(s, c)
    }

    val sc_map: MutableMap<Int, Int> = mutableMapOf()
    for((s, c) in sc) {
        sc_map.get(s)?.run {
            if(this != c) {
                println("-1")
                return
            }
        }
        sc_map[s] = c
    }

    val digit_list = (1..N).map { null as Int? }.toMutableList()
    
    for((s, c) in sc_map) {
        digit_list[s- 1] = c
    }
    if(N == 1) {
        (digit_list[0]?: 0).run(::println)
        return
    } else {
        var is_error = false 
        digit_list[0]?.run {
            if(this == 0) {
                println(-1)
                is_error = true
            }
        }
        if(is_error) {
            return
        }
    }
    for( i in 0 until digit_list.size) {
        if(digit_list[i] == null) {
            digit_list[i] = if(i == 0) {1} else {0}
        }
    }

    digit_list.joinToString("").toInt().let {
        val s = it.toString()
        s
    }.run(::println)
}

Measured memory_bytes: 37420
object Main extends App {

  val n = io.StdIn.readLine()
  println(convert(n.toInt))

  def convert(n: Int): String = {
    var a = n

    var a1 = a % 10
    a = a / 10
    var a2 = a % 10
    a = a / 10
    var a3 = a % 10

    if (a1 == 9) {
      a1 = 1
    } else if (a1 == 1) {
      a1 = 9
    }
    if (a2 == 9) {
      a2 = 1
    } else if (a2 == 1) {
      a2 = 9
    }
    if (a3 == 9) {
      a3 = 1
    } else if (a3 == 1) {
      a3 = 9
    }

    return a3.toString + a2.toString + a1.toString
  }

}


Measured memory_bytes: 25540
using System;
namespace csharptest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int n = int.Parse(str[0]);
            int m = int.Parse(str[1]);
            int[] c = new int[n];
            int[,] A = new int[n, m];
            int[] b = new int[m];
            for (int l = 0; l < n; l++)
            {
                str = Console.ReadLine().Split(' ');
                for (int k = 0; k < m; k++)
                {
                    A[l, k] = int.Parse(str[k]);
                }
            }
            for (int l = 0; l < m; l++)
            {
                b[l] = int.Parse(Console.ReadLine());
            }
            for (int l = 0; l < n; l++)
            {
                c[l] = 0;
                for (int k = 0; k < m; k++)
                {
                    c[l] += A[l, k] * b[k];
                }
            }
            for (int l = 0; l < n; l++)
            {
                Console.WriteLine(c[l]);
            }
        }
    }
}

Measured memory_bytes: 5892
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  vector<string> s(3);
  for (int i = 0; i < 3; i++) cin >> s[i];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4444; j++) s[i].push_back('?');
  }
  sort(s.begin(), s.end());
  auto match = [] (const char& a, const char& b) {
    return a == b || a == '?' || b == '?';
  };
  int ans = 1 << 30;
  do {
    int x = (int) s[0].size() - 4444, y = (int) s[1].size() - 4444, z = (int) s[2].size() - 4444;
    bitset<6666> ab, ac, bc;
    ab.set();
    ac.set();
    bc.set();
    for (int st = 0; st <= 2222; st++) {
      for (int i = 0; i < y; i++) {
        if (!match(s[0][st + i], s[1][i])) ab[st] = 0;
      }
      for (int i = 0; i < z; i++) {
        if (!match(s[0][st + i], s[2][i])) ac[st] = 0;
        if (!match(s[1][st + i], s[2][i])) bc[st] = 0;
      }
    }
    for (int i = 0; i <= 2020; i++) for (int j = i; j <= 2020 + i; j++) {
      if (ab[i] && ac[j] && bc[j - i]) {
        ans = min(ans, max({x, i + y, j + z}));
      }
    }
  } while (next_permutation(s.begin(), s.end()));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
constexpr ll mod = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < 1200; i++) {
        int a2 = (i * 8) / 100, b2 = (i * 10) / 100;
        if (a == a2 && b == b2) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

typedef pair<int,int> pii;

int W,H;
int N;
long long ans[10] = {0};
long long sum = 0;
vector<pii> V;

int main()
{
    scanf("%d%d%d",&H,&W,&N);
    for(int i = 0; i < N; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        for(int x = -1; x < 2; x++)
        {
            for(int y = -1; y < 2; y++)
            {
                if(2 <= a + y && a + y < H && 2 <= b + x && b + x < W)
                {
                    V.push_back(make_pair(a + y,b + x));
                }
            }
        }
    }
    sort(V.begin(),V.end());
    int mem = 1;
    for(int i = 0; i < V.size(); i++)
    {
        if(i == V.size() - 1 || V[i].first != V[i + 1].first || V[i].second != V[i + 1].second)
        {
            ans[mem]++;
            mem = 1;
            sum++;
            continue;
        }
        mem++;;
    }
    ans[0] = (H - (long long)2) * (W - (long long)2) - sum;
    for(int i = 0; i < 10; i++)
    {
        printf("%lld\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct ab {
  ll a;
  ll b;
};
int main() {
  ll n, m;
  ll ans = 0;
  cin >> n >> m;
  vector<ab> aa(n);
  for(int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    aa[i].a = a;
    aa[i].b = b;
  }
  sort(aa.begin(), aa.end(), [](const ab& x, const ab& y) {return x.a < y.a;});
  for(int i = 0; i < n; i++) {
    if(m >= aa[i].b) {
      m -= aa[i].b;
      ans += aa[i].a * aa[i].b;
    }
    else {
      ans += aa[i].a * m;
      m = 0;
    }
    if(m == 0) break;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int l[N];
    for (int i=0; i<N; i++){
        cin >> l[i];
    }
    int max=l[0];
    int sum=0;
    for (int i=0; i<N; i++){
        if (max<l[i]){
            max=l[i];
        }
        sum+=l[i];
    }
    sum-=max;
    if(max<sum){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
N, X, M = list(map(int, input().split()))
i = 1
a = X
s = 0
L = []
while i < N and a > 0:
    L.append(a)
    s += a
    a = (a**2) % M
    if a in L:
        j = L.index(a)
        break
    i += 1
else:
    s += a
    print(s)
    exit()

# print(L)
t = sum(L[:j])
L = L[j:]
u = s-t
N = N-j
v = t+u*(N//(i-j))
if N % (i-j) == 0:
    pass
else:
    v += sum(L[:N % (i-j)])
print(v)


Measured memory_bytes: 68776
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int w,a,b;cin>>w>>a>>b;
  if(a<=b&&b<=a+w){cout<<0<<endl;return 0;}
  if(b<=a&&a<=b+w){cout<<0<<endl;return 0;}
  cout<<min(abs(a+w-b),abs(b+w-a))<<endl;

  return 0;

}


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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

string s;
vector<char> v;

main() {
    cin >> s;
    v.pb(s[0])
    rep1(i,s.size()-1) {
        if (v.back()=='S' && s[i]=='T') v.pop_back();
        else v.pb(s[i])
    }
    ct(v.size())
}


Measured memory_bytes: 772
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
from math import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    d=defaultdict(lambda:[0,0])
    zz=0
    for _ in range(N):
        a,b=map(int,input().split())
        g=gcd(a,b)
        if g==0:
            zz+=1
        else:
            a//=g
            b//=g
            if a<0:
                a*=-1
                b*=-1
            if a*b>0:
                d[(a,b)][0]+=1
            elif a*b<0:
                d[(-b,a)][1]+=1
            else:
                if a:
                    d[(1,0)][0]+=1
                else:
                    d[(1,0)][1]+=1
    l=[]
    other=0
    for k,a in d.items():
        if a[0] and a[1]:
            l.append((a[0],a[1]))
        else:
            other+=sum(a)
    ans=pow(2,other,MOD)
    ans%=MOD
    dp=[[0]*2 for _ in range(len(l)+1)]
    dp[0][0]=1
    for i in range(len(l)):
        dp[i+1][0]=dp[i][0]+dp[i][1]
        dp[i+1][1]=(dp[i][0]+dp[i][1])*(pow(2,l[i][0],MOD)+pow(2,l[i][1],MOD)-2)
        dp[i+1][0]%=MOD
        dp[i+1][1]%=MOD
    ans*=sum(dp[-1])
    ans-=1
    ans+=zz
    ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 130264
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll a, b, c; cin >> a >> b >> c;
    ll d = a-b;
    ll e = c - 2*a - 2*b;

    if(c-a-b <= 0) dunk("No");


    else{

    if(d*d + c*(e) > 0) dunk("Yes");
    else dunk("No");
    }
}

Measured memory_bytes: 256
//
// Created by munaiyi on 2020/3/19.
//

#include <bits/stdc++.h>

using namespace std;
const int maxn = 20;
int a[maxn], b[maxn];

int Check(int state, int n) {
    bool flag = true;
    int tmp = state;
    while (tmp) {
        if (tmp & 1) flag = flag ^ 1;
        tmp = tmp >> 1;
    }
    if (!flag) return -1;
    vector<pair<int, int>> ji, ou, tot;
    for (int i = 0; i < n; i++) {
        bool j = i & 1, fan = false;
        if (state & (1 << i)) {
            j = j ^ 1;
            fan = true;
        }
        if (j) {
            ji.emplace_back(fan ? b[i] : a[i], i);
        } else {
            ou.emplace_back(fan ? b[i] : a[i], i);
        }
    }
    if ((ji.size() != ou.size() - (n & 1))) {
        return -1;
    }
    sort(ji.begin(), ji.end());
    sort(ou.begin(), ou.end());
    {
        auto j = ji.begin();
        auto o = ou.begin();
        while (j != ji.end() || o != ou.end()) {
            if (o != ou.end()) {
                tot.push_back(*o);
                o++;
            }
            if (j != ji.end()) {
                tot.push_back(*j);
                j++;
            }
        }
//        for (int i = 0; i < tot.size(); i++) {
//            printf("%d %d  ss %d\n", tot[i].first, tot[i].second, state);
//        }
    }

    int ans = 0;
    for (int i = 1; i < n; i++) {
        if (tot[i - 1].first > tot[i].first)
            return -1;
        for (int j = 0; j < i; j++) {
            if (tot[j].second > tot[i].second) ans++;
        }
    }
    return ans;

}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", b + i);
    }
    int ans = 10000;
    for (int now = (1 << n) - 1; now >= 0; now--) {
        int t = Check(now, n);
//        printf("%d %d\n", now, t);
        if (t + 1) {
            ans = min(ans, t);
        }
    }
    printf("%d\n", ans == 10000 ? -1 : ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e5+10;
vector<int>g[maxn],vis(maxn),dis(maxn),par(maxn),tpl;
int n,m;
void dfs(int u){
	vis[u]=1;
	for(auto v:g[u]){
		if( !vis[v]){
			dfs(v);
		}
	}
	tpl.push_back(u);
}	
int32_t main(){
	IOS
	cin>>n>>m;
	for(int i=1;i<=n-1+m;i++){
		int u,v;cin>>u>>v;
		g[u].push_back(v);
	}
	for(int i=1;i<=n;i++){
		if( !vis[i] ){
			dfs(i);
		}
	}
	reverse(tpl.begin(),tpl.end());
	for(int i=0;i<n;i++){
		int u = tpl[i];
		for(auto v:g[u]){
			if( dis[v] < dis[u] + 1){
				dis[v] = dis[u] + 1;
				par[v] = u;
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout << par[i] << endl;
	}
}
/*
 * long long or int?
 * index out of bound?
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 15268
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    // 入力
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    int ans = 0;

    // 解き方汚いけど分からないからごり押し
    for(int i=(int)n; i>=0; --i) {
      if((int)(i*1.08) == n) {
        ans = i;
      }
    }

    // 出力
    if(ans != 0)
      System.out.println(ans);
    else
      System.out.println(":(");

  }
}

Measured memory_bytes: 22100
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

vector<int> tree;

int Get(int v, int vleft, int vright, int pos) {
	if (vleft + 1 == vright) {
		return tree[v];
   	}

   	int vmid = (vleft + vright) / 2;
   	if (pos < vmid) {
   		return min(Get(2 * v + 1, vleft, vmid, pos), tree[v]);
   	} else {
   		return min(Get(2 * v + 2, vmid, vright, pos), tree[v]);
	}
}

void Set(int v, int vleft, int vright, int pos, int val) {
	if (vleft + 1 == vright) {
		tree[v] = val;
		return;
	}

	int vmid = (vleft + vright) / 2;
	if (pos < vmid) {
		tree[2 * v + 2] = min(tree[v], tree[2 * v + 2]);
		Set(2 * v + 1, vleft, vmid, pos, val);
	} else {
		tree[2 * v + 1] = min(tree[v], tree[2 * v + 1]);
		Set(2 * v + 2, vmid, vright, pos, val);
	}
	tree[v] = inf;
}

void Umn(int v, int vleft, int vright, int left, int right, int val) {
	if (left == vleft && right == vright) {
		tree[v] = min(tree[v], val);
		return;
	}

	int vmid = (vleft + vright) / 2;
	
	if (left < vmid) {
		Umn(2 * v + 1, vleft, vmid, left, min(right, vmid), val);
	}
	if (right > vmid) {
		Umn(2 * v + 2, vmid, vright, max(left, vmid), right, val);
	}
}

int main () {
	ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	int n;
	cin >> n;
	
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
	    cin >> b[i];
	}

	int m;
	cin >> m;
	vector<vector<int>> seg(n);
	for (int i = 0; i < m; ++i) {
		int left, right;
		cin >> left >> right;
		--left;
		seg[left].pb(right);
	}

    int num_0 = 0;
    for (int i = 0; i < n; ++i) {
    	num_0 += (b[i] == 0);
    }

    tree.resize(4 * (n + 1), inf);
    
    Set(0, 0, n + 1, n, 0);
    for (int i = n - 1; i >= 0; --i) {
    	Set(0, 0, n + 1, i, Get(0, 0, n + 1, i + 1) + (b[i] == 1 ? 1 : -1));
    	for (int j = 0; j < sz(seg[i]); ++j) {
    		Umn(0, 0, n + 1, i, seg[i][j], Get(0, 0, n + 1, seg[i][j]));
    	}
    }

    cout << num_0 + Get(0, 0, n + 1, 0) << endl;

	return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<bool> a(n);
  for(int i=0;i<4;i++){
    a[0]=i&1;
    a[1]=i&2;
    for(int j=2;j<n;j++){
      if(a[j-1]){
        if(s[j-1]=='o'){
          a[j]=a[j-2];
        }else{
          a[j]=!a[j-2];
        }
      }else{
        if(s[j-1]=='o'){
          a[j]=!a[j-2];
        }else{
          a[j]=a[j-2];
        }
      }
    }
    if(s[0]=='o'){
      if(s[n-1]=='o'){
        if((a[n-1]==a[1])==a[0]&&(a[0]==a[n-2])==a[n-1]){
          for(int j=0;j<n;j++) cout << (a[j]?'S':'W');
          cout << endl;
          return 0;
        }
      }else{
        if((a[n-1]==a[1])==a[0]&&(a[0]!=a[n-2])==a[n-1]){
          for(int j=0;j<n;j++) cout << (a[j]?'S':'W');
          cout << endl;
          return 0;
        }
      }
    }else{
      if(s[n-1]=='o'){
        if((a[n-1]!=a[1])==a[0]&&(a[0]==a[n-2])==a[n-1]){
          for(int j=0;j<n;j++) cout << (a[j]?'S':'W');
          cout << endl;
          return 0;
        }
      }else{
        if((a[n-1]!=a[1])==a[0]&&(a[0]!=a[n-2])==a[n-1]){
          for(int j=0;j<n;j++) cout << (a[j]?'S':'W');
          cout << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n;
long long f[87];
int main()
{
    f[0]=2;
    f[1]=1;
    cin>>n;
    for(int i=2;i<=n;i++)
        f[i]=f[i-1]+f[i-2];
    cout<<f[n];
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

char G[100][100];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b; cin>>a>>b;
  
  memset(G,'#',sizeof(G));
  irep(i,50,100){
    rep(j,100) G[i][j]='.';
  }
  
  ll row=0, pos=0;
  rep(i,a-1){
    G[row][pos]='.';
    pos+=2;
    if(pos>=100){
      pos=0;
      row+=2;
    }
  }
  
  row=51, pos=0;
  rep(i,b-1){
    G[row][pos]='#';
    pos+=2;
    if(pos>=100){
      pos=0;
      row+=2;
    }
  }
  cout<<100 <<" "<<100<<endl;
  rep(i,100){
    rep(j,100){
      cout<<G[i][j];
    }
    cout<<endl;
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val a = Array.fill(N)(sc.nextInt)

    var n = 0
    a.foreach { a =>
      var aa = a
      while (aa % 2 == 0) {
        aa /= 2
        n += 1
      }
    }
    n.toString
  }
}





Measured memory_bytes: 37984
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;
 
#define mod 1000000007

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    map<pair<int, int>, int> m, m2;
    int a[100001], b[100001];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        m[make_pair(a[i], b[i])] = 1;
        m2[make_pair(a[i], b[i])] = i;
    }
    bool ischecked[100001][3][3];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                ischecked[i][j][k] = false;
            }
        }
    }
    long long int ans[100001] = {};
    long long int sum = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(ischecked[i][j][k]) continue;
                // i番目の黒マスが3*3の正方形のうち(j, k)にあるとする(左上が(0, 0), 右下が(2, 2))
                long long int result = 0;
                bool isinfield = true;
                for(int p = a[i] - j; p < a[i] - j + 3; p++){
                    if(p <= 0 || p > h){
                        isinfield = false;
                        continue;
                    }
                    for(int q = b[i] - k; q < b[i] - k + 3; q++){
                        if(q <= 0 || q > w){
                            isinfield = false;
                            continue;
                        }
                        if(m.find(make_pair(p, q)) != m.end()){
                            result++;
                            int tmp = m2[make_pair(p, q)];
                            // cout << "checked->" << tmp << " " << p - a[i] + j << " " << q - b[i] + k << endl;
                            if(ischecked[tmp][p - a[i] + j][q - b[i] + k]) isinfield = false;
                            ischecked[tmp][p - a[i] + j][q - b[i] + k] = true;
                        }
                    }
                }
                
                if(isinfield){
                    ans[result]++;
                    sum++;
                    // cout << i << " " << j << " " << k << " " << result << endl;
                }
                // cout << endl;
            }
        }
    }
    cout << (long long int)(w - 2) * (h - 2) - sum << endl;
    for(int i = 1; i < 10; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define N 3000
#define MOD 998244353
ll f[N+10][N+10];
int A[N+10];
int ans=0;
void solve()
{
	int n,s;
	cin>>n>>s;
	for (int i=1;i<=n;i++)
		cin>>A[i];
	f[0][0]=1;
	for (int i=1;i<=n;i++)
		for (int j=0;j<=3000;j++)
		{
				if (A[i]<=j)
					f[i][j]=(f[i-1][j]*2+f[i-1][j-A[i]])%MOD;
				else
					f[i][j]=(f[i-1][j]*2)%MOD;				
		}
	
	cout<<f[n][s]<<endl;
}



int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	int t;
//	cin>>t;
//	while (t--) 
	solve();
	return 0;
}

Measured memory_bytes: 74128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();

        long[] A = new long[N];
        long[] B = new long[N];

        for(int i = 0;i<N;i++)
        {
            A[i] = cin.nextInt();
            B[i] = cin.nextInt();
        }

        long sum = 0;
        for(int i = N-1;i>=0;i--)
        {
            if ((sum + A[i]) % B[i] == 0) continue;
            sum += B[i] - ((sum + A[i]) % B[i]);
        }

        Console.WriteLine(sum);

    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 8384
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef pair<ul, ul> P;




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

	if(N==25){
		cout << "Christmas" << endl;
	}
	else if(N==24){
		cout << "Christmas Eve" << endl;
	}
	else if(N==23){
		cout << "Christmas Eve Eve" << endl;
	}
	else if(N==22){
		cout << "Christmas Eve Eve Eve" << endl;
	}


	return 0;
}

Measured memory_bytes: 764
//CazadorDivino
#include "bits/stdc++.h"
#include <cmath>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)


#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<int,int> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

//~ struct no{
	//~ int x, y;
	//~ int cust;
	//~ no(int x ,int y, int cust):x(x),y(y),cust(cust){
	//~ }
//~ };
//~ vector<no> g;
//~ bool vis[N];
//~ int v[N];
//~ void dfs(int u){
    //~ vis[u] = true;
    //~ rep(i,0,sz(g[u].x)-1){
        //~ if(!vis[g[u]])
            //~ dfs(g[u][i]);
    //~ }
    //~ return;
//~ }

//~ void add(int x, int y, int z){
	//~ no a(x,y,z);
	//~ g[x].pb(a);
	//~ g[y].pb(a);
//~ }

int main(){	
	//~ int n; cin>> n;
	//~ rep(i,1,n){
		//~ cin>> v[i];
	//~ }
	//~ int x , y , z;
	//~ rep(i,1,n-1){
		//~ cin>> x >> y >> z;
		
	//~ }
	
	int n; cin>> n; 
	if(n == 1){
		cout<<"Hello World";
	}
	else{
		int x, y;
		cin>> x >> y;
		cout<< x+y;
	}
	return 0;
}
	


Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
string sA="a";
string sB="b";
string sC="c";
int n,A,B,C;
string S;
string dp[52][52][52];
void upd(string &cur,string s,int tlen)
{
	if(s.size()==tlen&&s+S+S.substr(0,n-s.size())>=S+S)cur=max(cur,s);
}
bool check()
{
//	cerr<<"check:"<<S<<endl;
	for(int i=0;i<=A;i++)
	{
		for(int j=0;j<=B;j++)
		{
			for(int k=0;k<=C;k++)
			{
				string &cur=dp[i][j][k];
				cur="";
				if(i>0)upd(cur,sA+dp[i-1][j][k],i+j+k);
				if(j>0)upd(cur,sB+dp[i][j-1][k],i+j+k);
				if(k>0)upd(cur,sC+dp[i][j][k-1],i+j+k);
//				cerr<<i<<" "<<j<<" "<<k<<":"<<cur<<endl;
			}
		}
	}
	return dp[A][B][C].size()==n;
}
int main()
{
	cin>>A>>B>>C;
	n=A+B+C;
	S.resize(n);
	for(int i=0;i<n;i++)S[i]='a';
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<3;j++)
		{
			S[i]='a'+j;
			if(!check())
			{
				S[i]='a'+j-1;
				break;
			}
		}
	}
	cout<<S<<endl;
	return 0;
}


Measured memory_bytes: 1664
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
s = input().split(" ")
route = [int(i) for i in s]

price_of_route = []
for i in range(N + 1 ) :
    if i == 0 : 
        price_of_route.append( abs(route[i] - 0) )
    elif i == N : 
        price_of_route.append( abs(route[i-1] - 0) )
    else:
        price_of_route.append( abs(route[i] - route[i-1]) )

X = sum(price_of_route)

for i in range(N) : 
    if i == 0 :
        rst = X - price_of_route[0] - price_of_route[1] + abs(route[1] - 0) 
    elif i == N-1 : 
        rst = X - price_of_route[len(price_of_route) - 1] - price_of_route[len(price_of_route) - 2] + abs(route[N - 2] - 0) 
    else : 
        rst = X - price_of_route[i] - price_of_route[i + 1]  + abs(route[i + 1 ] - route[i-1]) 
        
    print(rst)

Measured memory_bytes: 20312
#include <stdio.h>
int n,A[200000],Left[100001],Right[100001],i,j,k;
long long count=0;
void Merge(int left,int mid,int right){
  int n1=mid-left,n2=right-mid;
  for(i=0;i<n1;i++)
    Left[i]=A[left+i];
  for(i=0;i<n2;i++)
    Right[i]=A[mid+i];
  Left[n1]=1000000001;
  Right[n2]=1000000001;

  for(i=0,j=0,k=left;k<right;k++){
    if(Left[i]>Right[j]){
      A[k]=Right[j++];
      count+=n1-i;
    }
    else A[k]=Left[i++];
  }
}
void MergeSort(int left,int right){
  int mid;
  if(right-left>1){
    mid=(left+right)/2;
    MergeSort(left,mid);
    MergeSort(mid,right);
    Merge(left,mid,right);
  }
}
int main(void){
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  MergeSort(0,n);
  printf("%lld\n",count);
  return 0;
}


Measured memory_bytes: 3416
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        int sum = 0;
        
        if(n == m)
            sum += n + m;
        else if(n > m)
            sum += n*2 -1;
        else
            sum += m*2 -1;
        
        System.out.println(sum);
    }
}


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

int main(){
  int N = 0;
  cin >> N;
  int min = 0;
  if(N > 0){
  rep(i, N){
    int a;
    int t_min = 0;
    cin >> a;
    bool flg = true;
    while(flg){
      if(a % 2 == 0){
        a /= 2;
        t_min++;
      }else{
        flg = false;
      }
    }
    if(i == 0){
      min = t_min;
    }else if(t_min < min){
      min = t_min; 
    }
  }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,ans=0,in;
	cin>>n;
	vl v(n);
	rep(i,n)cin>>v[i];
	rep(i,n){
		cin>>in;
		ans+=max(0,v[i]-in);
	}
	cout<<ans<<endl;
}


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

int R, C;
char G[1005][1005];
queue<pair<int, pair<int, int> > > Q;
int dist[1005][1005];

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

int main() {

  cin >> R >> C;
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      cin >> G[i][j];
      if (G[i][j] == '#') {
        Q.push(make_pair(0, make_pair(i, j)));
      }
    }
  }

  memset(dist, -1, sizeof(dist));
  while (!Q.empty()) {
    int d = Q.front().first, r = Q.front().second.first, c = Q.front().second.second;
    Q.pop();
    if (dist[r][c] != -1) continue;
    dist[r][c] = d;
    for (int i=0; i < 4; i++) {
      if (r + dx[i] >= 0 && r + dx[i] < R && c + dy[i] >= 0 && c + dy[i] < C) {
        Q.push(make_pair(d + 1, make_pair(r + dx[i], c + dy[i])));
      }
      
    } 
  }

  int big = -1;
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      if (dist[i][j] > big) {
        big = dist[i][j];
      }
    }
  }
  cout << big;

}

Measured memory_bytes: 53448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int N=3630000;
const int INF=123456789;

int f[11];
int dp[2][N];

inline int get_idx(const vector<int> &a)
{
    int n = a.size();
    int ret=0;
    vector<bool> use(n,false);
    rep(i,n)
    {
        int ct=0;
        rep(j,a[i])if(!use[j]) ++ct;

        ret += ct*f[n-1-i];

        use[a[i]]=true;
    }
    return ret;
}

inline vector<int> get_vec(int n, int idx)
{
    vector<int> ret(n);
    vector<bool> use(n,false);
    rep(i,n)
    {
        int s = idx/f[n-1-i];
        int j=0,ct=0;
        while(1)
        {
            if(!use[j])
            {
                ++ct;
                if(ct==s+1) break;
            }
            ++j;
        }

        use[j]=true;
        ret[i]=j;
        idx -= s*f[n-1-i];
    }
    return ret;
}

int main()
{
    f[0]=1;
    for(int i=1; i<=10; ++i) f[i] = f[i-1]*i;

    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n)
    {
        cin >>a[i];
        --a[i];
    }

    rep(d,2)
    {
        int start = d?get_idx(a):0;
        fill(dp[d],dp[d]+N,INF);
        dp[d][start]=0;
        queue<int> que;
        que.push(start);
        while(!que.empty())
        {
            int now = que.front();
            que.pop();

            vector<int> x = get_vec(n,now);
            rep(i,n)for(int j=i+2; j<=n; ++j)
            {
                reverse(x.begin()+i, x.begin()+j);

                int nx = get_idx(x);
                if(dp[d][nx]>dp[d][now]+1)
                {
                    dp[d][nx] = dp[d][now]+1;
                    if(dp[d][nx]<4) que.push(nx);
                }

                reverse(x.begin()+i, x.begin()+j);
            }
        }
    }

    int ans=9;
    rep(i,N)if(dp[0][i]<INF && dp[1][i]<INF) ans=min(ans,dp[0][i]+dp[1][i]);

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 31724
def find(x)
  while $ps[x][1] != x do
    x=$ps[x][1]
  end
  return x
end
def init(n)
  n.times{|i|
    $ps[i] = [0, i]
  }
end

def update(x,y)
  if $ps[x][0] > $ps[y][0]
    $ps[y][1] = x
  else
    $ps[x][1] = y
    if $ps[x][0] == $ps[y][0]
      $ps[y][0] += 1
    end
  end
end

$ps={}
n,q = gets.split.map(&:to_i)
init(n)
q.times{|i|
  com, x, y = gets.split.map(&:to_i)
  if com == 0
    x = find(x)
    y = find(y)
    update(x,y)
  else
    x = find(x)
    y = find(y)
    puts x==y ? 1 : 0
  end
}


Measured memory_bytes: 9432
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_108
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int l = ReadInt();
            var marginList = new List<bool>();
            int m = 0;
            int ll = l;
            while (ll > 1)
            {
                marginList.Add(ll % 2 == 1);
                m += 2 + (ll & 1);
                ll /= 2;
            }
            int n = marginList.Count;
            Console.WriteLine((n + 1) + " " + m);
            for(int i = 0; i < marginList.Count; i++)
            {
                if (marginList[i])
                {
                    l--;
                    Console.WriteLine((i + 1) + " " + (n + 1) + " " + l);
                }
                Console.WriteLine((i + 1) + " " + (i + 2) + " " + 0);
                Console.WriteLine((i + 1) + " " + (i + 2) + " " + l / 2);
                l /= 2;
            }
        }

        static List<int> PrimeFactors(int n)
        {
            var res = new List<int>();
            int tmp = n;

            for (int i = 2; i * i <= n; i++)
            {
                if (tmp % i == 0)
                {
                    while (tmp % i == 0)
                    {
                        tmp /= i;
                        res.Add(i);
                    }
                }
            }
            if (tmp != 1) res.Add(tmp);//最後の素数も返す

            return res;
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
/*
 * Author       : YangDavid
 * Created Time : 2019年06月01日 星期六 20时03分41秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

string s;
int lost;
int main() {
    cin >> s;
    for(auto c : s) if(c == 'x') lost++;
    if(lost > 7) puts("NO");
    else puts("YES");

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<iomanip>

#define rep(i,start,n) for(int i=0 ; i<n ; i++)

using namespace std;

int main(){

double x1=0,y1=0,x2=0,y2=0;                               //?????°??????
double ac=0,bd=0,abcd=0;
double dist=0;

cin >> x1 >> y1 >> x2 >> y2;                              //??\???

ac = (x2-x1) * (x2-x1);                                //??????????????????
bd = (y2-y1) * (y2-y1);                                //??????????????????
abcd = ac + bd;                                          //????¨?

dist = sqrt(abcd);                                         //????¨????????????????dist???????´?

cout << fixed << setprecision(8) << dist << endl;               //?°???°????¬¬8????????§??¨???

return 0;

}

Measured memory_bytes: 1284
import sys
sys.setrecursionlimit(10**6)

N=int(input())

G = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(lambda x:int(x)-1, input().split())
    G[a].append([b,i])
    G[b].append([a,i])

def bfs(x, c, b):
    if seen[x]:
        return
    seen[x] = True
    if b!=-1:
        global k
        color[b] = c
        k = max(k,c)
    t = 1
    for i,b in G[x]:
        if t==c:
            t+=1
        if not(seen[i]):
            bfs(i,t,b)
            t+=1

seen = [False]*N
color = [0]*N
k=0
bfs(0, 0, -1)


print(k)
print(*color[:-1],sep='\n')



Measured memory_bytes: 78844
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}


fun main() {
    val N = nextInt()
    val K = nextInt()
    val X = nextInt()
    val Y = nextInt()
    val ans = when {
        N <= K -> X * N
        else -> X * K + Y * (N - K)
    }
    println(ans)
}

Measured memory_bytes: 34596
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var as = toIntArr(input[1].split(' '));
	var bs = [];
	for(var i = 0; i < n; i++){
		bs[i] = as[i] - i - 1;
	}
	var cs = bs.sort(function(a,b){return a-b});
	function abs(a){
		return a>0? a: -a;
	}
	function sum(b,array){
		var sums = 0;
		for(var j = 0;j<n;j++){
			sums += abs(array[j] - b);
		}
		return sums;
	}
	var m = n%2===1? (n-1)/2: n/2;
	var ans = sum(cs[m],cs);
	if(n>1)var ans1 = sum(cs[m+1],cs);
	if(ans1 < ans) ans = ans1;
	console.log(ans);
}

Measured memory_bytes: 37852
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>         // abs
typedef long long ll;
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < int(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

int main()
{
	int n, m, c;
	cin >> n >> m >> c;
	vector<int>B(m);
	rep(i, m) cin >> B[i];
	vector<vector<int>> A(n, vector<int>(m));
	int ans = 0;
	rep(i, n) {
		int sum = c;
		rep(j, m) {
			cin >> A[i][j];
			sum += A[i][j] * B[j];
		}
		if (sum > 0) ans++;
	}

	cout << ans << endl;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n); i >= 0; i--)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define RREP(i, a, n) for(int i = (int)(n); i >= a; i--)
#define all(x) (x).begin(),(x).end()

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; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

#define MAX 510000
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    ll ans = 1;
    
    REP(i, 2, N+1)
    {
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 12160