akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int M = in.nextInt();
		int T = in.nextInt();
		int P = in.nextInt();
		int r = in.nextInt();
		if (M + T + P + r == 0) return false;

		int[][] a = new int[T][3];
		for (int i=0; i<T; i++) {
			a[i][0] = i+1;
		}

		int[][] wrong = new int[T][P];

		for (int i=0; i<r; i++) {
			int m = in.nextInt();
			int t = in.nextInt() - 1;
			int p = in.nextInt() - 1;
			int j = in.nextInt();
			if (j == 0) {
				a[t][1]++;
				a[t][2] += m + 20*wrong[t][p];
			} else {
				wrong[t][p]++;
			}
		}

		Arrays.sort(a, new Comparator<int[]>(){
			public int compare(int[] a, int[] b) {
				if (a[1] != b[1]) return b[1] - a[1];
				if (a[2] != b[2]) return a[2] - b[2];
				return b[0] - a[0];
			}
		});

		boolean f = true;
		ArrayList<Integer> ans = new ArrayList<>();
		for (int i=0; i<T; ) {
			ans.add(a[i][0]);
			i++;
			while (i < T && a[i][1] == a[i-1][1] && a[i][2] == a[i-1][2]) {
				ans.add(a[i][0]);
				i++;
			}
			if (!f) {
				out.print(",");
			} else {
				f = false;
			}
			for (int j=0; j<ans.size(); j++) {
				if (j != 0) out.print("=");
				out.print(ans.get(j));
			}
			ans.clear();
		}
		out.println();

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 68600
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
    
    int n, k;
    while(cin >> n >> k, n||k){
        bool a[100001];
        int dp[2][100001] = {0};
        
        memset(a, false, sizeof(a));
        for(int i = 0; i < k; i++){
            int num; cin >> num;
            a[num] = true;
        }
        
        for(int i = 1; i <= n; i++){
            if(a[i]){
                dp[0][i] = dp[0][i - 1] + 1;
                dp[1][i] = dp[1][i - 1] + 1;
            } else {
                dp[1][i] = dp[0][i - 1] + 1;
            }
        }
        cout << *max_element(dp[a[0]] + 1, dp[a[0]] + n + 1) << endl;
    }
}

Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n,k;
    int r,s,p;
    string t;

    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    vector<int> hand;

    int ans = 0;

    rep(i,n){

        if(i < k){
            if(t[i] == 'r'){
                hand.pback(2);
                ans += p;
            }else if(t[i] == 's'){
                hand.pback(0);
                ans += r;
            }else{
                hand.pback(1);
                ans += s;
            }
        }else{
            if(t[i] == 'r'){
                if(hand[i - k] != 2){
                    hand.pback(2);
                    ans += p;
                }else{
                    hand.pback(3);
                }
            }else if(t[i] == 's'){
                if(hand[i - k] != 0){
                    hand.pback(0);
                    ans += r;
                }else{
                    hand.pback(3);
                }
            }else{
                if(hand[i - k] != 1){
                    hand.pback(1);
                    ans += s;
                }else{
                    hand.pback(3);
                }
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#include <functional>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert
{
    template <typename T> _cert& operator << (T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
		cerr << (*i) << " ";
    }
    cerr << "\n";
}

int n;
ll l, t;
ll x[120000];
ll w[120000];
vector<ll> vv;

int main() {
    scanf("%d%lld%lld", &n, &l, &t);
    l *= 2;
    t *= 2;
    for (int i = 0; i < n; ++i)
        scanf("%lld%lld", x + i, w + i), x[i] *= 2;
    ll c = 0;
    for (int i = 1; i < n; ++i) {
        if (w[i] == w[0])
            continue;
        if (w[0] == 1) {
            ll k = (x[i] - x[0]) / 2;
            if (k <= t)
                c += 1 + 2 * (t - k) / l;
        }
        else {
            ll k = (x[0] + l - x[i]) / 2;
            if (k < t)
                c += 1 + (2 * (t - k) - 1) / l;
        }
    }
    c %= n;
    if (w[0] == 2)
        c = (n - c) % n;
    for (int i = 0; i < n; ++i) {
        if (w[i] == 1) {
            ll xx = x[i] + t;
            xx %= l;
            vv.push_back(xx);
        }
        else {
            ll xx = x[i] - t;
            xx %= l;
            if (xx < 0)
                xx += l;
            vv.push_back(xx);
        }
    }
    ll xx = vv[0];
    sort(vv.begin(), vv.end());
    int p = upper_bound(vv.begin(), vv.end(), xx) - vv.begin() - 1;
    p -= c;
    if (p < 0)
        p += n;
    for (int i = 0; i < n; ++i) {
        cout << vv[p] / 2 << "\n";
        ++p;
        if (p == n)
            p = 0;
    }
	return 0;
}




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

using namespace std;

int n, m, k;

void solve()
{
  cin >> n >> m >> k;
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= m; j++) {
      if(i * m + j * n - i * j * 2 == k) {
        cout << "Yes\n";
        return;
      }
    }
  }
  cout << "No\n";
}

int main()
{
  solve();
}

Measured memory_bytes: 256
//arc060_c.cpp
//Sat Jun 23 13:19:44 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

int n,a,X;
int x[50];
ll dptable[51][51][2501];

int main(){
	cin >> n >> a;
	X = a;
	for (int i=0;i<n;i++){
		cin >> x[i+1];
		X = max(X,x[i+1]);
	}

	for (int j=0;j<=n;j++){
		for (int k=0;k<=n;k++){
			for (int s=0;s<=n*X;s++){
				if (j==0 && k==0 && s==0){
					dptable[j][k][s] = 1;
				}else if (j>=1 && s<x[j]){
					dptable[j][k][s] = dptable[j-1][k][s];
				}else if (j>=1 && k>=1 && s>=x[j]){
					dptable[j][k][s] = dptable[j-1][k][s] + dptable[j-1][k-1][s-x[j]];
				}else {
					dptable[j][k][s] = 0;
				}
			}
		}
	}

	ll ans = 0;

	for (int k=1;k<=n;k++){
		ans += dptable[n][k][k*a];
	}

	cout << ans << endl;
}

Measured memory_bytes: 51072
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	char C, ans;
	cin >> C;
	if (C == 'A') ans = 'T';
	else if (C == 'T') ans = 'A';
	else if (C == 'C') ans = 'G';
	else ans = 'C';
	
	cout << ans << endl;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

constexpr ll INF = 1e15;

vector<pair<int,int>> e[200000];
ll cost[200000];
bool used[200000];
int R;
ll minr, minc;

bool dfs(int v, ll c) {
    if (v < R) minr = min(minr,c);
    else minc = min(minc,c);
    used[v] = true;
    cost[v] = c;
    bool ret = true;
    for (auto p: e[v]) {
        if (!used[p.first])
            ret &= dfs(p.first,p.second - c);
        else if (cost[p.first] != p.second - c)
            ret = false;
    }
    ret &= minr + minc >= 0;
    return ret;
}

int main() {
    int i, C, N;
    scanf("%d%d%d",&R,&C,&N);
    REP (i,N) {
        int r, c, a;
        scanf("%d%d%d",&r,&c,&a);
        r--; c--;
        e[r].emplace_back(c+R,a);
        e[c+R].emplace_back(r,a);
    }
    REP (i,R+C) cost[i] = INF;
    REP (i,R+C) if (!used[i]) {
        minr = minc = INF;
        if (!dfs(i,0)) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 14464
import sys

N = int(input())

xn = []
yn = []
hn = []

for i in range(N):
    xi, yi, hi = map(int, input().split())

    xn.append(xi)
    yn.append(yi)
    hn.append(hi)

for Cx in range(101):
    for Cy in range(101):

        last = None
        flg = True

        for i in range(N):

            if 0 == hn[i]:
                continue

            H = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

            if H < 0:
                continue

            if last:
                if H != last:
                    flg = False
                    break

            last = H

        if not flg:
            continue

        for i in range(N):

            if 0 == hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                if h < H:
                    flg = False
                    break

        if not flg:
            continue

        print(Cx, Cy, H)
        sys.exit()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  
    int n,m;
    cin >> n >> m;
    int a[n];

    int sum =0; 
    int c =0;

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

   for(int i =0;i<n;i++){
         if( 4*m*a[i] >= sum ) c++;
   }
  if( c >= m) cout << "Yes" <<endl;
  else cout << "No"<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b,c,A,B,C;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b&&a<c){
        A = a;
            if(b<c){
                B = b;
                C = c;
            }else{
                B = c;
                C = b;
            } 
    }else if(b<a&&b<c){
        A = b;
            if(a<c){
                B = a;
                C = c;
            }else{
                B = c;
                C = a;
            } 
    }else {
        A = c;
            if(a<b){
                B = a;
                C = b;
            }else{
                B = b;
                C = a;
            } 

    }

    printf("%d %d %d\n",A,B,C);
    return 0;
}

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

#define llint long long int

using namespace std;

int main()
{
    int N, D;

    cin >> N >> D;

    vector<vector<int>> X(N, vector<int>(D));

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < D; j++)
        {
            cin >> X[i][j];
        }
    }
    int count = 0;

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            int dist = 0;

            for (int k = 0; k < D; k++)
            {
                dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            for (int k = 0; k * k <= dist; k++)
            {
                if (k * k == dist)
                {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;
const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    long long ans = 0;
    long long sum = A[N -1];
    for(int i = N - 2; i >= 0; --i) {
        ans += A[i] * (sum % MOD) % MOD;
        ans %= MOD;
        sum += A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4772
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

map<ll, ll> mp;

int main(void){
	int n,i;
	ll m,a,t,ans=0ll;
	vector<ll> v;
	cin >> n >> m;
	v.push_back(0ll);
	for(i=0; i<n; ++i){
		cin >> a;
		v.push_back(a+v[i]);
	}
	for(i=n; i>=0; --i){
		++mp[v[i]%m];
	}
	for(auto itr = mp.begin(); itr != mp.end(); ++itr){
		ans += itr->second*(itr->second-1)/2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4980
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, m = LI()
print(m * (m - 1) // 2 + n * (n - 1) // 2)



Measured memory_bytes: 39664
fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];

    for x in 1..1001 {
        let x: f64 = x as f64;
        let ans1 = (x * 0.08) as u32;
        let ans2 = (x * 0.1) as u32;

        if ans1 == a && ans2 == b {
            println!("{}", x);
            return
        }
    }

    println!("-1");
}

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()
}

Measured memory_bytes: 4352
S = input()
Q = int(input())
count = 0
from collections import deque
q1 = deque()
q2 = deque()
for i in range(Q):
    li = input().split()
    if len(li) == 1:
        count +=1
        q11 = q1
        q22 = q2
        q1 = q22
        q2 = q11
    if len(li) == 3:
        if li[1] == '1':
            if count % 2 == 1:
                q1.append(li[2])
            if count % 2 == 0:
                q1.appendleft(li[2])
        if li[1] == '2':
            if count % 2 == 1:
                q2.appendleft(li[2])
            if count % 2 == 0:
                q2.append(li[2])
s1 = ''.join(list(q1))
s2 = ''.join(list(q2))
if count % 2 == 1:
    K = reversed(list(S))
    S = ''.join(K)
    s1 = ''.join(reversed(list(s1)))
    s2 = ''.join(reversed(list(s2)))
print(s1+S+s2)

Measured memory_bytes: 7348
/**
 *    author:  RM07
 *    created: July 15, 2020 9:47 PM
 *    motto: Knowledge is Power, Strive for Excellence
**/
 #include <bits/stdc++.h>

 using namespace std;
 int main() {
 int A, B; cin >> A >> B;
 int ans = 0;
 int outlet = 1;
 while (outlet < B) {
 --outlet;
 outlet += A;
 ++ans;
 }
 cout << ans << endl;
  }

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9+7;
ll fact[210200];
ll invfact[210200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll powMod(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return powMod(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll dp[1010][1010];

int main(){
    int h, w;
    int grid[1010][1010];
    cin >> h >> w;

    for(int i = 0; i < 1010; i++){
        fill(grid[i], grid[i]+1010, 0);
        fill(dp[i], dp[i]+1010, 0);
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c; cin >> c;
            if(c == '.'){
                grid[i][j] = 1;
            }
            else{
                grid[i][j] = 0;
            }
        }
    }

    dp[0][0] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(grid[i+1][j] == 1){
                dp[i+1][j] = add(dp[i+1][j], dp[i][j]);
            }
            if(grid[i][j+1] == 1){
                dp[i][j+1] = add(dp[i][j+1], dp[i][j]);
            }
        }
    }

//    for(int i = 0; i < h; i++){
//        for(int j = 0; j < w; j++){
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }
    cout << dp[h-1][w-1] << endl;


    return 0;
}


Measured memory_bytes: 12416
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  _, s_s, f_s, s_e, f_e = map(int, input().split())
  n = input().strip()

  s_s = s_s - 1
  s_e = s_e - 1
  f_s = f_s - 1
  f_e = f_e - 1

  if '##' in n[s_s + 1:s_e] or '##' in n[f_s + 1:f_e]:
    print('No')
  elif s_e < f_e:
    print('Yes')
  elif '...' in n[f_s - 1:f_e + 2]:
    print('Yes')
  else:
    print('No')


if __name__ == '__main__':
  main()



Measured memory_bytes: 3572
#include<iostream>
#include<cstdint>
#include<algorithm>

int const MAXN = 400;

uint64_t const INF = (uint64_t)1000000000 * (uint64_t)40000;

int N;
uint64_t a[MAXN];
uint64_t dp[MAXN+1][MAXN+1];

int main() {
  std::cin >> N;
  for(int i = 0; i <N; ++i) std::cin >> a[i];

  for(int i = 0; i+1 <= N; ++i) dp[i][i+1] = 0;
  for(int i = 0; i+2 <= N; ++i) dp[i][i+2] = a[i] + a[i+1];
  for(int i = 3; i<=N; ++i) for(int j = 0; j+i<=N; ++j) {
    int k = j+i; // calc dp[j][k]
    uint64_t ret = INF;
    for(int m = j+1; m < k; ++m) ret = std::min(ret, dp[j][m]+dp[m][k]);
    for(int m = j; m < k; ++m) ret += a[m];
    dp[j][k] = ret;
  }

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


Measured memory_bytes: 1536
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
queue<int> Q[301];
int main() {
  ios::sync_with_stdio(false);
  int N, M, A;
  cin >> N >> M;
  for (int i=0; i<N; i++) {
    for (int j=0; j<M; j++) {
      cin >> A;
      Q[i].push(A);
    }
  }
  int ret = 400;
  set<int> removed;
  for (int i=0; i<M; i++) {
    map<int, int> m;
    for (int j=0; j<N; j++) {
      int k = Q[j].front();
      while(removed.find(k) != removed.end()) {
        Q[j].pop();
        k = Q[j].front();
      }
      m[k]++;
    }
    int d = 0;
    int idx = 0;
    for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
      if (d < it->second) {
        d = it->second;
        idx = it->first;
      }
    }
    //cout << idx << ' ' << d << endl;
    ret = min(ret, d);
    removed.insert(idx);
  }
  cout << ret << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a;
  cin >> n;
  int m = 0;
  for(int i = 0; i < n; i++){
    int b = 0;
    cin >> a;
    if(a % 2 != 0){
      m = 0;
      break;
    }
    while(a % 2 == 0){
      a /= 2;
      b++;
    }
    if(m == 0 || m > b){
    	m = b;
    }
  }
  cout << m;
}

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


int main() {
  int a, b;
  cin >> a >> b;
  int ans = a - 2*b;
  if(ans < 0) ans = 0;
  cout << ans << endl;

  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int numOfZero = 0, numOfOne = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == '0'){
            numOfZero++;
        }else{
            numOfOne++;
        }
    }
    cout << 2 * min(numOfZero, numOfOne) << endl;
    return 0;
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    int g = 0;
    for (int _ = 0; _ < n; _++) {
        int x; cin >> x;
        g = __gcd(g, x);
    }
    cout << g;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int mp[111111];
vector<vector<int>> v(111111);

int main(){
	
	int n,q;cin >> n;
	REP(i,n){
		int a,b;cin >> a >> b;
		a--;b--;
		mp[a]++;
		mp[b]++;
		v[a].PB(b);
		v[b].PB(a);
	}
	
	queue<int> que;
	
	REP(i,n)if(mp[i] == 1)que.push(i);
	
	while(!que.empty()){
		int now = que.front();que.pop();
		REP(i,v[now].size()){
			mp[v[now][i]]--;
			if(mp[v[now][i]] == 1)que.push(v[now][i]);
		}
	}
	//SHOW1d(mp,n);
	cin >> q;
	REP(i,q){
		int a,b;cin >> a >> b;
		a--;b--;
		if(mp[a] > 1 && mp[b] > 1){
			cout << 2 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 8960
#include <iostream> 


using namespace std; 
int main(){
	unsigned long long int n,k;
	cin>>n>>k;
	
	unsigned long long temp  = n%k;
	unsigned long long tempo = ( temp > k ? temp-k : k-temp ) ;
	cout<<min(temp,tempo);
		
	
	
	return 0; 
} 


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

int n,m;
int g[60][60];
int v[60];

void dfs(int z)
{
    v[z] = 1;
    for(int i = 0; i < n; i++){
        if(g[z][i] == 1 && v[i] == 0) dfs(i);
    }
}

int main()
{
    cin >> n >> m;
    vector<int> a(m),b(m);
    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = 1;
    }

    int ans = 0;
    for(int i = 0; i < m; i++){
        g[a[i]][b[i]] = g[b[i]][a[i]] = 0;
        for(int j = 0; j < n; j++) v[j] = 0;
        dfs(0);
        int jud = 0;
        for(int j = 0; j < n; j++) if(v[j] == 0) jud = 1;
        if(jud) ans++; 
        g[a[i]][b[i]] = g[b[i]][a[i]] = 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import math

n, m = map(int, input().split())
MOD = 10 ** 9 + 7


M = math.factorial(m)
N = math.factorial(n)


if abs(n - m) > 1:
    print(0)

elif n == m:
    print(N * M * 2 % MOD)

elif n != m:
    print(N * M % MOD)


Measured memory_bytes: 5184
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
#define INF ((1LL<<62)-(1LL<<31))  // 浮動小数点型
#define bit(n,m)(((n)>>(m))&1)  // nのmビット目が1
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main() {
    int n; cin >> n;
    ll mae = 0;
    ll sum = 0;
    rep(i, n){
        ll a; cin >> a;
        if(mae > a) {
            sum += mae - a;
            mae = mae;
        }else{
            mae = a;
        }
    }

    cout << sum << endl;    
}

/*
g++ a.cpp
./a.out
*/

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

int seg[10] = {63,6,91,79,102,109,125,39,127,111};

int main() {
	int n, m;
	while (cin >> n, 0 <= n) {
		bitset<7> b(0);
		for (int i=0; i<n; ++i) {
			cin >> m;
			b ^= bitset<7>(seg[m]);
			cout << b << endl;
			b = bitset<7>(seg[m]);
		}
	}
	return 0;
}

Measured memory_bytes: 1200
import java.util.*;
import java.io.*;
import java.math.*;


class Main {
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int k=Integer.parseInt(br.readLine());
        String s=br.readLine();
        
        int l=s.length();
        
        if(l<=k)
        {
        	System.out.println(s);
        }
        else
        {
        	String s1=s.substring(0,k)+"...";
        	System.out.println(s1);
        }

    }
}

Measured memory_bytes: 36436
N,M=map(int, input().split())
K=[0]*(N+1)
for i in range(M):
  L,R=map(int, input().split())
  K[L-1]+=1
  K[R]-=1
#print(K)
R=[0]*N
R[0]=K[0]
for i in range(1,N):
  R[i]=R[i-1]+K[i]
import numpy as np
R=np.array(R)
if R.max()==M:
  print((R==M).sum())
else:
  print(0)

Measured memory_bytes: 18076
#include <bits/stdc++.h>
using namespace std;
#define long int64_t
int main()
{
   string s;
   cin >> s;
   sort(s.begin(), s.end());
   if( (s[0] == s[1]) && (s[2] == s[3]) && (s[0] != s[3]))
      cout << "Yes";
   else 
      cout << "No";
   return 0;
}
 

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

struct unionfind
{
    int n; 
    vector<int> par, rank;
    unionfind(int sz) : n(sz), par(sz), rank(sz)
    {
        for(int i=0; i<sz; i++)
        {
            par[i]=i;
            rank[i]=0;
        }
    }
    int find(int x)
    {
        if(par[x]==x) return x;
        else return par[x]=find(par[x]);
    }
    void unite(int x, int y)
    {
        x=find(x), y=find(y);
        if(x==y) return;
        if(rank[x]>rank[y]) par[y]=x;
        else{
            par[x]=y;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }
    bool same(int x, int y)
    {
        return find(x)==find(y);
    }
};

int main()
{
    int N, K, L;
    cin >> N >> K >> L;
    unionfind road(N), rail(N);
    for(int i=0; i<K; i++)
    {
        int p, q;
        cin >> p >> q;
        p--, q--;
        road.unite(p, q);
    }
    for(int i=0; i<L; i++)
    {
        int r, s;
        cin >> r >> s;
        r--, s--;
        rail.unite(r, s);
    }
    map<pair<int, int>, int>  ans;
    for(int i=0; i<N; i++) 
        ans[make_pair(road.find(i), rail.find(i))]++;
    for(int i=0; i<N; i++) 
        cout << ans[make_pair(road.find(i), rail.find(i))] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 17580
#include <iostream>
#include <vector>

int N, M, X;
std::vector<int> cost;
std::vector<std::vector<int>> vals;
static constexpr int MAX = 10000000;

int all_search(int idx, int sum, std::vector<int> idx_list) {
    if (idx == N) {
        for (int j = 0; j < M; j++) {
            int is_avail = 0;
            for (auto i : idx_list) {
                is_avail += vals[i][j];
            }
            if (is_avail < X) {
                return MAX;
            }
        }
        return sum;
    }

    int val1 = all_search(idx + 1, sum, idx_list);
    idx_list.push_back(idx);
    int val0 = all_search(idx + 1, sum + cost[idx], idx_list);
    return std::min(val0, val1);
}


int main() {
    std::cin >> N >> M >> X;

    cost = std::vector<int>(N);
    vals = std::vector<std::vector<int>>(N, std::vector<int>(M));

    for (int i = 0; i < N; i++) {
        std::cin >> cost[i];
        for (int j = 0; j < M; j++) {
            std::cin >> vals[i][j];
        }
    }

    std::vector<int> idx_list;
    int min_cost = all_search(0, 0, idx_list);
    if (min_cost == MAX) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << min_cost << std::endl;
    }
}


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

using ll = long long;

int main() {
   int N;
   cin >> N;
   map<ll, ll> mp;
   while (N--) {
      ll a;
      cin >> a;
      mp[a]++;
   }

   ll ans = 0;
   for (auto x : mp) {
      if (x.first <= x.second) {
         ans += x.second - x.first;
      } else {
         ans += x.second;
      }
   }
   cout << ans << endl;

   return 0;
}


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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[1001];
void factorial(int n){
    fact[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD;
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return -1;
    else{
        ll x=fact[r]*fact[n-r]%MOD;
        return fact[n]*fermat_inv(x)%MOD;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t=1;
    //cin>>t;
    //SieveOfEratosthenes(1000000);
    //factorial(1000);
    while(t--){
        string s;
        cin>>s;
        int n=s.size();
        int cnt=0,ans=0;
        for(int i=0;i<n;i++){
            if(s[i]=='R')
                cnt++,ans=max(ans,cnt);
            else cnt=0;
        }
        cout<<ans<<'\n';
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
 int a,b,c;
 cin>>c>>a>>b;
 if(b-a>=c){
     cout<<"OK";
 }
 else if(a%c-b%c>0){
     cout<<"OK";
 }
 else if(a%c==0 or b%c==0){
     cout<<"OK";
 }
 else{
     cout<<"NG";
 }
}

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

int n, m, x;
int min_sum_c = -1;
vector<int> c;
vector<vector<int>> a;

void skill_count(int book_index, bool b_buy, int sum, vector<int> skills)
{
    int add_sum = sum;
    vector<int> add_skills;
    add_skills = skills;
    if(b_buy)
    {
        add_sum += c[book_index];
        for(int i=0; i<m; i++)
        {
            add_skills[i] += a[book_index][i];
        }
    }
    if((book_index + 1) == n)
    {
        int i;
        for(i=0; i<m; i++)
        {
            if(add_skills[i] < x) break;
        }
        if(i == m)
        {
            if(min_sum_c < 0 || add_sum < min_sum_c) min_sum_c = add_sum;
        }
    }
    else
    {
        skill_count(book_index+1, true, add_sum, add_skills);
        skill_count(book_index+1, false, add_sum, add_skills);
    }
}

int main() {
    vector<int> skills;
    cin >> n >> m >> x;
    for(int i=0; i<n; i++)
    {
        int c_in;
        vector<int> aa;
        cin >> c_in;
        c.push_back(c_in);
        a.push_back(aa);
        for(int j=0; j<m; j++)
        {
            int a_in;
            cin >> a_in;
            a[i].push_back(a_in);
        }
    }
    for(int i=0; i<m; i++) skills.push_back(0);
    skill_count(0, true, 0, skills);
    skill_count(0, false, 0, skills);

    cout << min_sum_c << endl;

    return 0;
}



Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 n;
    cin >> n;
    vector<i64> a(n,0), a_sum(n,0);

    for (int i=0; i<n; ++i) {
        cin >> a[i];
    }
    a_sum[n-1] = a[n-1];
    for (i64 i = n-2; 0 <= i; --i) {
        a_sum[i] = a_sum[i+1] + a[i];
        a_sum[i] %= mod;
    }
    i64 ans{0};
    for (i64 i=0; i<n-1; ++i) {
        ans += (a[i] * a_sum[i+1] % mod);
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6420
N,K=map(int,input().split())
A=[list(map(int, input().split())) for i in range(N)]
B,C=zip(*A)
S=10**36
for left in B:
  for right in B:
    for up in C:
      for down in C:
        if left<right and down<up:
          cnt=0
          for x,y in A:
            if left<=x<=right and down<=y<=up:
              cnt+=1
          if cnt>=K:
            S=min(S,(right-left)*(up-down))
print(S)            

Measured memory_bytes: 49008
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main(void)
{
	char ch;
	int cnt[26] = {0};

	while(cin >> ch) {
		if(ch >= 'a' && ch <= 'z')			cnt[ch - 'a']++;
		else if(ch >= 'A' && ch <= 'Z')		cnt[ch - 'A']++;
	}

	for(char i = 'a'; i <= 'z'; i++)
		cout << i << " : " << cnt[i - 'a'] << endl;

	return 0;
}

Measured memory_bytes: 1140
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cfloat>

#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <list>

#include <iostream>
#include <sstream>
#include <fstream>

#include <algorithm>
using namespace std;
#ifdef ONLINE_JUDGE
    #define debug
    #define log(message)
#else
    #define debug printf("passing [%s] in line %d\n", __FUNCTION__, __LINE__)
    #define log(message) puts(message)
#endif
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
void closeSync() {ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);}
template<class T> inline void read(T &x) {
    x = 0; int f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') f &= (ch ^ '-'), ch = getchar();
    while('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
    x = f ? x : -x;
}

typedef long long ll;
typedef long double ld;

const int N = 210;

int A[N][N], H, W, c[10][10];

ll ans;

int main() {
	scanf("%d%d", &H, &W);
	for(int i = 0 ; i <= 9 ; ++ i) {
		for(int j = 0 ; j <= 9 ; ++ j) {
			scanf("%d", &c[i][j]);
		}
	}
	for(int k = 0 ; k <= 9 ; ++ k) {
		for(int i = 0 ; i <= 9 ; ++ i) {
			for(int j = 0 ; j <= 9 ; ++ j) {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	for(int i = 1 ; i <= H ; ++ i) {
		for(int j = 1 ; j <= W ; ++ j) {
			scanf("%d", &A[i][j]);
			if(A[i][j] != -1) {
				ans += c[A[i][j]][1];
			}
		}
	}
	printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	int h, w;
	cin>>h>>w;
	string box[h];
	FOR0(i,h) cin>>box[i];
	ll dp[h+1][w+1];
	dp[1][1] = (box[0][0]=='#')?0:1;
	FOR0(i,h+1){
		FOR0(j,w+1){
			if (i==0 || j==0) dp[i][j] = 0;
			else if (i==1 && j!=1){
				dp[i][j] = dp[i][j-1];
				if (box[i-1][j-1]=='#') dp[i][j] = 0;
			}
			else if (i!=1 && j==1){
				dp[i][j] = dp[i-1][j];
				if (box[i-1][j-1]=='#') dp[i][j] = 0;
			}
			else if (i!=1 && j!=1){
				if (box[i-1][j-1]=='#') dp[i][j] = 0;
				else dp[i][j] = (dp[i-1][j] + dp[i][j-1])%1000000007;
			}
		}
	}
	// FOR1(i,h){
	// 	FOR1(j,w) cout << dp[i][j];
	// 	cout << endl;
	// }
	cout << dp[h][w] << endl;
}

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

int main(){
    int a, b;

    cin >> a >> b;
    if (a > b) {
        cout << "a > b" << endl;
    }
    else if (a < b) {
        cout << "a < b" << endl;
    }
    else {
        cout << "a == b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
while allscore = STDIN.gets.split(" ")
  m = allscore[0].to_i
  f = allscore[1].to_i
  r = allscore[2].to_i

  if m == -1 && f == -1 && r == -1
    break
  elsif m == -1 || f == -1
    puts "F"
  elsif m + f >= 80
    puts "A"
  elsif m + f >= 65 && m + f < 80
    puts "B"
  elsif m + f >= 50 && m + f < 65 || m + f >= 30 && m + f < 55 && r >= 50
    puts "C"
  elsif m + f >= 30 && m + f < 55
    puts "D"
  elsif m + f < 30
    puts "F"
  end
end  
    
    


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

ll INF=LLONG_MAX;

int main(){
  int n;
  cin>>n;
  ll d1=INF*-1,d2=INF*-1,d3=INF,d4=INF;
  rep(i,n){
    ll x,y;
    cin>>x>>y;
    d1=max(x-y,d1);
    d2=max(x+y,d2);
    d3=min(x-y,d3);
    d4=min(x+y,d4);
  }
  ll ans=max(d1-d3,d2-d4);
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for(int i=s;i<e;i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(),(a).end()
typedef long long LL;

int main() {
   int n;
   cin>>n;
   vector<int> a(n);
   REP(i,n) cin>>a[i];
   int ans=0;
   REP(i,n){
     ans+=a[i]-1;
     }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <map>
#include <stack>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;
#define reg register int
#define isdigit(x) ('0' <= x&&x <= '9')
template<typename T>
inline T Read(T Type)
{
    T x = 0,f = 1;
    char a = getchar();
    while(!isdigit(a)) {if(a == '-') f = -1;a = getchar();}
    while(isdigit(a)) {x = (x << 1) + (x << 3) + (a ^ '0');a = getchar();}
    return x * f;
}
const int MAXN = 5e5 + 10,MAXM = 6 * MAXN;
int n,cnt,head[MAXN],In[MAXN],sta[MAXN];
struct EDGE
{
	int u,v,nxt;
}edge[MAXM];
inline void addedge(int u,int v)
{
	edge[++cnt].v = v;
	edge[cnt].u = u;
	edge[cnt].nxt = head[u];
	head[u] = cnt;
}
#define add(u,v) (addedge(u,v),addedge(v,u))
stack<int> st;
map<int,int> b[MAXN];
int a[MAXN],tot,ans[MAXN];
inline void Eular(int x)
{
	for(reg& e = head[x];e;e = edge[e].nxt)
	{
		int v = edge[e].v;
		if(!b[x][v])
		{
			b[x][v] = b[v][x] = 1;
			Eular(v);
		}
	}
	a[++tot] = x;
}
int main()
{
	n = Read(1);int all = n << 1 | 1;
	for(reg i = 1;i <= n;i++)
	{
		int v = Read(1);
		if(v == -1)  v = all;
		In[v]++,add(i,v);
	}
	for(reg i = 1;i <= n;i++)
	{
		int v = Read(1);
		if(v == -1) v = all;
		else v = all - v;
		In[v]++,add(all - i,v);
	}
	for(reg i = 1;i <= n << 1;i++) In[i] = !(In[i] & 1);
	In[all] = 0;
	for(reg i = 1;i <= n;i++)
	{
		if(In[i] != In[all - i])
		{
			printf("IMPOSSIBLE");
			exit(0);
		}
		if(In[i]) add(i,all - i);
	}
	Eular(1);
	for(reg i = tot;i >= 1;i--)
		if(a[i] == all - a[i - 1])
		{
			if(a[i] <= n) ans[a[i]] = -1;
			else ans[all - a[i]] = 1;
		}
	printf("POSSIBLE\n");
	for(reg i = 1;i <= n;i++) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 78848
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
    int N , K;
    cin >> N >> K;
    vector<int> p;
    for(int i =0; i < N; i++){
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    sort(p.begin(), p.end());
    int sum =0;
    for(int i =0; i < K; i++){
        sum += p[i];
    }
    cout << sum << endl;

}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void) {
	int ch, sum = 0;
	
	while (1) {
		ch = getchar();
		if ((ch == '0') && (sum == 0)) {
			break;
		}
		if ((ch >= '0') && (ch <= '9')) {
			sum += ch - '0';
		} else if (sum > 0) {
			printf("%d\n", sum);
			sum = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;
int main(){

ll N,Q;
ll sum = 0;

cin >> N;

vector<ll> A(N);
vector<ll> cnt(100001,0);

for(ll i = 0;i < N;++i){
    cin >> A[i];
    sum += A[i];
    ++cnt[A[i]];
}

cin >> Q;

vector<ll> B(Q);
vector<ll> C(Q);
vector<ll> S(Q,0);

for(ll i = 0;i < Q;++i){

    cin >> B[i] >> C[i];

    sum += (C[i] - B[i])*cnt[B[i]];
    cnt[C[i]] += cnt[B[i]];
    cnt[B[i]] = 0;
    
    S[i] = sum;

}

for(ll i = 0;i < Q;++i){

    cout << S[i] << endl;

}

return 0;

}


Measured memory_bytes: 7116
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main() {
    var (a, b,c ) = readInts()
    var k = readInt()
    while (true) {
        if (a < b && b < c) {
            println("Yes")
            return
        }
        if (k <= 0) {
            break
        }
        if (a >= b) {
            b *= 2
            k--
        } else if (b >= c) {
            c *= 2
            k--
        }
    }
    println("No")
}


Measured memory_bytes: 36316
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll 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;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


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

int main() {
ll l,r;
cin>>l>>r;
if(l/2019!=r/2019){
	cout<<0<<endl;
	return 0;
}

l%=2019;
r%=2019;



ll ans=2019;
for(int i=l;i<=r-1;i++){
for(int j=i+1;j<=r;j++){
	ll val=i*j;
	val%=2019;
	ans=min(ans,val);
}
}

cout<<ans<<endl;
return 0;

}




Measured memory_bytes: 256
using System;

class main{
	static void Main(){
		string[] str1 = Console.ReadLine().Trim().Split(' ');
		int N = int.Parse(str1[0]);
		int M = int.Parse(str1[1]);
		int X = int.Parse(str1[2]);
		string[] str2 = Console.ReadLine().Trim().Split(' ');
		int[] A = new int[100];
		for(int i = 0; i < M; i++){
			A[i] = int.Parse(str2[i]);
		}
		int ans = 0;
		for(int i = 0; i < M; i++){
			if(A[ans] > X) break;
			ans = i;
		}
		Console.WriteLine(Math.Min(ans, M - ans));
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1e9+7
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};


using namespace std;


int main() {
    int h,w;
    cin>>h>>w;
    vector<vector<char>> v(h,vector<char>(w));
    int a=0,b=0;
    rep(i,0,h){
        rep(j,0,w){
            cin>>v[i][j];
            if(v[i][j]=='#')a++;
            else b++;
        }
    }
    
    vector<vector<int>> d(h,vector<int>(w,INF));
    
    queue<P> que;
    que.push(P(0,0));
    d[0][0]=0;
    
    while(que.size()){
        P p=que.front(); que.pop();
        if(p.first==h-1&&p.second==w-1)break;
        
        rep(i,0,4){
            int nx=p.second+dx[i],ny=p.first+dy[i];
            
            if(0<=nx&&0<=ny&&nx<w&&ny<h&&v[ny][nx]!='#'&&d[ny][nx]==INF){
                que.push(P(ny,nx));
                d[ny][nx]=d[p.first][p.second]+1;
            }
        }
    }
    if(d[h-1][w-1]==INF)cout<<-1<<endl;
    else cout<<(b-d[h-1][w-1]-1)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void c2() {
	int K, T;
	cin >> K >> T;
	for (int i = 0; i < T; ++i) {
		int a;
		cin >> a;
		if (a > K / 2) {
			cout << (a*2 - K - 1) << endl;
			return;
		}
	}
	cout << 0 << endl;
}

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


Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int a,sum=0;
    scanf("%d",&a);
    
    if(a%10 == 1)
    {
        sum = sum + 1;
    }
    if((a/10)%10 == 1)
    {
        sum = sum +1;
    }
    if(a/100)
    {
        sum = sum + 1;
    }
    printf("%d",sum);
}


Measured memory_bytes: 1692