akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <typeinfo>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;

int main(void){
	int n;
	cin>>n;
	bool flag=false;
	for(int i=0;i<=n/7;i++){
		if((n-i*7)%4==0){
			flag=true;
			break;
		}
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
N = input()

if N[0] == "1":
    if int(N) <= 111:
        print(111)
    else:
        print(222)
elif N[0] == "2":
    if int(N) <= 222:
        print(222)
    else:
        print(333)
elif N[0] == "3":
    if int(N) <= 333:
        print(333)
    else:
        print(444)
elif N[0] == "4":
    if int(N) <= 444:
        print(444)
    else:
        print(555)
elif N[0] == "5":
    if int(N) <= 555:
        print(555)
    else:
        print(666)
elif N[0] == "6":
    if int(N) <= 666:
        print(666)
    else:
        print(777)
elif N[0] == "7":
    if int(N) <= 777:
        print(777)
    else:
        print(888)
elif N[0] == "8":
    if int(N) <= 888:
        print(888)
    else:
        print(999)
else:
    print(999)

Measured memory_bytes: 3064
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto A = new long[](N);
    auto B = new long[](N);
    foreach (i; 0 .. N)
        scan(A[i], B[i]);
    zip(A, B).sort();
    long cur;
    while (true)
    {
        if (B[cur] < K)
        {
            K -= B[cur];
            cur++;
            continue;
        }
        writeln(A[cur]);
        return;
    }
}


Measured memory_bytes: 4732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,m,p;
  cin >> n >> m >> p;
  vec d(n,-inf);
  d[0]=0;
  vec a(m);
  vec b(m);
  vec c(m);
  for(ll i=0;i<m;i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    c[i]-=p;
  }
  for(ll i=0;i<2*n;i++) {
    for(ll j=0;j<m;j++) {
      if(d[a[j]]==-inf) continue;
      if(d[a[j]]+c[j]>d[b[j]]) {
        if(i<n-1) {
          d[b[j]]=d[a[j]]+c[j];
        }
        else {
          d[b[j]]=inf;
        }
      }
    }
  }
  if(d[n-1]==inf) {
    cout << -1 << endl;
  }
  else {
    cout << max(d[n-1],0LL) << endl;
  }
}

Measured memory_bytes: 384
n = int(input())
p = list(map(int, input().split()))
ans = 0
def is_order(a, b, c):
  if (a > b and b > c) or (a < b and b < c):
    return True
  else:
    return False

for i in range(n-2):
  if is_order(p[i], p[i+1], p[i+2]):
    ans += 1
print(ans)

Measured memory_bytes: 38384
#include <stdio.h>

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  if ((1 <= a) && (a <= 9) && (1 <= b) && (b <= 9))
    printf("%d\n", a * b);
  else
    puts("-1");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;

int main()
{
    int t;
   
    for(int i=1; i<=5; i++){
        
        cin >> t;
        if(t == 0) {
            cout << i << endl;
            return 0;
        }
    }
    
    
    
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;
};

struct Card L[MAX/2 + 2], R[MAX/2 + 2];//左部分と右部分のリスト

void merge(struct Card A[], int n, int left, int mid, int right){
    int i,j,k;
    int n1 = mid - left;//左半分(正確に2等分ではない)
    int n2 = right - mid;//右半分(正確に2等分ではない)
    for(i=0;i<n1;i++){
        L[i]=A[left + i];//左部分に要素を追加
    }
    for(i=0;i<n2;i++){
        R[i]=A[mid + i];//右部分に要素を追加
    }
    L[n1].value=R[n2].value=SENTINEL;
    i=j=0;
    for(k=left;k<right;k++){
        if(L[i].value<=R[j].value){//任意に定めた数字より小さい時
            A[k]=L[i++];
        }else{//任意の定めた数字より大きい時
            A[k]=R[j++];
        }
    }
}

//以下はマージソート同様、半分ずつ整理する
void mergeSort(struct Card A[], int n, int left, int right){
    int mid;
    if(left+1<right){
        mid = (left + right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int partition(struct Card A[], int n, int p, int r){
    int i,j;
    struct Card t,x;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j].value <= x.value){//要素同士で大小関係の比較
            i++;
            t=A[i]; A[i]=A[j]; A[j]=t;//値を入れ替える
        }
    }
    t=A[i+1]; A[i+1]=A[r]; A[r]=t;//処理速度を高速化するためにfor文にの外に出す
    return i+1;//int型だから返り値必要
}

//任意に定めた数字を基準に要素を並べる。その後基準を再度変更し同様に要素を並べる、を繰り返す。
void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if(p<r){
        q=partition(A, n, p, r);
        quickSort(A, n, p, q-1);
        quickSort(A, n, q+1, r);
    }
}

int main(){
    int n,i,v;
    struct Card A[MAX], B[MAX];
    char S[10];//S[1]はダメだが、S[2]ではコードが通った。おそらく、出力する時の分だけ要素が必要である。
    int stable=1;
    
    scanf("%d", &n);
    
    for(i=0;i<n;i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }
    
    mergeSort(A,n,0,n);
    quickSort(B,n,0,n-1);
    
    for(i=0;i<n;i++){
        if(A[i].suit != B[i].suit){
            stable=0;
        }
    }
        
    if(stable == 1){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }
    for(i=0;i<n;i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    return 0;//int型の関数だから
}


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

using namespace std;

int main ()
{
	long long N, X;
	scanf("%lld %lld",&N,&X);
	long long res = N;
	N -= X;
	if (N < X) { long long temp = N; N = X; X = temp; }
	while (X)
	{
		res += (N / X) * (2 * X);
		N %= X;
		long long temp = N; N = X; X = temp;
	}
	res -= N;
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n;
  int cont;
  while(scanf("%d",&n)!=EOF){
    int a[n];
    for(int i=0;i<n;i++){
      a[i]=1;        //1 素数　０素数ではない
    }
    a[0]=0;
    cont=0;
    for(int i=2;i<=sqrt(n);i++){
      if(a[i-1]==1){
	for(int j=2;i*j<=n;j++){
	  a[i*j-1]=0;
	}
      }
    }
    for(int i=0;i<n;i++){
      if(a[i]==1)cont++;
    }
    cout<<cont<<endl;
  }
}

Measured memory_bytes: 5108
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (a, b): (usize, usize);
    input!(a, b);
    if a == 1 || b == 1 {
        println!("1");
    } else {
        let c = (a + 1) / 2;
        let d = a - c;
        println!("{}", (c + d) * (b / 2) + c * (b % 2));
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int A,B;
    cin >> A >> B;
    int min_8_answer = ceil(A*12.5);
    int max_8_answer = ceil((A+1)*12.5)-1;
    int min_10_answer = B*10;
    int max_10_answer = (B+1)*10-1;
    if (min_8_answer >= min_10_answer && min_8_answer <= max_10_answer)
    {
        cout << min_8_answer;
    }else if (min_10_answer >= min_8_answer && min_10_answer <= max_8_answer)
    {
        cout << min_10_answer;
    }else
    {
        cout << -1;
    }
}


Measured memory_bytes: 384
def linear_search(key, nums):
    for num in nums:
        if num == key:
            return True
    return False

def binary_search(key, nums):
    # print('binary_serach ' + str(key))
    left = 0
    right = len(nums)
    mid = int((left+right)/2)

    while left < right:
        mid = int((left+right)/2)
        # print(left, mid, right)
        if nums[mid] == key:
            return key
        elif key < nums[mid]:
            right = mid
        else:
            left = mid + 1
    return -1

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

count = 0
for t in T:
    if binary_search(t, S) > -1:
        count += 1
        
print(count)



Measured memory_bytes: 16712
#include <stdio.h>
#include <stdbool.h>
typedef unsigned long long ull;

int main()
{
    ull n;
    ull a[1000][1000];

    scanf("%lld", &n);
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n - 1; j++)
        {
            scanf("%lld", &a[i][j]);
            a[i][j]--;
        }
    }

    ull day = 0;
    ull next[1000] = {};

    while (1)
    {
        day++;
        bool done_today[1000] = {};
        bool flag = false;
        bool rest_exists = false;

        for (size_t i = 0; i < n; i++)
        {
            if (done_today[i] || next[i] == n - 1)
            {
                continue;
            }

            rest_exists = true;

            const ull enemy = a[i][next[i]];

            if (a[enemy][next[enemy]] == i && !done_today[enemy])
            {
                done_today[i] = true;
                done_today[enemy] = true;
                flag = true;
                next[i]++;
                next[enemy]++;
            }
        }

        if (!rest_exists)
        {
            printf("%lld\n", day - 1);
            return 0;
        }
        else if (!flag)
        {
            printf("-1\n");
            return 0;
        }
    }
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int N, X, Y; cin >> N >> X >> Y;
    vector<int> res(N,0);
    
    for (int i = 1; i <= N-1; i++)
    {
        for (int j = i + 1; j <= N; j++)
        {   int u,v;
            u= abs(X-i) + abs(j-Y) + 1;
            v = j-i;
            res.at(min(u, v)) ++;
        }
    }
    for (int i = 1 ; i < N; i++){
        cout << res.at(i) << endl;
    }
}

Measured memory_bytes: 256
N,M = [int(i) for i in input().split()]

li = []
for _ in range(N):
    a = [int(i) for i in input().split()]
    li.append(a)

li.sort()

p = 0
ans = 0
for i in range(N):
    if M > li[i][1]:
        M -= li[i][1]
        ans += li[i][0]*li[i][1]
    else:
        ans += li[i][0]*M
        print(ans)
        exit()


Measured memory_bytes: 21608
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<pair<string, int>, int>> SP(N);
	for (int i = 0; i < N; ++i) {
		cin >> SP[i].first.first >> SP[i].first.second;
		SP[i].second = i + 1;
	}
	sort(SP.begin(), SP.end(), [](pair<pair<string, int>, int>& a, pair<pair<string, int>, int>& b)->bool {
		if (a.first.first == b.first.first) return a.first.second > b.first.second;
		return a.first.first < b.first.first;
	});
	for (pair<pair<string, int>, int>& i : SP) cout << i.second << endl;
}

Measured memory_bytes: 256
import sys
import re
import random
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def solve():
    n, x, m = getList()

    visited = [-1] * (m+1)
    acc = [-1] * (m+1)
    tmp = x
    tmpsum = 0
    index = 0
    while True:
        # print(tmp)
        if visited[tmp] >= 0:
            cycle = index - visited[tmp]
            issyu = tmpsum - acc[tmp]
            outofcycle = index - 1
            ans = tmpsum
            cyclestart = tmp
            break

        visited[tmp] = index
        acc[tmp] = tmpsum
        tmpsum += tmp
        tmp = (tmp ** 2) % m
        index += 1
        if index == n:
            print(tmpsum)
            return

    # print("cycle ", cycle, issyu, cyclestart, outofcycle, ans)
    ans += ((n - outofcycle - 1) // cycle) * issyu


    tmp = cyclestart
    for i in range((n - outofcycle - 1) % cycle):
        ans += tmp
        tmp = (tmp ** 2) % m

    print(ans)
    # 16243 over




def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

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

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

int h_max = 0;
int ans = 0;
for (int i = 0; i < N; i++) {
    if (H[i] - h_max >= 0) {
        h_max = H[i];
        ans++;
    }
}
cout << ans << endl;
}

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

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, u, w, N, M;
	scanf("%d %d", &N, &M);
	
	int *indeg = (int*)malloc(sizeof(int) * (N + 1));
	list **adj = (list**)malloc(sizeof(list*) * (N + 1)), *d = (list*)malloc(sizeof(list) * (N + M - 1));	
	for (i = 1; i <= N; i++) {
		indeg[i] = 0;
		adj[i] = NULL;
	}
	for (i = 0; i < N + M - 1; i++) {
		scanf("%d %d", &u, &w);
		d[i].v = w;
		d[i].next = adj[u];
		adj[u] = &(d[i]);
		indeg[w]++;
	}
	
	int par[100001] = {}, q[100001], head, tail;
	list *p;
	for (i = 1; i <= N; i++) if (indeg[i] == 0) break;
	q[0] = i;
	par[i] = 0;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			indeg[w]--;
			if (indeg[w] == 0) {
				par[w] = u;
				q[tail++] = w;
			}
		}
	}
	
	for (i = 1; i <= N; i++) printf("%d\n", par[i]);
	fflush(stdout);
	return 0;
}

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

int main(){
	string S;
	cin >> S;
	int ans=0,tmp=0;
	for(int i=0;i<S.size();i++){
		if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T'){
			tmp++;
		}
		else{
			ans=max(ans,tmp);
			tmp=0;
		}
	}
	ans=max(ans,tmp);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>

using namespace std;

#define MAX 200002

int n;

vector<long long int> v;

multiset<long long int> mt;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		v.push_back(a);
		mt.insert(a);
	}
	int ans = 0;
	while (mt.size()) {
		long long int a = (*mt.rbegin());
		mt.erase(mt.lower_bound(a));
		long long int cur = 1LL;
		while (cur <= a) {
			cur *= 2LL;
		}
		if (mt.count(cur - a)) {
			ans++;
			mt.erase(mt.lower_bound(cur - a));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11248
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int n;
	long long ans = 0;
	cin >> n;

	vector<int> a(n+1);

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

	for(int i = 1; i < n+1; i++){
		int tmp = a[i];
		if(a[tmp] == i){
			ans++;
		}
	}

	cout << ans/2 << endl;


	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	int x;
	cin >> x;
	x ^= 1;

	cout << x << endl;
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int n = 0;
		int k = 0;
		ArrayList<Integer> anser = new ArrayList<>();

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();
		k = scan.nextInt();

		while(n>=k) {
			anser.add(n%k);
			n=n/k;
		}

		if(n<k) {
			anser.add(n);
		}
		System.out.println(anser.size());
	}

}


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

int main() {
  int n;
  cin >> n;
  vector<int> b(n);
  for(int i=0;i<n;i++) cin >> b[i];
  vector<int> ans(n);
  bool yes = true;
  for(int k=n-1;k>=0;k--) {
    int added = 0;
    for(int i=0;i<b.size();i++) {
      if(i+1 == b[i]) added = b[i]; 
    }
    if(added != 0) {
      ans[k] = added;
      b.erase(b.begin()+added-1);
    } else {
      yes = false;
      break;
    }
  }

  if(!yes) cout << -1 << endl;
  else {
    for(int i=0;i<n;i++) cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(a)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define chmax(a,b) (a) = max((a),(b))
#define pb push_back
#define sz size()
using namespace std;
typedef vector<int> vi;

//Strong Connected Component Decomposition
struct StronglyConnectedComponet{
  //input & auxiliary
  int V;
  vector<vi> G, rG;
  vi order;

  //output
  int sccV;
  vector<vi> sccG, group;
  vi sccID;

  StronglyConnectedComponet(const vector<vi> &graph){
    G = graph; V = G.sz; rG.resize(V);
    rep(i,V)rG[i].clear();
    rep(i,V)for(int to : G[i])rG[to].pb(i);

    vi use(V,0);
    order.clear();
    rep(i,V)if(!use[i])fdfs(i,use);

    use = vi(V,0); sccID.resize(V);
    sccV = 0;
    rrep(i,order.sz)if(!use[order[i]])rdfs(order[i],sccV++,use);

    group.resize(sccV);
    rep(i,V)group[sccID[i]].pb(i);

    sccG.resize(sccV);
    rep(i,V)for(int to : G[i]){
      if(sccID[i]!=sccID[to])sccG[sccID[i]].pb(sccID[to]);
    }
    rep(i,sccV){
      sort(all(sccG[i]));
      sccG[i].erase(unique(all(sccG[i])),sccG[i].end());
    }
  }

  void fdfs(int v, vi &use){
    use[v] = 1;
    for(int to : G[v])if(!use[to])fdfs(to,use);
    order.push_back(v);
  }

  void rdfs(int v,int k, vi &use){
    use[v] = 1; sccID[v] = k;
    for(int to : rG[v])if(!use[to])rdfs(to,k,use);
  }
};

int main(){
  int n1,m1;
  cin >> n1 >> m1;
  vector<char> c1(n1);
  rep(i,n1)cin >> c1[i];
  vector<vi> g1(n1);
  rep(i,m1){
    int a,b;
    cin >> a >> b; a--; b--;
    g1[a].pb(b);
  }
  StronglyConnectedComponet scc1(g1);

  int n2,m2;
  cin >> n2 >> m2;
  vector<char> c2(n2);
  rep(i,n2)cin >> c2[i];
  vector<vi> g2(n2);
  rep(i,m2){
    int a,b;
    cin >> a >> b; a--; b--;
    g2[a].pb(b);
  }
  StronglyConnectedComponet scc2(g2);

  set<char> loop1, loop2;
  rep(i,scc1.sccV){
    if(scc1.group[i].sz>1){
      for(int v : scc1.group[i])loop1.insert(c1[v]);
    }
  }
  rep(i,scc2.sccV){
    if(scc2.group[i].sz>1){
      for(int v : scc2.group[i])loop2.insert(c2[v]);
    }
  }
  for(int a : loop1){
    if(loop2.count(a)){
      cout << -1 << endl;
      return 0;
    }
  }

  int ans = 0;
  vector<vi> dp(scc1.sccV,vi(scc2.sccV,0));
  rep(i,scc1.sccV)rep(j,scc2.sccV){
    for(int v : scc1.sccG[i])chmax(dp[v][j], dp[i][j]);
    for(int v : scc2.sccG[j])chmax(dp[i][v], dp[i][j]);

    if(scc1.group[i].sz==1 && scc2.group[j].sz == 1){
      if(c1[scc1.group[i][0]] == c2[scc2.group[j][0]]){
	chmax(ans,dp[i][j]+1);
	for(int v : scc1.sccG[i])for(int u : scc2.sccG[j]){
	    chmax(dp[v][u], dp[i][j] + 1);
	  }
      }
    }else if(scc2.group[j].sz == 1){
      bool f = false;
      for(int a : scc1.group[i]){
	if(c2[scc2.group[j][0]] == c1[a])f = true;
      }
      
      if(f){
	chmax(ans,dp[i][j]+1);
	for(int v : scc2.sccG[j])chmax(dp[i][v], dp[i][j] + 1);
      }
    }else if(scc1.group[i].sz == 1){
      bool f = false;
      for(int b : scc2.group[j]){
	if(c1[scc1.group[i][0]] == c2[b])f = true;
      }
      
      if(f){
	chmax(ans,dp[i][j]+1);
	for(int v : scc1.sccG[i])chmax(dp[v][j], dp[i][j] + 1);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1532
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value )
      A[k] = L[i++];
    else
      A[k] = R[j++];
  }
}

void mergeSort(struct Card A[], int left, int right) {
  int mid;
  if ( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(struct Card A[], int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ )
    if ( A[j].value <= x.value ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

void quickSort(struct Card A[], int p, int r) {
  int q;
  if ( p < r ) {
    q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, 0, n);
  quickSort(B, 0, n - 1);

  for ( i = 0; i < n; i++ )
    // マージソートとクイックソートの結果を比べる
    if ( A[i].suit != B[i].suit ) stable = 0;

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ )
    printf("%c %d\n", B[i].suit, B[i].value);

  return 0;
}


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

using namespace std;

struct edge
{
    int destination;
    long long weight;

    edge()
    {
        destination = 0, weight = 0;
    }

    edge(int d, long long w)
    {
        destination = d;
        weight = w;
    }
};

const int MAX_N = 1e5;
vector <edge> tree[MAX_N];
vector <long long> weight_till(MAX_N, 0);

void dfs(int v, int parent)
{
    for(int i = 0; i < tree[v].size(); i++)
    {
        int child = tree[v][i].destination;
        long long child_weight = tree[v][i].weight;

        if(child != parent)
        {
            weight_till[child] = child_weight + weight_till[v];

            dfs(child, v);
        }
    }
}

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

    int no_of_edges = no_of_vertices - 1;
    for(int i = 1; i <= no_of_edges    ; i++)
    {
        int u, v, weight;
        cin >> u >> v >> weight;

        tree[u].push_back(edge(v, weight));
        tree[v].push_back(edge(u, weight));
    }

    int root;
    for(int i = 1; i <= no_of_vertices; i++)
        if(tree[i].size() == 1)
            root = i;

    weight_till[root] = 0;
    dfs(root, 0);

    for(int i = 1; i <= no_of_vertices; i++)
        cout << weight_till[i]%2 << endl;

    return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0){
        cout << 0 << endl;
        return 0;
    }
    vll d = {a, b, c};
    VSORT(d);
    cout << d[0] * d[1] << endl;
    return 0;
}

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

int main(void){
  
  char s[100][10],t[100][10];
  int n,m;
  int i,j;
  int y,ans=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    
    scanf("%s",s[i]);
    
  }
  
  scanf("%d",&m);
  
  for(i=0;i<m;i++){
    
    scanf("%s",t[i]);
    
  }
  
  for(i=0;i<n;i++){
    
    y=0;
    
    for(j=0;j<n;j++){
      
      if(strcmp(s[i],s[j])==0){
        
        y++;
        
      }
      
    }
      
    for(j=0;j<m;j++){ 
    
 	  if(strcmp(s[i],t[j])==0){
        
        y--;
        
      }
      
    }
    
    if(y>ans){
      
      ans=y;
      
    }
    
  }
    
  printf("%d",ans);
    
  return 0;
    
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

const int INF = 1 << 24;

int main(void){
    int n; cin >> n;

    while(n --){
        double x1, y1, x2, y2, x3, y3;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

        double a1 = 2 * (x2 - x1), a2 = 2 * (x3 - x1),
               b1 = 2 * (y2 - y1), b2 = 2 * (y3 - y1),
               c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2,
               c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3,
               px = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1),
               py = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1),
               r = sqrt(pow(x1 - px, 2) + pow(y1 - py, 2));

        printf("%.3f %.3f %.3f\n", px, py, r);
    }
 
    return 0;
}

Measured memory_bytes: 1244
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  string c;
  cin>>c;
  b--;
  if(c[b]=='A')
    c[b]='a';
  else if(c[b]=='B')
    c[b]='b';
  else if(c[b]=='C')
    c[b]='c';
  cout<<c<<endl;
}

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

int check(char s[100], char c){
	for(int i=0 ; i < 100 ; i++ ){
		if( s[i] == c ) return i;
	}
	return -1;
}

int main(){
	int n;
	cin >> n;
	for(int i=0 ; i< n ; i++ ){
		string s;
		cin >> s;

		char f[100];
		for(int i=0 ; i < 100 ; i++ )
			f[i] = '*';
		f[50] = s[0];

		for(int i=1 ; i < s.size() ; i+=3 ){
			char prev = s[i-1];
			char next = s[i+2];
			int j = check( f , prev );
			if( s[i] == '-' ){
				f[j+1] = next;
			}
			if( s[i] == '<' ){
				f[j-1] = next;
			}
		}
		for(int i=0 ; i < 100 ; i++ ){
			if( f[i] != '*' ){
				cout << f[i];
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int n;
	cin >> n;
	vector<ll> a(n),b(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];

	const ll asum = accumulate(begin(a),end(a),0LL);
	const ll bsum = accumulate(begin(b),end(b),0LL);
	
	if(asum < bsum) {
		puts("-1");
		return 0;
	}

	ll rest = asum - bsum;

	vector<ll> ary(n);
	rep(i,n) ary[i] = a[i] - b[i];
	sort(begin(ary), end(ary));

	ll ans = n;
	rep(i,n){
		if(ary[i] < 0) continue;
		if(ary[i] > rest) continue;
		rest -= ary[i], ans--;
	}

	cout << ans << endl;

	return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

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

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

    int N, M, Q;
    std::cin >> N >> M >> Q;

    vector<vector<int>> table(N + 1, vector<int>(N + 1, 0));
    REP(i, M) {
        int l, r;
        std::cin >> l >> r;
        table[l][r]++;
    }

    REP(flag, 2) {
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= N; j++) {
                table[i][j] += flag ? table[i - 1][j] : table[i][j - 1];
            }
        }
    }

    REP(i, Q) {
        int p, q;
        std::cin >> p >> q;
        std::cout << table[q][q] + table[p - 1][p - 1] -
                     table[p - 1][q] - table[q][p - 1] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();
        String t = in.next();
        for(int i=0; i<n; i++) {
            System.out.print(s.charAt(i));
            System.out.print(t.charAt(i));
        }
        System.out.println();
    }
}


Measured memory_bytes: 23252
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    bool can_buy = false;
    for (int i = 0; i <= n / 7; i++) {
        if ((n - i * 7) % 4 == 0) {
            can_buy = true;
        }
    }
    cout << (can_buy ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
def includeOddInArray? arr
  arr.any? {|num| num.odd? }
end


N = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)

counter = 0
loop do
  if includeOddInArray? arr
    break
  end
  
  arr.map!{|num| num/2} 
  counter += 1
end

puts counter

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> x(m);
	rep(i, m) cin >> x[i];
	sort(x.begin(), x.end());
	vector<int> a(m - 1);
	rep(i, m - 1) a[i] = x[i + 1] - x[i];
	sort(a.begin(), a.end());
	int sum = 0;
	rep(i, m - n) sum += a[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int cmp(const void *n1, const void *n2)
{
    return *(int *)n1 - *(int *)n2;
}

int main(void)
{

    double sumLength;

    scanf("%lf", &sumLength);

    double volume = pow((sumLength / 3), 3);

    printf("%lf", volume);

}

Measured memory_bytes: 128
H , W , K = map(int,input().split())
cake = [list(input()) for _ in range(H)]
strawberry = []
strawberry_num = 1
visited = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if cake[i][j] == "#":
            strawberry.append([i,j])
            visited[i][j] = strawberry_num
            strawberry_num += 1
 
for i in range(H):
    now = 0
    for j in range(W):
        if cake[i][j] == '#':
            now = visited[i][j]
        elif now != 0 and cake[i][j] == "." and visited[i][j] == 0:
            visited[i][j] = now
    now = 0
 
    for j in range(W-1 , -1 , -1):
        if cake[i][j] == '#':
            now = visited[i][j]
        elif now != 0 and cake[i][j] == "." and visited[i][j] == 0:
            visited[i][j] = now
 
 
for i in range(1,H):
    if visited[i][0] == 0:
        visited[i] = visited[i-1]
for i in range(H-2,-1,-1):
    if visited[i][0] == 0:
        visited[i] = visited[i+1]
for i in visited:
    print(*i)

Measured memory_bytes: 19412
n = int(input())
lst = []
for _ in range(n):
    lst.append(sorted(list(input())))
lst.sort()
ans = 0
count = 0
for i in range(n-1):
    if lst[i] == lst[i+1]:
        count += 1
    else:
        ans += count*(count+1)//2
        count = 0
ans += count*(count+1)//2
print(ans)

Measured memory_bytes: 24652
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
	int a, e, k;
	scanf("%d%d%d%d%d%d", &a, &e, &e, &e, &e, &k);
	if (e - a <= k)
		puts("Yay!");
	else
		puts(":(");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		map<string,ll> m;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			sort(s.begin(),s.end());
			m[s]++;
		}
		ll ans=0;
		for(auto i:m){
			ans+=((i.second)*(i.second-1))/2;
		}
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 11464
N, K = map(int, input().split())
ss = [[0] * (4*K+2) for i in range(4*K+2)]


def query(x1, x2, y1, y2):
    return ss[x2][y2] - ss[x2][y1] - ss[x1][y2] + ss[x1][y1]


def main():
    for i in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == 'W':
            y += K

        x, y = x % (2*K) + 1, y % (2*K) + 1

        ss[x][y] += 1
        ss[x+2*K][y] += 1
        ss[x][y+2*K] += 1
        ss[x+2*K][y+2*K] += 1

    for i in range(4*K+2):
        for j in range(4*K+1):
            ss[i][j+1] += ss[i][j]

    for i in range(4*K+1):
        for j in range(4*K+2):
            ss[i+1][j] += ss[i][j]

    ans = 0
    for i in range(1, 2*K+1):
        for j in range(1, 2*K+1):
            ans = max(ans, query(i, i+K, j, j+K)+query(i+K, i+2*K, j+K, j+2*K))

    print(ans)


if __name__ == '__main__':
    main()


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... Args> void rd(Args&... args) {((cin >> args), ...);}
template<typename... Args> void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ans=0;
    ll x;
    cin>>x;
    ll n=100;
    while(n<x){
        n=n*1.01;
        ans++;
    }
    cout<<ans;
    return 0;
}



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


int main() {
    string O, E, res;
    cin >> O >> E;

    for (int i = 0; i < O.length(); i++) {
      res += O[i];
      if (i + 1 > E.length())
        break;
      res += E[i];
    }

    cout << res << endl;

    return 0;
}


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

#define FIO                     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod                     1000000007
#define eps                     1e-9
#define setbits                 __builtin_popcount
#define gcd                     __gcd
#define rep(i,a,b)              for(int i=a;i<=b;i++)
#define repr(i,b,a)             for(int i=b;i>=a;i--)
#define forn(i,n)               for(int i=0;i<n;i++)
#define all(a)                  a.begin(), a.end()
#define in(a,b)                 ( (b).find(a) != (b).end())
#define pb                      push_back
#define fill(a,v)               memset(a, v, sizeof a)
#define endl                    "\n"
#define ff                      first
#define ss                      second
#define mp                      make_pair
#define minin(a)                *min_element (all(a))
#define maxin(a)                *max_element(all(a))
#define asort(c)                sort(all(c))
#define dsort(c)                sort(all(c), greater<int>()) 
#define PI                      3.14159265358979323846
#define int                     long long
typedef  vector<int>                 vi;
typedef  pair<int, int>              ii;
typedef  vector<ii>                 vii;
typedef  set<int>                    si;
typedef  map<int, int>              mii;
typedef  long double                 ld;

bool fun(int n)
{
  si a;
  while(n)
  {
    a.insert(n%10);
    n/=10;
  }
  return a.size()==1;
}

clock_t time_p=clock();
void timer()
{
    time_p=clock()-time_p;
    cerr<<"Execution Time: "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

int32_t main()
{
  FIO
 
   int x,ans,ess=-1,oss=-1;
   int n;
   cin>>n;
   mii odd,even;
   si allsm;

   rep(i,1,n)
   {
    cin>>x;
    allsm.insert(x);
    if(i&1)
      odd[x]++;
    else
      even[x]++;
   }

   if(allsm.size()==1)
   {
     cout<<n/2; return 0;
   }
   int omx=-1,emx=-1;
   int oid,eid;
   for(auto i: odd)
   {
     if(i.ss>omx)
     {
       omx=i.ss;
       oid=i.ff;
     }
   }
   for(auto i: even)
   {
     if(i.ss>emx)
     {
      emx=i.ss;
      eid=i.ff;
     }
   }
   for(auto i: even)
   {
     if(i.ff!=eid)
       ess=max(ess,i.ss);
   }
   for(auto i: odd)
   {
     if(i.ff!=oid)
      oss=max(oss,i.ss);
   }
   if(eid==oid)
   {
     if(emx+oss>omx+ess)
      ans=(n/2-emx)+(n/2-oss);
     else
      ans=(n/2-omx)+(n/2-ess);
   }
   else
     ans=(n/2-emx)+(n/2-omx);
      
   cout<<ans;
  timer();
  return 0;
}  

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

int main() {
    int n, m, k, a, ans = 0;
    cin >> n >> m;
    int A[30] = {0};
    for(int i = 0; i < n; ++i) {
        cin >> k;
        for(int j = 0; j < k; ++j) {
            cin >> a;
            a--;
            A[a]++;
        }
    }
    for(int i = 0; i < 30; ++i) {
        if(A[i] == n) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
int main() {
    
    int n;
    cin>>n;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
        cin>>vec[i];
    }
    int ac=0, tle=0, wa=0, re=0;
    for(int i=0; i<n; i++){
        if(vec[i]=="AC"){
            ac++;
        }
        else if(vec[i]=="WA"){
            wa++;
        }
        else if(vec[i]=="TLE"){
            tle++;
        }
        else{
            re++;
        }
    }

    cout<< "AC "<<"x "<<ac<<endl;
    cout<< "WA "<<"x "<<wa<<endl;
    cout<< "TLE "<<"x "<<tle<<endl;
    cout<< "RE "<<"x "<<re<<endl;



}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll V[105];
ll U[105];

ll dp[105][10005];

int main()
{
    ll N, W;
    cin >> N >> W;
    REP(i, N)
    {
        cin >> V[i] >> U[i];
    }
    memset(dp, 0, sizeof(dp));
    REP(i, N)
    {
        REP(j, W + 1)
        {
            dp[i + 1][j] = dp[i][j];
            if (j - U[i] >= 0)
                dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j - U[i]] + V[i]);
        }
    }

    ll max = 0;
    REP(i, W + 1)
    {
        max = std::max(max, dp[N][i]);
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 11308
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    vector<int> A(N); 
    map<int,ll> m;
    repp(i,0,N) {
        cin >> A[i];
        m[A[i]]++;
    }
    ll all = 0;
    for(auto x: m) {
        all += x.second * (x.second - 1) / 2;
    }
    repp(i,0,N) {
        cout << all - (m[A[i]] * (m[A[i]] - 1) / 2) + ((m[A[i]] - 1) * (m[A[i]] - 2) / 2) << endl;
    }
}


Measured memory_bytes: 12160
import sys
sys.setrecursionlimit(10 ** 9)
N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append([b, c])
    G[b].append([a, c])

Q, K = map(int, input().split())
K -= 1
dist = [-1] * N
dist[K] = 0


def dfs(n):
    for v, c in G[n]:
        if dist[v] < 0:
            dist[v] = dist[n] + c
            dfs(v)


dfs(K)
for q in range(Q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    print(dist[x] + dist[y])


Measured memory_bytes: 137932
class DisjointSets:#Union-Find
    def __init__(self, n):
        self.nodes = [-1] * n #根にサイズを負の値で格納する。
    def find(self, i):
        if self.nodes[i] < 0: #値が負の場合は根
            return i
        else:
            self.nodes[i] = self.find(self.nodes[i]) #縮約
            return self.nodes[i]
    def unite(self, i, j):
        i = self.find(i)
        j = self.find(j)
        if i == j:
            return
        if self.nodes[i] > self.nodes[j]: #サイズ比較してiの方がサイズが大きいようにする
            i, j = j, i
        self.nodes[i] += self.nodes[j] #大きい方に小さい方を統合しサイズを登録する。
        self.nodes[j] = i # jの親はi
    
    def size(self, i): # 所属する集合の大きさを返す
        i = self.find(i)
        return -self.nodes[i]

n, q = map(int, input().split())
ds = DisjointSets(n)
ans = []
for _ in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        ds.unite(u, v)
    else:
        ans.append(1 if ds.find(u) == ds.find(v) else 0)
for x in ans:
    print(x)


Measured memory_bytes: 81064
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(){
	long long n, k, eq=0, eq2=0;
	scanf("%lld %lld", &n, &k);
	
	if (n%k==0)
		printf("0");
	else if(n<k){
		eq= k-n;
		if(eq<n)
			printf("%lld", eq);
		else
			printf("%lld", n);
	}
	else{
		eq2= n%k;
		printf("%lld", k-eq2);
	}
	printf("\n");
    return 0;
}

Measured memory_bytes: 128
h,w,k=map(int,input().split())
c=[[0]*w for i in range(h)]
d=[[0]*w for i in range(h)]
ans=0
for i in range(h):
    a=input()
    for j in range(w):
        c[i][j]=a[j]
for i in range(2**(h+w)):
    for m in range(h):
        for n in range(w):
            d[m][n]=c[m][n]
    for j in range(h):
        if (i >> j)&1:
            for x in range(w):
                d[j][x]="r"
    for j in range(h,w+h):
        if (i >> j)&1:
            for x in range(h):
                d[x][j-h]="r"
    f=0
    for q in range(h):
        for s in range(w):
            if d[q][s]=="#":
                f+=1
            
        
    if f==k:
        ans+=1
print(ans)

Measured memory_bytes: 9264
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int x = Integer.parseInt(br.readLine());

		int ans = 0;
		while (x >= 500) {
			x -= 500;
			ans += 1000;
		}

		while (x >= 5) {
			x -= 5;
			ans += 5;
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 25044