akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define MAX 100000

/*1 partition(A, p, r)
2   x = A[r]
3   i = p-1
4   for j = p to r-1
4     if A[j] <= x
5       i = i+1
6       A[i] と A[j] を交換
7   A[i+1] と A[r] を交換
8   return i+1*/
int partition(int A[], int p, int r){
  int x, i, j, tmp;
  x = A[r];
  i = p - 1;
  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  return i+1;
}

int main(){
  int A[MAX], i, q, n;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
  q = partition(A, 0, n-1);

  for(i = 0; i < n; i++){
    if(i) printf(" ");
    if(i == q) printf("[");

    printf("%d", A[i]);

    if(i == q) printf("]");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

ll dp[2005];

int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<ull> A(N);
    rep(i,N){
        cin >> A[i];
    }
    vector<ull> V(N);
    for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            if(A[i]>A[j]){
                V[i]++;
            }
        }
    }
    sort(A.begin(),A.end(),greater<ll>());
    vector<ull> M(N);
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(A[i]!=A[j]){
                M[i]=N-j;
                break;
            }
        }    
    }

    ll val,ans;
    ans = 0;
    val = (K-1)*K/2%MOD; 
    
    rep(i,N){
        ans+=M[i]*val%MOD;
        ans+=V[i]*K%MOD;
        ans %= MOD;
    }

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

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  int i;
  rep(i,m) cin >> a[i] >> b[i];
  vector<int> count(n+1,0);
  rep(i,m)
  {
    count[a[i]]++;
    count[b[i]]++;
  }
  bool ok = true;
  rep(i,n+1)
  {
    if(count[i]%2 != 0) ok = false;
  }
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;
static const int inf = 10000;
static const int emp = -1;
static const int black = 1;
static const int white = 0;

int   graph[124][124] = {{}};;
int d[124] = {};
int color[124] = {};
int p[124] = {};
int n;

int  prim(){

  for(int i = 0;i < n;i++){
    d[i] = inf;
    color[i] = white;
    p[i] = -1;
  }

  d[0] = 0;
  int u ,v;
 

  while(1){

    v = inf;
    u = -1;

    for(int i = 0;i < n;i++){
      if(d[i] < v && color[i] != black){
	v= d[i];
	u = i;
      }
    }
    //    cout << "u = " << u << endl; 

    if(u == -1) break;
    color[u] = black;

    // cout << 'a' << endl;
    for(int i = 0;i < n;i++){
      if(graph[u][i] != -1 && color[i] != black){
	if(graph[u][i] < d[i]){
	  d[i] = graph[u][i];
	  p[i]= u;
	  //  cout << "d = " << d[i] <<endl;
	  // cout << "i = " << i << endl;
	}
      }
    }
  }

  int sum = 0;
  for(int i = 0;i < n;i++){
    if(p[i] != -1) sum += graph[i][p[i]];
  }
  return sum;
}



int main(){

  cin >> n;

  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      cin >> graph[i][j];
    }
  }



  cout <<  prim() << endl;

  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin>>A>>B;
  if(A>B){
    cout<<2*A-1<<endl;
  }
  else if(A<B){
    cout<<2*B-1<<endl;
  }
  else if(A=B){
    cout<<2*A<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    ll n,a,b,c,d,e; cin >> n >> a >> b >> c >> d >> e;
    // 最小容量の交通機関に乗る時間
    ll onTime = ceil((double) n / min({a,b,c,d,e}));
    // 最小容量の交通機関が使われていない時間
    // i番目から出る交通機関が最小キャパとすると，
    // i-1分に最速の人が使い始め，
    // ゴール前から5-i分には最後の人が使い終わる
    ll outTime = 4;
    ll ans = onTime + outTime;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize (Ofast)
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0); 
	long long n,x=0,count=0;
	long long k;

	{
		cin>>n>>k;
		vector<int> a(n),b(n,-1);
		forn(i,n){
			cin>>a[i];
			a[i]--;
		}

		while(b[x]==-1){
			b[x]=count++;
			x=a[x];
		}

		count-=b[x];
		if(k>10000000)
			k=(k-b[x])%count+b[x];
		x=0;
		while(k--){
			x=a[x];
		}

		cout<<x+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 4768
//
//  ALDS1_3_B_Queue.cpp
//  test
//
//  Created by Sajor on 2019/3/23.
//  Copyright © 2019年 Sajor. All rights reserved.
//

#include<queue>
#include<iostream>
using namespace std;

#define MAX_N 100005
struct P {
    string name;
    int value;
};

int main()
{
    queue<P> que;
    P p[MAX_N], temp;
    int n, q, sum=0;
    cin >> n >> q;
    for(int i=0; i<n; i++){
        cin >> p[i].name >> p[i].value;
        que.push(p[i]);
    }
    
    while(!que.empty()){
        temp = que.front();
        que.pop();
        if(temp.value > q){
            sum += q;
            temp.value -= q;
            que.push(temp);
        } else {
            sum += temp.value;
            cout << temp.name << " " << sum << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 7852
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

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

	string S;
	int w;
	cin >> S >> w;

	for (size_t i = 0; i < S.size(); i++) {
		if(i%w==0){
			cout << S[i];
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	A, B, C, K := nextInt(), nextInt(), nextInt(), nextInt()
	ans := 0
	ans = 1*minInt(K, A) - minInt(maxInt(K-A-B, 0), C)

	fmt.Println(ans)

}


Measured memory_bytes: 1756
a = raw_input()
for i, b in enumerate(a.split()):
	if i==0:
		x=int(b)
	elif i==1:
		y=int(b)
	else:
		z=int(b)
if x<=y<=z:
	print x,y,z
elif x<=z<=y:
	print x,z,y
elif y<=x<=z:
	print y,x,z
elif y<=z<=x:
	print y,z,x
elif z<=x<=y:
	print z,x,y
else:
	print z,y,x

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::map<int, int> c;
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        c[a]++;
    }

    bool flg = false;
    if (c.size() == 1) {
        if (c.begin()->first == 0) flg = true;
    } else if (c.size() == 2) {
        auto it = c.begin();
        if (it->first == 0 && it->second * 3 == n) flg = true;
    } else if (c.size() == 3) {
        std::vector<std::pair<int, int>> v;
        for (auto it = c.begin(); it != c.end(); it++) {
            v.push_back(*it);
        }
        if (v[0].second == v[1].second && v[1].second == v[2].second && (v[0].first ^ v[1].first) == v[2].first) flg = true;
    }

    std::cout << (flg ? "Yes" : "No") << std::endl;

    return 0;
}


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

int compare_long(const void *a, const void *b)
{
    return *(long*)a - *(long*)b;
}

int main(void)
{
    long n,X,x[100001],d,i,ifallzero=0;

    scanf("%ld %ld",&n,&X);
    for ( i = 0; i < n; i++)
    {
        scanf("%ld",x+i);
    }
    x[n]=X;

    qsort(x,n+1,sizeof(long),compare_long);

    for ( i = 0; i < n; i++)
    {
        x[i]=x[i+1]-x[i];
    }

    while(ifallzero==0)
    {
        d=1000000000;
        for ( i = 0; i < n; i++)
        {
            if(x[i]!=0&&d>x[i]) d=x[i];
        }

        for ( i = 0; i < n; i++)
        {
            x[i]=x[i]%d;
        }

        ifallzero=1;
        for ( i = 0; i < n; i++)
        {
            if(x[i]!=0) ifallzero=0;
        }
    }

    printf("%ld",d);

    return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int n;
    cin>>n;
    int ans = n + n*n + n*n*n;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
S = input()
Q = int(input())
ans = S
## vector が1なら正方向、-1なら逆方向
vector = 1
before = ""
after = ""
for i in range(Q):
    Query = input()
    if Query[0] == "1":
        vector *= -1
    elif vector == 1 and Query[0:3] == "2 1":
        before = Query[4] + before
    elif vector == 1 and Query[0:3] == "2 2":
        after = after + Query[4]
    elif vector == -1 and Query[0:3] == "2 1":
        after = after + Query[4]
    elif vector == -1 and Query[0:3] == "2 2":
        before = Query[4] + before
#     print(before)
#     print(after)
if vector==1:
    print(before + S + after)
else:
    print(after[::-1]+S[::-1]+before[::-1])

Measured memory_bytes: 4456
while True :
    a, op, b = map(str, raw_input().split(" "))
    a = int(a)
    b = int(b)
    if (op == "?") :
        break
    elif (op == "+") :
        print("%d" % (a+b))
    elif (op == "-") :
        print("%d" % (a-b))
    elif (op == "*") :
        print("%d" % (a*b))
    elif (op == "/") :
        print("%d" % (a/b))

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

int main () {
  int N;
  cin >> N;
  int a[N];
  for(int i = 1;i <= N;i++){
    cin >> a[i];
  }
  int j = 1;
  int count = 0;
  while(j != 2){
    if(count >= N){
    	count = -1;
      	break;
    }
    j = a[j];
    count++;
  }
  cout << count << endl;
}

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

int n, res = 1e9;
int arr[110];

int main(){
	int i, j, now;
	scanf("%d", &n);
	for(i = 0; i < n; i++) scanf("%d", &arr[i]);
	for(i = -100; i <= 100; i++){
		now = 0;
		for(j = 0; j < n; j++){
			now += (arr[j] - i) * (arr[j] - i);
		}
		res = min(res, now);
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 384
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
s = gets.chomp
size = s.size
ans = Array.new(size, 0)

rlpos = nil
lodd = true
r = 0
(size-1).times do |i|
  if s[i] == 'R' && s[i+1] == 'R'
    r += 1
  elsif s[i] == 'R' && s[i+1] == 'L'
    ans[i]   = 1 + r / 2
    ans[i+1] = r - r / 2
    r = 0
    rlpos = i
    lodd = true
  elsif s[i] == 'L'
    if lodd
      ans[rlpos+1] += 1
    else
      ans[rlpos] += 1
    end
    lodd = !lodd
  end
end
if lodd
  ans[rlpos+1] += 1
else
  ans[rlpos] += 1
end

puts ans.join(' ')

Measured memory_bytes: 3708
#include <stdio.h>

int main(void)
{
  int j, m, e, s;
  int S = 0;
  int T = 0;

  scanf("%d %d %d %d", &j, &m, &e, &s);
  S = j + m + e + s;

  scanf("%d %d %d %d", &j, &m, &e, &s);
  T = j + m + e + s;

  if(S > T){
    printf("%d\n", S);
  }
  else if(T > S){
    printf("%d\n", T);
  }
  else {
    printf("%d\n", S);
  }

  return(0);
}

Measured memory_bytes: 592
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define end "\n"
#define fi first
#define se second
#define db double
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) x & (-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(int i = a; i <= (b); i++)
#define Rep(i, a, b) for(int i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
const db eps = 1e-9;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
using namespace std;

char s[maxn];
int sum[maxn];


int32_t main()
{
	int n; scanf("%d", &n);
	scanf(" %s", s + 1);
	int cnt = 0;
	rep(i, 1, n) if(s[i] == '#') sum[i] = 1, cnt++;
	Rep(i, n, 1) sum[i] += sum[i+1];
	int ans = inf;
	rep(i, 1, n){
		if(s[i] == '#')
			ans = min(ans, (n - i + 1) - sum[i] + cnt - sum[i]);
	}
	ans = min(ans, cnt);
	if(ans == inf) ans = 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1784
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
y = [list(map(int,input().split())) for i in range(m)]
for i in range(n):
    res = 10**9+7
    ans = 0
    for j in range(m):
        temp = abs(x[i][0]-y[j][0])+abs(x[i][1]-y[j][1])
        if temp<res:
            res = temp
            ans = j+1
    print(ans)

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

int main() {
  int A;
  cin >> A;
 
  string op;
  cin >> op;
  
  int B;
  cin >> B;
  
  if ( op == "+"){
    cout << A + B <<endl;
  }
  else{
    cout << A-B <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
bool f = true;
int main() {
  int A, N; cin >> A >> N; if(N==1) {f=false; cout << 0 << endl;}
  
  int res = 1;
  int ans = 0;
  while(res<=N) {
  if(res==1) {res += A; ans++;}
  else {res += A-1; ans++;}
  }
  
  if(f) cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main() {
  // 高速化
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    ll  k, x;
    cin >> k >> x;

    if(500*k >= x){
      cout << "Yes" << "\n";
    }else{
      cout << "No"<< "\n"; 
    }
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	array<int, 3> last({0, 0, 0});
	bool ans = true;
	for (int i = 0; i < N; i++) {
		array<int, 3> cur;
		cin >> cur[0] >> cur[1] >> cur[2];
		ans &= ((cur[0]+cur[1]+cur[2]) % 2 == 0 && (abs(cur[1]-last[1]) + abs(cur[2]-last[2])) <= cur[0]-last[0]);
		last = cur;
	}
	cout << (ans ? "Yes" : "No") << '\n';

	return 0;
}

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

int main()
{
  int N;
  int a[10000];
  int c[9];
  int res=0;
  cin >> N;

  rep(i,N) cin >> a[i];
  rep(i,9) c[i]=0;
  const int boarder[9]={400,800,1200,1600,2000,2400,2800,3200,INF};

  rep(i,N){
    rep(j,9){
      if(a[i]<boarder[j]){
        c[j]++;
        break;
      }
    }
  }

  rep(i,8){
    if(c[i])res++;
  }

  if(c[8]==N) {
    cout << 1 << " " << c[8] << endl;
  }
  else {
    cout <<  res << " " << res+c[8] << endl;
  }

}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,a; cin >> n >> a;
  int bl = n*n-a;

  cout << bl << endl;
  
  return 0;
}


Measured memory_bytes: 3596
n, m = gets.to_s.split.map{|i| i.to_i }

#bits = [0] + Array.new(n){|i| 2**i }
# p bits = [0] + Array.new(12){|i| 2**i } #=> [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]
bits = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]

h = { 0 => 0 }
m.times do |i|
  
  a, b = gets.to_s.split.map{|i| i.to_i }
  c    = gets.to_s.split.map{|i| i.to_i }
  
  bit = c.map{|t| bits[t] }.reduce(0){|s,t|s+t}
  
  h.keys.each do |k|
    new = k | bit
    h[new] = h[k] + a if ( !h.has_key?(new) ||  h[new] > h[k] + a )
  end
end

puts h[ (1 << n) - 1] || -1

Measured memory_bytes: 10748
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		long x = sc.nextLong();
		
		long result = (x/11)*2;
		x %= 11;
		
		result += (int)Math.ceil(x / 6.);
		System.out.println(result);
	}

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
#define pb push_back
#define fi first
#define se second
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1LL<<60;
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;}
int main(){
    int n,m;
    cin>>n>>m;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    sort(all(vec));
    int ans=INF;
    FOR(i,m-1,n){
        chmin(ans,vec[i]-vec[i-m+1]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

map<ll,ll> prime_factor(ll n){
    map<ll,ll> res;
    for(ll i=2; i*i<=n; i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }
    if(n!=1) res[n]=1;
    return res;
}

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

    map<ll,ll> m = prime_factor(N);

    ll cnt=0;
    vector<ll> v={1};
    ll j=1, sum=3;

    for (long long i = 1; i < 100; i++) {
        if(i<sum){
            v.emplace_back(j);
        }else{
            j++;
            sum+=j+1;
            v.emplace_back(j);
        }
    }
    // vout(v);

    for (auto& e: m) {
        cnt+=v[e.second];
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3620
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getLine >>= print

solve :: String -> Int
solve xs = f xs

f :: String -> Int
f xs
  | null xs = 0
  | length xs == 1  = toInt xs
  | otherwise = (toInt xs) + sum (map (\(a,b) -> (read a) * (2 ^ (length b - 1)) + f b) ys)
  where
    ys = (tail . init) (zip (inits xs) (tails xs))
  

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

getc :: ([String] -> a) -> IO a
getc f = f . lines <$> getContents


Measured memory_bytes: 1020
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int G=0;
	int W=0;
	int Y=0;
	int P=0;
	int i=0;
	char S;
	for (i=0;i<N;i++){
		cin>>S;
		switch(S){
			case 'G':
				G++;
				break;
			case 'W':
				W++;
				break;
			case 'Y':
				Y++;
				break;
			case 'P':
				P++;
				break;
		}
	}
	if (G>0 && W>0 &&Y>0 &&P>0){
		cout<<"Four"<<endl;
	}else{
		cout<<"Three"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <cctype>
#include <algorithm>
#include <sstream>
using namespace std;

const float PI = 3.14;

int main()
{
	float n, m; cin >> n >> m;
	vector<int> a(n);

	int pop = 0;
	float all = 0;;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		all += a[i];
	}

	float base = all * (1.0 / (4.0 * m));

	for (int i = 0; i < n; i++) {
		if (a[i] >= base) { 
			pop++; 
		}
	}

	if (pop >= m) cout << "Yes\n";
	else cout << "No\n";
	
	return 0;
}


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

int main(void){
  int a = 0;
  string s; cin >> s;
  for(int i=0; i<4; i++){
    if(s.at(i) == '+') a++;
    else a--;
  }
  cout << a << endl;
  return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

int n,t;
ll dp[3010];
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>t;
    vector<pii> ab(n);

    REP(i,n){
        int a,b;
        cin>>a>>b;
        ab[i].first = a;
        ab[i].second = b;
    }
    sort(ALL(ab));

    fill(dp,dp+3010,-1);
    dp[0] = 0;

    REP(i,n){
        FORR(j,0,t){
            if(dp[j]>=0)
                chmax(dp[min(t,j+ab[i].first)], dp[j] + ab[i].second);
        }   
    }

    ll ans = 0;
    FORR(i,0,t+1){;
        if(dp[i]>=0){
            chmax(ans, dp[i]);
            break;
        }
    }

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

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t K, T;
  cin >> K >> T;
  vector<int64_t> A(T);
  for (int64_t i = 0; i < T; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  cout << max(A[0] - (K - A[0] + 1), 0L) << endl;

  return 0;
}


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



int main(){
    int w, h, n, x, y, a;
    cin >> w >> h >> n;
    vector<int> x_interval(2);
    vector<int> y_interval(2);
    x_interval.at(1) = w;
    y_interval.at(1) = h;

    for (int i = 0; i < n; i++)
    {
        cin >> x >> y >> a;
        if (a == 1)
        {
            x_interval.at(0) = max(x_interval.at(0), x);
            x_interval.at(1) = max(x_interval.at(1), x);
        }
        if (a == 2)
        {
            x_interval.at(0) = min(x_interval.at(0), x);
            x_interval.at(1) = min(x_interval.at(1), x);
        }
        if (a == 3)
        {
            y_interval.at(0) = max(y_interval.at(0), y);
            y_interval.at(1) = max(y_interval.at(1), y);
        }
        if (a == 4)
        {
            y_interval.at(0) = min(y_interval.at(0), y);
            y_interval.at(1) = min(y_interval.at(1), y);
        }
    }

    cout << (x_interval.at(1) - x_interval.at(0)) * (y_interval.at(1) - y_interval.at(0)) << endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#define ll long long
using namespace std;
ll SSS(string str)
{
    int len=str.size();
    ll sum=0;
    for(int i=0;i<len;i++)
    {
        sum=sum*10+(str[i]-'0');
    }
    return sum;
}
ll int search(string s1,ll presum){
	int i;
  	ll k,sum;
  	sum = 0;
  	for (i=1;i<=s1.size();i++){
      	string s2 = s1.substr(0,i);//[0,i)
      	string s3 = s1.substr(i);
      	if (s3==""){
        	s3 = "AC";//---//---//
        }
      	if(i == s1.size()){
        	sum += SSS(s1)+presum;//---
        }else{
            k = SSS(s2);//---
            if (s3=="AC"){
            	sum += k + presum;//--
            }else{
            	sum += search(s3,k + presum);
            }
        }
    }
  	return sum;//
}
int main(){
	ll sum;
  	string s;
  	cin >> s;
  	sum = search(s,0);//dfs
  	cout << sum;
  	return 0;
}


Measured memory_bytes: 256
S = input()
Counter = {"a": 0, "b": 0,"c": 0}
for c in S:
    Counter[c] += 1
# print(Counter)
max_val = max(Counter.values())
min_val = min(Counter.values())
if max_val - min_val <= 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
<?php
list($N, $K) = ints();
echo min($N % $K, $K - $N % $K);

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$N = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}


Measured memory_bytes: 4732
import copy
import math
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort()
A.reverse()
maxX = max(F) * max(A)
def is_able(low, up):
    target = (low + up) // 2
    if low == up - 1:
        return up
    if check(target):
        return is_able(low, target)
    else:
        return is_able(target, up)
def check(time):
    #time が可能かどうか
    practice = copy.deepcopy(k)
    for i in range(n):
        if A[i] * F[i] > time:
            practice -= A[i] - math.floor(time / F[i]) 
            if practice < 0:
                return False
    return True
print(is_able(-1, maxX))

Measured memory_bytes: 120696
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main() { cin.tie(0); ios::sync_with_stdio(false);
    string S; cin >> S;
    if( S[0] == S[1] || S[1] == S[2] || S[2] == S[3] ) {
        cout << "Bad\n";
    } else {
        cout << "Good\n";
    }
}


Measured memory_bytes: 256
mod = 1000000007

def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def f(M, a):
    count = M.count(a)
    if count == 0:
        return 0

    for i in range(2, -1, -1):
        if M[i] == a:
            M[i] += 1
            break

    return count


def main():
    N = int(input())
    A = read_list()

    M = [0, 0, 0]
    res = 1

    for a in A:
        res *= f(M, a)
        res %= mod
        if res == 0:
            print(0)
            return

    print(res % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14032
// 巡回セールスマン問題
// 蟻本p173と同じ。
// 訪問済状態をビットで表すとbitDPで解ける

#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <climits>
#include <cassert>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair


ll INF = 1e18;

// S: これまでたどった頂点  v: 今いる頂点
ll rec(int S, int v,
        const int V,
        vector<vector<ll>>& dp, const vector<vector<ll>>& dist) {
    if (dp[S][v] >= 0) return dp[S][v];
    if (S == (1 << V) - 1 && v == 0) {
        return dp[S][v] = 0;
    }

    ll res = INF;
    REP(u, V) {  // vの次に行く頂点をuとする
        if (!(S & (1 << u))) { // uに未訪問の場合
            auto d = dist[v][u];
            if (d != INF) { // v -> uにエッジが
                res = min(res, rec(S | 1 << u, u, V, dp, dist) + d);
            }
        }
    }
    return dp[S][v] = res;
}

ll travelling_salesman(int V, vector<vector<ll>>& dist) {
    vector<vector<ll>> dp(1<<V, vector<ll>(V, -INF));
    return rec(0, 0, V, dp, dist);
}

int main(){
    int V, E;
    cin >> V >> E;
    vector<vector<ll>> dist(V, vector<ll>(V, INF));
    REP(e, E) {
        int s, t;
        ll d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }
    auto ret = travelling_salesman(V, dist);
    cout << (ret == INF ? -1 : ret) << endl;
}



Measured memory_bytes: 7656
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int n; cin>>n;
  	int color[9]={};
  	for(int i=0;i<n;i++){
      int a; cin>>a;
      if(1<=a and a<400) color[0]++;
      else if(a<800) color[1]++;
      else if(a<1200) color[2]++;
      else if(a<1600) color[3]++;
      else if(a<2000) color[4]++;
      else if(a<2400) color[5]++;
      else if(a<2800) color[6]++;
      else if(a<3200) color[7]++;
      else color[8]++;
    }
  	int ansmin=0,ansmax=0;
  	for(int i=0;i<8;i++){
      if(color[i]>0) ansmin++;
    }
  	ansmax=ansmin+color[8];
  	if(ansmin==0) ansmin++;
  	cout<<ansmin<<" "<<ansmax<<endl;
  	return 0;
}


Measured memory_bytes: 256
// KOI NI YAAR SAB SAHI HOEGA  BAS  CHORRO MAT
// ENJOR KARO YAAR
// HAAR MAT MAANO
// // APNA TIME AAYEGA
// BEILIEVE IN GOD
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double
#define PI  3.14159265358979
#define pri  priority_queue<ll>
#define prim  priority_queue<ll,vector<ll>,greater<ll>>
#define flush  cout<<flush


//lli vis[3000];
//vector<lli>v[3000];

/*void dfs(lli num)
{vis[num]=1;
for(auto itr = v[num].begin();itr!=v[num].end();++itr)
{if(vis[*itr]==0)
{dfs(*itr);
}
}
}*/

lli a[101];



int main()
{ lli n,k;
cin>>n>>k;
loop(i,0,n)
{cin>>a[i];
}
lli dp[n+1][k+1];
lli pf[n+1][k+1];
loop(i,0,k+1)
{if(i<=a[0])
{dp[0][i]=1;
}
else
{dp[0][i]=0;
}
}
loop(i,0,k+1)
{if(i==0)
{pf[0][i]=dp[0][i]%mod;
}
else
{pf[0][i]=(pf[0][i-1]%mod +dp[0][i] %mod)%mod;
}
}

loop(i,1,n)
{loop(j,0,k+1)
{if(j<=a[i])
{dp[i][j]=(pf[i-1][j] %mod);
}
else
{dp[i][j]=(pf[i-1][j] - pf[i-1][j-a[i]-1] + mod)%mod;
}
}
loop(j,0,k+1)
{if(j==0)
{pf[i][j]=dp[i][j]%mod;
}
else
{pf[i][j]=(pf[i][j-1]%mod + dp[i][j]%mod)%mod;
}
}
}
cout<<dp[n-1][k]%mod;
}

Measured memory_bytes: 159768
using System;
using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace _1_A
//{
    class Program
    {
    static void Main(string[] args)
    {
        int time;
        int hour = 0;
        int min = 0;

        time = int.Parse(Console.ReadLine());
        while(time >= 3600)
        {
            time = time - 3600;
            hour = hour + 1;
        }
        while(time >= 60)
        {
            time = time - 60;
            min = min + 1;
        }

        Console.WriteLine(hour + ":" + min + ":" + time);

    }
    }
//}

Measured memory_bytes: 9160
using Yorukatsu045.Questions;
using Yorukatsu045.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu045.Questions
{
    /// <summary>
    /// ABC057 C
    /// </summary>
    public class QuestionD : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadLong();

            var min = int.MaxValue;
            for (long i = 1; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    min = Math.Min(min, F(n / i, i));
                }
            }

            yield return min;
        }

        int F(long a, long b) => Math.Max(F(a), F(b));

        int F(long a)
        {
            var count = 0;
            while (a > 0)
            {
                a /= 10;
                count++;
            }
            return count;
        }
    }
}


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

#region Base Classes

namespace Yorukatsu045.Questions
{

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

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

            return Solve(reader);
        }

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

}

#endregion

#region Extensions

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

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

#endregion

Measured memory_bytes: 13140
#include <stdio.h>
int main(void){
    long int ans[50],temp,n,i=0,j;
    while(scanf("%d",&n)!=EOF){
        temp=0;
        if(n<=1000){
            ans[i]=(n+3)*(n+2)*(n+1)/6;
        } else if (n<=2000) {
            for(j=0;j<n-1000;j++) temp+=2*(j+2)*(j+1);
            ans[i]=(n+3)*(n+2)*(n+1)/6 - temp;
        } else if(n<3000){
            for(j=0;j<3000-n;j++) temp+=2*(j+2)*(j+1);
            ans[i] = (4003-n)*(4002-n)*(4001-n)/6 - temp;
        } else {
            ans[i]= (4003-n)*(4002-n)*(4001-n)/6;
        }
        i++;
    }
    for(j=0;j<i;j++) printf("%d\n",ans[j]);
    return 0;
}

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

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  int sum = 0;
  for(int i=0; i<M; i++){
    int temp;
    cin >> temp;
    sum += temp;
    if(sum > N){
      cout << -1 << endl;
      return 0;
    }
  }
  
  cout << N - sum << endl;
  return 0;
}

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

int main(){
	int k;
	int ans = 0;
	cin >> k;
	//gcd(a,b,c) == gcd(gcd(a,b),c)
	for(int a = 1;a <= k;a++){
		for(int b = 1;b <= k;b++){
			for(int c = 1;c <= k;c++){
				ans += gcd(gcd(a,b),c);
			}
		}
	}
	cout << ans << endl;
}

int gcd(int p,int q){
	while(q != 0){
		int r = p % q;
		p = q;
		q = r;
	}
	return p;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

const int N = 1e2 + 10;

int a[N], n;

void trace(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        if(i > 0) cout << ' ';
        cout << a[i];
    }
    cout << endl;
}

void insertionSort(int a[], int n)
{
    int i, v, j;
    for(int i = 1; i < n; i++)
    {
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v)
        {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        trace(a, n);
    }
}

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

    cin >> n;

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

    trace(a, n);
    insertionSort(a,n);

    return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<int> A(N+1);
    ll c=1000;
    ll k=0;
    int t=0;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    A[N]=0;
    for(int i=0;i<N;i++){
        cerr << "i=" << i << "\t" << k << " " << c << endl;
        if(A[i]<=A[i+1]){
            // 株にする
            c += A[i]*k;
            k = c/A[i];
            c -= A[i]*k;
        }else{
            // 金にする
            c += A[i]*k;
            k=0;
        }
    }
    cerr << k << " " << c << endl;
    cout << k*A[N-1]+c << endl;
    return 0;
}


Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#include <stdio.h>
#define ll long long
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー

int length(char* str) {
	int len = strlen(str);
	return len;
}

int main()
{
	int A, B;
	cin >> A >> B;
	if (A % B == 0) {
		cout << '0';
		return 0;
	}
	cout << '1';
}


Measured memory_bytes: 256
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec replicate n f =
  if n = 0 then []
  else let h = f () in h :: replicate (n-1) f

let solve n m graph =
  let pos = Array.make n None in
  let rec visit v p x =
    Array.fold_left (fun res (w, d) ->
      if not res then false
      else
        match pos.(w) with
        | None   -> pos.(w) <- Some (x + d); visit w v (x+d)
        | Some y -> y = x + d
    ) true graph.(v) in
  List.fold_left (fun res v ->
    if not res then false else
      match pos.(v) with
      | None -> visit v (-1) 0
      | Some _ -> true
  ) true (range 0 n)

let () =
  let [n; m] = read_ints 2 in
  let idcs = Array.make n 0 in
  let edges = replicate m (fun () ->
    let [l; r; d] = read_ints 3 in
    idcs.(l-1) <- idcs.(l-1) + 1;
    idcs.(r-1) <- idcs.(r-1) + 1;
    (l-1, r-1, d)) in
  let graph = Array.init n (fun i -> Array.make idcs.(i) (-1, -1)) in
  Array.fill idcs 0 n 0;
  flip List.iter edges (fun (l, r, d) ->
    graph.(l).(idcs.(l)) <- (r, d);
    graph.(r).(idcs.(r)) <- (l, -d);
    idcs.(l) <- idcs.(l) + 1;
    idcs.(r) <- idcs.(r) + 1;
  );
  let result = solve n m graph in
  printf "%s\n" (if result then "Yes" else "No")


Measured memory_bytes: 42236
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <set>

using namespace std;

int main()
{
    int A, B, C, D, E, F;
    if (scanf("%d%d%d%d%d%d", &A, &B, &C, &D, &E, &F) < 6) return 0;

    set<int> sugar;
    for (int i = 0; i <= F; i++)
    {
        for (int j = 0; j <= F; j++)
        {
            int s = C * i + D * j;
            if (s <= F) sugar.insert(s);
        }
    }

    set<int> water;
    for (int i = 0; i <= F; i++)
    {
        for (int j = 0; j <= F; j++)
        {
            int w = 100 * (i * A + j * B);
            if (w <= F) water.insert(w);
        }
    }

    double conc = 0.0;
    int sw = 0;
    int sg = 0;
    for (auto s = sugar.begin(); s != sugar.end(); s++)
    {
        for (auto w = water.begin(); w != water.end(); w++)
        {
            double now = 0.0;
            if (0 < *s + *w) now = (double) 100.0 * *s / (*s + *w);
            if (*s + *w <= F
                && now <= (double) 100.0 * E / (100.0 + E)
                    && conc <= now)
            {
                conc = now;
                sw = *s + *w;
                sg = *s;
            }
        }
    }

    printf("%d %d", sw, sg);
    return 0;
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;

    vector<int> schL(1, -1);  // 仕事を前に詰めたときの仕事日
    vector<int> schR(1, N);   // 仕事を後ろに 〃

    for (int i = 0; i < N; ++i) {
        if ((int)schL.size() == K + 1) break;
        if (S[i] == 'o') {
            schL.push_back(i);
            i += C;
        }
    }

    for (int i = N - 1; i >= 0; --i) {
        if ((int)schR.size() == K + 1) break;
        if (S[i] == 'o') {
            schR.push_back(i);
            i -= C;
        }
    }

    vector<int> flag(N + 1, 0);  // flag[i] > 0 -> 働かなくても良い日

    for (int i = 0; i <= K; ++i) {
        int l = i, r = K - i;
        flag[schL[l] + 1]++;
        flag[schR[r]]--;
    }
    for (int i = 1; i < N; ++i) { flag[i] += flag[i - 1]; }

    for (int i = 0; i < N; ++i) {
        if (S[i] == 'o' && flag[i] == 0) cout << i + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5748