akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int64_t A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int P;
  int Q;
  
  int64_t M;
  
  if(B < 0) P = 0;
  else if(0 < A) P = 2;
  else P = 1;
  
  if(D < 0) Q = 0;
  else if(0 < C) Q = 2;
  else Q = 1;
  
  if(P == 0 && Q == 0) M = A * C;
  else if(P == 0 && Q == 1) M = A * C;
  else if(P == 0 && Q == 2) M = B * C;
  else if(P == 1 && Q == 0) M = A * C;
  else if(P == 1 && Q == 2) M = B * D;
  else if(P == 2 && Q == 0) M = A * D;
  else if(P == 2 && Q == 1) M = B * D;
  else if(P == 2 && Q == 2) M = B * D;
  else
  {
    int64_t X, Y;
    X = A * C;
    Y = B * D;
    if(X >= Y) M = X;
    else M = Y;
  }
  
  cout << M << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	static const ULL M = 1000000007;
	ULL X[100000];
	ULL fac[100001];
	ULL inv[100001];
	ULL dp[100000];

	void Solve() {
		ULL N; cin >> N;
		rep(i, N) cin >> X[i];
		fac[0] = 1;
		for (ULL i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % M;
		inv[1] = 1;
		for (ULL i = 2; i <= N; i++) inv[i] = (M - inv[M % i] * (M / i) % M) % M;
		ULL ans = 0;
		ULL G = 0;
		for (ULL i = 1; i < N; i++) {
			G = (G + inv[i]) % M;
			ans += (X[i] - X[i - 1]) * G;
			ans %= M;
		}
		ans *= fac[N - 1];
		ans %= M;
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 3328
#include<stdio.h>

int main()
{
    int N, M, X, A[101], x_to_zero=0, x_to_n=0, i;

    scanf("%d %d %d", &N, &M, &X);

    for(i=0; i<M; i++){
        scanf("%d", &A[i]);
    }

    for(i=0; i<M; i++){
        if(A[i]>X)
            x_to_n++;
        else
            x_to_zero++;
    }

    if(x_to_n<x_to_zero)
        printf("%d\n", x_to_n);
    else
        printf("%d\n", x_to_zero);

    return 0;
}


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

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

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

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int INF = 1<<29;

ll N, K;
vector <int> v;

bool check(ll c) {
    ll tmp = 0LL, cnt = K-1;
    rep(N, i) {
        if (v[i] > c) return false;
        if (tmp + v[i] > c) {
            cnt--;
            tmp = v[i];
        }
        else {
            tmp += v[i];
        }
        if (cnt < 0) return false;
    }
    return true;
}

void solve(void){
    cin >> N >> K;
    v.resize(N);
    rep(N, i) {
        cin >> v[i];
    }

    ll ok = INF, ng = 0LL;

    while(abs(ok-ng)>1) {
        ll mid = (ok + ng) / 2;
        if (check(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

}

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



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

void dfs(const vector<vector<int64_t>>& links, const vector<int64_t>& x,
         vector<int64_t>& out, int64_t cur, int64_t parent, int64_t counter) {
    counter += x[cur];
    out[cur] = counter;
    for (auto v : links[cur]) {
        if (v == parent) {
            continue;
        }

        dfs(links, x, out, v, cur, counter);
    }

    counter -= x[cur];
}

main() {
    int64_t n, q;
    cin >> n >> q;

    vector<vector<int64_t>> links(n);
    for (auto _ : irange(0L, n - 1)) {
        int64_t a, b;
        cin >> a >> b;
        --a;
        --b;
        links[a].push_back(b);
        links[b].push_back(a);
    }

    vector<int64_t> x(n);
    for (auto _ : irange(0L, q)) {
        int64_t p, xx;
        cin >> p >> xx;
        --p;
        x[p] += xx;
    }

    vector<int64_t> ans(n);
    dfs(links, x, ans, 0, -1, 0);

    auto delim = "";
    for (auto aa : ans) {
        cout << delim << aa;
        delim = " ";
    }
    cout << endl;
}

Measured memory_bytes: 32128
#include<cstdio>
#include<cstring>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
pair<int,int> l[MAXN],r[MAXN],id[MAXN];
bool used[MAXN];
int n;
ll ans=0;
bool cmp(pair<int,int> x,pair<int,int> y){
	return x>y;
}
ll goin(ll now,int x){
	if(now<id[x].first){
		ans+=id[x].first-now;
		now=id[x].first;
	}
	else if(now>id[x].second){
		ans+=now-id[x].second;
		now=id[x].second;	
	}
	return now;
}
int main(){
	SF("%d",&n);
	for(int i=1;i<=n;i++){
		SF("%d%d",&l[i].first,&r[i].first);	
		l[i].second=i;
		r[i].second=i;
		id[i].first=l[i].first;
		id[i].second=r[i].first;
	}
	sort(l+1,l+1+n,cmp);
	sort(r+1,r+1+n);
	bool flag=0;
	int cnta=1,cntb=1,las=0;
	for(int i=1;i<=n;i++){
		if(flag==0){
			while(used[l[cnta].second]==1)
				cnta++;
			used[l[cnta].second]=1;
			las=goin(las,l[cnta].second);
		}
		else{
			while(used[r[cntb].second]==1)
				cntb++;
			used[r[cntb].second]=1;
			las=goin(las,r[cntb].second);
		}
		flag^=1;
	}
	ll ans1=ans+abs(las);
	las=0;
	ans=0,cnta=1,cntb=1;
	flag=1;
	memset(used,0,sizeof used);
	for(int i=1;i<=n;i++){
		if(flag==0){
			while(used[l[cnta].second]==1)
				cnta++;
			used[l[cnta].second]=1;
			las=goin(las,l[cnta].second);
		}
		else{
			while(used[r[cntb].second]==1)
				cntb++;
			used[r[cntb].second]=1;
			las=goin(las,r[cntb].second);
		}
		flag^=1;
	}
	ll ans2=ans+abs(las);
	PF("%lld",max(ans1,ans2));
}

Measured memory_bytes: 2688
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

unsigned N;
vector<vector<vector<double>>> dp; 
vector<int> vals(4, 0); 

double solution(int x, int y, int z)
{
  if (!x && !y && !z) 
  {
    return 0.0;
  }
  if (dp[x][y][z] != -1.0)
  {
    return dp[x][y][z];
  }
  double sum = N;
  if (x > 0) sum += x * solution(x-1, y, z); 
  if (y > 0) sum += y * solution(x+1, y-1, z); 
  if (z > 0) sum += z * solution(x, y+1, z-1);
  return dp[x][y][z] = sum / (x+y+z);
}

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

  std::cin >> N;
  dp = vector<vector<vector<double>>>(N+1, vector<vector<double>>(N+1, vector<double>(N+1, -1.0)));

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

  std::cout << std::setprecision(20) << solution(vals[1], vals[2], vals[3]);

  return 0;
}

Measured memory_bytes: 216960
#include <bits/stdc++.h> 
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define inrep(t) int t;cin>>t; while(t--)
#define pb push_back
#define mp make_pair 
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi; 
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;


int main(){
	ios_base::sync_with_stdio(false); 
	int n; 
	cin>>n; 
	int a[n]; 
	set<int> s; 
	reu(i,0,n) {
		cin>>a[i]; s.insert(a[i]); 
	}
	cout<<s.size(); 
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
vector<ll> making_list(ll m) {
	vector<ll> ret;
	for (ll i = 1; i*i <= m; i++) {
		if (m%i == 0) {
			ret.push_back(i);

			
			if (i*i != m) {
				ret.push_back(m / i);
				//cout << "work" << endl;
			}
		}
	}
	/*for (ll i = 0; i*i < ret.size(); i++) {
		cout << ret[i] <<"???"<< endl;
	}*/
	sort(begin(ret), end(ret));

	return ret;

	/*ll& n = m;
	vector< int64_t > ret;
	for (int64_t i = 1; i*i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	for (ll i = 0; i < ret.size(); i++) {
		cout << ret[i] << "???" << endl;
	}
	sort(begin(ret), end(ret));
	return (ret); */
}

int main() {
	ll answer = 0;
	ll n, m;
	cin >> n >> m;
	vector<ll> ret = making_list(m);
	for (int i = 0; i < ret.size(); i++) {
		if (m >= n * ret[i]) {
		    answer = ret[i];
		}

	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int isPrime(int n){
	int i;
	for(i=2;i*i<=n;i++){
		if(n%i==0)return 0;
	}
	return 1;
}

int main(void){
	int n,i,t;
	scanf("%d",&n);
	printf("%d:",n);
	t=n;
	if(isPrime(n))printf(" %d",n);
	else{
		for(i=2;i*i<=t;i++){
			if(isPrime(i)){
				while(n%i==0){
					printf(" %d",i);
					n/=i;
				}
			}
		}
		if(n>1)printf(" %d",n);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 608
from itertools import permutations


def main():
    length = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))

    permutation_li = list(permutations([i for i in range(1, length + 1)]))

    p_index = permutation_li.index(p)
    q_index = permutation_li.index(q)

    print(abs(p_index - q_index))


if __name__ == '__main__':
    main()

Measured memory_bytes: 44912
//recursion
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (ll)(1e15); 
int n;
vector<vector<ll>> memo;
vector<ll> a;
// lay max nhat 
ll dp(int l,int r){
    if (l == r) return memo[l][r] = a[l];
    ll &ans = memo[l][r];
    if (ans > -INF) return ans;
    ans = max(a[l] - dp(l + 1,r),a[r] - dp(l,r - 1));
    return ans;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    memo.resize(n,vector<ll> (n,-INF));
    cout << dp(0,n - 1);
    return 0;
}

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

int main()
{
	string s, s1 = "CODEFESTIVAL2016";;
	cin >> s;

	
	int cnt = 0;
	for (int i = 0; i < 16; i++) {
		if (s.at(i) != s1.at(i)) cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
INF = 10**9+7

if abs(n-m) > 1:
    print(0)
else:
    nf = 1
    for i in range(1, n+1):
        nf *= i
        nf %= INF

    mf = 1
    for i in range(1, m+1):
        mf *= i
        mf %= INF

    if n == m:
        print(nf * mf * 2 % INF)
    else:
        print(nf * mf % INF)

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

using namespace std;

int main()
{	
	int flag = 0;
	string s, p;
	cin >> s >> p;
	string t = s + s;
	for (int i = 0;i < t.length();++i) {
		if (t.substr(i, p.length()) == p) flag = 1;
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3184
import sys

inf = float('inf')

def solve():
    N, M = map(int, sys.stdin.readline().split())

    cost = [[inf]*N for i in range(N)]
    for u in range(N):
        cost[u][u] = 0

    for i in range(M):
        si, ti, di = map(int, sys.stdin.readline().split())
        cost[si][ti] = di

    res = WarshallFloyd(N, cost)

    if res is None:
        print('NEGATIVE CYCLE')
    else:
        for i in range(N):
            print(*[res[i][j] if res[i][j] < inf else 'INF' for j in range(N)])


def WarshallFloyd(N, cost):
    dist = [[inf]*N for i in range(N)]

    for i in range(N):
        for j in range(N):
            dist[i][j] = cost[i][j]

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    if any(dist[i][i] < 0 for i in range(N)):
        return None
    else:
        return dist

if __name__ == '__main__':
    solve()

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

int cnt[100001];
vector<vector<int>>fight;

int solve(int n) {
	int ans = cnt[n];
	vector<int>win;
	for (int i = 0; i < fight[n].size(); i++) {
		win.push_back(solve(fight[n][i]));
	}
	sort(win.begin(), win.end());
	reverse(win.begin(), win.end());
	for (int i = 0; i < fight[n].size(); i++) {
		win[i] += i + 1;
		ans = max(ans, win[i]);
	}

	return ans;
}

int main()
{
	int N; cin >> N;
	fight.resize(N+1);
	for (int i = 2; i <= N; i++) {
		int a;
		cin >> a;
		cnt[a]++;
		fight[a].push_back(i);
	}

	cout << solve(1) << endl;

    return 0;
}



Measured memory_bytes: 15488
n, k = list(map(int, input().strip().split()))

mm = list(map(int, input().strip().split()))

dp = [float('inf')] * n

dp[0] = 0

for i in range(n):
  for j in range(1, k+1): 
    if i + j < n:
      dp[i+j] = min(dp[i+j], dp[i] + abs(mm[i+j] - mm[i]))

print(dp[n-1])

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

int main(){
	int r,c,n,count=0,total=0;
	cin >> r >> c;
	int x[r+1][c+1]={};
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin >> n;
			x[i][j]=n;
		}
	}
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			count+= x[i][j];
		}
		x[i][c] = count;
		total += count;
		count=0;
	}
	for(int i=0;i<c;i++){
		for(int j=0;j<r;j++){
			count += x[j][i];
		}
		x[r][i]=count;
		count=0;
	}
	x[r][c]=total;
	
	for(int i=0;i<(r+1);i++){
		for(int j=0;j<c;j++){
			cout << x[i][j] << ' ';
		}
		cout << x[i][c] << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll days(ll y,ll m,ll d){
  if(m<3)y--,m+=12;
  return 365*y+y/4-y/100+y/400+(153*m+8)/5+d;
}
void ymd(ll day,ll &y,ll &m,ll &d){
  ll lo=-1,hi=1000000000,mid;
  while(lo+1<hi){
    mid=(lo+hi)/2;
    if(days(mid,12,31)<day)lo=mid;
    else hi=mid;
  }
  y=hi;
  for(m=1;m<12;m++)if(days(y,m+1,1)>day)break;
  d=day-days(y,m,0);
}

int main() {
  string s;
  ll y=days(2012,12,21);
  while(cin >> s && s!="#") {
    s+='.';
    ll n=s.size(),x=0;
    vector<ll> a;
    for(int i=0; i<n; i++) {
      if(s[i]=='.') {
        a.push_back(x);
        x=0;
      } else {
        x*=10;
        x+=s[i]-'0';
      }
    }
    if(a.size()==3) {
      x=days(a[0],a[1],a[2]);
      x=(x+1872000-y)%1872000;
      ll b[5],c=20*20*18*20;
      b[0]=x/c;x%=c;c/=20;
      b[1]=x/c;x%=c;c/=20;
      b[2]=x/c;x%=c;c/=18;
      b[3]=x/c;x%=c;c/=20;
      b[4]=x;
      for(int i=0;i<5;i++) {
        if(i) cout << '.';
        cout << b[i];
      }
      cout << endl;
    } else {
      x=a[0]*20*20*18*20+a[1]*20*18*20+a[2]*18*20+a[3]*20+a[4];
      x=x+y;
      ymd(x,a[0],a[1],a[2]);
      cout << a[0] << "." << a[1] << "." << a[2] << endl;
    }
  }
}


Measured memory_bytes: 3200
#include <stdio.h>
 
#define max 100
 
int main(){
  int i,j,num,min,minj,ans=0;
 
  int data[max][max],flag[max],d[max];
 
  scanf("%d",&num);
 
  for(i = 0 ; i < num ; i++){
    flag[i] = 0;
    d[i] = 2001;
  }
  d[0] = 0;
 
  for(i = 0 ; i < num ; i++){
    for(j = 0 ; j < num ; j++){
      scanf("%d",&data[i][j]);
    }
  }
 
  for(i = 0 ; i < num-1 ; i++){
    min = 2001;
     
    for(j = 0 ; j < num ; j++){
      if(d[j] < min && flag[j] == 0 ){
    min = d[j];
    minj = j;
      }
    }
    flag[minj] = 1;
    for(j = 0 ; j < num ; j++){
      if(data[minj][j] != -1 && data[minj][j] < d[j] && flag[j] ==0){
 
    d[j] = data[minj][j];
      }
    }
  }
  for(i = 0 ; i < num ; i++){
    ans += d[i];
  }
  printf("%d\n",ans);
 
  return 0;
 
}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  int a = (S[0]-'0');
  int b = (S[1]-'0');
   int c = (S[2]-'0');
   int d = (S[3]-'0');
  
  int A = 10*a + b;
  int B = 10*c + d;
  
  if (A >= 1 && A <= 12 && B >= 1 && B <= 12 ){cout << "AMBIGUOUS" << endl;}
    if (A >= 1 && A <= 12 && (B == 0 || B > 12)){cout << "MMYY" << endl;}
    if ((A == 0 || A > 12) && B >= 1 && B <= 12 ){cout << "YYMM" << endl;}
    if ((A == 0 || A > 12)  && (B == 0 || B > 12) ){cout << "NA" << endl;}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr long long INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

struct UnionFind{
    vector<int> par,r;

    //はじめに全てが根であるとしておく
    UnionFind(int N):par(N),r(N,1){iota(par.begin(),par.end(),0);}

    int root(int x){//根に当たるまで再帰で探す
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool same(int x,int y){//つながっているかどうか判定
        return par[x] == par[y];
    }

    int size(int x){ //根の大きさを判定する
        return r[root(x)];
    }

    void unite(int x, int y){//根が同じでなかったらつなげる
        x = root(x), y = root(y);
        if(x == y) return;
        if(r[x] < r[y]) swap(x,y); //値を小さいほうを根にする
        r[x] += r[y];
        par[y] = x;
        return;
    }
};


signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N,M;cin >> N >> M;
    int P[N];
    REP(i,N){
        cin >> P[i];--P[i];
    }
    UnionFind UF(N);
    int x,y;
    REP(i,M){
        cin >> x >> y;
        --x;--y;
        if(x > y) swap(x,y);
        UF.unite(x,y);
    }
    int ans = 0;
    REP(i,N){
		UF.root(P[i]);UF.root(i);
        if(UF.same(P[i],i)){;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
// inputに入力データ全体が入る
function Main(input) {
  input = input.split('\n');
  var answer;

  var good = []; 
  var bad = []; 
  var switched = false;
  var counts = {};
  var max = 0;
  // nums = nums.map((e) => parseInt(e));

  for (var i = 1; i < input.length; i++) {
    if (/\d/.test(input[i])) {
      switched = true;
      continue;
    }

    if (switched) {
      bad.push(input[i]);
    } else {
      good.push(input[i]);
    }
  }

  good.forEach(e => {
    if (counts[e]) {
      counts[e] += 1;
    } else {
      counts[e] = 1;
    }
  });

  bad.forEach(e => {
    if (counts[e]) {
      counts[e] -= 1;
    }
  });

  for (var key in counts) {
    if (counts[key] > max) {
      max = counts[key];
    }
  }



  // 出力
  console.log(max);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 22076
N = int(input())
S = [0] * N
for i in range(N):
    S[i] = int(input())

S.sort()
tmp = sum(S)

if tmp%10 == 0:
    for i in range(N):
        if S[i]%10 != 0:
            tmp -= S[i]
            break

if tmp%10 == 0:
    ans = 0
else:
    ans = tmp

print(ans)

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

int main() {
	int n;
	long long int mod = 1000000007;
	std::cin >> n;
	std::string s1, s2;
	std::cin >> s1 >> s2;

	std::string s3;
	for (int i = 0; i < n; i++) {
		if (s1[i] == s2[i]) {
			s3 += 'a';
		}
		else {
			s3 += 'b';
			i++;
		}
	}

	if (s3.size() == 1) {
		std::cout << (s3[0] == 'a' ? 3 : 6) << std::endl;
		return 0;
	}

	long long int ans = (s3[0] == 'a' ? 3 : 6);
	for (int i = 1; i < s3.size(); i++) {
		if (s3[i - 1] == 'a') {
			ans = (ans * 2) % mod;
		}
		else if (s3[i - 1] == 'b' && s3[i] == 'b') {
			ans = (ans * 3) % mod;
		}
	}

	std::cout << ans << std::endl;

	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD (ll)(1e9 + 7)
#define MAX (ll)(2e5 + 4)
#define INF (ll)(1e9 + 1)
using namespace std;
using ll =  long long;
using ld = long double;

int main () {
	string st;
	cin >> st;
	int n = st.size ();
	int ar[n + 1] = {}, pr = -2, val = 0;
	for (int i = 0; i < n; i++) {
		if (st[i] == '<') {
			if (i - 1 == pr) {
				ar[i] = max (ar[i], ++val);
			}
			else {
				val = 0;
				ar[i] = max (ar[i], val);
			}
			pr = i;
			if (i == n - 1) {
				ar[i + 1] = max (++val, ar[i + 1]);
			}
		}
		else if (pr == i - 1) {
			ar[i] = max (++val, ar[i]);
		}
	}
	pr = n + 2, val = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (st[i] == '>') {
			if (i + 1 == pr) {
				ar[i + 1] = max (ar[i + 1], ++val);
			}
			else {
				val = 0;
				ar[i + 1] = max (ar[i + 1], val);
			}
			pr = i;
			if (!i) {
				ar[i] = max (++val, ar[i]);
			}
		}
		else if (pr == i + 1) {
			ar[i + 1] = max (++val, ar[i + 1]);
		}
	}
	ll su = 0;
	for (int i = 0; i <= n; i++) {
		su += ar[i];
	}
	cout << su << "\n";
}


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

#define REP(i,n) for(int i=0;i<n;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 pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 999999999999

using namespace std;

#define int long long

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

	vector<int> a;
	REP(i, 3*n){
		int x;
		cin >> x;
		a.pb(x);
	}
	SORT(a);
	
	int ans=a[3*n-2];
	for(int i=2; i<=n; i++){
		ans+=a[3*n-2*i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 5872
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    while(cin>>s>>t)
    {
        int len=s.size(),count=0;
        for(auto i=0;i<len;i++)
        {
            if(s[i]!=t[i])
                count++;
        }
        cout<<count<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3852
//#pragma GCC optimize("-O3")
/*
				C++
				encoding: UTF-8
				Last Modified: 24/Nov/19 05:33:20 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		int                    long long
#define		ve                     vector
#define		pb                     push_back
#define		endl                   "\n"
#define		ff                     first
#define		ss                     second
#define		pii                    pair<int, int>
#define		len(v)                 (int)v.size()
#define		all(v)                 v.begin(), v.end()
#define		reset(a, b)            memset(a, b, sizeof(a));
#define		fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
    cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
    cout << t << " ";
    pr (u, args...);
}

// clang-format on


signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	string s;
	cin >> s;
	int ans = 7;
	if (s == "SUN") {
		ans -= 0;
	} else if (s == "MON") {
		ans -= 1;
	} else if (s == "TUE") {
		ans -= 2;
	} else if (s == "WED") {
		ans -= 3;
	} else if (s == "THU") {
		ans -= 4;
	} else if (s == "FRI") {
		ans -= 5;
	} else if (s == "SAT") {
		ans -= 6;
	}
	pr (ans);
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    set<int> s;
    for(int i=-2; i<n+2; ++i)
        s.insert(i);
    long long ans = 0;
    for(int i=0; i<n; ++i){
        int k = index[i];
        s.erase(k);
        auto it1 = s.upper_bound(k);
        auto it2 = it1;
        int r1 = *it1;
        int r2 = *++it1;
        int l1 = *--it2;
        int l2 = *--it2;
        if(r1 < n)
            ans += (r2 - r1) * (long long)(k - l1) * (i + 1);
        if(l1 >= 0)
            ans += (l1 - l2) * (long long)(r1 - k) * (i + 1);
        s.erase(k);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 10123;
char k[nax];
const int mod = 1e9 + 7;

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int main() {
    scanf("%s", k);
    int D;
    scanf("%d", &D);
    int len = strlen(k);
    vector<vector<int>> dp(D, vector<int>(2));
    // dp[sum][smaller_already] - the number of ways to choose digits so far
    // such that the sum of digits modulo D is 'sum' and 'smaller_already'
    // says whether we already chosen some digit smaller than in K
    dp[0][0] = 1;
    for(int where = 0; where < len; ++where) {
        vector<vector<int>> new_dp(D, vector<int>(2));
        for(int sum = 0; sum < D; ++sum) {
            for(bool sm_already : {false, true}) {
                for(int digit = 0; digit < 10; ++digit) {
                    if(digit > k[where] - '0' && !sm_already) {
                        break;
                    }
                    add_self(new_dp[(sum+digit)%D][sm_already || (digit < k[where]-'0')],
                        dp[sum][sm_already]);
                }
            }
        }
        dp = new_dp;
    }
    int answer = (dp[0][false] + dp[0][true]) % mod;
    --answer;
    if(answer == -1) {
        answer = mod - 1;
    }
    printf("%d\n", answer);
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
vector<int>gg;
int dp[100001];
int solve(int x)
{
  if(x>=gg.size())return INF;
  if(x==gg.size()-1)return 0;
  if(dp[x]!= -1)return dp[x];
  int ans = INF;
  ans = min(ans , abs(gg[x+2]-gg[x])+solve(x+2));
  ans = min(ans , abs(gg[x+1]-gg[x])+solve(x+1));
  return dp[x]=ans;
}
int main()
{
  // flash;
  int x;
  cin>>x;
  memset(dp,-1,sizeof dp);
  for (int i = 0; i < x; ++i)
  {
    int j;cin>>j;gg.pb(j);
  }
  cout<<solve(0);
  return 0;
}

Measured memory_bytes: 3448
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007


void solve(void)
{
  int N;
  cin>>N;
  int L;
  cin>>L;
  vector<string> vec(N);

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

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

  for (int i = 0; i < N; i++)
  {
    cout<<vec[i];
  }
  cout<<endl;
  
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

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

int main() {
  int k,s,ans=0;
  cin >> k >> s;
  int x=k,y=k,z=k;
  for (int i=k;i>=0;i--) {
    for (int j=k;j>=0;j--) {
      if (i+j>s || s-i-j>k) continue;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  string str;

  cin >> str;

  for (uint32_t i = 0; i < str.size(); i++) {
    if (str[i] == ',')
      cout << " ";
    else
      cout << str[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
 
const long long Inf = 2e18;
const long long mod = 998244353;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
long long ans = 0;
long long A[200005];

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> A[i];
	}
	sort(A + 1, A + n + 1);
	int cnt = n - 2;
	ans = A[n];
	for(int i = n - 1; i >= 1; i--)
	{
		if(cnt)
		{
			ans += A[i];
			cnt--;
		}
		if(cnt)
		{
			ans += A[i];
			cnt--;
		}
	}
	cout << ans;
}

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

#define SZ 200009

int main()
{
    int a, b, c, d;

    cin >> a >> b >> c >> d;
    while(a>0 && b>0){
        c-=b;
        if(c<=0){
            puts("Yes");
            break;
        }
        a-=d;
        if(a<=0){
            puts("No");
            break;
        }
    }

    return 0;
}
/**


*/


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n, d;
int x[10][10];
int ans = 0;

int main() {
    cin >> n >> d;
    rep(i,n) rep(j,d) cin >> x[i][j];
    rep(i,n) for (int j = i+1; j < n; j++) {
        int len = 0;
        rep(k,d) {
            len += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
        }
        bool ok = false;
        for (int k = 0; k*k <= len; k++) {
            if (k*k == len) ok = true; 
        }
        if (ok) ans++;
    }
    cout << ans << endl;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int ai, ao, at, aj, al, as, az;
	cin >> ai >> ao >> at >> aj >> al >> as >> az;
	int ans = ai / 2 * 2 + aj / 2 * 2 + al / 2 * 2;
	if (ai and aj and al) {
		ai--, aj--, al--;
		chmax(ans, ai / 2 *2+ aj / 2*2 + al / 2*2 + 3);
	}
	cout << ans + ao << endl;
	return 0;
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define eps 1e-9

pii A[100005];

multiset<int> se;

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

	int n, m, i, j, k, x, y, z;
	cin >> n >> m;
	for (i = 0; i < m; ++i) cin >> A[i].fi >> A[i].sc;
	sort(A, A+m);
	int ans = 0;
	j = 0;
	for (i = 1; i <= n; ++i) {
		if (se.find(i) != se.end()) {
			ans += 1;
			se.clear();
		}
		while (j < m && A[j].fi == i) se.insert(A[j++].sc);
	}
	cout << ans << endl;

	return 0;
}

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

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

    string s;
    cin >> s;

    if ( (s.at(2) == s.at(3)) && (s.at(4) == s.at(5)) ){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){
    int N;
    cin >> N;
    if (N%2==0){
        cout <<0.5<< endl;
    }
    else {
         cout << fixed << setprecision(10) << double (N/2+1) /double(N)  << endl;
    } 
    
   
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a_=[]
cnt=0
while(1):
     while(a):
          a__=a.pop()
          if a__%2==0:
               a_.append(a__//2)
               cnt+=1
     if not a_:
          break
     a=a_.copy()
     a_=[]
print(cnt)

Measured memory_bytes: 4148
from sys import stdin
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def combinations_with_replacement_count(n, r):
    return combinations_count(n + r - 1, r)


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

x = S // 3
y = S % 3
count = 0

for i in range(x):
    j = i + 1
    count = count + \
        combinations_with_replacement_count((S - (3 * j) + 1), i)

print(count % (10 ** 9 + 7))

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

typedef long long ll;
 
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a, a+n);
  int i=0, ans=0;
  while(i<n){
    int now = a[i];
    int cnt = 0;
    while(i<n && a[i]==now){
      cnt++;
      i++;
    }
    ans += cnt%2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s, c = s+j, c+1
        j+=1
    x[c][s]+=1

while 1:
    n, s = map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

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

ll N, M, Q;
vector<ll> A(50, 0), B(50, 0), C(50, 0), D(50, 0);
ll ans = 0;

ll dfs(vector<ll> V, int index) {
  vector<ll> V2 = V;
  ll ret = 0;
  if (index < N - 1) {
    for (ll i = V[index]; i <= M; i++) {
      V2[index + 1] = i;
      ret = max(ret, dfs(V2, index + 1));
    }
  } else {
    for (ll i = 0; i < Q; i++) {
      if (V[B[i]] - V[A[i]] == C[i]) ret += D[i];
    }
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N >> M >> Q;
  for (ll i = 0; i < Q; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    A[i]--, B[i]--;
  }
  vector<ll> V(N, 0);
  V[0] = 1;
  ans = dfs(V, 0);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll n, m, d;
    cin >> n >> m >> d;

    double ans = 0, a;

    if (d == 0) a = n;
    else a = 2 * (n-d);

    cout << a * (m-1) / n / n << endl;
}

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

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

  if(x == 1 || x == 2*n-1){
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  if(n == 2){
    for(int i=1; i<=3; i++) cout << i << " ";
    cout << endl;
    return 0;
  }

  int ans[2*n];
  bool used[2*n];
  memset(used, 0, sizeof(used));

  if(x != 2){
    ans[n-1] = x-1; ans[n] = x; ans[n+1] = x+1; ans[n+2] = x-2;
    used[x-1] = used[x] = used[x+1] = used[x-2] = true;
  }
  else{
    ans[n-1] = x+1; ans[n] = x; ans[n+1] = x-1; ans[n+2] = x+2;
    used[x+1] = used[x] = used[x-1] = used[x+2] = true;
  }

  int i = 1;
  for(int j=1; j<2*n; j++){
    if(n-1 <= j && j <= n+2) continue;
    while(used[i]) i++;
    
    ans[j] = i;
    i++;
  }

  for(int i=1; i< 2*n; i++) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <stdlib.h>
using namespace std;

long long int N, K, mod, n, a, b;

int main(){
	cin >> N >> K;
  	mod = N % K;
  	n = (N - mod)/K;
  	a = abs(N - n*K);
  	b = abs(N - (n+1)*K);
  	if (a < b){
    	cout << a;
    }else{
    	cout << b;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

int main() {
    ios::sync_with_stdio(false);
    ll n, x;
    cin >> n >> x;
    ll ans = n;
    ll y=n-x;
    for (;;) {
        if (x<y) swap(x, y);
        if (y==0) {
            break;
        }
        if (x%y==0) {
            ll k=x/y;
            ans += (2*k-1)*y;
            break;
        }
        ll k=(x-1)/y;
        ans += 2*k*y;
        x %= y;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int  long long int
#define mod 1000000000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t;cin>>t; rep(casn,1,t+1)
#define el cout<<"\n";
#define deci(n) int n; scanf("%lld",&n);
#define decs(n) string n; cin>>n;
#define sz(v) v.size()
#define repit(m) for(auto it=m.begin();it!=m.end();it++)
// #define find(m,i) (m.find(i)!=m.end())
// #define find(m,i) (m.find(i)==m.end())
#define cYES cout<<"YES\n";
#define cNO cout<<"NO\n";
#define ins insert
#define imax 1000000000000000000
#define imin -1000000000000000000
// #define NP 50000
//  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
//  IIITA
//SUNEET KUMAR -->  ਸੁਨੀਤ
 
// scanning numbers extremely fast/////////
void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
// ========================================
int power(int a,int x)
{
        a%=mod;
    int res=1;
    while(x>0)
    {
        if(x&1)
        res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int max(int a,int b)
{
    if(a>b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int min(int a,int b)
{
    if(a>b)
    {
        return b;
    }
    else
    {
        return a;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans%mod;
}
int modinverse(int a)
{
    return power(a,mod-2);
}
 
void nhi_degi()
{
    int n,m;cin>>n>>m;
    int sum=0,x;
    for(int i=1;i<=m;i++)
    {
        cin>>x;
        sum+=x;
    }
    if(sum>n)
    {
        cout<<-1;el
    }
    else
    {
        cout<<(n-sum);el
    }
}
signed main()
{
    // cases(t)
    // {
        nhi_degi();
    // }
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <stdio.h>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int mod = 998244353;
int n, m, dp[8], a;
char c;
ll ans = 1;

int main() {
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	cin >> n;
	dp[0] = n;
	for(int i = 1; i <= 3 * n; ++i) {
		cin >> c;
		a = (c == 'R' ? 1 : c == 'G' ? 2 : 4);
		if(dp[7 ^ a]) {
			ans = (ans * dp[7 ^ a]) % mod;
			--dp[7 ^ a], ++dp[7];
		}
		else {
			bool flag = false;
			for(int j = 1; j < 8; j <<= 1)
				if(j != a && dp[j]) {
					ans = (ans * dp[j]) % mod;
					++dp[j | a], --dp[j], flag = true;
					break;
				}
			if(!flag) {
				ans = (ans * dp[0]) % mod;
				--dp[0], ++dp[a];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

using namespace std;


int main() {
	int n;
	string s;
	int ans=0;
	cin>>n>>s;
	rep(i,n){
		if(s.substr(i,3)=="ABC"){
			ans++;
		}
	}
	cout<<ans<<endl;
}


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

int bubbleSort(int *array, int N) {
	int sortCount=0, min;
	for (int i=0; i<N-1; i++) {
		min = i;
		for (int j=i+1; j<N; j++) {
			if (array[min] > array[j]) {
				min = j;
			}
		}
		if (array[i] > array[min]) {
			int tmp = array[i];
			array[i] = array[min];
			array[min] = tmp;
			sortCount++;
		}
		
	}
	return sortCount;
}

int main(int argc, const char * argv[]) {
	int N, array[100], sortCount=0;
	cin >> N;
	for (int i=0; i<N; i++) {
		cin >> array[i];
	}
	sortCount = bubbleSort(array, N);
	for (int i=0; i<N; i++) {
		cout << array[i];
		if (i == N-1) {
			cout << endl;
		} else {
			cout << " ";
		}
	}
	cout << sortCount << endl;

	return 0;
}


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

static const double pi = 3.141592653589793;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
  double a, b, h, m;

  cin >> a >> b >> h >> m;
  double lhand = m * 360 / 60;
  double shand = (h * 60 + m) * 360 / (12 * 60);
  double c;
  if (lhand < shand) {
    c = shand - lhand;
  } else {
    c = lhand - shand;
  }
  cout << fixed << setprecision(20)
       << sqrt(a * a + b * b - 2 * a * b * cos(c * pi / 180)) << "\n";
}


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

int main() {
    int n;
    cin >> n;
    ve<int> a(4,0);
    rep(i,n){
        string s;
        cin >> s;
        if(s == "AC")a[0]++;
        if(s == "WA")a[1]++;
        if(s == "TLE")a[2]++;
        if(s == "RE")a[3]++;
    }
    
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

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

using namespace std;

int n, k; 
int w[100100];

// 最大積載量pのk台のトラックに詰める荷物の数
 long long check(long long p) {
    long long res = 0;
    rep(i, k) {
        long long s = 0;
        while(s + w[res] <= p) {
            s += w[res];
            ++res;
            if (res == n) return res;
        }
    }
    return res;
}

long long binarySerch() {
    long long ng = -1;
    long long ok = 100000 * 10000;
    while(abs(ok - ng) > 1) {
        long long mid = (ng + ok) / 2;
        if (check(mid) == n) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    cin >> n >> k;
    rep(i, n) cin >> w[i];
    cout << binarySerch() << endl;
}



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


int main(){
    int stack[199] = {0}, i = 0, j = 0;
    string order;
    getline(cin, order);
    
    while(order[i]){
        if (order[i] == '+'){
            //stackの上二つを取り出して処理
            j--;
            stack[j-1] = stack[j-1] + stack[j];
            stack[j] = 0;
        }else if(order[i] == '-'){
            //stackの上二つを取り出して処理
            j--;
            stack[j-1] = stack[j-1] - stack[j];
            stack[j] = 0;
        }else if(order[i] == '*'){
            //stackの上二つを取り出して処理
            j--;
            stack[j-1] = stack[j-1] * stack[j];
            stack[j] = 0;
        }else if(order[i] == ' '){
            
        }else{
            //数字だった場合
            //空白が来るまでループ
            while(order[i] != ' '){
                stack[j] = stack[j]*10 + (order[i] - '0');
                i++;
            }
            j++;
        }
        i++;
    }
    cout << stack[0] << endl;
    return 0;
}


Measured memory_bytes: 3172