akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

int main()
{
  string S;
  cin >> S;
  
  int year = stoi(S.substr(0, 4));
  int month = stoi(S.substr(5, 2));
  int day = stoi(S.substr(8, 2));
  
  string ans = "Heisei";
  
  if(year >= 2019)
  {
    if(month >= 5)
    {
      ans = "TBD";
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = input()
_list = input().split(" ")
_list = [int(x) for x in _list]
even = [x for x in _list if x % 2==0]
answer = []
for x in even:
    if x % 3 == 0 or x % 5 == 0:
        answer.append(True)
if len(even) ==len(answer):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3064
#include<cstdio>
#include<utility>
#include<functional>
#include<algorithm>
using namespace std;

int main(){
	int N, M;
	scanf("%d %d", &N, &M);
	pair<int, int> a[M];
	for (int i = 0; i < M; ++i) scanf("%d %d", &a[i].first, &a[i].second);
	sort(a, a + M, greater<pair<int, int>>());
	int head = 100000, answer = 0;
	for (int i = 0; i < M; ++i){
		if(a[i].second <= head){
			answer++;
			head = a[i].first;
		}
	}
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = (1LL << 62);
int64_t dp[45][410][410]; // i番目にj:kとなる場合の最小コスト

int main()
{
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i] >> B[i] >> C[i];
  }
  for (int i = 0; i < 45; i++)
  {
    for (int j = 0; j < 410; j++)
    {
      for (int k = 0; k < 410; k++)
      {
        dp[i][j][k] = INF;
      }
    }
  }
  dp[0][0][0] = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 410; j++)
    {
      for (int k = 0; k < 410; k++)
      {
        if (dp[i][j][k] == INF)
          continue;
        dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
        dp[i + 1][j + A[i]][k + B[i]] = min(dp[i + 1][j + A[i]][k + B[i]], dp[i][j][k] + C[i]);
      }
    }
  }
  int64_t ans = INF;
  for (int i = 1; i < 400; i++)
  {
    if (Ma * i > 400 || Mb * i > 400)
      continue;
    ans = min(ans, dp[N][Ma * i][Mb * i]);
  }
  cout << (ans == INF ? -1 : ans) << endl;
}

Measured memory_bytes: 62728
var
	n,i,s,x,f:Longint;
	c:int64;
	a:array[1..200000]of Longint;
begin
	read(n);
	f:=1;
	for i:=1 to n do begin
		read(a[i]);
		inc(s,a[i]);
		x:=x xor a[i];
		while s<>x do begin
			dec(s,a[f]);
			x:=x xor a[f];
			inc(f);
		end;
		inc(c,i-f+1);
	end;
	writeln(c);
end.


Measured memory_bytes: 896
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=10000;
struct node{
	int l,r,p,s,deg,dep,h;
};
int n,v,l1,r1,tmp,root;
int vis[N]={0};
node tree[N];


int build(int k,int depth){
	if ((tree[k].l==-1)&&(tree[k].r==-1)) {
		tree[k].deg=0;
		tree[k].dep=depth;
		return tree[k].h=0;
	}
	else if ((tree[k].l!=-1)&&(tree[k].r!=-1)){
		tree[tree[k].l].p=k;
       	tree[tree[k].r].p=k;
		tree[tree[k].l].s=tree[k].r;
		tree[tree[k].r].s=tree[k].l;
		tree[k].deg=2;
		tree[k].dep=depth;
		return tree[k].h=max(build(tree[k].l,depth+1),build(tree[k].r,depth+1))+1;
	}
	else if (tree[k].l!=-1){
		tree[tree[k].l].p=k;

		tree[tree[k].l].s=-1;


		tree[k].deg=1;
		tree[k].dep=depth;
		return tree[k].h=build(tree[k].l,depth+1)+1;		
	}
	else if (tree[k].r!=-1){

       	tree[tree[k].r].p=k;

		tree[tree[k].r].s=-1;
		
		tree[k].deg=1;
		tree[k].dep=depth;
		return tree[k].h=build(tree[k].r,depth+1)+1;		
	}
  return -1;
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>v>>l1>>r1;
		tree[v].l=l1;
		tree[v].r=r1;
		if (tree[v].l!=-1) vis[tree[v].l]=1;
		if (tree[v].r!=-1) vis[tree[v].r]=1;
	}
	for(int i=0;i<n;i++){
		if (vis[i]==0){
			root=i;
			break;
		}
	}
	build(root,0);
	tree[root].p=-1;
	tree[root].s=-1;
	for(int i=0;i<n;i++){
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,tree[i].p,tree[i].s,tree[i].deg,tree[i].dep,tree[i].h);
		if (i==root) printf("root");
		else if(tree[i].l==-1&&tree[i].r==-1) printf("leaf");
		else printf("internal node");
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int x = -1, y = -1, z = -1;
    int ans = 1;
    rep(i, n)
    {
        //cout << x << " " << y << " " << z << endl;
        if (a[i] == 0)
        {
            if (x == -1)
                x = 0;
            else if (y == -1)
                y = 0;
            else if (z == -1)
                z = 0;
            else{
                cout << 0 << endl;
                return 0;
            }
            continue;
        }
        int cnt = 0;
        bool fx = false, fy = false, fz = false;
        if (x + 1 == a[i])
            fx = true, cnt++;
        if (y + 1 == a[i])
            fy = true, cnt++;
        if (z + 1 == a[i])
            fz = true, cnt++;
        (ans *= cnt) %= mod;
        if (fx)
            x++;
        else if (fy)
            y++;
        else
            z++;
    }
    if (x != -1 && y != -1 && z != -1)
        (ans *= 6) %= mod;
    else if (x != -1 && y != -1)
        (ans *= 6) %= mod;
    else
        (ans *= 3) %= mod;
    cout << ans << endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
////#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	int stone, n, a;
	fscanf(stdin, "%d", &a);
	while (a--) {
		fscanf(stdin, "%d%d", &stone, &n);
		if (!(stone%n)&1)P(d, n);
		else P(d, stone%n);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <algorithm>

// 入力受付用の変数
#define BUF 200002
char str[BUF];

// 入力された値
#define LIM_A 100001
int N;
int v[LIM_A];

double d[LIM_A];

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &N);

	for (size_t i = 0; i < N; i++) {
		scanf("%d", &v[i]);
	}
}

void solve() {
	double sum = 0;

	std::sort(v, v+N);

	d[0] = v[0];
	for (size_t i = 1; i < N; i++) {
		d[i] = (double)(v[i] + d[i-1]) / 2.0;
	}

	printf("%f\n", d[N-1]);
}

int main(void) {
	receive_input();

	solve();

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;

int w,h,Col;
typedef pair<int,int> C;
typedef vector<vector<int> > P;
P V;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int res;

P temp;
int tres=0;


void calc(int y,int x){
	if(y<0 || x<0 || x>=w || y>=h) return;
	if(temp[y][x]==Col){tres++;temp[y][x]=0;
	for(int r=0;r<4;r++)
		calc(y+dy[r],x+dx[r]);
	}
}

void on(P N,int count,int c){

	if(count==5){temp=N;tres=0;calc(0,0);res=max(res,tres);return;}

	int nc=N[0][0];
	queue<C> Q;
	Q.push(make_pair(0,0));
	bool used[8][8];
	memset(used,false,sizeof(used));

	int tres=0;
	while(!Q.empty()){
		C now=Q.front();
		Q.pop();
		if(used[now.first][now.second]) continue;
		used[now.first][now.second]=true;
		N[now.first][now.second]=c;
		for(int r=0;r<4;r++){
			int ny=now.first+dy[r],nx=now.second+dx[r];
			if(ny<0 || nx<0 || ny>=h || nx>=w) continue;
			if(N[ny][nx]==nc)
				Q.push(make_pair(ny,nx));
		}
	}

	if(count!=4){
		for(int i=1;i<=6;i++){
			if(c!=i)
				on(N,count+1,i);
		}
	}
	else on(N,count+1,Col);
}


void solve(){
	res=0;
	V.clear();
	V.resize(h);

	for(int y=0;y<h;y++)
		for(int x=0;x<w;x++){
			int t;
			cin>>t;
			V[y].push_back(t);
		}
	
	for(int i=1;i<=6;i++){
		if(V[0][0]!=i)
		 on(V,0,i);
	}

	cout<<res<<endl;

}



int main()
{
	while(cin>>h>>w>>Col){
		if(w==0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

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

        int A = in.nextInt(), B = in.nextInt();
        int res = 0;
        while (A * res - (res - 1) < B) res++;

        System.out.println(res);
    }
}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::vector<int>a;

int main()
{
	rep(i, 4)
	{
		char tmp;
		in >> tmp;
		a.push_back(tmp - '0');
	}

	rep(bit, (1 << 3))
	{
		int res = a[0];
		std::string ans=std::to_string(a[0]);
		rep(k, 3)
		{
			if (bit&(1 << k))
			{
				res -= a[k+1];
				ans += "-";
			}
			else
			{
				res += a[k + 1];
				ans += "+";
			}
			ans += std::to_string(a[k + 1]);
		}
		if (res == 7)
		{
			out << ans << "=7" << std::endl;
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint s(n);
  rep(i, n) cin >> s[i];
  vector<bool> dp(11111, false);
  dp[0] = true;
  rep(i, n) {
    for(int j = 10000; j >= s[i]; --j) {
      if(dp[j-s[i]]) dp[j] = true;
    }
  }
  int ans = 0;
  rep(i, 11111) if(dp[i] && i%10) chmax(ans, i);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner input = new Scanner(System.in)){
			String testCase = input.nextLine();
			solution(testCase);
		}
	}
	public static void solution(String str){
		String onesDigit = str.substring(str.length()-1);
		int x = Integer.parseInt(onesDigit);
		if (x==2||x==4||x==5||x==7||x==9){
			System.out.println("hon");
		}
		if (x==0||x==1||x==6||x==8){
			System.out.println("pon");
		}
		if (x==3){
			System.out.println("bon");
		}
	}
}


Measured memory_bytes: 35476
#include <iostream>
using namespace std;
const long long INF = 1LL << 60;
long long a[3001];
long long dp[2][3001][3001];
long long calc(int who, int i, int j) {
	if (who == 0) {
		if (dp[0][i][j] != -INF) return dp[0][i][j];
		if (i == j) return dp[0][i][j] = a[i];
		return dp[0][i][j] = max(calc(1, i + 1, j) + a[i], calc(1, i, j - 1) + a[j]);
	} else {
		if (dp[1][i][j] != INF) return dp[1][i][j];
		if (i == j) return dp[1][i][j] = -a[i];
		return dp[1][i][j] = min(calc(0, i + 1, j) - a[i], calc(0, i, j - 1) - a[j]);
	}
}
int main() {
	int N; cin >> N;
	for (int i = 1; i <= N; i++) cin >> a[i];
	for (int i = 1; i <= N; i++) {
		for (int j = i; j <= N; j++) {
			dp[0][i][j] = -INF;
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = i; j <= N; j++) {
			dp[1][i][j] = INF;
		}
	}
	cout << calc(0, 1, N) << endl;
}


Measured memory_bytes: 139904
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s;
int res = 0;
int cnt[3] = {0};

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    cin >> s;
    s += 'J';
    int mode = 1;

    rep(i, s.size()){
      if(mode == 1){
        if(s[i] == 'J')++cnt[0];
        else if(s[i] == 'O'){
          mode = 2; ++cnt[1];
        }else cnt[0] = 0;
      }else if(mode == 2){
        if(s[i] == 'J'){
          mode = 1;
          rep(j, 2)cnt[j] = 0;
          ++cnt[0];
        }else if(s[i] == 'O')++cnt[1];
        else{
          mode = 3; ++cnt[2];
        }
      }else{
        if(s[i] == 'J'){
          if(cnt[0] >= cnt[1] && cnt[1] <= cnt[2])res = max(res, cnt[1]);
          mode = 1;
          rep(j, 3)cnt[j] = 0;
          ++cnt[0];
        }else if(s[i] == 'O'){
          if(cnt[0] >= cnt[1] && cnt[1] <= cnt[2])res = max(res, cnt[1]);
          mode = 1;
          rep(j, 3)cnt[j] = 0;
        }else ++cnt[2];
      }
      //printf("%d %d %d %d %d\n", i, mode, cnt[0], cnt[1], cnt[2]);
    }
    pri(res);


/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3980
#include<iostream>
#include<algorithm>
using namespace std;
int b[9] = { 0,1,2,3,4,5,6,7,8 }, a[9], x[9];
int main() {
	for (int i = 0; i < 9; i++)cin >> x[i];
	int cnt = 0;
	do {
		for (int i = 0; i < 9; i++)a[i] = b[i] + 1;
		int S = a[0] + (a[1] * 10 + a[2]) + (a[3] * 100 + a[4] * 10 + a[5]);
		int T = (a[6] * 100 + a[7] * 10 + a[8]);
		if (S == T) {
			bool OK = true;
			for (int i = 0; i < 9; i++) {
				if (x[i] != -1 && a[i] != x[i])OK = false;
			}
			if (OK == true)cnt++;
		}
	} while (next_permutation(b, b + 9));
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3092
x = map(int, raw_input().split())
for i in range(len(x)-1):
    for j in range(len(x)-i-1):
        if x[j] > x[j+1]:
            tmp = x[j+1]
            x[j+1] = x[j]
            x[j] = tmp
print x[0], x[1], x[2]

Measured memory_bytes: 6428
"use strict";
const main = arg => {
  let Nums = arg.split(" ").map(n => n*1);
  let ans = (Nums[0]+Nums[1])%2 !== 1 ? (Nums[0]+Nums[1])/2 : "IMPOSSIBLE"; 
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	double x1,y1,x2,y2,r,r2;
	cin >> x1 >>y1 >> x2 >> y2;
	r2 = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	r = sqrt(r2);
	printf("%.8f\n",r);
	return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
vector<pair<int,int> > g[11000];
pair<int,pair<int,int> > edge[11000];
int v[11000];
int UF[11000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int main(){
	int T=0;
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		int ret=0;
		for(int i=0;i<a-1;i++){
			int p,q,r;scanf("%d%d%d",&p,&q,&r);
			p--;q--;
			g[p].push_back(make_pair(q,r));
			g[q].push_back(make_pair(p,r));
			edge[i]=make_pair(-r,make_pair(p,q));
			ret+=r;
		}
		std::sort(edge,edge+a-1);
		int rem=b-1-c;
		for(int i=0;i<a;i++)UF[i]=-1;
		for(int i=0;i<a;i++)v[i]=0;
		int fi=99999;
		for(int i=0;i<b;i++){
			int p;scanf("%d",&p);
			p--;v[p]=1;
			fi=min(fi,p);
		}
		for(int i=0;i<a;i++){
			if(v[i])UNION(i,fi);
		}
		for(int i=0;i<a-1;i++){
			if(FIND(edge[i].second.first)!=FIND(edge[i].second.second)){
				UNION(edge[i].second.first,edge[i].second.second);
				ret+=edge[i].first;
			}else if(rem){
				rem--;
				UNION(edge[i].second.first,edge[i].second.second);
				ret+=edge[i].first;
			}
		}
		printf("Case %d: %d\n",++T,ret);
	}
}

Measured memory_bytes: 6224
//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
//#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
int n, p;
string s;
ll ans = 0, curr = 0;
ll pw[2*100*1000], nx[2*100*1000], last[10*1000], dp[2*100*1000+1];
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> p >> s;
}

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    if(p == 2 || p == 5){
        forn(i, n) if((s[i]-'0') % p == 0) ans += i+1;
        cout << ans << endl;
        return 0;
    }

    fill(nx, nx+n, -1);
    fill(last, last+p, -1);
    pw[0] = 1;
    forns(i, n, 1) pw[i] = (pw[i-1] * 10) % p;

    last[0] = n;
    forw(i, n){
        curr += pw[n-1-i] * (s[i]-'0'), curr %= p;
        if(last[curr] != -1)
            nx[last[curr]-1] = i;
        last[curr] = i;
    }

    forn(i, n){
        int j = nx[i];
        dp[i] = j >= 0 ? (j>0?dp[j-1]:0) + 1: 0;
        ans += dp[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 5396
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   
 
 
int main(){
  ll i,j;
  //ll n; cin>>n;
  //ll a,b,c,d,e,f; cin>>a>>b;
  ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  //string s; cin>>s;
  ll result = 0;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  cout<<min(a*b,c)<<endl;
 
  /*
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<n;i++){
 
  }
  */
 
  return 0;
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())
M = max(A, B, C)
if 3 * M % 2 == (A + B + C) % 2:
    print((3 * M - (A + B + C)) // 2)
else:
    print((3 * (M + 1) - (A + B + C)) // 2)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

bool judge(std::vector<int> &h, int x, bool is_h)
{
    int sum = 0, N = h.size();
    for(int i=0; i<N; i++) sum += h[i];

    int M = 2 * sum + 1;
    // printf("M = %d\n", M);
    std::vector<std::vector<bool> > dp(N+1, std::vector<bool>(M, false));
    // for(int i=0; i<=N; i++) dp[i][sum] = true;
    dp[1][h[0]+sum] = true;
    if(!is_h) dp[1][sum-h[0]] = true;

    for(int i=2; i<=N; i++){
        for(int j=0; j<M; j++){
            // printf("i j = %d %d\n", i, j);
            if(j - h[i-1] >= 0 && dp[i-1][j-h[i-1]] == true) dp[i][j] = true;
            if(j + h[i-1] <  M && dp[i-1][j+h[i-1]] == true) dp[i][j] = true;
            // if(dp[i-1][j] == true) dp[i][j] = true;
        } 
    }
    // printf("table:\n");
    // for(int i=0; i<=N; i++){
    //     for(int j=0; j<M; j++) std::cout << dp[i][j] << " ";
    //     printf("\n");
    // }
    // printf("finish\n");
    if(x+sum < 0 || x+sum >= M) return false;
    return dp[N][x+sum];
}

int main()
{
    std::string s;
    int x, y;
    std::cin >> s >> x >> y;

    bool is_h = true;
    std::vector<int> h(1, 0), v(1, 0);
    for(auto &&itr = s.begin(); itr != s.end(); itr++){
        if(*itr == 'F'){
            if(is_h) h.back()++;
            else v.back()++;
        }
        else{
            is_h ^= 1;
            if(is_h) h.push_back(0);
            else v.push_back(0);
        }
    }

    // for(auto &&itr = h.begin(); itr != h.end(); itr++) printf("%d ", *itr);
    // printf("\n");
    // for(auto &&itr = v.begin(); itr != v.end(); itr++) printf("%d ", *itr);
    // printf("\n");

    bool b1 = judge(h, x, true);
    bool b2 = judge(v, y, false);
    if(b1 && b2) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
}

Measured memory_bytes: 2304
#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T & a, const T & b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7;

lint dp[51][51][2501];
lint arr[50];
lint N, A, X;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> A;
	fill((long long*)dp, (long long*)dp + sizeof(dp) / sizeof(long long), 0);
	dp[0][0][0] = 1;
	REP(i, N) {
		cin >> arr[i];
	}

	REP(i, N) {
		REP(j, N) {
			REP(k, 2500) {
				dp[i + 1][j][k] += dp[i][j][k];
				if(k + arr[i] <= 2500)
					dp[i + 1][j + 1][k + arr[i]] += dp[i][j][k];
			}
		}
	}
	lint sum = 0;
	REP(j, N) {
		sum += dp[N][j + 1][(j + 1) * A];
	}
	cout << sum;
}


Measured memory_bytes: 51072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace AtCoder
{
  public class Program
  {
    public static void Main()
    {
      int[] args = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      int m = args[1];
      int l = 1;
      int r = args[0];
      for(int i = 0; i < m; i++)
      {
        args = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        l = Math.Max(l, args[0]);
        r = Math.Min(r, args[1]);
      }
      Console.WriteLine(Math.Max(r - l + 1, 0));
    }
  }
}


Measured memory_bytes: 17472
#include <bits/stdc++.h>
using namespace std;
int a,b,i,n,bb,y;
float x,m;
int main()
{
	cin>>a>>b;
	bb=b;
	while(bb>0)
	{
		bb/=10;
		n++;
	}
	for(i=1;i<=n;i++)
		a*=10;
	n=a+b;
	x=sqrt(n);
	y=sqrt(n);
	m=x-y;
	if (m==0) cout<<"Yes";
	else cout<<"No";
}

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

using namespace std;

long dp[200000][5];

long calc_even(long n){
    if(n == 0) return 2;
    else return (n)%2;
}

int main(){
    int L;
    long A[200000];
    cin >> L;
    for(int i = 0; i < L; i++) cin >> A[i];
    dp[0][0] = A[0];
    dp[0][1] = calc_even(A[0]);
    dp[0][2] = (A[0]+1)%2;
    dp[0][3] = calc_even(A[0]);
    dp[0][4] = A[0];
    for(int i = 1; i < L; i++){
        dp[i][0] = dp[i-1][0]+A[i];
        dp[i][1] = min(dp[i-1][0], dp[i-1][1])+calc_even(A[i]);
        dp[i][2] = min({dp[i-1][0], dp[i-1][1], dp[i-1][2]}) + (A[i]+1)%2;
        dp[i][3] = min({dp[i-1][0], dp[i-1][1], dp[i-1][2], dp[i-1][3]})+calc_even(A[i]);
        dp[i][4] = min({dp[i-1][0], dp[i-1][1], dp[i-1][2], dp[i-1][3], dp[i-1][4]})+A[i];
    }
    cout << min({dp[L-1][0], dp[L-1][1], dp[L-1][2], dp[L-1][3], dp[L-1][4]}) << endl;
}

Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string S,T;
    cin >> S >> T;
    int flag=0;
    for(int i=0;i<S.size();i++){
        if(S.at(i)!=T.at(i)) flag=1;//break;
    }
    if(flag==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3632
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

def f(a, b):
  d = b-a
  if d%2==0:
    return d//2

  e = N-b
  g = a-1
  return min(e+1+f(a+e+1, N), g+1+f(1, b-g-1))

N, a, b = ints()
print(f(a, b))



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

int arr[100000];
int ops[100000][2];

int cmp(const void *ap, const void *bp) {
	const int *a = ap, *b = bp;
	return *a - *b;
}

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

	for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &ops[i][1], &ops[i][0]);
	}

	qsort(arr, n, sizeof arr[0], cmp);
	qsort(ops, m, sizeof ops[0], cmp);

	int i = 0;
	while (m--) {
		int b = ops[m][1], c = ops[m][0];
		int j; 
		for (j = 0; j < b && i+j < n && arr[i+j] < c; j++) {
			arr[i+j] = c;
		}
		i += j;
	}

	long long int sum = 0;
	while (n--) {
		sum += arr[n];
	}
	printf("%lld\n", sum);
}


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

int main() {
 int N;
  cin >> N;
  if(N == 1 || N == 2 || N == 3 || N == 5 || N == 6 || N == 9 || 
     N == 9 || N == 10 || N == 13  || N == 17){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#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 FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> vec(n);
    rep(i,n) {
        int p;
        cin>>p;
        p--;
        vec[p]=i;
    }
    
    FOR(i,1,n) cout<<40000*i+vec[i-1]<<endl;
    FOR(i,1,n) cout<<40000*(n+1-i)<<endl;
    
    
}



Measured memory_bytes: 768
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
    char s[10];
    int i,n=0,flag=0;

    scanf("%s",s);

    for(i=0;s[i]!=0;i++){
		n++;
	}
    //printf("%d\n",n);

    if(s[0]=='A'){
        s[0]='a';
         for(i=2;i<=n-2;i++){
            if(s[i]=='C'){
                if(flag){
                 flag=0;
                 break;
                 }
                flag=1;
                s[i]='c';
            }
         }
        if(flag){
            for(i=0;i<n;i++)
                if(s[i]<'a' || 'z'<s[i]){
                    flag=0;
                    break;
                }
        }
    }
        
    if(flag)
        printf("AC\n");
    else
        printf("WA\n");
}
   

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main()
{
	
	char a[80];
	while(scanf("%s",a)!=EOF)
	{
		if(a[0]!='A') {
			printf("WA\n");
			continue;
		}
		int n=0;
	int flag=1;
			for(int i=1;i<strlen(a);i++)
			{if(a[i]=='C')
			{ 
				n++;
				if(i==1||i==strlen(a)-1)
				{
			  
			  flag=0;
			  break;
				}
			}
			else if(a[i]>='A'&&a[i]<='Z')
			{flag=0;break;}
			
			}
			
			
			if(n==1&&flag==1) printf("AC\n");
		else printf("WA\n");
		
		
		
	}
	
	
	
	
	
}

Measured memory_bytes: 128
use_list = []


def make_prime(n):
    array = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt = cnt + 1
                temp = temp // i
            array[i] = cnt

    if temp != 1:
        array[temp] = 1

    if array == {}:
        array[n] = 1

    return array


def div_prime(n, count):

    if n == 1:
        return count

    # 素数一覧を取得
    prime_list = make_prime(n)
    for p, e in prime_list.items():
        for i in range(1, e + 1):
            if not p ** i in use_list:
                z = p ** i
                use_list.append(z)
                return div_prime(int(n / z), count + 1)

    return count


N = int(input())
print(div_prime(N, 0))


Measured memory_bytes: 9432
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    print(sigma(int(input())))


main()


Measured memory_bytes: 4688
# n/(m+1) < x <= n/m
# (n//(m+1), n//m]
# [n//(m+1) + 1, n//m]

n = int(input())
ans = 0
i = 1
while i * i < n:
    m = n // i
    ans += i * m * (m + 1) // 2
    i += 1
m = n // i
while m:
    s = (n//(m+1) + 1 + n//m) * (n//m - n//(m+1)) // 2
    ans += s * m * (m + 1) // 2
    m -= 1
print(ans)

Measured memory_bytes: 9132
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;
enum long MOD = 10L^^9+7;

void main() {
  long N, A, B;
  scanln(N, A, B);
  A--;
  B--;

  if (A > B) {
    swap(A, B);
  }

  if ((B-A)%2 == 0) {
    writeln((B-A)/2);
  } else {
    writeln(min(
      A + (B-A).ceil(2),
      (N-B-1) + ((N-A-1)-(N-B-1)).ceil(2)
    ));
  }
}

// ----------------------------------------------


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
  static if (__VERSION__ >= 2071) {
    readf!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "readf(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


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

int main(){
    // y = x^2
    int d, i, s;
    while(cin >> d){
        s = 0;
        for (i = 0; i < (600/d); ++i){
            s = s + (i * d) * (i * d) * d;
        }
        cout << s << endl;
    }
}


Measured memory_bytes: 3076
#include <stdio.h>
int main(void) {
    int n,m,a,h,p,q,i,j,flag;
    while (scanf("%d %d %d",&n,&m,&a)!=EOF&&(n!=0||m!=0||a!=0)) {
        int amida[1001][1001][2]={{{0}}};
        for (i=0; i<m; i++) {
            scanf("%d %d %d",&h,&p,&q);
            amida[h][0][0]++;
            amida[h][amida[h][0][0]][0]=p;
            amida[h][amida[h][0][0]][1]=q;
        }
        for (i=1000; i>0; i--) {
            flag=0;
            for (j=1; j<=amida[i][0][0]; j++) {
                if (amida[i][j][0]==a) {
                    flag=2;
                    break;
                } else if (amida[i][j][1]==a) {
                    flag=1;
                    break;
                }
            }
            if (flag!=0) {
                a=amida[i][j][flag-1];
            }
        }
        printf("%d\n",a);
    }
    return 0;
}

Measured memory_bytes: 8436
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

H,W = map(int,readline().split())
s = [readline().rstrip() for i in range(H)]

dp = [[INF] * W for i in range(H)]

dp[0][0] = 0 if s[0][0] == '.' else 1

for i in range(H):
    ii = max(0,i-1)
    for j in range(W):
        jj = max(0,j-1)
        dp[i][j] = min(dp[ii][j] + (s[i][j] != s[ii][j]), dp[i][jj] + (s[i][j] != s[i][jj]))

print((dp[H-1][W-1]+1)//2)


Measured memory_bytes: 9552
using System;
using System.Linq;

namespace ARC070
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(Enumerable.Range(0, 114514).Zip(Enumerable.Repeat(int.Parse(Console.ReadLine()), 364364), (i, x) => new { i, x }).TakeWhile(t => t.i * (t.i + 1) / 2 < t.x).Count());
        }
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back
 
 
int main(){
    int n;
    cin>>n;
 
    int a[n];
    int b[9]={0};
    int total=0;
    int other=0;
    int cnt=0;
    int mini=0;
 
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
 
    for(int i=0;i<n;i++){
 
 
        if(1<=a[i]&&a[i]<400){
            b[0]++;
        }else if(400<=a[i]&&a[i]<800){
            b[1]++;
        }else if(800<=a[i]&&a[i]<1200){
            b[2]++;
        }else if(1200<=a[i]&&a[i]<1600){
            b[3]++;
        }else if(1600<=a[i]&&a[i]<2000){
            b[4]++;
        }else if(2000<=a[i]&&a[i]<2400){
            b[5]++;
        }else if(2400<=a[i]&&a[i]<2800){
            b[6]++;
        }else if(2800<=a[i]&&a[i]<3200){
            b[7]++;
        }else if(a[i]>=3200){
            other++;
        }
 
        total++;
    }
 
    // cout<<"total="<<total<<endl;
    // cout<<"other="<<other<<endl;
    
    for(int i=0;i<8;i++){
        if(b[i]!=0){
            mini++;
        }
    }
    // cout<<endl;
    // cout<<mini<<" ";
    // cout<<endl;
    // cout<<other<<endl;
 
    if(other==0){
        cout<<mini<<" "<<mini<<endl;
    }else if(mini==0){
        cout<<1<<" "<<other<<endl;
    }else{
        cout<<mini<<" "<<other+mini<<endl;
    }
    // cout<<cnt<<endl;
    // cout<<total<<endl;
    // cout<<other<<endl; 
    // if(other+cnt>9){
    //  total=8;
    // }
    // cout<<cnt<<" "<<total<<endl;
 
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

ll A[200000];
ll B[200000];
ll C[200000];
ll D[400000];
//ll T[200000];

int main() {
    ll N;
    cin >> N;
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N) {
        C[i] = A[i] ^ A[(i+1)%N];
        D[i] = B[i] ^ B[(i+1)%N];
        D[i+N] = D[i];
    }
    ll pos = 0;
    ll wpos = 0;

    // T構築
    /*ll tpos = 2;
    ll twpos = -1;
    T[0] = -1;
    T[1] = 0;
    while(tpos < N) {
        if (C[tpos-1] == C[twpos]) {
            T[tpos] = twpos + 1;
            tpos++;
            twpos++;
        } else if (twpos > 0) {
            twpos = T[twpos];
        } else {
            T[tpos] = 0;
            tpos++;
        }
    }*/

    vector<int> T(N+1);
    T[0] = -1;
    int j = -1;
    for (int i = 0; i < N; i++) {
        while (j >= 0 && C[i] != C[j]) j = T[j];
        T[i+1] = ++j;
    }

    vector<ll> Ks;

    while(pos + wpos < 2*N-1) {
        if(C[wpos] == D[pos+wpos]) {
            wpos++;
            if(wpos == N) {
                Ks.push_back((N-pos)%N);
                pos = pos + wpos - T[wpos];
                wpos = T[wpos];
            }
        } else {
            pos = pos + wpos - T[wpos];
            if(wpos > 0) wpos = T[wpos];
        }
    }
    sort(Ks.begin(), Ks.end());
    for(auto k : Ks) {
        ll x = B[0] ^ A[k];
        cout << k << " " << x << endl;
    }
    return 0;
}

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

#define ll long long

ll MOD = pow(10,9)+7;

int main(){
    ll N, ans = 0;
    cin >> N;
    vector<ll> A(N+1), buf(N+1);
    for(int i = 1; i <= N; ++i) cin >> A[i];
    /*
    for(int i = 1; i <= N-1; ++i){
        for(int j = i+1; j <= N; ++j){
            ll buf = A[i]*A[j] % MOD;
            ans += buf;
            ans %= MOD;
        }
    }
    */
   for(int i = N-1; i >= 1; --i){
       if(i == N-1) buf[N-1] = A[N];
       else buf[i] = (buf[i+1]+A[i+1])%MOD;
   }
   for(int i = 1; i <= N-1; ++i){
       ans += (A[i]%MOD)*(buf[i]%MOD);
       ans %= MOD;
   }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6424
module Main where

import qualified Data.Vector as V
import           Data.List
import           Control.Applicative
import           Control.Monad

main :: IO ()
main = do
  n <- readLn
  k <- readLn
  print $ f n k 1

f 0 _ c = c
f n k c = f (n - 1) k $ min (2 * c) (c + k)

Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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

    /*if(c == d) {
        rep(j, n) {
            ll k = a + (n-1-2*j)*c;
            if(b == k) {
                cout << "YES" << endl;
                return 0;
            }
        }

        cout << "NO" << endl;
        return 0;
    }*/

    rep(j, n) {
        ll u = a + (n-1-j)*c - j*d;
        ll v = a - j*c + (n-1-j)*d;
        if(u <= b && b <= v) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
ll INF = 9999999999999999;

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

int main(void){
    ll N; cin >> N;
    vector<pair<ll, ll>> p(N);
    for(int i = 0; i < N; i++){
        cin >> p[i].second >> p[i].first;
    }
    sort(p.begin(), p.end());
    for(int i = 0; i < N; i++){
        swap(p[i].first, p[i].second);
        // cout << p[i].first << " " << p[i].second << endl;
    }
    
    bool OK = true;
    ll now = 0;
    for(int i = 0; i < N; i++){
        now += p[i].first;
        if(now > p[i].second) OK = false;
    }
    
    if(OK) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define int long long 
#define dou double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int n,k,x;
	cin >> n;
	int arr[n+1];
	int sum=0;
	vector<int>count(100001,0);
	for(int i=0;i<n;i++){
		cin >> arr[i];
		sum+=arr[i];
		count[arr[i]]++;
	}
	int q,b,c;
	cin >> q;
	for(int j=0;j<q;j++){
		cin >> b >> c;
		x=count[b];
		sum=sum-b*x+c*x;
		count[c]+=x;
		count[b]-=x;
		cout << sum << endl;		
	}
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	return 0;
}


Measured memory_bytes: 4692
while line = gets
  m = /([0-9X]+)\+([0-9X]+)=([0-9X]+)/.match(line)
  next unless m
 
  x_s, y_s, z_s = m[1], m[2], m[3]
  numbers = (0..9).to_a
  [x_s, y_s, z_s].each do |s|
    if s.length > 1 && s[0] == "X"
      numbers -= [0]
      break
    end
  end
 
  found = false
  numbers.each do |n|
    x, y, z = [x_s, y_s, z_s].map {|s| s.gsub("X", n.to_s).to_i}
    if x + y == z
      found = true
      puts n
      break
    end
  end
 
  puts "NA" unless found
end

Measured memory_bytes: 8812
#include <iostream>

using namespace std;

int main(){
    int a,b;
    int answer;
    char op;
    
    while(1){
        cin >> a >> op >> b;
        
        if(op == '?'){
            break;
        }
        
        if(op == '+'){
            answer = a + b;
        }else if(op == '-'){
            answer = a - b;
        }else if(op == '*'){
            answer = a * b;
        }else if(op == '/'){
            answer = a / b;
        }
        
        cout << answer << endl;
        
    }
    
    return 0;
    
}


Measured memory_bytes: 3112
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
      #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
       ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
           # #  # # #                   # #      ###### #    # #    # #      #####
      #    # #   #  #              #    # #      #    # #    # #    # #      #   #
       ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long  LLi;
typedef long long LL;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef vector<pair<LLi, LLi> > VP;
 
 
#define For(in) for (LLi i = 0; i < (n); i++)
#define FOR(in) for(LLi i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 

 
 
int main()
{
	long long a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>17)cout<<no<<endl;
	else cout<<yes<<endl;
 
    exit()
 
 
}


Measured memory_bytes: 3608
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		long a = 0,b = 0; 
		long A = 0,B = 0;      
		for( int i=1; i*i<=N; i++ ){
			a++;
			b = N/a;
			if( N%a==0 ){
				A = a;
				B = b;              
			}
			if( a>=b ){
				break;              
            }              
			if( i*i==N ){
				A = N;
				B = 1;
			}
		}
		System.out.println((A-1)+(B-1));
	}
}


Measured memory_bytes: 23892