akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define pb push_back
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
typedef long long LL;
int read(){
	char c=getchar();int d=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';d=d*10+c-48,c=getchar());
	return d*f;
}
const int N=200100,mod=1e9+7;
bool instk[N];
int n,tp,top,tmpr,ans,w[N],res,f[N],mkx[N],mky[N],F[N],vis[N],stk[N],h[N],t[N];
struct xint{int x,y;}p[N];
vector<int> vx[N],vy[N];

int cnt,head[N];
struct Xint{int to,next;}V[N*8];
void add(int x,int y){
	V[++cnt]=(Xint){y,head[x]};head[x]=cnt;
	V[++cnt]=(Xint){x,head[y]};head[y]=cnt;
}

bool cmpx(int a,int b){return p[a].x<p[b].x;}
bool cmpy(int a,int b){return p[a].y<p[b].y;}
void nosolution(){
	printf("0\n");exit(0);
}
void dfs(int f,int x){
	if(instk[x]){
		for(int i=top;i>0;i--){
			h[++h[0]]=stk[i];
			if(stk[i]==x)break;
		}return;
	}
	if(vis[x])return;
	if(!mkx[p[x].x])tmpr++;mkx[p[x].x]=1;
	if(!mky[p[x].y])tmpr++;mky[p[x].y]=1;
	tmpr--;
	vis[x]=1;
	stk[++top]=x;instk[x]=1;
	for(int i=head[x];i;i=V[i].next){
		int y=V[i].to;if(y!=f)dfs(x,y);
	}
	stk[top--]=0;instk[x]=0;
}
int dfs(int x){
	vis[x]=tp;
	t[x]=0;
	int X=p[x].x,Y=p[x].y,sum=1;
	if(w[x]==1){
		int sz=vx[X].size();
		ref(i,0,sz-1)if(vx[X][i]!=x&&vis[vx[X][i]]!=tp){
			int y=vx[X][i];w[y]=2;
			int s=dfs(y);
			if(p[y].y<Y){
				t[x]+=t[y];
				sum=(LL)sum*F[t[y]]%mod*s%mod;
			}else res=(LL)res*F[t[y]]%mod*s%mod;
		}
	}
	if(w[x]==2){
		int sz=vy[Y].size();
		ref(i,0,sz-1)if(vy[Y][i]!=x&&vis[vy[Y][i]]!=tp){
			int y=vy[Y][i];w[y]=1;
			int s=dfs(y);
			if(p[y].x<X){
				t[x]+=t[y];
				sum=(LL)sum*F[t[y]]%mod*s%mod;
			}else res=(LL)res*F[t[y]]%mod*s%mod;
		}
	}
	sum=(LL)sum*f[t[x]]%mod;
	t[x]++;
	return sum;
}
void work(int x){
	tmpr=0;h[0]=0;dfs(0,x);
	if(tmpr!=0)nosolution();
	int o=0,xx,yy,s=0,Res=0;res=1;
	ref(i,1,h[0])if(!o||xx<p[h[i]].x||xx==p[h[i]].x&&yy<p[h[i]].y)
		o=h[i],xx=p[h[i]].x,yy=p[h[i]].y;
	tp=2;w[o]=1;s=dfs(o);Res=(Res+(LL)res*F[t[o]]%mod*s%mod)%mod;res=1;
	tp=3;w[o]=2;s=dfs(o);Res=(Res+(LL)res*F[t[o]]%mod*s%mod)%mod;
	ans=(LL)ans*Res%mod;
}
int mi(int a,int b){
	int s=1;
	for(;b;b>>=1,a=(LL)a*a%mod)
		if(b&1)s=(LL)s*a%mod;
	return s;
}
void init(){
	f[0]=F[0]=1;
	ref(i,1,n)f[i]=(LL)f[i-1]*i%mod;
	F[n]=mi(f[n],mod-2);
	def(i,n-1,1)F[i]=(LL)F[i+1]*(i+1)%mod;
}
int main(){
	n=read();n=n*2;
	ref(i,1,n)p[i].x=read(),p[i].y=read();
	ref(i,1,n)vx[p[i].x].pb(i),vy[p[i].y].pb(i);
	ref(i,1,n/2)if(!vx[i].empty()){
		sort(vx[i].begin(),vx[i].end(),cmpy);
		int s=vx[i].size();
		ref(j,0,s-2)add(vx[i][j],vx[i][j+1]);
	}
	ref(i,1,n/2)if(!vy[i].empty()){
		sort(vy[i].begin(),vy[i].end(),cmpx);
		int s=vy[i].size();
		ref(j,0,s-2)add(vy[i][j],vy[i][j+1]);
	}
	init();ans=f[n];
	ref(i,1,n)if(!vis[i])work(i);
	printf("%d\n",ans);
}

Measured memory_bytes: 34688
/* ex 9_2
   riverstone */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

void push(node **first, char elem);
char pop(node **first);

int main(void){
    //最初のノードの指す先
    node *first = NULL;
    int i,ret = 0;
    //入力する配列を定義
    char cube_input[SIZE];
    scanf("%s", cube_input);
    
    for (i=0;i<strlen(cube_input);i++){
        //最初のキューブ、及び赤色のキューブと青色のキューブが隣り合っている時
        if (first == NULL || cube_input[i] == first -> elem){
            //スタックにプッシュする。
            push(&first, cube_input[i]);
        }

        //隣り合っていない場合はそのまま追加
        else{
            //スタックからデータを取り出す。
            pop(&first);
            //2つキューブを取り除けたことになる
            ret += 2;
        }
    }
    printf("%d\n", ret);
    return 0;
}

//スタックにデータを追加
//先頭を示すノードと追加するデータを引数にする
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL){
        exit(1);
    }

    //新しいノード(要素と次の要素のポインタのセット)を作る
    new->elem = elem;
    new->next = *first;
    //先頭のノードを新しく作ったノードにする。
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;

    if(tmp == NULL){
        exit(1);
    }
    //先頭のノードの要素を取り出す
    elem = tmp->elem;
    //先頭のポインタを1つずらす
    *first = tmp->next;

    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

Measured memory_bytes: 4880
#include <iostream>
using namespace std;
using ULL = unsigned long long;
using LL = long long;
using pii = pair<int, int>;
const int MAX_N = 1e7;
int nr_divisors[MAX_N + 1];


int main()
{
    cin.sync_with_stdio(0);

    int N;
    cin >> N;

    for (int i = 1; i <= N; ++i)
    {
        for (int j = i; j <= N; j += i)
        {
            ++nr_divisors[j];
        }
    }

    LL res = 0;
    for (int K = 1; K <= N; ++K)
    {
        res += (LL)K * nr_divisors[K];
    }

    cout << res;
}

Measured memory_bytes: 42644
#include<iostream>
#include<map>
#include<cmath>
#include<string>

using namespace std;

void debug(char a[100][100], string s, int N) {
	cout << "debug:" << s << endl;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cout << i << "," << j << ":=" << a[i][j] << endl;
		}
	}
}

int main() {
	int N, M;
	char a[100][100];
	char b[100][100];


	cin >> N;
	cin >> M;

	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < M; i++) {
		cin >> b[i];
	}

	//debug(a, "a", N);
	//debug(b, "b", M);

	char c[100][100];
	for (int i = 0; i < N-M+1; i++) {
		for (int j = 0; j < N-M+1; j++) {
			if (a[i][j] == b[0][0]) {
				for (int k = 0; k < M; k++) {
					for (int l = 0; l < M; l++) {
						c[k][l] = a[k+i][l+j];
					}
				}
				//debug(c, "c", M);
				int flag = 1;
				for (int x = 0; x < M; x++) {
					for (int y = 0; y < M; y++) {
						if (c[x][y] != b[x][y]) flag = 0;
					}
				}
				if (flag) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
program am
    implicit none
    character(12)::S,T
    integer::l
    logical::check=.true.
    read*,S
    read*,T
    l=len_trim(S)
    if(S(1:l)/=T(1:l))check=.false.
    print"(A)",trim(merge("Yes","No ",check))
contains 

end program am

Measured memory_bytes: 2920
import java.util.Scanner;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final int N;

    public Main() {
	N = Integer.parseInt(scan.next());

	scan.close();
    }

    public final void answer() {
	int a0 = N % 10;
	int a1 = N / 10;

	System.out.println(a0 == 9 || a1 == 9 ? "Yes" : "No");
    }
}


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

int main(){
    int N,K; cin >> N >> K;
    vector<int> A(N,0),B(N,0);
    rep(i,N) cin >> A[i];
    rep(k,min(K,41)){
        rep(i,N) B[i] = 0;
        rep(i,N){
            int l,r;
            l = max(0,i-A[i]);
            r = min(N-1,i+A[i]);
            B[l]++;
            if(r+1<N)B[r+1]--;
        }
        for(int i=1;i<N;i++) B[i] += B[i-1];
        A = B;
    }
    rep(i,N) cout << A[i] << " ";
    cout << endl;
}

Measured memory_bytes: 4812
#include<bits/stdc++.h>
#define ll long long
#define mod (long long)(1e9+7)
#define endl "\n"
using namespace std;


void solve(){
	ll n,x,t;
	cin>>n>>x>>t;
	cout<<(n/x)*t+(n%x!=0?t:0)<<endl;
}


int main(){
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define mp make_pair
// #define pb push_back
#define ll long long
#define endl "\n"
using namespace std;


int main() {
	ll n;
	cin>>n;
	long double a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll req=(n+1)/2;
	long double dp[n+1][req+1];
	for(ll i=0;i<=n;i++){
		for(ll j=0;j<=req;j++){
			if(j==0){
				dp[i][j]=1.0;
			}
			else if(i==0){
				dp[i][j]=0.0;
			}
			else{
				dp[i][j]=(a[i-1]*dp[i-1][j-1]) + ((1.0-a[i-1])*dp[i-1][j]);
			}
		}
	}
	cout<<fixed<<setprecision(10)<<dp[n][req]<<endl;
}

Measured memory_bytes: 74156
import java.util.*;
import java.io.*;
class Main{
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		int n=in.nextInt();
		int a[]=new int[n];
		int count=0;
		for(int i=0;i<n;i++)
			a[i]=in.nextInt();
		for(int i=0;i<n;i++){
			for(int j=n-1;j>=i+1;j--){
				if(a[j]<a[j-1]){
					count++;
					int temp=a[j];
					a[j]=a[j-1];
					a[j-1]=temp;
				}
			}
		}
		for(int i=0;i<n;i++){
			if(i==n-1)
				out.printf(a[i]+"\n");
			else
				out.print(a[i]+" ");
		}
		out.println(count);

	}
}


Measured memory_bytes: 26544
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(" ").map { it.toInt() }
    val l = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    var cnt = 0
    var sum = 0
    for (i in l) {
        sum += i
        if (sum <= x) cnt++
    }
    println(cnt + 1)
}

Measured memory_bytes: 37908
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  vvi c(3, vi(3));
  rep(i,3){
    rep(j,3) cin >> c.at(i).at(j);
  }
  
  rep(i,2){
    int p = c.at(i).at(2) - c.at(i+1).at(2);
    rep(j,2){
      if(p == c.at(i).at(j) - c.at(i+1).at(j)) continue;
      NO;
      return 0;
    }
  }
  rep(j,2){
    int p = c.at(2).at(j) - c.at(2).at(j+1);
    rep(i,2){
      if(p == c.at(i).at(j) - c.at(i).at(j+1)) continue;
      NO;
      return 0;
    }
  }
  YES;
  return 0;
}


Measured memory_bytes: 3584
import numpy as np

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

ins = np.zeros(5)
ins[0] = a
ins[1] = b
ins[2] = c
ins[3] = d
ins[4] = e

ls = np.zeros(5)
ls[0] = a%10
ls[1] = b%10
ls[2] = c%10
ls[3] = d%10
ls[4] = e%10

count=0
for i in range(5):
    if ls[i]==0:
        count=count+1
x = np.argsort(ls)

ans = 0
for i in range(5):
    if ls[i]==0:
        ans = ans+ins[i]
    elif i==x[count]:
        ans = ans+ins[i]
    else:
        ans = ans + ((ins[i]//10)+1)*10
print(int(ans))


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

int main(){
    int N, Y;
    cin >> N >> Y;
    Y /= 1000;
    int x = 0, y, z;
    while( x * 9 <= Y - N){
        if((Y - N - 9 * x) % 4 == 0 ){
            y = (Y - N - 9 * x) / 4;
            if(N - x - y >= 0){
                cout << x << " " << y << " " << N - x - y << endl;
                return 0;
            }
        }
        x++;
    }
    cout << "-1 -1 -1\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  FOR(i,0,1<<3) {
    string ans = "";
    ans += s[0];
    int num = s[0] - '0';
    FOR(j,0,3) {
      // +
      if((i>>j)&1) {
        num += s[j+1] - '0';
        ans += "+";
        ans += s[j+1];
      } else {
        num -= s[j+1] - '0';
        ans += "-";
        ans += s[j+1];
      }
    }
    if(num == 7) {
      ans += "=7";
      cout << ans << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
ki = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ki[a].append(b)
    ki[b].append(a)
#print(ki)
c = list(map(int,input().split()))
c.sort()
c.reverse()
point = 1
lis = [0] * N
que = deque([0])
lis[0] = c[0]
while len(que) != 0:
    p = que.popleft()
    #print(p)
    for i in ki[p]:
        if lis[i] == 0:
            que.append(i)
            lis[i] = c[point]
            point += 1
print(sum(c)-c[0])
print(' '.join(map(str,lis)))


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

using namespace std;

typedef unsigned long long ull;

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int field[100][100];
int cost[100][100];
int n, m;

int main(){
    while(cin >> n >> m, n+m){
        rep(i, 100)rep(j, 100) cost[i][j] = inf;

        for(int i=0; i< m*2-1; i++){
            for(int j=0; j < n; j++){
                if(i%2==0 && j == n-1) break;
                if(i%2==0) cin >> field[i][j*2+1];
                else cin >> field[i][j*2];
            }
        }
        queue<pair<int, int> >que;
        que.push(make_pair(0, 0));
        cost[0][0] = 0;

        while(que.size()){
            pair<int, int> p = que.front(); que.pop();
            if(p.first == m*2-2 && p.second == n*2-2) break;
            int dx[4] = {1, 0, -1, 0};
            int dy[4] = {0, 1, 0, -1};
            for(int i=0; i < 4; i++){
                if(0 <= p.first+dx[i]*2 && p.first+dx[i] < m*2-1 && 0 <= p.second+dy[i]*2 && p.second+dy[i] < n*2-1 && field[p.first+dx[i]*2][p.second+dy[i]] != 1 && field[p.first+dx[i]][p.second+dy[i]*2] != 1 && cost[p.first+dx[i]*2][p.second+dy[i]*2] == inf){
                    que.push(make_pair(p.first+dx[i]*2, p.second+dy[i]*2));
                    cost[p.first+dx[i]*2][p.second+dy[i]*2] = cost[p.first][p.second]+1;
                }
            }
        }
        int ret = cost[m*2-2][n*2-2];
        cout << (ret==inf?0:ret+1) << endl;
    }
}

Measured memory_bytes: 1276
import numpy as np
S = list(input())
cnts = [0]*len(S)

c = 0
for idx in range(len(S)):
    if S[idx] == 'R':
        c += 1
    else:
        cnts[idx] += np.floor(c / 2)
        cnts[idx-1] += np.ceil(c / 2)
        c = 0

c = 0
for i in range(len(S)):
    idx = len(S)-i-1
    if S[idx] == 'L':
        c += 1
    else:
        cnts[idx] += np.floor(c / 2)
        cnts[idx+1] += np.ceil(c / 2)
        c = 0
        
print(' '.join([str(int(x)) for x in cnts]))


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

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main() {
  long long N,M,c=1;
  cin>>N>>M;
  vector<long long> num(N+1,0);
  for(int i=1;i<=N;i++){
    cin>>num.at(i);
    num.at(i)=(num.at(i-1)+num.at(i))%M;
  }
  sort(num.begin(),num.end());
  vector<long long> kosu(0);
  for(int i=0;i<=N;i++){
   // int c=1;
    if(i==N||num.at(i)!=num.at(i+1)){
      kosu.push_back(c);
      c=1;
    }
    else{
      c++;
    }
  }
  long long ans=0;
  for(int i=0;i<kosu.size();i++){
    ans+=(kosu.at(i)*(kosu.at(i)-1))/2;
  }
  cout<<ans;
       
    
}


Measured memory_bytes: 1660
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A = LI()

from math import gcd

g = 0  # Aiたちの最大公約数
for i in range(N):
    g = gcd(g,A[i])

if g != 1:
    print('not coprime')
    exit()

B = []
for i in range(N):
    if A[i] != 1:
        B.append(A[i])
N = len(B)
# 以下、このB,Nで考えれば良い

if N == 0:
    print('pairwise coprime')
    exit()

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
# 1000以下の素数のリスト(168個)

if N > 78498:  # 78498は10**6以下の素数の個数
    print('setwise coprime')
    exit()

C = [0]*(10**6+1)  # C[i] = 1 ⇔ Bの元に素因数iを持つものが存在する

for i in range(N):
    b = B[i]
    for p in primes:
        if b % p == 0:
            if C[p] == 1:
                print('setwise coprime')
                exit()
            else:
                C[p] = 1
            while b % p == 0:
                b //= p
    if b != 1:
        if C[b] == 1:
            print('setwise coprime')
            exit()
        else:
            C[b] = 1

print('pairwise coprime')

# 計算量 O(min(N,A/logA)*√A/logA) ?




Measured memory_bytes: 205972
#include <cstdio>
#include <algorithm>
#include <iostream>
#define ll long long
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (a < 10)
		cout << (10 - a) * 100 + b << endl;
	else
		cout << b;
	return 0;
}

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

int n, m;
vector<int> vertex[51];

int main(){
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int s, t;
    cin >> s >> t;
    vertex[s].push_back(t);
    vertex[t].push_back(s);
  }
  for(int i = 1; i <= n; i++){
    cout << vertex[i].size() << endl;
  }
}


Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
S = gets.chomp.chars.take(N)
zero_list = []
zero_start = nil
S.each.with_index do |ch, i|
  if ch == '0'
    zero_start = i unless zero_start
    if i == S.size - 1
      zero_list.push([zero_start, i])
    end
  else
    if zero_start
      zero_list.push([zero_start, i - 1])
      zero_start = nil
    end
  end
end

if zero_list.empty?
  puts N
  exit
end
ans = 0
(0..(zero_list.size - 1)).each do |i|
  s = nil
  if i == 0
    s = 0
  else
    s = zero_list[i - 1][1] + 1
  end
  e = nil
  if i == zero_list.size - 1
    e = N - 1
  elsif i + K <= zero_list.size - 1
    e = zero_list[i + K][0] - 1
  else
    e = N - 1
  end
  count = (e - s) + 1
  ans = count if count > ans
end
puts ans


Measured memory_bytes: 11132
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#include <functional>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const ll mod = 1000000000 + 7; //10^9

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N + 1);
    B[0] = 0;
    for (ll i = 0; i < N; i++)
    {
        cin >> A[i];
        B[i + 1] = (A[i] + B[i]) % mod;
    }
    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
        ans += A[i] * ((B[N] - B[i + 1] + mod) % mod) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6356
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<stack>
#include<queue>
#include<stdlib.h>
#include<string.h>
#include<vector>
#define LL long long
#define  long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const double INF=1e9+7;
LL Find[100005];
LL find(int x) {return Find[x]==x?x:Find[x]=find(Find[x]);}
int a[100][100];
int b[100];
int main()
{

     int n,m,c;
     scanf("%d%d%d",&n,&m,&c);
     for(int i=1;i<=m;i++)
     {
         scanf("%d",&b[i]);
     }
     for(int i=1;i<=n;i++)
     {
         for(int j=1;j<=m;j++)
         {
             scanf("%d",&a[i][j]);
         }
     }
     int sum=0;
     for(int i=1;i<=n;i++)
     {
         int ans=c;
         for(int j=1;j<=m;j++)
            ans+=a[i][j]*b[j];
         if(ans>0) sum++;
     }
     printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main {

	int gcd(int x, int y){ return y==0?x:gcd(y,x%y); }

	class Frac{
		int a, b;
		Frac(int _a, int _b){
			int d = _a==0?1:gcd(_a,_b);
			this.a = _a/d;
			this.b = _b/d;
		}
	}

	long[] sqs;

	class Cmp implements Comparator<Frac>{
		public int compare(Frac x, Frac y){
			int dif = x.a*y.b - x.b*y.a;
			return Integer.signum(dif);
		}
	}

	void run(){
		Scanner in = new Scanner(System.in);
		init();
		for(;;){
			int p = in.nextInt(), n = in.nextInt();
			if(n==0 && p==0) return ;
			solve(n,p);
		}
	}

	void init(){
		sqs = new long[10005];
		for(int i=0; i<10005; i++){
			sqs[i] = (long)i*i;
		}
	}

	void solve(int n, int p){
		Frac[] lower = new Frac[n], upper = new Frac[n];
		lower[0] = new Frac((int)sqrt(p),1);
		upper[0] = new Frac((int)(sqrt(p)+1),1);
		for(int i=2; i<=n; i++){
			int id = - 1 - binarySearch(sqs, (long)p*i*i);
			if(1<=id-1 && id-1<=n) lower[i-1] = new Frac(id-1,i);
			else lower[i-1] = new Frac(0,1);
			if(1<=id && id<=n) upper[i-1] = new Frac(id, i);
			else upper[i-1] = new Frac(p,1);
		}
		sort(lower, new Cmp());
		sort(upper, new Cmp());
		System.out.printf("%d/%d %d/%d\n", upper[0].a, upper[0].b, lower[n-1].a, lower[n-1].b);
	}

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

Measured memory_bytes: 17000
#include<bits/stdc++.h>
using namespace std;
#define MAXN 500
#define LL long long int
#define DEBUG false

int N, K, A[MAXN + 3], sumA;

bool check(int g) {
    if (DEBUG) {
        cout << "\n#####################\n";
        cout << "DEBUG check " << g << endl;
    }

    int r[MAXN + 3];
    LL sumNeg[MAXN + 3], sumPos[MAXN + 3];

    for (int i = 1; i <= N; i++)
        r[i] = A[i]%g;

    sort(r + 1, r + N + 1);

    sumNeg[0] = 0;
    for (int i = 1; i <= N; i++) sumNeg[i] = sumNeg[i - 1] + r[i];

    sumPos[N + 1] = 0;
    for (int i = N; i >= 1; i--) sumPos[i] = sumPos[i + 1] + (g - r[i]);

    if (DEBUG) {
        cout << "r:\n";
        for (int i = 1; i <= N; i++)
            cout << r[i] << " ";
        cout << endl;

        cout << "sumNeg:\n";
        for (int i = 1; i <= N; i++)
            cout << sumNeg[i] << " ";
        cout << endl;

        cout << "sumPos:\n";
        for (int i = 1; i <= N; i++)
            cout << sumPos[i] << " ";
        cout << endl;
    }

    for (int i = 1; i <= N - 1; i++) {
        if (sumNeg[i] == sumPos[i + 1] && sumNeg[i] <= K)
            return true;
    }

    //Corner case, no need to perform operation
    if (sumNeg[N] == 0)
        return true;

    return false;
}

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

    sumA = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        sumA += A[i];
    }

    if (DEBUG) {
        cout << "sumA: " << sumA << endl;
    }

    int answer = 0;
    for (int g = 1; g * g <= sumA; g++) {
        if (sumA % g == 0) {
            if (check(g)) answer = max(answer, g);
            if (check(sumA/g)) answer = max(answer, sumA/g);
        }
    }

    cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, par[2*int(1e5)+1], s[2*int(1e5)+1];
int find(int x){
    if (par[x]==x) return x;
    return par[x]=find(par[x]);
}
int main(){
    cin >> n >> m;
    for (int i=1; i<=n; i++) par[i]=i;
    for (int i=1; i<=m; i++){
        int x, y;
        cin >> x >> y;
        int a=find(x), b=find(y);
        if (a!=b) par[a]=b;
    }
    int maxx=0;
    for (int i=1; i<=n; i++) s[find(i)]++;
    for (int i=1; i<=n; i++) maxx=max(maxx, s[i]);
    cout << maxx << endl;
    return 0;
}

Measured memory_bytes: 10520
class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size))
        self.rank = [0] * size

    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

N, M = map(int, input().split())
L = [list(map(int, input().split()))[1:] for _ in range(N)]
uf = UnionFind(M+1)
used = [False] * (M+1)
for i in range(N):
    u = L[i][0]
    used[u] = True
    for v in L[i][1:]:
        used[v] = True
        uf.unite(u, v)
root = set()
for v in range(1, M+1):
    if used[v]:
        root.add(uf.find(v))
if len(root) == 1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 76632
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int n, *A, q, M;

bool dfs(int i, int sum) {
	if (sum > M) return false;
	if (i == n) return (sum == M);
	if (dfs(i + 1, sum + A[i])) return true;
	if (dfs(i + 1, sum)) return true;
	return false;
}

int main() {
	cin >> n;
	A = new int[n];
	for (int i = 0; i < n; i++)
		cin >> A[i];

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> M;
		if (dfs(0, 0))
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	delete[] A;
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
using namespace std;

const int N = 1e6 + 5;

//int a[N];


void solve() {
    LL a, b, c;
    scanf("%lld %lld %lld", &a, &b, &c);
    if(a + b >= c) {
        puts("No"); return ;
    }
    LL res = c - a - b;
    res = res * res;
    if(4LL * a * b < res) {
        puts("Yes");
    }
    else puts("No");
    return ;
}

int main() {
//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	
	public static void Main(string[] args)
	{
		var k = Console.ReadLine().ToInt();
		if(k < 1000)
			Console.WriteLine("ABC");
		else
			Console.WriteLine("ABD");
	}


	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


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

const int MAX = 200000;
const int MOD = 1000000007;

//逆元計算
  long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    u=(u+m)%m;
    return u;
  }
  
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
  int64_t n, a, b, fa=1,fb=1;
  cin>>n>>a>>b;

  vector<int> inv(b+1, 1);
  for(int i=1; i<b+1; i++){
    inv.at(i)=modinv(i,MOD);
  }

  for(int i=0; i<a; i++){
    fa=(fa*(n-i)%MOD)*inv.at(i+1)%MOD;
  }
  for(int i=0; i<b; i++){
    fb=(fb*(n-i)%MOD*inv.at(i+1))%MOD;
  }
  cout<<((modpow(2, n, MOD)-1-fa-fb)%MOD+MOD)%MOD<<endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int ans = 1;
  int d[110];
  cin >> N;
  for (int i; i < N; i++)
    cin >> d[i];
  sort(d, d+N);
  for (int i = 0; i < N-1; i++)
    ans += (d[i] != d[i+1]);
  cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

#define lpair pair<ll, ll>

int main()
{
  string n;
  cin >> n ;
  string ans = (n[0] >= 'a' && n[0] <= 'z') ? "a" : "A";

  cout << ans << endl;

  return 0;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

signed main() {
  int a[3] = {};
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    a[s[i] - 'a']++;
  }

  sort(a, a + 3);

  a[2] -= a[0];
  a[1] -= a[0];
  a[0] = 0;
  for (int i = 0; i < 3; ++i) {
    if (a[i] >= 2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll sqr(ll x){
	return x * x;
}

ll solve(ll x, vector<ll> &v){
	ll ans = 0;
	for(auto &y : v){
		ans += sqr(abs(y - x));
	}
	return ans;
}

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	
	vector<ll> x(n);
	for(int i = 0; i < n; i++)
		cin >> x[i];
	
	
	
	ll ans = 1e15;
	for(ll y = -1000; y <= 1000; y++){
		ans = min(ans, solve(y, x));
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
from scipy.special import comb

N = int(input())
index = list(map(int, input().split()))
val = [0]*max(index)
for i in index:
    val[i-1] += 1
total = 0
for i in val:
    if i >= 2:
        total += comb(i, 2, exact=True)
for i in index:
    if val[i-1] >= 2:
        print(total-(comb(val[i-1], 2, exact=True)-comb(val[i-1]-1, 2, exact=True)))
    else:
        print(total)


Measured memory_bytes: 65988
#include <bits/stdc++.h>
	
using namespace std;
 
#define int long long
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define LOCAL
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)
 
typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;
 
const int INF = LONG_LONG_MAX/2;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

int32_t main() {
	FAST_IO;
	
	int n, k;
	cin >> n >> k;
	
	vi p(n);
	for (int& x: p) cin >> x;
	
	sort(ALL(p));
	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += p[i];
	}
	cout << ans << endl;
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


Measured memory_bytes: 3640
A,B = map(int,input().split())
S = input().strip()
flag = 0
for i in range(A+B+1):
    if i==A:
        if S[i]!="-":
            flag = 1
            break
    else:
        if not(48<=ord(S[i])<=57):
            flag = 1
            break
if flag==1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int dis = in.nextInt();
        in.close();
        dis += dis + 1;
        int ans = num / dis;
        if (num % dis != 0) {
            ans++;
        }
        System.out.println(ans);
    }
}

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

int main(){
  int N;
  int d[110];
  cin >> N;
  
  for(int i = 0;i < N;i++)cin >> d[i];
  
  int num[110] = {0};
  
  for (int i = 0;i < N;i++){
    num[d[i]]++;
  }
  
  int res = 0;
  for (int i = 1;i <= 100;i++){
    if(num[i]){
      res++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
from fractions import gcd


def prime_factors(n):
    i = 2

    factors = []

    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)

    return factors


A, B = [int(x) for x in input().split()]

print(len(set(prime_factors(gcd(A, B)))) + 1)


Measured memory_bytes: 5048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				int result = i * j;
				if (N == result) {
					System.out.println("Yes");
					return;
				}

			}
		}
		System.out.println("No");
	}

}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
int main(){
    int n,m;
    cin>>n>>m;
    char s[n][n],t[m][m];
    rep(i,0,n)cin>>s[i];
    rep(i,0,m)cin>>t[i];
    
    int ok2=1;
    rep(i,0,n-m+1){
      rep(j,0,n-m+1){
        if(s[i][j]==t[0][0]){
          ok2=1;
          int ok=1;
          rep(k,0,m){
            rep(l,0,m){
              if(s[i+k][j+l]!=t[k][l])ok=0;
            }
            if(!ok){
              ok2=0;
              break;
            }
          }
          if(ok2){
              cout<<"Yes"<<endl;
              return 0;
          }
        }
      }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	char ch[n];
	int flag = 0;
	for(int i = 0; i<n; i++) { cin>>ch[i]; if(ch[i]=='Y') flag = 1;}
	if(flag) cout<<"Four";
else cout<<"Three";
	return 0;
}

Measured memory_bytes: 256
// E - Colorful Hats 2
#include <bits/stdc++.h>

using namespace std;

#define	MOD	1000000007

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<long long> dp(n), c(n);
	for (int i = 0; i < n; i++) {
		int x = a[i];
		long long m = (x == 0 ? 3LL : c[x - 1]) - c[x];
		if (i == 0) dp[i] = m;
		else dp[i] = dp[i - 1] * m % MOD;
		c[x]++;
	}

	cout << dp[n - 1] << endl;

	return 0;
}


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

const int m[] = {100, 101, 102, 103, 104, 105 };

int main() {

    int x;
    vector<bool> v(100000 + 300, false);

    cin >> x;

    for(int i = 0; i < 6; ++i) {
        v[m[i]] = true;
    }

    for(int i = 100; i <= 100000; ++i) {

        if(v[i] == true) {
            for(int j = 0; j < 6; ++j) {
                v[i + m[j]] = true;
            }


        }

    }

    cout << (int)v[x] << endl;
    return 0;

}

Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

use std::io::Write;

#[allow(unused_must_use)]
fn main() {
    input! {
        n: usize,
        q: usize,
        s: chars,
        lrs: [(usize, usize); q],
    }

    let mut flag = false;
    let mut cnt = 0;
    let mut acc = vec![0; n + 1];
    for (i, c) in s.iter().enumerate() {
        if *c == 'A' {
            flag = true
        } else {
            if *c == 'C' && flag {
                cnt += 1;
            }
            flag = false;
        }
        acc[i + 1] = cnt;
    }
    let out = std::io::stdout();
    let mut buf = std::io::BufWriter::new(out.lock());
    for (l, r) in lrs {
        writeln!(buf, "{}", acc[r] - acc[l]);
    }
}


Measured memory_bytes: 6908
/*      ______     _    _______
       |  ___ \   | |  |  ____/   /\
       | |   \ \  | |  | |       /  \
       | |___/ /  | |  | |___   / /\ \
       |     _/   | |  |  __/  / /__\ \
       | |\ \     | |  | |    / ______ \
       | | \ \    | |  | |   / /      \ \
       |_|  \_\   |_|  |_|  /_/        \_\
*/

#include<bits/stdc++.h>

//#define FILEIO

using namespace std;

const int SZ = 52;
const double EPS = 1e-9;
const int MOD = 100000008;
const int INF = ( 1 << 30 ) - 1;
const double PI = 2 * acos( 0.0 );

template <class T> T MIN(T a, T b) { return (a < b) ? a : b; }
template <class T> T MAX(T a, T b) { return (a > b) ? a : b; }
template <class T> void SWAP(T &a, T &b) { T c; c = a; a = b; b = c; }
template <class T> T GCD(T a, T b) { T c; while(b > 0) { c = a % b; a = b; b = c; } return a; }

bool CMP(int a, int b)
{
    return (a > b);
}

int main()
{
    #ifdef FILEIO
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    long long int a, ans;
    long double b;

    cin >> a >> b;
    ans = a * b;
    //ans = floor(ans);
    cout << ans << endl;

    return 0;
}


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

template <typename T,typename U>
struct compressor{
	vector<pair<T,U>> v;
	void add(T x,U y){
		v.emplace_back(x,y);
	}
	
	void compress(){
		stable_sort(v.begin(),v.end());
		
		vector<pair<T,U>> t;
		rep(i,v.size()){
			if(t.size()!=0 && t.back().first == v[i].first){
				t.back().second = func(t.back().second,v[i].second);
			}
			else{
				t.push_back(v[i]);
			}
		}
		swap(v,t);
		
	}

	U func(U a,U b){
		return a+b;
	}

	U e(){
		return 0;
	}

	int size(){
		return v.size();
	}
	
	U get(int p){
		return v[p].second;
	}
	
	U operator[] (T &x){
		auto it = lower_bound(v.begin(),v.end(),make_pair(x,0));
		if(it==v.end() || it->first!=x){
			if(it!=v.begin()){
				it--;
			}
		}
		if(it==v.end() || it->first!=x){
			return e();
		}
		else return it->second;
	}
};

bool f = false;
compressor<pair<string,string>,int> get(string S){
	int N = S.size();
	compressor<pair<string,string>,int> C;
	for(int i=0;i<(1<<N);i++){
		string s="",t="";
		for(int j=0;j<N;j++){
			if((i>>j)&1)s+=S[j];
			else t+=S[j];
		}
		reverse(t.begin(),t.end());
		if(f)swap(s,t);
		C.add(make_pair(s,t),1);
	}
	f=true;
	C.compress();
	return C;
}
 
int main(){
	
	int N;
	cin>>N;
	
	string S;
	cin>>S;
	
	compressor<pair<string,string>,int> C0 = get(S.substr(0,N)),C1 = get(S.substr(N));
	
	long long ans = 0;
 
	for(auto a:C0.v){
		ans += (long long)a.second * C1[a.first];
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 86156
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let K: usize = read();
    let S: String = read();
    let mut ans = "".to_string();
    for (i, c) in S.chars().enumerate() {
        if i < K {
            ans.push(c);
        } else {
            for _ in 0..3 {
                ans.push('.')
            }
            break;
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn solve() {}

#[cfg(test)]
#[allow(unused_imports)]
mod tests {
    #![allow(unused_imports)]
    use super::*;

    #[test]
    fn test1() {
        assert_eq!(true, true);
    }
}


Measured memory_bytes: 2124
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
int main()
{
    int n,k;cin >> n >> k;

    long long int c_r0=0;
    long long int c_rk2=0;

    for(int i=1;i<=n;i++){
        if(i%k==0) c_r0++;
        if(i%k==k/2) c_rk2++;
    }
    if(k%2==0){
        p(c_r0*c_r0*c_r0+c_rk2*c_rk2*c_rk2)
    } else {
        p(c_r0*c_r0*c_r0)
    }
}

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

string A, B, C;

int main(){
    cin >> A >> B >> C;

    char ans = 'a';
    while(1){
        if( ans == 'a' ){
            if( A.empty() ) break;
            ans = A[0];
            A.erase(A.begin());
        } else if( ans == 'b' ){
            if( B.empty() ) break;
            ans = B[0];
            B.erase(B.begin());
        } else{
            if( C.empty() )   break;
            ans = C[0];
            C.erase(C.begin());
        }
    }
    ans -= 32;
    cout << ans << endl;
}

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

int n,dp[1008][1008],x[1008],y[1008];

int dfs(int l,int r){
  if(dp[l][r]!=1e9)return dp[l][r];
  int res=1e9;
  for(int i=l;i<r;i++){
    dp[l][r]=min(dp[l][r],dfs(l,i)+dfs(i+1,r)+ (y[i]-y[r])+(x[i+1]-x[l]) );
  }
  return dp[l][r];
}

int main(){
  cin>>n;
  r(i,n) cin>>x[i]>>y[i];
  r(i,n)r(j,n) dp[i][j] = (i==j?0:1e9);
  cout<<dfs(0,n-1)<<endl;
}


Measured memory_bytes: 7116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{	
	int n,m,h,a,b,t[100005]={},u[100005]={},sum=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i];
	}
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		if(u[a]<t[b])u[a]=t[b];
		if(u[b]<t[a])u[b]=t[a];
	}
	for(int i=1;i<=n;i++)
	{
		if(t[i]>u[i])sum++;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 4420
#include<bits/stdc++.h>
using namespace std;
const int N=3e3+10;
typedef long long ll;
int n,m,d;
ll  dp[N][N][4],a[N][N];
int main(){
	scanf("%d%d%d",&n,&m,&d);
	for(int i=1,x,y,z;i<=d;i++){
		scanf("%d%d%d",&x,&y,&z);
		a[x][y]=(ll)z;
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	for(int k=1;k<=3;k++){
		dp[i][j][k]=max(dp[i-1][j][3]+a[i][j],max(dp[i][j-1][k-1]+a[i][j],dp[i][j-1][k]));
	}
	printf("%lld\n",dp[n][m][3]);
	return 0;
}

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

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

  ll K; cin >> K;
  ll cnt = 9;
  priority_queue<ll, vector<ll>, greater<ll>> pq;
  for (ll i = 1; i < 10; i++) {
    pq.emplace(i);
  }
  while (true) {
    K--;
    ll x = pq.top(); pq.pop();
    if (K == 0) {
      cout << x << '\n';
      break;
    }
    int d = x % 10;
    if (d > 0) pq.emplace(x * 10 + (d - 1));
    pq.emplace(x * 10 + d);
    if (d < 9) pq.emplace(x * 10 + (d + 1));
  }
  return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int MAXN=100010;
ll a[MAXN];
int n;
ll x,sum;
int main()
{
    sum=0;
	scanf("%d%lld",&n,&x);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	if (sum<x){
		printf("%d\n",n-1);
		return 0;
	}
	sort(a+1,a+n+1);
	int ans=0;
	for (int i=1;i<=n;i++)
	if (x>=a[i])
	{
		x-=a[i]; ans++;
	}
	else break;
	printf("%d\n",ans);
}

Measured memory_bytes: 256