akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    ll n, k; cin>>n>>k;
    vector<ll> a(n), b(n);
    for(int i=0; i<n; i++) cin>>a[i]>>b[i];

    vector<ll> v;
    v.push_back(k);
    bool existZero = false;
    for(int bit=0; bit<32; bit++){
        if(!(k & (1LL << bit))){
            existZero = true;
        }
        else{
            if(existZero){
                ll num = k - k % (1LL << bit) - 1;
                v.push_back(num);
            }
        }
    }

    ll ans=0;
    for(auto i:v){
        ll sum=0;
        for(int j=0; j<n; j++){
            bool valid = true;
            for(int bit=0; bit<32; bit++){
                if(!(i & (1LL << bit)) && (a[j] & (1LL << bit))){
                    valid = false;
                }
            }

            if(valid){
                sum += b[j];
            }
        }

        chmax(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  int i,j;
  int N,M;
  int A[100000],B[100000],cmp,count=0;
 
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  
  int left,right,mid=N;
  
  scanf("%d",&M);
  for(i=0;i<M;i++) scanf("%d",&B[i]);

  for(i=0;i<M;i++){
    
    cmp=B[i];
    
    left=0;
    right=N;
    while(left<right){
     
      mid=(left+right)/2;
    
      if(cmp==A[mid]){
	count++;
	break;
      }
      else if(cmp>A[mid]){
	left=mid+1;
      }
      else if(cmp<A[mid]){
	right=mid;
      }
      
    }
    
  }

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




  return 0;
}



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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N,K;
    cin >> N >> K;
    int A[N];
    int C[N];

    rep(i,N){
        int a;
        cin >> a;
        A[i] = a;
    }

    rep(i,K) {
        int B[N+1] = {};
        rep(j,N){
            int l_min = max(0,j-A[j]);
            int l_max = min(N,j+A[j]+1);
            B[l_min]++;
            B[l_max]--;
        }
        bool t = true;
        rep(j,N){
            if (j==0){
                A[j] = B[j];
            }
            else {
                A[j] = A[j-1] + B[j];
            }
            if (A[j]!=N) {
                t = false;
            }
        }
        if (t) {
            break;
        }
    }
    rep(i,N) {
        cout << A[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 5136
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
using ll = long long;
#define max(a,b) ((a)>(b) ? (a):(b))
#define min(a,b) ((a)<=(b) ? (a):(b))
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

int main(){
  ll K,R;
  cin >> K >> R;
  if (K >= 10) cout << R;
  else cout << R + (100 * (10-K));
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;



int main(){
    int n,m;cin >> n >> m;
    vector<vector<int>> v(n+1);
    vector<int> x(n+1,0);
    for (int i = 0; i < n+m-1; i++) {
        int a,b;cin >> a >> b;
        v[a].pb(b);
        x[b]++;
    }
    int s=0;
    for (int i = 1; i <= n; i++) {
        if(x[i]==0){
            s=i;
            break;
        }
    }
    queue<P> que;
    vector<P> ans(n+1,P(-1,0));
    que.push(P(s,0));
    ans[s]=P(0,0);
    vector<int> y(n+1,0);
    while(!que.empty()){
        P p=que.front();que.pop();
        int ll=p.fs;
        int ss=p.sc;
        y[ll]++;
        for (int k = 0; k < v[ll].size(); k++) {
            if(x[ll]!=y[ll]&&ll!=s) continue;
            que.push(P(v[ll][k],ss+1));
            ans[v[ll][k]]=P(ll,ss+1);
        }
    }    
    for (int i = 1; i <=n ; i++) {
        cout << ans[i].fs << endl;
    }
    return 0;
}





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

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))

int compare_long(const void *a, const void *b)
{
	long *A = (long *)a;
	long *B = (long *)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;
	return 0;
}

int main(void)
{
	//変数の宣言
	int n;
	int a[310][310];
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	llong int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			flag=0;
			for(k=0;k<n;k++){
				if(a[i][j]>a[i][k]+a[k][j]){
					printf("-1");
					return 0;
				}else if(i==k||j==k){
					//nothing;
				}else if(a[i][j]==a[i][k]+a[k][j]){
					flag=1;
				}
			}
			if(flag==0){
				ans=ans+a[i][j];
			}
		}
	}
	
	
	
//	printf("計算部分終了\n");
	//出力
	
	printf("%lld",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
  vector<char> vec;
  char S[11];
  scanf("%s",S);
  int l=strlen(S);
  for(int i=0;i<l;i++){
    if(S[i]=='B'){
      if(vec.size()!=0) vec.pop_back();
    }
    else vec.push_back(S[i]);
  }
  for(vector<char>::iterator it=vec.begin();it<vec.end();it++){
    printf("%c",*it);
  }
  printf("\n");
  return 0;
}


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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    pass:
    c-=b;
    a-=d;
    if(c<=0){
    	cout<<"Yes"<<endl;
    	return 0;
	}
	if(a<=0){
		cout<<"No"<<endl;
		return 0;
	}
	goto pass;
	return 0;
}


Measured memory_bytes: 3620
import numpy as np
n = int(input())
A_1 = np.zeros((4,4), dtype='int64')
A_2 = np.ones((4,4), dtype='int64')
B = np.ones((4,4), dtype='int64')
for _ in range(n-2):
    A_3 = np.dot(B, A_2).T
    A_3 %= 10**9+7
    A_3[2,1] -= A_2[0,2]+A_1[0,2]+A_1[0,3]
    A_3[1,2] -= A_2[0,1]
    A_3[0,1] -= A_2[2,0]
    A_3[3,1] -= A_1[0,2]
    A_1, A_2 = A_2, A_3
print(np.sum(A_3)%(10**9+7))

Measured memory_bytes: 12512
#include <stdio.h>
void swap(int *, int *);

int main(void)
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a > b) {
        swap(&a, &b);
    }
    if (a > c) {
        swap(&a, &c);
    }
    if (b > c) {
        swap(&b, &c);
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

void swap(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>


using namespace std;

int main()
{  
    int a,b;
    //int count=0;
        
    cin>>a>>b;
    
    if(a*b%2!=0)cout<<"Odd"<<endl;
    else cout<<"Even"<<endl;
    
    //cout<<n<<endl;
    
         
    return 0;
    
}

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

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

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007


// 連続する長さを数えてpairをvector		{1,2,1,1,3,2,2}=>{(1,1),(2,1),(1,2),(3,1),(2,2)}
vector<P> count_runlength(int* a, int* b){
	vector<P> v;
	for (int* p = a; p < b;){
		int* q = p;
		while (q < b && *p == *q) q++;
		v.push_back(P(*p, q - p));
		p = q;
	}

	return v;
}


signed main(){

	int N, a[101];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	auto v = count_runlength(a, a + N);
	int r=0;
	for (auto i = v.begin(); i != v.end(); i++)
		r += i->second / 2;

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 256
using System;

namespace A
{
	class Program
	{
		static void Main()
		{
			var line = Console.ReadLine();
			var splited = line.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
			var T = Int32.Parse(splited[0]);
			var X = Int32.Parse(splited[1]);

			Console.WriteLine((double)T / (double)X);
		}
	}
}

Measured memory_bytes: 13140
N = int(input())
W_Str = input()

W = [0] * N
W = W_Str.split(" ")

ans = 100**9
g1 = 0
g2 = 0

for i in range(N):
    g2 = g2 + int(W[i])

for i in range(N):
    g1 = g1 + int(W[i])
    g2 = g2 - int(W[i])
    ans = min(abs(g2-g1),ans)

print(ans)

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

#define N 3
#define N2 9

typedef struct{
  int f[N2];
  int space;
  //char path[20];
  int path;
}Puz;

int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
//char dir[4]={'u','l','d','r'};
//Puz V[N2];
//int vv[N2];

int tail=0,head=0;
Puz queue[2000000];
int cnt=0,key;

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y==NIL)root=z;
  else if(z->key < y->key)y->left = z;
  else y->right = z;
  
}

Node treeSearch(Node u, int k){

  while(u!=NIL && k != u->key){
    if(k < u->key)u = u->left;
    else u = u->right;
  }
  return u;
}

/*

void in(Puz p){
  int i,ten;
  ten=1;
  v[cnt]=0;
  for(i=0;i<N2;i++){
    v[cnt]+=(ten*p.f[i]);
    ten*=10;
    }
   v[cnt]=key;
   printf("aaaa %d,%d\n",v[cnt],cnt);
  cnt++;
 
  }*/

int search(Puz p){
  int i,ten;
  ten=1;
  key=0;
  for(i=0;i<N2;i++){
    key+=(ten*p.f[i]);
    ten*=10;
  }
  // printf("bbbb %d\n",key);
  // printf("bbbb %d\nbbbb %d\n\n",key,v[i]);
     if(treeSearch(root,key)==NIL){
       //printf("ddddddddddddddddddddddddd\n");
	return -1;
      }
  return 1;
}



Puz pop(void){

  head=(head+1)%2000000;
  return queue[head];
}
void push(Puz c){
  tail=(tail+1)%2000000;
  queue[tail]=c;
}

int istarget(Puz p){
  int i;
  for(i=0;i<N2;i++){
    if(p.f[i]!=(i+1))return 0;
  }
  return 1;
}

int bfs(Puz s){
  Puz u,v;
  int tmp,i;
  int sx;
  int sy;
  int tx,ty;
  int r;
  int len=0;
  //s.path[0] = ' ';
  s.path=0;
  push(s);
  // V[s]=1;
  while(head!=tail){
    u=pop();
    //printf("head:%d,tail:%d\n",head,tail);
    if(istarget(u)){
      // printf("bbb\n%d %d %d\n%d %d %d\n%d %d %d\n\n",u.f[0],u.f[1],u.f[2],u.f[3],u.f[4],u.f[5],u.f[6],u.f[7],u.f[8]);
      //return strlen(u.path);
      return u.path;
    }
    sx=u.space/N;
    sy=u.space%N;
    for(r=0;r<4;r++){
      tx=sx+dx[r];
      ty=sy+dy[r];
      // printf("%d %d\n",tx,ty);
      if(tx<0 || ty<0 || tx>=N ||ty>=N)continue;
      v=u;
      // v.ff = dir[r];
      tmp=v.f[u.space];
      v.f[u.space]=v.f[tx*N+ty];
      v.f[tx*N+ty]=tmp;
      v.space=tx*N+ty;
      //printf("(%d,%d) path:%d\n",u.space,tx*N+ty,v.path);
      //printf("aaa\n%d %d %d\n%d %d %d\n%d %d %d\n",v.f[0],v.f[1],v.f[2],v.f[3],v.f[4],v.f[5],v.f[6],v.f[7],v.f[8]);
    
      if(search(v)==1)continue;
      
      insert(key);
      v.path++;
      push(v);
    }
  }
  return 0;
}

int main(){

  int i,j;
  Puz in;
  
  for(i=0;i<N2;i++){
    scanf("%d",&in.f[i]);
    if(in.f[i]==0){
      in.f[i]=N2;
      //in.ff=NULL;
      in.space = i;
    }
  }

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



Measured memory_bytes: 18056
import java.io.*;

class Main{
  public static void main(String[] args)throws java.io.IOException{
	
	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

	String hoge = input.readLine();
	int i = Integer.parseInt(hoge);

	System.out.println(i*i*i);
  }
}

Measured memory_bytes: 24164
#include <iostream>

using namespace std;

int main(){
	int N, T;
	cin >> N >> T;
	int minA = 1e9 + 1, maxB = -1e9 - 1, ans = 0;
	for (int i = 0; i < N; i++){
		int A;
		cin >> A;
		if (A - minA == maxB){
			ans++;
		} else if (A - minA >= maxB){
			ans = 1;
			maxB = A - minA;
		}
		minA = min(minA, A);
	}

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


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

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	HashSet<String> set;

	void run(){
		for(;;){
			int n=sc.nextInt();
			if(n==0){
				break;
			}
			set=new HashSet<String>();
			for(int i=0; i<n; i++){
				set.add(sc.next());
			}
			solve();
		}
	}

	String[] ss;
	int n;

	void solve(){
		for(;;){
			String remove=null;
			for(String s : set){
				for(String t : set){
					if(!t.equals(s)&&t.indexOf(s)>=0){
						remove=s;
					}
				}
			}
			if(remove!=null){
				set.remove(remove);
			}else{
				break;
			}
		}
		ss=set.toArray(new String[0]);
		n=ss.length;
		M=new int[n][n];
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				// ss[i]->ss[j]
				for(int k=0; k<ss[j].length(); k++){
					if(ss[i].endsWith(ss[j].substring(0, k))){
						M[i][j]=k;
					}
				}
				// debug(ss[i], ss[j], M[i][j]);
			}
		}
		now=new char[200];
		ans=null;
		rec(0, -1, 0);
		println(new String(ans).substring(0, length(ans)));
	}

	int[][] M;
	char[] now, ans;

	void rec(int length, int last, int used){
		if(used==(1<<n)-1){
			// debug(now);
			if(ans==null||length(now)<length(ans)
					||(length(now)==length(ans)&&compare(now, ans)<0)){
				ans=now.clone();
			}
		}
		for(int i=0; i<n; i++){
			if((used>>i&1)==0){
				if(last==-1){
					add(now, length, ss[i], 0);
					rec(ss[i].length(), i, used|(1<<i));
					remove(now, 0, ss[i].length());
				}else{
					add(now, length, ss[i], M[last][i]);
					rec(length+(ss[i].length()-M[last][i]), i, used|(1<<i));
					remove(now, length, length+ss[i].length()-M[last][i]);
				}
			}
		}
	}

	void add(char[] cs, int at, String s, int from){
		for(int i=from; i<s.length(); i++){
			cs[at+(i-from)]=s.charAt(i);
		}
	}

	void remove(char[] cs, int from, int to){
		for(int i=from; i<to; i++){
			cs[i]=0;
		}
	}

	int length(char[] cs){
		for(int i=0; i<cs.length; i++){
			if(cs[i]==0){
				return i;
			}
		}
		return cs.length;
	}

	int compare(char[] c1, char[] c2){
		for(int i=0; i<min(c1.length, c2.length); i++){
			if(c1[i]!=c2[i]){
				return c1[i]-c2[i];
			}
		}
		return Integer.signum(c1.length-c2.length);
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 52260
import itertools

N = [i for i in str(input())]
op = ['+', '-']

def isTen(sets):
    num = sets[0]
    op = sets[1]
    formular = '{n1}{op1}{n2}{op2}{n3}{op3}{n4}'.format(
        n1=num[0],
        n2=num[1],
        n3=num[2],
        n4=num[3],
        op1=op[0],
        op2=op[1],
        op3=op[2]
    )
    if eval(formular) == 7:
        return formular + '=7'
    return ''

all_nums = list(itertools.permutations(N))
all_ops = list(itertools.product(op, repeat=3))
all = list(itertools.product(all_nums, all_ops))
for a in all:
    ans = isTen(a)
    if ans != '':
        print(ans)
        exit()


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

void copy(char A[][3], char C[][3], int N){
  for ( int i = 0; i < N; i++ ) strcpy(A[i], C[i]);
}

void trace(char A[][3], int N){
  for ( int i = 0; i < N; i++ ){
    if ( i > 0 ) cout << " ";
    cout << A[i][0] << A[i][1];
  }
  cout << endl;
}

bool isStable(char in[][3], char out[][3], int N){
  for ( int i = 0; i < N; i++ ){
    for ( int j = i+1; j < N; j++ ){
      for ( int a = 0; a < N; a++ ){
        for ( int b = a+1; b < N; b++ ){
          if ( in[i][1] == in[j][1] && !strcmp(in[i], out[b]) && !strcmp(in[j], out[a] ) ) return false;
        }
      }
   }
  }
  return true;
}

void BubbleSort(char C[][3], int N){
  char A[36][3];
  bool s;
  copy(A, C, N);
  for ( int i = 0; i < N; i++ ){
    for ( int j = N-1; j > i; j-- ){
      if ( A[j][1] < A[j-1][1]  ) swap(A[j], A[j-1]);
    }
  }
  trace(A, N);
  s = isStable(C, A, N);
  if (s) cout << "Stable";
  else cout << "Not stable";
  cout << endl;
}

void SelectionSort(char C[][3], int N){
  char A[36][3];
  int minj;
  bool s;
  copy(A, C, N);
  for ( int i = 0; i < N; i++ ){
  	minj = i;
  	for ( int j = i; j < N; j++ ){
  	  if ( A[j][1] < A[minj][1] ) minj = j;
  	}
  	swap(A[i], A[minj]);
  }
  trace(A, N);
  s = isStable(C, A, N);
  if (s) cout << "Stable";
  else cout << "Not stable";
  cout << endl;
}

int main(){
  int N;
  char C[36][3];
  cin >> N;
  for ( int i = 0; i < N; i++ ){
    cin >> C[i][0] >> C[i][1];
    C[i][2] = '\0';
  }

  BubbleSort(C, N);
  SelectionSort(C, N);

  return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i) >> B.at(i);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if (N % 2 == 0) {
        int l = A[N / 2 - 1] + A[N / 2];
        int r = B[N / 2 - 1] + B[N / 2];
        cout << r - l + 1 << endl;
    } else {
        int l = A[N / 2];
        int r = B[N / 2];
        cout << r - l + 1 << endl;
    }
}


Measured memory_bytes: 4844
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=2e5+5;
const int mod=1e9+7;
using namespace std;
int n,k,nr[nmax],x,i,idx,ans;
pair<int,int>a[nmax];
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		if(!nr[x])a[++idx].sc=x;
		nr[x]++;
    }
    for(i=1;i<=idx;i++)a[i].fr=nr[a[i].sc];
    sort(a+1,a+idx+1);
    for(i=1;i<=idx;i++)	
	{
	  if(idx-i+1<=k)rc(ans);	
	  ans+=a[i].fr;	
	}
	return 0;
}

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

using namespace std;

vector<int> dpS;

int S(int K, vector<int>& stones){
  if(dpS[K] == -1){
    dpS[K] = 0;
    for(auto stone : stones)
      if(K-stone >= 0)
        dpS[K] |= (S(K-stone,stones)?0:1);
  }
  return dpS[K];
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> stones(N);
  for(int i=0;i<N;i++)
    cin >> stones[i];
  dpS = vector<int>(K+1,-1);
  dpS[0] = 0; 
  cout << (S(K,stones)?"First":"Second");
  return 0;
} 

Measured memory_bytes: 6912
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;


signed main(){
    ll n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    ll cnt = 0;
    rep(i,0,n){
        ll tmp = 0;
        rep(j,0,n){
            if(s[i+j] != t[j]) break;
            tmp++;
        }

        cnt = max(cnt,tmp);
    }

    cout << 2*n - cnt << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
static long long INF = (1LL<<62);

LL dp[100002] = {0};

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, A, B; cin >> N >> A >> B;
	vector<LL> X;
	for(int i=0; i<N; i++){
		LL x; cin >> x;
		X.push_back(x);
	}

	dp[0] = 0;
	dp[1] = min(A*(X[1]-X[0]), B);
	for(int i=1; i<N; i++){
		dp[i] = dp[i-1] + min(A*(X[i]-X[i-1]), B);
	}
	printf("%lld\n", dp[N-1]);
	return 0;
}


Measured memory_bytes: 5124
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            String S = in.next();
            if (S.equals("RRR")) out.println(3);
            else if (S.contains("RR")) out.println(2);
            else if (S.contains("R")) out.println(1);
            else out.println(0);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 32820
#include <stdio.h>
#include <algorithm>
#include <string.h>

int ans = 123456789;
int blocks[123][3];

int check(int white, int blue, int red){
	int counter = 0;
	for (int a = 0; a < white; a++){
		counter += blocks[a][1] + blocks[a][2];
	}
	for (int a = white; a < blue; a++){
		counter += blocks[a][0] + blocks[a][2];
	}
	for (int a = blue; a < red; a++){
		counter += blocks[a][0] + blocks[a][1];
	}
	return counter;
}

int main(){
	int h, w;
	char buf;
	scanf("%d%d", &h, &w);
	for (int a = 0; a < h; a++){
		for (int b = 0; b < w; b++){
			scanf(" %c", &buf);
			switch (buf){
			case 'W':
				blocks[a][0]++;
				break;
			case 'B':
				blocks[a][1]++;
				break;
			case 'R':
				blocks[a][2]++;
				break;
			}
		}
	}
	for (int a = 1; a <= h - 2; a++){
		for (int b = a + 1; b <= h - 1; b++){
			ans = std::min(ans, check(a, b, h));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
using namespace std;

int main()
{
    string s;
    cin>>s;
    map<char, int> hash;
    
    for(int i=0;i<s.length();i++)
    {
        hash[s[i]]+=1;
    }
     
    if(hash['N']!=0&&hash['S']!=0&&hash['E']&&hash['W']!=0)
    {cout<<"Yes";}
    
   else if(hash['N']>0&&hash['S']>0&&hash['E']==0&&hash['W']==0)
   {cout<<"Yes";}
    
   else if(hash['E']>0&&hash['W']>0&&hash['N']==0&&hash['S']==0)
   {cout<<"Yes";}
    
    else
    {cout<<"No";}
      
    
	return 0;
}

Measured memory_bytes: 3576
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
is_neighbor = [[True] * n for i in range(n)]

f = True
for i in range(n):
    if not f: break
    for s in range(n):
        if not f: break
        for t in range(n):
            if a[s][t] > a[s][i] + a[i][t]:
                f = False
                break
            elif i == s or i == t: continue
            elif a[s][t] == a[s][i] + a[i][t]:
                is_neighbor[s][t] = False
if f:
    ans = 0
    for i in range(n):
        for j in range(n):
            if is_neighbor[i][j]:
                ans+=a[i][j]
    print(ans//2)
else:
    print(-1)

Measured memory_bytes: 75732
#include "bits/stdc++.h"

using namespace std;
using std::vector;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
 
  int t, x; cin >> t >> x;
  printf("%.5lf\n", (float)t / x);  
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

// 制約fを満たす最大値（最小値）の二分探索
// ok < ng なら最大値，ok > ng なら最小値探索になる
template<class T, typename F> T bsearch(T ok, T ng, int loop, F f) {
	for(int i = 0; i < loop; ++i) {
		T middle = (ok + ng) / 2;
		(f(middle) ? ok : ng) = middle;
	}
	return ok;
}

#define EPS (1e-10)

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vl A(n); REP(i, n) cin >> A[i];
	ll cnt = 0;
	REP(i, n) {
		cnt += A[i] % 2;
	}
	cout << (cnt % 2 == 0 ? "YES" : "NO") << endl;

}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    string S[3];
int main(){
    cin>>S[0]>>S[1]>>S[2];
    REP(i,3)cout<<S[i][i];
    cout<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  Int sum=0;
  for(Int a:as) sum+=a;

  if(n&1){
    if(sum&1) drop("First");
    else drop("Second");
  }

  if((~*min_element(as.begin(),as.end())&1) and (~sum&1))
    drop("Second");

  drop("First");
  return 0;
}



Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P std::pair<int,int>
#define double long double
#define prique priority_queue<int,vector<int>,greater<int>>
#define INF LLONG_MAX/3
#define inf INT_MAX/3
#define moder 100000
typedef long long ll;
using namespace std;
signed main() {
	double n,t,a,h;
	cin>>n>>t>>a;
	double ans;
	double g=1000000;
	rep(i,n){
		cin>>h;
		if(abs(a-(t-h*0.006))<g){
			g=abs(a-(t-h*0.006));
			ans=i+1;
		}
	}
	cout<<ans<<endl;	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int n,ans_n=0,ans_k=0;
  cin >> n;
  vector<long int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
    ans_n = max(ans_n,a[i]);
  }
  for(int i = 0;i < n;i++){
    if(abs(ans_n-2*ans_k) > abs(ans_n-2*a[i])){
      ans_k = a[i];
    }
  }
  cout << ans_n << " " << ans_k << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define F first
#define s second
#define int long long		
int x[214514];
int y[214514];
int z[214514];
int a[45][45];
int sum[214514];
signed main(){
	sc(s) sc(t)
	int n=s.size();
	rep(0,i,n){
		if(s==t){
			c("Yes")
			return 0;
		}
		s=s.back()+s.substr(0,n-1);
	}
	c("No")
}			
								

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<Integer> List = new ArrayList<>();
        boolean check = true;
        for(int i=0;i<N;i++) List.add(sc.nextInt());
        Collections.sort(List);
        for(int i=0;i<N-1;i++){
            if(List.get(i+1)-List.get(i)==0){
                check = false;
                break;
            }
        }
        if(check) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 87680
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int 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)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string N;
    cin >> N;
    REP(i, N.size()) {
        if(N[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

using namespace std;

//#define TEST

signed main(){
    int n;
    cin >> n;
    int* h = new int[n];
    for (int i = 0;i < n;++i)
        cin >> h[i];
    
#ifdef TEST
    cout << "------h------" << endl;
    for (int i = 0;i < n;++i)
        cout << h[i] << " " ;
    cout << endl;
#endif

    /* 
            dp[i] : i番目まで単調非減少にした時のi番目の
                    マスの高さの最小値
        というDPを行う.
     */
    int* dp = new int[n];
    dp[0] = h[0] - 1;
    for (int i = 1;i < n;++i){
        if (dp[i - 1] <= h[i] - 1){
            dp[i] = h[i] - 1;
        }
        else if (dp[i - 1] == h[i]){
            dp[i] = h[i];
        }
        else {
            cout << "No" << endl;
            goto End;
        }
    }

#ifdef TEST
    cout << "------dp-----" << endl;
    for (int i = 0;i < n;++i)
        cout << dp[i] << " ";
    cout << endl;
#endif

    cout << "Yes" << endl;

    End:;
    delete[] h,dp;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
2番目に大きい値の総和･･･
12345

1234
234
34
4

231
21
2
2個とりの場合一番大きい値以下を全部

54321
4321
432
43
4

41325
1122
323
33
4
そうでもないぽい
ただDPぽい

8 2 7 3 4 5 6 1

2
27
337
3447
44557
555667
1555667

      2
     27
    337
   3447
  44557
 555667
1555667

678
8=1
7=3
{0,0,1,3,9,9}
7の場合(8-2)*(1-0)=6通り
6=7
{0,0,1,3,7,9,9}
6の場合(9?-7)*(3-1)=4通り
5=6
{0,0,1,3,6,7,9,9}
5の場合(9-1)-(3+1))*(3-1)=8通り
4=5
{1,3,5,6,7}
4の場合((7-1)-(3+1))*(3-1)=4
(2個上-1)-(1個下+1))*(1個下-2個下)
{0,0,1,3,4,5,6,7,9,10}
3の場合

0と9は2個いれ

N-1と1だけ特別？
そうでもないか

015342
3から見て、両端が自分より大きい場合は和になる？
015324 =7通り？
3*2+1

126453
{0,3,4,5,7}4の場合　5通り
発展性がどれだけあるか。左と右で、和か。
・64とったとき、1*3 3通り
（1個上)-(自分))*(1個下-(2個下))=3
・45とったとき、1*2 2
(2個上)-(1個上))*(自分-(1個下))=2
小さいのがきたらそのまま。大きいのがきたら更新
全部やってたらN^2でだめだから、
それぞれが何回出現するか個別判断
右みて自分より大きい数が出たら、左に自分より小さい数が何個あるか
左も同じ
結局N^2回足してる
効率的に位置をわりだせれば掛け算であるいは
あれ、積っぽい、いけるか
4*2=8//5
カウントでいけるのかな。lower使えん
もっと早い方法、絶対ある

最低値をとってくるやつ、set
https://atcoder.jp/contests/agc005/submissions/12274141
近いかな、

(2個上)-(1個上))*(自分-(1個下) 
(1個上)-(自分))*(1個下-(2個下)
8 2 7 3 4 5 6 1
{0,0,1,3,9,9}
7の場合(8-2)*(1-0)=6通り
6=7
{0,0,1,3,7,9,9}
6の場合(9?-7)*(3-1)=4通り
5=6
{0,0,1,3,6,7,9,9}
5の場合(9-1)-(3+1))*(3-1)=8通り
4=5
{1,3,5,6,7}
4の場合((7-1)-(3+1))*(3-1)=4
(2個上-1)-(1個下+1))*(1個下-2個下)
{0,0,1,3,4,5,6,7,9,10}
3の場合
*/
int main(){
  ll N,ans=0; cin>>N;
  multiset<ll> S={0,0,N+1,N+1};
  vector<ll> P(N+1,0);
  for(ll i=1; i<=N; i++){
    ll a; cin>>a;
    P[a]=i;
  }
  //最大はどうせ0通り。setにいれとく
  S.insert(P[N]);
  for(ll i=N-1; i>=1; i--){
    S.insert(P[i]);
//for(auto IT=S.begin(); IT!=S.end(); IT++) cout<<*IT;
//cout<<endl;
// (2個上)-(1個上))*(自分-(1個下) 
    ll R1,R2,L1,L2;
    auto IT1=S.find(P[i]);
    auto IT2=IT1;
    //R1
    IT1++,IT1++;
    R1=*IT1;
    IT1--;
    R1-=*IT1;
    IT1--;
    R2=*IT1;
    IT1--;
    R2-=*IT1;
    R1*=R2;
//（1個上)-(自分))*(1個下-(2個下)
    //L1
    IT2++;
    L1=*IT2;
    IT2--;
    L1-=*IT2;
    IT2--;
    L2=*IT2;
    IT2--;
    L2-=*IT2;
    L1*=L2;
    ans+=(R1+L1)*i;
//cout<<"R1:"<<R1<<" L1:"<<L1<<"ans:"<<ans<<endl;    
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5760
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

int N, M;

int main() {
    cin >> N >> M;
    int ans = 0;
    if (N > 1) {
        ans += N *(N - 1) / 2;
    }
    if (M > 1) {
        ans += M * (M - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

def main():
	n, m, q, *L = map(int, open(0).read().split())
	lr = L[:2 * m]
	pq = L[2 * m:]
	arr = np.zeros((n + 1, n + 1), int)
	for l, r in zip(*[iter(lr)] * 2):
		arr[l, r] += 1
	arr = np.cumsum(arr, 0)
	arr = np.cumsum(arr, 1)
	for p, q in zip(*[iter(pq)] * 2):
		print(arr[q, q] - arr[p - 1, q] - arr[p, p - 1] + arr[p - 1, p - 1])


if __name__ == "__main__":
	main()

Measured memory_bytes: 66988
#include <bits/stdc++.h>
#define int long long
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);
#define loop(n) for (int i = 0; i < n; i++)
#define double long double
#define mod 998244353
#define pi 3.1415926535897
#define F first
#define S second
#define pb push_back

using namespace std;

signed main()
{
    fast;
    int test = 1;
    // cin >> test;
    for (int index = 0; index < test; index++)
    {
        int a;
        double b;
        cin >> a >> b;
        double ans = a * b;
        cout << (int)ans << endl;
    }
}


Measured memory_bytes: 3744
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/30/2019 11:03:37 PM
*************************************************************************/
//#pragma GCC optimize(3)
//#pragma GCC diagnostic error "-std=c++11"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#define lowbit(x) x&(-x)
#define ls u<<1
#define rs u<<1|1
using namespace std;
template<typename T> inline T MIN(const T &a,const T &b) {return a<b?a:b;}
template<typename T> inline T MAX(const T &a,const T &b) {return a>b?a:b;}
template<typename T,typename ...Args> inline T MIN(const T &a,const T &b,Args ...args) {return MIN(MIN(a,b),args...);}
template<typename T,typename ...Args> inline T MAX(const T &a,const T &b,Args ...args) {return MAX(MAX(a,b),args...);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef WindCry1
	freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
#endif
	int n;string s;cin>>n>>s;
	int res=0;
	for(int i=0;i<n-2;i++){
		if(s[i]=='A' and s[i+1]=='B' and s[i+2]=='C') ++res;
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n = II()
    r = 1
    for i in range(1,n+1):
        r = r*i % mod
    return r

print(main())


Measured memory_bytes: 7696
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n):
  b[i] = a[i] + b[i-1]
ans = b[-1]
for j in range(n):
  ans = min(ans,abs(b[-1]-b[j]*2))
print(ans)

Measured memory_bytes: 26224
#include <iostream>
#include <cstring>
#include <cstdio>
#include<cstdint>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<vector>
#include<string>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
const int MOD = 1e9+7;
#define NIL -1
const int INF = 1 << 29;
ll n;
int min_digit(const ll a,const ll b){
    ll cnt=(a>b?a:b);
    int count=0;
    while(cnt){
        cnt/=10;
        count++;
    }
    return count;
}

int main(){
cin>>n;
int ans=INF,temp;
for(ll i=1;i*i<=n;i++){//N=A*B=B*Aが成り立つのでA<=Bとなる場合のみで良い
    if(n%i!=0)continue;
    temp=min_digit(i,n/i);
    if(temp<ans)ans=temp;
    
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007
#define PI 3.14159265359

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  long double N, M, X; cin >> N >> M >> X;
  if (X ==  (1.0 / 2.0) * pow(N, 2) * M) {
    cout << 45.0 << endl;
  } else if ( X > (1.0 / 2.0) * pow(N, 2) * M) {
    long double ans = atan((pow(N, 2) * M - X) / ((pow(N, 3) * (1.0 / 2.0)))) * 180 / PI;
    cout << setprecision(12) << ans << endl;
  } else {
    long double ans = atan( (N * pow(M, 2))/ (X*2)) * 180 / PI;
    cout << setprecision(12) << ans << endl;
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <array>

using namespace std;

struct Card {
	char suit;
	int value;
  bool operator==(const Card& rhs) const {
    return this->suit == rhs.suit && this->value == rhs.value;
  }
};

static void printCard(Card cards[], int N) {
  for (int i = 0; i < N; i++) {
    cout << (i != 0 ? " " : "") << cards[i].suit << cards[i].value;
  }
  cout << endl; 
}

static void inputCard(Card cards[], int N) {
  for (int i = 0; i < N; i++) {
    cin >> cards[i].suit >> cards[i].value;
   }
}

static int bubbleSort(Card cards[], int N) {
  bool flag = true;
  int count = 0;
  for (int i =0; flag; i++) {
    flag = false;
    for (int j = N - 1; j > i; j--) {
      if (cards[j].value < cards[j - 1].value) {
        swap(cards[j], cards[j - 1]);
        flag = true;
        count++;
      }
    }
  }
  return count;
}

static int selectionSort(Card cards[], int N) {
  int minj, count = 0;
  for (int i = 0; i < N; i++) {
    minj = i;
    for (int j = i; j < N; j++) {
      if (cards[j].value < cards[minj].value) {
      	minj = j;
      }
    }
    if (cards[i].value != cards[minj].value) {
      swap(cards[i], cards[minj]);
      count++;
    }
  }
  return count;
}

static bool isStable(Card in[], Card out[], int N) {
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      for (int a = 0; a < N; a++) {
        for (int b = a + 1; b < N; b++) {
          if (in[i].value == in[j].value && in[i] == out[b] && in[j] == out[a]) {
            return false;
          }
        }
      }
    }
  }
  return true;
}

static bool isSame(Card in[], Card out[], int N) {
  for (int i = 0; i < N; i++) {
    if (!(in[i] == out[i])) {
      return false;
    }
  }
  return true;
}

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

  array<Card, 36> A, B;
  inputCard(A.data(), N);

  B = A;
  bubbleSort(A.data(), N);
  selectionSort(B.data(), N);
  
  // バブルソートは常に stable.
  printCard(A.data(), N);
  cout << "Stable" << endl;

  // バブルソートと同じ結果か？
  printCard(B.data(), N);
  bool stable = isSame(A.data(), B.data(), N);
  cout << (stable ? "Stable" : "Not stable") << endl;
  
  return 0;
}



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

int h, w, a, b;

int main() {
	cin >> h >> w >> a >> b;
	
	int tate = a * (h / a);
	int yoko = b * (w / b);
	
	cout << h * w - tate * yoko << endl;
	return 0;
}


Measured memory_bytes: 3104
import java.util.*;
class Main{
  static int n=0;
  static int fibonacci[];
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    fibonacci = new int[n];
    if(n >= 1){
      fibonacci[0] = 1;
    }
    if(n >=2){
      fibonacci[1] = 2;
    }
    for(int i = 2; i<n; i++){
      fibonacci[i] = fibonacci[i-1]+fibonacci[i-2];
    }
    // System.out.println(Fibonacci(n-1));
    System.out.println(fibonacci[n-1]);

  }

  static int Fibonacci(int n){
    if(n == 0) return fibonacci[0];
    if(n == 1) return fibonacci[1];
    fibonacci[n] = Fibonacci(n-1) + Fibonacci(n-2);
    return fibonacci[n];
  }
}


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

int main(){
    char c;
    cin >> c;
    cout << ++c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int cnt_digits(ll N) {
  int digits = 0;

  while (N > 0) {
    N /= 10;
    digits++;
  }
  return digits;
}

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

  int ans = cnt_digits(N);

  for (ll A = 1LL; A * A <= N; ++A) {
    if (N % A != 0) continue;
    const ll B = N / A;
    const int cur = max(cnt_digits(A), cnt_digits(B));

    if (ans > cur) {
      ans = cur;
    }
  }

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


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
#define sent 2000000000
#define MAX 500000



using namespace std;

struct Card {
    char str;
    int num;
};

Card L[MAX/2+2],R[MAX/2+2];

int partition(Card A[],int p,int r){
    int x=A[r].num;
    int i=p-1;
    for (int j=p;j<r;j++){
        if(A[j].num<=x){
            i++;
            swap(A[i],A[j]);
        }
    } 
    swap(A[i+1],A[r]);
    return i+1;
}

void quickSort(Card A[],int p,int r){
    if (p<r){
        int q=partition(A,p,r);
        quickSort(A,p,q-1);
        quickSort(A,q+1,r);
    }
}

void merge(Card A[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;

    rep(i,n1) L[i]=A[left+i];
    rep(i,n2) R[i]=A[mid+i];

    L[n1].num=R[n2].num=sent;

    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(L[i].num<=R[j].num){
            A[k]=L[i++];
        }else{
            A[k]=R[j++];
        }
    }

}

void mergeSort(Card A[],int left,int right){
    if (left+1<right){
        int mid=(left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }

}

int main(){
    int n;
    cin>>n;
    Card A[n],B[n];
    
    rep(i,n){
        cin>>A[i].str;
        cin>>A[i].num;
        B[i]=A[i];
    }
    
    mergeSort(B,0,n);
    quickSort(A,0,n-1);
    
    int stable=1;

    rep(i,n) if(A[i].str !=B[i].str) stable=0;

    if (stable) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    rep(i,n){
        cout<<A[i].str<<" "<<A[i].num<<endl;
    }
    return 0;
}


Measured memory_bytes: 5400