akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/arc026/tasks/arc026_2
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=''
  if n==0:
    return 0

  while True:
    if abs(n)==0:
      return ans

    if n%2==0:
      ans='0'+ans
    else:
      ans='1'+ans
    n//=2
    n*=(-1)

# main()
print(main())


Measured memory_bytes: 5188
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <math.h>
#include <string>
#include <iostream>
#include <functional>
using namespace std;
typedef long long ll;

int main()
{
	int N, K;
	scanf("%d %d", &N, &K);

	priority_queue<int> PQ;
	for (int i = 1; i <= N; i++)
	{
		int h;
		scanf("%d", &h);
		PQ.push(h);
	}

	ll ans = 0;
	while (!PQ.empty())
	{
		if (K > 0) K--;
		else ans += PQ.top();

		PQ.pop();
	}
	printf("%lld", ans);

	return 0;
}

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;

  // 白：0, 黒：1
  vector<vector<int>> board(110, vector<int> (110, 0));

  rep(i, n) {
    int x, y, a;
    cin >> x >> y >> a;
    
    if (a == 1) {
      rep(j, h) {
        for (int k = 0; k < x; k++) board[j][k] = 1;
      }
    } else if (a == 2) {
      rep(j, h) {
        for (int k = x; k < w; k++) board[j][k] = 1;
      }
    } else if (a == 3) {
      for (int j = 0; j < y; j++) {
        rep(k, w) board[j][k] = 1;
      }
    } else {
      for (int j = y; j < h; j++) {
        rep(k, w) board[j][k] = 1;
      }
    }
  }

  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if (board[i][j] == 0) 
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 2e5 + 5;

 
int arr[N];

int32_t  main() {

	IOS;



	int x, y;

	cin >> x >> y;

	if(x*2 <= y && x*4>= y && y%2==0 ){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 3120
n=int(input());l=[list(map(int,input().split()))for i in[0]*n];a=[0]*n;d=1;k=n*(n-1)
while sum(a)<k and d<9999:
 L=[0]*n;y=0;d+=1
 for i in range(n):
  if a[i]<n-1:
   x=l[i][a[i]]-1
   if l[x][a[x]]-1==i and L[x]+L[i]<1:
    a[i]+=1;a[x]+=1;L[i]=L[x]=y=1
d*=y;print([k//2,d-1][d<9999])

Measured memory_bytes: 53980
from heapq import  heappop, heappush
def dijkstra(edges,start,first_index=0):
    d=[-1]*(len(edges)+first_index)
    hq=[(0,start)]
    while hq:
        c,v=heappop(hq)
        if d[v]!=-1:continue
        d[v]=c
        for to,cos in edges[v]:
            if d[to]==-1:heappush(hq,(c+cos,to))
    return d
v,e,st,*l=map(int,open(0).read().split())
ed=[[] for i in range(v)]
for a,s,d in zip(*[iter(l)]*3):
    ed[a].append((s,d))

for i in dijkstra(ed,st):
    print("INF"if -1==i else i )



Measured memory_bytes: 167280
/***
 ** "A lion doesn't concern himself with the opinion of sheep."
 **     -- David Hyner
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: __________
  *  Date:   27.04.2020
  *  Time:   03:55:12
**/

#define header_file "Lib/debug.h"
#if __has_include(header_file)
	#include header_file
#else
	#include<bits/stdc++.h>
	using namespace std;
	
	#define fundri 108
	#define debug(...) 1729
#endif

#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(), s.end()

// if vector isn't soted then it will remove consecutive same elements
#define make_unique(vec) vec.erase(unique(all(vec)), vec.end())
#define test int TC = 1;if(testcases)cin >> TC;for(int tc = 1 ; tc <= TC ; tc++)
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

void online_judge();
int seed; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}

template<typename T>bool isPrime(T n) {for(T i = 2; i * i <= n; i++)if(n % i == 0)return 0; return 1;}
template<typename T>inline bool in_range(T a, T l, T r) {return (a >= l && a <= r);}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.ff >> a.ss; return in;}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(auto &x : a)in >> x; return in;}

int32_t main(int32_t argc, char **argv)
{
	online_judge();
	
	int a, b, c, d;
	
	test {
	
		cin >> a >> b >> c >> d;
		bool f = false;
		
		while(a > 0 && c > 0)
		{
			if(f) a -= d;
			else  c -= b;
			
			f = !f;
		}
		
		cout << (f ? "Yes" : "No") << endl;
		
		fundri;
	}
	
	return 0;
}

void online_judge()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
#ifdef DHRUV_GHEEWALA
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
#endif
	
}

Measured memory_bytes: 3600
N,Q = [int(i) for i in input().split()]
graph = [[] for _ in range(N+1)]
ans = [0] * (N+1)
for i in range(N-1):
    a,b = [int(j) for j in input().split()]
    graph[a].append(b)
    graph[b].append(a)
for i in range(Q):
    pa,xaa = [int(j) for j in input().split()]
    ans[pa] += xaa

seen = [False] * (N+1)

import collections
from collections import deque
que = deque()
que.append(1)
seen[1] = True
while len(que) != 0:
    x = que.popleft()
    seta = set(graph[x])
    for i in seta:
        if seen[i]:
            continue
        ans[i] += ans[x]
        que.append(i)
        seen[i] = True
print(*ans[1:])

Measured memory_bytes: 118884
#include <iostream>
#include <cmath>

using namespace std;

int main(void)
{
    long long n, a, b, step;

    cin >> n >> a >> b;

    if(abs(a-b)&1)
    {
        if(a > b)
            swap(a,b);
        if(a-1 < n-b)
        {
            step = a-1;
            b-=step;
            if((b-1)&1)
                cout << ((b-1)>>1)+1+a-1;
            else
                cout << ((b-1)>>1)+a-1;
        }
        else
        {
            step = n-b;
            a+=step;
            if((n-a)&1)
                cout << ((n-a)>>1)+1+n-b;
            else
                cout << ((n-a)>>1)+n-b;
        }
    }
    else
        cout << (abs(a-b)>>1);

    return 0;
}


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

int f(char *s){
    int i, x = 0, n = strlen(s);
    for (i = 0; i < n; i++) x += s[i] - '0';
    return x;
}

int main(){
    char x[9];
    scanf("%s", x);
    if (atoi(x)%f(x) == 0) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 128
//https://atcoder.jp/contests/abc165/tasks/abc165_a
#include <stdio.h>

int main() {
    
    int a, b, k, i;
    
    int c[2000];
    
    scanf("%d", &k);
    printf("\n");
    
    scanf("%d %d", &a, &b);
    
    c[0]= a;
    
    if(b-a+1>k||b-a+1==k||a%k==0||b%k==0)
        printf("OK");
    else{
        for(i=1; i<=b-a+1; i++){
            c[i]= c[i-1]+1;
            //printf("繰り返し : %d\n", c[i]);
            
            if(c[i]%k==0&&i<b-a+1){
                printf("OK");
                break;
            }
            else if(i==b-a+1){
                printf("NG");
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int dp[100005];
int solve(){
    int k; cin>>n>>k;
    int h[n+1]; rep(i,1,n) cin>>h[i];
    rep(i,2,n){
        dp[i]=INF;
        rep1(j,i-1,1){
            if(i-j>k) break;
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n];
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

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

int main() {
    int N, M, sum = 0;
    cin >> N;
    int T[N];
    for(int i = 0; i < N; i++) {
        cin >> T[i];
        sum += T[i];
    }
    cin >> M;
    int P[M], X[M];
    for(int i = 0; i < M; i++) {
        cin >> P[i] >> X[i];
    }

    for(int i = 0; i < M; i++) {
        cout << sum - (T[P[i]-1] - X[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int k,n;
    cin>>k>>n;
	int a[n],mx=-1;
	rep(i,0,n){
		cin>>a[i];
		if(i!=0&&mx<a[i]-a[i-1])mx=a[i]-a[i-1];
	}
	int chk=k+a[0]-a[n-1];
	if(chk>mx)mx=chk;
	cout<<k-mx<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


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

using namespace std;

int main(){
	char ch=getchar();
	bool flag1=0;
	while(ch!=EOF){
		if(ch=='C') flag1=1;
		if(flag1&&ch=='F') {
			printf("Yes");
			return 0;
		}
		ch=getchar();
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  ll N,F=0;
  cin>>N;
  rep(i,3501){
    rep(j,3501){
      if(i&&j&&4*i*j-N*j-N*i>0) if((N*i*j)%(4*i*j-N*j-N*i)==0&&(N*i*j)/(4*i*j-N*j-N*i)<=3500){
        cout<<i<<" "<<j<<" "<<(N*i*j)/(4*i*j-N*j-N*i)<<endl;
        F++;
        break;
      }
    }
    if(F) break;
  }
}



Measured memory_bytes: 256
// https://drken1215.hatenablog.com/entry/2019/02/14/124300

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define nyan "(=^･ω･^=)"
using namespace std;

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
using ll = long long;
using P = pair<int,int>;

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; }


class UnionFind{
public:
    
    // 親の番号を格納する
    // Parent -> -(the size)
    vector<int> Parent;
    
    // initialization
    // all nodes are roots
    UnionFind(int N){
        Parent =  vector<int>(N, -1);
    }
    
    int root(int A){
        if (Parent[A] < 0) return A; // A is in its own group.
        return Parent[A] = root(Parent[A]); // exchange parents
    }
    
    long long size(int A){
        return -Parent[root(A)];
    } 
    
    void connect(int A, int B){
        
        A = root(A);
        B = root(B);
        
        if (A == B) return; //already connected
        
        if (size(A) < size(B)) swap(A, B);
        
        Parent[A] += Parent[B]; //小さい方を大きい方にくっつける
        Parent[B] = A; //小さい方を大きい方にくっつける
        
    }
};


// x座標による辞書式順序でMST
// y座標による辞書式順序でMST


int main(){
    int N;
    cin >> N;
    
    vector<int> x(N), y(N);
    rep(i, N) cin >> x[i] >> y[i];
    
    // Kruskal methodで使うedge
    using pint = pair<int, int>; //edgeを表現する
    
    // long longのほうがコスト, pintのほうがedgeの情報を表す
    using Edge = pair<long long, pint>; 
    vector<Edge> edges;
    
    // x 軸方向にソートして隣接している部分のみ
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0); //???????
    sort(ids.begin(), ids.end(), [&](int i, int j) {return x[i] < x[j];});
    
    for (int i = 0; i+1 < ids.size(); i++){
        int u = ids[i];
        int v = ids[i+1];
        edges.push_back( Edge(x[v] - x[u], pint(u, v) ) );
    }
    
    // y軸方向にソートして隣接している部分のみ考える
    sort(ids.begin(), ids.end(), [&](int i, int j) {return y[i] < y[j]; } );
    for (int i = 0; i+1 < ids.size(); i++){
        int u = ids[i];
        int v = ids[i+1];
        edges.push_back( Edge(y[v] - y[u], pint(u, v)) );
    }
    
    // kruskal method
    sort(edges.begin(), edges.end()); //edge.costが小さい順にソートする
    
    UnionFind Uni(N);
    
    long long res = 0;
    
    for (auto e : edges){
        
        int u = e.second.first;
        int v = e.second.second;
        long long cost = e.first;
        
        if(Uni.root(u) == Uni.root(v)) continue;
        
        Uni.connect(u, v);
        
        res += cost;
    }
    
    cout << res << endl;
}



Measured memory_bytes: 7664
#include<iostream>
#include<cmath>

using namespace std;

int main( )
{
	double a, b, C;

	cin>>a>>b>>C;
	
	double radianC = ( C * M_PI )/180.0;
	double h = sin( radianC ) * b;
	double S = a * h * 0.5;
	
	double L = sqrt( pow( ( a-( cos( radianC ) * b ) ), 2 ) + pow( h, 2 ) );
	L = L + a + b;
	
	
	cout.setf( ios::fixed );
	cout<<S<<'\n'<<L<<'\n'<<h<<'\n';
		
	return 0;
}

Measured memory_bytes: 1288
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int min(int a,int b){if(a<b){return a;}return b;}

long long nCr[64][64]={0};
void calcnCr(){
  nCr[0][0]=1;
  long long i,j;
  for(i=0;i<63;i++){
    for(j=0;j<=i;j++){
      nCr[i+1][j]+=nCr[i][j];
      nCr[i+1][j+1]+=nCr[i][j];
    }
    for(j=2;j<=i;j++){nCr[i][j]+=nCr[i][j-1];}
  }
  return;
}

long long res=0,s,t,k;

void rep(int nb,int nv,int lis[],int c){
  if(c<=0){return;}
  int i,bd;
  if(nb==-1){
    long long ce=1;
    bd=min(c,k);
    if(nv&1){ce=-1;}
    res+=(ce*nCr[c][bd]);
    //printf("<%lld>\n",ce*nCr[c][bd]);
    //for(i=1;i<=bd;i++){
      //printf("<%lld>\n",ce*nCr[c][i]);
      //res+=(ce*nCr[c][i]);
    //}
    return;
  }
  //printf("<%d %d>:",nb,nv);
  //for(i=0;i<c;i++){printf("[%d]",lis[i]);}printf("\n");
  rep(nb-1,nv,lis,c);
  if((s&(1<<nb))==(t&(1<<nb))){return;}
  int liz[64],lio[64],lzc=0,loc=0;
  for(i=0;i<c;i++){
    if((lis[i]&(1<<nb))){lio[loc]=lis[i];loc++;}
    else{liz[lzc]=lis[i];lzc++;}
  }
  rep(nb-1,nv+1,lio,loc);
  rep(nb-1,nv+1,liz,lzc);
}

int main(void){
  calcnCr();
  int i,j,n,a[64];
  int lis[64],c=0;
  scanf("%d%d%d%d",&n,&k,&s,&t);
  if((s&t)!=s){printf("0\n");return 0;}
  if((s|t)!=t){printf("0\n");return 0;}
  for(i=0;i<n;i++){scanf("%d",&a[i]);}
  for(i=0;i<n;i++){
    if((a[i]&s)!=s){continue;}
    if((a[i]|t)!=t){continue;}
    lis[c]=a[i];c++;
  }
  rep(17,0,lis,c);
  printf("%lld\n",res);
  return 0;
}


Measured memory_bytes: 1776
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

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

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll n, K; cin >> n >> K;
	vector<ll> d;
	for (ll i = 1; i * i <= n; i++) {
		d.emplace_back(n / i);
		d.emplace_back(i);
	}
	sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end());
	vector<ll> cnt(d.size());
	for (int i = 0; i + 1 < d.size(); i++) {
		cnt[i] += n / d[i] - n / d[i + 1];
	}

	cnt.back() = 1;
	vector dp(K + 1, vector<mint>(d.size() + 1));
	auto get = [&](ll x)-> int {
		return lower_bound(d.begin(), d.end(), x) - d.begin();
	};
	dp[0][(int)d.size() - 1] = 1;
	for (int i = 1; i <= K; i++) {
		vector<mint> sum(d.size() + 1); for (int j = 0; j < d.size(); j++) sum[j + 1] = sum[j] + dp[i - 1][j];
		for (int j = 0; j < d.size(); j++) {
			dp[i][j] += (sum.back() - sum[get(n / d[j])]) * cnt[j];
		}
	}
	mint res = 0; for (int i = 0; i < d.size(); i++) res += dp[K][i];
	cout << res.x << "\n";
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  int i;
  for (i=0; i<N; i++) cin >> card.at(i);
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  int Alice=0;
  int Bob=0;
  for (i=0; i<N; i++){
    if (i%2==0) Alice+=card.at(i);
    else Bob+=card.at(i);
  }
  cout << Alice-Bob << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    double mu = (double)(a+b)/2;
    System.out.println((int)Math.ceil(mu));
  }
}


Measured memory_bytes: 21716
import re

s = "".join("." if i == "?" else i for i in input())
t = input()

lent = len(t)
mgroup = ""
mstart = 0
for start in range(len(s) - lent + 1):
    m = re.match(re.compile(s[start:start+lent]), t)    
    if m:
        mgroup, mstart = m.group(), start
else:
    if mgroup:
        s = s[:mstart] + t + s[mstart+lent:]
        print(s.replace(".", "a"))
    else:
        print("UNRESTORABLE")

Measured memory_bytes: 9800
#include <cstdio>
#include <vector>

int main()
{
	int n, m;
	std::vector<int> target;
	std::vector<int> score;

	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; ++i) {
		int temp;
		scanf("%d", &temp);
		target.push_back(temp);
	}
	score.resize(n, 0);

	for(int game_count = 0; game_count < m; ++game_count) {

		int t = target[game_count] - 1;
		score[t] += n;

		for(int i = 0; i < n; ++i) {

			int v;
			scanf("%d", &v);
			v -= 1;
			if(v != t)
				continue;
			score[t] -= 1;
			score[i] += 1;
		}
	}

	for(int i = 0; i < n; ++i)
		printf("%d\r\n", score[i]);

	return 0;
}

Measured memory_bytes: 2740
#include<stdio.h>
#include<string.h>

int main()
{
	char S[11];
	char T[11];
	
	scanf("%s", S);
	scanf("%s", T);
	
	int A,B;
	scanf("%d", &A);
	scanf("%d", &B);
	
	char U[10];
	scanf("%s", U);
	
	if(strcmp(U,S)==0) printf("%d %d", A-1,B);
	if(strcmp(U,T)==0) printf("%d %d", A,B-1);
	
	return 0;
}

Measured memory_bytes: 3176
#import
#import math
#import numpy as np
#= int(input())
#= input()
N, W = map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]

x = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, W + 1):
        dp[i][j] = dp[i - 1][j]
        if i != 0 and x[i - 1][0] <= j:
            dp[i][j] = max(dp[i][j], dp[i-1][j-x[i-1][0]] + x[i-1][1])

print(dp[-1][W])


Measured memory_bytes: 152240
n, m = map(int, input().split())
ans = 0
k = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

for bit in range(1 << n):
    for i in range(m):
        flag = True
        acc = 0
        for s in k[i][1:]:
            #スイッチssが点灯しているかどうか
            if (bit & (1 << s)):
                acc += 1
        if acc % 2 != p[i]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)


Measured memory_bytes: 39920
X, Y, Z, K = map(int, input().split())
*A, = sorted(map(int, input().split()), reverse=True)
*B, = sorted(map(int, input().split()), reverse=True)
*C, = sorted(map(int, input().split()), reverse=True)
AB = [A[x] + B[y] for y in range(Y) for x in range(X)]
AB.sort(reverse=True)
AB = AB[:K]
XY = len(AB)
ABC = [AB[x] + C[z] for z in range(Z) for x in range(XY)]
ABC.sort(reverse=True)
for k in range(K):
    print(ABC[k])


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int32 n;
vector<int32> par;
vector<vector<int32>> children;
vector<vector<int32>> adj;

vector<int32> cntChildren;

int32 dfs(int32 x){
    if(children[x].size() == 0)return cntChildren[x] = 1;
    int32 res = 1;
    for(int32 y : children[x]){
        res += dfs(y);
    }
    return cntChildren[x] = res;
}

int64 modpow(int64 n, int64 r){
    if(r == 0)return 1;
    if(r % 2 == 0){
        int64 x = modpow(n, r / 2);
        return x * x % MOD;
    }else{
        return modpow(n,r-1) * n % MOD;
    }
}

vector<int64> powerOfTwo;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    par.resize(n,-1);
    children.resize(n);
    adj.resize(n);
    cntChildren.resize(n,0);
    powerOfTwo.resize(n+1);
    REP(i,n-1){
        int32 a,b;
        cin >> a >> b;
        a--;b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    queue<int32> que;
    par[0] = 0;
    que.push(0);
    while(!que.empty()){
        int32 x = que.front();
        que.pop();
        for(int32 y : adj[x]){
            if(par[y] == -1){
                par[y] = x;
                children[x].pb(y);
                que.emplace(y);
            }
        }
    }
    dfs(0);
    powerOfTwo[0] = 1;
    REP(i,n){
        powerOfTwo[i+1] = powerOfTwo[i] * 2 % MOD;
    }
    int64 ans = 0;
    REP(i,n){
        vector<int64> cnt;
        int64 sum = 0;
        for(int32 x : children[i]){
            sum += cntChildren[x];
            cnt.pb(cntChildren[x]);
        }
        if(n - sum - 1 > 0)
            cnt.pb(n - sum - 1);
        // cout << i << endl;
        // for(int64 x : cnt)cout << x << " ";
        // cout << endl;
        if(cnt.size() < 2)continue;
        ans += modpow(2,MOD-2) - modpow(powerOfTwo[n], MOD-2);
        ans = (ans + MOD) % MOD;
        for(int64 x : cnt){
            ans -= modpow(powerOfTwo[n-x], MOD-2) - modpow(powerOfTwo[n], MOD-2);
            ans = (ans + MOD) % MOD;
        }
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 33280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N; cin>>N;
  vector<vector<int>> abc;
  abc.assign(N, vector<int>(3,0));
  for(auto& abci : abc) {
    for(auto& i : abci) {
      cin >> i;
    }
  }

  vector<vector<int>> dp(N+10, vector<int>(3,0));
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 3; j++) {
      for(int k = 0; k < 3; k++) {
        if(j == k) { continue; }
        dp[i+1][j] = max(dp[i+1][j], dp[i][k] + abc[i][k]);
      }
    }
  }

  int imax = max(dp[N][0], max(dp[N][1], dp[N][2]));
  cout << imax << endl;
}


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

int main(){
    
    int ap,bp,cp,t;
    char a[999],b[999],c[82];
    
    scanf("%d",&t);
    while (~scanf("%s %s",a,b)) {
        ap = strlen(a);
        bp = strlen(b);
        c[cp=(ap>80 || bp>80)? 0:81]='\0';
        t=0;
        while ((t||ap||bp) && cp>0) {
            t +=(ap? a[--ap]-'0':0) + (bp? b[--bp]-'0':0);
            c[--cp] = t%10 + '0';
            t /=10;
        }
        if(cp>0) printf(&c[cp]);
        else printf("overflow");
        printf("\n");
    }
    
    return 0;
    
}

Measured memory_bytes: 588
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <functional>
#include <algorithm>
#include <utility>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <complex>

using namespace std;

typedef long double C;
typedef complex<C> P;

#define have(X, Y) (X).find(Y) != (X).end()
#define X real()
#define Y imag()
#define ui unsigned int
#define int long long
#define mp make_pair
#define timer fghge
#define y1 yjyjyju
#define all(X) (X).begin(), (X).end()
#define endl "\n"

const int mod = 998244353;

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("search5.out", "w", stdout);

	int n, s; cin >> n >> s;
	vector<int> a(n);
	for (auto &i : a)
		cin >> i;
	vector<vector<int>> dp(n, vector<int>(s + 1));
	for (int j = 0; j <= s; j++) {
		if (a[0] == j)
			dp[0][j] = 1;		
	}
	int ans = dp[0][s];

	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= s; j++) {			
			dp[i][j] = dp[i - 1][j];
			if (a[i] == j)
				dp[i][j] += i + 1;
			dp[i][j] %= mod;
			if (a[i] <= j) 
				dp[i][j] += dp[i - 1][j - a[i]];
			dp[i][j] %= mod;
		}
		ans += dp[i][s];
		ans %= mod;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 70784
def main():
    H, W = map(int, input().split())
    matrix = [list(input()) for _ in range(H)]
    L = [[0 for _ in range(W)] for _ in range(H)]
    R = [[0 for _ in range(W)] for _ in range(H)]
    D = [[0 for _ in range(W)] for _ in range(H)]
    U = [[0 for _ in range(W)] for _ in range(H)]

    # 左方向についてカウントする
    for i in range(H):
        if matrix[i][0] == '.':
            L[i][0] = 1
        for j in range(1, W):
            s = matrix[i][j]
            if s == '.':
                L[i][j] = L[i][j-1] + 1

    # 右方向についてカウントする
    for i in range(H):
        if matrix[i][-1] == '.':
            R[i][-1] = 1
        for j in range(W-2, -1, -1):
            s = matrix[i][j]
            if s == '.':
                R[i][j] = R[i][j+1] + 1
    
    # 上方向についてカウントする
    for i in range(W):
        if matrix[0][i] == '.':
            U[0][i] = 1
        for j in range(1, H):
            s = matrix[j][i]
            if s == '.':
                U[j][i] = U[j-1][i] + 1
    
    # 下方向についてカウントする
    for i in range(W):
        if matrix[-1][i] == '.':
            D[-1][i] = 1
        for j in range(H-2, -1, -1):
            s = matrix[j][i]
            if s == '.':
                D[j][i] = D[j+1][i] + 1    
    
    max_val = -3
    for i in range(H):
        for j in range(W):
            max_val = max(max_val, R[i][j]+L[i][j]+U[i][j]+D[i][j])
    print(max_val-3)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 312840
// inputに入力データ全体が入る
function Main(input) {
  input = input.split(' ');
  var a = Number(input[0]);
  var b = Number(input[1]);
  var r = a - b * 2;
  if (r < 0) {
  	r = 0
  }
  console.log(r);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
//config = {input: 'tmp', newline: '\r\n'}; // win
config = {input: '/dev/stdin', newline: '\n'}; //linux

line = require('fs').readFileSync(config.input, 'ascii')
  .split(' ')
  .map(Number);

function gcd(x, y) {
  if (y > x) gcd(y, x);
  if (y % x === 0) return x;
  return gcd(y, x % y);
}

console.log(gcd(line[0], line[1]));

Measured memory_bytes: 15584
#!/usr/bin/env python3
import sys


def solve(N: int, B: "List[int]"):
    B_ex = [B[0]] + B + [B[-1]]
    print(sum([min(B_ex[i], B_ex[i+1]) for i in range(N)]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(std::string S){
    if (S.size() % 2) {
        string s1 = S.substr(0, S.size()/2);
        string s2 = S.substr(S.size()/2 + 1);
        reverse(s2.begin(), s2.end());
        int count = 0;
        REP(i, S.size()/2)
            if (s1[i] != s2[i]) count++;
        cout << count << '\n';
    } else {
        string s1 = S.substr(0, S.size()/2);
        string s2 = S.substr(S.size()/2);
        reverse(s2.begin(), s2.end());
        int count = 0;
        REP(i, S.size()/2)
            if (s1[i] != s2[i]) count++;
        cout << count << '\n';
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

	public void solve() {
		int n = in.nextInt();
		int[] a = new int[n];
		long sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
			sum += a[i];
		}
		long t = a[0];
		sum -= a[0];
		long min = Math.abs(t - sum);
		for(int i = 1; i < n - 1; i++) {
			t += a[i];
			sum -= a[i];
			min = Math.min(min, Math.abs(t - sum));
		}
		System.out.println(min);
	}

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

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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	vector<int> p(N);
	for(int i=0;i<N;i++)	cin >> p.at(i);

	int count=0;
	for(int i=0;i<N;i++){
		if(p.at(i)==i+1)	count++;
	}
	if(count>=N-2)	cout << "YES" << endl;
	else	cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=7+1e9;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}
ll getInv(ll x,ll p){return qpow(x,p-2,p);}
const double pi=3.1415926535898;
#define fi first
#define se second
const int N=5+1e3;
vector<pair<pair<int,int>,int>> a;
double squ(ll x){ return x*x;}
double cal(ll x,ll y){ return max(sqrt(squ(a[x].fi.fi-a[y].fi.fi)+squ(a[x].fi.se-a[y].fi.se))-a[x].se-a[y].se,0.00000000000);}
double dis[N][N];
priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> q;
double d[N];

int main(){
    pair<int,int> tmp; cin>>tmp.fi>>tmp.se;
    a.push_back({tmp,0});
    cin>>tmp.fi>>tmp.se;
    a.push_back({tmp,0});
    int n; cin>>n;
    for(int i=1;i<=n;i++){
        int v;
        cin>>tmp.fi>>tmp.se>>v;
        a.push_back({tmp,v});
    }
    for(int i=0;i<n+2;i++)
        for(int j=i+1;j<n+2;j++)
            dis[j][i]=dis[i][j]=cal(i,j);
    for(int i=0;i<n+2;i++) d[i]=LONG_LONG_MAX;
    d[0]=0;
    q.push({d[0],0});
    while(q.size()){
        int x=q.top().second;
        q.pop();
        for(int i=0;i<n+2;i++){
            if(i==x) continue;
            if(d[i]>d[x]+dis[x][i]){
                d[i]=d[x]+dis[x][i];
                q.push({d[i],i});
            }
        }
    }
    printf("%.11lf\n",d[1]);
}

Measured memory_bytes: 15296
import java.util.*
import kotlin.math.abs

fun main() {
    a()
}

fun a() {
    val x = readLong()
    if (x >= 30) {
        "Yes"
    } else {
        "No"
    }.let { println(it) }
}

fun readLong() = readLine()!!.toLong()
fun readLongList() = readLine()!!.split(" ").map { it.toLong() }

fun Long.bitEach(action: (Int) -> Unit) {
    (0 until Long.SIZE_BITS).forEach { action(((this shr it) and 1).toInt()) }
}

fun Long.bitFilter(bit: Int) = (0 until Long.SIZE_BITS).filter { ((this shr it) and 1) == 1L }

fun <T1, T2> pairs(first: Iterable<T1>, second: Iterable<T2>) = first.flatMap { t1 -> second.map { t2 -> t1 to t2 } }

fun Long.print() {
    println(this)
}

Measured memory_bytes: 34472
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

x,y=map(int,input().split())

if (2*y-x)%3==0:
    a=(2*y-x)//3
    b=(2*x-y)//3
    mod = 10**9+7 #出力の制限
    N = a+b
    r=min(a,b)
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    print(cmb(N,r,mod))
else:
    print(0)

Measured memory_bytes: 118988
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use std::mem::swap;

#[fastout]
fn main() {
    input! {
    s: Chars
    }
    let p = 1_000_000_007;
    let n = s.len();
    let mut dp = vec![0; 13];
    dp[0] = 1;
    for i in 0..n {
        let mut prev = vec![0; 13];
        swap(&mut prev, &mut dp);
        let d = if s[i] == '?' { 10 } else { s[i].to_digit(10).unwrap() as usize };
        for j in 0..10{
            if d < 10 && j != d {continue}
            for k in 0..13 {
                dp[(k * 10 + j) % 13] += prev[k];
                dp[(k * 10 + j) % 13] %= p;
            }
        }
    }
    let ans = dp[5];
    println!("{}", ans);
}


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> X(3);
  X[0] = abs(A - B);
  X[1] = abs(A - C);
  X[2] = abs(B - C);
  sort(X.begin(), X.end());
  cout << X[0] + X[1] <<endl;
}

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

int A[1010], B[1010], dp[1010][10010];

int main() {
	int H, N;
	cin >> H >> N;
	for(int i=0; i<N; ++i) cin >> A[i] >> B[i];
	for(int i=1; i<=H; ++i) dp[0][i]=1e9;
	dp[0][0]=0;
	for(int i=0; i<N; ++i){
		for(int j=0; j<=H; ++j){
			dp[i+1][j]=dp[i][j];
			if(j<A[i]) dp[i+1][j]=min(dp[i+1][j], B[i]);
			else dp[i+1][j]=min(dp[i+1][j], dp[i+1][j-A[i]]+B[i]);
		}
	}
	cout << dp[N][H] << endl;
	return 0;
}

Measured memory_bytes: 39424
#include<stdio.h>
int main()
{
	int a,b,c,n;
	while(scanf("%d",&n)!=EOF)
	{
		b=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a);
			b+=a;
		}
		printf("%d\n",b-n);
	}
	return 0;
}



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

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define SQ(a) (a)*(a)

typedef long long ll;

using namespace std;

int main() {

    int n , m, t, p , x;
    vector<int> v;
    int sum = 0; 

    cin >> n;

    while (n--)
    {
        cin >> t;
        v.push_back(t);
        sum+=t;
    }

    cin >> m;

    while(m--) {
        cin >> p >> x;
        cout << sum-v[p-1]+x << endl;
    }

	
	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pc _putchar_nolock
#define mp make_pair
#define mt make_tuple
#define um unordered_map
#define inf (ll)9223372036854775807
using namespace std;
using ll=long long int;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void input(vector<int>&a,int n)
{
   rep(i,0,n-1)
   cin>>a[i];
}
void solve()
{
  int n; cin>>n; string s; cin>>s; 
  if(n<3)
  {
  	cout<<0<<"\n"; return;
  }
  vector<int>a; 
  rep(i,0,n-1)
  {
  	if(s[i]=='A') a.eb(i);
  }
  if((int)a.size()==0)
  {
  	cout<<0<<"\n"; return;
  }
  int res=0;
  for(auto i:a)
  {
  	if(i<n-2 and s[i+1]=='B' and s[i+2]=='C') res++;
  }
  cout<<res<<"\n";
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  while(t--)
  {
	 solve();
  }
  return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	if (n % 10 == 7 || n % 100 / 10 == 7 || n / 100 == 7)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 1644
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

priority_queue<ll> pq;

int main(void){
	int n,m,i;
	ll ans=0ll,a,b;
	cin >> n >> m;
	for(i=0; i<n; ++i){
		cin >> a;
		ans += a;
		while(a){
			b = a/2;
			pq.push(a-b);
			a = b;
		}
	}
	while(!pq.empty()){
		if(!m){
			break;
		}
		ans -= pq.top();
		pq.pop();
		--m;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 35044
import java.util.Scanner;

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

        String S = scanner.next();
        String T = scanner.next();

        // 素直にやっても最悪1000 * 1000なので行ける気がする
        int minReplace = Integer.MAX_VALUE;

        for (int seek = 0; seek + T.length() <= S.length(); seek++) {
            int replace = 0;
            for (int i = 0; i < T.length(); i++) {
                if (T.charAt(i) != S.charAt(seek + i)) {
                    replace++;
                }
            }

            if (minReplace > replace) {
                minReplace = replace;
            }
        }

        System.out.println(minReplace);
    }
}

Measured memory_bytes: 27120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n, k, s;
  cin >> n >> k >> s;
  if(s!=1e9){
    rep(i,k){
      cout << s << " ";
    }
    rep(i,n-k){
      cout << 1000000000 << " ";
    }
    cout << endl;
  }
  else{
    rep(i,k){
      cout << 1000000000 << " ";
    }
    rep(i,n-k){
      cout << 1 << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int a, b;
    cin >> a >> b;
    if (!a && !b) return 0;
    int n, dp[16][16];
    bool M[16][16];
    for (int x = 0; x < a; x++)
      for (int y = 0; y < b; y++)
        M[x][y] = true;
    cin >> n;
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      M[x-1][y-1] = false;
    }
    dp[0][0] = 1;
    for (int x = 1; x < a; x++)
      dp[x][0] = M[x][0] ? dp[x-1][0] : 0;
    for (int y = 1; y < b; y++)
      dp[0][y] = M[0][y] ? dp[0][y-1] : 0;
    for (int x = 1; x < a; x++)
      for (int y = 1; y < b; y++)
        dp[x][y] = M[x][y] ? dp[x-1][y] + dp[x][y-1] : 0;
    cout << dp[a-1][b-1] << endl;
  }
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  
  int n, m; cin >> n >> m;
  vi h(n);

  rep(i, n) cin >> h[i];
  set<int> used;

  rep(i, m) {
    int a, b; cin >> a >> b;
    if (h[a-1] > h[b-1]) used.em(b-1);
    else if (h[a-1] < h[b-1]) used.em(a-1);
    else {
      used.em(a-1);
      used.em(b-1);
    }
  }

  cout << n - si(used) << endl;
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];
//平方根　= sqrt

int solve() {
  string s; cin >> s;
  
  int n = s.size();

  int ans = 999;
  for (int i=0;i <= n-3; ++i) {
    int num = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
    ans = min(ans,abs(num-753));
  }

  cout << ans << endl;
}


int main(){
  solve();
  return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;

const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

int fact(int k){
    int sum = 1;
    for(int i = 1; i<= k; ++i){
        sum *= i;
    }
    return sum;
}

int main() {
  int n, k;
  cin >> n >> k;
  int result = n - k + 1;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int w,l,r;
};
struct Node A[MAX];
int m;

void prp(int s){
  if(s == NIL) return;
  printf(" %d",s);
  prp(A[s].l);
  prp(A[s].r);
}


void inp(int s){
  if(s == NIL) return;
  inp(A[s].l);
  printf(" %d",s);
  inp(A[s].r);
}

void postp(int s){
  if(s == NIL)return;
  postp(A[s].l);
  postp(A[s].r);
  printf(" %d",s);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&m);
  for(i =0;i<m;i++){
    A[i].w = NIL;
  }

  for(i = 0;i<m;i++){
    scanf("%d %d %d",&v,&l,&r);
    A[v].l = l;
    A[v].r = r;
    if(l != NIL) A[l].w = v;
    if(r != NIL) A[r].w =v;
  }

  for(i = 0;i<m;i++)if(A[i].w == NIL) root = i;
  
  printf("Preorder\n");
  prp(root);
  printf("\n");
  printf("Inorder\n");
  inp(root);
  printf("\n");
  printf("Postorder\n");
  postp(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2000
h, w = map(int, input().split())
S = [list(input()) for i in range(h)]
          
for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            cnt = 0
            for k in range(-1, 2):
                for l in range(-1, 2):
                    ni = i + k
                    nj = j + l
                    if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == '#':
                        cnt += 1                    
            S[i][j] = cnt
                        
for i in range(h):
    print(''.join(map(str, S[i])))

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans;
string a,b,c;
int main(void){
    cin>>n>>a>>b>>c;
    for(int i=0;i<n;i++){
        if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i])ans+=2;
        else if(a[i]==b[i]&&b[i]==c[i])ans+=0;
        else ans+=1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256