akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	x--; y--;
	int ans[n]; fill(ans, ans+n, 0);
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			int d = min(j-i, abs(x-i)+1+abs(y-j));
			ans[d]++;
		}
	}
	for (int i = 1; i < n; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
long long n, x[1000000];
long long sum;
int main() {
	while (cin >> n) {
		sum = 0;
		memset(x, 0, sizeof(x));
		for (int i = 0; i < n; i++) {
			cin >> x[i];
		}
		sort(x, x + n);
		long long cnt = 0;
		for (int i = 0; i < n; i++) {
			cnt += x[i];
			sum += cnt;
		}
		cout << sum << endl;
	}
	return 0;
}

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

int main(){
  int n,m;
  int maxn = 0;
  
  cin >> n;
  cin >> m;
  
  int *in = new int[n];
  int *out = new int[n];
  int *S = new int[n + 1];

  for(int i=0; i<n; ++i) cin >> in[i] >> out[i];


  S[0] = m;
  for(int i=0; i<n; ++i){
    S[i + 1] = m + in[i] - out[i];

    m = S[i + 1];
    
    if(S[i + 1] < 0){
      cout << "0" << endl;
      return 0;
    }
    if(S[maxn] < S[i + 1]){
      maxn = i + 1;
    }
  }
  

  cout << S[maxn] << endl;
  
  delete[] in;
  delete[] out;
  delete[] S;
  
  return 0;
}



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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"

ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}
// dsu start

vi root(200001,0);
vi size(200001,1);
int find(int x){while(x!=root[x])x = root[x];return x;}
bool same(int a,int b){return find(a)==find(b);}
void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}

// dsu end
vi vis(200001,0);
vi adj[200001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //string bitstring = std::bitset< 3 >( 7 ).to_string(); <bits> (num)
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
 	string s;
 	cin>>s;
 	string a="",b="";
 	for(int i=0; i<2; ++i)
 	{
 		a+=s[i];
 		b+=s[i+2];
 	}
 	int x = stol(a);
 	int y = stol(b);
 	if(x<=12 && x>0 && y>0 && y<=12)
 		cout<<"AMBIGUOUS"<<"\n";
 	else if(x>12 && y>0 && y<=12)
 		cout<<"YYMM"<<"\n";
 	else if(x==0 && y<=12 && y>0)
 		cout<<"YYMM"<<"\n";
 	else if(x<=12 && x>0 && y==0)
 		cout<<"MMYY"<<"\n";
 	else if(x<=12 && x>0 && y>12)
 		cout<<"MMYY"<<"\n";
 	else
 		cout<<"NA"<<"\n";

}

Measured memory_bytes: 7296
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
ll k;
//ld ;
string s;
// char c;

int main() {
  cin >> s;
  bool flg = true;
  if((s.length()%2)!=0){
    flg = false;
  }else{
    for(ll i=0; i<s.length()/2; i++){
      if(s[2*i]!='h' || s[2*i+1]!='i'){
        flg = false;
      }
    }
  }
  yorn(flg);
  return 0;
}

Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : a : b : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    (k, l) = n `divMod` (a + b)
    m = min l a
  print $ a * k + m

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
N, K = map(int, input().split())
p = list(map(int, input().split()))
rui = [0]
for tmp in p:
    tmp = (tmp + 1) / 2
    rui.append(tmp + rui[-1])

ans = 0
for i in range(0, N-K+1):
    ans = max(ans, rui[i+K] - rui[i])
print(ans)

Measured memory_bytes: 25060
#include<iostream>
//#include <string>
using namespace std;
int main() {
    string S;
    cin >> S;
    int min=999;
    for (int i=0; i<S.length()-2; i++) {
        string str = S.substr(i,3);
        int num = stoi(str);
        int diff = abs(753 - num);
        if (min>diff) min=diff;
    }
    cout << min << endl;
    return 0;
}

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

int n,dep[100009],dim[100009],nxt,cnt;
vector<int>v[100009];

void dfs(int d,int n){
    dep[d]=n;
    while(v[n].size()<dim[n]){
        cin>>nxt;
        if(nxt<0){
            int x=dep[d+nxt];
            v[x].push_back(n);
            v[n].push_back(x);
        }
        else{
            cnt++;
            dim[cnt]=nxt;
            v[cnt].push_back(n);
            v[n].push_back(cnt);
            dfs(d+1,cnt);
        }
    }
}

int main(){
    int T;
    cin>>T;
    while(T--){cnt=0;
        r(i,100009)v[i].clear();
        memset(dim,-1,sizeof(dim));
        memset(dep,-1,sizeof(dep));
        cin>>dim[0];
        dfs(0,0);
        cin>>nxt;
        cnt++;
        r(i,cnt){
            cout<<i+1;
            sort(v[i].begin(),v[i].end());
            r(j,v[i].size())cout<<' '<<v[i][j]+1;
            cout<<endl;
        }
    }
}


Measured memory_bytes: 6220
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

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

	long long int a, b, c; cin >> a >> b >> c;
	if (a % 2 && b % 2 && c % 2) {
		cout << min(a, min(b, c)) * (a + b + c - max(a, max(b, c)) - min(a, min(b, c))) << endl;
	} else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
ary=$stdin.readlines
od=Array.new
ev=Array.new
n = ary[0].to_i
array=ary[1].split.map!(&:to_i)
p=0
while p<n
  od.push(array[p]) if p%2==0
  ev.push(array[p]) if p%2==1
  p+=1
end

  sd_n_ns_od = od.group_by{|i| i}.sort_by{|k,v| v.size}
  sd_n_ns_ev = ev.group_by{|i| i}.sort_by{|k,v| v.size}



if sd_n_ns_od.size == 1 && sd_n_ns_ev.size == 1
  if sd_n_ns_od.last.first == sd_n_ns_ev.last.first
    answer = n/2
  else
    answer= 0
  end
else
most_n_od = sd_n_ns_od.last.first
most_n_ev = sd_n_ns_ev.reject{|k,v| k == most_n_od}.last.first
answer1=0
answer1+=od.reject{|i| i==most_n_od}.size
answer1+=ev.reject{|i| i==most_n_ev}.size

most_n_ev = sd_n_ns_ev.last.first
most_n_od = sd_n_ns_od.reject{|k,v| k== most_n_ev}.last.first
answer2=0
answer2+=ev.reject{|i| i==most_n_ev}.size
answer2+=od.reject{|i| i==most_n_od}.size

 answer = (answer1 <= answer2)?  (answer1):(answer2)

 if  sd_n_ns_od.size == 1
   answer=answer1
 end

 if  sd_n_ns_ev.size == 1
   answer=answer2
 end
 end

 if  sd_n_ns_od.size > 1  && sd_n_ns_ev.size > 1
     if sd_n_ns_od.last.last.size == sd_n_ns_od[-2].last.size || sd_n_ns_ev.last.last.size == sd_n_ns_ev[-2].last.size
       answer=0
     answer+=od.reject{|i| i == sd_n_ns_od.last.first}.size
     answer+=ev.reject{|i| i == sd_n_ns_ev.last.first}.size
    end
   end

puts answer


Measured memory_bytes: 26508
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

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

	int t = x/100;

	cout << !(t*5 < x%100 or x > 1000000 * 105) << endl;


}

Measured memory_bytes: 256
A = ['dream', 'dreamer', 'erase', 'eraser']

for i in range(len(A)):
    A[i] = A[i][::-1]

s = input()[::-1]
i = 0
while True:
    f = True
    for a in A:
        if len(a) > len(s) - i:
            continue
        if s[i:i+len(a)] == a:
            i += len(a)
            f = False
            break
    else:
        if i == len(s):
            print('YES')
            exit()
        if f == True:
            print('NO')
            exit()


print('YES')

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

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    int ans=a.at(0);
    for(int i=1;i<n;i++){
        ans=gcd(ans,a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3792
import java.util.Scanner;

public class Main {


    private static int pow(int base,int os) {
        if(os == 0)
            return 1;
        int temp = pow(base, os/2);
        if (os % 2 == 0)
            return temp * temp;
        else
            return (base * temp * temp);
    }

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int ans = 0;
        for(int i=1;i<=x;++i) {
            for (int j = 2; j <= x; ++j) {
                int num = pow(i, j);
                if (num > x)
                    break;
                ans = Math.max(ans, pow(i, j));
            }
        }
        System.out.println(x==1?1:ans);

    }
}


Measured memory_bytes: 21844
/*alurquiza*/
//Z:Frog
#include <bits/stdc++.h>

using namespace std;

vector<long long> M,N;

bool bad(int r1,int r2,int r3){
    long long m1 = M[r1],n1 = N[r1];
    long long m2 = M[r2],n2 = N[r2];
    long long m3 = M[r3],n3 = N[r3];

    ///true si la x en la que se intersectan la recta 1 y 3 es menor que la x donde se intersectan r1 y r2
    return (n3 - n1) * (m1 - m2) <= (n2 - n1) * (m1 - m3);
}

void add(long long m,long long n){
    M.push_back(m);
    N.push_back(n);

    while(M.size() >= 3 && bad(M.size() - 3,M.size() - 2,M.size() - 1)){
        M.erase(M.end() - 2);
        N.erase(N.end() - 2);
    }
}
//puntero a la mejor soulcion hasta ahora
int p = 0;

long long query(long long x){
    p = min(p,(int)M.size() - 1);

    while(p + 1 < M.size() && M[p] * x + N[p] > M[p + 1] * x + N[p + 1])
        p++;

    return M[p] * x + N[p];
}

long long pot(long long b){
    return 1LL * b * b;
}

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

//    freopen(".in","r",stdin);
//    freopen(".out","w",stdout);

    int N;
    long long C;
    cin >> N >> C;

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

    long long sol = 0;
    add(-2LL * A[1],sol + pot(A[1]));
    for(int i = 2;i <= N;i++){
        sol = query(A[i]) + pot(A[i]) + C;
        add(-2LL * A[i],sol + pot(A[i]));
    }

    cout << sol << '\n';

    return 0;
}


Measured memory_bytes: 5220
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = sum(B)
for i,(a,b) in enumerate(zip(A,A[1:])):
    if b-a == 1:
        ans += C[a-1]
print(ans)

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

int main(){
  int N;
  int A[200];
  cin >> N;
  for (int i=0; i<N; i++){
    cin >> A[i];
  }
  int min=A[0], max=A[0];
  for (int i=0; i<N; i++){
    if (A[i]<min){
      min=A[i];
    }
    else if (A[i]>max){
      max=A[i];
    }
  }
  cout << max-min << endl;
}


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

int main(){
    int a, b, c, t;
    cin >> a >> b >>c;
    
    if (a > b) { t = a; a = b; b = t; }
    if (b > c) { t = b; b = c; c = t; }
    if (a > b) { t = a; a = b; b = t; }
    
    cout << a << " " << b << " " << c << endl;
    
    return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long mod = 2019;
		var h = new HashSet<long>();
		for(long x=L;x<=Math.Min(R,L+2019);x++){
			for(long y=x+1;y<=Math.Min(R,x+1+2019);y++){
				h.Add((x * y) % mod);
			}
		}
		var l = h.ToList();
		Console.WriteLine(l.Min());
		
	}
	long L, R;
	public Sol(){
		var d = ria();
		L = d[0]; R = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13536
N = int(input())
S = str(input())
ans = []
lst = ['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']

for i in range(len(S)):
    tmp = lst.index(S[i])
    tmp += N
    if tmp > 25:
        tmp -= 26
    ans.append(lst[tmp])
print(''.join(ans))


Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
using ll=long long;

const int MAX_N=100000;

struct Process{
	string name;
	int time;
};

struct Queue{
	Process p[MAX_N];
	int f=0,b=0;
	
	void emplace(Process x){
		p[b++]=x;
		b%=MAX_N;
	}
	
	Process front(){
		if(empty()) abort();
		return p[f];
	}
	
	void pop(){
		if(empty()) abort();
		p[f++]=Process();
		f%=MAX_N;
	}
	
	bool empty(){
		return f==b;
	}
};

int main(){
	int n,q;
	cin>>n>>q;
	Queue que;
	for(int i=0;i<n;++i){
		Process prs;
		cin>>prs.name>>prs.time;
		que.emplace(prs);
	}
	
	ll res=0;
	while(!que.empty()){
		Process prs=que.front(); que.pop();
		res+=min(prs.time,q);
		prs.time-=min(prs.time,q);
		if(prs.time==0){
			cout<<prs.name<<" "<<res<<endl;
		}else{
			que.emplace(prs);
		}
	}
}



Measured memory_bytes: 6972
# -*- coding: utf-8 -*-

import math

def main():
     x = int(input())
     # x は 正の整数
     # ans = a^5 - b^5 = x となる a, b

     num_list = []
     len_num_list = 0

     a = 0
     end = False
     while(not end):
          num_list.append(pow(a, 5))
          len_num_list += 1

          # print(a)
          # print(num_list)

          for i in range(len_num_list):
               for j in range(i, len_num_list):
                    i_5div = num_list[i]
                    j_5div = num_list[j]

                    if i_5div - j_5div == x:
                         print('{} {}'.format(i, j))
                         end = True
                         break
                    if j_5div - i_5div == x:
                         print('{} {}'.format(j, i))
                         end = True
                         break
                    if i_5div + j_5div == x:
                         print('{} {}'.format(i, j * (-1)))
                         end = True
                         break
                    if j_5div + i_5div == x:
                         print('{} {}'.format(j, i * (-1)))
                         end = True
                         break

          a += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 9232
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
          
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int b = 0;
    string a;
    cin >> a;
    for ( int i = (int)a.length() - 1 ; i >= 0 ; i-- ) {
        if ( a[i] == 'Z' ) {
            b = i;
            break;
        }
    }
    for ( int i = 0 ; i < a.length() ; i++ ) {
        if ( a[i] == 'A' ) {
            b -= i;
            break;
        }
    }
    cout << b + 1;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    
    int x;
    cin >> x;
    int a = x/500 * 1000;
    x %= 500;
    int b = x/5 * 5;
    cout << a + b << endl;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
//ll MOD = 1000000007;
ll MOD = 998244353;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  ll n; cin >> n;
  //先頭と末尾に注目する
  //B〇〇は,〇〇Aの後ろについた方がいい
  //B〇〇Aは上の足りない方につける
  deque<string> a,b,c,d;
  ll ans = 0;
  rep(i,n){
      string t; cin >> t;
      int m = t.size();
      if(t[0] == 'B' && t.back() == 'A')d.emplace_back(t);
      else if(t[0] == 'B')b.emplace_back(t);
      else if(t.back() == 'A')a.emplace_back(t);
      else c.emplace_back(t);
      rep(j,m-1)if(t[j] == 'A' && t[j+1] == 'B')ans++;
  } 
  ll as = a.size();
  ll bs = b.size();
  ll ds = d.size();
  if(as+bs == 0)ans+=max(0LL,ds-1);
  else ans+= ds+min(as,bs);
  out(ans);
}


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

using namespace std;
const int maxn=1e5+5;
int n,m,t,p[maxn],dis[maxn],vis[maxn],pre[maxn];
int a,b,c;
struct edge {
	int nxt,to,dis;
} e[maxn*4];
int read() {
	char ch = getchar();
	int x = 0, f = 1;
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + ch - 48, ch = getchar();
	return x * f;
}
void add(int from,int to,int dis) {
	e[t].to=to,e[t].dis=dis,e[t].nxt=p[from],p[from]=t++;
}
void spfa() {
	for(int i=1; i<=n; i++)
		dis[i]=2e9;
	deque<int> q;
	q.push_back(1),vis[1]=1,dis[1]=0;
	while(!q.empty()) {
		int now=q.front();
		q.pop_front(),vis[now]=0;
		for(int i=p[now]; i!=-1; i=e[i].nxt) {
			int to=e[i].to;
			if(dis[to]>dis[now]+e[i].dis) {
				dis[to]=dis[now]+e[i].dis;
				pre[to]=now;
				if(!vis[to]) {
					vis[to]=1;
					if(q.empty()||dis[to]>dis[q.front()]) q.push_back(to);
					else q.push_front(to);
				}
			}
		}
	}
}
int main() {
	memset(p,-1,sizeof(p));
	n=read(),m=read();
	for(int i=1; i<=m; i++)
		a=read(),b=read(),add(a,b,1),add(b,a,1);
	spfa();
	vector<int> ans;
	for(int i=2; i<=n; i++) {
		if(dis[i]==2e9) {
			cout<<"No";
			return 0;
		}
		ans.push_back(pre[i]);
	}
	cout<<"Yes"<<endl;
	for(int i=0; i<ans.size(); i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 10408
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	ll X, K, D;
	cin >> X >> K >> D;
	if( X < 0){
		X = -X;
	}
	
	if(K >= X/D){
		if( (K - (X / D)) % 2 == 0){
			cout << X - (X / D)*D << endl;
		}else{
			cout << D - (X - (X / D)*D) << endl;
		}
	}else{
		cout << X - K*D << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int p = in.nextInt();
        int result = (int)Math.floor((a*3+p)/2.0);
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
bool cmp(string a,string b){
	return a<=b;;
}
int main(){
	string cc[200010];
	int n,i,j,k,l,cnt=1;
	cin>>n;
	for(i=1;i<=n;i++)cin>>cc[i];
	sort(cc+1,cc+1+n);
	for(i=2;i<=n;i++){
		if(cc[i]!=cc[i-1])cnt++;
	}
	cout<<cnt;
	getchar();getchar();
} 

Measured memory_bytes: 9888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A, B, C, X, Y;
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		X = sc.nextInt();
		Y = sc.nextInt();
		long ans = Long.MAX_VALUE;
		for (int k = 0; k <= 100000; k++) {
			int res = 2 * C * k + Math.max(X - k, 0) * A + Math.max(Y - k, 0) * B;
			ans = Math.min(ans, res);
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int t = sc.nextInt();
		int s = sc.nextInt();

		if(d <= t * s) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();

	}

}


Measured memory_bytes: 35800
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> vec(n);
    rep(i, n){
        ll num;
        cin >> num;
        vec[i] = num-1;
    } 
    vector<ll> flag(n, -1);
    vector<ll> track;
    ll cnt = 0;
    flag[0] = 0;
    track.push_back(0);
    rep(i, n+1){
        cnt++;
        track.push_back(vec[track.back()]);
        if(flag[vec[track[track.size()-2]]] != -1){
            if(k <= cnt){
                cout << track[k]+1 << endl;
                return 0;
            }else{
                k -= flag[vec[track[track.size()-2]]];
                k %= (cnt-flag[vec[track[track.size()-2]]]);
                cout << track[flag[vec[track[track.size()-2]]]+k]+1 << endl;
                return 0;
            }
        }
        flag[vec[track[track.size()-2]]] = cnt;
    }
    return 0;
}

Measured memory_bytes: 8500
import java.util.Arrays;
import java.util.Scanner;

public class Main {


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

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] X = new int[M];
		for (int i = 0; i < M; i++) {
			X[i] = sc.nextInt();
		}
		Arrays.sort(X);

		int[] between = new int[M - 1];
		for (int i = 1; i < X.length; i++) {
			between[i - 1] = Math.abs(X[i - 1] - X[i]);
		}
		Arrays.sort(between);

		int ans = 0;
		for (int i = 0; i < (between.length - N + 1); i++) {
			ans += between[i];
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 49868
import sys
input = sys.stdin.readline
#-------------------------------------

n,l = map(int,input().split())

ans = 0
minimum = 999
minimum_v = 0
for i in range(n):
        ans += i+l
        if abs(i+l) < minimum:
                minimum = abs(i+l)
                minimum_v = i+l

ans -= minimum_v
print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int n, m, q, a[53], b[53], c[53], d[53];

ll dfs(int* k, int p, int cn) {
	int i;
	ll res;
	if (p == n) {
		res = 0ll;
		for (i = 0; i < q; i++) {
			if (k[b[i] - 1] - k[a[i] - 1] == c[i]) {
				res += d[i];
			}
		}
		return res;
	}
	res = 0ll;
	for (i = cn; i <= m; i++) {
		k[p] = i;
		res = max(res, dfs(k, p + 1, i));
	}
	return res;
}

int main(void) {
	int i, k[13] = {};

	scanf("%d%d%d", &n, &m, &q);
	for (i = 0; i < q; i++) {
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
	}

	printf("%lld\n", dfs(k, 0, 1));

	return 0;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    intl k[n];
    vector<vector<intl> > v(n);
    rep(i,n){
        cin >> k[i];
        rep(j,k[i]){
            intl a;
            cin >> a;
            v[i].pb(a);
        }    
    }
    intl b[m];
    m0(b);
    rep(i,n){
        for(auto j: v[i])b[j - 1]++;
    }
    intl ans = 0;
    rep(i,m)if(b[i] == n)ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val s = readLine()!!.toSet()

    println(when {
        s.size == 4 -> "Yes"
        s.size == 2 && s.containsAll(listOf('N', 'S')) -> "Yes"
        s.size == 2 && s.containsAll(listOf('E', 'W')) -> "Yes"
        else -> "No"
    })
}

Measured memory_bytes: 38048
N=int(input())
S=input()
a=[]
half=int(N/2)
count=0
if N%2==1:
  print("No")
else:
  for i in range(half):
    if S[i]==S[i+half]:
      count+=1
  
  if count==half:
    print("Yes")
  else:
    print("No")


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

int countDivisibles(int A, int B, int M) 
{  
	int counter = 0; 
	for (int i = A; i <= B; i++) 
		if (i % M == 0) 
			counter++; 

	return counter; 
} 


int main() 
{ 
	 int A, B, M;
	 cin >> A >> B >> M;
	cout << countDivisibles(A, B, M) << endl; 
	return 0; 
} 


Measured memory_bytes: 3628
import java.util.Scanner;

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

        int p = stdIn.nextInt();
        int q = stdIn.nextInt();
        int r = stdIn.nextInt();

        int max = p;
        if (max < q)
            max = q;
        if (max < r)
            max = r;
        System.out.println(p + q + r - max);
    }
}

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

#define int long long

int gcd(int a, int b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

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

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

    int R[N + 1], L[N + 1];
    R[0] = L[0] = 0;

    for(int i = 0; i < N; ++i){
        R[i + 1] = gcd(R[i], A[i]);
        L[i + 1] = gcd(L[i], A[N - 1 - i]);
    }

    int ans = 0;

    for(int i = 0; i < N; ++i){
        ans = max(ans, gcd(R[i], L[N - i - 1]));
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

int main()
{
	int n, k, num, ans, sam;
	
	while(cin >> n >> k)
	{
		if(!n && !k) break;
		queue<int> que;
		ans = 0;
		sam = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> num;
			que.push(num);
			sam += num;
			if(que.size() == k )
			{
				if(ans < sam)
				{
					ans = sam;
				}
				sam -= que.front();
				que.pop();
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1348
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <math.h>
#include <deque>
#include <queue>
#include <map>
#include <iterator>
#include <set>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const int mxN = 203;
ll dis[mxN][mxN];
const ll INF = 1e18;

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

	int n, m, r;
	cin >> n >> m >> r;
	vector<ll> R(r);
	for (int i = 0; i < r; i++) {
		cin >> R[i];
		R[i]--;
	}

	sort(R.begin(), R.end());

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) dis[i][j] = 0;
			else dis[i][j] = INF;
		}
	}
	for (int i = 0; i < m; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		dis[a][b] = c;
		dis[b][a] = c;
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}

	ll ans = INF;

	do {
		ll tmp = 0;
		for (int i = 0; i < r - 1; i++) {
			tmp += dis[R[i]][R[i + 1]];
		}
		chmin(ans, tmp);
	} while (next_permutation(R.begin(), R.end()));

	cout << ans << endl;
}

Measured memory_bytes: 640
#include"iostream"
#include"vector"
#include"string"
using namespace std;

int main()
{
	int n, m;
	vector<string> s(110), t(110);
	cin >> n;
	for (int i = 0; i < n; i++)cin >> s[i];
	cin >> m;
	for (int i = 0; i < m; i++)cin >> t[i];
	int ans, max = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (s[i] == s[j])ans++;
		}
		for (int j = 0; j < m; j++)
		{
			if (s[i] == t[j])ans--;
		}
		if (max < ans)max = ans;
		ans = 0;
	}
	cout << max << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    char[] zeroOne = line.toCharArray();
    int count = 0;
    for (int i = 0; i < 3; i++) {
      if (zeroOne[i] == '1') {
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>

using namespace std;

const int MAXN = 2005;
const int INF = 1e9;

int n;
char color[MAXN << 1];
int a[MAXN << 1];
int posb[MAXN], posw[MAXN];
int sumb[MAXN << 1][MAXN], sumw[MAXN << 1][MAXN];
int dp[MAXN][MAXN];

int main()
{
    cin >> n;
    for (int i = 1; i <= 2 * n; ++i) {
        cin >> color[i] >> a[i];
        (color[i] == 'B' ? posb[a[i]] : posw[a[i]]) = i;
    }
    for (int i = 1; i <= 2 * n; ++i) {
        for (int j = 1; j < i; ++j) {
            (color[j] == 'B' ? sumb[i][a[j]] : sumw[i][a[j]]) += 1;
        }
    }
    for (int i = 1; i <= 2 * n; ++i) {
        for (int j = 2; j <= n; ++j) {
            sumb[i][j] += sumb[i][j - 1];
            sumw[i][j] += sumw[i][j - 1];
        }
    }
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) dp[i][j] = INF;
    }
    dp[0][0] = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (i) dp[i][j] = min(dp[i][j], dp[i - 1][j] + posb[i] - sumb[posb[i]][i - 1] - sumw[posb[i]][j] - 1);
            if (j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + posw[j] - sumb[posw[j]][i] - sumw[posw[j]][j - 1] - 1);
        }
    }
    cout << dp[n][n] << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; i++) cin >> L[i];
  sort(L.begin(), L.end());
  
  int ans = 0;
  for(int a=0; a<N; a++){
    for(int b=a+1; b<N; b++){
      int c = lower_bound(L.begin(), L.end(), L[a]+L[b]) - L.begin();
      ans += max(c-(b+1),0);
    }
  }
  cout << ans;
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1000000 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}


void work()
{
    int n, m;
    map<int, int> mp;

    cin >>n >>m;
    int ans = 0, ac = 0;
    for(int i = 0; i < m; i++)
    {
        int id;
        string res;
        cin >>id >>res;

        if(res == "AC")
        {
            if(mp[id] != -1)
            {
                ac++;
                ans += mp[id];
                mp[id] = -1;
            }
        }
        else
        {
            if(mp[id] != -1) mp[id]++;
        }
    }
    cout <<ac <<" " <<ans <<endl;
}


int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 4992
# scipyなし
n, m = map(int, input().split())

st = [list(map(int, input().split())) for _ in range(n)]
cp = [list(map(int, input().split())) for _ in range(m)]

for s in st:
    mandist = float('inf')
    for i, c in enumerate(cp):
        d = abs(s[0] - c[0]) + abs(s[1] - c[1])
        if d < mandist:
            ans_check = i + 1
            mandist = d
    print(ans_check)

Measured memory_bytes: 9080
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
namespace mp = boost::multiprecision;
using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

queue<ll> s;
set<ll> st;
vector<ll>v;
vector<ll>v2;

void ju(ll p,ll q){
	if(v2[q]==0){
		s.push(q);
		v[q]=v[p]+1;
		v2[q]=1;
	}
}

int main(){
	ll h,w;
	cin>>h>>w;
  v.assign(w*h,0);
	v2.assign(w*h,0);
	char c;
	for(ll i=0;i<h;i++){
	  for(ll j=0;j<w;j++){
	    cin>>c;
			if(c=='#'){
				s.push(i*w+j);
				v2[i*w+j]=1;
			}
	  }
	}
	for(;!s.empty();s.pop()){
		ll x=s.front();
		if(!(x<w)){
			ju(x,x-w);
		}
		if(!(x%w==0)){
			ju(x,x-1);
		}
		if(!(x%w==w-1)){
			ju(x,x+1);
		}
		if(!(x>=w*(h-1))){
			ju(x,x+w);
		}
	}
	ll ans=0;
	for(ll i=0;i<h*w;i++){
	  ans=max(ans,v[i]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 23808
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
llfor;ll mod=1000000007;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/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;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n;
 cin>>n;
 ll x,y;
 ll ans=0;
 vector<pair<ll,ll>>pair(n);
 rep(i,0,n){
  cin>>x>>y;
  pair[i]={x+y,x-y};
 }
 sort(all(pair));
 ll cmp=-1000000001;
 rep(i,0,n){
  if(cmp<=pair[i].second){
   ans++;
   cmp=pair[i].first;
  }
 }
 pr(ans);
return 0;}

Measured memory_bytes: 4840
a = b = c = ans = 0
for _ in range(int(input())):
    s = input()
    ans += s.count("AB")
    a += s[-1] == "A"
    b += s[0] == "B"
    c += s[-1] + s[0] == "AB"
print(ans+min(a, b)-(0 < a == b == c))


Measured memory_bytes: 9192
import sys


N = int(input())
edge = []
for s in sys.stdin.readlines():
    u, v = map(int, s.split())
    if u > v:
        u, v = v, u
    edge.append((u, v))

ans = 0
for i in range(1, N + 1):
    ans += i * (N - i + 1)

for u, v in edge:
    ans -= u * (N - v + 1)

print(ans)


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n;
    cin >> n;

    vi a(n+1, 0);
    int tmp;
    rep(i,0,n-1){
        cin >> tmp;
        ++a[tmp];
    }

    rep(i,1,n+1) cout << a[i] << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 4016
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <stdlib.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define For(I,N) for(int I=0;I<N;I++)
typedef unsigned long long ull;
using namespace std;

int main()
{
//	freopen("input.txt","r",stdin);
	string c;
	cin>>c;
	cout<<c.substr(0,c.size()-8);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(i64, R, G, B, N);
    i64 ans = 0;

    rep(r, 0, N + 1) rep(g, 0, N + 1) {
        const i64 sum = R * r + G * g;
        const i64 rem = N - sum;
        if (rem >= 0 && rem % B == 0) {
            ++ans;
        }
    }

    print(ans);
    return 0;
}


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

typedef long long int LL;
typedef unsigned long long uLL;
const int inf = (int)1e9;
const LL INF = (LL)2e18;
const int N = 100005;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos( -1.0 );
#define all( V )     V.begin(), V.end()
#define Unique( a )  sort( all(a) ), a.erase( unique( all(a) ), a.end() )

template < typename T > inline T Power ( T b , T p ) {
    T res = 1 , x = b;
    while( p ) {
        if( p&1 ) res = (res*x);
        x = (x*x); p >>=1;
    } return res;
}

vector < int > V;

void calc( ) {
    for( int i = 2; i <= 1000; i++ ) {
        for( int j = 2; j <= 10; j++ ) {
            LL val = Power( i , j );
            if( val > 0 && val <= 1000 ) V.push_back( val );
            else break;
        }
    }
}
int main( int argc, char const *argv[] ) {

    //for( int i = 2; i <= 10; i++ ) cout << Power( 2 , i ) << endl;

    int n;
    cin >> n;
    if( n == 1 ) return cout << 1 << endl,0;
    calc( );
    Unique( V );
    //or( auto x : V ) cout << x << " ";
    int pos = upper_bound( V.begin() , V.end() , n )-V.begin();
    cout << V[--pos] << endl;
    return 0;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b-1);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a;
    string b;
    cin>>a>>b;
    ll res=0;
    res+=(b[0]-'0')*a*100;
    res+=(b[2]-'0')*a*10;
    res+=(b[3]-'0')*a;
    cout<<res/100;
    return 0;
}


Measured memory_bytes: 3648