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

int isPower(int a, int d);

int main(void){
  int i,j,k;
  int n,d;
  int sum=0;
  int count=0;

  scanf("%d %d",&n, &d);
  int x[n][d];

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

  for(i=0; i<n-1; i++){
    for(j=i+1; j<n; j++){
      //x[i][]とx[i+1][],x[i+2][],...,x[n-1][]の比較
      sum=0;
      for(k=0; k<d; k++){
        //x[i][]とx[j][]の比較
        //n乗根にする前の値
        sum+=pow(x[i][k]-x[j][k],2);
        //sumがd乗根だったらcount++
        // printf("i=%d j=%d k=%d\n", i,j,k);
        // printf("x[i][k]-x[j][k]=%d\n", x[i][k]-x[j][k]);
      }
      // printf("sum=%d\n", sum);
      if(isPower(sum, 2)) count++;
    }
  }

  printf("%d\n", count);
  return 0;
}

int isPower(int a, int d){
  int r=1;
  int num;

  while(1){
    num=pow(r,d);
    if(a<num) return 0;
    if(a==num) return 1;
    r++;
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("input.txt");ofstream coutt("output.txt");

int f(int n,int k){
    return n/k;
}

signed main(){
    FASTER;
    int k,a,b;cin>>k>>a>>b;
    if(f(b,k)-f(a-1,k)>0){
        cout<<"OK";
    }else cout<<"NG";
}

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

int main(void){
    vector<long> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end());
    long count=0;
    do{
        long d0 = v[2]-v[0];
        long d1 = v[2]-v[1];
        if(d0%2==1 && d1%2==1){
            v[0]++;
            v[1]++;
            count++;
        }else if(d0%2==1 && d1%2==0){
            v[1]++;
            v[2]++;
            count++;
        }else if(d0%2==0 && d1%2==1){
            v[0]++;
            v[2]++;
            count++;
        }
    }while(!((v[2]-v[0])%2==0 && (v[2]-v[1])%2==0));
    count += (v[2]-v[0])/2+(v[2]-v[1])/2;
    cout << count << endl;
    return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	
	int n;cin >> n;
	
	if(n == 7 || n == 5 || n == 3){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	int a;
	cin >> a;
	cout << a/3 << endl;
}


Measured memory_bytes: 764
N = int(input())
n = []
R = []
for i in range(N+1):
    if i % 2 != 0 and i != 1:
        n.append(i)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
for x in n:
    a = factorization(x)
    b = []
    for y in range(len(a)):
        b.append(a[y][1] + 1)
    import functools
    import operator
    result = functools.reduce(operator.mul, b)
    if result == 8:
        R.append(x)
print(len(R))


Measured memory_bytes: 3572
s=0
A,B=map(int,input().split())
if abs(A-B)<30:
  for i in range(A,B+1):
    s=s^i
  print(s)
else:
  c=A//4
  L=range(A,4*(c+1))
  for i in L:
    s=s^i
  c=B//4
  L=range(4*(c-1),B+1)
  for i in L:
    s=s^i
  print(s)

Measured memory_bytes: 9092
#include<stdio.h>
int main()
{
	int i,n;
	int s[1000];
	int a,b,c,d;
	int x,y,z;
	scanf("%d%d%d",&a,&b,&c);
	for(i=0;i<100;i++)
	{
		if(a%2==0&&b%2==0&&c%2==0)
		{
			x=a/2;
			y=b/2;
			z=c/2;
			a=y+z;
			b=x+z;
			c=x+y;
		}
		else break;	
	}
	n=i;
	if(n==100)printf("-1");
	else printf("%d",n);
	return 0;
}

Measured memory_bytes: 128
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    X = int(input())

    res = 1000 * (X // 500)
    X %= 500
    res += 5 * (X // 5)

    print(res)



main()


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUF_SIZE 100100
int main(void) {

  char line[BUF_SIZE] = {0};
  FILE* fp = stdin;
  if(!fgets(line, BUF_SIZE, fp)) return 0;

  char *tmp;
  for(tmp = line; *tmp !='\n'; ) {
    int step = 0;
    if(!strncmp(tmp, "dream", 5)) {
      if(tmp[5] == 'e' && tmp[6] == 'r') {
        // in case that dreameraser
        if(tmp[7] == 'a') {
          step = 5;
        } else {
          step = 7;
        }
      } else {
        step = 5;
      }
    } else if (!strncmp(tmp, "erase", 5)) {
      step = (tmp[5] == 'r') ? 6 : 5;
    }
    if(!step) {
      printf("NO\n");
      return 0;
    }
    tmp += step;
  }
  printf("YES\n");
  return 0;
}

Measured memory_bytes: 256
x = list(input().split())
for i in range(5):
#    logging.debug("i = {},x[i] = {}".format(i, x[i])) #
    if x[i] == "0":
        print(i + 1)
        exit()

#    logging.debug("n = {},f = {},f**b = {}".format(n, f, f**b))  #
#logging.debug("デバッグ終了")#

Measured memory_bytes: 8916
//%std
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
int main()
{
	int k=read()*500,x=read();
	if(k>=x)
		puts("Yes");
	else
		puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
int main() {
    cin>>n;
    cout<<(n-2)*180<<endl;
    return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;

  if(abs(a-b)%2==1)
    cout << "IMPOSSIBLE";

  else
    cout << min(a,b)+abs(a-b)/2;;

  return 0;
}


Measured memory_bytes: 256
import itertools
n = int(input())
ps = tuple(input().split())
qs = tuple(input().split())

s = [str(i) for i in range(1, n+1)]
s_list = list(itertools.permutations(s))
# print(s_list)
# print(s_list.index(ps))
print(abs(s_list.index(ps) - s_list.index(qs)))


Measured memory_bytes: 8052
#include <iostream>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if (a >= 13)
    {
        cout << b << endl;
    }
    else if (a >= 6)
    {
        cout << (b / 2) << endl;
    }
    else
    {
        cout << "0" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#define INF 1000000000000
using namespace std;
using ll = long long;
int main(){
    vector<ll> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    cout << (a[0]*a[1])/2 << endl;
}

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

using namespace std;


int main(){
    int N, D, X;
    cin >> N >> D >> X;

    int ans = X;
    for (int i = 0; i < N; i++){
        int A; cin >> A;
        ans += D / A;
        if (D % A != 0){
            ans++;
        }
    }
      
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  string s;
  cin >> s;
  int ans = INF;
  for (int i = 0; i < s.size() - 2; i++) {
    ans = min(ans, abs(753 - stoi(s.substr(i, 3))));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/* it was worth becoming a chemist */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "cardgame"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

int n;
ll a[MAXN], b[MAXN];
ll sum;

int main() {	
    // #ifndef ONLINE_JUDGE
	//~ freopen(NAME".in", "r", stdin);
    //~ freopen(NAME".out", "w", stdout);
    // #endif

    
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = n; i >= 1; i--) {
		ll y = ((a[i] + sum) / b[i]) + (ll)((a[i] + sum) % b[i] != 0);
		ll x = y * b[i] - (a[i] + sum);
		sum += x;
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 1792
n=int(input())
l=["a","b","c","d","e","f","g","h","i","j"]
a="a"
ans=["a"]
for i in range(1,n):
    tt=[]
    for j in ans:
        s=len(set(j))
        for k in range(s+1):
            tt.append(j+l[k])
    ans=tt
ans.sort()
for i in ans:
    print(i)

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

int main() {
    int S;
    cin >> S;
    int h = S/3600;
    int m = (S-h*3600)/60;
    int s = S-h*3600-m*60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}



Measured memory_bytes: 3116
package main
import (
  "fmt"
)
func main() {
  var n int
  fmt.Scan(&n)
  as := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&as[i])
  }
  bs := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&bs[i])
  }
  cs := make([]int, n-1)
  for i := 0; i < n-1; i++ {
    fmt.Scan(&cs[i])
  }
  result := 0
  for i, a := range as {
    result += bs[a-1]
    if i != 0 && as[i-1] + 1 == a {
      result += cs[as[i-1]-1]
    }
  }
  fmt.Println(result)

}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
string S;
	cin >> S;
	int ans = 0;
	fx(S.size()) {
		ans++;
		if (x+1<S.size()&&S[x]==S[x+1]) {
			x+=2;
			if (x<S.size()) {
				ans++;
			}

		}
	}
	ce(ans)

    return 0;
}



Measured memory_bytes: 640
n, k = map(int, input().split())

d = [0] * k
a = [0] * k
sunuke = [0] * n

for i in range(k):
    d[i] = int(input())
    a[i] = list(map(int, input().strip().split()))
    for j in range(len(a[i])):
        sunuke[a[i][j]-1] = sunuke[a[i][j]-1] + 1

print(sunuke.count(0))


Measured memory_bytes: 9136
h,w = gets.chomp.split(" ").map(&:to_i)
a = h.times.map{gets.chomp}
c = Hash.new(0)
for i in 0..h-1
  for j in 0..w-1
    c[a[i][j]] += 1
  end
end
c = c.values.map{|i|i%4}
d = c.count{|i|i%2 == 1}
e = c.count(2)
if (h%2 == 0 && w%2 == 0 && d == 0 && e == 0) || (h%2 == 1 && w%2 == 1 && d == 1 && e <= h/2+w/2) || ((h%2+w%2 == 1 && d == 0 && e <= (h/2)*(w%2)+(w/2)*(h%2)))
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String S1 = S.substring(N / 2);
		String S2 = S.substring(0, N / 2);
		String S3 = S1 + S2;
		sc.close();
		if (N % 2 == 1) {
			System.out.println("No");
		} else {
			if (S.equals(S3)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

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

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

    int ans = 100;

    for (int64_t a = 1; a <= floor(sqrt(n) + 1); a++) {
        if (n % a != 0) {
            continue;
        }

        else {
            int64_t b = n / a;

            int64_t c = max(a, b);
            int d = 0;
            while (c > 0) {
                c /= 10;
                d += 1;
            }
            ans = min(ans, d);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
k=gets.to_i
q=[1,2,3,4,5,6,7,8,9]
while k>0
  s=q.shift
  q << s*10+s%10-1 if s%10>0
  q << s*10+s%10
  q << s*10+s%10+1 if s%10<9
  k-=1
end
puts s


Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

int parent[100010], sz[100010]; // サイズを忘れずに入れる

int root(int a)
{
    if(parent[a]==a)    return a;
    else    return (parent[a]=root(parent[a]));
}

bool same_set(int a, int b)
{
    return (root(a)==root(b));
}

void unite(int a, int b)
{
    if(root(a)!=root(b))
    {
        if(sz[root(a)]<sz[root(b)]) swap(a, b);
        sz[root(a)]+=sz[root(b)];
        parent[root(b)]=root(a);
    }
}

int main()
{
	pai a[100010], b[100010];
	int x, y, n;
	cin >> n;
	rep(i, n)
	{
		cin >> x >> y;
		a[i]=make_pair(x, i+1);
		b[i]=make_pair(y, i+1);
	}
	sort(a, a+n);
	sort(b, b+n);
	pair<int, pair<int, int>> edge[200010];
	rep(i, n-1)
	{
		edge[2*i]=make_pair(a[i+1].first-a[i].first, make_pair(a[i].second, a[i+1].second));
		edge[2*i+1]=make_pair(b[i+1].first-b[i].first, make_pair(b[i].second, b[i+1].second));
	}
	sort(edge, edge+(2*n-2));

	reps(i, n)
    {
        parent[i]=i;
        sz[i]=1;
    }
    ll ans=0;
    int cnt=0;
    rep(i, 2*n-2)
    {
    	pai p=edge[i].second;
    	if(!same_set(p.first, p.second))
    	{
    		unite(p.first, p.second);
    		ans+=edge[i].first;
    		cnt++;
    		if(cnt==n-1) break;
    	}
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
import math

Q = int(input())
Query = []
for i in range(Q):
    Query.append(tuple(map(int, input().split())))
for a, b in Query:
    sq = int(math.sqrt(a * b))
    ans = sq * 2 - 1
    if a == b:
        ans -= 1
    elif sq ** 2 == a * b:
        ans -= 2
    elif sq * (sq + 1) >= a * b:
        ans -= 1
    print(ans)


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

int n, m;
const int MAX = 55;
bool G[MAX][MAX], used[MAX];
int A[MAX], B[MAX];

void dfs(int now){
    used[now] = true;
    for(int i = 0; i < n; i++){
        if(!used[i] && G[now][i]){
            dfs(i);
        }
    }
    return;
}

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

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        G[A[i]][B[i]] = true;
        G[B[i]][A[i]] = true;
    }

    int ans = 0;
    for(int i = 0; i < m; i++){
        G[A[i]][B[i]] = false;
        G[B[i]][A[i]] = false;
    
        for(int j = 0; j < n; j++){
            used[j] = false;
        }

        dfs(0);

        bool f = false;
        for(int j = 0; j < n; j++){
            if(used[j] == false) f = true;
        }

        if(f) ans++;

        G[A[i]][B[i]] = true;
        G[B[i]][A[i]] = true;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPX(op, t, x) operator op(CRP(t, x))
#define OPL(t, x) bool OPX(<, t, x) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef int64_t ll, i64;
typedef uint64_t ull, u64;
template <typename T>
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
template <typename T>
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
inline char getchar(int)
{
    static char buf[64 << 20], *S = buf, *T = buf;
    if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + S;
    return S == T ? EOF : *S++;
}
template <typename T, typename = enable_if_integral<T>>
inline void read(T &x)
{
    int ch = x = 0, f = 1;
    while (!isdigit(ch = getchar()))
        if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}
template <typename T, typename... Args, typename = enable_if_integral<T>>
inline void read(T &x, Args &... args) { read(x), read(args...); }
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fpow(ll a, ll b, ll m)
{
    ll r = 1;
    for (; b; b >>= 1, a = a * a % m)
        if (b & 1) r = r * a % m;
    return r;
}
constexpr double eps = 1e-8;
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
int l[10];
int st[10];
int main()
{
    int n, A, B, C, ans = INT_MAX;
    read(n, A, B, C);
    for (int i = 0; i < n; i++) read(l[i]);
    for (int i = 0; i < (1 << (n << 1)); i++)
    {
        for (int j = 0; j < n; j++) st[j] = i >> (j << 1) & 3;
        int a = 0, b = 0, c = 0;
        int ca = 0, cb = 0, cc = 0;
        for (int j = 0; j < n; j++) switch (st[j])
            {
            case 1:
                a += l[j], ca++;
                break;
            case 2:
                b += l[j], cb++;
                break;
            case 3:
                c += l[j], cc++;
                break;
            }
        if (!ca || !cb || !cc) continue;
        ans = min(ans, abs(A - a) + abs(B - b) + abs(C - c) + 10 * (ca + cb + cc - 3));
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let (n, k) = Scanf.sscanf (read_line ()) "%d %d" @@ fun n k -> (n, k)
let p = read_line () |> split_string ~pattern:" " |> List.map int_of_string

let rec take res n acc = match (n, acc) with
  | (_, []) | (0, _) -> List.rev res
  | (i, x :: xs) -> take (x :: res) (n - 1) xs
let take = take []

let () = p 
  |> List.sort compare
  |> take k
  |> List.fold_left (+) 0
  |> Printf.printf "%d\n"

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

using namespace std;
int a[200010];

int main(){
    int n,m;
    cin>>n;
    for(int i=2;i<=n;i++){
        cin>>m;
        a[m]++;
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",a[i]);
    return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int a, b;
  cin >> a >> b;
  int n = b - a;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans += i;
  } 
  dump(a, b, n);
  cout << ans - a << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io;
use std::io::BufRead;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let n: usize = sc.next().unwrap();
    let mut a: Vec<i64> = vec![];

    for i in 0..n {
        let m:i64 = sc.next().unwrap();
        a.push(m - (i as i64));
    }
    a.sort();
    let m = a[n/2];
    let mut res = 0;
    for i in 0..n {
        res += (m - a[i]).abs()
    }

    println!("{}", res);
}

/// Scanner
///
/// # Example
/// ```
/// use contest::io::scanner;
/// let mut sc = scanner::Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
/// assert_eq!("1".to_string(), sc.next::<String>().unwrap());
/// assert_eq!(2, sc.next());
/// assert_eq!(3.5, sc.next());
/// assert_eq!(None, sc.next::<i32>());
/// ```

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

impl<R: io::Read> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> Option<T>
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: "))
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}


Measured memory_bytes: 16248
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,cnt=0;
  cin>>a>>b>>c;
  if(a%2!=b%2&&a%2!=c%2){ 
    a--;cnt++;
  }else if(a%2!=b%2&&b%2!=c%2){ 
    b--;cnt++;
  }else if(a%2!=c%2&&b%2!=c%2){ 
    c--;cnt++;
  }
  int mx=max({a,b,c});
  cnt+=(mx-a)/2;
  cnt+=(mx-b)/2;
  cnt+=(mx-c)/2;
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

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

bool option(pair<int, int>& a, pair<int, int>& b) {
    return a.second < b.second;
}

int main() {
    bool f = true;
    int n, tmp;
    map<int, int> a;
    map<int, int>::iterator it;

    cin >> n;

    rep(0, n) {
        cin >> tmp;
        a[tmp]++;
    }

    for (it = a.begin(); it != a.end(); it++) {
        if (it->second > 1) {
            f = !f;
            break;
        }
    }

    cout << ((f) ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 13008
n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

ans = r_cnt * g_cnt * b_cnt

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

print(ans)


Measured memory_bytes: 9200
def operation(N,point):
    N_another = []
    for i in N:
        count = 0
        for j in N:
            if i==j:
                count +=1
        N_another.append(count)
    if N==N_another:return N,point
    else:return operation(N_another,point+1)
while 1:
    num=int(input())
    if num==0:break
    N=list(map(int,input().split()))
    answer_1,answer_2=operation(N,0)
    print(answer_2)
    print(*answer_1)


Measured memory_bytes: 5596
def answer(n: int) -> str:
    temp = n
    sum_of_digits = 0

    while 0 < temp:
        temp, mod = divmod(temp, 10)
        sum_of_digits += mod

    return 'Yes' if n % sum_of_digits == 0 else 'No'


def main():
    n = int(input())
    print(answer(n))


if __name__ == '__main__':
    main()

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

int main(){
    int n;cin>>n;
    string s;cin>>s;
    int k;cin>>k;

    char target = s[k-1];
    for (auto c : s){
        if (c != target){
            cout << "*";
        } else {
            cout << c;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_debug;
#define debug(x) cout << "Case : " << #x << " " << x 
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define vi vector<ll>
#define vll vector<ll> 
#define ss second
#define inf 1000000000

int main()
{
    ll n,a,b;
    cin >> n >> a >> b;
    if(b < a)swap(a,b);

    if((b-a)%2 == 0)
    {
        cout << (b-a)/2;
    }
    else
    {
        ll num1 = min(a-1 , n-b);
        cout << (num1) + 1 +(b-a-1)/2;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[1000000];
long long int  cnt = 0;
void insertionSort(int b[], int n, int g) {
	for (int i = 0; i < n; i++) {
		int k = b[i];
		int m = i;
		for (int j = i-g; j >= 0; j=j-g) {
			if (b[j] <= k) break;					//=号要搞上
			m = j;
			b[j + g] = b[j];
			cnt++;
		}
		b[m] = k;
	}
}
void shellSort(int b[], int n) {
	int G[100000];
	int all = 0;
	for (int i = 1; i <= n; i = i * 3 + 1) {				//n可以取等
		G[all++] = i;
	}
	cout << all << endl;
	for (int i = all - 1; i >= 0; i--) {
		cout << G[i];
		if(i!=0)cout<< " ";
		insertionSort(b, n, G[i]);
	}
	cout << endl;
	cout << cnt << endl;
}
int main(void) {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	shellSort(a, n);
	for (int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
}


Measured memory_bytes: 7004
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

ll originalMerge(vector<int> &as, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> l(n1 + 1), r(n2 + 1);

    int i, j;
    ll cnt;
    rep(i, n1) l[i] = as[left + i];
    rep(i, n2) r[i] = as[mid + i];
    l[n1] = INT_MAX;
    r[n2] = INT_MAX;
    i = 0; j = 0; cnt = 0;
    for (int k = left; k < right; ++k) {
        if (l[i] <= r[j]) {
            as[k] = l[i];
            i++;
        }
        else {
            as[k] = r[j];
            j++;
            cnt += n1 - i;
        }
    }
    return cnt;
}

ll mergeSort(vector<int> &as, int left, int right) {
    ll cnt = 0;
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        cnt += mergeSort(as, left, mid);
        cnt += mergeSort(as, mid, right);
        cnt += originalMerge(as, left, mid, right);
    }
    return cnt;
}

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

    int n;
    cin>>n;
    vector<int> as(n);
    rep(i, n) cin>>as[i];

    ll cnt = mergeSort(as, 0, n);
    cout<<cnt<<endl;
}


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

using namespace std;

int main()
{
    int n , k ;
    cin>>n>>k ;
    int ans = 1 ;
    for(int i = 0 ; i < n ; ++i)
        ans = min(ans + k , ans*2);
    cout<<ans;
    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x,t;
    int t1=0;
    cin >> n >> x >> t;
    while(n>0){
            t1=t1+t;
            n=n-x;
    }
    cout << t1;
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
int n;
string a,b,c;

int main(){
    cin >> n;
    cin >> a >> b >> c;

    ll ans = 0;
    for(int i = 0; i < n; i++){
        char mem1,mem2,mem3;
        mem1 = a[i];
        mem2 = b[i];
        mem3 = c[i];

        if(mem1 == mem2 && mem1 == mem3){
            continue;
        }
        if(mem1 == mem2 || mem1 == mem3 || mem2 == mem3){
            ++ans;
        }
        else{
            ans += 2;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
import math, sys
from collections import Counter
inputs = iter(sys.stdin.readlines())
n = int(next(inputs))
cnt = Counter([next(inputs).rstrip() for _ in range(n)])
print(f'AC x {cnt["AC"]}')
print(f'WA x {cnt["WA"]}')
print(f'TLE x {cnt["TLE"]}')
print(f'RE x {cnt["RE"]}')

Measured memory_bytes: 23648
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int test(int64_t N, int64_t T, int64_t *A);
int main(void) {
    char *buf;
    char *p;
    int64_t N, T, *A;
    int i,cnt = 0;

    buf = (char*)malloc(32);
    p = fgets(buf, 32, stdin);
    (void)sscanf(buf, "%ld %ld", &N, &T);
    buf = (char*)realloc((void*)buf, 11 * N + 3);
    A = (int64_t*)malloc(sizeof(int64_t) * N);
    p = fgets(buf, 11 * N + 3, stdin);
    for(i=0;;i++){
        if(buf[i] == ' ') {
            buf[i] = '\0';
            A[cnt++] = strtol(p, 0, 0);
            p = &buf[i+1];
        } else if((buf[i] < '0') || (buf[i] > '9')){
            A[cnt++] = strtol(p, 0, 0);
            break;
        }
    }

    cnt = test(N, T, A);
    printf("%d\n", cnt);

    free(buf);
    return 0;
}

int test(int64_t N, int64_t T, int64_t *A) {
    int maxpos = -1;
    int64_t curmax = -1;
    int64_t diffmax = -1;
    int64_t diffmaxpos = -1;
    int64_t diffminpos = -1;
    int i,cnt = 0;

    // 後ろから最大差分を探す
    for(i=N-1;i>=0;i--){
        if(curmax < A[i]) {
            curmax = A[i];
        } else if(diffmax < (curmax - A[i])) {
            diffmaxpos = maxpos;
            diffminpos = i;
            diffmax = curmax - A[i];
        }
    }

    // このパターンは条件的に無い
//    if(diffmax <= 0) { 
//        return 0;
//    }

    // 最大差分の組が何個あるか
    curmax = -1;
    for(i=N-1;i>=0;i--) {
        if(curmax < A[i]) {
            curmax = A[i];
        } else if(diffmax == (curmax - A[i])) {
            cnt++;
        }
    }

    return cnt;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back 
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k))
#define ll long long
#define ls root*2
#define rs root*2+1
int rd()
{
    int sum = 0;char c = getchar();bool flag = true;
    while(c < '0' || c > '9') {if(c == '-') flag = false;c = getchar();}
    while(c >= '0' && c <= '9') sum = sum * 10 + c - 48,c = getchar();
    if(flag) return sum;
    else return -sum;
}
const int p = 1e9+7;
const int INF = 1e9;
int n,k;
int a[501000],b[501000],du[501000];
int ans[501000];
int tr[2001000];
int linkk[501000],t;
struct node{int n,y;}e[1001000];
void add(int root,int l,int r,int pl,int v)
{
    if(l == r) {tr[root] = v;return;}
    int mid = l+r>>1;
    if(pl <= mid) add(ls,l,mid,pl,v);
    else add(rs,mid+1,r,pl,v);
    tr[root] = min(tr[ls],tr[rs]);
}
void dele(int root,int l,int r,int pl)
{
    if(l == r) {tr[root] = INF;return;}
    int mid = l+r>>1;
    if(pl <= mid) dele(ls,l,mid,pl);
    else dele(rs,mid+1,r,pl);
    tr[root] = min(tr[ls],tr[rs]);
}
int ask(int root,int l,int r,int x,int y)
{
    if(l > y || r < x) return INF;
    if(x <= l && r <= y) return tr[root];
    int mid = l+r>>1;
    return min(ask(ls,l,mid,x,y),ask(rs,mid+1,r,x,y));
}
void insert(int x,int y)
{
    e[++t].y = y;e[t].n = linkk[x];linkk[x] = t;du[y]++;
}
priority_queue<int>q;
int main()
{
  //  freopen("hehe.in","r",stdin);
  //  freopen("dream.out","w",stdout);
    n = rd();k = rd();rep(i,1,n) a[i] = rd(),b[a[i]] = i;
    memset(tr,10,sizeof(tr));
    if(k == 1)
    {
        rep(i,1,n) printf("%d\n",i);
        return 0;
    }
    rep(i,1,n) add(1,1,n,b[i],i);
    rep(i,1,n)
    {
        int t = ask(1,1,n,b[i]-k+1,b[i]-1);
        if(t > i && t <= n)insert(b[i],b[t]);
        t = ask(1,1,n,b[i]+1,b[i]+k);
        if(t > i && t <= n)insert(b[i],b[t]);
        dele(1,1,n,b[i]);
    }
    rep(i,1,n) if(du[i] == 0) q.push(-i);
    int tot = 0;
    while(!q.empty())
    {
        ans[-q.top()] = ++tot;
        int x = -q.top();q.pop();
        for(int i = linkk[x];i;i = e[i].n) 
        {
            du[e[i].y]--;
            if(du[e[i].y] == 0) q.push(-e[i].y);
        }
    }
    rep(i,1,n) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 29560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(0,c-(a-b))<<endl;
}

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

struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<string, int> SP;
#define rep(i, n) for(int i = 0; i < n; ++i)

const int INF = 1e9 + 7;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // vvvi V (50, vvi(50, vi(2500)));

    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    int sum = 0;
    rep(i, M){
        int tmp;
        cin >> tmp;
        sum += tmp;
    }

    if(sum > N){
        cout << -1 << endl;
    }
    else{
        cout << N - sum << endl;
    }

    return 0;
}

Measured memory_bytes: 3692
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        char[] c = new char[4];
        
        int count = 1;
        boolean flag = true;
        for (int i = 0; i < s.length(); i++) {
            count = 1;
            for (int j = 0; j < s.length(); j++) {
                if (i == j) continue;
                if (s.charAt(i) == s.charAt(j)) {
                    count++;
                }
            }
            if (count != 2) {
                flag = false;
                break;
            }
        }
        
        
        System.out.println(flag?"Yes":"No");
    }
}





Measured memory_bytes: 21332
// #include "stdc++.h"
#include <bits/stdc++.h>
using namespace std;
 
#define get(a) scanf("%lld", &a);
#define print(a) printf("%lld",a)
#define println(a) printf("%lld\n",a)
 
#define do(i,a) for(long long i = 0; i < a; i++)
#define loop() for(;;) 
#define done return 0
 
long long n,ans,
          R,G,B,
          lastR = -1, lastG = -1, lastB = -1, D;
 
bool r,g,b;
 
string s;
 
int main() {
    // printf("...\n");
    get(n);
    cin >> s;
    // n = 39;
    // s = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB";
    do(i,n) if (s[i]=='R') R++; else if (s[i]=='G') G++; else if (s[i]=='B') B++;
    
    ans = R * G * B;
    do(i,n/2+1) {
        for (long long j = 2*(i); j < n; j++) {
            r = 0;
            g = 0;
            b = 0;
            if (s[j]=='R' || s[j-i]=='R' || s[j-2*i]=='R') r = true;
            if (s[j]=='G' || s[j-i]=='G' || s[j-2*i]=='G') g = true;
            if (s[j]=='B' || s[j-i]=='B' || s[j-2*i]=='B') b = true;
            if (r && g && b) ans--;
        }
    }
 
    print(ans);
 
}

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

int n,k;

int main() {
	scanf("%d%d",&n,&k);
	if(k&1) {
		int tmp=n/k;
		printf("%lld\n",1ll*tmp*tmp*tmp);
	}
	else {
		int foo=n/k,bar=(n+(k/2))/k;
		printf("%lld\n",1ll*foo*foo*foo+1ll*bar*bar*bar);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

using ull = unsigned long long;
using vi = vector<int>;
using vs = vector<string>;
using vull = vector<ull>;

#define FO(i,a,b) for(int i=(a);i<=(b);i++)
#define rFO(i,a,b) for(int i=(b);i>=(a);i--)
#define SO(a) sort((a).begin,(a).end);
#define rSO(a) sort((a).rbegin,(a).rend);
#define yn(a) cout <<((a)?"Yes":"No")<<endl;

int isP(int n) {
    if(n<=1) return 0;
    FO(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    int yc=0;
    vi x(2);
    vi xx(2);
    cin >>x[0]>>x[1];
    FO(i,0,1) {
        if(x[i]==1) xx[i]=0;
        if(x[i]==2) xx[i]=2;
        if(x[i]==3) xx[i]=0;
        if(x[i]==4) xx[i]=1;
        if(x[i]==5) xx[i]=0;
        if(x[i]==6) xx[i]=1;
        if(x[i]==7) xx[i]=0;
        if(x[i]==8) xx[i]=0;
        if(x[i]==9) xx[i]=1;
        if(x[i]==10) xx[i]=0;
        if(x[i]==11) xx[i]=1;
        if(x[i]==12) xx[i]=0;
    }
    
    yn(xx[0]==xx[1]);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
char maze[100][100];
int main() {
  int h, w;
  cin >> h >> w;
  vector<P> rec;

  rep(i,h) rep(j,w) {
    char c; cin >> c;
    maze[i][j] = c;
    if (c == '#') rec.push_back(make_pair(i,j));
  }

  int dx[4] = {0,-1,0,1}, dy[4] = {1,0,-1,0};
  rep(i,rec.size()) {
    int x = rec[i].first, y = rec[i].second;
    bool can = false;
    rep(j,4) {
      int nx = x + dx[j], ny = y + dy[j];
      if (0<=nx&&nx<h&&0<=ny&&ny<w&&maze[nx][ny]=='#') {can = true; break;}
    }
    if (!can) {cout << "No" << endl; return 0;}
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3652
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  return strShift()[0]+strShift()[1]+strShift()[2];
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
ant
obe
rec
`);

Measured memory_bytes: 7372
using System;
class Program{
	static void Main(){
		string s=Console.ReadLine();
		string ans="YES";
		int n=s.Length;
		while(ans=="YES"&&n>0){
			if(n<5){ans="NO";break;}
			if(s.Substring(n-5,5)=="dream"||s.Substring(n-5,5)=="erase"){n-=5;}
			else if(n>=7&&s.Substring(n-7,7)=="dreamer"){n-=7;}
			else if(n>=6&&s.Substring(n-6,6)=="eraser"){n-=6;}
			else{ans="NO";}
		}
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
void dfs(int v,vector<int>& dist,vector<vector<pair<int,int>>>& adj)
{
    for(auto const&e:adj[v])
    {
        int ne=e.first;
        int val=e.second;
        if(dist[ne]==-1)
        {
            if(val==1)
            {
                dist[ne]=1-dist[v];
            }
            else
            {
                dist[ne]=dist[v];
            }
            dfs(ne,dist,adj);
        }
    }
    return;
}
int main()
{
    int n;
    cin>>n;
    vector<vector<pair<int,int>>> adj(n);
    for(int i=0;i<n-1;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        adj[a].push_back({b,c%2});
        adj[b].push_back({a,c%2});
    }
    vector<int> dist(n,-1);
    dist[0]=0;
    dfs(0,dist,adj);
    for(auto const&e:dist)
        cout<<e<<" ";
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 11628
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, K;
  cin >> N >> K;

  vector<bool> ng(10, false);
  REP(i, K){
    int d; cin >> d;
    ng[d] = true;
  }

  int cur = 1;
  while(1){
    if(cur >= N){
      int tmp = cur;
      bool flag = true;
      while(tmp){
        if(ng[tmp%10]) flag = false;
        tmp /= 10;
      }
      if(flag) break;
    }
    cur++;
  }

  cout << cur << "\n";

  return 0;
}

Measured memory_bytes: 256
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <pthread.h>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	int n;	cin >> n;
	int First = n/500;
	int Second = n%500;
	int Final = Second/5;
	cout << First*1000+Final*5 << endl; 
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	Solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    auto a = vec<int>(n, n); cin >> a;
    VL dp(1 << n);
    FOR(bit, 0, 1 << n)FOR(i, 0, n) {
        if (bit & (1 << i))FOR(j, i + 1, n) {
            if (bit & (1 << j))dp[bit] += a[i][j];
        }
    }
    FOR(bit, 0, 1 << n)for (int sub = bit; sub; sub = (sub - 1) & bit) {
        chmax(dp[bit], dp[sub] + dp[bit ^ sub]);
    }
    print(dp.back());
    
    return 0;
}

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

int arr[1010];

int main() {
  
  int n, m, cnt =0;
  double ss = 0;
  
  cin >> n >> m;
  
  for(int i=0; i<n; i++) {
    cin >> arr[i];
    ss += arr[i];
  }
  
  ss /= (4*m);
  
  for(int i=0; i<n; i++)
    cnt += (arr[i] >= ss);
  
  cout << (cnt >= m ? "Yes" : "No") << endl;
 
  return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

main :: IO ()
main = do
  x <- readLn
  print $ solve x

solve :: Int -> Int
solve x = head $ filter isExpNumber [x, x-1 ..]

isExpNumber :: Int -> Bool
isExpNumber 1 = True
isExpNumber x = any g [b | b <- [2 .. x], x `mod` b == 0] where
  g b = any (x ==) $ takeWhile (x >=) [b ^ p | p <- [2 ..]]


Measured memory_bytes: 636