akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
const int MAX = 101;
int A[MAX][MAX];

void construct(int h,int l,int n){
  assert(n&1);

  A[h+0][l+0]=l+1;
  A[h+0][l+1]=l+2;
  A[h+0][l+2]=l+0;

  A[h+1][l+0]=l+2;
  A[h+1][l+1]=l+0;
  A[h+1][l+2]=l+1;

  for(int i=3;i<n;i++){
    A[h+0][l+i]=l+0;
    A[h+1][l+i]=l+1;

    A[h+i-1][l+0]=l+i;
    A[h+i-1][l+1]=l+i;
  }

  if(n==3) return;
  construct(h+2,l+2,n-2);
}

void build(int h,int l1,int l2,int n){
  if(n==3){
    A[h+0][l1+0]=l2+1;
    A[h+0][l1+1]=l2+2;
    A[h+0][l1+2]=l2+0;
    A[h+0][l2+0]=l1+0;
    A[h+0][l2+1]=l1+1;
    A[h+0][l2+2]=l1+2;

    A[h+1][l1+0]=l2+2;
    A[h+1][l1+1]=l2+0;
    A[h+1][l1+2]=l2+1;
    A[h+1][l2+0]=l1+2;
    A[h+1][l2+1]=l1+0;
    A[h+1][l2+2]=l1+1;

    A[h+2][l1+0]=l2+0;
    A[h+2][l1+1]=l2+1;
    A[h+2][l1+2]=l2+2;
    A[h+2][l2+0]=l1+1;
    A[h+2][l2+1]=l1+2;
    A[h+2][l2+2]=l1+0;
    return;
  }

  A[h+0][l1+0]=l2+0;
  A[h+0][l1+1]=l2+1;
  A[h+0][l2+0]=l1+1;
  A[h+0][l2+1]=l1+0;

  A[h+1][l1+0]=l2+1;
  A[h+1][l1+1]=l2+0;
  A[h+1][l2+0]=l1+0;
  A[h+1][l2+1]=l1+1;

  for(int j=2;j<n;j++){
    A[h+j][l1+0]=l2+j;
    A[h+j][l1+1]=l2+j;
    A[h+j][l2+0]=l1+j;
    A[h+j][l2+1]=l1+j;

    A[h+0][l1+j]=l2+0;
    A[h+1][l1+j]=l2+1;
    A[h+0][l2+j]=l1+0;
    A[h+1][l2+j]=l1+1;
  }
  build(h+2,l1+2,l2+2,n-2);
}

signed main(){
  int n;
  cin>>n;
  if(n==2) drop(-1);
  if(n==4){
    A[0][0]=1;
    A[0][1]=2;
    A[0][2]=3;
    A[0][3]=0;

    A[1][0]=2;
    A[1][1]=3;
    A[1][2]=1;
    A[1][3]=2;

    A[2][0]=3;
    A[2][1]=0;
    A[2][2]=0;
    A[2][3]=1;

    for(int i=0;i+1<n;i++){
      for(int j=0;j<n;j++){
        assert(A[i][A[i][j]]!=j);
        assert(A[i][j]!=j);
      }
    }

    for(int i=0;i<n;i++){
      for(int j=0;j+1<n;j++){
        if(j) cout<<" ";
        cout<<A[j][i]+1;
      }
      cout<<endl;
    }
    return 0;
  }

  if(n&1){
    construct(0,0,n);
  }else{
    int m=n/2;
    if(m&1){
      construct(0,0,m);
      construct(0,m,m);
      build(m-1,0,m,m);
    }else{
      construct(0,0,m+1);
      construct(0,m+1,m-1);
      for(int j=m+1;j<n;j++){
        A[m-2][j]=m-1;
        A[m-1][j]=m+0;
      }
      for(int i=m;i+1<n;i++){
        int d=i-m+1;
        A[i][m-1]=m+d;
        A[i][m+0]=m+d;
      }
      build(m,0,m+1,m-1);
    }
  }

  for(int i=0;i+1<n;i++){
    for(int j=0;j<n;j++){
      assert(A[i][A[i][j]]!=j);
      assert(A[i][j]!=j);
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j+1<n;j++){
      if(j) cout<<" ";
      cout<<A[j][i]+1;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int h, w;
  while(1){
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0){break;}
        for(int i = 0; i < h; i++){
          for(int j = 0; j < w; j++){
                printf("#");
          }
          printf("\n");
        }
        printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
 using namespace std;
 #define rep(i, c) for(int i = 0; i < (int)c; i++)
 const int inf = 1000000000; // 10^9

 int main() {
 int N;
 cin >> N;
 vector<int> X(N);
 rep(i, N) cin >> X[i];
 int ans = inf;
 for(int i = 1; i <= 100; i++) { // L やR の計算が不要
 int cost = 0;
 rep(j, N) cost += (X[j] - i) * (X[j] - i);
 ans = min(ans, cost);
 }
 cout << ans << endl;
 return 0;
 }

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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m, d;
    cin >> n >> m >> d;
    vector<pair<int, int>> a(100010);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int x;
            cin >> x;
            a[x] = {i, j};
        }
    }
    vector<vector<int>> g(d + 1);
    for (int i = 1; i <= d; i++) {
        g[i].push_back(0);
        g[i].push_back(0);
        for (int j = i + d; j <= 100000; j += d) {
            g[i].push_back(abs(a[j].first - a[j - d].first) + 
                abs(a[j].second - a[j - d].second) + g[i].back()
            );
        }
    }
    
    
    int q;
    cin >> q;
    while (q-- > 0) {
        int l, r;
        cin >> l >> r;
        int i = l % d;
        if (i == 0) {
            i = d;
            cout << g[i][r / d] - g[i][l / d] << '\n';
        } else {
            cout << g[i][r / d + 1] - g[i][l / d + 1] << '\n';
        }
    }
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);
    for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
    string num(n, '0');
    num[0] = '1';
    int st = stoi(num);
    num = num + '0';
    int e = stoi(num);
    if (n == 1) st = 0;
    for (int num = st; num < e; num++) {
        bool flag = true;
        string t = to_string(num);
        for (int i = 0; i < m; i++) {
            if (t[s[i] - 1] != c[i]) flag = false;
        }
        if (flag) {
            cout << num << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// typedef
typedef complex<double> Point;
// typedef pair<int, int> P;
// typedef pair<int, P> PP;
// typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int mod = 1e9+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int N;

signed main()
{
    cin >> N;
    vi P(N),Q(N);
    rep(i,N)cin >> P[i];
    rep(i,N)cin >> Q[i];

    vi R(N);

    for(int i=1;i<=N;i++)
    {
        R[i-1]=i;
    }

    int cnt=0;

    int Pcnt = 0;
    int Qcnt = 0;

    bool eqcheck = false;
    bool Pflag = true;
    bool Qflag = true;

    do 
    {
        rep(i,N)
        {
            if(Pcnt==0 and R[i]!=P[i])
            {
                Pflag = false;
            }
            if(Qcnt==0 and R[i]!=Q[i])
            {
                Qflag = false;
            }
        }

        if(Pcnt==0 and Pflag)
        {
            Pcnt = cnt;
        }
        if(Qcnt==0 and Qflag)
        {
            Qcnt = cnt;
        }

        if(Pflag and Qflag)break;

        Pflag = Qflag = true;

        cnt++;

    } while(next_permutation(R.begin(), R.end()));

    cout << abs(Pcnt - Qcnt) << endl;

    return 0;
}

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

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long


int main(){
    int n; cin >> n;
    vector<long> v;
    rep(i, n){
        long x; cin >> x; v.push_back(x);
    }
    sort(all(v));
    if(n == 2){
        cout << v[1] << " " << v[0] << endl;
        return 0;
    }
    long v_max = v[n-1];
    auto itr = lower_bound(all(v), v_max/2);
    long k1 = *itr, k2 = *(--itr);
    if(k1-v_max/2 > v_max/2-k2) k1 = k2;
    cout << v_max << " " << k1 << endl;
}

Measured memory_bytes: 2032
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();

        int maxSum = 0;

        int availK = K;
        if(availK - A >= 0){
            availK -= A;
            maxSum += A;
        }
        else if(availK > 0){
            maxSum += availK;
            availK = 0;
        }
        if(availK - B >= 0){
            availK -= B;
        }
        else if(availK > 0){
            availK = 0;
        }
        if(availK - C >= 0){
            availK -= C;
            maxSum -= C;
        }
        else if(availK > 0){
            maxSum -= availK;
            availK = 0;
        }
        System.out.println(maxSum);
    }
}

Measured memory_bytes: 35868
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define TLong long long

typedef struct {
	TLong a;	// price
	TLong b;	// limit
} store;

int comp(const void *p,const void *q){
    return ((store *)p)->a - ((store*)q)->a;
}

int main(int argc, char const *argv[])
{
	TLong n,m;
	TLong t_price = 0;
	TLong temp;
	store st[100000];
	scanf("%lld%lld",&n,&m);
	for (TLong i = 0; i < n; ++i)	scanf(" %lld%lld", &st[i].a, &st[i].b);

	qsort(st,n,sizeof(store),comp);
	for (int i = 0; (i < n && m > 0); ++i)
	{
		temp = (st[i].b <= m) ? st[i].b : m;
		t_price += st[i].a * temp;
		m -= temp;
	}
	printf("%lld\n",t_price);
	return 0;
}


Measured memory_bytes: 3324
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
A = LI()

b = 0
ans = 0
for a in A:
    # print(a)
    if b > a:
        ans += b - a
        a = b
    b = a

print(ans)

Measured memory_bytes: 49756
N = int(input())
c = list(map(str, input().split()))

def bin_search(arr, num): # num以上の最小の値を探す
    lb = -1
    ub = len(arr)

    while ub - lb > 1:
        mid = (ub + lb) // 2
        if arr[mid] < num:
            lb = mid
        else:
            ub = mid
        
    return ub

red_list = list()
white_list = list()
for i in range(N):
    if c[0][i] == "R":
        red_list.append(i)
    else:
        white_list.append(i)

red_cnt = len(red_list)
white_cnt = len(white_list)

print(red_cnt - bin_search(red_list, red_cnt))




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

int main(){
	int n[999], m[999], a;
	int count = 0;
	cin >> a;
	for (int i = 0; i < a; i++){
		cin >> n[i];
		count += 1;
	}
	for (int j = 0; j < a; j++){
		m[j] = n[count - 1 -j];
	}
	for (int f = 0; f < a; f++){
		cout << m[f];
		if (f < a - 1){
			cout << " ";
		}
		
	}
	cout << endl;

}


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

const int maxn = 500;

int n, a[maxn][maxn];
long long from[maxn][maxn], to[maxn][maxn], dp[maxn][maxn][maxn], ans;

void cmin(long long &x, long long y) { x = min(x, y); }

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) if (j != i) {
			scanf("%d", &a[i][j]);
			from[i][j] = (j?from[i][j-1]:0) + a[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			to[i][j] = (j?to[i][j-1]:0) + a[j][i];
		}
	}
	memset(dp, 0x3f, sizeof(dp));
	ans = dp[0][0][0];
	dp[0][0][0] = 0;
	for (int i = 0; i < n-1; ++i) {
		for (int j = 0; j <= i; ++j) {
			for (int k = 0; k <= j; ++k) {
				cmin(dp[i+1][j][k], dp[i][j][k]+(to[i+1][i]-(j?to[i+1][j-1]:0))+(k?from[i+1][k-1]:0));
				cmin(dp[i+1][i+1][j], dp[i][j][k]+(j?from[i+1][j-1]:0));
			}
		}
	}
	for (int j = 0; j < n; ++j)
		for (int k = 0; k <= j; ++k)
			cmin(ans, dp[n-1][j][k]);
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
const int maxn = (int) 1e5 + 2;

int n;
int a[maxn], b;
ll ans;
int main(){
    cin >> n;
    for(int i = 1; i <= n + 1; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> b;
        ans += min(a[i] + a[i + 1], b);
        a[i] -= b;
        if(a[i] < 0){
            a[i + 1] += a[i];
            if(a[i + 1] < 0){
                a[i + 1] = 0;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long K = long.Parse(str[1]);
		long ans = N%K;
		ans = Math.Min(ans,K-N%K);
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
#include <stdio.h>

int main(void){
    int n;
    scanf("%d", &n);

    int V[101][101];
    for(int i = 1; i <= 100; i++){
        for(int j = 1; j <= 100; j++){
            V[i][j] = 0;
        }
    }

    for(int i = 0; i < n; i++){
        int num1;
        scanf("%d", &num1);

        int n;
        scanf("%d", &n);

        int num2;
        for(int j = 0; j < n; j++){
            scanf("%d", &num2);
            V[num1][num2] = 1;
        }
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(j == 1){
                printf("%d", V[i][j]);
            }else{
                printf(" %d", V[i][j]);
            }
        }
        printf("\n");
    }
}



Measured memory_bytes: 2740
#include <stdio.h>
int main(void){
  int i;
  int x,y,z;
  int a,b;
  int co=0;
  scanf("%d%d%d",&x,&y,&z);
  a=x-y-z-z;
  b=y+z;
  for(i=0;b*i<=a;i++) co++;
  printf("%d\n",co);
  return(0);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>

#define ll long long

using namespace std;

int main(){

    int n;
    cin >> n;

    //A*GC, AG*C, GAC ACG,AGCをふくんではいけない

    switch(n){
        case 3:
            cout << 61 << endl;
            break;
        default:
            ll array[256] = {0};
            ll new_array[256] = {};

            for(int i = 0; i < 64; i++){
                if(i != 11 && i != 14 && i != 35){
                    array[i]  = 1;
                }
            }

            for(int i = 0; i < n - 3; i++){
                for(int j = 0; j < 64; j++){
                    for(int k = 0; k < 4; k++){
                        ll tmp;
                        int index = j * 4 + k;
                        if(index % 64 == 11 || index % 64 == 14 || index % 64 == 35){
                            tmp = 0;
                        }else if(index == 27 ||  index == 43 || index == 59 || index == 39 || index == 47){
                            tmp = 0;
                        }else tmp = (array[j] + array[j + 64] + array[j + 128] + array[j + 192]) % 1000000007; 
                        new_array[index] = tmp;
                    }
                }
                memcpy(array,new_array,sizeof(ll) * 256);
            }

            ll ans = 0;

            for(int i = 0; i < 256; i++){
                ans = (ans + new_array[i]) % 1000000007;
            }

            cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }


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

	int n,t; cin >> n >> t;
	ll pt = 0, nt = 0, ans = 0;
	cin >> pt;
	rep1(i, n-1) {
	  cin >> nt;
		if(pt + t <= nt) ans += t;
		else ans += nt - pt;
		pt = nt;
	}


	cout << ans+t << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
ll const MOD=1e9+7;
using ll = long long;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> data(m);
  int count=0;
  REP(i,m){
    cin>>data.at(i);
    count+=data.at(i);
  }
  if(count>n){
    cout<<"-1"<<endl;
  }
  else{
    cout<<n-count<<endl;
  }
}


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

int main(void)
{
	double needv;
	int i;
	
	while( scanf( "%lf", &needv ) != EOF )
	{
		for( i = 1;; i++ )
		{
			int height = 5 * i - 5;
			double t = sqrt(height / 4.9);
			double v = t * 9.8;
			
			if( v >= needv )
			{
				break;
			}
		}
		printf( "%d\n", i );
	}
	
	return (0);
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
    int n = 5;
    int answer = 0;
    rep(i, n){
        int tmp;
        cin >> tmp;
        if(tmp == 0){
            answer = i;
        }
    }
    cout << answer + 1 << endl;
    return 0;    
}

Measured memory_bytes: 3528
#include <stdio.h>

int main(void) {
	int n,m,bib[128] = {0},swh,i,j;
	scanf("%d%d",&n,&m);
	for(i = 1;i <= n;i++){scanf("%d",&bib[i]);}
	for(i = 1;i <= m;i++){
		for(j = 1;j < n;j++){
			if(bib[j] % i > bib[j+1] % i){
				swh = bib[j];
				bib[j] = bib[j+1];
				bib[j+1] = swh;
			}
		}
	}
	for(i = 1;i <= n;i++){
		printf("%d\n",bib[i]);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    LL C,K; cin >> C >> K;
    VL T(N); REP(i,N) cin >> T[i];
    sort(T.begin(),T.end());
    int cnt = 0;
    LL start = 0;
    LL ans = 0;
    REP(i,N){
        if(cnt == 0) {
            start = T[i];
            cnt++;
        }
        else{
            if(T[i]-start <= K){
                cnt++;
            }
            else{
                //cnt = 0;
                cnt = 1;
                start = T[i];
                ans++;
                dump(i)
                dump(cnt)
                continue;
            }
        }

        if(cnt == C){
            dump(i)
            dump(cnt)
            cnt = 0;
            ans++;
        }
    }
    if(cnt > 0) ans++;
    cout << ans << endl;



}

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

struct Rectangle {
	int h;
	int p;  // position from left
};

int max_area_of_histgram(int n, vector<int>& height) {
	stack<Rectangle> S;

	/*	initialize	*/
	int maxv = 0;

	for (int i = 0; i <= n; i++) {
		Rectangle rect;
		rect.h = height[i];
		rect.p = i;

		if (S.empty()) {
			S.push(rect);
		}
		else if (S.top().h < rect.h) {
			S.push(rect);
		}
		else if (S.top().h > rect.h) {
			int now = i;
			while (!(S.empty()) && (S.top().h >= rect.h)) {
				Rectangle pre_rect = S.top(); S.pop();
				maxv = max(maxv, pre_rect.h * (i - pre_rect.p));
				now = pre_rect.p;
			}
			rect.p = now;
			S.push(rect);
		}
	}
	return maxv;
}

int get_Largest_Rectangle(int H,int W,vector<vector<int>>& dp) {
	for (int h = 1; h < H; h++) {
		for (int w = 0; w < W; w++) {
			if (dp[h][w] == 0) continue;
			dp[h][w] = dp[h - 1][w] + 1;
		}
	}

	int maxv = 0;
	for (int h = 0; h < H; h++) {
		maxv = max(maxv, max_area_of_histgram(W, dp[h]));
	}
	return maxv;
}
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int H, W; cin >> H >> W;
	vector<vector<int>> c(H + 1, vector<int>(W + 1,0)), dp(H + 1, vector<int>(W + 1,0));

	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			cin >> c[h][w];
			if (c[h][w] == 0) { dp[h][w] = 1; }
			else { dp[h][w] = 0; }
		}
	}
	cout << get_Largest_Rectangle(H, W, dp) << endl;
}

Measured memory_bytes: 18152
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <cstring>
#include <string>
#include <cassert>
using namespace std;
typedef long long ll;
#define MOD (ll)(1e9+7)

typedef pair<int,int> pp;
typedef pair<pp,int> ppp;

map<int,pair<pp,int>> dic;
// map<pp,pp> dic;

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

void output(ll n,ll a,ll b,ll c){
	int t[3];
	t[0]=a;
	t[1]=b;
	t[2]=c;
	sort(t,t+3);

	printf("dic[%d]=pp(pp(%d,%d),%d);\n",(int)n,t[0],t[1],t[2]);
}


bool chk[100010];

int main(){
/*
	freopen("output.txt","w",stdout);

	for(int i=1;i<=3500;i++){
		for(int j=i;j<=3500;j++){
			ll y=(i+j);
			ll x=(i*j);
			ll t=gcd(x,y);
			x/=t;
			y/=t;
			if(dic.find(pp(x,y))==dic.end())dic[pp(x,y)]=pp(i,j);
		}
	}

	for(int N=2;N<=100000;N++){

		if(chk[N])continue;
		for(ll i=(ll)N*N;i<=100000;i+=N)chk[i]=1;

		for(int i=N/4;i<=3500;i++){
			if(4*i-N<0)continue;
			ll x=N*i;
			ll y=4*i-N;
			ll t=gcd(x,y);
			x/=t;
			y/=t;
			if(dic.find(pp(x,y))!=dic.end()){
				output(N,dic[pp(x,y)].first,dic[pp(x,y)].second,i);
				break;
			}
		}
	}
*/

#define pp make_pair

dic[2]=pp(pp(1,2),2);
dic[3]=pp(pp(1,4),12);
dic[5]=pp(pp(2,4),20);
dic[7]=pp(pp(2,15),210);
dic[11]=pp(pp(3,34),1122);
dic[13]=pp(pp(4,18),468);
dic[17]=pp(pp(5,30),510);
dic[19]=pp(pp(5,100),1900);
dic[23]=pp(pp(6,144),3312);
dic[29]=pp(pp(8,80),2320);
dic[31]=pp(pp(8,279),2232);
dic[37]=pp(pp(10,130),2405);
dic[41]=pp(pp(11,164),1804);
dic[43]=pp(pp(11,594),2322);
dic[47]=pp(pp(12,705),2820);
dic[53]=pp(pp(14,280),2120);
dic[59]=pp(pp(15,1416),2360);
dic[61]=pp(pp(16,366),2928);
dic[67]=pp(pp(17,2278),2278);
dic[71]=pp(pp(18,2130),3195);
dic[73]=pp(pp(20,292),730);
dic[79]=pp(pp(20,3160),3160);
dic[83]=pp(pp(21,3486),3486);
dic[89]=pp(pp(24,356),2136);
dic[97]=pp(pp(28,194),2716);
dic[101]=pp(pp(26,1313),2626);
dic[103]=pp(pp(27,702),2678);
dic[107]=pp(pp(28,749),2996);
dic[109]=pp(pp(28,1526),3052);
dic[113]=pp(pp(30,565),3390);
dic[131]=pp(pp(36,524),1179);
dic[137]=pp(pp(36,1233),1644);
dic[139]=pp(pp(36,1668),2502);
dic[151]=pp(pp(40,1208),1510);
dic[163]=pp(pp(42,2282),3423);
dic[173]=pp(pp(45,1730),3114);
dic[181]=pp(pp(48,1086),2896);
dic[191]=pp(pp(52,764),2483);
dic[223]=pp(pp(60,1115),2676);
dic[229]=pp(pp(60,2290),2748);
dic[263]=pp(pp(70,1841),2630);
dic[271]=pp(pp(72,2168),2439);

#undef pp

	int N;
	scanf("%d",&N);

	for(int p=2;p*p<=N;p++){
		if(N%p==0){
			int x=dic[p].first.first;
			int y=dic[p].first.second;
			int z=dic[p].second;
			int w=N/p;
			printf("%d %d %d\n",x*w,y*w,z*w);
			return 0;
		}
	}

	int x=dic[N].first.first;
	int y=dic[N].first.second;
	int z=dic[N].second;
	printf("%d %d %d\n",x,y,z);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 2e5 + 100;
VI e[MAXN];

bool odd[MAXN];
int ans[MAXN];

void DFS(int x, int p, bool is_odd) {
  odd[x] = is_odd;
  for (int u : e[x]) {
    if (u == p)
      continue;
    DFS(u, x, !is_odd);
  }
}

bool used[MAXN];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i < N; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    e[a].PB(b);
    e[b].PB(a);
  }
  DFS(1, 0, true);
  int cnt_odd = 0;
  for (int i = 1; i <= N; i++)
    if (odd[i])
      cnt_odd++;
  int cnt_even = N - cnt_odd;

  int c0 = N / 3;
  int c1 = N / 3 + (N % 3 >= 1 ? 1 : 0);
  int c2 = N / 3 + (N % 3 >= 2 ? 1 : 0);
  int first = -1;
  bool go_odd;
  if (cnt_odd > c1 + c0) {
    first = 3;
    go_odd = false;
  } else if (cnt_even > c2 + c0) {
    first = 3;
    go_odd = true;
  } else {
    int n1 = 1, n2 = 2;
    for (int i = 1; i <= N; i++) {
      if (odd[i]) {
        if (n1 <= N) {
          ans[i] = n1;
          used[n1] = true;
          n1 += 3;
        }
      } else {
        if (n2 <= N) {
          ans[i] = n2;
          used[n2] = true;
          n2 += 3;
        }
      }
    }
    goto ff;
  }

  for (int i = 1; i <= N; i++) {
    if (odd[i] == go_odd) {
      ans[i] = first;
      used[first] = true;
      first += 3;
    }
  }
  ff:
  assert(first - 3 <= N);
  first = 1;
  for (int i = 1; i <= N; i++) {
    if (ans[i] == 0) {
      while (used[first])
        first++;
      ans[i] = first;
      first++;
    }
  }
  for (int i = 1; i <= N; i++)
    printf("%d%c", ans[i], " \n"[i == N]);
  return 0;
}


Measured memory_bytes: 18688
n=int(input())
A_c=0
Un_c=0
flag=0
for i in range(n):
    s=input()
    if s=="A":
        A_c+=1
    elif s=="Un":
        Un_c+=1
    if A_c<Un_c:flag=1
if A_c!=Un_c:flag=1
if flag==0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 5592
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
using namespace std;

#define rep(i, e) for (int i = 0; i < e; i++)
#define repp(i, s, e) for (int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;
ll dp[100005];

int main()
{
    int n, a, b, c, d, k, x;
    ll cnt = 1, ans = 0;
    string s[100005] = {};
    int cheak[100005] = {};

    scanf("%d", &n);
    rep(i, n)
    {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s, s + n);
    // rep(i, n)
    // {
    //     if (i)
    //         cout << " ";
    //     cout << s[i];
    // }
    // cout << endl;

    rep(i, n - 1)
    {
        if (s[i] == s[i + 1])
        {
            cnt++;
        }
        else if (cnt >= 1)
        {
            ans += (cnt * (cnt - 1)) / 2;
            cnt = 1;
        }
    }
    ans += (cnt * (cnt - 1)) / 2;
    cout << ans << endl;
}

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

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

  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }

  int count = 1;
  int maxh = H.at(0);
  for (int i = 1; i < N; i++) {
    if (H.at(i) >= maxh) {
      count++;
    }
    maxh = max(maxh, H.at(i));
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    set<ll> ans;
    ll s=a;
    ll t=b;
    rep(i,min(k,abs(s-t)+1)){
        ans.insert(a);
        ans.insert(b);
        a++;
        b--;
    }
    for(auto x:ans){
        cout << x << endl;
    }
} 

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

int main(void){
  int n;
  while(cin >> n && n != 0){
    int c, m1, s1, m2, s2, m3, s3, m4, s4;
    vector<pair<int, int> > team;
    for(int i = 0; i < n; i++){
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      int time = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
      team.push_back(pair<int, int>(time, c));
    }
    sort(team.begin(), team.end());
    cout << team[0].second << endl;
    cout << team[1].second << endl;
    cout << team[team.size() - 2].second << endl;
  }
  return 0;
}

Measured memory_bytes: 1304
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)

typedef pair<int, int> pii;

int dp[150][10][80]; //[i][j][k] i???????????§??§(i???,j??????)????????§?????????k????????£????????§????????¨??????????°????
vector<pii> stone[150]; // x, dang
int n, m;

int main() {
	while (cin >> n >> m, n || m) {
		fill(dp[0][0], dp[n][0], INF);
		REP(i, n) stone[i].clear();
		
		REP(i, n) {
			int k;
			scanf("%d", &k);
			REP(j, k) {
				int a, b;
				scanf("%d %d", &a, &b);
				stone[i].push_back(pii(a, b));
			}
		}
		
		REP(i, stone[0].size()) dp[0][i][m] = 0;
		if (m != 0) REP(i, stone[1].size()) dp[1][i][m - 1] = 0;
		
		REP(i, n - 1) REP(j, stone[i].size()) REP(k, m + 1) {
			pii &from = stone[i][j];
			
			// 1????£???°???
			if (i < n - 2 && k > 0) {
				REP(l, stone[i + 2].size()) {
					pii &to = stone[i + 2][l];
					int cost = (from.second + to.second) * abs(from.first - to.first);
					dp[i + 2][l][k - 1] = min(dp[i + 2][l][k - 1], dp[i][j][k] + cost);
				}
			}
			
			REP(l, stone[i + 1].size()) {
				pii &to = stone[i + 1][l];
				int cost = (from.second + to.second) * abs(from.first - to.first);
				dp[i + 1][l][k] = min(dp[i + 1][l][k], dp[i][j][k] + cost);
			}
		}
		
		int ans = INF;
		REP(i, stone[n - 1].size()) REP(j, m + 1) ans = min(ans, dp[n - 1][i][j]);
		REP(i, stone[n - 2].size()) FOR(j, 1, m + 1) ans = min(ans, dp[n - 2][i][j]);
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& e : a) cin >> e;

    int64_t ans = 0;
    for (auto& e : a) ans += abs(e);
    int nc = 0;
    for (auto& e : a) if (e < 0) nc++;
    if(nc%2 != 0 && find(a.begin(), a.end(), 0) == a.end()) {
        vector<int> absn;
        for (auto& e : a) absn.push_back(abs(e));
        ans -= (*min_element(absn.begin(), absn.end())*2);
    } 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1276
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


struct Team
{
	int id, u, a, p;
	void input()
	{
		cin >> id >> u >> a >> p;
	}
};
bool operator<(const Team& a, const Team& b)
{
	return a.a > b.a || a.a == b.a && a.p < b.p
		|| a.a == b.a && a.p == b.p && a.id < b.id;
}
int main()
{
	int n;
	while (cin >> n, n)
	{
		Team team[500];
		rep (i, n)
			team[i].input();
		sort(team, team + n);

		int	select[1024];
		fill_n(select, n, 0);
		int s = 0;
		for (int i = 0; i < n && s < 26; ++i)
		{
			static const int limit[] = { 3, 2, 1 };
			if (select[team[i].u] < limit[s / 10])
			{
				++s;
				++select[team[i].u];
				cout << team[i].id << endl;
			}
		}
	}
}

Measured memory_bytes: 0
inp = input()
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
d = int(inp[3])
o= ['-','+'] 
def cal(n,i,x,y):
	    if check(n,i):
	    	    return x+y
	    if not check(n,i):
	    	    return x-y

def check(i,j):
	return  (i>>j)%2
for i in range(8):
	    p = cal(i,0,a,b)
	    q = cal(i,1,p,c)
	    r = cal(i,2,q,d)
	    if r == 7:
	    	    s = str(o[check(i,0)])
	    	    t = str(o[check(i,1)])
	    	    u = str(o[check(i,2)])
	    	    print(str(a)+s+str(b)+t+str(c)+u+str(d)+'=7')
	    	    exit(0)
	 
print(-1)


Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args) throws Exception {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		int l = sc.nextInt();
		int t = sc.nextInt();
		int[][] grid = new int[l][t];
		boolean[][] rocks = new boolean[l][t];
		for(int i=0;i<l;i++) {
			String str = sc.nextToken();
			for(int j=0;j<t;j++) {
				rocks[i][j]=str.charAt(j)=='.';
			}
		}
		int x=0;
		while(x<l&&rocks[x][0]) {
			grid[x++][0]=1;
		}
		x=0;
		while(x<t&&rocks[0][x]) {
			grid[0][x++]=1;
		}
		for(int i=1;i<l;i++) {
			for(int j=1;j<t;j++) {
				if(!rocks[i][j])grid[i][j]=0;
				grid[i][j]=(get(grid,i,j-1,rocks)+get(grid,i-1,j,rocks))%(int)(1e9+7);
			}
		}
		pw.println(grid[l-1][t-1]);
		pw.close();
	}
	static int get(int[][] arr, int x,int y, boolean[][] rocc) {
		if(x<0||y<0||x>=arr.length||y>=arr[0].length||!rocc[x][y])return 0;
		else return arr[x][y];
	}
}
@SuppressWarnings("all")
class FastScanner {
    BufferedReader br;
    StringTokenizer st;
 
    public FastScanner(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
 
    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
 
    String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    int nextInt() {
        return Integer.parseInt(nextToken());
    }
 
    long nextLong() {
        return Long.parseLong(nextToken());
    }
 
    double nextDouble() {
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 32428
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();

		System.out.println(a*b);
	}

}


Measured memory_bytes: 27052
#include <iostream>
#include <algorithm>
#include <cstdio>

#define VMAX 500000
#define MAX 200000
#define NIL -1

using namespace std;

struct Node {int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u){
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)
    h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL)
    h2 = setHeight(T[u].right) + 1;
  return H[u] = max(h1, h2);
}

int getSibling(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);
  
  if(T[u].parent == NIL){
    printf("root\n");
  }else if (T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}

int main(int argc, const char * argv[]) {
  int v, l, r, root = 0;
  cin >> n;

  for(int i=0; i<n; i++) T[i].parent = NIL;

  for(int i=0; i<n; i++){
    cin >> v >> l >> r;
    T[v].left = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(int i=0; i<n; i++) if(T[i].parent == NIL) root = i;

  setDepth(root, 0);
  setHeight(root);

  for(int i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    if (a < b)
        return gcd(b, a);
    else if (a % b)
        return gcd(b, a % b);
    else
        return b;
}
int main()
{
    int n;
    cin >> n;
    int a[n];
    int u[n],v[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
  	sort(a,a+n);
    int x = a[0], y = a[1];
    for (int i = 0; i < n; i++)
    {
       u[i]=gcd(x,a[i]);
       v[i]=gcd(y,a[i]);
    }
    sort(u,u+n);
    reverse(u,u+n);
    sort(v,v+n);
    reverse(v,v+n);
    int s = u[0], t = v[0];
    for (int i = 0; i < n - 1; i++)
    {
        s = gcd(s, u[i]);
        t = gcd(t, v[i]);
    }
    cout << max(s, t) << endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include <string>

using namespace std;
#define ll long long int
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

	ll n;
	cin >> n;
	ll a[n], b[n], count = 0 ;
	for (ll i = 0 ; i < n; i++)
		cin >> a[i] >> b[i];
	for (ll i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			count++;
			for (ll j = i + 1 ; j <= i + 2; j++) {
				if (a[j] == b[j]) {
					count++;
				}
			}
		}
		if (count == 3) {
			cout << "Yes";
			break;
		}
		count = 0 ;
	}
	if (count != 3)
		cout << "No";



	return 0 ;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans,kotae;
  cin>>n;
  for(long i=1; i*i<=n; i++){
    if(n%i==0){
      ans=n/i;
    }
  }
  kotae=0;
  while(ans>0){
    ans=ans/10;
    kotae++;
  }
  cout<<kotae;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9 + 7;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int n, k;
    cin >> n >> k;
    ll sum = 0;
    vector<ll> dp(k + 1, 0);
    for (int i = k; i >= 1; i--) {
        dp[i] = modpow((k / i), n, MOD);
        for (int j = 2; i * j <= k; j++) dp[i] -= dp[i * j];
        dp[i] = (dp[i] % MOD + MOD) % MOD;
        sum += i * dp[i];
        sum %= MOD;
    }
    cout << sum << endl;
    return 0;
}


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

int main(void) {
    int minN,cnt=0;
    string s,t;
    cin>>s>>t;

    sort(s.begin(), s.end());sort(t.rbegin(), t.rend());

    if((int)s.size()>(int)t.size()){
      minN = (int)t.size();
    }else{
      minN = (int)s.size();
    }
    for(int i=0;i<minN;i++){
      if(s[i]<t[i]){
        cout<<"Yes"<<endl;
        return 0;
      }
      if(s[i]==t[i]){
        cnt++;
      }
    }
    if((cnt==minN)&&(int)s.size()<(int)t.size()){
      cout<<"Yes"<<endl;
      return 0;
    }

    cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e5+100;
char s[N];
int n,k,c[2];
int main(){
    scanf("%d %d",&n,&k);
    scanf("%s",s);
    for(int i=0,j=0,t=0;i<n;i=j,t++){
        while(j<n&&s[j]==s[i]) j++;
        if(i<j) c[t%2]++;
    }
    if(c[0]==c[1]){
        if(k>=c[0]) printf("%d\n",n-1);
        else printf("%d\n",n-2*c[0]+2*k);
    }
    else printf("%d\n",n-c[0]-c[1]+2*min(c[1],k));

}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (56)
ll n, k, s, t, B[MAXN], ans, A[MAXN], co, C[MAXN][MAXN], ways[MAXN];
bool inc(ll x,ll bit) { return bool(x&(1<<bit)); }
int main(){
	FAST
	cin>>n>>k>>s>>t;
	FOR(j,0,17)if(inc(s,j) && !inc(t,j)) { cout<<"0\n"; return 0; }
	FOR(i,1,n)cin>>B[i];
	FOR(i,1,n){
		bool in=1;
		FOR(j,0,17){
			if(inc(s,j)==inc(t,j)){
				if(inc(B[i],j) ^ inc(s,j)) in=0;
			}
		}
		if(in)A[++co]=B[i];
	}
	n=co;
	FOR(i,0,MAXN-1)C[i][0]=1;
	FOR(i,1,MAXN-1)FOR(j,1,MAXN-1)C[i][j]+=C[i-1][j-1]+C[i-1][j];
	FOR(i,1,MAXN-1){
		FOR(j,1,min(i,k)){
			ways[i] += C[i][j];
		}
	}
	FOR(k,0,(1<<18)-1){
		bool bad=0;
		FOR(j,0,17)if(1<<j&k)if(inc(s,j)==inc(t,j))bad=1;
		if(bad)continue;
		vector<ll> v;
		FOR(i,1,n){
			v.eb(A[i] & k);
		}
		ll sign=(__builtin_popcount(k) & 1 ? -1 : 1);
		sort(all(v));
		for(ll s=0,e=0;s<v.size();s=e+1,++e){
			while(e+1<siz(v) && v[e] == v[e+1]) ++ e;
			ans += sign * ways[e-s+1];
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;

vector<vector<int>> A;
int n,m;

int calc(vector<int>& perm){
    vector<int> vi(m+1,0);
    /*for(int i=1; i<=m; i++){
        cout<<perm[i]<<" ";
    }
    cout<<endl;
    */
    for(int i=1; i<=n; i++){
        //pair<int,int> choice=make_pair(m+1,0);
        bool found=false;
        for(int j=1; j<=m && !found; j++){
            
            if(perm[A[i][j]]){
                found=true;
                vi[A[i][j]]++;
            }
        }
        //cout<<i<<" "<<choice<<endl;
        //vi[choice.second]++;
            
    }/*
    for(int i=1; i<=m; i++){
        cout<<vi[i]<<" ";
    }
    cout<<endl;*/
    auto it=max_element(vi.begin()+1,vi.end());
    int pos=it-vi.begin();
    //cout<<pos<<endl;
    perm[pos]=0;
    
    return *it;
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    
    cin>>n>>m;
    A.resize(n+1);
    for(int i=1; i<=n; i++){
        A[i].push_back(0);
        for(int j=1; j<=m; j++){
            int x;
            cin>>x;
            A[i].push_back(x);
        }
    }
    vector<int> perm(m+1,1);
    
    int ans=calc(perm);
    
    for(int i=1; i<m; i++){
        ans=min(ans,calc(perm));
        /*for(int i=1; i<=m; i++){
            cout<<perm[i]<<" ";
        }*/
        //cout<<endl;
    }
    
    cout<<ans;
    
    
    
    return 0;
}

Measured memory_bytes: 896
#include <iostream>

int main() {
  char S[3];
  std::cin >> S;

  int ramen = 700;
  for (int i = 0; i < 3; ++i) {
    if ( S[i] == 'o' ) ramen += 100;
  }
  std::cout << ramen << std::endl;

  return 0;
}


Measured memory_bytes: 256
/**
*    created: 06.05.2020 01:45:31
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    int n, k;
    cin >> n >> k;
    int x[n];
    rep(i, n) cin >> x[i];
    int ans = 0;
    rep(i, n) ans += min(2 * (k - x[i]), 2 * x[i]);
    cout << ans << endl;
}

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

int main(){
	int N, i, j, k;
	scanf("%d", &N);
	vector<int> S(1 << N);
	for(i = 0; i < (1 << N); i++){
		scanf("%d", &S[i]);
	}
	sort(S.begin(), S.end(), greater<int>());
	for(i = 0; i < N; i++){
//		printf("i = %d\n", i);
		sort(S.begin(), S.begin() + (1 << i), greater<int>());
		sort(S.begin() + (1 << i), S.end(), greater<int>());
/*		for(j = 0; j < (1 << N); j++){
			printf("%d ", S[j]);
		}
		printf("\n");
*/		for(j = 0, k = (1 << i); j < (1 << i); j++, k++){
			while(k < (1 << N) && S[j] <= S[k]){
				k++;
			}
//			printf("(j, k) = (%d, %d)\n", j, k);
			if(k == (1 << N)){
				printf("No\n");
				return 0;
			}
			swap(S[(1 << i) + j], S[k]);
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int N, M;
  cin >> N >> M;

  vector<int> T(N);
  for (int i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    T.at(a - 1)++;
    T.at(b - 1)++;
  }

  for (int i = 0; i < N; i++)
  {
    cout << T.at(i) << endl;
  }

  return 0;
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n; cin >> n;
    vector<ll> L(n);
    rep(i, n) cin >> L[i];
    sort(ALL(L));
    ll ans = 0;

    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(L[i] + L[j] > L[k] && L[i] != L[j] && L[j] != L[k]) ans++;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3628
n,m = gets.chomp.split.map(&:to_i)
arr = []
n.times.map {arr << gets.split.map(&:to_i)}
counter = 0
arr_all = []
#1人につき、k種類回答する(k = 各人の回答配列のarr[0]要素)
arr.each do |v|
   v[1..v[0].to_i].each do |v2|
    arr_all << v2
   end
end

# n人全員が好きと答えたもの　
# <=> 回答全体を同じ配列にまとめ、
# ある要素がn個ある

(1..m).to_a.each do |v|
  if arr_all.count(v) == n
    counter += 1
  end
end

p counter

Measured memory_bytes: 1916