akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int N;
bool num[100000];
vector<int>l;
int ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; i++)cin >> num[i];
	l.push_back(-1);
	for (int i = 0; i < N - 1; i++) {
		if (num[i] == num[i + 1])l.push_back(i);
	}
	l.push_back(N-1);
	
	int box = -1;
	for (int i = 1; i < l.size() - 2; i++) {
		ans = max(ans, l[i + 2] - l[i - 1]);
	}
	if (!ans)ans = N;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF=0x3f3f3f3f;
int N,M,X;
int ttt[13];
int a[13][13];
int v[13];
int minn=INF;
void dfs(int id,int *ans,int sum)
{
    //cout<<sum<<endl;
    int i;
    for(i=0; i<M; i++)
    {
        if(ans[i]<X) break;
    }
    if(i==M)
    {
        minn=min(minn,sum);
        return ;
    }
    if(id==N) return ;
    int anss[13];
    for(int i=0; i<M; i++)
        anss[i]=ans[i]+a[id][i];
    dfs(id+1,anss,sum+v[id]);
    dfs(id+1,ans,sum);
}
int main()
{
    cin>>N>>M>>X;
    for(int i=0; i<N; i++)
    {
        cin>>v[i];
        //cout<<v[i]<<endl;
        for(int j=0; j<M; j++) cin>>a[i][j];
    }
    dfs(0,ttt,0);
    if(minn==INF)
        cout<<-1<<endl;
    else
    cout<<minn<<endl;
    return 0;
}


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

int has[4];

int main()
{
    for (int i = 0; i < 3; i++) {
        int a, b; scanf("%d %d", &a, &b);
        has[a - 1]++;
        has[b - 1]++;
    }
    sort(has, has + 4);
    if (has[0] == 1 && has[1] == 1 && has[2] == 2 && has[3] == 2) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
function getChangeIndex(input, containText) {
  var index = -1;
  var cIndex = -1;

  for (var i = input.length - containText.length; i >= 0; i--) {
    if (input[i] !== containText[0] && input[i] !== '?') {
      // console.log(input[i]);
      // console.log(containText[0]);
      continue;
    }
    var slicedInput = input.slice(i, i + containText.length);
    // console.log({ slicedInput });

    var result = true;
    for (var j = 0; j < containText.length; j++) {
      if (slicedInput[j] !== containText[j] && slicedInput[j] !== '?') {
        // console.log(slicedInput[j], containText[j]);
        result = false;
        break;
      }
    }

    if (result) {
      index = i;
      break;
    }
  }
  // console.log(index);
  return index;
}

function solve(inputRaw) {
  var row = inputRaw.trim().split('\n');
  var input = row[0];
  var containText = row[1];

  var index = getChangeIndex(input, containText, 0);

  if (index >= 0) {
    var result = input.substr(0, index) + containText + input.substr(index + containText.length, input.length);
    result = result.split('?').join('a');
    return result;
  }

  return 'UNRESTORABLE';
}

console.log(solve(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 21064
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  string S;
  cin >> S;
  vector<char> S_odd;
  vector<char> S_even;
  for(int i=0; i<S.length(); ++i)
  {
    if(i%2)
      S_even.push_back(S[i]);
    else
      S_odd.push_back(S[i]);
  }

  int even_0=0;
  int even_1=0;
  int odd_0 =0;
  int odd_1 =0;
  for(char c : S_even)
  {
    if(c == '0')
      ++even_0;
    else
      ++even_1;
  }
  for(char c : S_odd)
  {
    if(c == '0')
      ++odd_0;
    else
      ++odd_1;
  }
  int cnt1 = even_0 + odd_1;
  int cnt2 = even_1 + odd_0;
  cout << (cnt1<cnt2?cnt1:cnt2) << endl;

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int A=0,B=0,C=0,D=0;
  int i=0;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  
  while(A>0 && C>0){
    if(i % 2 == 0){
      C = C - B;
    }
    else
      A = A - D;
    i++;
  }
  if(C<=0)
    printf("Yes");
  else if(A <= 0)
    printf("No");
  
  return 0;
}

Measured memory_bytes: 1728
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.nextLine();
        HashMap<Integer, HashMap<Integer, HashMap<Integer, Integer>>> bs = new HashMap<>();
        IntStream.rangeClosed(1, 4)
                 .forEach(b -> {
                     HashMap<Integer, HashMap<Integer, Integer>> fs = new HashMap<>();
                     IntStream.rangeClosed(1, 3)
                              .forEach(f -> {
                                  HashMap<Integer, Integer> rs = new HashMap<>();
                                  IntStream.rangeClosed(1, 10)
                                           .forEach(r -> {
                                               rs.put(r, 0);
                                           });
                                  fs.put(f, rs);
                              });
                     bs.put(b, fs);
                 });
        while(sc.hasNext()) {
            List<Integer> b_f_r_n = Stream.of(sc.nextLine().split(" "))
                                          .map(Integer::parseInt)
                                          .collect(Collectors.toList());
            int n = bs.get(b_f_r_n.get(0)).get(b_f_r_n.get(1)).get(b_f_r_n.get(2));
            bs.get(b_f_r_n.get(0)).get(b_f_r_n.get(1)).put(b_f_r_n.get(2), n + b_f_r_n.get(3));
        }
        bs.forEach((b, floors) -> {
            floors.forEach((f, rooms) -> {
                rooms.forEach((r, n) -> {
                    System.out.print(" " + n);
                });
                System.out.println();
            });
            if (b != 4) {
                System.out.println("####################");
            }
        });
    }
}




Measured memory_bytes: 33676
#include <iostream>
using namespace std;
int main()
{
	int x1, x2, y1, y2, x3, x4, y3, y4;
	while (cin >> x1 >> y1 >> x2 >> y2)
	{
		int dx = x2 - x1, dy = y2 - y1;
		x3 = x2 - dy;
		y3 = y2 + dx;
		x4 = x3 - dx;
		y4 = y3 - dy;
		cout << x3 <<" "<< y3 <<" "<< x4<<" "<< y4 << endl;
	}
	return 0;
}

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

using namespace std;

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

	int a,b; cin >> a >> b;

	if(a+b == 15) cout << "+" << endl;
	else if(a*b == 15) cout << "*" << endl;
	else cout << "x" << endl;	

	return 0;

}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  long long int n,k;
  cin>>n>>k;
  cout<<(long long int)pow(k-1,n-1)*k<<endl;
}
///////////////////////////

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

using ll = long long;


int main() {

    int n;
    ll k;
    scanf("%d %lld", &n, &k);
    vector<ll> a(n);

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

    ll cur = 0LL;
    for ( ll d = 60; d >= 0; --d) {
        ll b = (1LL << d);
        if ((cur ^ b) > k) continue;
        int zeros = 0;
        for (ll x : a) {
            if ((x & b) == 0) {
                ++zeros;
            }
        }

        int ones = n - zeros;
        // zeroの方が多いならビットを立てる
        if (zeros > ones) {
            cur ^= b;
        }
    }

    ll res = 0LL;
    for (ll x : a) {
        res += (x ^ cur);
    }

    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,x[100],out=1,a;
  cin>>n;
  for(int i=0;i<n;i++)cin>>x[i];
  sort(x,x+n);
  a=x[n-1];
  for(int i=n-1;i>=0;i--){
    if(a>x[i]){
      out++;
      a=x[i];
    }
  }
  cout<<out<<endl;
}

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


int main(void) {

int n;
cin >> n;

vector<int> v(n);


	for (int unsigned i = 0; i < v.size(); i++){
	cin >> v[i];
	}


	for (int unsigned i =0; i < v.size(); i++){
	cout<< v[n-i-1];
		if (i == n - 1){
		cout << endl;
		}
		else{
			cout << " ";
		}
	}

//system("pause");
return 0;
}

Measured memory_bytes: 1196
X,N = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
  print(X)
elif N == 1:
  if p[0] == X:
    print(X-1)
  else:
    print(X)
else:
  ans = float('inf')
  for z in range(0,p[0]):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  for i in range(N-1):
    for z in range(p[i]+1,p[i+1]):
      if (ans-X)**2 > (z-X)**2 :
      	ans = z
  for z in range(p[-1]+1,102):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  print(ans)

Measured memory_bytes: 9080
def solve(n, h, a):
    size = 1 << ((n + 1) - 1).bit_length()  # 元の配列サイズ以上の最小の二冪 == 最下段
    # 高さに対する美しさの最大値なので、高さ[0,n]の(n+1)要素に対して、segを考える
    seg = [0] * (size * 2 - 1)

    def update(seg, k, x):
        k += size - 1
        seg[k] = x  # 値を更新する
        while k > 0:
            k = (k - 1) // 2  # 親のindex
            seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2])

    def get(seg, a, b, k=0, l=0, r=-1):
        # [a,b)区間の処理結果を返す
        # 注目区間[l,r)
        if r < 0:
            r = size

        if r <= a or b <= l:
            return 0
        # 区間が重ならない

        if a <= l and r <= b:
            return seg[k]
        # 完全被覆

        m = (l + r) // 2
        return max(get(seg, a, b, k * 2 + 1, l, m), get(seg, a, b, k * 2 + 2, m, r))
        # 部分被覆

    for h_, a_ in zip(h, a):
        update(seg, h_, get(seg, 0, h_) + a_)
        # 1回あたり更新するのは1箇所だから、iを状態にもつ必要はなくて、配列を使い回すことができる
        # 区間maxが高速に計算できればいいから、セグメント木を使えばできる
    return get(seg, 0, n + 1)


if __name__ == '__main__':
    import sys

    input = sys.stdin.readline

    n = int(input())
    h = tuple(map(int, input().split()))
    a = tuple(map(int, input().split()))
    print(solve(n, h, a))

# https://kyopro-friends.hatenablog.com/entry/2019/01/12/231035


Measured memory_bytes: 125776
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

#define MOD 1000000007
#define INT_MAX

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

	int l = n - m + 1;
	for (int i = 0; i < l; i++) {
		for (int j = 0; j < l; j++) {
			int cnt = 0;
			for (int x = 0; x < m; x++) {
				for (int y = 0; y < m; y++) {
					if (a[x + i][y + j] == b[x][y]) {
						cnt++;
					}
				}
			}
			if (cnt == m * m) {
				cout << "Yes" << endl;
				return (0);
			}
		}
	}
	cout << "No" << endl;

	return (0);
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    int mx_left = 0, mn_right = INT_MAX;
    for(int i = 0; i < m; i++){
        int l,r;
        cin >> l >> r;
        mx_left = max(l, mx_left);
        mn_right = min(mn_right, r);
    }
    cout << max(0, mn_right - mx_left + 1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}


Measured memory_bytes: 11936
# ref https://www.owlog.org/abc128/

import sys
sys.setrecursionlimit(10 ** 7)
from bisect import bisect_left

def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())

    # 通行止めの地点 (X,S,T)
    closure = []
    for _ in range(N):
        start, end, pos = map(int, input().split())
        closure.append((pos, start, end))

    # 座標の昇順でソート
    closure.sort()

    D = [int(input()) for _ in range(Q)]

    # 各人の止まる地点
    ans = [-1] * Q
    # その人が既に止まっているか
    skip = [-1] * Q

    # 各通行止めの地点で止まる人を探索
    # Dが範囲[S-X,T-X)にあるときに止まる
    for pos, start, end in closure:
        # 一番左の人のインデックス
        left = bisect_left(D, start - pos)
        # 一番右の人のインデックス
        right = bisect_left(D, end - pos)

        while left < right:
            if skip[left] == -1:
                # 停止座標を記録
                ans[left] = pos
                # 右端の人のインデックスを記録
                skip[left] = right
                left += 1
            else:
                # [left,skip[left])にいる人は既に止まっている
                left = skip[left]

    return ans


if __name__ == '__main__':
    print(*main(), sep='\n')

Measured memory_bytes: 104924
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
 
    int n;
    cin >> n;
    int c=1;
    vector<int> ans;
   
    while(c*5+1<=55555){
        for(int i=2;i<=(c*5+1)/2;i++){
            if((c*5+1)%i==0)break;
            if(i==(c*5+1)/2)ans.push_back(c*5+1);
        }
        c++;
    }
    
    rep(i,n){
        cout << ans[i];
        if(i!=n-1)cout << ' ';
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-3
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
const int N=105;
//Code begin...

int main ()
{
    int n, mi=INF, ma=0, x;
    scanf("%d",&n);
    FOR(i,1,n) {
        scanf("%d",&x);
        mi=min(mi,x); ma=max(ma,x);
    }
    printf("%d\n",ma-mi);
    return 0;
}


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

int main() {
  int n;
  ll x, s = 0, s2 = 0, mod = 1000000007;
  cin >> n;
  rep(i, n) {
    cin >> x;
    s += x;
    s2 += (x * x)%mod;
  }
  s = s % mod;
  s2 = s2 % mod;
  x = s*s - s2;
  if(x < 0) x += mod;
  ll ans = x % mod;
  if(ans % 2 == 1) ans += mod;
  cout << ans/2 << endl;
}

Measured memory_bytes: 3644
#include<stdio.h>
 int main()
 {
     long long int h,n,i,x; 
     scanf("%lld %lld",&h,&n);
     for(i=0;i<n;i++)
     {
         scanf("%lld",&x); h=h-x;
         }
     if(h<=0)
     printf("Yes\n"); else printf("No\n"); return 0; }

Measured memory_bytes: 128
N,P=map(int,input().split())
Q=[0]*(10**6+1)

i=2

if N==1:
  print(P)
  exit()

while 1:
  if P==1 or i>=10**6:
    break
  if P%i==0:
    P//=i
    Q[i]+=1
    i=2
  else:
    i+=1
#print(Q[:20])
#print(list(map(lambda x: x//N,Q)))
Q=list(map(lambda x: x//N,Q))

ans=1
for i,q in enumerate(Q):
  if q:
    ans*=i**q
print(ans)

Measured memory_bytes: 18852
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(n*n*n);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  string s, t;
  cin >> s >> t;

  int ans = t.size();

  for(int i=0; i<=s.size()-t.size(); ++i){
    int cnt = 0;
    for(int j=0; j<t.size(); ++j){
      if(t[j] != s[i+j]) cnt++;
    }
    ans = min(ans, cnt);
  }

  cout << ans << endl;
}

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

int main() {
  long long A,B,C,K,X=0;
  cin >> A >> B >> C >> K;
  for(long long i=0;i<A; i++){
    X++;
    K--;
    if(K == 0){
      cout << X << endl;
      return 0;
    }
  }
  for(long long i=0;i<B; i++){
    K--;
    if(K == 0){
      cout << X << endl;
      return 0;
    }
  }
  for(long long i=0; i<C; i++){
    X--;
    K--;
    if(K == 0){
      cout << X << endl;
      return 0;
    }
  }
  cout << X << endl;
}


Measured memory_bytes: 3628
using AtCoderBeginnerContest158.Questions;
using AtCoderBeginnerContest158.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest158.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nab = inputStream.ReadLongArray();
            var n = nab[0];
            var a = nab[1];
            var b = nab[2];
            var balls = a + b;

            var div = n / balls;
            var mod = n % balls;
            yield return a * div + Math.Min(mod, a);
        }
    }
}


namespace AtCoderBeginnerContest158
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest158.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest158.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

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

    map<int, int> A;
    REP(i,n){
        int tmp;
        cin >> tmp;
        A[tmp]++;
    }
    int ans=0;
    for(auto x : A)
        if(x.first <= x.second) ans+=x.second-x.first;
        else ans+=x.second;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;*/
    
    int n,q,c=0;cin>>n>>q;
    string s;cin>>s;
    vector<int> cum1(n+1),cum2(n+1);
    for(int i=1;i<n;i++){
        cum1[i+1]=cum1[i]+(s[i]=='C'&&s[i-1]=='A'?1:0);
        if(s[i]=='C'&&s[i-1]=='A'){
            c++;
            cum2[i+1]=c;
            cum2[i]=c;
        }
        else {
            cum2[i+1]=c;
        }
    }
    while(q--){
        int l,r;cin>>l>>r;
        int x=cum1[r]-cum2[l-1];
        cout<<x<<"\n";
    }

    /*#ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
    return 0;
}

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

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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
using mint = modint998244353;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 998244353LL;

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

mint ten[200005],one[200005];

struct S{
    mint a;
    int len;
};

S op(S x,S y){
    return S{x.a*ten[y.len]+y.a,x.len+y.len};
}

S e(){
    return S{0,0};
}

S mapping(mint f,S x){
    if(f==0) return x;
    return S{one[x.len]*f,x.len};
}

mint composition(mint a,mint b){
    if(a==0) return b;
    return a;
}

mint id(){
    return 0;
}


int main(){
    ll N,Q;
    cin>>N>>Q;
    ten[0] = (mint)1;
    rep(i,200004) {
        ten[i+1] = ten[i] * 10;
    }
    one[0] = 0;
    rep(i,200004){
        one[i+1] += ten[i]+one[i];
    }
    lazy_segtree<S,op,e,mint,mapping,composition,id> seg(N);
    rep(i,N) {
        seg.set(i,S{1,1});
    }
    rep(i,Q){
        int l,r,d;
        cin>>l>>r>>d;
        l--;
        seg.apply(l,r,d);
        printf("%d\n",seg.all_prod().a.val());
    }
}


Measured memory_bytes: 11480
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<62;
const double eps=1e-9;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int n;cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	int ans=0;
	for(int i=0;i<n;i++){
		if(i+1==a[i]){
			ans++;
			if(i<n-1)swap(a[i],a[i+1]);
		}
	}
	cout<<ans<<endl;
}

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

alias sread = () => readln.chomp();
long bignum = 1_000_000_007;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

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;
    }
}

auto manhattan(long x1, long y1, long x2, long y2)
{
    return abs(y2 - y1) + abs(x2 - x1);
}

void main()
{
    auto n = lread();
    long t_prev, x_prev, y_prev;
    bool travel = true;
    foreach (_; 0 .. n)
    {
        long t, x, y;
        scan(t, x, y);
        auto limit = t - t_prev;
        auto m_dist = manhattan(x_prev, y_prev, x, y);
        limit -= m_dist;
        if(limit < 0 || limit % 2)
            travel = false;
        
        t_prev = t;
        x_prev = x;
        y_prev = y;
    }
    if(travel)
        writeln("Yes");
    else
        writeln("No");
}

Measured memory_bytes: 1404
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let main() =
    let [| N; M |] = reada int
    let acs = Array.zeroCreate N
    let mutable ac = 0
    let mutable wa = 0
    let was = Array.zeroCreate N
    for i in 0 .. M - 1 do
        let [| p; s |] = reada string
        let p = Convert.ToInt32(p) - 1
        match s with
        | "AC" ->
            if acs.[p] |> not then
                acs.[p] <- true
                ac <- ac + 1
                wa <- wa + was.[p]
        | "WA" -> was.[p] <- was.[p] + 1
        | _ -> failwith "hoge"

    sprintf "%d %d" ac wa |> puts
    ()

main()
writer.Close()


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  ll c[52][52];
  rep(i, 52) rep(j, 52) c[i][j] = 0;
  c[0][0] = 1;
  for(int i = 1; i <= 50; ++i) {
    c[i][0] = c[i][i] = 1;
    for(int j = 1; j < i; ++j) c[i][j] = c[i-1][j]+c[i-1][j-1];
  }
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  sort(ALL(v));
  double ave = 0;
  rep(i, a) ave += v[n-1-i];
  ave /= a;
  int max_s = distance(lower_bound(ALL(v), v[n-1]), v.end());
  printf("%0.10f\n", ave);
  if(max_s < a) {
    vector<ll> use;
    rep(i, a) use.push_back(v[n-1-i]);
    sort(ALL(use));
    int m = distance(lower_bound(ALL(use), use.front()), upper_bound(ALL(use), use.front()));
    int r = distance(lower_bound(ALL(v), use.front()), upper_bound(ALL(v), use.front()));
    cout << c[r][m] << endl;
  }
  else {
    ll num = 0;
    for(int i = a; i <= min(b, max_s); ++i) num += c[max_s][i];
    cout << num << endl;
  }
}

Measured memory_bytes: 3800
words = lambda t : list(map(t, input().split()))
n = int(input())
a = words(int)

i = 1
j = n-2
left = a[0]
right = a[-1]
while i <= j:
    if left >= right:
        right += a[j]
        j -= 1
    else:
        left += a[i]
        i += 1

print(abs(left-right))


Measured memory_bytes: 88912
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  vector<int> x(n),y(n);
  for(int i=0; i<n; ++i) cin>>x[i];
  y=x; sort(y.begin(),y.end()); int z=(n-1)/2;
  for(int i=0; i<n; ++i){
    int m=lower_bound(y.begin(),y.end(),x[i])-y.begin();
    if(z<m) cout<<y[z]<<endl; else cout<<y[z+1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 4776
# https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_c
# 直感的には大きい小さいを交互に並べれば良さそうだが...?

# Nが偶数なら交互でok
# Nが奇数なら、短い方を真ん中に入れれば良い

# 1 5 7 10
# 1 10 5 7 →16# 最後に行くに連れ差は少なくなってく
# 1 7 5 10 →13# 差がマイルドになるのでは?

# ソートしたとき一番最初と一番最後は必ず差が最大。
# それ以外の選び方をした場合差はそれより必ず小さくなるので、ソートの端から選んでいくのが最適だとわかる。
# しかし最後に関しては差が小さく微妙。実は中央値を先頭に付け足したほうが良い。

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

A.sort()


# もしNが偶数のとき
if N & 1 == 0:
    now = A[N // 2]
    ans = 0
    for i in range(N // 2):
        for idx in [i, -(i + 1)]:
            if idx == -N // 2:
                break
            ans += abs(now - A[idx])
            now = A[idx]
    print(ans)
else:  # Nが奇数のとき
    # med = A[N // 2]
    # med_score = max(A[0] - med, A[-1] - med)

    now = A[N // 2]
    ans1 = 0
    for i in range(N // 2):
        for idx in [i, -(i + 1)]:
            ans1 += abs(now - A[idx])
            now = A[idx]

    now = A[N // 2]
    ans2 = 0
    for i in range(N // 2):
        for idx in [-(i + 1), i]:
            ans2 += abs(now - A[idx])
            now = A[idx]
    # print(ans1, ans2)
    print(max(ans1, ans2))


Measured memory_bytes: 7516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int edpos[200010],n;
ll num[200010],ans=0;
string s;
int main()
{
	cin>>s;
	n=s.size();
	s=' '+s;
	for(int i=1;i<=n;++i) {
		int tmppos=i-1,tmp=0;
		while(tmppos<=n) {
			++tmppos;
			if(tmppos>n) {
				edpos[i]=0;
				break;
			}
			tmp=tmp*10+s[tmppos]-'0';
			if(tmp%2019==0) {
				edpos[i]=tmppos;
				break;
			}
			tmp%=2019;
		}
	}
	for(int i=n;i>=1;--i) {
		if(edpos[i]!=0) num[i]=1+num[edpos[i]+1];
		ans+=num[i];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 6060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

ll patty(ll N, ll X){
    if(N==0) return 1;
    if(X==1) return 0;
    ll MAXIM=pow(2, N+2)-3;
    ll NEXT=pow(2, N)-1;
    if(X==MAXIM) return NEXT*2+1;
    if(X==MAXIM/2+1) return NEXT+1;
    if(X<MAXIM/2+1) return patty(N-1, X-1);
    else return NEXT+1+patty(N-1, X-(MAXIM/2+1));
}

int main(void){
    ll N, X;
    cin>>N>>X;
    cout<<patty(N, X)<<endl;
    return 0;
}


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

int main ()
{
    string str;
    map<char,int> n;
    n['A'] = 1; n['C'] = n['B'] = 0;
    while (cin >> str) {
        int p = n[str[0]];
        n[str[0]] = n[str[2]];
        n[str[2]] = p;
    }
    for (char i = 'A'; i < 'D'; i++) {
        if (n[i] == 1) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1180
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

#define iter(i, n) forw(i, 1, n)
#define forw(i, a, b) for (int i = a; i <= b; ++i)

typedef long long i64;
#define NR 201000

typedef pair<i64, i64> pii;
#define fi first
#define se second
int n, lc[NR], rc[NR], fw[NR];
vector<pii> vec[NR];
i64 lim;

void dfs(int x) {
//	printf("d %d %d %d\n", x, lc[x], rc[x]);
	if (lc[x] == 0) {
		vec[x].push_back(pii(0, 0));
		return;
	}

	int i = lc[x], j = rc[x];
	dfs(i);
	dfs(j);

	if (vec[i].size() > vec[j].size()) swap(i, j);

	vector<pii> tmp; vec[x].clear();

	for (pii p : vec[i]) {
		int index = lower_bound(vec[j].begin(), vec[j].end(), pii(lim - p.se - fw[i] - fw[j] + 1, 0)) - vec[j].begin();

	//		printf("!!%lld %lld %d\n", lim, lim - p.se - fw[i] - fw[j] + 1, index);
		if (index > 0) {
			--index;
			tmp.push_back(pii(p.fi + fw[i], vec[j][index].se + fw[j]));
			tmp.push_back(pii(vec[j][index].se + fw[j], p.fi + fw[i]));
		}
	}

	sort(tmp.begin(), tmp.end());
	i64 lst = 1e12;
	for (pii p : tmp) if (p.se < lst) vec[x].push_back(p), lst = p.se;
}

bool check(i64 l) {
	lim = l;
	dfs(1);
	return !vec[1].empty();	
}

int main() {
	scanf("%d", &n);
	forw(i, 2, n) {
		int fa;
		scanf("%d%d", &fa, &fw[i]);
		if (lc[fa]) rc[fa] = i;
		else lc[fa] = i;
	}

	i64 l = 0, r = 1e11;
	for (; l < r;) {
		i64 mid = (l + r) / 2;

		if (check(mid)) r = mid;
		else l = mid + 1;
	}

	printf("%lld\n", l);
	return 0;
}

Measured memory_bytes: 95492
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    string s;
    cin >> s;
    int win=0;
    rep(i,s.size()){
        if(s.at(i) == 'o') win++;
    }
    if(win+7 >= s.size()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.lang.StringBuilder

fun main(arr:Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!!.map { it } }
    val posList = mutableListOf<Pos>()
    (0 until h).forEach {
        val row = it
        posList.addAll((0 until w).map {a-> Pos(row, a, w, map) })
    }
    val saitan = (0 until posList.size).map { (0 until posList.size).map { 800 }.toMutableList() }
    for(i in posList.indices) {
        for(j in posList.indices) {
            for(k in posList.indices) {
                if(posList[j].isSame(posList[k])) {
                    saitan[j][k] = 0
                }
                if(posList[j].isNear(posList[k])) {
                    saitan[j][k] = 1
                }
                if(saitan[j][i] + saitan[i][k] < saitan[j][k]) {
                    saitan[j][k] = saitan[j][i] + saitan[i][k]
                }
            }
        }
    }
    var ans = 0
    for(row in saitan) {
        for(col in row) {
            if(col >= 800) {
                continue
            }
            if(col == 0) {
                continue
            }
            ans = Math.max(ans, col)
        }
    }
    println(ans)

}

class Pos(val row:Int, val col:Int, val maxCol:Int, val map:List<List<Char>>) {
    val index = row*maxCol+col
    fun isSame(target:Pos):Boolean {
        return this.row == target.row && this.col == target.col && map[row][col] == '.'
    }
    fun isNear(target: Pos):Boolean {
        if(this.isSame(target)) {
            return false
        }
        if(map[row][col] != '.' || map[target.row][target.col] != '.') {
            return false
        }
        if(this.row == target.row) {
            return Math.abs(this.col - target.col) == 1
        }
        if(this.col == target.col) {
            return Math.abs(this.row - target.row) == 1
        }
        return false
    }
}


Measured memory_bytes: 48596
from operator import itemgetter

N, K = map(int, input().split())
TD = [list(map(int, input().split())) for _ in range(N)]

TD.sort(key=itemgetter(1), reverse=True)

remain = []
removable = []
used = [False for _ in range(N+1)]
val = 0
S = 0
for i, (t, d) in enumerate(TD):
    if i < K:
        S += d
        if not used[t]:
            val += 1
        else:
            removable.append(d)
        used[t] = True
    else:
        if not used[t]:
            remain.append(d)
            used[t] = True

S += val**2
removable.sort()

delta = 0
ans = S
for k, r in enumerate(remain):
    if k >= len(removable):
        break
    val += 1
    delta += r - removable[k] + 2*val - 1
    ans = max(ans, S+delta)
print(ans)

Measured memory_bytes: 29156
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
vector<int> vec[200010];
int cnt1, cnt2;
int d[200010];
bool bl[200010];
int ans1 = 1, ans2 = 2, ans3 = 3;

void bfs() {
	queue<P> que;
	que.push({ 1,0 });
	cnt1++;
	d[1] = 0;
	bl[1] = true;
	while (!que.empty()) {
		P p = que.front(); que.pop();
		int v = p.first;
		for (int i = 0; i < (int)vec[v].size(); i++) {
			if (bl[vec[v][i]])continue;
			if (p.second == 1)cnt1++;
			else cnt2++;
			d[vec[v][i]] = 1 - p.second;
			bl[vec[v][i]] = true;
			que.push({ vec[v][i],1 - p.second });
		}
	}
}

signed main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	bfs();
	int x = (n + 2) / 3;
	if (x <= cnt1 && x <= cnt2) {
		for (int i = 1; i <= n; i++) {
			if (!d[i]) {
				if (ans1 <= n) {
					cout << ans1 << " ";
					ans1 += 3;
				}
				else {
					cout << ans3 << " ";
					ans3 += 3;
				}
			}
			else {
				if (ans2 <= n) {
					cout << ans2 << " ";
					ans2 += 3;
				}
				else {
					cout << ans3 << " ";
					ans3 += 3;
				}
			}
		}
		cout << endl;
	}
	else if (cnt1 < x) {
		for (int i = 1; i <= n; i++) {
			if (!d[i]) {
				cout << ans3 << " ";
				ans3 += 3;
			}
			else {
				if (ans1 <= n) {
					cout << ans1 << " ";
					ans1 += 3;
				}
				else if (ans2 <= n) {
					cout << ans2 << " ";
					ans2 += 3;
				}
				else {
					cout << ans3 << " ";
					ans3 += 3;
				}
			}
		}
		cout << endl;
	}
	else {
		for (int i = 1; i <= n; i++) {
			if (!d[i]) {
				if (ans1 <= n) {
					cout << ans1 << " ";
					ans1 += 3;
				}
				else if (ans2 <= n) {
					cout << ans2 << " ";
					ans2 += 3;
				}
				else {
					cout << ans3 << " ";
					ans3 += 3;
				}
			}
			else {
				cout << ans3 << " ";
				ans3 += 3;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 17000
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define all(vv) (vv).begin(), (vv).end()
#define rep(ii, jj, ll, ss) for(int ii = jj; ii < ll; ii += ss)
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0;
#define get(vv, times) for(int ii = 0; ii < times; ++ii) {int jj; cin >> jj; (vv).pb(jj);}

int n;
set <int> v;

int32_t main() {
	cin >> n;
	rep(i, 0, n, 1) {
		int x; cin >> x;
		v.insert(x);
	}
	cout << v.size();
}

Measured memory_bytes: 3556
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
using namespace std;

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

int main(){
    int n,m; cin >> n >> m;
    vector<int> v(m); rep(i,m) cin >> v[i];
    if(n >= m){cout << 0 << endl; return 0;}
    sort(v.begin(),v.end());
    vector<int> dif; rep(i,m-1) dif.push_back(v[i+1] -v[i]);
    sort(dif.begin(),dif.end(), greater<int>());
    long long int sum = 0;
    rep(i,n-1) sum = sum + dif[i];
    cout << v[m-1] - v[0] - sum << endl;
    return 0;
}

Measured memory_bytes: 1276
import itertools

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

list_ = list(range(1, n + 1))

def turn_num(list_num, arr, m):
    for num ,v in enumerate(itertools.permutations(list_num, m)):
        if arr == list(v):
            res = num + 1
            break
    return res

ans = abs(turn_num(list_, p, n) - turn_num(list_, q, n))

print(ans)

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] S = sc.next().toCharArray();
		int[] bl = new int[N+1];
		for(int i = 1; i <= N; i++) {
			bl[i] = bl[i-1];
			if(S[i-1] == '#')
				bl[i]++;
		}
		int ans = Math.min(N - bl[N], bl[N]);
		for(int i = 1; i <= N; i++) {
			int black = bl[N]-bl[i];
			int white = N-bl[N]-(i-bl[i]);
			if(black > white) {
				ans = Math.min(ans, bl[i] + white);
			}
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 29988
#include <algorithm>
#include <iostream>
#include <string>

static inline int countChangeNum(char c1, char c2, char c3) {
  if (c1 == c2 && c2 == c3) {
    return 0;
  }
  
  if (c1 != c2 && c2 != c3 && c3 != c1) {
    return 2;
  }
  
  return 1;
}

int main(void)
{
  using namespace std;

  int N;
  string A, B, C;

  std::cin >> N >> A >> B >> C;

  int op = 0;

  for (int i=0; i<N; i++) {
    char c1 = A[i];
    char c2 = B[i];
    char c3 = C[i];
    op += countChangeNum(c1, c2, c3);
  }

  std::cout << op << std::endl;

  return 0;
}


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

int main(void) {
	int N;
	cin >> N;
	vector <int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	vector <int> B = A;
	sort(B.begin(), B.end());

	for (int i = 0; i < N; i++) {
		if (B[N-1]==A[i]) {
			cout << B[N-2] << endl;
		} else {
			cout << B[N-1] << endl;
		}
	}
  return 0;
}


Measured memory_bytes: 3200
#define F(I,H) x=0;for(I=H;I--;x+='.'-s[i][j]);if(x)
char s[100][101];h;r[100],R,c[100],C,i,j,x;
main(w){scanf("%d%d",&h,&w);for(i=h;i--;){scanf("%s",s[i]);
F(j,w)r[R++]=i;}
for(j=w;j--;){F(i,h)c[C++]=j;}
for(i=0;i<R;i++){for(j=C;j--;)putchar(s[r[i]][c[j]]);puts("");}
}


Measured memory_bytes: 128
using System;
using System.Linq;

class SimultaneousEquation 
{
    static void Main()
    {
        var q =
            from se in GetProblems().Select( _ => _.Split( ' ' ).Select( double.Parse ) )
            let a = se.Skip( 0 ).First()
            let b = se.Skip( 1 ).First()
            let c = se.Skip( 2 ).First()
            let d = se.Skip( 3 ).First()
            let e = se.Skip( 4 ).First()
            let f = se.Skip( 5 ).First()
            let x = ( c * e - f * b ) / ( a * e - d * b )
            let y = ( c - a * x ) / b
            select string.Format( "{0:0.000} {1:0.000}\n", x, y );
        Console.Write( new string( q.SelectMany( _ => _ ).ToArray() ) );
    }

    static System.Collections.Generic.IEnumerable<string> GetProblems()
    {
        string buffer = "";
        while ( ( buffer = Console.ReadLine() ) != null )
            yield return buffer;
    }
}

Measured memory_bytes: 6328
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let c = (n + 999) / 1000;
    let ans = c * 1000 - n;
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
	int a;
	vector<int> v;
	while (cin >> a) {
		v.push_back(a);
	}
	sort(v.begin(), v.end(), greater<int>());
	
	cout << v[0] << "\n" << v[1] << "\n" << v[2] << "\n";
	return 0;
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  vi a(4);

  REP(i, 3) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x]++;
    a[y]++;
  }

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

  if (a[0] == 1 and a[1] == 1 and a[2] == 2 and a[3] == 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256