akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<pair<int, int>> R(N);
    vector<pair<int, int>> B(N);
    REP(i, 0, N) {
        int a, b; cin >> a >> b;
        R[i] = make_pair(a, b);
    }
    REP(i, 0, N) {
        int a, b; cin >> a >> b;
        B[i] = make_pair(a, b);
    }

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

    int ans = 0;
    REP(i, 0, N) {
        int idx = -1, max_y = 0;
        REP(j, 0, N) {
            if (B[i].first > R[j].first && B[i].second > R[j].second && max_y <= R[j].second) {
                max_y = R[j].second;
                idx = j;
            }
        }
        if (idx != -1) {
            ans++;
            R[idx] = make_pair(INT32_MAX, INT32_MAX);
        }
    }
    cout << ans << endl;
    return 0;
}

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

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let ds: Vec<i32> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let s: Vec<char> = lines.next().unwrap().unwrap().chars().collect();
  let n = ds[0];
  let k = ds[1];
  let c = ds[2];

  let mut l = vec![-1 as i32; k as usize];
  let mut d: i32 = 0;
  let mut w: i32 = 0;
  while d < n && w < k {
    if s[d as usize] == 'o' {
      l[w as usize] = d;
      w += 1;
      d += c + 1;
    } else {
      d += 1;
    }
  }

  let mut r = vec![-1 as i32; k as usize];
  let mut d: i32 = n - 1;
  let mut w: i32 = k - 1;
  while d >= 0 && w >= 0 {
    if s[d as usize] == 'o' {
      r[w as usize] = d;
      w -= 1;
      d -= c + 1;
    } else {
      d -= 1;
    }
  }

  for i in 0..k {
    if l[i as usize] == r[i as usize] {
      println!("{}", l[i as usize] + 1);
    }
  }
}

Measured memory_bytes: 7676
#include <cstdio>
#include <stack>

std::stack<int> st;

int main()
{
  char ch[10];
  while( scanf( "%s", ch ) != EOF )
    {
        if( *ch >= '0' && *ch <= '9' )
        {
            int p;
            sscanf( ch, "%d", &p );

            st.push( p );
        }
        else
        {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();

            st.push( *ch=='+'?b+a:*ch=='-'?b-a:b*a );
        }
    }

    printf( "%d\n", st.top() );

    return 0;
}

Measured memory_bytes: 2708
def subsolve(n, x):
    if(n == 0 and x == 1):
        return 1
    if(x <= 1): # level 1
        return 0
    L1 = (1 << (n + 1)) - 3
    Ps = (1 << n) - 1
    if(x >= 2 * L1 + 2): # level 5
        return 2 * Ps + 1
    if(x > L1 + 2): #level 4
        return Ps + subsolve(n - 1, x - L1 - 2) + 1
    if(x == L1 + 2): # level  3
        return Ps + 1
    return subsolve(n - 1, x - 1) # level 2
if __name__ == '__main__':
    n, x = map(int, input().split())
    print(subsolve(n, x))

Measured memory_bytes: 3064
#include <cstdio>

int main(void) {
    int n;
    scanf("%d", &n);
    int x = 0, y = 0, z = 0;
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        if (a % 4 == 0) {
            x++;
        }
        else if (a % 2 == 0) {
            y++;
        }
        else {
            z++;
        }
    }
    if (z - x + (y % 2) >= 2) {
        puts("No");
    }
    else {
        puts("Yes");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007

int main(){
    ll n, m;
    cin >> n >> m;
    char a[n][m];
    for(ll i= 0; i < n; i++)
    for(ll j = 0; j < m; j++){
        cin >> a[i][j];
    }
    ll dp[n][m];
    if(a[0][0] == '.'){
        dp[0][0] = 1;
    } else {
        dp[0][0] = 0;
    }
    for(ll i =1; i < n; i++){
        if(a[i][0] == '.'){
            dp[i][0] = dp[i - 1][0];
        } else {
            dp[i][0] =0;
        }
    }
    for(ll i =1; i < m; i++){
        if(a[0][i] == '.'){
            dp[0][i] = dp[0][i - 1];
        } else {
            dp[0][i] =0;
        }
    }
    for(ll i= 1; i < n; i++){
        for(ll j = 1; j < m; j++){
            if(a[i][j] == '.'){
                dp[i][j] = (dp[i - 1][j] + dp[i][j -1]) % M;
            } else {
                dp[i][j] = 0;
            }
            
        }
    }

    cout << dp[n - 1][m - 1] % M << endl;
    
}

Measured memory_bytes: 9088
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using G = greater<T>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

const int INF = 2e9;
const LL MOD = 1e9 + 7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, G<T> >;
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;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I "; else cout << A[i] << " ";}}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if (s == "ABC") cout << "ARC";
  else cout << "ABC";
  return 0;
}


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

using namespace std;


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

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

    // 区間[a_l, a_r)が残っている場合での最適な行動をとった場合のX-Yの最大値dp[l][r]
    vector<vector<long long>> dp(N+1, vector<long long>(N+1, 0));

    // 初期条件
    for (int l = 0; l < N; l++) {
        dp[l][l] = 0;
    }

    // dp開始
    for (int len = 1; len <= N; len++) {
        for (int l = 0; l + len <= N; l++) {
            int r = l + len;

            // 先手
            if ((N-len) % 2 == 0) {
                dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1] + a[r-1]);
            } else { //後手
                dp[l][r] = min(dp[l+1][r] - a[l], dp[l][r-1] - a[r-1]);
            }
        }
    }

    cout << dp[0][N] << endl;
	return 0;
}

Measured memory_bytes: 73700
#include<bits/stdc++.h>
#define ll  long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<ll>

#define sz(x) ((int) (x).size())
#define pll pair<long long,long long>
#define mp make_pair
#define F first
#define S second
#define T int tt; cin>>tt; while(tt--)
#define fastio ios_base::sync_with_stdio(false);
 
#define endl '\n'
#define all(a) (a).begin(), (a).end()
#define display(x) for(auto i : x) cout << i << " "; cout << '\n';
#define input(x) for(int i = 0; i < n; i++) cin >> x[i];
#define make(x,y) fill(all(x), y)
#define FO(i,startLoop,n) for (int i = startLoop; i < n; i++)

#define mod 1000000007
#define Y cout<<"YES"<<endl;
#define N cout<<"NO"<<endl;
#define ITFO(myiterator, mymap) for(auto myiterator = mymap.begin(); myiterator!=mymap.end(); ++myiterator)
using namespace std;  
 

int main()
{
    fastio
    cin.tie(NULL); cout.tie(0);
    
    

  int n, w; cin>>n>>w;
  int a[n + 1], val[n + 1];
  a[0] = 0, val[0] = 0;
  FO(i, 1, n+1) cin>>a[i]>>val[i];

  ll dp[n+1][w+1];
  FO(i, 0, n+1) FO(j, 0, w+1) dp[i][j] = 0;

  for(int i = 1; i<=n; ++i)
  {
      for(int j = 1; j<=w; ++j)
      {

        if( a[i] > j ) {  dp[i][j] = dp[i-1][j]; }
        else{
          int need = j - a[i];
      
          dp[i][j] = max(dp[i-1][j], dp[i-1][need] + val[i]);
        }
        // cout<<dp[i][j]<<" ";
      }
      // cout<<endl;
  } 
  cout<<dp[n][w];
  cerr << "\nTime elapsed: "<< 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
   return 0;
}

Measured memory_bytes: 79232
n = int(input())
c = list(input())
hrcnt = 0
rcnt = 0
for i in range(len(c)):
    if c[i]=='R':
        rcnt += 1
for i in range(len(c)):
    if i+1<=rcnt and c[i]=='R':
        hrcnt += 1

wcnt = len(c)-rcnt
if rcnt==len(c) or rcnt==0:
    ans = 0
else:
    ans = rcnt-hrcnt

print(ans)

Measured memory_bytes: 10788
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int par[500];
int find(int a){
	if(par[a] != a){
		par[a] = find(par[a]);
	}
	return par[a];
}

int main(){
	int n, h;
	cin >> n >> h;
	vector<int> edges[500];
	int deg[500];
	for(int i = 0; i < 500; i++){
		deg[i] = 0;
		par[i] = i;
	}
	for(int i = 0; i < n; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int v1 = c;
		int v2 = -d;
		if(c == 0) v1 = -a;
		if(d == 0) v2 = b;
		v1 += 250;
		v2 += 250;
		edges[v1].push_back(v2);
		deg[v1]++;
		deg[v2]--;
		par[find(v1)] = find(v2);
	}
	int ok = 1;
	map<int,int> c;
	for(int i = 0; i < 500; i++){
		if(deg[i] < 0 && i < 250) ok = 0;
		if(deg[i] > 0 && i > 250) ok = 0;
		if(deg[i] > 0){
			c[find(i)] = 1;
		}
	}
	for(int i = 0; i < 500; i++){
		if(edges[i].size() > 0 && c[find(i)] != 1) ok = 0;
	}
	cout << (ok ? "YES" : "NO") << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    string s;
    cin >> s;
    cout << 700+(s[0]=='o')*100+(s[1]=='o')*100+(s[2]=='o')*100 << endl;
    return 0;
}



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

int main(){
    int N; cin >> N;
    int i=1;
    while(N>=i*i){
        i++;
    }
    cout << (i-1)*(i-1);
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/14  Problem: 084_abc_c / Link: https://abc084.contest.atcoder.jp/tasks/abc084_c?lang=en ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	N--;
	VL C(N), S(N), F(N);
	FOR(i, 0, N) {
		cin >> C[i] >> S[i] >> F[i];
	}


	FOR(j,0,N){
		LL t = 0;
		FOR(i, j, N) {
			if (t == S[i])t += C[i];
			else if (t > S[i]) {
				LL ret = t - S[i];
				ret = (ret + F[i] - 1) / F[i];
				t = S[i] + ret*F[i] + C[i];
			}
			else if (t < S[i])t = S[i] + C[i];
		}
		ans = t;
		cout << ans << "\n";
	}
	cout << 0 << endl;
	return 0;
}


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

int main() {
    int a,b;
    cin >> a >> b;
    if((a == 1 && b == 2) || (a == 2 && b == 1))  {
        cout << 3 << endl;
    }else if((a == 1 && b == 3) || (a == 3 && b == 1)){
        cout << 2 << endl;
    }else{
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

long long int gcd(long long int a, long long int b){
	return a%b==0?b:gcd(b,a%b);
}

int main(void){
	int t;
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		long long int a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if(b>a || b > d){
			printf("No\n");
			continue;
		}
		else if(c >= b){
			printf("Yes\n");
			continue;
		}
		long long int g = gcd(d,b);
		if(b-g+a%g > c){
			printf("No\n");
		}
		else{
			printf("Yes\n");
		}
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int d(int a) {return a*a;}

int main()
{
  int h,w;
  while(1){
	cin >> h >> w;
	if (h == 0 && w == 0) break;
	int tai = d(h)+ d(w);
	int ansh=150,answ=0,now=(150*150);
	for (int i = 1; i <= 150; i++) {
	  for (int j = (i + 1); j <= 150; j ++) {
		int newtai = d(i)+d(j);
		if((newtai > tai) && (newtai < now || (newtai == now && i < ansh))){
		  ansh = i;
		  answ = j;
		  now = newtai;
		}else if((newtai == tai) && ((now == tai && i < ansh) || now > tai) && (i > h)){
			ansh = i;
			answ = j;
			now = newtai;
		}
	  }
	}

	cout << ansh << " " << answ << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

map<string, int> mp;

int main()
{
    int n;
    cin>>n;
    REP(i,n) {
        string str;
        cin>>str;
        mp[str]++;
    }
    cout<<mp.size()<<endl;

    return 0;
}


Measured memory_bytes: 19128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    long long a, b, c, ans;

    cin >> a >> b >> c;

    if(a%2==0 || b%2==0 || c%2==0){
        cout << 0 << endl;
    }

    else{
        ans = min(a*b, b*c);
        ans = min(ans, c*a);

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


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


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


mod = 1000000007
inf = float('INF')

# solve


def solve():
    n = II()
    s, t = LS()
    for i in range(n):
        print("{}{}".format(s[i], t[i]), end="")
    print()
    return


# main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 38896
#include <stdio.h>
void sh(int x, int y);
 
int main(void){
	while(1) {
        int h, w, x, y;
        scanf("%d %d", &h, &w);
        if (h == 0 & w == 0) {
            return 0;
        }
        for (y = 0; y < h; y++) {
            for (x = 0; x < w; x++) {
                sh(x, y);
            }
            printf("\n");
        }
        printf("\n");
    }
}
 
void sh(int x, int y)
{
    if (x % 2) {
        if (y % 2) {
            printf("#");
        } else {
            printf(".");
        }
    } else {
        if (y % 2) {
            printf(".");
        } else {
            printf("#");
        }
    }
}

Measured memory_bytes: 2592
#include <iostream>
using namespace std;
int main(){
    int P,Q,R;
    cin >> P >> Q >> R;
    if ((P+Q)<(P+R)){
        if((P+Q)<(Q+R)){
            cout << P+Q <<endl;
        }
        else{
            cout << Q+R << endl;
        }
    }
    else if((P+R)<(Q+R)){
        cout << P+R <<endl; 
    }
    else{
        cout << Q+R <<endl;
    }

    return 0;
}

Measured memory_bytes: 504
using System;
using System.Collections.Generic;
using System.Linq;

static class CircumscribedCircleOfATriangle
{
    static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(
        this IEnumerable<TFirst> source,
        IEnumerable<TSecond> second,
        Func<TFirst, TSecond, TResult> func)
    {
        var q1 = new Queue<TFirst>( source );
        var q2 = new Queue<TSecond>( second );
        while ( q1.Any() && q2.Any() )
            yield return func( q1.Dequeue(), q2.Dequeue() );
    }

    static void Main()
    {
        Func<
            IEnumerable<double>, 
            IEnumerable<double>, 
            Func<double, double, double>, 
            double[]>
            calc = (a, b, f) => a.Zip( b, f ).ToArray();
        var q =
            from n in Enumerable.Repeat( 0, int.Parse( Console.ReadLine() ) )
            let t = Console.ReadLine()
                .Split( ' ' )
                .Zip( new[] { 0, 0, 1, 1, 2, 2 }, 
                    (pc, p) => new { pc, p } )
                .GroupBy( e => e.p, e => e.pc )
                .Select( p => p.Select( double.Parse ).ToArray() )
                .ToArray()
            let a = t.First()
            let v = t.Skip( 1 )
                .Select( p => calc( p, a, (x, y) => x - y ) )
                .Select( ap => new
                {
                    m = ap.Select( c => c / 2 ),
                    tp = new[] { -ap[1], ap[0] }
                } )
                .ToArray()

            let s = calc( v[0].m, v[0].tp, (x, y) => x + y )
            let cross = new[] 
                { 
                    calc( v[1].m, v[0].m, (x, y) => x - y ),
                    calc( s, v[1].m, (x, y) => x - y )
                }
                .Select( x => v[1].tp[0] * x[1] - v[1].tp[1] * x[0] )
                .ToArray()
            let k = cross[0] / cross.Sum()

            let ag = calc( v[0].m, s, (x, y) => x + k * ( y - x ) )
            let og = calc( ag, a, (x, y) => x + y )
            let r = Math.Sqrt( ag[0] * ag[0] + ag[1] * ag[1] )

            select string.Format( "{0:0.000} {1:0.000} {2:0.000}\n", og[0], og[1], r );
        Console.Write( new string( q.SelectMany( _ => _ ).ToArray() ) );
    }
}

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

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

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

    ll ans = 0;
    for (int i = 1; i <= K; i++){
        for (int j = 1; j <= K; j++){
            for (int l = 1; l <= K; l++){
                ans += gcd (gcd (i,j), l);
            } 
        }   
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100010
#define INF 10000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
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;
    }
}
// 二項係数計算 COMinit()を先に使用すること
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,k;
    cin>>n>>k;
    COMinit();
    for(int i=1;i<=k;i++){
        ll ans=(ll)COM(n-k+1,i)*COM(k-1,i-1);
        ans%=MOD;
        OUT(ans);
    }
	return 0;
}

Measured memory_bytes: 23680
package main

import (
	"fmt"
)

func slove(n int) int {
	if n%2 == 1 {
		return 0
	}

	var res int
	n /= 2
	for 0 < n {
		res += n / 5
		n /= 5
	}
	return res
}

func main() {
	var n int
	fmt.Scan(&n)

	fmt.Println(slove(n))
}


Measured memory_bytes: 512
#include <stdio.h>
#define big 101




int main (){
  int i,j,q;
  int k,u,r;
int m[big][big];
  
  for(i=0;i<big;i++)
    for(j=0;j<big;j++)
      m[i][j] = 0;
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&r);r--;
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&u);
      m[r][u-1] = 1;
    }
  }
  for(i=0;i<q;i++){
    
	for(j=0;j<q;j++){
    printf("%d",m[i][j]);
    if (j<q-1) printf(" ");
		}
		printf("\n");
	}
  return 0;
}


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

int main() {
int X,A,B;
cin >> X;
cin >> A;
cin >> B;
int C = X - A;
if(B < C || B == C){
    cout << C%B <<endl;
}
else if(B > C){
    cout << 0 <<endl;
}

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {

	char A[100];
	int  len,i;

	scanf("%s",A);
	len=strlen(A);

	for(i=0;i<len;i++) A[i]='x';

	printf("%s",A);
	return 0;
}


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

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rInt(a) scanf("%d",&a);

main(){
    int n;
    rInt(n);
    int mini, val, maxi;
    int miniPos, maxiPos;
    vector<ll> arr (n);
    cin >> mini; miniPos = 0;
    arr[0] = mini;
    cin >> val;
    arr[1] = val;
    if(val<mini){
        maxi = mini;
        maxiPos = 0;
        mini = val;
        miniPos = 1;
    }else{
        maxi = val;
        maxiPos = 1;
    }
    for(int i=2;i<n;++i){
        cin >> arr[i];
        if(arr[i]<mini) mini = arr[i], miniPos = i;
        if(arr[i]>maxi) maxi = arr[i], maxiPos = i;
    }
    vector<pii> ops;
    if(abs(mini)>maxi){
        rep(i,n){
            if(arr[i]>0){
                ops.push_back(pii(miniPos+1,i+1));
                arr[i] += mini;
            }
        }    
        for(int i=n-1;i>0;--i){
            if(arr[i-1]>arr[i]){
                ops.push_back(pii(i+1,i));
                arr[i-1] += arr[i];
            }
        }
    }else{
        rep(i,n){
            if(arr[i]<0){
                ops.push_back(pii(maxiPos+1,i+1));
                arr[i] += maxi;
            }
        }    
        rep(i,n-1){
            if(arr[i+1]<arr[i]){
                ops.push_back(pii(i+1,i+2));
                arr[i+1] += arr[i];
            }
        }
    }
    printf("%d\n",ops.size());
    rep(i,ops.size()) printf("%d %d\n",ops[i].first,ops[i].second);
}

Measured memory_bytes: 384
import heapq
from sys import stdin
input = stdin.readline

#入力
# s = list(input()[0:-1])
# n = int(input())
x = list(map(int, input().split()))
# a = list(map(int,input().split()))
# b = list(map(int,input().split()))
# w = [int(input()) for i in range(n)]

# ab=[]
# for i in range(N):
#     a,b = map(int, input().split())
#     ab.append((a,b))
 
def main():
    sal = {1:(3*10**5),2:2*(10**5),3:10**5}
    ans = 0
    for i in x:
        if i not in sal:
            continue
        ans+=sal[i]
    if x[0]==1 and x[1]==1:
        ans+=4*(10**5)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
def func(A,B):
    return max(len(str(A)),len(str(B)))

def enum_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def main():
    N = int(input())
    divisors = enum_divisors(N)
    res = float('inf')
    for i in range(len(divisors)):
        A = divisors[i]
        B = int(N/A)
        if B < A:
            break
        res = min(res,func(A,B))

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
from decimal import Decimal

def check(index):
    if index > len(debt_lis)-1:
        for i in range(len(debt_lis)):
            debt_lis[i] = '0'
        debt_lis.append('1')
        return
    if int(debt_lis[index]) + 1 == 10:
        return check(index+1)
    else:
        for i in range(index):
            debt_lis[i] = '0'
        num = int(debt_lis[index]) + 1
        debt_lis[index] = str(num)
        return

input_line = raw_input()
n = int(input_line)

debt = 100000
for i in range(n):
    debt = int((debt * Decimal(1.05))) 
    debt_lis = list(str(debt))
    debt_lis.reverse()
    for char_num in debt_lis[:3]:
        if not int(char_num) == 0:
            check(3)
            break
    debt_lis.reverse()
    debt = int(''.join(debt_lis))
print(debt)

Measured memory_bytes: 5912
#include<stdio.h>

int main()
{
    int a, b, s1, s2, s3, max;
    scanf("%d %d", &a, &b);
    s1 = a+b;
    s2 = a-b;
    s3 = a*b;
    if(s1>=s2 && s1>=s3)
      max=s1;
    else if(s2>=s1 && s2>=s3)
      max=s2;
    else
      max=s3;
    printf("%d\n", max);
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov
//export PATH=:~/.local/bin

int main(){
    string s;
    cin >> s;
    if(s.size()==2){
        if(s[0]==s[1]){
            cout << 1<<" "<<2 << endl;
            return 0;
        }
    }
    rep(i,s.size()-2){
        if(s[i]==s[i+1]){
            cout << i+1 <<" "<<i+2<< endl;
            return 0;
        }
        if(s[i+1]==s[i+2]){
            cout << i+2 <<" "<<i+3<< endl;
            return 0;
        }
        if(s[i+2]==s[i]){
            cout << i+1 <<" "<<i+3<< endl;
            return 0;
        }
    }
    cout << -1<<" "<<-1<< endl;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i,N){
    cin >> A.at(i);
  }
  if(N==K){
    cout << "1" << endl;
  }else if(K==2){
    cout << N-1 << endl;
  }else{
    if((N-1)%(K-1)){
      cout << (N-1)/(K-1)+1 << endl;
    }else{
      cout << (N-1)/(K-1) << endl;
    }
  }
}

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

int main(){
	int n; cin >> n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	vector<long long> bits(30,0);
	for(int k=0;k<bits.size();k++){
		long long T=1<<k;
		vector<int> ta(n),tb(n);
		for(int i=0;i<n;i++) {
			ta[i]=a[i]%(T*2);
			tb[i]=b[i]%(T*2);
		}
		sort(tb.begin(),tb.end());
		for(int i=0;i<n;i++){
			auto it1=lower_bound(tb.begin(),tb.end(),T-ta[i]);
			auto it2=lower_bound(tb.begin(),tb.end(),2*T-ta[i]);
			auto it3=lower_bound(tb.begin(),tb.end(),3*T-ta[i]);
			auto it4=lower_bound(tb.begin(),tb.end(),4*T-ta[i]);
			bits[k]+=(it2-it1)+(it4-it3);
		}
	}
	int ans=0;
	for(int k=0;k<bits.size();k++){
		ans+=((bits[k]%2)<<k);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3432
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,p,d1,d2;
pair<int,int> pa[10000];

int main(){
	while(cin>>n){
		if(!n)return 0;
		for(int i=0;i<n;i++){
			cin>>p>>d1>>d2;
			pa[i]=make_pair(d1+d2,p);
		}
		sort(pa,pa+n);
		cout<<pa[n-1].second<<" "<<pa[n-1].first<<endl;
	}
}

Measured memory_bytes: 944
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int X = scan.nextInt();
		int Y = scan.nextInt();
		int Z = scan.nextInt();

		System.out.println(Z + " " + X + " " + Y);
	}
}

Measured memory_bytes: 23508
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for x in range(n)]

count = 0
for i in a:
  count += 1
  j = 1 
  while True:
    temp = j * i + 1
    if temp > d:
      break
    else:
      count += 1
      j += 1

count += x
print(count)

Measured memory_bytes: 3064
# abc085c

def solve(n, y, bills = [], denoms = [10000, 5000, 1000])
  if denoms.size == 1
    if n * denoms[0] == y
      bills + [n]
    else
      nil
    end
  else
    (0..(y / denoms[0])).reverse_each do |i|
      ans = solve(n - i, y - i * denoms[0], bills + [i], denoms.drop(1))
      if ans
        return ans
      end
    end
    nil
  end
end

n, y = gets.split.map(&:to_i)

triple = solve(n, y)

puts (triple || [-1,-1,-1]).join(' ')


Measured memory_bytes: 6140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////



 
int main(){fastio
    
    ll n,t;cin>>n>>t;
    ll a[n],b[n];rep(i,0,n-1)cin>>a[i]>>b[i];
    ll dp[n+1][t+1];memset(dp,0,sizeof(dp));
    rep(i,0,n-1){
        rep(j,0,t){
            dp[i+1][j]=dp[i][j];
            if(j-1>=0)Max(dp[i+1][j],dp[i+1][j-1]);
            if(j-a[i]>=0)Max(dp[i+1][j],dp[i][j-a[i]]+b[i]);
        }
    }
    ll ep[n+1][t+1];memset(ep,0,sizeof(ep));
    for(ll i=n-1;i>=0;i--){
        rep(j,0,t){
            ep[i][j]=ep[i+1][j];
            if(j-1>=0)Max(ep[i][j],ep[i][j-1]);
            if(j-a[i]>=0)Max(ep[i][j],ep[i+1][j-a[i]]+b[i]);
        }
    }
    /*
    rep(i,0,n){
        rep(j,0,t){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }cout<<endl;
    rep(i,0,n){
        rep(j,0,t){
            cout<<ep[i][j]<<" ";
        }cout<<endl;
    }cout<<endl;
    */
    ll ans=dp[n][t];
    rep(i,0,n-1){
        rep(j,1,t-1){
            ll sum=dp[i][j];
            sum+=ep[i+1][t-j-1];
            sum+=b[i];
            Max(ans,sum);
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


/*
 
 
 3 6
 3 10
 3 20
 3 30
 
 */


Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

#define N 	100*1000+5
int A[N];
void solve(){
	int n;
	cin>>n;
	rep(i,0,n)cin>>A[i];
	if(A[0] != 1) A[0]--;
	rep(i,1,n){
		if(A[i] - A[i-1] >= 1)
			A[i]--;
		else if(A[i] < A[i-1]){
			cout<<"No"<<endl;
			return;
		}
	}
	cout<<"Yes"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main() {
	long long n,ans=1,i;
	string s;
	cin>>n;
	cin>>s;
	for(i=0;i<n-1;i++) {
		if(s[i+1]!=s[i]) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 512
def getIntList(): return [int(x) for x in input().split()]

A = getIntList()

M = A[0]
d10 = int(A[1]/10)
d1 = int(A[1]-d10*10)
count = 0

for i in range(M):
  for j in range(A[1]):
    if(M>3):
      if(A[1]>21):
        d10 = int((j+1)/10)
        d1 = int((j+1)-d10*10)
        if(d1>1):
          if(d10>1):
            if(d1*d10 == (i+1)):
              count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  vector<int> a(n),b(n),c(n);
  REP(i,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  REP(i,n){
    cin>>b[i];
  }
  sort(b.begin(),b.end());
  REP(i,n){
    cin>>c[i];
  }
  sort(c.begin(),c.end());
  long long bc[n];//b[i]より大きいcの要素の数
  int C=0;
  REP(i,n){
    if(C==n){
      bc[i]=0;
      continue;
    }
    while(b[i]>=c[C]){
      C++;
      if(C==n){
        break;
      }
    }
    if(C==n){
      bc[i]=0;
      continue;
    }else{
      bc[i]=n-C;
    }
  }
  int B=0;
  int abi[n];//a[i]<b[j]となるような最小のjを格納する配列
  REP(i,n){
    if(B==n){
      abi[i]=-1;
      continue;
    }
    while(a[i]>=b[B]){
      B++;
      if(B==n){
        break;
      }
    }
    if(B==n){
      abi[i]=-1;
      continue;
    }else{
      abi[i]=B;
    }
  }
  
  for(int i=n-1;i>=0;i--){
    if(i==n-1){
      continue;
    }else{
      bc[i]=bc[i]+bc[i+1];
    }
  }
  long long ans=0;
  REP(i,n){
    if(abi[i]==-1){
      break;
    }else{
      ans += bc[abi[i]];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;
int main() {

    int i, j;

    for (i = 1; i <= 9; i++) {
	for (j = 1; j <= 9; j++) {
	    cout << i << "x" << j << "=" << i*j << endl;
	}
    }

    return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

//UnionFind1
int n = 300000;
vector<int> par1(n);
vector<int> size1(n);

void init1(int n){
  for(int i=0; i<n; i++){
    par1.at(i) = i;
    size1.at(i) = 1;
  }
}

int root1(int x){
  if(par1.at(x) == x){
    return x;
  }
  else{
    return par1.at(x) = root1(par1.at(x));
  }
}

bool same1(int x, int y){
  return root1(x) == root1(y);
}

void unite1(int x, int y){
  x = root1(x);
  y = root1(y);
  if(x == y){
    return;
  }
  if (size1.at(x) < size1.at(y)){
    swap(x, y);
  }
  size1.at(x) += size1.at(y);
  par1.at(y) = x;
}

int size_x1(int x){
  return size1.at(root1(x));
}

//UnionFind2
vector<int> par2(n);
vector<int> size2(n);

void init2(int n){
  for(int i=0; i<n; i++){
    par2.at(i) = i;
    size2.at(i) = 1;
  }
}

int root2(int x){
  if(par2.at(x) == x){
    return x;
  }
  else{
    return par2.at(x) = root2(par2.at(x));
  }
}

bool same2(int x, int y){
  return root2(x) == root2(y);
}

void unite2(int x, int y){
  x = root2(x);
  y = root2(y);
  if(x == y){
    return;
  }
  if (size2.at(x) < size2.at(y)){
    swap(x, y);
  }
  size2.at(x) += size2.at(y);
  par2.at(y) = x;
}

int size_x2(int x){
  return size2.at(root2(x));
}


int main(){
  int N, K, L;
  cin >> N >> K >> L;
  init1(N);
  init2(N);
  vector<vector<int>> vec1(K,vector<int>(2));
  for(int i=0; i<K; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    vec1.at(i).at(0) = a;
    vec1.at(i).at(1) = b;
    unite1(a,b);
  }
  vector<vector<int>> vec2(L,vector<int>(2));
  for(int i=0; i<L; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    vec2.at(i).at(0) = a;
    vec2.at(i).at(1) = b;
    unite2(a,b);
  }
  
  map<P,int> mp;
  for(int i=0; i<N; i++){
    P add = {root1(i),root2(i)};
    mp[add]++;
  }
  
  for(int i=0; i<N; i++){
    P add = {root1(i),root2(i)};
    cout << mp[add] << endl;
  }
}

Measured memory_bytes: 29768
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
typedef vector<ll> vec;
const int MAX_N=2000;
int N;
const ll MOD=1e9+7;
vector<int> G[MAX_N];
vec dp[MAX_N][3];
ll minv2;
ll mpw(ll n,ll m){
	ll ret=1;
	while(m){
		if(m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return ret;
}
void add(ll &a,ll b){
	a+=b;
	if(a>=MOD){
		a-=MOD;
	}
}
void dfs(int v,int p){
	REP(i,3){
		int a=0;
		if(i==0)a=1;
		dp[v][i].push_back(a);
	}
	for(auto e:G[v]){
		if(e!=p){
			dfs(e,v);
			int n=(int)dp[v][0].size(),m=(int)dp[e][0].size();
			vec tmp[3];
			REP(i,3){
				tmp[i].resize(n+m);
			}
			REP(i,n){
				REP(d1,3){
					REP(j,m){
						REP(d2,3){
							int c2,d3;
							c2=i+j+1;
							d3=d1;
							add(tmp[d3][c2],dp[v][d1][i]*dp[e][d2][j]%MOD);
							if(d1==2 || d2==2)continue;
							d3=d1+1;
							ll x;
							c2--;
							if(d1==0 && d2==0){
								x=2;
							}else if(d1==0 || d2==0){
								x=1;
							}else{
								x=minv2;
							}
							add(tmp[d3][c2],dp[v][d1][i]*dp[e][d2][j]%MOD*x%MOD);
						}
					}
				}
			}
			REP(i,3){
				dp[v][i]=tmp[i];
			}
		}
	}
}
			
int main(){
	minv2=mpw(2,MOD-2);
	cin>>N;
	REP(i,N-1){
		int b;
		cin>>b;
		b--;
		G[i+1].push_back(b);
		G[b].push_back(i+1);
	}
	dfs(0,-1);
	ll ans=0,x=1,sgn=1;
	REP(i,N-1)sgn*=-1;
	REP(i,N){
		x*=(i+1);
		x%=MOD;
		REP(j,3){
			add(ans,(sgn*(dp[0][j][i]*x)%MOD+MOD)%MOD);
		}
		sgn*=-1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 53632
#include <iostream>

using namespace std;
#include <string>
typedef long long int ll;
#include <algorithm>
#include <stack>
#include <vector>
#include <array>
#include <queue>


int main(){

  string S;
  cin >> S;
  vector<int> ninzuu(S.size(),0);

  int n = 0;
  int o = -1;//0=guusuu;

  int i = 0;
  while(i<S.size()){
    if(S[i]=='R'){
      n += 1;
      o += 1;
    }else{//Lにぶつかったとき
      o += 1;
      //cout << i <<endl;
      if(n>0){
        if(o%2==0){
          ninzuu[i] += n/2;
          ninzuu[i-1] += n/2;
        }else{
          ninzuu[i] += n/2;
          ninzuu[i-1] += n/2+1;
        }
      }
      n = 0;
      o = -1;
    }
    i += 1;
  }





  i = S.size()-1;
  n = 0;
  o = -1;
  while(i>=0){
    if(S[i]=='L'){
      n+=1;
      o+=1;
    }else{
      o+=1;
      if(n>0){
        if(o%2==0){
          ninzuu[i] += n/2;
          ninzuu[i+1] += n/2;
        }else{
          ninzuu[i] += n/2;
          ninzuu[i+1] += n/2+1;

        }
      }
      n=0;
      o=-1;
    }
    i -= 1;
  }

  for(int i=0;i<S.size();i++){
    cout << ninzuu[i]<<endl;
  }
  return 0;

}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n";



int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);

    int a;
    int b;
    cin >> a >> b;
    cout << a*b << endl;

   
    

}


Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    
    int n,gap,what;
    int a[1001];
    
    while (1){
        cin >> n ;
        if(n == 0 ) break;
        
        for(int i=0;i<n;i++) {
            cin >> a[i];
        }
        gap = abs(a[0]-a[1]);
        
        for(int i = 0; i<n;i++){
            for(int j = i+1;j<n;j++){
                what = abs(a[i]-a[j]);
                if(gap>= what) gap = what;
            }
        }
        cout << gap << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3064
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    B = [0]*(N-1)
    B[0] = A[0]
    for i in range(1, N - 1):
        B[i] = B[i - 1] + A[i]
    i = N - 2
    # print(A, B)
    while i >= 0:
        if A[i + 1] <= B[i] * 2:
            i -= 1
        else:
            break
    print(N - i - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14224
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    return 0;
}

Measured memory_bytes: 256
def ave(n):
    return (n+1)/2

n, k = map(int, input().split())
p = list(map(int, input().split()))

sum = 0

for i in range(k):
    sum += ave(p[i])

max_sum = sum

for i in range(n-k):
    sum -= ave(p[i])
    sum += ave(p[i+k])
    max_sum = max(sum, max_sum)

print(max_sum)

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

int ssn;

int check_digit(int x[10][10],int a,int b,int c,int d){
  return x[x[x[x[0][a]][b]][c]][d];
}

int check(int x[10][10],int a,int b,int c,int d,int e){
  if(ssn==10000*a+1000*b+100*c+10*d+e) return 1;
  return x[x[x[x[x[0][a]][b]][c]][d]][e];
}

int human_error(int x[10][10],int a,int b,int c,int d,int e){
  ssn=10000*a+1000*b+100*c+10*d+e;
  for(int i=0;i<10;i++){
    if(i==a) continue;
    if(!check(x,i,b,c,d,e)) return 1;
  }
  for(int i=0;i<10;i++){
    if(i==b) continue;
    if(!check(x,a,i,c,d,e)) return 1;
  }
  for(int i=0;i<10;i++){
    if(i==c) continue;
    if(!check(x,a,b,i,d,e)) return 1;
  }
  for(int i=0;i<10;i++){
    if(i==d) continue;
    if(!check(x,a,b,c,i,e)) return 1;
  }
  for(int i=0;i<10;i++){
    if(i==e) continue;
    if(!check(x,a,b,c,d,i)) return 1;
  }
  if(!check(x,b,a,c,d,e)) return 1;
  if(!check(x,a,c,b,d,e)) return 1;
  if(!check(x,a,b,d,c,e)) return 1;
  if(!check(x,a,b,c,e,d)) return 1;
  return 0;
}

int main(){
  int x[10][10];
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      cin>>x[i][j];

  int n=0;
  int e;
  for(int a=0;a<10;a++)
    for(int b=0;b<10;b++)
      for(int c=0;c<10;c++)
	for(int d=0;d<10;d++){
	  e=check_digit(x,a,b,c,d);
	  n+=human_error(x,a,b,c,d,e);
	}
  cout<<n<<endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}

#define MOD 1000000007
typedef long long ll;

ll kaijou(ll n){
  if(n==1)return 1;
  return kaijou(n-1)*n%MOD;
}

int main(){
  ll n,m;
  cin >> n >> m;
  if(abs(n-m)>1){
    cout << 0 << endl;
    return 0;
  }
ll ans;
  if(n==m){
    ans=kaijou(n)*kaijou(n)%MOD;
    ans=ans*2%MOD;
  }else{
    ans=kaijou(n)*kaijou(m)%MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792