akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        '''
        要素xが属するグループの根を返す
        '''
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        '''
        要素xが属するグループと要素yが属するグループとを併合する
        '''
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        '''
        要素xが属するグループのサイズ（要素数）を返す
        '''
        return -self.parents[self.find(x)]

    def same(self, x, y):
        '''
        要素x, yが同じグループに属するかどうかを返す
        '''
        return self.find(x) == self.find(y)

    def members(self, x):
        '''
        要素xが属するグループに属する要素をリストで返す
        '''
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        '''
        各要素の親要素の番号を格納するリスト
        '''
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        '''
        グループの数を返す
        '''
        return len(self.roots())

    def all_group_members(self):
        '''
        {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        '''
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

ans = 0
for i in range(M):
    G = UnionFind(N)
    for j in range(M):
        if i == j:
            continue
        a, b = ab[j]
        a, b = a-1, b-1
        G.union(a, b)
    if G.group_count() > 1:
        ans += 1
print(ans)

Measured memory_bytes: 73884
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define com bool operator<(const node &b)
using namespace std;
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;

void solve() {
    set<string> s;
    int n;
    cin >> n;
    while (n--) {
        string c;
        cin >> c;
        s.insert(c);
    }
    cout << s.size();
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 19152
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    s=readline().strip()
    t=np.array([1 if s[i]=="R" else 2 if s[i]=="G" else 3 for i in range(n)],dtype=np.int64)
    ans=t[t==1].size*t[t==2].size*t[t==3].size

    for i in range(n):
        if (n+i)%2==0:
            j=np.arange(i+1,(n+i)//2)
            k=2*j-i
        else:
            j=np.arange(i+1,(n+i)//2+1)
            k=2*j-i

        if j.size==0:
            break
        i=np.full(j.size,i,dtype=np.int64)
        tmp=t[i]*t[j]*t[k]
        ans-=tmp[tmp==6].size

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 28040
// thanks to "https://betrue12.hateblo.jp/entry/2019/07/24/015109"

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
namespace mp = boost::multiprecision;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template<typename T> using Graph = vector<vector<T>>;
template<typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

template<typename T>
bool CompareBySecond(pair<T, T> a, pair<T, T> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

template<typename T>
bool CompareBySlope(pair<T, T> a, pair<T, T> b) {
// counterclockwise from 12 o'clock direction
  if (a.first * b.first < 0) {
    return a.first < b.first;
  }
  if (a.first == 0) {
    if (a.second >= 0) {
      return true;
    }
    return a.first < b.first;
  }
  if (b.first == 0) {
    if (b.second >= 0) {
      return false;
    }
    return a.first < b.first;
  }
  return a.second * b.first < a.first * b.second;
}

template<typename T>
T GCD(T a, T b) {
  T c = a % b;
  while (c != 0) { a = b; b = c; c = a % b; }
  return b;
}


/* -------- <templates end> -------- */


void solve() {
  int N, K; cin >> N >> K;
  Spacial<ll> dp(N+1, Graph<ll>(N+1, vl(N*(N+1)+1, 0)));
  dp[0][0][0] = 1;
  rep1(i,N) {
    rep(j,i) {
      rep0(k,i*(i-1)) {
        (dp[i][j+1][k+2*j] += dp[i-1][j][k]) %= MOD;
        (dp[i][j][k+2*j] += dp[i-1][j][k]) %= MOD;
        if (j == 0) continue;
        (dp[i][j][k+2*j] += 2*j * dp[i-1][j][k]) %= MOD;
        (dp[i][j-1][k+2*j] += j*j * dp[i-1][j][k]) %= MOD;
      }
    }
  }
  cout << dp[N][0][K] << endl;
}


/* -------- <programs end> -------- */


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


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

int prime[1001];

void p_cnt(int n){
    if(n%2==0){
        while(n%2==0){
            n/=2;
            prime[2]++;
        }
    }
    for(int i=3; n!=1; i+=2){
        if(n%i==0){
            while(n%i==0){
                n/=i;
                prime[i]++;
            }
        }
    }
}

long long int keisan(int i){
    if(i==1000){
        return 1;
    }
    long long int ret=keisan(i+1);
    if(prime[i]!=1){
        ret*=prime[i];
        ret%=(long long int)((1e+9)+7);
    }
    return ret;
}

int main(){
    int n;
    cin>>n;
    fill(prime,prime+1001,1);
    for(int i=2; i<=n; i++){
        p_cnt(i);
    }
    cout<<keisan(2)<<endl;
    return 0;
}


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

#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define overload_rep(arg_0, arg_1, arg_2, name, ...) name
#define all(box) box.begin(), box.end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int H, W;
int grid[80][80];
constexpr int initial = 12800;
bitset<initial * 2 + 1> dp[80][80];

int main() {

    cin >> H >> W;
    rep(i, H)rep(j, W)cin >> grid[i][j];
    rep(i, H)rep(j, W) {
        int b;
        cin >> b;
        grid[i][j] -= b;
        if(grid[i][j] < 0)grid[i][j] = -grid[i][j];
    }

    dp[0][0][initial + grid[0][0]] = 1;
    dp[0][0][initial - grid[0][0]] = 1;
    rep(i, H)rep(j, W) {
        if(i > 0) {
            dp[i][j] |= dp[i - 1][j] << grid[i][j];
            dp[i][j] |= dp[i - 1][j] >> grid[i][j];
        }
        if(j > 0) {
            dp[i][j] |= dp[i][j - 1] << grid[i][j];
            dp[i][j] |= dp[i][j - 1] >> grid[i][j];
        }
    }

    int ans = 1 << 30;
    rep(i, 0, initial * 2) {
        if(dp[H - 1][W - 1][i]) {
            chmin(ans, abs(initial - i));
        }
    }

    cout << ans << '\n';
    return 0;

}


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

typedef long long int ll;

vector <ll> a;
ll ans[200005];

int main()
{
	ll i,j,k,l,m,n,u,v;

	cin >> n;

	a.push_back(0);

	for(i=0;i<n;i++)
	{
		cin >> k;
		a.push_back(k);
	}

	l = n;


	for(i=1;i<=(n-1);i++)
	{
		ans[l] = ans[l]^a[i];
	}

	k = ans[n];
	j = n;



	for(i=1;i<n;i++)
	{
		k = k^a[i];

		k = k^a[j];

		ans[i] = k;

		j++;
		j = j%n;
	}

	for(i=1;i<=n;i++)
		cout << ans[i] << " ";
	cout << '\n';
	
	
	
	


}

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

int main(){
    int n,m,a,b;
    cin >> n >> m;
    vector<tuple<int,int,int>> c;
    vector<int> count(n + 1,1);
    vector<pair<int,int>> ans(m);
    for(int i = 0;i < m;i++){
        cin >> a >> b;
        c.emplace_back(a,b,i);
    }
    sort(c.begin(),c.end());
    for(int i = 0;i < m;i++){
        ans[get<2>(c[i])].first = get<0>(c[i]);
        ans[get<2>(c[i])].second = count[get<0>(c[i])];
        count[get<0>(c[i])]++;
    }
    for(int i = 0;i < m;i++){
        cout << setfill('0') << right << setw(6) << ans[i].first;
        cout << setfill('0') << right << setw(6) << ans[i].second << endl;
    }

}



Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define REP(i,m,n) for (int i=m;i<n;i++)
#define FOR(i,m,n,a) for(int i=m;i<n;i+=a)
const ll MOD=1e9+7;

int main(){
  int a,b;
  cin >> a >> b;
  if(a==1) a+=13;
  if(b==1) b+=13;

  if(a>b){
    cout << "Alice" << endl;
  }
  else if(a<b){
    cout << "Bob" << endl;
  }
  else{
    cout << "Draw" << endl;
  }
  return 0;
}


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

int main() {
    int n; cin >> n;
    for(int i = n; i <= 999; i++) {
        string si = to_string(i);
        if(si[0] == si[1] && si[1] == si[2]) {
            cout << si << endl;
			break;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
 
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

	int sw[1 << 10];
	int k[10], s[10][10], p[10];
	for(int i = 0; i < M; ++i) {
		cin >> k[i];
		for(int j = 0; j < k[i]; ++j) {
			cin >> s[i][j];
			--s[i][j];
		}
	}
	for(int i = 0; i < M; ++i) cin >> p[i];

	int res = 0;
	for(int i = 0; i < (1 << N); ++i) {
		bool on = true;
		for(int j = 0; j < M; ++j) {
			int count = 0;
			for(int sw = 0; sw < k[j]; ++sw) {
				if(i & (1 << s[j][sw])) ++count;
			}
			if(count % 2 != p[j]) on = false;
		}
		if(on) ++res;
	}
	cout << res << endl;
    return 0;
}


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

int main(){
  int h1,m1,h2,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  int ans = (h2-h1)*60 + (m2-m1);
  ans -= k;

  cout<<ans<<endl;
}

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

using namespace std;

int main(void)
{
	int n, d;
	cin >> n >> d;
	int range = d * 2 + 1;
	if (n % range == 0)
	{
		cout << n / range << endl;
	}
	else
	{
		cout << (n / range) + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <memory.h>
int main(void){
	int n,q,m,d,i,f[101],max,ans;
	while(1){
		scanf("%d %d",&n,&q);
		if(!n)
			break;
		memset(f,0,sizeof(f));
		max=ans=0;
		while(n--){
			scanf("%d",&m);
			while(m--){
				scanf("%d",&d);
				f[d]++;
			}
		}
		for(i=0;i<101;i++){
			if(f[i]>=q&&f[i]>max){
				max=f[i];
				ans=i;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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


int main() {
    int N, K;
    std::cin >> N >> K;
    std::vector<int> price(N);
    for (int i = 0; i < N; i++) {
        std::cin >> price[i];
    }
    std::sort(price.begin(), price.end(), [](auto lhs, auto rhs) {return lhs < rhs;});
    int sum = 0;
    for (int i = 0; i < K; i++) {
        sum += price[i];
    }
    std::cout << sum << std::endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;
int cnt = 0,X;

int main(){
  int N,A,B,C,y;
  while(true){
    cin >> N >> A >> B >> C >> X;
    if(N+A+B+C+X == 0)break;
    cnt = 0;
    vector<int> Y;
    for(int i=0;i<N;i++){
      cin >> y;
      Y.push_back(y);
    }
    int i,f = 0;
    for(i=0;i<=10000;i++){
      if(X == Y[f])f++;
      if(f == N)break;
      X = (X*A+B)%C;
      cnt++;
    }
    if(i == 10001)cnt = -1;

    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
    int n; cin >> n;
    vector<int> a(n-1);
    rep(i,n-1){
        cin >> a[i];
        a[i]--;
    }
    vector<int> s(2e5,0);
    rep(i,n-1){
        s[a[i]]++;
    }
    rep(i,n){
        cout << s[i] << endl;
    }
}

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

ull gcd_ori(ull a, ull b){
    if(b == 0){
        return a;
    }

    return gcd_ori(b, a % b);
}

int main() {
    int N; cin >> N;
    vector<ull> T(N, 0);
    rep(i,N){
        cin >> T.at(i);
    }

    if(N==1){
        cout << T.at(0) << endl;
        return 0;
    }

    if(T.at(0)<T.at(1)){
        ull t = T.at(0);
        T.at(0) = T.at(1);
        T.at(1) = t;
    }

    ull tmp = gcd_ori(T.at(0), T.at(1));
    tmp = T.at(0) * (T.at(1) / tmp);
    for(ull i=1; i<N; i++){
        if(tmp < T.at(i)){
            ull t = tmp;
            tmp = T.at(i);
            T.at(i) = tmp;
        }
        ull div_n = gcd_ori(T.at(i), tmp);
        tmp = T.at(i)*(tmp/div_n);
    }

    cout << tmp << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
   int N;
   cin >> N;
   vector<bool> A(1000000010);
   int count = 0;
   for(int i = 0; i < N; i++){
       ll a;
       cin >> a;
       if(A.at(a) == true){
           A.at(a) = false;
           count--;
       }
       else{
           A.at(a) = true;
           count++;
       }
   }
   cout << count << endl;
}


Measured memory_bytes: 122368
H, W, K = map(int, input().split())
G = [list(input()) for i in range(H)]


# イチゴがない行の番号を記録しておく
non_placed_row_indexes = set()
for h in range(H):
    if G[h].count('#') == 0:
        non_placed_row_indexes.add(h)


ans = [[0] * W for i in range(H)]
painting = 0
for h in range(H):
    # イチゴがない行なら何もしない
    if h in non_placed_row_indexes:
        continue

    # 各行最初のイチゴは色を変えなくてよい（行の変化によって変わるので）
    find_flg = False
    for w in range(W):
        # 行が変わる
        if w == 0:
            painting += 1

        # イチゴを見つける
        if G[h][w] == '#':
            if find_flg:
                painting += 1
            else:
                find_flg = True

        ans[h][w] = painting


# １つ上の行を見ながら下にくだる
for h in range(1, H):
    # イチゴがある行なら何もしない
    if h not in non_placed_row_indexes:
        continue

    for w in range(W):
        # １つ上の行の色をコピー
        ans[h][w] = ans[h - 1][w]

# １つ下の行を見ながら上にのぼる
for h in range(H - 2, -1, -1):
    # イチゴがある行なら何もしない
    if h not in non_placed_row_indexes:
        continue

    for w in range(W):
        # １つ下の行の色をコピー
        ans[h][w] = ans[h + 1][w]


# 出力
for a in ans:
    print(*a, sep=' ')


Measured memory_bytes: 8272
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[114514]={};
    long long int m=0;
    for(int i = 0;i<n;i++){
        cin>>a[i];
        m+=a[i];
    }
    if(m%2==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}



Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    cin>> a >> b >> c;
    if(a<b&&a<c){cout << a <<" ";
        if(b<c){cout << b <<" "<< c <<endl;
        }else{
            cout << c <<" "<< b <<endl;
        }
    }else if(b<a&&b<c){cout << b <<" ";
        if(c<a){cout << c <<" "<< a <<endl;
        }else{
            cout << a <<" "<< c <<endl;
        }
    }else{cout << c <<" ";
        if(a<b){cout << a <<" "<< b <<endl;
        }else{
            cout << b <<" "<< a <<endl;
        }
    }
    // Your code here!
    
}


Measured memory_bytes: 3096
words=str(input())
n=int(input())
for i in range(n):
    order=str(input())
    order_s=order.split()
    if order_s[0]=="print":
        print(words[int(order_s[1]):int(order_s[2])+1])
    if order_s[0]=="reverse":
        w_k=words[int(order_s[1]):int(order_s[2])+1]
        words=words.replace(w_k, w_k[::-1])
    if order_s[0]=="replace":
        k=0
        s_l=list(words)
        for j in range(int(order_s[1]),int(order_s[2])+1):
            s_l[j]=order_s[3][k]
            k+=1
        words="".join(s_l)


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
string s,p;

int main()
{
    ft
    int i,j,n,m,l,r,a[102],f=0;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(i=0; i<n; i++)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3!=0 && a[i]%5!=0)
            {
                f=1;
                break;
            }
        }
    }
    if(f==0)
    {
        cout<<"APPROVED\n";
    }
    else
        cout<<"DENIED\n";
    return 0;
}



Measured memory_bytes: 256
//まともに使い方を理解していないくせにincludeしまくる人間のクズ
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <iostream>


//using namespace stdしないと表記がめんどくさいからね、仕方ないね
using namespace std;

//可読性を上げるためのdefineがあだとなる典型的パターン
#define FOR(x) for(int i = 0; i < x; i++)

//ローカル変数とグローバル変数は使い分けよう！
stack<short> x, y;
short a[10], n, j, i, m, ans;

//関数って楽しいよね！（魔王スマイル）
void solve(short c, short sum, short cnt){
    if(cnt == n){
        if(sum == m) ans++;
        return;
    }
    if(cnt < n && c > 9) return;
    if(sum > m) return;
    solve(c + 1, sum + c, cnt + 1);
    solve(c + 1, sum, cnt);
    return;
}

int main(){
    while(true){
        scanf("%d %d", &n, &m);
        if(n == 0 && m == 0) return 0;
        ans = 0;
        solve(0, 0, 0);
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char **GET_ARRAY_CHAR2(long row, long col);
int compare_string(const void *a, const void *b);
void SORT(char s[]);
int main(void) {
   
   int N;
   
   scanf("%d",&N);
  
   char **S = GET_ARRAY_CHAR2(N, 11);
   
   int i,j;
   
   for (i = 0; i < N; i++) {
      scanf("%s",S[i]);
      SORT(S[i]);
   }
   
   qsort(S, N, sizeof *S, compare_string);

   /*
   for (i = 0;i < N;i++) {
      printf("%s\n",S[i]);
   }
    */
   
   long Ans[N];

   
   for (i = 0; i < N; i++) {
      Ans[i] = 1;
   }
   
   int count = 0;
   for (i = 0; i < N - 1; i++) {
      if (strcmp(S[i], S[i+1]) == 0) {
         Ans[count]++;
      }
      else {
         count++;
      }
   }
   
   long ans = 0;
   for (i = 0; i < N; i++) {
      ans = ans + Ans[i]*(Ans[i] - 1)/2;
   }
   

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

void SORT(char str[]) {
   
   int i,j;
   char a;
   
   for (i = 0; str[i] != 0; i++) {
      for (j = i+1; str[j] != 0; j++) {
         if(str[i] > str[j]){
            a = str[i];
            str[i] = str[j];
            str[j] = a;
         }
      }
   }
}

int compare_string(const void *a, const void *b) {
   return strcmp(*(const char **)a, *(const char **)b);
}



char **GET_ARRAY_CHAR2(long row, long col) {
   
   long i,j;
   
   char **Matrix;
   Matrix = malloc(sizeof(char*)*row);
   if (Matrix == NULL) {
      printf("Error in GET_ARRAY_CHAR2\n");
      printf("Need More Memory(row=%ld)\n",row);
      exit(1);
   }
   for (i = 0; i < row; i++) {
      Matrix[i] = malloc(sizeof(char)*col);
      if(Matrix[i] == NULL){
         printf("Error in GET_ARRAY_CHAR2\n");
         printf("Need More Memory(col=%ld)\n", col);
         exit(1);
      }
   }
   
   /*
   for (i = 0; i < row; i++) {
      for (j = 0;j < col; j++) {
         Matrix[i][j] = 0;
      }
   }
   */
   
   return Matrix;
   
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  char a, b;
  cin >> a >> b;

  if(a == 'H') {
    cout << b << endl;
  } else {
    if(b == 'H') cout << 'D' << endl;
    else cout << 'H' << endl;
  }
}


Measured memory_bytes: 256
import itertools
import numpy as np

n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int,input().split())))



ans = []

def distance(a, b):
    return np.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)

for v in itertools.permutations(xy, n):

    tmp = 0
    for i in range(n-1):
        tmp += distance(v[i], v[i+1])

    ans.append(tmp)


print(np.average(ans))


Measured memory_bytes: 14216
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n)+1) : 1)
#define mem(x, val)    memset(x, val, sizeof(x))

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;

int n;
vector<pii> v;
ll dp[100][(int)1e5 + 1];
ll solve(int i, int w){
    if(i==n) return 0;

    ll &ret  = dp[i][w];
    if(~ret) return ret;

    ret = solve(i+1, w); // leave
    if(w>=v[i].F) ret = max(ret, v[i].S + solve(i+1, w - v[i].F)); // take

    return ret;
}
int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    int w;
    cin>>n>>w;
    v.resize(n);
    for(auto &it: v) cin>>it.F>>it.S;
    ///F = w, S = value
    for(int i =0; i<100; i++)mem(dp[i], -1);
    cout<<solve(0, w);
    return 0;
}







Measured memory_bytes: 78464
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {

    input!{
       n:usize
    }

    if n % 2 == 0 {
        println!("{}", n);
    }else{
        println!("{}", n * 2)
    }

}


Measured memory_bytes: 4352
def c6(x):
    res=0
    while x>0:
        res,x=res+x%6,x//6
    return res

def c9(y):
    res=0
    while y>0:
        res,y=res+y%9,y//9
    return res

N=int(input())
ans=100000
for x in range(N+1):
    # print(x,N-x,c6(x),c9(N-x),c6(x)+c9(N-x))
    ans=min(ans,c6(x)+c9(N-x))

print(ans)

Measured memory_bytes: 41324
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int k = sc.nextInt();
		int s = sc.nextInt();
		
		// 計算
		int result = 0;
		for(int i = 0; i <= k; i++){
		    for(int j = 0; j <= k; j++){
		        if(0 <= s-(i+j) && s-(i+j) <= k) result++;
		    }
		}
		
		
		// 出力
		System.out.println(result);
	}

	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


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

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

  int h[n+1];
  for(int i=1;i<n+1;i++){ cin >> h[i];}

  int c[n+1];

  c[1] =0;
  c[2] = abs(h[2]-h[1]);

  for(int i=3;i<=n;i++){
      c[i] = min(c[i-1]+abs(h[i-1]-h[i]),c[i-2]+abs(h[i-2]-h[i]));
  }

  cout << c[n] << endl;


}

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

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

    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s[i];
    }

    int ans = 0;
    for(int k=0; k<n; k++){
        bool flag = true;
        
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(s[i][(j+k)%n] != s[j][(i+k)%n]) flag = false;
            }
        }
        if(flag == true) ans += n;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3776
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)

	scope := 2*b + 1
	man := a / scope
	if a%scope == 0 {
		fmt.Println(man)
	} else {
		fmt.Println(man + 1)
	}
}


Measured memory_bytes: 512
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/3
Solved on 2019/3/3
@author: shinjisu
"""


# ABC 120
# import math


def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**12


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def prob_B():
    A, B, K = getIntList()
    dmp((A, B, K))
    count = 0
    i = 1
    while count < K:
        if A % i == 0 and B % i ==0:
            count += 1
            if count == K:
                break
        i += 1
    return i


def prob_C():
    S = input()
    red = 0
    blue = 0
    for cube in S:
        if cube == '0':
            red += 1
        else:
            blue += 1
    dmp((red, blue))
    return min(red, blue)*2


debug = False  # True False
ans = prob_C()
print(ans)
#for row in ans:
#    print(row)


def prob_D():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    return 123


def prob_A():
    A, B, C = getIntList()
    dmp((A, B, C))
    count = min(B // A, C)
    return count




Measured memory_bytes: 3316
from math import ceil
import numpy as np
[n, h] = list(map(int, input().split()))
sword = []
for _ in range(n):
    sword.append(list(map(int, input().split())))
if n > 1:
    sword.sort(key=lambda x:x[1])
    cut = max(sword, key=lambda x:x[0])
    sword.remove(max(sword, key=lambda x:x[0]))
    sword.reverse()
    counter = 0
    for i in sword:
        if i[1] < cut[0]:
            break
        h -= i[1]
        counter += 1
        #print("HP:{}, attack:{}, counter:{}".format(h, i[1], counter))
        if h <= 0:
            break
    if h > 0:
        h -= cut[1]
        counter += 1
        if h > 0:
            counter += int(ceil(h / float(cut[0])))
    print(counter)
else:
    print(int(ceil((h - sword[0][1]) / sword[0][0])) + 1)


Measured memory_bytes: 40076
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func KMP(A, B []interface{}) []int {
  N := len(B)
  PMT := make([]int, N + 1)
  PMT[0] = -1
  for i, j := 2, 0; i <= N; {
    if B[i - 1] == B[j] {
      PMT[i] = j + 1
      i++
      j++
    } else if 0 < j {
      j = PMT[j]
    } else {
      PMT[i] = 0
      i++
    }
  }
  M := make([]int, 0)
  for i, j := 0, 0; i + j < len(A); {
    if A[i + j] == B[j] {
      j++
      if j == N {
        M = append(M, i)
        i += N - PMT[N]
        j = PMT[j]
      }
    } else {
      i += j - PMT[j]
      if 0 < j { j = PMT[j] }
    }
  }
  return M
}

func main() {
  N := NextInt()
  A := NextIntVec()
  B := NextIntVec()
  XA := make([]interface{}, N)
  XB := make([]interface{}, N)
  for i, a := range A {
    XA[i] = a ^ A[(i + 1) % N]
    XB[i] = B[i] ^ B[(i + 1) % N]
  }
  XA = append(XA, XA...)
  K := KMP(XA, XB)
  for _, k := range K {
    if N <= k { break }
    x := A[k] ^ B[0]
    WriteIntVec([]int{k, x})
  }
  Output()
}

Measured memory_bytes: 44928
def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
            #print(result)
            result %= (10**9+7)

    return result


def f(x,k,small):    
    d = len(x)
    #print(x, k, d,small)
    if d == 0:        
        if k==0:
            return 1
        else:   
            return 0
    #if d==1 and k==0:
    #    return 0 
    if d<k:
        return 0

    if k==0:
        return 1

    #if d==1:
    #    return x[0]

    if small:
        #print(k,d)
        return (9**(k))*cmb(d, k)

    #A = max(x[0]-1, 0)
    if x[0]==0:
        return f(x[1:],k,False)
    zero = f(x[1:],k,True)
    aida=f(x[1:],k-1,True)*(x[0]-1)
    eq = f(x[1:], k-1,False)
    #print(zero,aida,eq)
    return zero+aida+eq

N=list(map(int,list(input())))
K=int(input())

print(f(N,K,False))

#dp0[i][j]=x[0]*dp0[i][j]+dp1[i+1][j]



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

int h[100055],dp[100055];
const int inf = 0x3f3f3f;
int main()
{
	int n;
	memset(dp,0,sizeof(dp));
	cin>>n;
	h[1]=inf;
	h[0]=inf;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=2;i<=n;i++)
	{
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
		
	cout<<dp[n]<<endl;
	return 0;
} 
//max(h[i],h[i-2])-min(h[i],h[i-2])

Measured memory_bytes: 1024
def main():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())
    norimono = [A,B,C,D,E]
    norimono.sort()
    kaisuu = N // norimono[0]
    if N % norimono[0] != 0:
        kaisuu += 1
    print(kaisuu + 4)

main()


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int r;

int main()
{
	scanf("%d", &r);
	int ans = r * r;
	printf("%d\n", ans);
	
		
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main() {
    long long a,b,c;
  long long sum=0;
  cin>>a>>b>>c;
  bool ok=false;
  for(int i=1;i<=110;i++){
    sum+=a;
    if(sum%b==c)ok=true;
  }
  if(ok)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>

using namespace std;
typedef long long ll;
const int maxn = 2e5+10;

int main(){
    ll n,m;
    cin>>m>>n;
    ll ans = 1;
    for(int i = 1;(ll)i*i<=n;i++){
        if(n % i == 0){
            ll j = n/i;
            if(j>=m) ans = max(ans,(ll)i);
            if(i>=m) ans = max(ans,(ll)j);
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
int main(){
 long long n,a,b;
scanf("%lld%lld%lld",&n,&a,&b);
if(a > b)
return 0*printf("0\n");
if(n == 1 && a < b)
return 0*printf("0\n");
printf("%lld\n",a+b*(n-1)-(b+a*(n-1))+1);
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{   string a,b;
    cin>>a>>b;
    int n=a.length(),m=b.length();
    int dp[n+1][m+1];
    for(int i=0;i<=n;i++)
    dp[i][0]=0;
    for(int i=0;i<=m;i++)
    dp[0][i]=0;
    for(int i=1;i<=n;i++)
    {   for(int j=1;j<=m;j++)
        {   if(a[i-1]==b[j-1])
            dp[i][j]=max(1+dp[i-1][j-1],max(dp[i-1][j],dp[i][j-1]));
            else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int x=n,y=m;
    string s="";
    while(x>0 && y>0)
    {   if(a[x-1]==b[y-1])
        {s+=a[x-1];
        x--;y--;}
        else if(dp[x-1][y]>dp[x][y-1])
        x--;
        else
        y--;
    }
    reverse(s.begin(),s.end());
    cout<<s;
}

Measured memory_bytes: 35456
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
int main()
{
   int a, b, angle;
   double s, l, h;
   scanf("%d %d %d", &a, &b, &angle);
   h=b*sin(angle*M_PI/180.0);
   s=a*h/2;
   l=a+b+sqrt((a*a+b*b-2*a*b*cos(angle*M_PI/180.0)));
   printf("%f\n", s);
   printf("%f\n", l);
   printf("%f\n", h);
   return 0;
}


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

int main(){
    long long n,num,mn,nm,mon;
    while(cin >> n,n){
        int c=0,sc[4001],cn=0,cc=0;
        map<int,long long> maps;
        for(int i=0;i<n;i++){
            int cnt=0,j=0;
            cin >> num >> mn >> nm;
            mon = mn*nm;
            maps[num] += mon;
            for(;j<c;j++){
                if(sc[j]==num)cn++;
            }
            if(cn==0||j==0){
                sc[c] = num;
                c++;
                //cout << sc[c] << endl;
            }
        }
        for(int i=0;i<c;i++){
            if(maps[sc[i]]>=1000000){
                cout << sc[i] << endl;
                cc++;
            }
        }
        if(cc==0) cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define N ('z'-'a')
using namespace std;
int n,ans;
string str[501];
long long mp[N+1];

void mk_mp(int pos,int i,int j){
  while(i<=j&&pos>=str[i].size())i++;
  if(i>=j)return;
  int ni=-1,ch=str[i][pos]-'a',c=1;

  while(i<j){
    int a=str[++i][pos]-'a',f=(ch==a);
    if(f&&ni==-1)ni=i-1;
    if(!f&&ni>=0)mk_mp(pos+1,ni,i-1),ni=-2;
    if(!f&&c)mk_mp(pos,i,j),mp[ch]|=((1LL<<a)|mp[a]),c=0;
    ans*=!(f&&!c)&!(f&&str[i-1].size()>str[i].size()&&!str[i][pos+1]);
  }
  if(ni>=0) mk_mp(pos+1,ni,j);
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>str[i];
    ans=1;
    mk_mp(0,0,n-1);
    for(int i=0;i<=N;mp[i]=0,i++) ans*=!(mp[i]&(1<<i));
    cout <<(ans? "yes":"no")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

using ll = long long;
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define tc() int t; cin>>t; while(t--)
#define print(n) cout<<n<<"\n"
#define inp(n) int n; cin>>n
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define maxn 1000010
#define mod 1e9+7
#define ff  first
#define ss  second
#define fora(var, start, end) for(int var = start; var < end; var++)
int main()
{
    fast();
    int h,a;
    cin>>h>>a;
    print((h/a)+(h%a!=0));
    return 0;
}

Measured memory_bytes: 256
n,m = gets.chomp.split.map(&:to_i)
hs = gets.chomp.split.map(&:to_i)
rs = m.times.map{gets.chomp.split.map(&:to_i)}

array = Array.new(n){Array.new}
cnt = 0
rs.each do |a,b|
	array[a-1] << b-1
	array[b-1] << a-1
end

array.each_with_index do |as,i|
	flag = true
	h1 = hs[i]
	as.each do |r|
		if h1 <= hs[r]
			flag = false
		end
	end
	cnt += 1 if flag
end

puts cnt

Measured memory_bytes: 27172
n,m=map(int,input().split())
a=list()
for i in range(n):
    a.append(list(map(int,input().split())))
b=list()
for i in range(m):
    b.append(int(input()))
for i in range(n):
    ans=0
    for j in range(m):
        ans+=a[i][j]*b[j]
    print(ans)


Measured memory_bytes: 6012
(let* ((dmax (read))
       (c (make-array '(27)))
       (s (make-array (list (1+ dmax) 27)))
       (score 0)
       (last (make-array '(27) :initial-element 0)))
  ; read
  (loop :for i :from 1 :to 26
        :do (setf (aref c i) (read)))
  (loop :for d :from 1 :to dmax
        :do (loop :for i :from 1 :to 26
                  :do (setf (aref s d i) (read))))
  ;
  (defun delta (x d)
    (- (aref s d x)
       (loop :for i :from 1 :to 26
             :sum (* (aref c i) (- d (if (= i x) d (aref last i)))))))

  ;;
  (loop :for d :from 1 :to dmax
        :do (let ((cand-c 1)
                  (cand-v (delta 1 d)))
              (loop :for i :from 2 :to 26
                    :do (let ((v (delta i d)))
                          (if (> v cand-v)
                              (setf cand-c i)
                              (setf cand-v v))))
              (incf score cand-v)
              (setf (aref last cand-c) d)
              (format t "~A~%" cand-c)))
  ;(format t "~A~%" score)
  t)


Measured memory_bytes: 29572
code = """

# distutils: language=c++
# distutils: include_dirs=[/home/USERNAME/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False

from libcpp.vector cimport vector
from libc.stdio cimport getchar, printf

cdef extern from *:
    ctypedef int MOD_t "998244353"
    ctypedef long long ll "long long"

cdef extern from "<atcoder/convolution>" namespace "atcoder":
    vector[int] convolution[M](vector[int] a, vector[int] b)
    vector[ll] convolution_ll(vector[ll] a, vector[ll] b)

cpdef vector[int] Conv(vector[int] a, vector[int] b):
    return convolution[MOD_t](a, b)

cpdef vector[ll] ConvL(vector[ll] a, vector[ll] b):
    return convolution_ll(a, b)

cpdef inline vector[int] readInt(int n) nogil:
    cdef int b, c
    cdef vector[int] *v = new vector[int]()
    for i in range(n):
        c = 0
        while 1:
            b = getchar() - 48
            if b < 0: break
            c = c * 10 + b
        v.push_back(c)
    return v[0]

cpdef inline void printLongN(vector[long] l, int n):
    for i in range(n): printf("%ld\\n", l[i])

cpdef inline void printLong(vector[long] l, int n):
    for i in range(n): printf("%ld ", l[i])
"""


import os, sys, getpass

if sys.argv[-1] == 'ONLINE_JUDGE':
    code.replace("USERNAME", getpass.getuser())
    open('atcoder.pyx','w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')
    sys.exit(0)


from atcoder import Conv, readInt, printLong

N,M = readInt(2)

A = readInt(N)
B = readInt(M)

C = Conv(A,B)

printLong(C, len(C))

Measured memory_bytes: 128044
#include<stdio.h>

int main(void){
    int x=0,a=0,b=0;
    int disA=0,disB=0;
    
    scanf("%d %d %d",&x,&a,&b);
    disA=x-a;
    if(disA<0) disA*=-1;
    disB=x-b;
    if(disB<0) disB*=-1;
    if(disA<disB) printf("A\n");
    else printf("B\n");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  int list[50];
  list[0] = 0;
  int sum = 0;
  for (int i = 1; sum + i < 50; i++) {
    list[sum + i] = list[sum] + 1;
    sum += i;
    for (int j = 1; j <= i && sum + j < 50; j++) {
      list[sum + j] = list[sum];
    }
  }
  long long ans = 0;
  for (long long p = 2; p * p <= N; p++) {
    if (N % p == 0) {
      int e = 0;
      while (N % p == 0) {
        N /= p;
        e++;
      }
      ans += list[e];
    }
  }
  if (N > 1) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

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

	string s;
	cin >> s;

	Int len = s.size();

	Int g = 0;
	Int p = 0;
	Int kachi = 0;
	Int aiko = 0;
	Int make = 0;

	for (Int i = 0; i < len; i++) {
		if (s[i] == 'p') {
			if (p < g) {
				p++;
				aiko++;
			}
			else {
				g++;
				make++;
			}
		}
		else {
			if (p < g) {
				kachi++;
				p++;
			}
			else {
				g++;
				aiko++;
			}
		}
	}

	cout << kachi-make << "\n";

}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
struct UnionFind{
    vector<int> par;//親(根)
    vector<int> rank;//木の深さ

    //UnionFind(int n) { init(n); };
    UnionFind(int n){//初期化関数
        par.resize(n);
        rank.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;//初めはノード一個の木なので根は自身
            rank[i] = 1;
        }
    }

    int root(int x){//木の根を求める
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
    }

    bool same(int x, int y){//同じ木かどうか判定
        return root(x) == root(y);//同じ木ならtrue
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;//もし同じ木に属していたら何もしない
        if(rank[x] < rank[y]) swap(x, y);//数が大きい方に小さい方を結合させる
        par[y] = x;
        rank[x] += rank[y];//深さが同じ時だけ結合後深さが増える
    }

    int size(int x) {//深さを返す関数
        return rank[root(x)];
    }
};
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    for(int i = 0; i < N; i++){
        cin >> p[i];
        p[i]--;
    }
    vector<int> x(M), y(M);
    UnionFind U(N);
    for(int i = 0; i < M; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
        U.unite(x[i], y[i]);
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(U.root(i) == U.root(p[i])) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5116
open Batteries

let () =
  let a, b, c = Scanf.scanf "%d %d %d\n" (fun a b c -> a, b, c) in
  let k = Scanf.scanf "%d\n" (fun a -> a) in

  let m = max a (max b c) in

  let rec t2 init n =
    if n = 0 then init
    else t2 (init * 2) (n-1)
  in

  print_endline (string_of_int (a + b + c - m + (t2 m k)))


Measured memory_bytes: 1152