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

#define INFTY 1000000001
#define MAX 100000

typedef struct {
  char pic;
  int val;
}Card;

void mergeSort(Card*,int,int);
void merge(Card*,int,int,int);

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

  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;

  return i+1;
}

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


int main(){
  int n,i,flag=0,j;
  Card Q[MAX],M[MAX];
  char c[3];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",c,&Q[i].val);
    M[i].pic=Q[i].pic=c[0];
    M[i].val=Q[i].val;
  }

  mergeSort(M,0,n);
  quicksort(Q,0,n-1);

  for(i=0;i<n;i++){
    if(Q[i].pic!=M[i].pic){
      flag=1;
      break;
    }
  }


  if(flag==0)
    printf("Stable\n");
  else
    printf("Not stable\n");

    for(i=0;i<n;i++){
      printf("%c %d\n",Q[i].pic,Q[i].val);
    }
  return 0;
}

void merge(Card*A, int left,int mid,int right){
  int n1,n2,k,i,j;

  n1 = mid - left;
  n2 = right - mid;

  Card L[n1+2],R[n2+2];

  for (i=0;i<n1;i++)
    L[i] = A[left + i];

  for (i=0;i<n2;i++)
    R[i] = A[mid + i];

  L[n1].val = INFTY;
  R[n2].val = INFTY;
  i = 0;
  j = 0;
  for (k=left;k<right;k++)
    if (L[i].val <= R[j].val){
      A[k] = L[i];
      i = i + 1;
    }
    else {
      A[k] = R[j];
      j = j + 1;
    }
}

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



Measured memory_bytes: 4060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        HashMap<String, Integer> map = new HashMap<>();
        map.put("SUN",7);
        map.put("MON",6);
        map.put("TUE",5);
        map.put("WED",4);
        map.put("THU",3);
        map.put("FRI",2);
        map.put("SAT",1);
        System.out.println(map.get(s));
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N, Ans = 0;cin >> N;
map<ll, ll> P;
map<ll, ll> Q;

rep(i, 1, N + 1){

    ll a;cin >> a;

    P[i + a]++;

    Q[i - a]++;

    }

for(auto p : P ){

    Ans += p.second*Q[p.first];

}

cout << Ans;

}


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

using namespace std;

int n,a,b;

int main()
{
	cin>>n>>a>>b;
	
	int ans=0;
	
	for (register int i=1;i<=n;++i)
	{
		int tmp=i,sum=0;
		
		while (tmp>0)
		{
			sum+=tmp%10;
			tmp/=10;
		}
		
		if (sum>=a && sum<=b) ans+=i;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <math.h>
    #include <algorithm>
    using namespace std;

    int gcd(int a,int b){
        int t;
        while(b){
            t=b;
            b=a%b;
            a=t;
        }
        return a;
    }
    int main() {
        int n;
        cin>>n;
        int s;
        cin>>s;
        int v;
        for(int i=2;i<=n;i++){
            cin>>v;
            s=gcd(v, s);
        }
        int t=0;
        while(s)
        {
            t++;
            s=s>>1;
        }
        cout<<t-1<<endl;
        // insert code here...
        //std::cout << "Hello, World!\n";
        return 0;
    }


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<int> point(n,0);

  for(int i = 0; i < m; i++){
      cin >> a >> b;
      point[a-1]++;
      point[b-1]++;
  }

  for(int i=0; i < n; i++){
      cout << point[i] << endl;
  }

}


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

int main(){
    int N,D;
    cin >> N >> D;
    int d1,d10;
    int ans = 0;
    
    for ( int i = 22; i <= D; i++ ){
        d1  = i % 10;
        d10 = ( i - d1 ) / 10;
        for ( int j = 4; j <= N; j++ ){
            if ( j == d1 * d10 && d1 >= 2 && d10 >= 2){
                ans++;
            }
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[2010][2010];

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> s(n);
  rep(i,n) cin >> s[i];
  vector<int> t(m);
  rep(i,m) cin >> t[i];
  dp[0][0]=1;
  rep(i,n+1)rep(j,m+1){
    if(i-1>=0&&j-1>=0&&s[i-1]==t[j-1]) dp[i][j]+=dp[i-1][j-1];
    dp[i][j]%=mod;
    if(i-1>=0)dp[i][j]+=dp[i-1][j];
    dp[i][j]%=mod;
    if(j-1>=0)dp[i][j]+=dp[i][j-1];
    dp[i][j]%=mod;
    if(i-1>=0&&j-1>=0)dp[i][j]-=dp[i-1][j-1];
    if(dp[i][j]<0) dp[i][j]+=mod;
  }
  cout << dp[n][m] << endl;
}


Measured memory_bytes: 31616
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	fmt.Println(n * n)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll a;
  cin >> a;
  
  cout << a + a*a + a*a*a << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;



int main(void){
	int dp[102][5][5],f[102];
	int n,k;
	int a,b,c;
	int x,y;
	for(a=0;a<102;a++){
		f[a]=0;
		for(b=0;b<5;b++){
			for(c=0;c<5;c++){
				dp[a][b][c]=0;
			}
		}
	}
	cin >> n >> k;
	for(a=0;a<k;a++){
		cin >> x >> y;
		f[x]=y;
	}
	if(f[1]!=0)dp[1][f[1]][1]=1;
	else dp[1][1][1]=dp[1][2][1]=dp[1][3][1]=1; 
	for(a=2;a<=n;a++){
		if(f[a]==0){
			dp[a][1][1]=(dp[a-1][2][1]+dp[a-1][2][2]+dp[a-1][3][1]+dp[a-1][3][2])%10000;
			dp[a][1][2]=dp[a-1][1][1]%10000;

			dp[a][2][1]=(dp[a-1][1][1]+dp[a-1][1][2]+dp[a-1][3][1]+dp[a-1][3][2])%10000;
			dp[a][2][2]=dp[a-1][2][1]%10000;

			dp[a][3][1]=(dp[a-1][1][1]+dp[a-1][1][2]+dp[a-1][2][1]+dp[a-1][2][2])%10000;
			dp[a][3][2]=dp[a-1][3][1]%10000;
		}else{
			dp[a][f[a]][2]=dp[a-1][f[a]][1]%10000;
			for(b=1;b<=3;b++){
				if(b!=f[a])dp[a][f[a]][1]+=(dp[a-1][b][1]+dp[a-1][b][2])%10000;

			}
		}
	}
	printf("%d\n",(dp[n][1][1]+dp[n][1][2]+dp[n][2][1]+dp[n][2][2]+dp[n][3][1]+dp[n][3][2])%10000);
	return 0;
}

Measured memory_bytes: 0
a, b, x = map(int, input().split())

import math

half = a*b*a/2

if x<=half:
  theta = math.atan(a*b*b/2/x)
  theta = math.degrees(theta)
else:
  theta = math.atan(2*b/a - 2*x/(a**3))
  theta = math.degrees(theta)

print(theta)

Measured memory_bytes: 38512
#include <stdio.h>
#include <stdlib.h>
int *tree[100000];
int cnt[100000], cnts[100000];
int colors[100000];
long long int black = 0, white = 0;
int dfs(int v, int color){
    colors[v] = color;
    if(color == 1){
        white++;
    }else if(color == -1){
        black++;
    }
    for(int i = 0; i < cnt[v]; i++){
        int v_i = tree[v][i];
        if(colors[v_i] == color){
            return 0;
        }
        if(colors[v_i] == 0 && dfs(v_i, -color) == 0){
            return 0;
        }
    }
    return 1;
}
int main(void){
    long long int n, m;
    scanf("%lld%lld", &n, &m);
    int a[100000], b[100000];
    int i, j;
    for(i = 0; i < n; i++){
        cnt[i] = 0;
        cnts[i] = 0;
        colors[i] = 0;//0:tbd -1:b 1:w
    }
    for(i = 0; i < m; i++){
        scanf("%d%d", &a[i], &b[i]);
        a[i]--;
        b[i]--;
        cnt[a[i]]++;
        cnt[b[i]]++;
    }
    for(i = 0; i < n; i++){
        tree[i] = malloc(sizeof(int) * (cnt[i] + 1));
    }
    for(i = 0; i < m; i++){
        tree[a[i]][cnts[a[i]]++] = b[i];
        tree[b[i]][cnts[b[i]]++] = a[i];
    }

    if(dfs(0, 1) == 0){
        printf("%lld\n", n*(n-1)/2 - m);
        
    }else{
        printf("%lld\n", black*white-m);
    }
    return 0;
}

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

#define int long long

const int MOD = 1e9+7;

int pow(int x, int n) {
  int ret = 1;
  while ( n > 0 ) {
    if ( n & 1 ) (ret *= x) %= MOD;
    (x *= x) %= MOD;
    n /= 2;    
  }
  return ret;
}

int inv(int x) {
  return pow(x, MOD-2);  
}

int dp[2010][2010];

signed main() {
  int N, D, X;
  while ( cin >> N >> D >> X, N ) {    
    fill_n(*dp, 2010*2010, 0);
    dp[0][0] = 1;
    for ( int i = 0; i < N; i++ ) {
      int sum = 0;      
      for ( int j = 0; j <= N; j++ ) {	
	if ( j >= X ) sum -= dp[i][j-X];	
	dp[i+1][j] += sum;
	dp[i+1][j] %= MOD;	
	sum += dp[i][j];
	sum %= MOD;
      }
    }
    /* for ( int i = 0; i <= N; i++ ) {
      for ( int j = 0; j <= N; j++ ) {
	cout << dp[i][j] << " ";
      }
      cout << endl;
      } */
    int ans = 0;
    for ( int i = 1; i <= min(D, N); i++ ) {
      int a = 1, b = 1;
      for ( int j = 0; j < i; j++ ) {
	a *= ((D-j)%MOD);	
	a %= MOD;
	b *= (i-j);	
	b %= MOD;	
      }
      int add = a*inv(b)%MOD;      
      add = add*dp[i][N]%MOD;
      ans += add;
      ans %= MOD;
    }

    if ( ans < 0 ) ans += MOD;    
    cout << ans << endl;
  }  
  return 0;
}



Measured memory_bytes: 34556
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n;
    string s;
    ll sum_b[200010],sum_w[200010];
    ll count_b,count_w;
    std::cin >> n;
    std::cin >> s;
    count_b = count_w =0 ;
    Fill(sum_w,0);
    Fill(sum_b,0);
    for (int i = 0; i < n; i++) {
        if(s[i] == '.'){
            count_w++;
            sum_w[i+1]++;
        }else{
            count_b++;
            sum_b[i+1]++;
        }
        sum_w[i+1] += sum_w[i];
        sum_b[i+1] += sum_b[i];
    }
    
    ll result = n;
    
    for (int i = 0; i <= n; i++) {
        ll cost = sum_b[i] + count_w - sum_w[i];
        result = min(cost,result);
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 3716
sx, sy, tx, ty = map(int, input().split())
ans = ""
ans += "U" * (ty-sy)
ans += "R" * (tx-sx)
ans += "D" * (ty-sy)
ans += "L" * (tx-sx+1)
ans += "U" * (ty-sy+1)
ans += "R" * (tx-sx+1)
ans += "DR"
ans += "D" * (ty-sy+1)
ans += "L" * (tx-sx+1)
ans += "U"
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
map<string, int> mp;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool ta;
    while(a > 0 && c > 0){
        c -= b;
        if(c <= 0){
            ta = true;
            break;
        }
        a -= d;
        if(a <= 0){
            ta = false;
            break;
        }
    }
    cout << (ta? "Yes":"No") << endl;
    return 0;
}  

Measured memory_bytes: 3592
l = input().strip()
MOD = pow(10, 9) + 7
ans = 0
tmp = 0
for ll in range(len(l)):
  if l[ll] == '1':
    ans += pow(2, tmp, MOD) * pow(3, len(l)-ll-1, MOD) % MOD
    tmp += 1

print((ans+pow(2, tmp, MOD))%MOD)


Measured memory_bytes: 3188
use std::io::*;
use std::str::FromStr;
use std::cmp;
   
fn read<T: FromStr>() -> 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().expect("failed to parse token")
}

fn main() {
	let n: usize = read();
	let mut b: Vec<u32> = Vec::new();
	for i in 0..n-1{
		b.push(read());
	}

	let mut c = vec![b[0]];

	for i in 0..n-2 {
		c.push(cmp::min(b[i], b[i+1]));
	}

	c.push(b[n-2]);

	println!("{}", c.iter().fold(0, |x, y| x+y));
	
}


Measured memory_bytes: 4352
#include <stdio.h>

void show();
void bubble();
void select();

int count = 0;

int main(void){
	int size, i;
	scanf("%d",&size);
	int a[size];

	for(i = 0; i < size; i++)
		scanf("%d",&a[i]);

	select(a, size);
	show(a, size);
	printf("%d\n",count);
	return 0;
}

void select(int x[], int len){
	int i, j, minj, temp;
	for(i = 0; i < len; i++){
		minj = i;
		for(j = i; j < len; j++){
			if(x[j] < x[minj]){
				minj = j;
			}
		}
		if(i != minj){
			temp = x[minj];
			x[minj] = x[i];
			x[i] = temp;
			count++;
		}
	}
}

void show(int x[], int len){
	int i;
	printf("%d",x[0]);
	for(i = 1; i < len; i++){
		printf(" %d",x[i]);
	}
	printf("\n");
}

Measured memory_bytes: 1828
while 1:
  n=input()
  if n==0: break
  D={}
  A=[]
  for _ in [0]*n:
    a,b,c=map(int, raw_input().split())
    if D.has_key(a): D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  for e in B: print e

Measured memory_bytes: 4340
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int del0(int a[], int b[], int n)
{
  int c = 0;
  int i;
  for ( i=0; i<n; i++ ) {
    if ( a[i] > 0 ) {
      b[c++] = a[i];
    }
  }
  return c;
}

int main(void)
{
  int c = 0;
  int k, n;
  int a[200001] = {0};
  int b[200001] = {0};
  int d;
  int t;
  int i;
  int s = 0;
  scanf("%d %d", &n, &k);
  for ( i=0; i<n; i++ ) {
    scanf("%d", &t);
    a[t]++;
  }
  for ( i=0; i<200001; i++ ) {
    if ( a[i] > 0 ) { s++; }
  }
  sort(a, a+200000);
  d = del0(a, b, 200001);
  for ( i=0; i<s-k; i++ ) {
    c += b[i];
  }
  printf("%d\n", c);
  return 0;
}



Measured memory_bytes: 2424
#include <stdio.h>

int main(void){
	long long n;
	scanf("%lld",&n);
	long long a[n],b[n],sum=0,count1=0,count2=0;
	for (int i=0; i<n; i++){
	    scanf("%lld",&a[i]);
	    sum-=a[i];
	}
    for (int i=0; i<n; i++){
        scanf("%lld",&b[i]);
        sum+=b[i];
    }
    for (int i=0; i<n; i++){
        if (a[i]<b[i]){
            count1+=(b[i]-a[i])/2+(b[i]-a[i])%2;
        } else if (a[i]>b[i]){
            count2+=(a[i]-b[i]);
        }
    }
    if (sum>=count1 && sum>=count2){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
	return 0 ;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int x,y,d,i;

  scanf("%d %d",&x,&y);

  if(x < y);

  i = x;
  x = y;
  y = i;

  while(y>0){
    d = x % y;
    x = y;
    y = d;
  }
  printf("%d\n",x);
  return 0;
}

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

std::vector< int > last;

int binary_search(int key) {
    int left = -1;
    int right = (int)last.size();
    
    while(right - left > 1){
        int mid = left + (right - left) / 2;
        
        if(last[mid] < key){
            right = mid;
        }else{
            left = mid;
        }
    }
    
    return right;
}

int main(){
    int N;
    std::cin >> N;
    std::vector< int > A(N);
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }
    
    last.resize(1);
    last[0] = A[0];
    
    for(int i=1; i<N; i++){
        int index = binary_search(A[i]);
        //std::cout << "index" << index << std::endl;
        if(index == last.size()){
            last.push_back(A[i]);
        }else{
            last[index] = A[i];
        }
        //std::cout << "vector ";
        //for(int a=0; a<last.size(); a++){
        //    std::cout << last[a] << " ";
        //}
        //std::cout << std::endl;
    }
    
    std::cout << last.size() << std::endl;
    
    return 0;
}



Measured memory_bytes: 1276
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

// tree<key_type, value_type(set if null), comparator, ...>
using ordered_set = tree<pair<int, int>, null_type, greater<>, rb_tree_tag, tree_order_statistics_node_update>;

int a[300005], n;

struct maxsum
{
    ordered_set st;

    int n;
    long long sum = 0;

    maxsum() {}

    void add(int val, int idx)
    {
        st.insert({val, idx});
        int order = st.order_of_key({val, idx});

        if (order < n)
        {
            sum += val;
            if (st.size() > n) sum -= st.find_by_order(n)->first;
        }
    }

    void sub(int val, int idx)
    {
        int order = st.order_of_key({val, idx});
        if (order < n)
        {
            sum += st.find_by_order(n)->first;
            sum -= val;
        }

        st.erase({val, idx});
    }
};

maxsum prefix, postfix;

int main()
{
    int n;
    scanf("%d",&n);
    for (int i = 1; i <= 3 * n; i++) scanf("%d", &a[i]);

    prefix.n = postfix.n = n;

    for (int i = 1; i <= n; i++) prefix.add(a[i], i);
    for (int i = n + 1; i <= 3 * n; i++) postfix.add(-a[i], i);

    long long ans = prefix.sum + postfix.sum;

    for (int i = n + 1; i <= 2 * n; i++)
    {
        prefix.add(a[i], i);
        postfix.sub(-a[i], i);
        ans = max(ans, prefix.sum + postfix.sum);
    }

    printf("%lld\n", ans);
}


Measured memory_bytes: 20224
#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<string>
#include<cmath>
#include<string.h>
#include<sstream>
#include<limits.h>
#include<regex>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;

//最大公約数
int gcd(int a,int b){
    return b ? gcd(b,a%b):a;
}

//最小公倍数
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}

//素数判定
bool isPrime(int x){
    if(x<2)return 0;
    else if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i+=2){
        if(x%i==0)return 0;
    }
    return 1;
}

//桁ごとの足し算
int digsum(int n){
    int res=0;
    while(n>0){
        res+=n%10;
        n/=10;
    }
    return res;
}

//約数列挙
vector<int> enum_div(int n){
    vector<int> ret;
    for(int i=1;i*i<=n;++i){
        if(n%i==0){
            ret.push_back(i);
            if(i*i !=n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

//累乗の計算とあまり,0で累乗そのまま出力
long long modpow(long long a,long long n,long long mod){
    if(mod==0)mod=__LONG_LONG_MAX__;
    long long res=1;
    while(n>0){
        if(n & 1)res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

int N;

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

Measured memory_bytes: 6400
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 10010
#define MAX_INT 9223372036854775807

int main() {
  long long int N, M, K, A[200001] = {0}, B[200001] = {0};
  scanf("%lld%lld%lld", &N, &M, &K);

  for (long long i = 1; i <= N; i += 1) {
    scanf("%lld", A + i);
    A[i] += A[i - 1];
  }

  for (long long i = 1; i <= M; i += 1) {
    scanf("%lld", B + i);
    B[i] += B[i - 1];
  }

  long long j = M, ans = 0;
  // Aの机の上にある本を0冊始めてN冊まで1冊ずつ増やしていく
  for (long long i = 0; i <= N; i += 1) {
    // Bの机の上にある本をM冊から始めて0冊まで1冊ずつ減らしていく
    // 0冊になった時か、Ai冊Bj冊の合計時間が制限時間（K）以下になったらループ終了
    while(j > 0 && A[i] + B[j] > K) {
      j -= 1;
    }

    // Ai冊Bj冊の合計時間が制限時間（K）以下の時
    if (A[i] + B[j] <= K) {
      // max(i + j, ans)のsyntax shugar
      ans = i + j < ans ? ans : i + j;
    }
  }

  printf("%lld\n", ans);
}


Measured memory_bytes: 4828
#include<bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0;char c;
	for(c=getchar();c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())n=n*10+c-48;
	return n;
}
const int maxn=2e6+5;
int i,j,n,num,ans,l,r,m,mx,x,y;
int k[maxn],ne[maxn],g[maxn],cnt;
int dfn[maxn],low[maxn],q[maxn],cn,ct,cx,be[maxn];
bool bz[maxn];
struct ar{
	int x,id;
}a[maxn];
bool cmp(ar a,ar b){
	return a.x<b.x;
}
int re(int x){
	return (x<=n)?x+n:x-n;
}
void add(int x,int y){
	ne[++cnt]=k[x],k[x]=cnt,g[cnt]=y;
}
void dfs(int x){
	int i;
	bz[x]=1;
	dfn[x]=low[x]=++cn,q[++ct]=x;
	for(i=k[x];i;i=ne[i]){
		int y=g[i];
		if (!dfn[y]) dfs(y),low[x]=min(low[x],low[y]);else
		if (bz[y]) low[x]=min(low[x],dfn[y]);
	}
	if(dfn[x]==low[x]){
		cx++;
		for(;q[ct]!=x;ct--) be[q[ct]]=cx,bz[q[ct]]=0;
		be[x]=cx,bz[x]=0,ct--;
	}
}
bool check(){
	int i;
	cn=ct=0;
	memset(bz,0,sizeof(bz));
	memset(dfn,0,sizeof(dfn));
	fo(i,1,n<<1) if (!dfn[i]) dfs(i);
	fo(i,1,n) if(be[i]==be[i+n]) return 0;
	return 1;
}
void ins(int k,int l,int r,int a,int b){
	if (l==a&&r==b){
		add(2*n+k,re(x));
		return;
	}
	int m=(l+r)>>1,lk=k<<1,rk=lk+1;
	if (b<=m) ins(lk,l,m,a,b);else
	if (a>m) ins(rk,m+1,r,a,b);else
	ins(lk,l,m,a,m),ins(rk,m+1,r,m+1,b);
}
void ads(int k,int l,int r,int i){
	add(x,2*n+k);
	if (l==r) return;
	int m=(l+r)>>1,lk=k<<1,rk=lk+1;
	if (i<=m) ads(lk,l,m,i);else ads(rk,m+1,r,i);
}
int main(){
	n=read();
	fo(i,1,n) {
		a[++num].x=read(),a[num].id=i;
		a[++num].x=read(),a[num].id=i+n;
	}
	sort(a+1,a+1+num,cmp);
	mx=a[num].x;
	l=0,r=mx/(n-1);
	for(;l<r;){
		m=(l+r+1)>>1;
		memset(k,0,sizeof(k));
		cnt=0;
		fo(i,1,num){
			x=a[i].id;
			ads(1,1,num,i);
			int ls=i,rs=num,mid;
			for(;ls<rs;){
				mid=(ls+rs+1)>>1;
				if (a[mid].x-a[i].x<m) ls=mid;else rs=mid-1;
			}
			if (ls>i)ins(1,1,num,i+1,ls);
			ls=1,rs=i;
			for(;ls<rs;){
				mid=(ls+rs)>>1;
				if (a[i].x-a[mid].x<m) rs=mid;else ls=mid+1;
			}
			if (ls<i)ins(1,1,num,ls,i-1);
		}
		if (check()) l=m;else r=m-1;
	}
	printf("%d\n",l);
}

Measured memory_bytes: 37632
/*
[abc165] C - Many Requirements
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 10;
const int MAX_M = 10;
const int MAX_Q = 50;

int N, M, Q;
int a[MAX_Q], b[MAX_Q], c[MAX_Q], d[MAX_Q];
int dp[MAX_N + 1][MAX_M + 1];

int calc(vector<int> &nums) {
    int ret = 0;
    for (int i = 0; i < Q; i++) {
        if (nums[b[i]] - nums[a[i]] == c[i]) {
            ret += d[i];
        }
    }

    return ret;
}

int dfs(vector<int> &nums) {
    if ((int)nums.size() == N) {
        return calc(nums);
    }

    int ans = 0;
    int l = nums.empty() ? 1 : nums.back();
    for (int i = l; i <= M; i++) {
        nums.push_back(i);
        ans = max(ans, dfs(nums));
        nums.pop_back();
    }

    return ans;
}

ll solve() {
    vector<int> nums;
    return dfs(nums);
}

int main() {
    cin >> N >> M >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3604
import bisect
A, B, Q = map(int, input().split())
s = [-10**10 - 1, -10**10] + [int(input()) for _ in range(A)] + [2*10**10]
t = [-10**10 - 1, -10**10] + [int(input()) for _ in range(B)] + [2*10**10]
x = [int(input()) for _ in range(Q)]


def func(c, d, z):
    i = bisect.bisect_left(c, z)
    j1 = bisect.bisect_left(d, c[i - 1])
    j2 = bisect.bisect_left(d, c[i])
    return min(z - d[j1 - 1], z - c[i - 1] * 2 + d[j1], d[j2] - z, c[i] * 2 - z - d[j2 - 1])


for z in x:
    print(min(func(s, t, z), func(t, s, z)))

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

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int gcd(int x, int y) {
	int r;
	if(x < y) swap(x, y);

	while(y > 0){
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

int main(){
	int n, x;
	cin >> n >> x;

	int ans = -1;
	rep(i,n){
		int a;
		cin >> a;
		if(ans == -1) ans = abs(a - x);
		else ans = gcd(ans, abs(a - x));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ll beki3[35];

int maxBlack(ll g, ll h, ll i, ll j){
	int res=29;
	while(res>=0){
		ll hr=h%beki3[res+1], jr=j%beki3[res+1];
		if(min(hr, jr)<=beki3[res] || beki3[res]*2<max(hr, jr) || abs(j-h)>=beki3[res]){
			--res;
			continue;
		}
		if((g+beki3[res]-1)/beki3[res+1]==(i+beki3[res]-1)/beki3[res+1]){
			--res;
			continue;
		}
		break;
	}
	return res;
}

ll solve(ll g, ll h, ll i, ll j){
	int x=maxBlack(g, h, i, j), y=maxBlack(h, g, j, i);
	if(x>=0){
		ll k=(h/beki3[x+1])*beki3[x+1]+beki3[x];
		return abs(i-g)+min((h-k)+(j-k), (k+beki3[x]+1-h)+(k+beki3[x]+1-j));
	}
	if(y>=0){
		ll k=(g/beki3[y+1])*beki3[y+1]+beki3[y];
		return abs(j-h)+min((g-k)+(i-k), (k+beki3[y]+1-g)+(k+beki3[y]+1-i));
	}
	return abs(i-g)+abs(j-h);
}


int main() {
	int Q;
	cin >> Q;
	beki3[0]=1;
	for(int i=1; i<=30; ++i) beki3[i]=beki3[i-1]*3;
	for(int q=0; q<Q; ++q){
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << solve(a, b, c, d) << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

vector<ll> primes;
map<ll, ll> factors;
 
void erathosthenes(ll n) {
    vector<bool> primeFlags(n+10, true);
    primeFlags[0] = primeFlags[1] = false;
    vector<int> sqrtprimes;
    for (int i = 2; i*i <= n; i++) {
        bool mod0 = false;
        for (int j = 2; j*j <= i; j++) {
            if (i%j == 0) mod0 = true;
        }
        if (!mod0) sqrtprimes.push_back(i);
    }
    for (auto &&e: sqrtprimes) {
        for (int i = 2; i <= n; i++) {
            if (i%e == 0) primeFlags[i] = false;
        }
    }
    for (auto &&e: sqrtprimes) primeFlags[e] = true;
    for (int i = 1; i <= n; i++) if (primeFlags[i]) primes.push_back(i);
    return;
}
 
void factoring(ll n) {
    ll m = sqrt(n);
    erathosthenes(m);
    for (auto &&e: primes) {
        while(n%e == 0){
            factors[e]++;
            n /= e;
        }
    }
    factors[n]++;
    factors.erase(1);
}

int main(int argc, char const *argv[]) {
    ll a,b; cin>>a>>b;

    factoring(a);
    map<ll,ll> A(factors);
    factors.clear(); primes.clear();
    factoring(b);
    map<ll,ll> B(factors);

    map<ll,ll> ans;

    for (auto &&e: A) {
        ans[e.first]++;
    }
    for (auto &&e: B) {
        ans[e.first]++;
    }

    int cnt = 0;

    for (auto &&e: ans) {
        if (e.second==2) cnt++;
    }

    cout << cnt+1 << endl;

    return 0;
}


Measured memory_bytes: 1528
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>

using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//# define m 163577857
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)

const ll mod = 1000000007;
const int K = 2;
//typedef vector<vector<int> > matrix;
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}


ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}
set<int> v[100005];
signed main()
{
    gok
   //fact0();
   int n,m;
   cin>>n>>m;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   for(int i=0;i<m;i++)
   {
       int x,y;
       cin>>x>>y;
       v[x].insert(y);
       v[y].insert(x);
   }
   int an=0;
   for(int i=1;i<=n;i++)
   {
       bool ch=true;
       for(auto ii:v[i])
       {
           if(a[ii-1]>=a[i-1])
           {
               ch=false;
               break;
           }
       }
       if(ch)
        an++;
   }
   cout<<an;














    return 0;
    }


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

int main() {
  
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  
  if ( a >= k ){
    cout << k << endl;
  }else if ( a < k && a + b >= k ){
    cout << a << endl;
  }else if ( a + b < k && a + b + c > k ){
    cout << a - ( k - a - b ) << endl;
  }else{
    cout << a - c << endl;
  }

}

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

int main() {
  
  int K, A, B;
  cin >> K >> A >> B;
  
  if(A%K != 0) {
    if(B >= (A/K+1)*K) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  
  else cout << "OK" << endl;
  
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
signed main() {
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    vector<int> SS;
    map<int, int> M1, M2, M3, M4;
    rep(i, N) {
        int n = i + 1;
        M1[A[i] - n]++;
        M2[-A[i] - n]++;
        M3[A[i] + n]++;
        M4[n - A[i]]++;
        SS.push_back(A[i] - n);
        SS.push_back(-A[i] - n);
        SS.push_back(A[i] + n);
        SS.push_back(n - A[i]);
    }
    int ans = 0;
    sort(all(SS));
    SS.erase(unique(all(SS)), SS.end());
    for(auto x : SS) {
        ans += M1[x] * M2[x];
        ans += M3[x] * M4[x];
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 184564
import java.util.*;
import java.lang.*;
  
public class Main{
  public static void main(String[] args){
    Scanner stdIn=new Scanner(System.in);
    int i=0,x=stdIn.nextInt(),y=stdIn.nextInt();
    while(x!=0||y!=0){
	if (x>y){
	    System.out.println(y+" "+x);
	}else{
	    System.out.println(x+" "+y);
	}
	x=stdIn.nextInt();y=stdIn.nextInt();
    }
  }
}



Measured memory_bytes: 35792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



string O, E;
//-----------------------------------------------------------------------------------
int main() {
    cin >> O >> E;

    string ans = "";
    rep(i, 0, min(O.length(), E.length())) {
        ans += O[i];
        ans += E[i];
    }
    if (O.length() != E.length()) ans += O.back();
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
//------------------------------------------------------------------------

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  string s,t; cin >> s >> t;
  rep(i,n){
    cout << s[i] << t[i];
  }

  cout << endl;
  return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
 		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47468
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

signed main(){
	string s;
	int a,b,c,n;
	cin >> s;

	if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
		cout<<"Bad"<<endl;

	}
	else {
		cout<<"Good"<<endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int ci(char c) {
    return c - '0';
}

bool isMM(int i) {
    return 1 <= i && i <= 12;
}

int main() {
    string S;
    cin >> S;
    int a = ci(S[0]) * 10 + ci(S[1]);
    int b = ci(S[2]) * 10 + ci(S[3]);
    if (isMM(a) && isMM(b)) {
        cout << "AMBIGUOUS" << endl;
    }
    else if (!isMM(a) && isMM(b)) {
        cout << "YYMM" << endl;
    } else if (isMM(a) && !isMM(b)) {
        cout << "MMYY" << endl;
    } else {
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a, b, k, f;
    cin >> a >> b >> k;
    if(b-a<=k)
    {
        for(int i=a; i<=b; i++)
            cout << i << '\n';
    }
    else
    {
    for(int i=0; i<k; i++)
        {
            f=a+i;
            cout << f << '\n';
        }
        for(int i=b-k+1; i<=b; i++)
        {
            if(i==f)
                continue;
            cout << i << '\n';
        }
    }
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int

#define M_DEBUG 1
#define PI 3.141592653589793
#define MOD 100000007

#define M 1000000000

#define E '\n'

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> aa(n, 0);
    for (int i = 0; i < m; ++i) {
        int j;
        string ss;
        cin >> j >> ss;
        j--;
        if (aa[j] >= 0) {
            if (ss == "WA")
                aa[j]++;
            else {
                a++;
                p += aa[j];
                aa[j] = -1;
            }
        }
    }

    cout << a << " " << p << E;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    string S;cin>>S;
    
    int ans=0;
    for(int i=2;i<N;i++){
        if(S[i-2]=='A'&&S[i-1]=='B'&&S[i]=='C') ans++;
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
        int n;
        vector<pair<int, pair<int, int>>> v;
        cin >> n;
        for(int i = 0; i < n; i++) {
                int a, b, c;
                cin  >> a>> b>> c;
                v.push_back({a, {b, c}});
        }
        sort(v.begin(), v.end());
        int x = 0, y = 0, t = 0;
        for (int i = 0; i < n; i++) {
                int dst = abs(x - v[i].second.first)+abs(y - v[i].second.second);
                int rem = (dst%(v[i].first - t));
                if (dst > (v[i].first-t) ||  (rem != 0 && rem % 2 == 0)) {
                        cout << "No";
                        return 0;
                } else {
                        x = v[i].second.first;
                        y = v[i].second.second;
                        t = v[i].first;
                }
        }
        cout << "Yes";
        return 0;
}


Measured memory_bytes: 1912
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define debug(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define debug(...) 
#define end_time()
#endif
 
 
#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
inline int gcd(int a, int b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); } 
inline int power(int x, int n, int m = LLONG_MAX)
    {  int res=1; x = (x%m + m)%m;
       while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
    }
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007
void dfs(vector<vector<int>> &adj, vector<int> &vis, vector<int> &cnt, int node){
	trace(node);
	vis[node] = 1;
	for(auto x : adj[node]){
		if(vis[x]) {
			cnt[node] = max(cnt[node],1+cnt[x]);
			continue;
		}
		dfs(adj,vis,cnt,x);
		cnt[node] = max(cnt[node],1+cnt[x]);
	}
	trace(node,cnt[node]);
	return;
}
void solve(){
	int n,m;
	cin>>n>>m;
	vector<vector<int>> adj(n+1);
	vector<vector<int>> tadj(n+1);
	for(int i = 0; i<m; i++){
		int u,v;
		cin>>u>>v;
		adj[u].pb(v);
		tadj[v].pb(u);
	}
	vector<int> vis(n+1,0);
	vector<int> in(n+1,0);
	vector<int> out(n+1,0);
	for(int i = 1; i<=n; i++){
		if(!vis[i]) dfs(adj,vis,out,i);
	}
	vis = vector<int>(n+1,0);
	for(int i = 1; i<=n; i++){
		if(!vis[i]) dfs(tadj,vis,in,i);
	}
	debug(out);
	debug(in);
	int ans = 0;
	for(int i = 1; i<=n; i++){
		ans = max(ans,in[i]+out[i]);
	}
	cout<<ans<<"\n";
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;++i) {
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	end_time();
	return 0;
}


Measured memory_bytes: 25432
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>

using namespace std;
char a;
int num[200];
int main()
{
	for (int i = 0; i < 3; i++)
	{
		cin >> a;
		num[a]++;
		if (num[a] > 1)
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;

 }

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<String> wordList = new ArrayList<String>();
		String beforeWord = sc.next();
		wordList.add(beforeWord);
		for(int i =1;i <n;i++) {
			String word = sc.next();
			if(!beforeWord.substring(beforeWord.length()-1).equals(
					word.substring(0, 1))) {
				System.out.println("No");
				return;
			}
			if(wordList.indexOf(word) != -1) {
				System.out.println("No");
				return;
			}
			wordList.add(word);
			beforeWord = word;
		}
		System.out.println("Yes");
	}
}

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

int main(){
	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	if(v == w){
		if(a == b){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}else if(v > w){
		if((v-w)*t >= abs(a-b)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}else if(v < w){
		if(a == b){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

vector<string> split(const string &str, char delim) {
    vector<string> res;
    size_t current = 0, found;
    while((found = str.find_first_of(delim, current)) != string::npos) {
        res.push_back(string(str, current, found - current));
        current = found + 1;
    }
    res.push_back(string(str, current, str.size() - current));
    return res;
}

string func(string a,string b) {
    string ret;
    if(a.size() < b.size()) swap(a,b);

    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());

    int carry = 0;
    rep(i,b.size()) {
        int x = a[i] - '0';
        int y = b[i] - '0';
        int z = x + y + carry;

        carry = z / 10;
        ret.push_back('0' + (z%10));
    }

    REP(i,b.size(),a.size()) {
        int x = a[i] - '0';
        int z = x + carry;

        carry = z / 10;
        ret.push_back('0' + (z%10));
    }

    if(carry) ret.push_back('0' + carry);
    reverse(ret.begin(),ret.end());
    return ret;
}

int main() {
    string s;
    while(cin >> s) {
        vector<string> t = split(s,'+');
        vector<string> v = split(t[1], '=');

        string a = t[0], b = v[0] , c = v[1];
        bool flag = true;

        rep(i,10) {
            string A = a, B = b, C = c;
            rep(j,a.size()) {
                if(i == 0 && j == 0 && a.size() >= 2) continue;
                if(a[j] == 'X') A[j] = '0' + i;
            }

            rep(j,b.size()) {
                if(i == 0 && j == 0 && b.size() >= 2) continue;
                if(b[j] == 'X') B[j] = '0' + i;
            }

            rep(j,C.size()) {
                if(i == 0 && j == 0 && c.size() >= 2) continue;
                if(c[j] == 'X') C[j] = '0' + i;
            }

            bool ch = true;
            rep(j,A.size()) if(A[j] == 'X') ch = false;
            rep(j,B.size()) if(B[j] == 'X') ch = false;
            rep(j,C.size()) if(C[j] == 'X') ch = false;

            // cout << "i:" << i << endl;
            // cout << A << endl;
            // cout << B << endl;
            // cout << C << endl;


            if(ch && func(A,B) == C) {
                cout << i << endl;
                flag = false;
            }
        }

        if(flag) cout << "NA" << endl;

    }
    return 0;
}

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

int main()
{
    int k;
    string s;

    cin >> k >> s;

    if (s.length() <= k)
        cout << s << endl;
    else
    {
        for (int i = 0; i < k; ++i)
            cout << s[i];

        cout << "..." << endl;
    }

    return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int A[100010];

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

	int N;
	cin >> N;
	int A[100010];
	rep(i, 0, N)
	{
		cin >> A[i];
	}

	sort(A, A + N);

	int ans[2] = { 0 };
	pair<int, int> ps[2];
	ps[0] = mp(0, N - 1);
	ps[1] = mp(0, N - 1);
	ans[0] = A[N / 2];
	ans[1] = -A[N / 2];
	rep(i, 1, N)
	{
		int t = 2;
		if (i == N - 1)
		{
			t = 1;
		}
		if (i % 2 == 1)
		{
			ans[0] -= t * A[ps[0].first];
			ps[0].first++;
			ans[1] += t * A[ps[1].second];
			ps[1].second--;
		}
		else
		{
			ans[0] += t * A[ps[0].second];
			ps[0].second--;
			ans[1] -= t * A[ps[1].first];
			ps[1].first++;
		}
	}

	cout << max(ans[0],ans[1]) << endl;

	return 0;
}

Measured memory_bytes: 1024