akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	deque<int> q;
	int n, i, j, k, x;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x;
		if (i % 2 == 0) q.push_back(x);
		else q.push_front(x);
	}

	vector<int> a;
	while (!q.empty()) {
		a.push_back(q.front());
		q.pop_front();
	}

	if (n % 2 == 1) reverse(a.begin(), a.end());
	for (auto p : a)cout << p << " ";
	cout << "\n";

	return 0;
}


Measured memory_bytes: 3952
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = n / 2;
    if (n % 2 == 1)
    {
        cout << ans + 1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a[10],b[10],i,j,t;
  for(i=0;i<10;i++){
    scanf("%d",&a[i]);
    for(j=i;j;j--){
      if(a[j-1]<a[j]){
	t=a[j-1];
	a[j-1]=a[j];
	a[j]=t;
      }
    }
  }
  a[0]+=a[1]+a[2];
  for(i=0;i<10;i++){
    scanf("%d",&b[i]);
    for(j=i;j;j--){
      if(b[j-1]<b[j]){
	t=b[j-1];
	b[j-1]=b[j];
	b[j]=t;
      }
    }
  }
  b[0]+=b[1]+b[2];
  printf("%d %d\n",a[0],b[0]);
  return 0;
}

Measured memory_bytes: 596
N=int(input())
A=list(map(int,input().split()))
S=sum(A)%(10**9+7);T=0
for i in range(N-1):
  T=T+(A[i]%(10**9+7)*(S-A[i]%(10**9+7)))
  S=S-A[i]%(10**9+7)
  #print(i,T)
print(T%(10**9+7))

Measured memory_bytes: 31692
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n,m,k;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int h=0,o;
        o=m;
        while(o>0)
        {
            o=o/10;
            h++;
        }
        for (int i=0;i<h;i++) n=n*10;
        k=n+m;
        double b=sqrt(k);
        int c=b;
        if (c*c==k) printf("Yes\n"); else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int _max = -1145141919;
    int _min = 1145141919;
    long long sum = 0;
    for(int i = 0;i < n;i++) {
        int a;
        cin >> a;
        sum += a;
        _min = min(_min,a);
        _max = max(_max,a);
    }
    printf("%d %d ",_min,_max);
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3248
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

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

    for _ in range(K):
        if B <= A:
            B *= 2
        elif C <= B:
            C *= 2
    
    if A < B < C:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 10396
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n;
string s;

int main() {
    cin >> n >> s;
    int ans = 1;
    for (int i = 1; i < s.length(); i++) {
        if (s[i] != s[i-1]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
use std::cmp;

// use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let mut a : Vec<u64> = read_vec::<u64>();

    let answer = solve(n, &mut a);
    println!("{}", answer);
}

fn solve(n: usize, a: &mut [u64]) -> u64 {
    // 1. Get XOR of whole set
    let mut all_xor : u64 = 0;
    for i in 0..n {
        all_xor = all_xor ^ a[i];
    }
    //println!("all_xor = {}", all_xor);

    // 2. Ignore bits where all_xor is 1.
    //    For those bits, always XOR(A) + XOR(B) = 1. So you don't need to calculate it.
    for i in 0..n {
        a[i] = a[i] & !all_xor;
    }

    // 3. Gauss Elimination
    let rank = gauss_elim(n, a);
    //println!("rank = {}", rank);
    //print_a(n, a);

    // 4. Get max XOR for bits where all_xor is 0.
    let mut x : u64 = 0;
    for i in 0..rank {
        x = cmp::max(x ^ a[i], x);
    }
    //println!("x = {}", x);
    
    return 2 * x + all_xor;
}

fn gauss_elim(n: usize, a: &mut [u64]) -> usize{
    let mut rank : usize = 0;
    for i in (0..60).rev() {
        //println!("i = {}", i);
        //print_a(n, a);
         // 1. Find Pivot
        let mut pivot:usize = std::usize::MAX;
        for j in rank..n {
            if a[j] & (1u64 << i) > 0 {
                pivot = j;
                break;
            }
        }
        if pivot == std::usize::MAX {
            continue;
        }
        a.swap(rank, pivot);

        // 2. Make the target bit of other rows to 0
        for j in rank+1..n {
            if a[j] & (1u64 << i) == 0 {
                continue;
            }
            a[j] = a[j] ^ a[rank];
        }
        rank += 1;
    }
    return rank;
}

fn print_a(n:usize, a: &[u64]) {
    for i in 0..n {
        println!("  {:?}", a[i]);
    }
}


Measured memory_bytes: 8444
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from fractions import gcd

def main():
    A, B, C, D = LI()
    ans = B - A + 1
    ans -= (B // C) - ((A - 1) // C)
    ans -= (B // D) - ((A - 1) // D)
    E = C * D // gcd(C, D)
    ans += (B // E) - ((A - 1) // E)
    return ans

print(main())

Measured memory_bytes: 66028
n = int(input())
h = list(map(int, input().split()))

ans = True
h[0] -= 1
for i in range(1, n):
    if h[i - 1] > h[i]:
        ans = False
        break
    if h[i - 1] < h[i]:
        h[i] -= 1

print('Yes' if ans else 'No')


Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define Author std::ios_base::sync_with_stdio(0);
#define ABHISHEK_SHARMA cout.tie(0);
#define IIIT_ALLAHABAD cin.tie(0);

int main(){
    //Booster
    Author
        ABHISHEK_SHARMA
        IIIT_ALLAHABAD
    //Driver Code here
    ll n, i, t=0, a, b, c;
    cin>>a>>b>>c;
    cout<<max(a,max(b,c))-min(a,min(b,c));
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# 最大公約数
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)

# 入力
n = int(input())
a = list(map(int, input().split()))

# 累積GCD
left = [0]*(n+1)
right = [0]*(n+1)
for i in range(n):
    left[i+1] = gcd(left[i], a[i])
for i in reversed(range(n)):
    right[i] = gcd(right[i+1], a[i])

# print(left)
# print(right)

# 集計
ans = 0
for i in range(n):
    l = left[i]
    r = right[i+1]
    ans = max(ans, gcd(l, r))

print(ans)

Measured memory_bytes: 14584
// 2011/12/01 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool F[30];
	for(int i=0; i<30; i++)
		F[i] = false;

	for(int i=0; i<28; i++){
		int x;
		cin >> x;
		F[x-1] = true;
	}

	for(int i=0; i<30; i++)
		if(!F[i])
			cout << i+1 << endl;

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;



int main(){
    string s; cin >> s;
    if(s=="Sunny") cout << "Cloudy" << endl;
    if(s=="Cloudy") cout << "Rainy" << endl;
    if(s=="Rainy") cout << "Sunny" << endl;
    
    return 0;
    
    
    
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

MOD = 1000000007
SUM = 0
for i in range(N):
  SUM += A[i]
SUM = SUM*SUM
for i in range(N):
  SUM -= A[i]*A[i]
SUM = SUM // 2
SUM %= MOD
print(SUM)
    

Measured memory_bytes: 31508
use proconio::input;
use proconio::marker::Chars;

fn f(p: &mut Vec<(i64, i64)>) -> bool {
    p.sort_by_key(|&p_i| std::cmp::Reverse(p_i));
    let mut c = 0;
    for &(b, r) in p.iter() {
        if c + b < 0 {
            return false;
        }
        c += r;
    }
    true
}

fn main() {
    input! {
        n: usize,
        s: [Chars; n],
    };
    let mut sum = 0;
    let mut p_l = vec![];
    let mut p_r = vec![];
    for s_i in s.iter() {
        // 初期位置から b まで下がって r で終わるものという表現に変換する
        let (b, r) = s_i.iter().fold((0, 0), |(b, r), &c| match c {
            '(' => (b, r + 1),
            ')' => (std::cmp::min(b, r - 1), r - 1),
            _ => unreachable!(),
        });
        // 左半分に配置するものと右半分に配置するものに分ける
        // 右半分の配置は左右を反転させたものとして解釈する
        if r > 0 {
            p_l.push((b, r));
        } else {
            p_r.push((b - r, -r))
        }
        sum += r;
    }
    let ans = if sum == 0 && f(&mut p_l) && f(&mut p_r) {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


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

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

    if(S.size() <= K){
        cout << S << endl;
        return 0;
    }else{
        for(int i=0;i<K;i++){
            cout << S.at(i);
        }
    }
    cout << "..." << endl;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;


int main() {
    cin>>N>>M;
    mat dp(N + 1, vec(N * 3 + 1, 0));
    dp[N][N * 3] = 1;
    ll ans = 0;
    Rrep(i, N + 1){
        Rrep(j, N * 3 + 1){
            if(i == 0){
                (ans += dp[i][j])%=M;
            }else{
                if(j >= 1) (dp[min(i, (j - 1) / 2)][j - 1] += dp[i][j])%=M;
                if(j >= 2) (dp[i - 1][j - 2] += (dp[i][j] * (j - 1))%M)%=M;
                if(j >= 3){
                    (dp[min(i - 1, (j - 3) / 2)][j - 3] += (dp[i][j] * ((j - 1) * (j - 2) % M)%M))%=M;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 94208
<?php

list($n, $m) = explode(' ', trim(fgets(STDIN)));
$a_list = explode(' ', trim(fgets(STDIN)));

$border = array_sum($a_list) / (4 * $m);
$select = array_filter($a_list, function ($value, $key) use ($border) {
    return $value >= $border;
}, ARRAY_FILTER_USE_BOTH);

echo count($select) >= $m ? 'Yes' : 'No';


Measured memory_bytes: 4856
#include <iostream>

using namespace std;
int main(){
	long long a,b,k;
	cin >> a >> b >> k;
	if(k<a){
		cout << a - k << " " << b << endl;
		return 0;
	}
	k -= a;
	a = 0;
	if(k<b){
		cout << a << " " << b - k << endl;
		return 0;
	}else{
		cout << 0 << " " << 0 << endl;
	}
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void MAIN() {
  int n; cin >> n;
  vector<ii> a(n);
  for (auto &i : a) {
    int x, l;
    cin >> x >> l;
    i.sc = x - l;
    i.fi = x + l;
  }
  sort(all(a));
  // left = sc | right = fi
  int ans = 0, d = -2e9;
  for (auto &i : a) {
    if (i.sc >= d) {
      d = i.fi;
      ans++;
    }
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 4780
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

constexpr int INF{1001001001};
constexpr lint LINF{1001001001001001001ll};
constexpr int MOD{(int)1e9 + 7};
constexpr double EPS{1e-9};
const double PI{acos(-1)};
constexpr int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)(v.size() - 1) ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  int N = in();
  vi a(N);
  rep(i, N) cin >> a[i];
  bool f[100001] = {};
  
  rep(i, 1, N + 1) {
    if (a[i - 1] == i) f[i - 1] = true;
  }
  int res = count(all(f), true);

  rep(i, N) {
    if (f[i] && f[i + 1]) {
      f[i] = f[i + 1] = false;
      res--;
    }
  }
  print(res);

}


Measured memory_bytes: 768
a, b, c, x, y = map(int, input().split())
INF = 10 ** 9
cost = INF
if x < y:
    x, y = y, x
    a, b = b, a
for i in range(x + 1):
    cost = min(cost, 2 * c * i + a * max(x - i, 0) + b * max(y - i, 0))

print(cost)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

// const int kMaxN;

int A, B, C, K;
int ans = 0;

signed main() {
  cin >> A >> B >> C >> K;

  if (K%2 == 0) {
    ans = A-B;
  } else {
    ans = B-A;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 512;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

int c[MAX], s[MAX], f[MAX];

void solve(void){
    int N;
    cin >> N;
    rep(N-1, i) scanf("%d %d %d\n", &c[i], &s[i], &f[i]);
    rep(N-1, i) {
        int t = 0;
        Rep(i, N-2, j) {
            if (t <= s[j]) t = s[j];
            else t = s[j] + ((t-s[j]-1)/f[j]+1)*f[j];
            t += c[j];
        }
        cout << t << endl;
    }
    cout << 0 << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define show(x) cerr << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define pi  pair    <int,int>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define OO  (ll)1e18
#define EPS 1e-9
using namespace std;
using namespace __gnu_pbds;
void ONLINE__JUDGE();

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
pii swapii( pii pr ){ return { pr.S , pr.F }; }
ll binEXP( ll x , ll pw , ll MOD = LLONG_MAX );
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 1e4 + 7;

string s; ll d , dp[MAX][102][2];
ll go ( ll i , ll rem = 0 , ll gr = 0 ){

    if ( i < 0 ){
        return mod(rem , d) == 0 && gr == 0;
    }

    ll& ret = dp[i][rem][gr];
    if ( ~ret ) return ret;

    ll ans = 0;
    for ( int digit = 0; digit < 10; ++digit ){
        if ( digit <  s[i] - '0' ){
            ans += go( i-1 , (rem+digit)%d , 0  );
        }
        if ( digit == s[i] - '0' ){
            ans += go( i-1 , (rem+digit)%d , gr );
        }
        if ( digit > s[i] - '0' ){
            ans += go( i-1 , (rem+digit)%d , 1  );
        }
        ans %= MOD;
    }
    return ret = (ans%MOD);
}

int main()
{
    FASTIO //ONLINE__JUDGE();

    cin >> s >> d; mem( dp , -1 );
    ll ret = go( s.L-1 ) - 1;
    cout << mod( ret , MOD );
    return 0;
}

void ONLINE__JUDGE()
{
    #ifndef ONLINE_JUDGE
    freopen( "inp.c"         , "r" , stdin  );
    //freopen( "OutPut.txt"   , "w" , stdout );
    #endif // ONLINE_JUDGE
}

ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }


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

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int x, y, a, b, c;
void solve() {
    cin >> x >> y >> a >> b >> c;
    vector<pair<ll, int>> v;
    rep(i, a) {
        ll p;
        cin >> p;
        v.emplace_back(p, 0);
    }
    rep(i, b) {
        ll p;
        cin >> p;
        v.emplace_back(p, 1);
    }
    rep(i, c) {
        ll p;
        cin >> p;
        v.emplace_back(p, 2);
    }

    all(sort, v, greater<>());
    ll ans = 0;
    int p = 0, q = 0, r = 0;
    for (auto& val : v) {
        if (val.second == 0) {
            if (p < x - max(0, (q + r) - y)) {
                ans += val.first;
                ++p;
            }
        }
        if (val.second == 1) {
            if (q < y - max(0, (p + r) - x)) {
                ans += val.first;
                ++q;
            }
        }
        if (val.second == 2) {
            if (p + q + r < x + y) {
                ans += val.first;
                ++r;
            }
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 10604
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int a,b,c;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = a * b;
        if(c % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
const ll MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main() {
    int n;
    cin >> n;
    vi a(n + 1);
    repp(i, n)cin >> a[i];
    vb ans(n + 1, false);
    for (int i = n; i >= 1;i--) {
        int k = n / i;
        int sum = 0;
        while (k > 1) {
            if (ans[i * k]) sum++;
            k--;
        }
        if (sum % 2 != a[i]) ans[i] = true;
    }
    int count = 0;
    repp(i, n) {
        if (ans[i])count++;
    }
    cout << count << endl;
    repp(i, n) {
        if (ans[i])cout << i << " ";
    }
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main(void) {
    
    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    vpii w(n);
    rep(i,n)w[i]=mp(v[i],i+1);
    Sort(w);
    rep(i,n){
        if(i==0)cout<<w[i].second;
        else cout<<' '<<w[i].second;
    }
    cout<<endl;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d);
}

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

int n;
int node[MAX_H + 1];

int main(void){
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> node[i];
  for(int i = 1; i <= n; i++){
    cout << "node " << i << ": ";
    cout << "key = " << node[i] << ", ";
    if(i/2 != 0) cout << "parent key = " << node[i/2] << ", ";
    if(i*2 <= n) cout << "left key = " << node[i*2] << ", ";
    if(i*2 + 1 <= n) cout << "right key = " << node[i*2+1] << ", ";
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
long long int gcm(long long int a,long long int b)
{
	if(b == 0)
	{
		return a;
	}
	return gcm(b,a%b);
}
int main(){
	int t;
	long long int a, b, c, d, a1, c1, d1, e;
	cin >> t;
	for(int i = 0;i < t;i++){
		cin >> a >> b >> c >> d;
		if(a < b){
			cout << "No" << endl;
		}else if(b > d){
			cout << "No" << endl;
		}else if(b <= c){
			cout << "Yes" << endl;
		}else{
			a1 = a % b;
			c1 = c % b;
			d1 = d % b;
			e = gcm(b, d1);
			if(d1 == 0){
				if(a1 > c1){
					cout << "No" << endl;
				}else{
					cout << "Yes" << endl;
				}
			}else if(((((b - a1) - 1) / e) * e + a1) > c){
				cout << "No" << endl;
			}else{
				cout << "Yes" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

string S;
set<string> st;
vector<string> list;
int K;

int main() {
    cin >> S >> K;
    int n = S.size();
    
    for (int i = 1; i <= K; i++) {
        for (int j = 0; j < n; j++) {
            st.insert(S.substr(j,i));
        }
    }
    
    auto it = st.begin();
    while(it != st.end()) {
        list.push_back(*it);
        it++;
    }
    sort(list.begin(), list.end());
    cout << list[K-1] << endl;

    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <chrono>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

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

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

    sort(a, a + 3);

    int cnt = 0;
    while (!(a[0] == a[1] && a[2] == a[1] && a[0] == a[2])) {
        if (a[2] > a[1]) a[0]++, a[1]++;
        else if(a[2] == a[1]) a[0] += 2;
        sort(a, a + 3);
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,A,B;
    cin>>N>>A>>B;
    int X[N];
    rep(i,N){
        cin>>X[i];
    }
    int ans=0;
    rep(i,N-1){
        int t=(X[i+1]-X[i])*A;
        if(t>B) ans+=B;
        else ans+=t;
    }
    cout << ans << endl;



}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int,n,l);
  vector<string> vs(n);
  for (auto &e:vs) cin>>e;

  sort(all(vs));

  for (auto e:vs) cout << e;
  puts("");

  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        x: usize, y: usize
    };

    let min = x * 2;
    let max = x * 4;
    if y > max {
        println!("No");
        return;
    }
    let a = max - y;
    let res = if y >= min && y <= max && a % 2 == 0 && a / 2 <= x {
        "Yes"
    } else {
        "No"
    };
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int mn = 2000000;
    int ans = 0;
    rep(i, N) {
        if(A[i] <= mn) {
            ++ans;
            mn = A[i];
        }
    }
    cout << ans << '\n';
    return 0;
}


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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String op = sc.next();
		int b = sc.nextInt();
		if(op.equals("+")) {
			System.out.println(a+b);
		}else {
			System.out.println(a-b);
		}
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int AA=0;
  int BB=0;
  string S;
  cin>>S;
  vector<char>A(S.size());
  for(int X=0;X<S.size();X++){
    if(X%2==0){
      A.at(X)='1';
    }
    else{
      A.at(X)='0';
    }
  }
  for(int X=0;X<S.size();X++){
    if(S.at(X)==A.at(X)){
      AA++;
    }
    else{
      BB++;
    }
  }
  if(AA>=BB){
    cout<<BB<<endl;
  }
  else{
    cout<<AA<<endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string n;
    cin >> n;
    int a, b, c, d;
    a = n[0] - '0';
    b = n[1] - '0';
    c = n[2] - '0';
    d = n[3] - '0';
    bool found = false;
    int res;
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            for (int k = 0; k < 2; k++)
            {
                res = a;
                if (i)
                    res += b;
                else
                    res -= b;
                if (j)
                    res += c;
                else
                    res -= c;
                if (k)
                    res += d;
                else
                    res -= d;
                if (res == 7)
                {
                    cout << a << (i ? '+' : '-') << b << (j ? '+' : '-') << c << (k ? '+' : '-') << d << "=7" << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	if (a + b != 0) {
		cout << (n / (a + b))*a + min(a, n % (a + b)) << endl;
	}
	else {
		cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N=int(input())
S=[0]*4
for i in range(N):
    tmp=input()
    if tmp=="AC":
        S[0]+=1
    elif tmp=="WA":
        S[1]+=1
    elif tmp=="TLE":
        S[2]+=1
    else:
        S[3]+=1

print("AC","x",S[0])
print("WA","x",S[1])
print("TLE","x",S[2])
print("RE","x",S[3])



Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define MP make_pair
#define pb push_back
const int INF = 1e9;
const int MOD = INF+7;
using i64 = long long;
using P = pair<i64,i64>;



int main(){
    i64 N,M;
    cin >> N >> M;
    vector<P> drink(N);

    rep(i,N) cin >> drink[i].first >> drink[i].second;

    sort(all(drink));

    i64 ans = 0;
    i64 cnt = 0;

    int i=0;
    while(cnt < M){
        if(cnt + drink[i].second <= M){
            ans += drink[i].first * drink[i].second;
            cnt += drink[i].second;
            //cout << ans << endl;
        }
        else {
            ans += drink[i].first * (M-cnt);
            cnt = M;
        }
        i++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    string S;

    cin >> S;

    int len = (int)S.length();
    bool flag = true;
    bool flag_s = true;


    for(int i=0;i<len;i++){
        if(S[i] == S[len-i-1]){
        }
        else{
            flag = false;
            break;
        }
    }

    for(int i=0;i<len/2;i++){
        if(S[i] == S[len/2-i-1]){
        }
        else{
            flag_s = false;
            break;
        }
    }



    if(flag && flag_s){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

}

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

int n,m,cnt,s[N][N],s1[N][N],s2[N][N];
char a[N][N];
int calc(int s[][N],int x1,int y1,int x2,int y2){
	if (x1>x2 || y1>y2) return 0;
	return s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1];
}
int main(){
	scanf("%d%d%d",&m,&n,&cnt);
	int i,j;
	for (i=1; i<=m; i++) scanf("%s",a[i]+1);
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++){
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(a[i][j]=='1');
			s1[i][j]=s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1]+(a[i][j]=='1' && j<n && a[i][j+1]=='1');
			s2[i][j]=s2[i-1][j]+s2[i][j-1]-s2[i-1][j-1]+(a[i][j]=='1' && i<m && a[i+1][j]=='1');
		}
	while (cnt--){
		int x1,x2,y1,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		printf("%d\n",calc(s,x1,y1,x2,y2)-calc(s1,x1,y1,x2,y2-1)-calc(s2,x1,y1,x2-1,y2));
	}
	return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int V = 200000;
struct UF {
	int id[V];
	vector<int> vec[V];
	void init() {
		inc(i, V) { id[i] = i; vec[i].PB(i); }
	}
	void unite(int x, int y) {
		if(id[x] == id[y]) { return; }
		if(size(x) < size(y)) { swap(x, y); }
		
		int iy = id[y];
		inc(i, vec[iy].size()) {
			id[ vec[iy][i] ] = id[x];
			vec[ id[x] ].PB(vec[iy][i]);
		}
		vec[iy].clear();
	}
	int find(int x) {
		return id[x];
	}
	int size(int x) {
		return vec[ id[x] ].size();
	}
};

int n, k, l;
UF K, L;
map<pair<int, int>, int> mp;

int main() {
	cin >> n >> k >> l;
	
	K.init();
	L.init();
	
	inc(i, k) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		K.unite(p, q);
	}
	inc(i, l) {
		int r, s;
		cin >> r >> s;
		r--; s--;
		L.unite(r, s);
	}
	inc(i, n) {
		mp[ MP(K.find(i), L.find(i)) ]++;
	}
	
	inc(i, n) {
		cout << (i == 0 ? "" : " ") << mp[ MP(K.find(i), L.find(i)) ];
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 35712
/*
Author : N_o_o_B
Created : April 22 2020 15:26:13 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n;
    cin >> n;
    vi a(n);
    fori(i,n){
        cin >> a[i];
    }
    ll best = INF;
    rep(i,1,100){
        ll sum = 0;
        for(ll x:a){
            sum += (i-x)*(i-x);
        }
        best = min(best,sum);
    }
    cout << best << endl;



    time_taken();
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int s[5];
int len;
char st[100005];
bool check(int x,int y)
{
	int g[5];
	g[1]=s[1];g[2]=s[2];g[3]=s[3];
    if (g[x]<=0||g[y]<=0) return 0;
    g[x]--,g[y]--;
    for (int i=2;i<len;i++)
    {
    	int z=6-x-y;
    	if (g[z]<=0) return 0;
    	g[z]--;
		x=y; y=z; 
	}
	return 1;
}
int main()
{
	scanf("%s",st);
	len=strlen(st);
	for (int i=0;i<len;i++) s[st[i]-96]++;
	if (len<2||check(1,2)||check(1,3)||check(2,3)||check(2,1)||check(3,1)||check(3,2)) printf("YES"); 
	else printf("NO");
	return 0;
}



Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h:u32,
        n:u32,
        v:[u32; n],
    }
    let mut sum = 0;
    for i in v.iter() {
        sum += *i;
    }
    if sum >= h {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String z = sc.next();
        if(z.startsWith(s) && z.length() - 1 == s.length())
        {
        System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

int main(){
	int N,K,C; string S;
	cin>>N>>K>>C>>S;

	vector<int> L,R;
	int c;

	c = 0;
	rep(i, N){
		if(c-- > 0) continue;
		c = 0;
		if(S[i] == 'o'){ L.push_back(i); c = C; }
	}

	c = 0;
	for(int i=N-1; i>=0; --i){
		if(c-- > 0) continue;
		c = 0;
		if(S[i] == 'o'){ R.push_back(i); c = C; }
	}

	reverse(R.begin(), R.end());

	if(L.size() > K) return 0; // 働ける日に余裕があると、その日に必ず働く必要がない

	// L の一番右の日からみて、
	// 同日かさらに後日に、R の一番右の日がある
	// 常に間隔は C 日以上開いている
	// これらから、L,R のサイズは。かならず同じになる！
	rep(i, L.size()) if(L[i] == R[i]) cout<<L[i]+1<<endl;
}

Measured memory_bytes: 3448
#include <iostream>
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
using namespace std;


int main(void){
  int a,b,c,k;
  int ans;
  
  cin >> a >> b >> c >> k;
  ans = 0;
  if (k>0){
    ans += MIN(a,k);
    k -= MIN(a,k);
  }
  if (k>0){
    k -= MIN(b,k);
  }
  if (k>0){
    ans -= MIN(c,k);
    k -= MIN(c,k);
  }
  cout << ans << endl;
  return 0;
}
    

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int N;
  cin >> N;
  vector<int> a(N);

  int a_max = -10000000;
  int a_min = 10000000;
  int a_max_i, a_min_i;
  REP(i,N){
    int a;
    cin >> a;
    if(a > a_max){
      a_max = a;
      a_max_i = i;
    }
    if(a < a_min){
      a_min = a;
      a_min_i = i;
    }
  }
  if(abs(a_max) >= abs(a_min)){
    cout << 2*N-2 << endl;
    REP(i,N){
      if(i == a_max_i)continue;
      cout << a_max_i+1 << " " << i+1 << endl;
    }
    REP(i,N-1){
      cout << i+1 << " " << i+2 << endl;
    }

  }else{
    cout << 2*N-2 << endl;
    REP(i,N){
      if(i == a_min_i)continue;
      cout << a_min_i+1 << " " << i+1 << endl;
    }
    REP(i,N-1){
      cout << N-i << " " << N-i-1 << endl;
    }

  }



}



Measured memory_bytes: 256