akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <limits>
#include <vector>
#include <unordered_set>
#include <algorithm>

int main() {
    int n;
    std::cin >> n;
    int k;
    std::cin >> k;
    std::vector<int64_t> v(n);
    std::vector<int64_t> w(n);
    for(int i = 0; i < n; ++i) {
        std::cin >> w[i];
        std::cin >> v[i];
    }

    std::vector<std::vector<int64_t>> memo(k + 1, std::vector<int64_t>(n, 0));
    for (int j = 0; j <= k; ++j) {
        if (w[0] <= j)
            memo[j][0] = v[0];
        else
            memo[j][0] = 0;
    }
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j <= k; ++j) {
            if (w[i] <= j) {
                memo[j][i] = std::max(memo[j][i - 1], memo[j - w[i]][i - 1] + v[i]);
            } else {
                memo[j][i] = memo[j][i - 1];
            }
        }
    }

    std::cout << memo[k][n - 1];

    return 0;
}


Measured memory_bytes: 82304
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
#include <fstream>
#include <array>
#include <utility>
#include <functional>

using namespace std;
typedef long long Int;
#define REP(i , x) for(int i = 0 ; i < x ; ++i)

typedef pair<int, int> P;

struct gg{ Int v, a, b; };

gg dp[1100][1100];
Int a[1100];
Int b[1100];

Int gcd(Int x, Int y){
	return x%y ? gcd(y, x%y) : y;
}

int main()
{

	Int x, y;
	while (cin >> x >> y){
		Int a = gcd(x, y);
		cout << a << " " << x*y / a << endl;
	}
}

Measured memory_bytes: 1156
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

S = sys.stdin.readline().rstrip()

evens = [1] * len(S)
odds = [0] * len(S)
for i in range(len(S) - 1):
    if S[i] == 'R':
        odds[i + 1] += evens[i]
        evens[i] = 0
        evens[i + 1] += odds[i]
        odds[i] = 0
for i in range(1, len(S))[::-1]:
    if S[i] == 'L':
        odds[i - 1] += evens[i]
        evens[i] = 0
        evens[i - 1] += odds[i]
        odds[i] = 0
for i, c in enumerate(odds):
    if S[i] == 'R':
        evens[i + 1] += c
    else:
        evens[i - 1] += c
print(*evens)


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


void solve(std::string S, std::string T){
    cout << T+S << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
#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 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; }

// ---- ----

LL n, a[1000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	bool pl = false;
	inc(i, n) { if(a[i] > 0) { pl = true; } }
	
	if(pl) {
		LL ma[2] = { 0, 0 };
		inc(i, n) { if(a[i] > 0) { ma[i % 2] += a[i]; } }
		
		cout << max(ma[0], ma[1]) << "\n";
		
		vector<int> v;
		if(ma[0] > ma[1]) {
			dec(i, n) { if((i % 2 == 0 && a[i] <= 0) || (i % 2 == 1 && a[i - 1] > 0)) { v.PB(i); } }
			if(a[0] <= 0) { v.PB(0); }
		} else {
			dec(i, n) { if((i % 2 == 1 && a[i] <= 0) || (i % 2 == 0 && (i == 0 || a[i - 1] > 0))) { v.PB(i); } }
		}
		
		cout << v.size() << "\n";
		inc(i, v.size()) { cout << v[i] + 1 << "\n"; }
	} else {
		pair<LL, int> ma = MP(a[0], 0);
		inc(i, n) { setmax(ma, MP(a[i], i)); }
		
		cout << ma.FI << "\n";
		cout << n - 1 << "\n";
		decID(i, ma.SE + 1, n) { cout << (i + 1) << "\n"; }
		inc(I, ma.SE) { cout << 1 << "\n"; }
	}
	
	return 0;
}


Measured memory_bytes: 256
use std::vec::Vec;
use std::collections::HashSet;
use std::cmp::*;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let (n, m) = read_touple::<usize>();
    let a: Vec<usize> = read_vec();
    let b: Vec<usize> = a.iter().map(|&x| x / 2).collect();
    let c: Vec<usize> = a.iter().map(|&x| count2(x)).collect();
    let l = b.iter().fold(1, |acc, &x| (acc * x) / gcd(x, acc));
    let mut d = false;
    for i in 0..n {
      if c[0] != c[i] {
         d = true;
      }
    }
    //let ans: usize = (m / l) / 2;
    let ans: usize = if d {
       0
    } else if (m / l) % 2 == 0  {
       (m / l) / 2
    } else {
      (m / l) / 2 + 1
    };

    //println!("{}", l);
    println!("{}", ans);
}


fn gcd(a: usize, b: usize) -> usize {
  if b > a {
    gcd(b, a);
  }

  if a % b == 0 {
    return b;
  }

  let r: usize = a % b;

  return gcd(b, r);
}

fn count2(x: usize) -> usize {
  let mut res = 0;
  let mut x = x;
  while x % 2 == 0{
    res += 1;
    x /= 2;
  }
  res
}

Measured memory_bytes: 8444
a = list(map(int,input().split()))
a[0]-=1
c = [a[0]%4,a[1]%4]
d = [0,0]

for i in range(len(c)):
    if c[i]==0:
        d[i]=a[i]
    elif c[i]==1:
        d[i]=1
    elif c[i]==2:
        d[i]=a[i]+1
    else:
        d[i]=0

x,y = map(bin,d)
g = max(len(str(x)),len(str(y)))
x = str(x)[2:].zfill(g-2)
y = str(y)[2:].zfill(g-2)

f = []
for i in range(len(x)):
    if x[-i-1]==y[-i-1]:
        f.append(0)
    else:
        f.append(1)
ans = 0
for i in range(len(f)):
    ans += f[i]*2**i

print(ans)

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

from collections import Counter

cA = Counter(A)
cB = Counter(B)

f = 0

for num, val in cA.items():
    if num not in cB:
        continue
    else:
        if cB[num] + val > N:
            f = 1

tpA = [-1] * (N + 1)
tpB = [-1] * (N + 1)
a = A[0]
b = B[0]
tpB[b] = 0
for i in range(1, N):
    if a != A[i]:
        tpA[a] = i
        a = A[i]
    if b != B[i]:
        b = B[i]
        tpB[b] = i
tpA[a] = N


ans = [0] * N
if f == 1:
    print("No")
else:
    print("Yes")
    t = 0
    for i in range(N+1):
        if tpA[i] >= 0 and tpB[i] >= 0:
            t = max(t, tpA[i] - tpB[i])
    for i in range(N):
        ans[i+t-N] = B[i]
    #print(tpA, tpB, t)
    print(" ".join([str(_) for _ in ans]))

Measured memory_bytes: 74516
#148d
n=int(input())
a=[int(x) for x in input().split()]
if not (1 in a):
    print(-1)
    exit()
start=0
sum=0
for i in range(1,n+1):
    count=0
    for j in range(start,n):
        if i == a[j]:
            count+=1
            start=j
            sum+=count
            break
    if count==0:
        break

print(n-sum)

Measured memory_bytes: 25768
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;cin>>s;
	int N = s.size();
	int tmp = 0;
	vector<int> n(N + 1);
	for(int i = 0; i < N; i++) {
		n[i + 1] = s[N - i - 1] - '0';
	}
	// for(int i = 1; i <= N; i++) {
	// 	cout << n[i] << endl;
	// }
	vector<vector<int>> dp(N + 1,vector<int>(2,INF));
	dp[0][0] = 0;
	for(int i = 1; i <= N; i++) {
		for(int j = 0; j < 2; j++) {
			if (j == 0){
				dp[i][0] = min(dp[i - 1][0] + n[i],dp[i - 1][1] + 1 + n[i]);
			}
			else{
				dp[i][1] = min(dp[i - 1][0] + 10 - n[i],dp[i - 1][1] + 10 - (1 + n[i]));
			}
		}
	}
	cout << min(dp[N][0],dp[N][1] + 1) << endl;
	return 0;
}

Measured memory_bytes: 59780
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
long long mod = 1000000007;
 
long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}
 
void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
 
int main() {
    int n, m, k, ans = 0;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= m; j++){
            if (i * j + (n - i) * (m - j) == n * m - k){
                cout << "Yes" <<endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

int main(void) {
	int n;
	scanf("%d", &n);
	vector<int> v;
	for (int i = 0; i < n; i++)
		v.push_back(i + 1);
	do {
		for (int i = 0; i < n; i++) {
			printf(i < n - 1?"%d ":"%d\n", v[i]);
		}
	} while(next_permutation(v.begin(), v.end()));
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, m, i, x, ans=0;
    priority_queue<long long> a;
    cin >> n >> m;
    for(i=0;i<n;i++){
        cin >> x;
        a.push(x);
    }
    for(i=0;i<m;i++){
        long long tmp;
        tmp=a.top();
        tmp=tmp/2;
        a.pop();
        a.push(tmp);
    }
    for(i=0;i<n;i++){
        long long tmp;
        tmp=a.top();
        ans=ans+tmp;
        a.pop();
    }
    cout << ans <<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<float>a(n,0);
    for(int i=0;i<n;i++)cin>>a[i];
    float sum=0;
    for(int i=0;i<n;i++)sum+=(1/a[i]);
    cout<<(1/sum);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    char c;
    
    scanf("%c",&c);
    
    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
        printf("vowel\n");
    }
    else{
        printf("consonant\n");
    }
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
void insertionSort( int A[] , int N )
{
	for( int i = 1 ; i < N ; i++ )
	{
		for( int i = 0; i < N-1; i++ )
		    cout << A[i] << " ";
		cout << A[N-1] << endl;
		int v =A[i];
		int j = i-1;
		while( j >= 0 && A[j] > v )
		{
			A[j+1] = A[j];
			j--;
			A[j+1] = v;
		}
	}
	for( int i = 0; i < N-1; i++ )
		    cout << A[i] << " ";
		cout << A[N-1] << endl;
}

int main()
{
	int N;
	cin >> N;
	int *A = new int [N];
	for( int i = 0; i < N ; i++ )
	{
		cin >> A[i];
	}
	insertionSort( A , N);
	return 0;
} 


Measured memory_bytes: 3096
#!/usr/bin/env python3
import sys

def solve(K: int):
    s = set(range(1, 10))
    while len(s) <= 10 ** 5:
        ss = set(s)
        for n in s:
            t = n % 10
            ss.add(n * 10 + t)
            if t != 0:
                ss.add(n * 10 + t - 1)
            if t != 9:
                ss.add(n * 10 + t + 1)
        s = ss
    s = sorted(s)
    print(s[K-1])


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25756
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double

void fio() 
{
    std::ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
}

void inputread()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

int32_t main()
{
    fio();
    ll n,i,s=0;
    cin >> n;

    for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            // cout << i << " ";
            s+=i;
        }
    }
    cout << s ;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

int main()
{
    FAST_IO;

    int n, x;
    cin >> n >> x;
    vector<int> v(n+5), d;
    for (int i = 0; i < n; i++)
        cin >> v[i];

    d.push_back(0);
    for (int i = 1; i <= n; i++)
        d.push_back(d[i-1]+v[i-1]);
    int ans =0;
    for (int i = 1; i < (int) d.size(); ans = ++i) {
        if (d[i] > x) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, a, b = ril()
if (b - a) % 2 == 0:
    print('Alice')
else:
    print('Borys')

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)


int main()
{
    string s;
    cin>>s;
    int f=0;
    for(int i=0;i<s.size();i++)
    {
        if(i%2==0)
        {
            if(s[i]=='L')
                f=1;
        }
        else
        {
            if(s[i]=='R')
                f=1;
        }
    }
    if(f)
        cout<<"No";
    else
        cout<<"Yes";

}


Measured memory_bytes: 256
// AOJ ITP1_11_B Dice II
// 2018.4.29 bal4u
 
#include <stdio.h>
 
int rot[24][7] = {
    { 0,1,2,3,4,5,6 },{ 0,1,3,5,2,4,6 },{ 0,1,4,2,5,3,6 },{ 0,1,5,4,3,2,6 },
    { 0,2,6,3,4,1,5 },{ 0,2,3,1,6,4,5 },{ 0,2,1,4,3,6,5 },{ 0,2,4,6,1,3,5 },
    { 0,3,1,2,5,6,4 },{ 0,3,2,6,1,5,4 },{ 0,3,5,1,6,2,4 },{ 0,3,6,5,2,1,4 },
    { 0,4,1,5,2,6,3 },{ 0,4,2,1,6,5,3 },{ 0,4,5,6,1,2,3 },{ 0,4,6,2,5,1,3 },
    { 0,5,1,3,4,6,2 },{ 0,5,3,6,1,4,2 },{ 0,5,4,1,6,3,2 },{ 0,5,6,4,3,1,2 },
    { 0,6,2,4,3,5,1 },{ 0,6,3,2,5,4,1 },{ 0,6,5,3,4,2,1 },{ 0,6,4,5,2,3,1 } };
int assign[7];
 
int main()
{
    int i, j;
    int a[7], b[7], dice[7];
 
    for (i = 1; i <= 6; i++) scanf("%d", assign+i);
    for (i = 1; i <= 6; i++) scanf("%d", a+i);
    for (j = 0; j < 24; j++) {
        for (i = 1; i <= 6; i++) dice[i] = rot[j][i];
        for (i = 1; i <= 6; i++) b[i] = assign[dice[i]];
        for (i = 1; ; i++) {
            if (i > 6) { puts("Yes"); return 0; }
            if (a[i] != b[i]) break;
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 2144
#include <stdio.h>
int main(void){
    int n, i, a[128], x;
    scanf("%d", &n);
    x = 0;
    
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    
    for(i = 0; i < n; i = i + 2){
        if(a[i] % 2 == 1){
            x++;
        }
    }
    
    printf("%d\n", x);
    
    return 0;
}

Measured memory_bytes: 1716
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  vector<int> a(3);
  int c = 0;
  REP(i, 3) {
    cin >> a[i];
  }
  sort(ALL(a));
  while (a[0] != a[1] || a[1] != a[2] || a[2] != a[0]) {
    if ((a[2] - a[0]) - (a[2] - a[1]) == 1) {
      a[1] += 1;
      a[2] += 1;
    } else if (a[1] == a[2]) {
      a[0] += 2;
    } else {
      a[0] += 1;
      a[1] += 1;
    }
    c++;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
import collections
n , k= map(int,input().split())
a = list(map(int,input().split()))
c = collections.Counter(a)
p = c.most_common()
s = len(p)
if s <= k:
    print(0)
    exit()

ans = 0
for i in range(s-k):
    ans += p[-(i+1)][1]

print(ans)

Measured memory_bytes: 39348
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var H, W int
	con.Scan(&H, &W)
	for i := 0; i < H; i++ {
		var s string
		con.Scan(&s)
		con.Println(s)
		con.Println(s)
	}
	return nil
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
ll A[5000001],bin[5000001];
vector<ll>v;
map<int,int>myMap;
set<int>mySet;
vector<pair<ll,ll> >vp;
/* Precode Start Here *\



     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll d,k;
    cin>>d;
    if(d<100)
    {
        cout<<0<<endl;
        return 0;
    }
    k=d/100;
    d%=100;
    while(k!=0&&d!=0)
    {
        k--;
        d-=5;
        if(d<0)
        {
            d+=5;
            k++;
            break;
        }
    }
    while(k!=0&&d!=0)
    {
        k--;
        d-=4;
        if(d<0)
        {
            d+=4;
            k++;
            break;
        }

    }
    while(k!=0&&d!=0)
    {
        k--;
        d-=3;
        if(d<0)
        {
            d+=3;
            k++;
            break;
        }
    }
    while(k!=0&&d!=0)
    {
        k--;
        d-=2;
        if(d<0)
        {
            d+=2;
            k++;
            break;
        }
    }
    while(k!=0&&d!=0)
    {
        k--;
        d-=1;
        if(d<0)
        {
            d+=1;
            k++;
            break;
        }
    }
    if(d==0)
    {
        cout<<1<<endl;
    }
    else
        cout<<0<<endl;
    return 0;
}



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

int main(void){
    int k,a,b,i,flag;
    flag = 1;
    cin >> k >> a >> b;

    for(i=a; i<=b; i++){
        if(i % k == 0){
            cout << "OK" << endl;
            flag = 0;
            break;
        }
    }

    if(flag == 1){
        cout << "NG" << endl;
    }

    return 0;
}

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

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

template<class T,class F>
struct segment_tree{
  std::vector<T> data;
  int n;
  F f;
  T identity;
  segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){
    n = 1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
  }
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){
    build(v);
  }
  void build(std::vector<T> const& v){
    int sz = v.size();
    n = 1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
    for(int i=0;i<sz;++i)data[i+n]=v[i];
    for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  void set(int i,T x){
    i += n;
    data[i] = x;
    while(i,i>>=1)data[i] = f(data[i<<1|0],data[i<<1|1]);
  }
  T query(int l,int r)const{
    l += n, r += n;
    T x = identity;
    while(l<r){
      if(l&1)x = f(x,data[l++]);
      if(r&1)x = f(x,data[--r]);
      l>>=1, r>>=1;
    }
    return x;
  }
  T operator[](int i)const{
    return data[i+n];
  }
};
template<class T,class F>
auto make_segtree(int n,T ide,F f){
  return segment_tree<T,F>(n,ide,f);
}
template<class T,class F>
auto make_segtree(std::vector<T>const& v,T ide,F f){
  return segment_tree<T,F>(v,ide,f);
}

signed main(){
  int n;
  cin>>n;
  std::vector<int64_t> a(n);
  for(auto& ai:a)cin>>ai;
  auto gcd = [](auto a,auto b){
    while(b){
      a %= b;
      std::swap(a,b);
    }
    return a;
  };
  auto seg = make_segtree<int64_t>(a,0,gcd);
  int64_t ans = 1;
  for(int i=0;i<n;++i){
    seg.set(i,0);
    ans = std::max(ans,seg.query(0,n));
    seg.set(i,a[i]);
  }
  cout<<(ans)<<endl;
}

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

int main(){
	int n;
	cin>>n;
	
	int ans=0;
	
	int i;
	
	for(i=1;i<=n;i++){
		ans+=i;
		if(ans>=n)break;
	}
	
	for(int j=1;j<=i;j++){
		if(j!=(ans-n))cout<<j<<endl;
	}
	
	return 0;
}

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

int main() {
  long x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << x2+(y1-y2) << " ";//x3
  cout << y2+(x2-x1) << " ";//y3
  cout << x2+(y1-y2)+(x1-x2) << " ";//x4
  cout << y2+(x2-x1)+(y1-y2) << endl;//y4
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  string s = a + b;
  auto n = atoi(s.c_str());
  for (int i = 1; i < 350; i++) {
    if(n == i*i){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  int n, k, r[3];
  int i, c;
  int sum = 0;
  vector<int> prev;
  string t;

  cin >> n >> k;
  cin >> r[1] >> r[2] >> r[0];
  cin >> t;

  prev.resize(k,-1);

  for(i=0;i<n;i++){
    if(t[i]=='r') c = 0;
    else if(t[i]=='s') c = 1;
    else if(t[i]=='p') c = 2;

    if(prev[i%k]==c){
      prev[i%k] = 3;
    }
    else{
      prev[i%k] = c;
      sum += r[c];
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int n,a[222222],cost[222222][6],dp[222222][6],ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
	{
		cost[i][1]=cost[i][5]=a[i];
		cost[i][3]=!(a[i]&1);
		if (!a[i]) cost[i][2]=2;
		else cost[i][2]=(a[i]&1);
		cost[i][4]=cost[i][2];
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=5;j++)
		dp[i][j]=1e9;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=5;j++)
		{
			for (int k=1;k<=j;k++)
			{
				dp[i][j]=min(dp[i][j],dp[i-1][k]+cost[i][j]);
			}
		}
	}
	ans=1e9;
	for (int i=1;i<=5;i++) ans=min(ans,dp[n][i]);
	printf("%d\n",ans);
	return 0;
}

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

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

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin >> s;
  rep(i, 2) {
    if (s[i] != s[i+1]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3604
import java.io.*;
import java.util.*;

public class Main {
    int n;
    long A,D;
    PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    // greed. No need for advanced structure. A simply deque would work.
    long solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); D = sc.nextInt(); A = sc.nextInt();
        int[][] pos_hp = new int[n][];
        for(int i=0;i<n;i++){
            int pos = sc.nextInt(), hp = sc.nextInt();
            pos_hp[i] = new int[]{pos,hp};
        }
        Arrays.sort(pos_hp,(o1,o2)->(o1[0]-o2[0])); // sort according to the x_pos
        Deque<long[]> queue = new LinkedList<>(); // int[]{end_position, damage at this operation}
        long cur_all_damage = 0, ans = 0;
        for(int start = 0; start < n; start++){
            int[] curMonster = pos_hp[start];
            while(queue.size()>0&&queue.peek()[0]<curMonster[0]){
                long[] temp = queue.poll();
                cur_all_damage -= temp[1];
            }
            if(cur_all_damage >= curMonster[1]) continue; // this monster can be killed by previous moves
            else{
                long left = curMonster[1]-cur_all_damage;
                long moves = (left-1)/A+1;
                ans += moves;
                long d_damage = moves*A;
                cur_all_damage += d_damage;
                queue.addLast(new long[]{curMonster[0]+2*D, d_damage});
            }
        }
        return ans;
    }
}



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


using namespace std;


int main(){
  	
  int a,b,c;
  bool flag = false;
 	cin>>a>>b>>c;
  	
  	if(a==5 && b == 5 && c==7) flag = true;
  if(a==5 && c == 5 && b==7) flag = true;
  if(b==5 && c == 5 && a==7) flag = true;
  
  if(flag) cout<<"YES\n";
  else cout<<"NO\n";
  return 0;
}

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

bool isok(int f,int e,const string& s){
    if(f>=e)
        return true;
    int x=-1;
    for(int i=f;i<e;i++){
        if(s[i]=='(' || s[i]=='['){
            x=i;
            break;
        }
        if(s[i]==')' || s[i]==']')
            return false;

    }
    if(x==-1)
        return true;

    char rig;
    if(s[x]=='(')
        rig=')';
    else
        rig=']';
    int y=-1;
    int cnl=1;int cnr=0;
    for(int i=x+1;i<e;i++){
        if(s[i]==rig)cnr++;
        if(s[i]==s[x])cnl++;
        if(cnr==cnl){
            y=i;
            break;
        }


    }
    if(y==-1)
        return false;
    return isok(x+1,y,s) && isok(y+1,e,s);
}
int main(){
    string s;
    while(getline(cin,s),s!="."){
        string res=(isok(0,s.size(),s) ? "yes":"no");
        cout<<res<<endl;

    }
    return 0;
}

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

int a[10001];
int main() {
	a[1] = 2;
	for (int i = 2; i <= 10000; i++)a[i] = a[i - 1] + i;
	int n; while (cin >> n)cout << a[n] << endl;
	return 0;
}

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

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  long long n, input, tmp = 1, cnt = 0;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> input;
    if (input == tmp) {
      tmp++;
    } else {
      cnt++;
    }
  }
  if (tmp == 1) {
    cout << -1 << endl;
  } else {
    cout << cnt << endl;
  }
}


Measured memory_bytes: 4824
h,w=list(map(int,input().split()))

a=[]
coin_sum=0
for i in range(h):
    a_row=list(map(int,input().split()))
    a.append(a_row)

operation=[]
def search(x,y):
    if x==w-1 and y==h-1:
        return

    if a[y][x]%2==1:
        if x==w-1 and y<h-1:
            a[y][x]-=1
            a[y+1][x]+=1

            operation.append([y,x,y+1,x])
        else:
            a[y][x]-=1
            a[y][x+1]+=1

            operation.append([y,x,y,x+1])

for x in range(w):
    for y in range(h):
        search(x,y)

print(len(operation))
for i in range(len(operation)):
    o=operation[i]
    print(o[0]+1,o[1]+1,o[2]+1,o[3]+1)

Measured memory_bytes: 26360
#include<bits/stdc++.h>
using namespace std;
int n,s[100005],q,t;
bool binarySearch(int key){
    int left=0, right=n;
    while(left<right){
        int mid=(left+right)/2;
        if(s[mid]==key){
            return true;
        }
        else if(key < s[mid]){
            right=mid;
        }
        else{
            left=mid+1;
        }
    }
    return false;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>s[i];
    cin>>q;
    int ans=0;
    for(int i=0;i<q;i++){
        cin>>t;
        if(binarySearch(t)) ans++;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3424
#include<iostream>
#include<map>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
typedef pair<int,int>pii;
long long dp[2010][2010]={0},in[2020],n,o;
queue<pii>q;
int main(){
	cin>>n;
	rep(i,n){cin>>in[i];dp[i][1]=in[i],q.push(pii(i,1));}
	while(!q.empty()){
		pii r=q.front();q.pop();
		int a=r.first,b=r.second,s=(a+n-1)%n,t=(s+1+b)%n,w;
		rep(i,2){
			if(b%2&&in[s]<in[t])s=a;
			w=b%2?0:in[(i?t:s)];
			if(dp[s][++b]<dp[a][b-1]+w){
				dp[s][b]=dp[a][b-1]+w;
				if(b!=n)q.push(pii(s,b));
			}
			if(--b%2==0)s=a;
		}
	}
	rep(i,n)o=max(o,dp[i][n]);
	cout<<o<<endl;
}

Measured memory_bytes: 32664
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll n,k;cin>>n>>k;
    vector<vector<vector<ll> > >dp(n+2,vector<vector<ll> >(k+1,vector<ll>(n+1,inf*inf)));
    vector<ll>a(n+1);
    REP(i,1,n+1){
        cin>>a[i];
    }
    dp[0][0][0]=0;
    rep(i,n+1){
        rep(j,k+1){
            rep(l,n+1){
                if(dp[i][j][l]==inf*inf)continue;
                if(a[l]>=a[i]){
                    dp[i+1][j][i]=min(dp[i][j][l],dp[i+1][j][i]);
                }else{
                    dp[i+1][j][i]=min(dp[i][j][l]+a[i]-a[l],dp[i+1][j][i]);
                }
                if(j<k){
                    dp[i+1][j+1][l]=min(dp[i+1][j+1][l],dp[i][j][l]);
                }
            }
        }
    }
    ll ans=inf*inf;
    rep(i,k+1){
        rep(j,n+1){
            ans=min(ans,dp[n+1][i][j]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 220300
#include<bits/stdc++.h>
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define test lli t;cin>>t;while(t--)
#define arrin lli n;cin>>n;lli a[n];for(lli i=0;i<n;i++)cin>>a[i]
#define floop for(lli i=0;i<n;i++)
#define mod 1000000007
#define defvec vector<lli>v
#define ub upper_bound
#define pb push_back
#define bs binary_search
#define endl '\n'
using namespace std;
lli merge(lli a[],lli l,lli mid,lli r)
{
  lli i=l,j=mid,k=0;
  lli temp[r-l+1];
  lli ans=0;
 while(i<mid&&j<=r)
{
   if(a[i]<=a[j])
{
   temp[k++]=a[i++];
}
else
{
   temp[k++]=a[j++];
   ans+=mid-i;
}
}
while(i<mid)
temp[k++]=a[i++];
while(j<=r)
temp[k++]=a[j++];
for(lli i=l,k=0;i<=r;i++,k++)
{
  a[i]=temp[k];
}
return ans;
}
lli merge_sort(lli a[],lli l,lli r)
{  lli count=0;
  if(l<r)
{
   lli mid=l+(r-l)/2;
   lli right_count=merge_sort(a,mid+1,r);
   lli left_count=merge_sort(a,l,mid);
   lli mergingcount=merge(a,l,mid+1,r);
   return right_count+left_count+mergingcount;
}
return count;
}

int main()
{  
  lli n;
  cin>>n;
  lli a[n];
  for(lli i=0;i<n;i++)
  cin>>a[i];
  double flag=a[0];
  for(lli i=1;i<n;i++)
  {   flag=(((flag*a[i])*(1.0))/(flag+a[i]));
  }
  cout<<flag<<endl;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,k = li()
l = sorted(list(li()), reverse=True)
print(sum(l[:k]))

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();
    
    string s;
    cin >> s;
    
    int n = 0;
    n += (s[5] - '0');
    n *= 10;
    n += (s[6] - '0');
    int m = 0;
    m += (s[0] - '0');
    m *= 10;
    m += (s[1] - '0');
    m *= 10;
    m += (s[2] - '0');
    m *= 10;
    m += (s[3] - '0');
    
    if (m > 2019)
    	return cout << "TBD", 0;
    if (m == 2019 and n > 4)
    	return cout << "TBD", 0;
    	
    cout << "Heisei";
    
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
void main()
{
    string s = rdStr;

    long len = s.length;
    long[] lists = new long[len];
    auto g = s.group.array;
    long cnt;
    foreach (x; g)
    {
        long n = x[1].to!long;
        cnt += n;
        if (x[0] == 'R')
        {
            lists[cnt-1] += (n >> 1) + (n & 1);
            lists[cnt] += (n >> 1);
        }
        else
        {
            lists[cnt-n-1] += (n >> 1);
            lists[cnt-n] += (n >> 1) + (n & 1);
        }
    }

    foreach (i, x; lists)
    {
        x.write;
        if (i == len - 1) writeln;
        else " ".write;
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 3736
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	int n;
	cin >> n;
	string kotae = "111";

	if (n <= 111) {
		kotae = "111";
	}
	else if (n <=222 ) {
		kotae = "222";
	}
	else if (n <=333 ) {
		kotae = "333";
	}
	else if (n <=444 ) {
		kotae = "444";
	}
	else if (n <=555 ) {
		kotae = "555";
	}
	else if (n <=666 ) {
		kotae = "666";
	}
	else if (n <=777 ) {
		kotae = "777";
	}
	else if (n <=888 ) {
		kotae = "888";
	}
	else if (n <= 999) {
		kotae = "999";
	}
	cout << kotae;
	return 0;
}

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

int main(){
    using namespace std;
    size_t n, m;
    scanf("%lu%lu", &n, &m);
    vector<size_t> a(n), b(m), c, d;
    for(auto& i : a)scanf("%lu", &i);
    for(auto& i : b)scanf("%lu", &i);
    set_intersection(begin(a), end(a), begin(b), end(b), back_inserter(c));
    set_union(begin(a), end(a), begin(b), end(b), back_inserter(d));
    printf("%lu %lu\n", c.size(), d.size());
    for(const auto i : c)printf("%lu\n", i);
    for(const auto i : d)printf("%lu\n", i);
}


Measured memory_bytes: 7076
#include<cstdio>
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define _USE_MATH_DEFINES // M_PI????????????????????????
#include<math.h>
#pragma warning(disable:4996)
using namespace std;

#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

void maxHeapify(int i){
	int l, r, largest;
	l = 2*i;
	r = 2*i + 1;

	// ????????????????????????????????§???????????§????????????????????¶
	if( l<=H && A[l] > A[i] ) largest = l;
	else largest = i;
	if( r <= H && A[r] > A[largest] ) largest = r;

	if( largest!=i ){
		swap(A[i],A[largest]);
		maxHeapify(largest);
	}
}

int extract(){
	int maxv;
	if(H<1) return -INFTY;
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}

void increaseKey(int i, int key){
	if( key<A[i] ) return;
	A[i] = key;
	while(i>1 && A[i/2] < A[i] ){
		swap(A[i],A[i/2]);
		i = i/2;
	}
}

void insert(int key){
	H++;
	A[H] = -INFTY;
	increaseKey(H,key);
}


int main(){
	int key;
	char com[10];

	while(1){
		cin >> com;
		if( com[0]=='e'&& com[1]=='n' ) break;
		if( com[0]=='i' ){
			cin >> key;
			insert(key);
		}else{
			cout << extract() << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 6912
n = int(input())
t1 = 0
x1 = 0
y1 = 0
count = 0
for _ in range(n):
    t,x,y = map(int,input().split())
    t = abs(t - t1)
    x = abs(x - x1)
    y = abs(y - y1)
    if x + y <= t and (x+y) % 2 == t % 2:
        t1 = t
        x1 = x
        y1 = y
        count += 1
if count == n:
    print("Yes")
else:
    print("No")
        

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
from operator import mul
from functools import reduce
def cmb(n, r):
  if not n >= r:return 0
  r = min(n-r, r)
  if r == 0:
      return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1, r + 1))
  return over // under


n = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
for i in range(n+1):
  ans += cmb(C[i],2)
for i,ai in enumerate(A):
  print(ans-cmb(C[ai],2) + cmb(C[ai]-1,2))
  

Measured memory_bytes: 97656
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[2][n];
		for(int i=0;i<2;i++){
			for(int j=0;j<n;j++){
				a[i][j] = sc.nextInt();
			}
		}
		int[][] dp = new int[2][n];
		dp[0][0] = a[0][0];
		for(int i=1;i<n;i++){
			dp[0][i] = dp[0][i-1] + a[0][i];
		}
		dp[1][0] = a[1][0] + a[0][0];
		for(int i=1;i<n;i++){
			dp[1][i] = Math.max(dp[0][i],dp[1][i-1]) + a[1][i];
		}
		System.out.println(dp[1][n-1]);
	}
}

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

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

Measured memory_bytes: 3628
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        // Your code here!
        int[] s = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int N = s[0];
        int K = s[1];
        int num = 1;
        for(int i = 0; i < N; i++)
        {
            if(i == 0) num *= K;
            else num *= (K - 1);
        }
        Console.WriteLine(num);
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long
int inf = (1LL <<  62);
using namespace std;

signed main(){
    string s;
    cin >> s;
    string a = s.substr(0, 2);
    string b = s.substr(2, 2);
    int an = stoi(a);
    int bn = stoi(b);
    if(an==0 && bn==0){
        cout << "NA";
        exit(0);
    }
    if(an == 0){
        if(bn > 12){
            cout << "NA";
            exit(0);
        }else{
            cout << "YYMM";
            exit(0);
        }
    }
    if(bn == 0){
        if(an > 12){
            cout << "NA";
            exit(0);
        }else{
            cout << "MMYY";
            exit(0);
        }
    }
    if(an > 12){
        if(bn > 12){
            cout << "NA";
            exit(0);
        }else{
            cout << "YYMM";
            exit(0);
        }
    }else{
        if(bn > 12){
            cout << "MMYY";
            exit(0);
        }else{
            cout << "AMBIGUOUS";
            exit(0);
        }
    }
}

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

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N, A;
	cin >> N;
	vector<int> v(N);
	rep(i, N) {
		cin >> A;
		v[i] = A;
	}
	int i = 0, result = 0;
	while (v[i] % 2 == 0) {
		if (v[i] % 2)
			break;
		v[i] /= 2;
		i++;
		if (i == N - 1) {
			result++;
			i = 0;
		}
	}
	cout << result << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

int main(void){

   ll n, a, b;

   cin >> n >> a >> b;

   //２人の距離が近い場合(偶数)
   if((b-a)%2==0){
      ll cnt_div = (b - a) / 2;
      cout << cnt_div << endl;
      return 0;
   }

      //ここから奇数

      //卓１まで移動してから出会う+1戦して調整する
      ll cnt1 = a; //１卓＋１戦

      //卓Nまで移動してから出会う＋1戦して調整する
      ll cntN = n - b + 1;

      ll meet = (b - a - 1) / 2;

      cout << min(cnt1, cntN) + meet << endl;

      return 0;
}


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

int main(void){

  char S[200001],T[200001];
  int i,ans = 0;

  scanf("%s",S);
  scanf("%s",T);

  for(i = 0;i < strlen(S);i++){
    if(S[i] != T[i]) ans++;
  }

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


Measured memory_bytes: 2116