akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
void cppio(){ ios_base::sync_with_stdio(0); cin.tie(0); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()

int n;
int a[200'010];
ll k;

vector<int> wh[200'010];
int kth[200'010];

pp nxt[200'010];

int main()
{
	cppio(); cin >> n >> k;
	rrep(i, n) {
		cin >> a[i];
		kth[i] = wh[a[i]].size();
		wh[a[i]].pb(i);
	}

	rrep(i, n) {
		int np = (i == wh[a[i]].back() ? n + wh[a[i]][0] : wh[a[i]][kth[i]+1]);
		nxt[i] = {np%n + 1, np/n};
		if(0) printf("nxt[%d] = %d %d\n",
		i, nxt[i].x, nxt[i].y);
	}

	static int vis[200'010];
	static int dist[200'010];
	int p = 1, d = 0;
	for(;;) {
		if(d + nxt[p].y >= k) break;

		vis[p] = 1;
		dist[p] = d;

		d += nxt[p].y;
		p = nxt[p].x;

		if(vis[p]) {
			break;
		}
	}

	auto job = [&](int p, int cnt) {
		vector<int> ans;
		static bitset<200'010> has;

		if(cnt < 0) return;

		for(int i=p; i<=n; ++i) {
			int v = a[i];
			if(has[v]) {
				while(ans.back() != v) {
					has[ans.back()] = 0;
					ans.pop_back();
				}
				ans.pop_back(); has[v] = 0;
			} else {
				ans.pb(v);
				has[v] = 1;
			}
		}

		for(;cnt--;) {
			for(int i=1; i<=n; ++i) {
				int v = a[i];
				if(has[v]) {
					while(ans.back() != v) {
						has[ans.back()] = 0;
						ans.pop_back();
					}
					ans.pop_back(); has[v] = 0;
				} else {
					ans.pb(v);
					has[v] = 1;
				}
			}
		}

		for(int x:ans) cout << x << ' ';
		cout << endl;
	};

	if(!vis[p]) {
		job(p, k - 1 - d);
	} else {
		ll D = d - dist[p];
		ll nokori = k - dist[p];
		nokori -= D * (max(0ll, (nokori - D + 1)) / D);
		while(nokori) {
			if(nokori <= nxt[p].y) break;
			nokori -= nxt[p].y;
			p = nxt[p].x;
		}

		job(p, nokori - 1);
	}

	return 0;
}


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

int main()
{
		long int n, i;
		cin >> n;
		long int a[n];
		for (i=0; i<n; i++) cin >> a[i];
		long int min=a[0], max=a[0], sum=0;

		for (i=0; i<n; i++) {
				if (min>a[i]) min = a[i];
				if (max<a[i]) max = a[i];
				sum+=a[i];
		}
		cout << min << " " << max << " " << sum << "\n";
}

Measured memory_bytes: 3160
def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            tmp = A[i]
            A[i] = A[j]
            A[j] = tmp
    tmp = A[r]
    A[r] = A[i+1]
    A[i+1] = tmp
    return i+1


n = int(input())
A = [int(_) for _ in input().split()]
idx = partition(A, 0, n-1)

print(" ".join(map(str, A[:idx])) + ' [' + str(A[idx]) + '] ' + " ".join(map(str, A[idx+1:])))


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

int main() {
    long N;
    cin >> N;
    string S[N];
    char str[10];
    for(int i = 0; i < N; i++)
    {
        cin >> S[i];
        for(int j = 0;j < 10;j++)
        {
            str[j] = S[i][j];
        }
        sort(str, str + 10);
        S[i] = str;
    }
    sort(S, S + N);
    long count = 0;
    long equal_count = 0;
    for(long i = 0;i < N;i++)
    {
        if(S[i] == S[i + 1])
        {
            equal_count++;
            count += equal_count;
        }
        else equal_count = 0;        
    }
    cout << count << endl;
}


Measured memory_bytes: 7296
#include<stdio.h>
int main(void)
{
    int n,l[10],i,s=0,tmp;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&l[i]);
    for(i=1;i<n;i++)
        if(l[0]<l[i]){
            tmp=l[0]; l[0]=l[i]; l[i]=tmp;
        }
    for(i=1;i<n;i++)
        s+=l[i];
    if(l[0]<s) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

const int INF = 1 << 28;

int main() {
	int n, m;
	
	while ( cin >> n >> m, n | m ) {
		VVI L( n, VI( n, INF ) ),
			S( n, VI( n, INF ) );
		
		for ( int i = 0; i < m; ++i ) {
			int x, y, t;
			char s;
			cin >> x >> y >> t >> s;
			
			switch ( s ) {
			case 'L':
				L[x - 1][y - 1] = L[y - 1][x - 1] = min( t, L[x - 1][y - 1] );
				break;
			case 'S':
				S[x - 1][y - 1] = S[y - 1][x - 1] = min( t, S[x - 1][y - 1] );
				break;
			}
		}
		
		int r;
		cin >> r;
		
		VI Z( r, 0 );
		
		for ( int i = 0; i < r; ++i ) {
			cin >> Z[i];
			--Z[i];
		}

		for ( int i = 0; i < n; ++i ) {
			L[i][i] = S[i][i] = 0;
		}

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

		VVI d( r, VI( n, INF ) );
		d[0][Z[0]] = 0;
		for ( int i = 0; i + 1 < r; ++i ) {
			int from = Z[i], to = Z[i + 1];
			//d[i + 1][to] = min( d[i + 1][to], d[i][from] + S[from][to] );
			for ( int j = 0; j < n; ++j ) {
				d[i + 1][to] = min( d[i + 1][to], d[i][j] + L[from][j] + S[j][to] );
				d[i + 1][j] = min( d[i + 1][j], d[i][j] + L[from][to] );
				d[i + 1][j] = min( d[i + 1][j], d[i][from] + S[from][j] + L[j][to] );
				for ( int k = 0; k < n; ++k ) {
					d[i + 1][k] = min( d[i + 1][k], d[i][j] + L[from][j] + S[j][k] + L[k][to] );
				}
			}
		}

		int ans = INF;
		for ( int i = 0; i < n; ++i ) {
			ans = min( ans, d[r - 1][i] );
		}

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

Measured memory_bytes: 2324
#include <iostream>
#include <algorithm>

using namespace std;


int main(){
    int n,k,sum = 0;
    int l[500];
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> l[i];

    sort(l,l + n, greater<int>());
    for(int i = 0; i < k; i++){
        sum += l[i];
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a,b;
	int c,d,e,f;
	int cou=0;
	cin>>a>>b;
	for (int i=4;i<=a;i++){
		for (int j=22;j<=b;j++){
			c=j/10;
			d=j%10;
			if (c>=2&&d>=2&&(c*d)==i) cou++;
		}
	}
	cout<<cou<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
s=[int(input()) for i in range(n)]
ten=[]
p=[]
for x in s:
    if x%10==0:ten.append(x)
    else:p.append(x)
ten=sum(ten)
if len(p)==0:print(0)
else:
    p=sorted(p)
    Sum=sum(p)
    print(Sum+ten-p[0] if Sum%10==0 else Sum+ten)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
    ll n, m;
    cin >> n >> m;
    if (n > m) swap(n, m);

    if (n == 1 && m == 1) cout << 1 << endl;
    else if (n == 1) cout << m - 2 << endl;
    else cout << (n - 2) * (m - 2) << endl;
    
    return 0;
}


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

int main(){
  int N;
  cin>>N;
  
  vector<int> mochi(N);
  for(int i=0;i<N;i++){
    cin>>mochi.at(i);
  }
  
  sort(mochi.begin(),mochi.end());
  
  int dan=1;
  for(int j=1;j<N;j++){
    if(mochi.at(j-1)<mochi.at(j)) dan+=1;
  }
  cout<<dan<<endl;
}

Measured memory_bytes: 256
use v5.18;
use warnings;
sub read_line { chomp(my $str = <STDIN>); $str }
sub splited_read_line { split / /, read_line }
use List::Util qw( min sum );

my $n = read_line;

my $min = $n;
for (1 .. $n - 1) {
  my ($a, $b) = ($n - $_, $_);
  my @a_nums = split //, $a;
  my @b_nums = split //, $b;
  $min = min( $min, sum( @a_nums, @b_nums ) );
}
say $min;


Measured memory_bytes: 768
#include <stdio.h>


int main (void){
 
 int a, b;
 char op;
 
 while(op != '?'){
 scanf("%d %c %d", &a, &op, &b);
 
 if(op == '+'){
     printf("%d\n", a + b);
 }else if(op == '-'){
     printf("%d\n", a - b);
 }else if(op == '*'){
     printf("%d\n", a * b);
 }else if(op == '/'){
     printf("%d\n", a / b);
 }else if(op == '?'){
     break;
 }
 }
 



 return 0;

}

Measured memory_bytes: 600
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" ");
    return os;
}

int N,M,A,B,C,T;
int S[55];

#define MCR mat const&
template<typename T>
struct mat {
    vector<vector<T>> dat;
    int height, width;
    mat(int height = 0, int width = 0): dat(height, vector<T>(width)), height(height), width(width){}
    vector<T> const & operator [] (int i) const { return dat[i]; };
    vector<T> & operator [] (int i){ return dat[i]; };
    mat & operator += (MCR v){ rep(i,height) rep(j,width) dat[i][j]+=v[i][j]; return *this; }
    mat & operator -= (MCR v){ rep(i,height) rep(j,width) dat[i][j]-=v[i][j]; return *this; }
    mat & operator *= (MCR b){
        mat res(height, b.width);
        rep(i,height) rep(k,b.height) rep(j,b.width) (res[i][j] += dat[i][k]*b[k][j]) %= M;
        return *this = res;
    }
    mat operator + (MCR v) const { return mat(*this) += v; }
    mat operator - (MCR v) const { return mat(*this) -= v; }
    mat operator * (MCR v) const { return mat(*this) *= v; }
    bool operator < (MCR v) const { return dat < v.dat; }
    mat exp(ll t) const { int n = height; mat e = *this, res = id(n); for(; t; e*=e, t>>=1) if(t&1) res *= e; return res; }
    mat trans() const { mat t(width, height); rep(i,width) rep(j,height) t[i][j] = dat[j][i]; return t; }
    static mat id (int n) {
        mat res(n,n);
        rep(i,n) res[i][i] = 1;
        return res;
    }
};

typedef mat<int> matrix;

int main(){
#ifdef LOCAL
    freopen("in","r", stdin);
#endif
    while(cin>>N>>M>>A>>B>>C>>T && N){
        matrix a(N,N), x(N,1);
        rep(i,N) cin >> x[i][0];
        rep(i,N){
            if(i!=0) a[i][i-1] = A;
            a[i][i] = B;
            if(i!=N-1) a[i][i+1] = C;
        }
        cout << (a.exp(T)*x).trans()[0] << endl;
    }
}

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

int main(){
  int A,B,K,num;
  cin >> A >> B >> K;
  
  for(int i=min(A,B);i>=1;i--){
    
    if(A%i==0 && B%i==0){
      num=i;
      K--;
    }
    
    if(K==0)
      break;
      
  }
  
  cout << num;
  return 0;
}

Measured memory_bytes: 256
import bisect

N = int(input())
lst =list(map(int, input().split()))
lst.sort()
ret = 0
for i in range(N):
    for j in range(i + 1, N):
        n = lst[i] + lst[j]
        idx = bisect.bisect_left(lst, n, j + 1, N)
        ret += max(0, idx - j - 1)
print(ret)

Measured memory_bytes: 3188
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;
//__int128

const int maxn = 2e5;
int dp[maxn][5];

signed main() {
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s;  
  cin >> s;
  int n = (int)s.size();
  for(int i = 1; i <= 4; ++i) {
    dp[i][i] = 1;
  }
  for(int i = 1; i <= n; ++i) {
    for(int j = 1; j < 5; ++j) {
      for(int k = 1; k < 5; ++k) {
        if(i - j >= 0 && i + k <= n && (j != k || s.substr(i - j, j) != s.substr(i, k))) {
          dp[i + k][k] = max(dp[i + k][k], dp[i][j] + 1);
        }
      }
    }
  }
  /*for(int i = 1; i <= n; ++i) {
    for(int j = 1; j <= 4; ++j) {
      cout << dp[i][j] << ' ';
    }
    cout << endl;
  }*/
  cout << *max_element(dp[n], dp[n] + 5) << endl;
  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int a, b; cin >> a >> b;
        int h, m; cin >> h >> m;
        double w = (h * 60 + m) / 2. - m * 6.;
        if (w < 0) w += 360;
        w = min(w, 360 - w);
        cout << fixed << setprecision(10) << sqrt(a * a + b * b - 2 * a * b * cos(w * M_PI / 180));
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int n;
int arr[200005];
int x;
vector<ii> v;

bool carry(int i){
	if(i<=0)return 0;
	if(!v.empty()&&v.back().first==i){
		if(v.back().second==x-1){
			v.pop_back();
			if(!carry(i-1))return 0;
		}else{
			v[SZ(v)-1].second++;
		}
	}else{
		v.push_back(mp(i,1));
	}
	return 1;
}

inline bool poss(){
	v.clear();
	for(int i=1;i<n;i++){
		if(arr[i]<=arr[i-1]){
			if(x==1)return 0;
			while(!v.empty()&&v.back().first>arr[i])v.pop_back();
			if(v.empty())v.pb(mp(arr[i],1));
			else{
				if(v.back().first!=arr[i])v.pb(mp(arr[i],1));
				else if(v.back().second<x-1)v[SZ(v)-1].second++;
				else{
					v.pop_back();
					if(!carry(arr[i]-1))return 0;
				}
			}
		}
	}
	return 1;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&arr[i]);
	int l=1,r=n;
	while(l<r){
		int mid=(l+r)/2;
		x=mid;
		if(poss())r=mid;
		else l=mid+1;
	}
	printf("%d",l);
}


Measured memory_bytes: 4576
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
	int K;
    double N, ans = 0, temp = 0;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		temp = 0;
		for (int j = i + 1; j < K; j = j * 2) {
			temp++;
		}
		ans += (1.0 / N) * pow((1.0 / 2.0), temp);
	}
	std::cout << std::fixed << std::setprecision(10) << ans << endl;

	return 0;
}


Measured memory_bytes: 256
def examC():
    N = I()
    S = SI()
    E = S.count("E"); W = N-E
    curW = 0; curE = 0
    ans = N-1
    for i in range(N):
        if S[i]=="W":
            curW +=1
        cur = N -1 - (W-curW) - curE
        if S[i]=="E":
            curE +=1
        ans = min(ans,cur)
#        print(cur)
    print(ans)
    return

def examD():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,ALPHABET
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]
ALPHABET = [chr(ord('A') + i) for i in range(26)]

if __name__ == '__main__':
    examC()


Measured memory_bytes: 41180
import java.util.*;
        import java.io.*;

class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)
    {
        FastReader s = new FastReader();
        String line = s.nextLine();
        int a = Integer.parseInt(line.charAt(0)+"");
        int b = Integer.parseInt(line.charAt(1)+"");
        int c = Integer.parseInt(line.charAt(2)+"");
        int d = Integer.parseInt(line.charAt(3)+"");

        if(a+b+c+d == 7)
        {
            System.out.println(a+"+"+b+"+"+c+"+"+d+"=7");
        }
        else if(a-b+c+d == 7)
        {
            System.out.println(a+"-"+b+"+"+c+"+"+d+"=7");
        }
        else if (a+b-c+d == 7)
        {
            System.out.println(a+"+"+b+"-"+c+"+"+d+"=7");
        }
        else if (a-b-c+d == 7)
        {
            System.out.println(a+"-"+b+"-"+c+"+"+d+"=7");
        }
        else if (a+b+c-d == 7 )
        {
            System.out.println(a+"+"+b+"+"+c+"-"+d+"=7");
        }
        else if (a-b+c-d == 7)
        {
            System.out.println(a+"-"+b+"+"+c+"-"+d+"=7");
        }
        else if (a+b-c-d == 7)
        {
            System.out.println(a+"+"+b+"-"+c+"-"+d+"=7");
        }
        else
        {
            System.out.println(a+"-"+b+"-"+c+"-"+d+"=7");
        }


    }
}

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

using namespace std;
typedef long long ll;

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

const int size = 200;
const int limit = 1000001;
int dp[limit], dp_odd[limit];
int tetra[size], odd[size];

int main(void){
    int size_odd = 0;
    for(int i=1; i<size+1; ++i) {
        ll t = i*(i+1)*(i+2)/6;
        tetra[i-1] = t;
        if(t%2==1) {odd[size_odd]=t; size_odd++;}
    }
    int inf = numeric_limits<int>::max();
    rep(i, limit) dp[i] = dp_odd[i] = inf;
    dp[0] = 0;
    dp_odd[0] = 0;
    rep(i, size) {
        for(int j=tetra[i]; j<limit; ++j)
            dp[j] = min(dp[j-tetra[i]]+1, dp[j]);
    }
    rep(i, size_odd) {
        for(int j=odd[i]; j<limit; ++j)
            dp_odd[j] = min(dp_odd[j-odd[i]]+1, dp_odd[j]);
    }

    int n;
    while(cin >> n && n) {
        cout << dp[n] << " ";
        cout << dp_odd[n] << endl;
    }
}



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

const int N = 200005;

int n, k;
int a[N];
int pre[N];

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }

  k = min(k, 42);

  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < n; ++j) pre[j] = 0;
    for (int j = 0; j < n; ++j) {
      ++pre[max(0, j - a[j])];
      --pre[min(n, j + a[j] + 1)];
    }

    int sum = 0;
    for (int j = 0; j < n; ++j) {
      a[j] = sum += pre[j];
    }
  }

  for (int i = 0; i < n; ++i) {
    printf("%d%c", a[i], " \n"[i == n-1]);
  }
  return 0;
}


Measured memory_bytes: 5372
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n;
	cin>>n;
	ll sum=0LL;
	ll k=n;
	while(k>0)
	{
		sum+=k%10;
		k=k/10;
	}
	if(n%sum==0)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

bool tri_in(double p0x, double p0y, double p1x, double p1y, double p2x, double p2y, double px, double py) {
	//(p0x, p0y),(p1x, p1y),(p2x, p2y)の三角形
	//(px, py)が判定したい点
	//辺上は入っている
	double Area = 0.5 * (-p1y * p2x + p0y * (-p1x + p2x) + p0x * (p1y - p2y) + p1x * p2y);
	double s = 1 / (2 * Area) * (p0y * p2x - p0x * p2y + (p2y - p0y) * px + (p0x - p2x) * py);
	double t = 1 / (2 * Area) * (p0x * p1y - p0y * p1x + (p0y - p1y) * px + (p1x - p0x) * py);

	if ((0 <= s)&&(s <= 1) && (0 <= t)&&(t <= 1) && (0 <= 1 - s - t)&&(1 - s - t <= 1)) {
		return true; //Inside Triangle
	}
	else {
		return false;
	}
}


int main() {
	
	double p0x, p0y, p1x, p1y, p2x, p2y, px, py;
	while (cin >> p0x >> p0y >> p1x >> p1y >> p2x >> p2y >> px >> py) {
		if (tri_in(p0x, p0y, p1x, p1y, p2x, p2y, px, py)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	
}


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

#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)

#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  int a=0,b=0,c=0;
  string A,B,C;
  string turn="a";

  cin>>A;
  cin>>B;
  cin>>C;

  while(1){
    if(turn=="a"){
      turn=A[a];
      a++;
      if(a>A.length()){
	cout<<"A"<<endl;
	return 0;
      }
    }else if(turn=="b"){
      turn=B[b];
      b++;
      if(b>B.length()){
	cout<<"B"<<endl;
	return 0;
      }
    }else{
      turn=C[c];
      c++;
      if(c>C.length()){
	cout<<"C"<<endl;
	return 0;
      }
    }
  }
  
  return 0;
}


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

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


	int answer = 0;
	
	// 横
	for (int j_down = 1; j_down <= N; j_down++) {
		
		int tmpSum = 0;


		// 1段目
		for (int k = 1; k <= j_down; k++) {
			tmpSum += a[1][k];
		}

		// 2段目 
		for (int k = j_down; k <= N; k++) {
			tmpSum += a[2][k];
		}

		answer = max(answer, tmpSum);
	}
	
	cout << answer << endl;
		
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		double A = sc.nextInt();
		double B = sc.nextInt();
		double C = sc.nextInt();
		double D = sc.nextInt();
		double E = sc.nextInt();
		double F = sc.nextInt();
		double ans1 = A * 100;
		double ans2 = 0;
		for(int a = 0; a <= F / (A * 100); a++) {
			for(int b = 0; b <= F / (B * 100); b++) {
				for(int c = 0; c <= F / C; c++) {
					for(int d = 0; d <= F / D; d++) {
						if(100 * a * A + 100 * b * B + C * c + D * d <= F && (double)(C * c + D * d) / (double)(a * A * 100 + b * B * 100) <= (double)E / (double)100) {
							if(a == 0 && b == 0) continue;
							if((double)ans2 / (double)ans1 < (double)(C * c + D * d) / (double)(100 * a * A + 100 * b * B + C * c + D * d)) {
								ans1 = 100 * a * A + 100 * b * B + C * c + D * d;
								ans2 = C * c + D * d;
							}
						}
					}
				}
			}
		}
		System.out.println((int)ans1 + " " + (int)ans2);

	}
}


Measured memory_bytes: 22868
#include <cstdio>
const int N = 3e5;
char s[N];

int main(){
	scanf("%s",s);
	int res = 0;
	bool flag = true;
	for (int l = 0, r = 0; true; ++r)
		if (s[r] != s[l])
		{
			int run = r - l;
			if (run % 3 == 0)
				res += run * 2 / 3;
			if (run % 3 == 1)
				res += (run * 2 + 1) / 3, flag = true;
			if (run % 3 == 2)
				res += (run * 2 - 1) / 3, res += flag ^= true;
			if (!s[l = r])
				break;
		}
	printf("%d\n",res);
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+15+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  cin >> n;
  rep(i,0,n){
    cin >> m;
    d[m-1]++;
  }
  rep(i,0,100){
    if(d[i] != 0)l++;
  }
  print(l);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
int n;
int main()
{
    scanf("%d",&n);
    printf("%d:",n);
    int tmp=n;
    for(int i=2;i*i<=n;i++)
    {
        if(tmp%i==0)
        {
            while(tmp%i==0)
            {
                printf(" %d",i);
                tmp/=i;
            }
        }
    }
    if(tmp>1)
    {
        printf(" %d\n",tmp);
    }
    else
    {
        printf("\n");
    }
    return 0;
}



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


int main () {
  string A, B, C;
  cin >> A >> B >> C;
  if ((A.at(A.size() - 1) == B.at(0)) && (B.at(B.size() - 1) == C.at(0))){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3596
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
c=[0]*m
d=[0]*m
cnt=1000000000000000
ans=0
for i in range(n):
    a[i],b[i]=map(int,input().split())
for j in range(m):
    c[j],d[j]=map(int,input().split())
count=[]
for i in range(n):
    for j in range(m):
        if cnt>abs(a[i]-c[j])+abs(b[i]-d[j]):
            cnt=abs(a[i]-c[j])+abs(b[i]-d[j])
            ans=j+1
    count.append(ans)
    ans=0
    cnt=1000000000000000
#print(count)
for i in range(n):
    print(count[i])

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <string.h>
#include <algorithm>
//#include <bits/stdc++.h>
#include    <vector>
#define INF 999999999
# include <cstdio>
# include <cstdlib>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

int main(){
    int n;
    cin >>n;
    cout<<"ABC"<<n<<endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
lists  = []
pas = [0,0,0]
for i in range(1,N+1):
    pas[0] = i
    for j in range(1,N+1):
        pas[1] = j
        for k in range(1,N+1):
            pas[2] = k
            lists.append(pas)
print(len(lists))

Measured memory_bytes: 3060
#include <iostream>
#include <climits>

const int MAX_N = 20;
const int MAX_Q = 200;

bool test(int A[], int n, int x, int y, int z) {
  if (x == z) {
    return true;
  }

  if (y == n) {
    return false;
  }  

  return (test(A, n , x, y + 1, A[y] + z) || test(A, n , x, y + 1, z));
}

int main() {
  std::ios_base::sync_with_stdio(false);
  
  int n = 0;
  int q = 0;

  int A[MAX_N] = {0};
  int Q[MAX_Q] = {0};

  std:: cin >> n;

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

  std::cin >> q;

  for (int i = 0; i < q; i++) {
    std::cin >> Q[i];
  }

  for (int i = 0; i < q; i++) {
    if (test(A, n, Q[i], 0, 0)) {
      std::cout << "yes" << std::endl;
    } else {
      std::cout << "no" << std::endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct data {
  int nt, to;
} a[N << 1];
int head[N], dep[N], f[N], d[N], n, cnt = 0;

void add(int x, int y) {
  a[++cnt].to = y;
  a[cnt].nt = head[x];
  head[x] = cnt;
}

void dfs(int u, int fa) {
  f[u] = fa, dep[u] = dep[fa] + 1;
  for(int i = head[u]; i; i = a[i].nt) {
    int to = a[i].to;
    if(to == fa) continue;
    dfs(to, u);
  }
}

vector<int> g;
int ans = 0, S, T, tag[N];

void GetDia() {
  dfs(1, 0);
  for(int i = 1; i <= n; ++i) if(dep[i] > ans) ans = dep[i], S = i;
  memset(dep, 0, sizeof dep), memset(f, 0, sizeof f);
  ans = 0;
  dfs(S, 0);
  for(int i = 1; i <= n; ++i) if(dep[i] > ans) ans = dep[i], T = i;
  for(int u = T; u; u = f[u]) {
    tag[u] = 1;
//    printf("%d ", u);
    g.push_back(d[u]);
  }
//  puts("");
  for(int i = 1; i <= n; ++i) {
    if(!tag[i]) {
      if(d[i] >= 2) {
        puts("-1");
        exit(0);
      }
    }
  }
}

void go(int a[]) {
  int now = 0;
  for(int i = 0; i < g.size(); ++i) {
    int w = g[i];
    if(i && i != g.size() - 1) w--;
//    printf("%d ", w);
    a[now + 1] = now + w;
    for(int j = 1; j < w; ++j) a[now + 1 + j] = now + j;
    now += w;
  }
//  puts("www");
}

int p[N], p1[N], p2[N];

int main() {
  scanf("%d", &n);
  for(int i = 2, x, y; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
    d[x]++, d[y]++;
  } 
  GetDia();
  go(p);
  for(int i = 1; i <= n; ++i) p1[p[i]] = i;
  reverse(g.begin(), g.end());
  go(p);
  for(int i = 1; i <= n; ++i) p2[p[i]] = i;
  int now = 1;
  while(now <= n && p1[now] == p2[now]) ++now;
  if(p1[now] < p2[now]) 
    for(int i = 1; i <= n; ++i) printf("%d ", p1[i]);
  else 
    for(int i = 1; i <= n; ++i) printf("%d ", p2[i]);
  return 0;
}

Measured memory_bytes: 9208
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();  
        int n = r.i();
        int[] p = r.ii();
        int count = 0;
        for(int i = 1; i <= n-2; i++){
            int[] a = {p[i-1], p[i], p[i+1]};
            Arrays.sort(a);
            if(a[1] == p[i])
                count++;
        }
        println(count);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21460
#include <stdio.h>

long GCD(long a, long b);
long LCM(long a, long b, long gcd);

int main(void){
	long a, b, gcd, lcm;
	while(scanf("%ld %ld", &a, &b) != EOF){
		gcd = GCD(a, b);
		lcm = LCM(a, b, gcd);

		printf("%ld %ld\n", gcd, lcm);
	}
	return 0;
}

long GCD(long a, long b){
	long comp, R;

	if(a < b){
		comp = a;
		a = b;
		b = comp;
	}

	while(b != 0){
		comp = a % b;
		a = b;
		b = comp;
	}

	return a;
}

long LCM(long a, long b, long gcd){
	long lcm;
	lcm = a * b / gcd;
	return lcm;
}

Measured memory_bytes: 596
import java.util.HashSet;
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();
		sc.close();

		HashSet<Integer> set = new HashSet<Integer>();
		for (int i = 0; i < 3; i++) {
			set.add(i + 1);
		}
		set.remove(a);
		set.remove(b);
		System.out.println(set.toArray()[0]);
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
using namespace std;

void outPut(int array[], char mark)
{
  for (int i = 1; i <= 13; i++ )
  {
    if (array[i] == 0)
      printf("%c %d\n", mark, i);
  }
}

int main()
{
  char mark[2];
  int n, S[13], H[13], C[13], D[13], tmp;
  for (int i = 0; i < 14; i++)
    S[i] = H[i] = C[i] = D[i] = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%s %d", mark, &tmp);
    switch (mark[0])
    {
    case 'S':
      S[tmp] = 1;
      break;
    case 'H':
      H[tmp] = 1;
      break;
    case 'C':
      C[tmp] = 1;
      break;
    case 'D':
      D[tmp] = 1;
      break;
    default:
      break;
    }
  }
  outPut(S, 'S');
  outPut(H, 'H');
  outPut(C, 'C');
  outPut(D, 'D');
}


Measured memory_bytes: 2680
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n + 1);
  B = malloc(sizeof(short)*n + 1);
  for(i=0; i<=VMAX; i++) C[i]=0;

  for(i=0; i<n; i++){
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1; i<=VMAX; i++) C[i] = C[i] + C[i-1];
  for(j=1; j<=n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i=1; i<=n; i++){
    if(i>1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 9556
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashSet<String> dictionary = new HashSet<>();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    String type = sc.next();
		    String name = sc.next();
		    if (type.equals("insert")) {
		        dictionary.add(name);
		    } else {
		        if (dictionary.contains(name)) {
		            sb.append("yes");
		        } else {
		            sb.append("no");
		        }
		        sb.append("\n");
		    }
		}
		System.out.print(sb);
	}
 }



Measured memory_bytes: 230864
#include <stdio.h>

using namespace std;
#define MAX 100000

int partition( int * ary, int p, int r ) {
	int x = ary[r];
	int i = p-1; 
	int j;
	int tmp = 0;

	for ( j = p ; j < r ; j++ ) {
		if ( ary[j] <= x ) {
			i++;
			tmp = ary[j];
			ary[j] = ary[i];
			ary[i] = tmp;
		}
	}
	tmp = ary[i+1];
	ary[i+1] = ary[r];
	ary[r] = tmp;
	return i+1;
}


int main() {
	int number = 0;
	int ary[MAX] = {0};
	int sep = 0;
	scanf( "%d", &number );

	for ( int i = 0 ; i < number ; i++ ) {
		scanf( " %d", &ary[i] );	
	}

	sep = partition( ary, 0, number-1 );
	for ( int i = 0 ; i < number ; i++ ) {
		if ( i ) {
			fprintf( stdout, " " );
		} 

		if ( sep == i ) {
			fprintf( stdout, "[%d]", ary[i] );
		} else {
			fprintf( stdout, "%d", ary[i] );
		}
	}
	fprintf( stdout, "\n" );
	return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <sstream>
#include <numeric>
using namespace std;

int main(){
    int n ;
    cin >> n ;
    vector<int64_t> a(n,0) ;
    vector<int64_t> plus(0) ;
    vector<int64_t> minus(0);
    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
        if (a.at(i) < 0)
        {
            minus.push_back(a.at(i));
            a.at(i) *= -1 ;
        }else
        {
            plus.push_back(a.at(i)) ;
        }
        
    }
    int64_t ans = accumulate(a.begin(),a.end(),int64_t(0)) ;
    /*for (size_t i = 0; i < n; i++)
    {
        ans += a.at(i) ;
    }
    */
    
    if (minus.size() % 2 == 1)
    {
        sort(a.begin(),a.end()) ;
        ans -= 2*a.at(0) ;
    }
    cout << ans << endl ;
}

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

int main()
{
    int m;
    cin >> m;
    ll digit = -1;
    ll sum = -1;
    rep(i, m)
    {
        ll d, c;
        cin >> d >> c;
        digit += c;
        sum += c * d;
    }

    cout << digit + sum / 9 << endl;
}

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


int main() 
{
    string s;
    cin >> s;
    bool ans = true;
    for (int i = 0; i < s.size();i++)
    {
        if(i%2==0)
        {
            if(s[i]=='L')
                ans = false;
        }
        else
        {
            if(s[i]=='R')
                ans = false;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] c1 = sc.next().split("");
		String[] c2 = sc.next().split("");
		String[] c3 = sc.next().split("");
		System.out.println(c1[0]+c2[1]+c3[2]);
	}
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const lli inf=1e18;
const int mod=1e9+7;
int main(){
IOS;
int auxi[101],i,j,n;
memset(auxi,0,sizeof(auxi));
for(i=1;i<=9;i++){
    for(j=1;j<=9;j++)
        auxi[i*j]++;
}
cin>>n;
if(auxi[n])
    cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int a,b;
   cin >> a >> b;
   int cnt = 0;
   for(int i=a; i<=b; i++)
   {
      // stringstream gk ;
       int num = i;

     ostringstream str1;


    str1 << num;


    string geek = str1.str();
    bool mrk = 0;
    for(int r=0,j=geek.size()-1; r<=j; r++,j--)
    {
        if(geek[r]==geek[j])continue;
        else {mrk=1;break;}
    }
  if(!mrk)cnt++;

   }
   cout << cnt << endl;
}


Measured memory_bytes: 3500
#include <stdio.h>
#include<string.h> 
int main(void){
    char c2[3];
    char a[]={"A"};
    char b[]={"B"};
    char o[]={"O"};
     
    int c1,aa=0,bb=0,oo=0,ab=0;
 
    while(scanf("%d,%s", &c1, &c2)!=EOF){
    if(strcmp(c2,a)==0)aa=aa+1;
    else if(strcmp(c2,b)==0)bb=bb+1;
    else if(strcmp(c2,o)==0)oo=oo+1;
    else ab=ab+1;
    }
 
     printf("%d\n",aa);
     printf("%d\n",bb);
     printf("%d\n",ab);
     printf("%d\n",oo);
 
    return 0;
}

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table
  
tmp = set(prime_decomposition(gcd(a,b)))

print(len(tmp)+1)

Measured memory_bytes: 38384
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


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

	int N;
	cin >> N;
	vector<int>A(N);
	rep(i, N)cin >> A[i];

	vector<int>S(N+1);
	rep(i,N)S[i+1] = S[i] + A[i];
	sort(ALL(S));
	
	int ans = 0, count = 1;
	REP(i, 1, N+1) {
		if (S[i] == S[i - 1]) {
			count++;
		}
		else {
			ans += count*(count-1)/2;
			count = 1;
		}
	}

	cout << ans + count*(count - 1)/2 << endl;
	
	return 0;
}

Measured memory_bytes: 3456
def make_dup_length_array(word_list)
  dsize = word_list.length

  dup_length_array = Array.new(dsize){ Array.new(dsize, 0) }

  word_list.each_with_index{|word1, idx1|
    word_list.each_with_index{|word2, idx2|
      min_length = [word1.length, word2.length].min
      min_length.downto(0){|l|
        if word1[-l, l] == word2[0, l] && idx1 != idx2
          dup_length_array[idx1][idx2] = l
          break
        end
      }
    }
  }

  return dup_length_array
end

def concatinate_string_dict_order(word_list)
  word_list.sort.join
end

def generate_min_len_string(word_list, dup_len_array)
  is_zero_array = true

  # puts "enter: #{word_list}, #{dup_len_array}"

  dup_len_array.each_index{|idx1|
    dup_len_array[idx1].each_index{|idx2|
      l = dup_len_array[idx1][idx2]
      if l > 0
        # idx1 + idx2 ??????????????? idx2 ??????????????????
        # idx1 ?????????????????????
        new_word_list = word_list.dup
        new_word_list[idx2] = new_word_list[idx1] + word_list[idx2][l .. -1]
        new_word_list.delete_at(idx1)

        # [idx2][idx1] = 0
        # idx1 ???????????????
        # idx2 ????????? idx1??????????????????
        # idx1 ???????????????
        new_dup_len_array = dup_len_array.dup
        new_dup_len_array[idx2] = dup_len_array[idx2].dup
        new_dup_len_array[idx2][idx1] = 0
        new_dup_len_array.delete_at(idx1)
        tmp = new_dup_len_array.transpose
        tmp[idx2] = tmp[idx1].dup
        tmp.delete_at(idx1)
        new_dup_len_array = tmp.transpose

        is_zero_array = false
        generate_min_len_string(new_word_list, new_dup_len_array)
      end
    }
  }

  if is_zero_array
    sss = concatinate_string_dict_order(word_list)
    # puts "#{sss} #{$min_sss}"
    if sss.length < $min_sss.length ||
       (sss.length == $min_sss.length && sss < $min_sss)
      $min_sss = sss
    end
  end
end

loop{
  n = readline.to_i
  exit if n == 0

  word_list = []
  n.times{
    inp_word = readline.chomp
    word_list.each_with_index{|word, i|
      if word.include?(inp_word)
        inp_word = nil
        break
      end
      if inp_word.include?(word)
        word_list.delete(word)
      end
    }
    word_list << inp_word unless inp_word.nil?
  }

  $min_sss = word_list.join

  # p word_list
  dup_len_array = make_dup_length_array(word_list)
  # p dup_len_array

  generate_min_len_string(word_list, dup_len_array)

  puts $min_sss

  # $min_sss = word_list.join
  # (0..word_list.size-1).to_a.permutation{|order|
  #   cur_pos = order.shift
  #   sss = word_list[cur_pos]
  #   order.each{|cur_pos|
  #     next_word = word_list[cur_pos]

  #     min_length = [sss.length, next_word.length].min

  #     min_length.downto(0){|l|
  #       if sss[-l, l] == next_word[0, l]
  #         sss += next_word[l .. -1]
  #         break
  #       end
  #     }
  #   }
  #   # puts "cur:#{sss} min:#{min_sss}"
      
  #   if sss.length < min_sss.length ||
  #      (sss.length == min_sss.length && sss < min_sss)
  #     min_sss = sss
  #   end
  # }
  # puts min_sss
}

Measured memory_bytes: 9516
#include <stdio.h>
#define INFTY 1000000000
#define N 500000

void merge(int [],int,int,int);
void mergesort(int [],int,int);

int cnt=0;

int main()
{
  int n,s[N],i;

  scanf("%d",&n);
  for(i=0 ; i<n ; i++)
  {
    scanf("%d",&s[i]);
  }

  mergesort(s,0,n);

  for(i=0 ; i<n-1 ; i++)
  {
    printf("%d ",s[i]);
  }
  printf("%d\n",s[n-1]);
  printf("%d\n",cnt);

  return 0;
}

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

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

  int L[n1],R[n2];

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

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

  L[n1] = INFTY;
  R[n2] = INFTY;

  i=0;
  j=0;

  for(k = left ; k<right ; k++)
  {
    if(L[i] <= R[j])
    {
      A[k] = L[i];
      i = i+1;
      cnt++;
    }
    else
    {
      A[k]=R[j];
      j = j+1;
      cnt++;
    }
  }
}

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



Measured memory_bytes: 5620
#include <iostream>
    #include <string>
     
    using namespace std;
     
    int main() {
     
    string a,b,c;
     
    cin >> a >> b >> c;
     
    int A,B,C;
     
    A=a.size();
    B=b.size();
    C=c.size();
     
    int aa,bb,cc;
     
    aa=1;
    bb=0;
    cc=0;
     
    char x;
    
    x=a[0];
     
    while(1){
    	if(x=='a'){
    		
    		x=a[aa];
    		aa++;
    	}else if(x=='b'){
    		
    		x=b[bb];
    		bb++;
    		
    	}else if(x=='c'){
    		
    		x=c[cc];
    		cc++;
    	}
    	if(aa==A+1){
    			cout << "A" << endl;
    			break;
    		}
    	
    	if(bb==B+1){
    			cout << "B" << endl;
    			break;
    		}
    	
     	if(cc==C+1){
    			cout << "C" << endl;
    			break;
    		}
    
    }
    
    
     
    return 0;
    }

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

int main() {
    
    int N,M;
    cin >> N >> M;
    
    for(int i=0;i<M;i++){
        int A_i;
        cin >> A_i;
        N -= A_i;
        if(N < 0){
            cout << -1 <<endl;
            return 0;
        }
        
        if(i == M-1) cout << N <<endl;
    }
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y,a,b,c,val; cin>>x>>y>>a>>b>>c;
	multiset<int>p,q,r;
	for(int i=0;i<a;i++) {
		cin>>val;
		p.insert(val);
	}
	for(int i=0;i<b;i++) {
		cin>>val;
		q.insert(val);
	}
	for(int i=0;i<c;i++) {
		cin>>val;
		r.insert(val);
	}
	vector<int>ret;
	for(int i=0;i<x;i++){
		int this_val=*p.rbegin();
		p.erase(p.find(this_val));
		ret.push_back(this_val);
	}
	for(int i=0;i<y;i++){
		int this_val=*q.rbegin();
		q.erase(q.find(this_val));
		ret.push_back(this_val);
	}
	sort(ret.begin(),ret.end());
	for(int i=0;i<ret.size();i++){
		if(r.empty()) 
			break;
		int this_val=*r.rbegin();
		if(this_val>ret[i]){
			r.erase(r.find(this_val));
			ret[i]=this_val;
		}
	}
	long long ans=0;
	for(const int& r:ret)
		ans+=r;
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 15480