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

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);

    int x, n;
    cin >> x >> n;

    vector<int> arr(n);
    map<int, int> counter;

    for(int &i : arr) cin >> i, counter[i]++;

    int ans = x, ab = INT_MAX;

    for(int i=0; i<=200; i++){
        if(counter[i]==0 and abs(i-x)<ab){
            ab = abs(i-x);
            ans = i;
        }
    }

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e9 + 7;
int si[8] = {-1,0,1,-1,1,-1,0,1};
int sj[8] = {-1,-1,-1,0,0,1,1,1};

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if (t*s >= d) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3680
N=int(input())
ans=0
for i in range(2,10**6+1):
  anssub=0
  t=0
  while N%i==0:
    N=N//i
    anssub+=1
  while t*(t+1)//2<=anssub:
    t+=1  
  ans+=t-1
if N!=1:
  ans+=1
print(ans)  

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int x=0,f=1;
	while(c<'0'||c>'9'){ if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
int h,w;
char s[505][505];
int main(){
	h=read(),w=read();
	for(int i=0;i<h;++i) scanf("%s",s[i]);
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			if(i==0||i==h-1||j==w-1) printf(".");
			else if(j==0||i&1||s[i][j]=='#') printf("#");
			else printf(".");
		}
		printf("\n");
	}
	printf("\n");
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			if(i==0||i==h-1||j==0) printf(".");
			else if(j==w-1||!(i&1)||s[i][j]=='#') printf("#");
			else printf(".");
		}
		printf("\n");
	}
	return 0;
}


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

int main(void){
    int n, d;
    int ans = 0;
    scanf("%d %d",&n ,&d);
    int x[n][d];
    int i, j, k, l;
    int m = 0;
    for(i=0;i<n;i++){
        for(j=0;j<d;j++){
            scanf("%d",&x[i][j]);
        }
    }  
    for(i=0;i<n;i++){
        for(j=i;j<n;j++){
            m = 0;
            for(k=0;k<d;k++){
                m = m + (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
            }
            for(l=1;l<=160;l++){
                if(l*l == m){
                    ans++;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
    
}

Measured memory_bytes: 128
#include<stdio.h>

#define N 1001

int main(void)
{
	int i,j,n_fruit,k_fruit,price=0,fruit[N],temp;

	scanf("%d%d",&n_fruit,&k_fruit);

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

	

	for(i=0;i<n_fruit;i++){
		for(j=i+1;j<n_fruit;j++){
			if(fruit[i]>fruit[j]){
				temp = fruit[i];
				fruit[i] = fruit[j];
				fruit[j] = temp;
			}
		}
	}

	for(i=0;i<k_fruit;i++){
		price += fruit[i];
	}

	printf("%d\n",price);

	return 0;
}


Measured memory_bytes: 1720
import math
n, k = map(int, input().split())
num = [int(input()) for i in range(n)]
#num.sort()
left = max(max(num), math.ceil(sum(num)/k))
right = sum(num)
while left < right:
    mid = (left + right) // 2
    track = 1
    cnt = 0
    flag = 0
    for i in num:
        cnt += i
        if cnt > mid:
            track+=1
            cnt = i
        if track > k:
            flag = 1
            break
        if flag:
            break
    if flag == 0:
        right = mid
    else:
        left = mid+1
print(left)


Measured memory_bytes: 9616
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int Maxn = 100000;
string S1,S2,S3;
int main()
{
    cin>>S1;
    cin>>S2;
    cin>>S3;
    printf("%c%c%c\n",S1[0] - 'a' + 'A',S2[0] - 'a' + 'A',S3[0] - 'a' + 'A');
    return 0;
}

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

int main(void)
{
    long long int h, power = 0;
    int n;
    scanf("%lld%d", &h, &n);
    long long int a[n];
    for(int i = 0; i<n; i++) scanf("%lld", &a[i]);
    
    for(int i = 0; i<n; i++) power += a[i];

    if(power>=h) printf("Yes");
    else printf("No");

    return 0;    
}

Measured memory_bytes: 896
#include<iostream>
#include<iomanip>
#include<cctype>
#include<string>

using namespace std;

int main()
{
    int i=0;
    string s;
    getline(cin, s);
    for(i = 0;i < s.size();i++){
        if(s[i] == '\n') break;
        if(isupper(s[i])){
            cout << char(tolower(s[i]));
        }else if(islower(s[i])){
            cout << char(toupper(s[i]));
        }else{
            cout << char(s[i]);
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3156
def insertionSort(arr, n)
    i = 1
    outputArr(arr,0)
    while i < n
        v = arr[i]
        j = i - 1
        while j >= 0 && v < arr[j] 
            arr[j+1] = arr[j]
            j -= 1
        end
        arr[j+1] = v
        i += 1
       
        if i == n
            outputArr(arr, 1)
        else 
            outputArr(arr,0)
        end
    end
    arr
end

def outputArr(arr, mode)
    str = ""
    arr.each do |i|
        str = str + i.to_s + " "
    end
    str = str.strip
    puts str
end

num = ARGF.gets.to_i
arr = ARGF.gets.split
arr = arr.map{|s| s.to_i}

insertionSort(arr, num)



Measured memory_bytes: 8532
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int bits[12];
vector<int>bb[22];
int p[22];
int n,m;
void print()
{
    for(int i=0;i<n;i++)cout<<bits[i];
    cout<<endl;
}
int ans=0;
void check()
{
    for(int i=0;i<m;i++)
    {
        int temp=0;
        for(int j=0;j<bb[i].size();j++)
        {
            int pos=bb[i][j]-1;
            if(bits[pos]==1)
            {
                temp++;
            }
        }
        if(temp%2!=p[i])return;
    }
//    print();
    ans++;
}
void call(int pos)
{
    if(pos==n)
    {
        check();
        return;
    }
    call(pos+1);
    bits[pos]=1;
    call(pos+1);
    bits[pos]=0;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int k;cin>>k;
        for(int j=0;j<k;j++)
        {
            int a;cin>>a;
            bb[i].pb(a);
        }
    }
    for(int i=0;i<m;i++)cin>>p[i];
    call(0);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n, k;
  cin >> n >> k;
  if (k <= (n+1)/2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int X, S;

int main() {
	cin >> X; X = abs(X);
	for (int i = 1; i <= 50000; i++) {
		S += i;
		if (S >= X) { cout << i << endl; break; }
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    string A,B,C;
    cin >> A >> B >> C;
    char now = 'a';
    while(true){
        if(now=='a'){
            if(A.size() == 0){
                cout << "A" << endl;
                return 0;
            }
            now = A[0];
            A.erase(A.begin());
        }
        if(now=='b'){
            if(B.size() == 0){
                cout << "B" << endl;
                return 0;
            }
            now = B[0];
            B.erase(B.begin());
        }
        if(now=='c'){
            if(C.size() == 0){
                cout << "C" << endl;
                return 0;
            }
            now = C[0];
            C.erase(C.begin());
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include <map>
using namespace std;
int main() {
    long long  N;
    cin >> N;
    vector<long long> L(N+1);
     L.at(0) = 2;
     L.at(1) = 1;
    for(long long i=0;i<=N-2;i++){
        L.at(i+2) = L.at(i+1) + L.at(i) ;
    }
    cout << L.at(N) << endl;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main{
        public static void main(String[] args){
                try(Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt(), M = sc.nextInt();
                        long[] a = new long[N], b = new long[N];
                        long[] c = new long[M], d = new long[M];
                        for(int i = 0; i < N; i++) {
                                a[i] = sc.nextLong();
                                b[i] = sc.nextLong();
                        }
                        for(int i = 0; i < M; i++) {
                                c[i] = sc.nextLong();
                                d[i] = sc.nextLong();
                        }
                        for(int i = 0; i < N; i++) {
                                long len = (long)1e12;
                                int ans = 0;
                                for(int j = 0; j < M; j++) {
                                        if(len > Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j])) {
                                                len = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
                                                ans = j;
                                        }
                                }
                                System.out.println(ans + 1);
                        }
                }
        }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

vector<ll> v;
map<ll, int> mp;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    ll n, x, m, ret = 0; cin >> n >> x >> m;
    int idx = -1;
    for(int i=1; i<=n; i++){
        if(mp.count(x)){ idx = i; break; }
        mp[x] = i; v.push_back(x);
        ret += x;
        x *= x; x %= m;
    }
    if(mp.size() == n){ cout << ret; return 0; }
    ll sz = idx - mp[x], rem = n - idx + 1;
    ll val = 0;
    for(int i=mp[x]-1; i<v.size(); i++) val += v[i];
    ret += rem / sz * val; rem %= sz;
    for(int i=0; i<rem; i++) ret += v[mp[x]-1+i];
    cout << ret;
}

Measured memory_bytes: 6724
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
 
var lines = [];
reader.on('line',(line) => {
          lines.push(line);
});
 
reader.on('close', () => {
          var line = lines[0];
  var s = [...line];
  var L = s.length
  var x = 0;
  for(var i = 0; i < L; i++){
    var D = i - s[i];
    if( D % 2 == 0){
      x = x + 1;
    }
  }
  if(x <= L/2){
    console.log(x);
  } else {
    console.log(L - x);
  }
});

Measured memory_bytes: 21320
/*{{{*/
#include<bits/stdc++.h>

typedef long long ll;

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

#define vl vector<ll>
#define pll pair<ll,ll>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
/*}}}*/

ll gcd(ll a,ll b){
  if(a<b) swap(a,b);
  if(a%b==0) return b;
  return gcd(b,a%b);
}
int main() {
  ll n;
  cin >> n;
  vector<bool> isPrime(1e6+1, true);
  vl primes;
  vl miniPrimes;
  isPrime[0] = false;
  isPrime[1] = false;
  FOR(i,2,isPrime.size()){
    if(isPrime[i]){
      for(ll j = i*2;j<isPrime.size();j += i){
        isPrime[j] = false;
      }
      primes.push_back(i);
      if(i<=1e3) miniPrimes.push_back(i);
    }
  }
  //cout << "size of miniPrimes is " << miniPrimes.size() << endl;
  //return 0;
  vl a(n);
  REP(i,n) cin >> a[i];
  ll gcdAll = a[0];
  REP(i,n) gcdAll = gcd(a[i],gcdAll);
  if(gcdAll>1) {
    cout << "not coprime" << endl;
    return 0;
  }

  vl primeCount(primes.size(),0);
  //REP(i,primes.size()) primeToCount.insert({primes[i],0});
  REP(i,n){
    REP(j,miniPrimes.size()){
      if(a[i]%miniPrimes[j]!=0) continue;
      while((a[i]%miniPrimes[j]==0)) a[i] /= miniPrimes[j];
      //cout << i << ", " << a[i] << endl;
      primeCount[j]++;
    }
    if(a[i]>1) {
      ll ok = 0;
      ll ng = primes.size();
      while(abs(ok-ng)>1){
        ll m = (ok+ng)/2;
        if(primes[m]<=a[i]) ok = m;
        else ng = m;
      }
      primeCount[ok]++;
    }
  }
  //REP(i,10){
  //  cout << primes[i] <<  ": " << primeCount[i] << endl;
  //}

  REP(i,primes.size()){
    if(primeCount[i]>1){
      cout << "setwise coprime" << endl;
      return 0;
    }
  }

  cout << "pairwise coprime" << endl;

  return 0;
}


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

int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K;

	ll ans;
	if (K & 1)
	{
		ll tmp = N/K;
		ans = pow(tmp, 3);
	}
	else
	{
		ll tmp1 = N/K;
		ll tmp2 = (N+K*0.5)/K;
		ans = pow(tmp1, 3) + pow(tmp2, 3);
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 384
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
int A,B,K;
vector<int> a;
int cal=0;
cin >> A >> B >> K;
for(int i=1;i<min(A,B)+1;i++)
{
if(A%i==0&&B%i==0)a.push_back(i);
}
cout << a.at(a.size()-K);
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ans = [-1 for _ in range(N)]
if N ==1:
  ans = 0
  clis = []
  for _ in range(M):
    s, c = map(int, input().split())
    clis.append(c)
  if len(set(clis)) == 1:
    print(clis[0])
    exit()
  elif len(set(clis)) == 0:
    print(0)
    exit()
  else:
    print(-1)
    exit()
else:
  for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
      print(-1)
      exit()
    if ans[s-1] == c or ans[s-1] == -1:
      ans[s-1] = c
    else:
      print(-1)
      exit()

ans[0] = max(1, ans[0])
answer = ''
for k in range(N):
  if ans[k] == -1:
    answer += '0'
  else:
    answer += str(ans[k])
print(answer)


Measured memory_bytes: 9256
#include <iostream>

using namespace std;

unsigned long long int gcd(unsigned long long int a, unsigned long long int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

unsigned long long int lcm(unsigned long long int a, unsigned long long int b)
{
   return a * b / gcd(a, b);
}

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

   //cout << "最大公約数:" << gcd(a, b) << endl;
   cout << lcm(a, b) << endl;
   return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

int main() 
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b; cin >> a >> b;
  cout << (a + b + 1)/2  << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int a,b,c;
int main() {
  int max;
  cin>>a>>b>>c;
  max=b/a;
  if(c>=max){
  	cout<<max<<endl;
  }else{
   	cout<<c<<endl; 
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] d = arrayLong(sc, n);
		sc.close();
		boolean can = true;
		if (d[0] != 0)
			can = false;
		Arrays.sort(d);
		long ans = 0;
		long mod = 998244353l;
		int prev = -1;
		int prevnum = 0;
		int prevnumprev = 0;
		// System.out.println(Arrays.toString(d));
		for (int i = 0; i < n; i++) {
			if (prev == -1) {
				if (d[i] == 0) {
					prev = 0;
					prevnum = 1;
				} else {
					break;
				}
			} else if (prev == 0) {
				if (d[i] == 0) {
					break;
				} else if (d[i] == 1) {
					prev = 1;
					ans = 1;
					prevnumprev = prevnum;
					ans *= prevnumprev;
				} else {
					break;
				}
			} else {
				if (d[i] == prev) {
					prevnum++;
					ans *= prevnumprev;
					ans %= mod;
				} else if (d[i] - 1 == prev) {
					prevnumprev = prevnum;
					prevnum = 1;
					ans *= prevnumprev;
					ans %= mod;
					prev++;
				} else {
					ans = 0;
					break;
				}
			}
		}
		System.out.println(can ? ans : 0);
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 62152
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

u64 gcd(u64, u64);
u64 canDivide(u64, u64, u64);

u64 A, B, C, D;


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

    cin >> A >> B >> C >> D;

    u64 g = gcd(C, D);
    u64 E = (C / g) * D;

    cout << B - A + 1 - canDivide(A, B, C) - canDivide(A, B, D) + canDivide(A, B, E) << "\n";

    return 0;
}

u64 gcd(u64 x, u64 y)
{
    if (x < y)
    {
        u64 temp = x;
        x = y;
        y = temp;
    }

    while (y)
    {
        u64 temp = x % y;
        x = y;
        y = temp;
    }

    return x;
}

u64 canDivide(u64 s, u64 e, u64 div)
{
    if (div == 0 || e < s) return 0;
    u64 ret = e / div - s / div;
    if (s % div == 0) ++ret;

    return ret;
}



Measured memory_bytes: 256
import math

class coordinate:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    

def koch(n, p1, p2):
    if n == 0:
        return str(p2.x) + " " + str(p2.y)
    
    else:
        s = coordinate((2*p1.x + p2.x)/3, (2*p1.y + p2.y)/3)
        t = coordinate((p1.x + 2*p2.x)/3, (p1.y + 2*p2.y)/3)
        u = coordinate((t.x-s.x)/2-(t.y-s.y)/2*math.sqrt(3)+s.x, (t.x-s.x)/2*math.sqrt(3)+(t.y-s.y)/2+s.y)
        print(koch(n-1, p1, s))
        print(koch(n-1, s, u))
        print(koch(n-1, u, t))
        return(koch(n-1, t, p2))


q1 = coordinate(0.00000000, 0.00000000)
q2 = coordinate(100.00000000, 0.00000000)

print(str(q1.x) + " " + str(q1.y))
print(koch(int(input()), q1, q2))



Measured memory_bytes: 5716
#include <stdio.h>
#define SIZE 123456*2+100
int main(void){
  int is_prime[SIZE];
  int i,j,ans,n;
  for(i=0;i<SIZE;i++){
    is_prime[i]=1;
  }
  is_prime[0]=is_prime[1]=0;
  for(i=2;i*i<=SIZE;i++){
    if(is_prime[i]){
      for(j=i+i;j<SIZE;j+=i){
	is_prime[j]=0;
      }
    }
  }

  while(1){
    scanf("%d", &n);
    if(n==0)break;
    ans=0;
    for(i=n+1;i<=n*2;i++){
      ans += is_prime[i];
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1564
N = int(input())
C = [int(input()) for _ in range(N)]

dp = [0] * N
dp[0] = 1
d = {C[0]:0}

for i in range(1, N):
    if C[i] in d and C[i] != C[i-1]:
        dp[i] = (dp[i-1] + dp[d[C[i]]]) % (10**9+7)
    else:
        dp[i] = dp[i-1]
    d[C[i]] = i

print(dp[-1])


Measured memory_bytes: 36552
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
    int64_t H;
    cin >> H;
    int64_t count = 0;
    count++;
    for (double i = H / 2.0;i >= 1; i /= 2.0) {
        count++;
    }

    cout << (int64_t)pow(2,count) - 1<< endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
    int64_t N, A , B;
    cin >> N >> A >> B;
    if(A > B) {
        swap(A, B);
    }
    if((A-B)%2 == 0) {
        cout << (B-A)/2 << endl;
    } else {
        cout << min((B+A)/2, N - (A+B)/2) << endl;
    }
    return 0;
}


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

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

  int ans = 0;

  for (int i = 0; i < n; i++) {
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
      ans++;
      i = i + 2;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    if(a>=13)cout<<b<<endl;
    if(a>=6&&a<=12)cout<<b/2<<endl;
    if(a<=5)cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input!{
        r: usize,
        D: usize,
        x2000: usize,
    }

    for ind in 1..11 {
        x2000 = r*x2000 - D;
        println!("{}", x2000);
    }
}

Measured memory_bytes: 4352
#include <stdio.h>

int main ( void ) {
  
  int foot, head, judge = 0;
  
  scanf("%d", &head);
  scanf("%d", &foot);
  
  for(int i = 0; i <= head; i++){
    if(i * 4 + ( head - i ) * 2 == foot) {
      printf("Yes\n");
      judge++;
    }
  }
  
  if(judge == 0){
    printf("No\n");
  }  
  
  return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    int s=a+b;
    if(s%2==0)
    {
        cout<<s/2;
    } else
        cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int piv = -1;
  long count = 0;
  for(int i=n-1;i>=0;i--){
    if(piv == -1 && s.at(i) == 'B') continue;
    if(piv == -1 && s.at(i) == 'W') piv = i;
    if(s.at(i) == 'B'){
      count += piv - i;
      piv--;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
n, k = map(int,input().split()) 
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
"""
ans = 0
for i in range(k):
    ans += h[i]
#尺取り
tmp = ans
for i in range(n - k):
    tmp = tmp - h[i] + h[i + k]
    if tmp < ans:
        ans = tmp
print(ans)
"""
ans = 10 ** 18
for i in range(n - k + 1):
    if (h[i + k - 1] - h[i]) < ans:
        ans = h[i + k - 1] - h[i]
print(ans)


Measured memory_bytes: 7384
#include<cstdio>
#include<algorithm>
#include<cmath>
#define P 1000000007

using namespace std;

typedef long long LL;
int n,m;
LL ans;

int main(){
	int i;
	scanf("%d%d",&n,&m); 
	if(abs(n-m)<=1){
		ans=1;
		for(i=1;i<=n;i++) ans=ans*i%P;
		for(i=1;i<=m;i++) ans=ans*i%P;
		if(n==m) ans=ans*(LL)2%P;
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 128
// GRL_3_C: Connected Components - Strongly Connected Components
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

typedef vector< vector<int> > Graph;

void dfs(int idx, Graph& graph, vector<bool>& used, vector<int>& order)
{
  if(used[idx]) return;
  used[idx] = true;
  for(int i = 0; i < graph[idx].size(); i++) {
    dfs(graph[idx][i], graph, used, order);
  }
  order.push_back(idx);
}

void rdfs(int idx, Graph& rgraph, vector<int>& cmp, int& cnt)
{
  cmp[idx] = cnt;
  for(int i = 0; i < rgraph[idx].size(); i++) {
    if(cmp[rgraph[idx][i]] == -1) rdfs(rgraph[idx][i], rgraph, cmp, cnt);
  }
}

int StronglyConnectedComponents(Graph& graph, vector<int>& cmp)
{
  int cnt = 0;
  Graph rgraph(graph.size());
  for(int i = 0; i < graph.size(); i++) {
    for(int j = 0; j < graph[i].size(); j++) {
      rgraph[graph[i][j]].push_back(i);
    }
  }
  cmp.resize(graph.size(), -1);
  vector<bool> used(graph.size(), false);
  vector<int> order;
  for(int i = 0; i < graph.size(); i++) {
    dfs(i, graph, used, order);
  }
  reverse(order.begin(), order.end());
  for(int i = 0; i < order.size(); i++) {
    if(cmp[order[i]] == -1) rdfs(order[i], rgraph, cmp, cnt), cnt++;
  }
  return cnt;
}


int main()
{
  int V, E; cin >> V >> E;
  Graph graph(V);
  while(E--) {
    int s, t;
    cin >> s >> t;
    graph[s].push_back(t);
  }
  vector<int> cmp;
  StronglyConnectedComponents(graph, cmp);
  int Q; cin >> Q;
  while(Q--) {
    int u, v;
    cin >> u >> v;
    if(cmp[u] == cmp[v]) puts("1");
    else puts("0");
  }
  return 0;
}

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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {
    int N;
    cin >> N;
    VV<pair<int, int>> p(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++) {
            int x, y;
            cin >> x >> y;
            x--;
            p[i].push_back({x, y});
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << N); i++) {
        bool flg = true;
        V<int> person(N);

        int cnt = 0;
        for (int j = 0; j < N; j++) {
            if (((i >> j) % 2) == 1) {
                cnt++;
                person[j] = 1;
            } else {
                person[j] = 0;
            }
        }

        for (int j = 0; j < N; j++) {
            if (!flg)
                break;
            if (((i >> j) % 2) == 1) {
                for (auto pp : p[j]) {
                    if (person[pp.first] != pp.second) {
                        flg = false;
                        break;
                    }
                }
            }
        }
        if (flg)
            ans = max(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.*;

class Main
{
    public static  void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if (a < b) {
            
            for (int i = 0; i < b; i++) {
                System.out.print(a);
            }
            
        } else if (a >= b) {
            for (int i = 0; i < a; i++) {
                System.out.print(b);
            }
            
        }
        System.out.println();
        
    }
}

Measured memory_bytes: 21716
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

bool isPalindrome(std::string s) {
  std::string t = s;
  std::reverse(t.begin(), t.end());
  return s == t;
}

int main() {

  std::string s;
  std::cin >> s;

  bool ans = true;

  if (!isPalindrome(s))
    ans = false;

  if (!isPalindrome(s.substr(0, s.size() / 2)))
    ans = false;


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

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8

n, k = map(int, input().split())
s = input()
s += "2"
n += 1

nums = []
if s[0] == "0":
    nums.append(0)

fin = False
i = 0
while i < n:
    if fin:
        break
    for j in range(i, n):
        if s[j] != s[i]:
            nums.append(j-i)
            i = j
            break
        if i == n-1:
            fin = True
            break

if s[-2] == "0":
    nums.append(0)
# print(nums)
length = min([2*k+1, len(nums)])

ans = 0
for i in range(0, length):
    ans += nums[i]

oldsum = ans
for i in range(0, len(nums), 2):
    if i + length + 1 < len(nums):
        newsum = oldsum - (nums[i] + nums[i+1]) + (nums[length+i] + nums[length+i+1])
        if newsum > ans:
            ans = newsum
        oldsum = newsum
    else:
        break

print(ans)


Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
int Inf = (1<<30);
ll inf = (1LL<<60);
const int MOD = 1e9 + 7;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	VVL dp(n + 1, VL(13, 0));
	dp[0][0] = 1;
	int i, j;
	for (i = 0; i < n; i++) {
		if (s[i] != '?') {
			int digit = s[i] - '0';
			for (j = 0; j <= 12; j++) {
				dp[i + 1][(j * 10 + digit) % 13] += dp[i][j];
				dp[i + 1][(j * 10 + digit) % 13] %= MOD;
			}
		}
		else {
			for (int D = 0; D <= 9; D++) {
				for (j = 0; j <= 12; j++) {
					dp[i + 1][(j * 10 + D) % 13] += dp[i][j];
					dp[i + 1][(j * 10 + D) % 13] %= MOD;
				}
			}
		}
	}
	/*
	for (i = 1; i <= n; i++) {
		cout << i << ":";
		for (j = 0; j <= 12; j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	cout << dp[n][5];
	return 0;
}

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

int main()
{
    int n,i,sum=0;
    cin >>n;
    int arr[n];
    for (i=0;i<n;i++)
        cin >>arr[i];
    for (i=0;i<n;i+=2)
    {
        if (arr[i] %2 !=0)
            sum ++;
    }
    cout <<sum << endl;
    return 0;
}

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

string s,ans;
int n,num,now;
int csize[10]={0,5,3,3,3,3,3,4,3,4};
char btn[10][5]={
  {'-','-','-','-','-'},
  {'.',',','!','?',' '},
  {'a','b','c','-','-'},
  {'d','e','f','-','-'},
  {'g','h','i','-','-'},
  {'j','k','l','-','-'},
  {'m','n','o','-','-'},
  {'p','q','r','s','-'},
  {'t','u','v','-','-'},
  {'w','x','y','z','-'}
};

int main(){
  int i,a,j;
  cin >> n;
  for(a=0;a<n;a++){
    ans="";
    cin >> s;
    for(i=0;i<s.size();i++){
      now = s[i]-'0';
      num=0;
      if(now==0)continue;
      while(s[++i]==now+'0')num++;
      ans+=btn[now][num%csize[now]];
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3068
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String S = s.next();
        int Q = Integer.parseInt(s.next());
        StringBuilder sb = new StringBuilder(S);
        StringBuilder sbF = new StringBuilder();
        StringBuilder sbB = new StringBuilder();
        boolean reversed = false;
        for (int i = 0; i < Q; i++) {
            // 反転
            if (s.nextInt() == 1) {
                reversed = !reversed;
                continue;
            }
            // 文字追加
            int F = s.nextInt();
            String C = s.next();
            // 先頭に追加
            if (F == 1) {
                if (reversed) {
                    // 反転されている場合は末尾追加
                    sbB.append(C);
                    continue;
                }
                sbF.append(C);
                continue;
            }
            if (reversed) {
                // 反転されている場合は先頭追加
                sbF.append(C);
                continue;
            }
            // 末尾に追加
            sbB.append(C);
        }

        if (reversed) {
            System.out.print(sbB.reverse());
            System.out.print(sb.reverse());
            System.out.println(sbF);
        } else {
            System.out.print(sbF.reverse());
            System.out.print(sb);
            System.out.println(sbB);
        }
    }
}

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

int main()
{
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int *c, *v;
  int n, i, j, m;
  cin >> n;
  v = (int *)malloc(sizeof(int) * n);
  c = (int *)malloc(sizeof(int) + n);
  for (i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (i = 0; i < n; i++) {
    cin >> c[i];
  }
  m = 0;
  for (i = 0; i < n; i++) {
    v[i] -= c[i];  // もうけ
    if (0 < v[i]) {
      m += v[i];
    }
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
	int n, i = 1, x;
	scanf("%d", &n);
	while (i <= n){
		if (i % 3 == 0){
			printf(" %d", i);
		}
		else{
			if (i % 10 == 3){
				printf(" %d", i);
			}
			else{
				x = i;
				while (x){
					if (x % 10 != 3){
						x /= 10;
					}
					else{
						printf(" %d", i);
						break;
					}
				}
			}
		}
		i++;
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll HMOD = (ll)1e9 + 7;
const ll LMOD = 998244353;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
const long double EPS = 1e-10;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	int N; cin >> N;
	string S; cin >> S;
	REP(i, 8) {
		VB T;
		REP(j, 3) T.push_back(i & 1 << j);
		if ( T[1] && S[1] == 'o' && T[0] != T[2]) continue;
		if ( T[1] && S[1] == 'x' && T[0] == T[2]) continue;
		if (!T[1] && S[1] == 'o' && T[0] == T[2]) continue;
		if (!T[1] && S[1] == 'x' && T[0] != T[2]) continue;
		FOR(j, 2, N - 1) {
			if ( T[j] && S[j] == 'o') T.push_back( T[j - 1]);
			if ( T[j] && S[j] == 'x') T.push_back(!T[j - 1]);
			if (!T[j] && S[j] == 'o') T.push_back(!T[j - 1]);
			if (!T[j] && S[j] == 'x') T.push_back( T[j - 1]);
		}
		if ( T[N - 1] && S[N - 1] == 'o' && T[N - 2] != T[0]) continue;
		if ( T[N - 1] && S[N - 1] == 'x' && T[N - 2] == T[0]) continue;
		if (!T[N - 1] && S[N - 1] == 'o' && T[N - 2] == T[0]) continue;
		if (!T[N - 1] && S[N - 1] == 'x' && T[N - 2] != T[0]) continue;
		if ( T[0] && S[0] == 'o' && T[N-1] != T[1]) continue;
		if ( T[0] && S[0] == 'x' && T[N-1] == T[1]) continue;
		if (!T[0] && S[0] == 'o' && T[N-1] == T[1]) continue;
		if (!T[0] && S[0] == 'x' && T[N-1] != T[1]) continue;
		
		string U;
		REP(i, N) U.push_back((T[i] ? 'S' : 'W'));
		cout << U << endl;
		return 0;
	}
	cout << -1 << endl;
	return 0;
}



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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

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

int main()
{
  int n, a, b; cin >> n >> a >> b;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  int p1 = 0, p2 = 0, p3 = 0;
  rep(i, n) {
    if(p[i] <= a) ++p1;
    else if(p[i] <= b) ++p2;
    else ++p3;
  }
  cout << min(p1, min(p2, p3)) << endl;
}


Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

	private void doit() {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		while(m-- > 0){
			int start = sc.nextInt();
			int year = sc.nextInt();
			int n = sc.nextInt();
			int ans = 0;
			while(n-- > 0){
				int digit = sc.nextInt();
				Double profit = sc.nextDouble();
				int charge = sc.nextInt();
				int money = start;
				if(digit == 1){
					for(int i=0; i < year; i++){
						money =  (int)(money * (1.0 + profit)) - charge;
					}
				}
				else{
					int sumprofit = 0;
					for(int i=0; i < year; i++){
						sumprofit += (int)(money * profit);
						money -= charge;
					}
					money += sumprofit;
				}
				ans = Math.max(ans, money);
			}
			System.out.println(ans);
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}

}

Measured memory_bytes: 13000
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int v;
    cin >> v;
    v /= 400;
    if (v >= 8) {
      mp[8]++;
    } else {
      mp[v]++;
    }
  }
  int min = 0, max = 0;

  rep(i, 8) {
    if (mp[i] != 0) {
      min++;
    }
  }

  max = min + mp[8];
  if (min == 0) {
    cout << 1 << " " << max;
  } else {
    cout << min << " " << max;
  }
  return 0;
}


Measured memory_bytes: 3580
import scala.collection.{immutable, mutable}
import scala.io.StdIn._
object Main extends App {
  val n = readInt()
  val labels = mutable.Map[String, Int]()
  val nodes = Array.fill(n + 1){Nil: List[Edge]}
  val statements = Array.fill(n){
    readLine.trim.split(' ') match {
      case Array("goto", label) ⇒ Goto(label.dropRight(1))
      case Array(label) ⇒ Label(label.dropRight(1))
      case _ ⇒ ???
    }
  }
  for ((s, i) ← statements.zipWithIndex) {
    s match {
      case Label(name) ⇒
        labels(name) = i
        nodes(i) ::= Edge(i + 1, 0)
      case Goto(_) ⇒
        nodes(i) ::= Edge(i + 1, 1)
    }
  }
  for ((Goto(name), i) ← statements.zipWithIndex) {
    nodes(i) ::= Edge(labels(name), 0)
  }
  val minCost = Array.fill(n + 1){Int.MaxValue}
  minCost(0) = 0
  val queue = mutable.PriorityQueue[(Int, Int)]()(Ordering.by[(Int, Int), Int](_._1).reverse)
  queue.enqueue((0, 0))
  while (queue.nonEmpty) {
    val (current, cost) = queue.dequeue()
    if (minCost(current) == cost) {
      for (Edge(to, c) ← nodes(current) if minCost(to) > cost + c) {
        minCost(to) = cost + c
        queue.enqueue((to, cost + c))
      }
    }
  }
  println(minCost.last)
  case class Edge(to: Int, cost: Int)
  sealed trait Statement
  case class Label(name: String) extends Statement
  case class Goto(labelName: String) extends Statement
}


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

using namespace std;

const int max_n = 111, inf = 1000111222;

int n;
vector<int> a, ans;

bool ok(const vector<int> &a) {
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] > i + 1) {
            return false;
        }
    }
    return true;
}

vector<int> go(const vector<int> &a) {
    if (a.empty()) {
        return {};
    }
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] == i + 1) {
            vector<int> b = a;
            b.erase(b.begin() + i);
            if (ok(b)) {
                vector<int> res = go(b);
                res.push_back(i + 1);
                return res;
            }
        }
    }
    exit(228);
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    if (!ok(a)) {
        cout << -1 << endl;
        return 0;
    }
    ans = go(a);
    for (int x : ans) {
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import collections
n = int(input())
dat = list(map(int, input().split()))
dat.sort()
f = True
if n % 2 == 0: # 偶数
    for i in range(n):
        if dat[i] != 2 * (i // 2) + 1:
            f = False
    if f:
        print(2 ** (n // 2) % (1000000000+7) )
else: # 奇数
    if dat[0] != 0:
        f = False
    for i in range(n - 1):
        if dat[i + 1] != 2 * (i//2 + 1):
            f = False
    if f:
        print(2** (n //2 ) % (1000000000+7) )
if f is False:
    print(0)


Measured memory_bytes: 52332
n,a,b,c=gets.split.map(&:to_i)
takearray=[]
n.times{
    long=gets.to_i
    takearray.push(long)
}

i=0
ans=10**10
(4**n).times{
    nisin=i.to_s(4).rjust(n, '0').split('').map(&:to_i) 
    agroup=[]
    bgroup=[]
    cgroup=[]
    cost=0
    
    n.times{|k|
        if nisin[k]==1
            agroup.push(takearray[k])
        elsif nisin[k]==2
            bgroup.push(takearray[k])
        
        elsif nisin[k]==3
            cgroup.push(takearray[k])
        
        end
    }
    
    if agroup.count==0 || bgroup.count==0 || cgroup.count==0
        i+=1
        next
    end
    
    cost+=(agroup.count-1)*10
    cost+=(bgroup.count-1)*10
    cost+=(cgroup.count-1)*10
    
    cost+=(agroup.inject(:+)-a).abs
    cost+=(bgroup.inject(:+)-b).abs
    cost+=(cgroup.inject(:+)-c).abs
    
    ans=[cost,ans].min
    
    i+=1
}

puts ans

Measured memory_bytes: 2044
def print_list(num_list):
    print(" ".join(map(str, num_list)))

N = int(input())

A = list(map(int, input().split()))

print_list(A)

for i in range(1, N):
    v = A[i]
    j = i - 1
    while j >=0 and v < A[j]:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    print_list(A)



Measured memory_bytes: 5600
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n,n){
        int cnt = 0;
        bool f = false;
        rep(i,n){
            int a;
            cin >> a;
            if(a == 0) cnt++;
            if(a >= 2) f = true;
        }
        if(f) cout << n - cnt + 1 << endl;
        else cout << "NA" << endl;
    }
}

Measured memory_bytes: 3112