akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//Initialize UFDS
int parent[100005], sz[100005];
void init(int n) {
	for (int i = 0; i <= n; i++) {
		parent[i] = i;
		sz[i] = 1;}}
int find(int x) {
	if (parent[x] == x) {
		return x;} 
  else {
		parent[x] = find(parent[x]);
		return parent[x];}}
void merge(int x, int y) {
	x = find(x);
	y = find(y);
	if (sz[x] < sz[y]) {
		parent[x] = y; sz[y] += sz[x];} 
  else {parent[y] = x; sz[x] += sz[y];
   sz[y] += sz[x];}}

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

  deque <pair<long long, long long>> xlist, ylist;
  deque <deque<long long>> G;
  pair <long long, long long> xample, yample; set <long long> set1;
  long long N, xa, ya, cost=0, W, A, B; cin >> N;
  for (long long i=1; i<=N; i++){
    cin >> xa >> ya;
    xample = make_pair(xa,i); yample = make_pair(ya,i);
    xlist.push_back(xample); ylist.push_back(yample);}
  sort(xlist.begin(), xlist.end()); sort(ylist.begin(), ylist.end());
  
  //Kruskal's Algorithm
  for (long long i=0; i<N-1; i++) {
		deque<long long> x_edge;
		x_edge.push_back(xlist[i+1].first - xlist[i].first);
		x_edge.push_back(xlist[i].second);
		x_edge.push_back(xlist[i+1].second);
		G.push_back(x_edge);
		deque<long long> y_edge;
		y_edge.push_back(ylist[i+1].first - ylist[i].first);
		y_edge.push_back(ylist[i].second);
		y_edge.push_back(ylist[i+1].second);
		G.push_back(y_edge);}
  sort(G.begin(), G.end()); init(N);

  for (int i = 0; i < G.size(); i++) {
    W=G[i][0], A=G[i][1], B=G[i][2];
    if (find(A)!= find(B)){
      merge(A,B); cost+=W;}}
  cout << cost;}

Measured memory_bytes: 142604
n, m = map(int, input().split())

num_list = []

for _ in range(n):
    num_list.append(list(map(int,input().split())))
    
gyou = [int(input()) for _ in range(m)]


for i in range(n):
    ans = 0
    for j in range(m):
        ans += num_list[i][j] * gyou[j]
    print(ans)



Measured memory_bytes: 6020
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    int N, M;
    scan(N, M);

    int[] divs;

    for (int i = 1; i*i <= M; i++) {
        if (M % i == 0) {
            divs ~= i;
            divs ~= M / i;
        }
    }

    auto ans = divs.sort().lowerBound(M / N + 1).back;

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import sys
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if 4*h*n -N*h -N*n <= 0: continue
        w = N*h*n/(4*h*n -N*h -N*n)
        if not 0<w<=3500: continue 
        if w==int(w):
            print(h,n,int(w))
            sys.exit()

Measured memory_bytes: 41580
package main

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

func max(a, b uint) uint {
	if a >= b { return a}
	return b
}

func main(){
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var (
		N int
		S string 
	) 
	fmt.Fscan(reader, &N, &S)
	var mp = make(map[byte]uint)
	for _, c := range S { mp[byte(c)] =  1}
	var ans uint = 0
	for i := 1; i < N; i++ {
		var (
			mpF = make(map[byte]uint)
			mpB = make(map[byte]uint)
			res uint = 0
		)
		for j := 0; j < i; j++ { mpF[S[j]] = 1 }
		for j := i; j < N; j++ { mpB[S[j]] = 1}
		for key := range mp {
			_, okF := mpF[key]
			_, okB := mpB[key]
			if okF && okB { res++ }
		} 
		ans = max(ans, res)
	}

	fmt.Fprintln(writer, ans)
}

Measured memory_bytes: 768
package main

import (
	"fmt"
	"log"
)

func main() {
	var a string
	if _, err := fmt.Scan(&a); err != nil {
		log.Fatal(err)
	}

	var oneCnt int
	for _, val := range a {
		if val == '1' {
			oneCnt = oneCnt + 1
		}
	}
	fmt.Println(oneCnt)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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 main(){
    int N, M;
    cin >> N;
    map< string, int> m;
    rep(i, N){
        string S;
        cin >> S;
        m[S]++;
    }
    cin >> M;
    rep(i, M){
        string S;
        cin >> S;
        m[S]--;
    }
    int max = 0;
    for(auto i: m){
        chmax(max, i.second);
    }
    cout << max << endl;



}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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

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

int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  vector<ll> b(n), c(n);
  rep(i, n) b[i] = a[i]+i+1;
  rep(i, n) c[i] = i+1-a[i];

  map<ll, vector<ll>> mp;
  rep(i, n) mp[c[i]].push_back(i);

  ll ans = 0;
  rep(i, n) ans += (ll)distance(upper_bound(ALL(mp[b[i]]), i), mp[b[i]].end());
  cout << ans << endl;
}

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

int main() {
	int a,b;
	cin>>a>>b;
	if(a>b){
		cout<<"a > b"<<endl;
	}if(a==b){
		cout<<"a == b"<<endl;
	}
	if(a<b){
		cout<<"a < b"<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3072
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n//2]
center2 = 0
if not n == 1:
    center2 = b[n//2+1]
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))


Measured memory_bytes: 26184
/***************************************************
	> File Name: Unkown_Error.cpp
	> Author: Zcorpio
	> Mail: 1113043195@qq.com 
	> Created Time: [Data_Deleted]
***************************************************/
#include<bits/stdc++.h>
//#define int long long
#define rint register int
#define mst(a,b) memset(a,b,sizeof(a))
#define go(u) for(int i=head[u],v=to[i];i;v=to[i=nxt[i]])
#define F(i,a,b) for(register int i=(a),i##_end=(b);i<=i##_end;++i)
#define R(i,a,b) for(register int i=(a),i##_end=(b);i>=i##_end;--i)
#define File(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
//const int mod=1e9+7;
//const int mod=998244353;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
/*
template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline bool chkmin(T &a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool chkmax(T &a,T b){return a>b?a=b,1:0;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b)
{while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
inline void write(T k,char ch=0)
{
	if(k<0)k=-k,putchar('-');
	if(k>=10)write(k/10);
	putchar(k%10+'0');
	if(ch)putchar(ch);
}
inline void add(int u,int v)
{
	cnt++;
	nxt[cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
}
*/
inline ll read()
{
	ll x=0;
	bool f=0;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') f=1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return f?-x:x;
}
int main()
{
	//File("");
	ll a=read(),b=read(),c=read();
	ldb len=(ldb)c/a/b*2.0;
	if(len<=a)
	{
		cout<<fixed<<setprecision(8)<<atan(b/len)/3.141592653589793*180.0<<endl;
	}
	else
	{
		len=(ldb)2.0*c/a/a-b;
		cout<<fixed<<setprecision(8)<<atan((ldb)(b-len)/a)/3.141592653589793*180.0<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S)

p = [i + (1 if S[i] == "R" else -1) for i in range(N)]
i = 1
while i < N:
    p = [p[p[j]] for j in range(N)]
    i <<= 1
ans = [0] * N
for i in range(N):
    ans[p[i]] += 1
print(" ".join(map(str, ans)))

Measured memory_bytes: 20756
#include "bits/stdc++.h"
#include <set>
 
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>
 
void print(T x)
{
	std::cout << x << " ";
}
template <typename T>
 
void println(T x)
{
	std::cout << x << "\n";
}
 
int GetDigit(int num) {
	int digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}
 
signed main(void) {
	int a;
	long double b;
	cin >> a >> b;
	long double ans = a * b;
	print((int)ans);
}

Measured memory_bytes: 3724
s = input()
t = input()
m = len(s)
n = len(t)
dp = [[0]*(n+1) for _ in range(m+1)]
for i in range(1,m+1):
    for j in range(1,n+1):
        x = s[i-1]
        y = t[j-1]
        if x == y:
            dp[i][j] = dp[i-1][j-1]+1
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])
res = ""
while n != 0 and m != 0:
    if dp[m][n] == dp[m-1][n]:
        m -= 1
    elif dp[m][n] == dp[m][n-1]:
        n -= 1
    else:
        n -= 1
        m -= 1
        res = s[m] + res
print(res)

Measured memory_bytes: 112220
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;
 
int main(){
    int a, b;
    cin >> a >> b;
    cout << a / b <<" "<< a%b <<" "<< fixed<< setprecision(5)<<(double)a / b << endl;
    return 0;
}

Measured memory_bytes: 3256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }

  sort(all(a));

  map<ll,ll> cnts;
  rep(i,n) {
    ++cnts[a[i]];
  }

  set<ll> seen;
  vector<ll> b;
  for (auto&p : cnts) {
    if (p.second == 1) { // unique
      b.push_back(p.first);
    } else {
      seen.insert(p.first);
    }
  }
  sort(all(b));

  ll ans = 0;
  for (ll v : b) {
    bool found = false;

    ll i = 1;
    while (i*i <= v) {
      if (v%i == 0) {
        // Chekc i and v/i
        if (seen.find(i) != seen.end()) {
          found = true;
          break;
        }
        if (seen.find(v/i) != seen.end()) {
          found = true;
          break;
        }
      }
      ++i;
    }

    if (!found) {
      ++ans;
    }

    seen.insert(v);
  }

  cout << ans << endl;
}


Measured memory_bytes: 28216
n = int(input())
s = input()

import itertools

ans = 0
for x, y, z in itertools.product(range(10), repeat=3):
    pin = str(x) + str(y) + str(z)
    cur = 0
    for i in range(n):
        if s[i] == pin[cur]:
            cur += 1
            if cur == 3:
                break
    if cur == 3:
        ans += 1
    
print(ans)

Measured memory_bytes: 41820
N,Y=map(int, input().split())

for i in range(N+1):
  for j in range(N+1-i):
    if 10000*i+5000*j+1000*(N-i-j)==Y:
      print(str(i)+' '+str(j)+' '+str(N-i-j))
      exit()
        
    
print('-1 -1 -1')


Measured memory_bytes: 9160
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
	int counter[200],m;
	memset(counter, 0, sizeof(counter));
	int i;
	while (cin >> i)
		counter[i]++;
	for (int i = 0; i < 200; i++)
		m = max(counter[i], m);
	for (int i = 0; i < 200; i++)
	{
		if (counter[i] == m)
			cout << i << endl;
	}
}

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

int main() {
	long long int N, M, L;
	while( cin >> N, N ) {
		vector<set<long long int>>d( N );
		for( size_t i = 0; i < N; i++ ) {
			//d[i].insert( i + 1 );
			cin >> M;
			for( size_t j = 0; j < M; j++ ) {
				cin >> L;
				d[i].insert( L );
			}
		}
		cin >> M;
		vector<long long int>x( M );
		for( size_t i = 0; i < M; i++ ) {
			cin >> x[i];
		}
		[&] () {
			long long int ans = -1;
			for( size_t i = 0; i < N; i++ ) {
				auto ret = [&] () {
					for( size_t j = 0; j < M; j++ ) {
						if( d[i].find( x[j] ) == d[i].end() ) {
							return -1LL;
						}
					}
					return (long long int)i + 1;
				}();
				if( ans == -1 ) {
					ans = ret;
				} else {
					if( ret != -1 ) {
						cout << -1 << endl;
						return;
					}
				}
			}
			cout << ans << endl;
			return;
		}();
	}
}

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

int main() {
 	ios::sync_with_stdio(false);
    string s; cin >> s;
  	int n = (int)s.size();
  	int ans = 0;
  	for(int i = 0; i < n / 2; i++) if(s[i] != s[n - i - 1]) ans++; 
  	cout << ans << '\n';
  
  
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

one = sorted(Counter([v[i] for i in range(0, n, 2)]).items(), key=lambda x: x[1], reverse=True)
two = sorted(Counter([v[i] for i in range(1, n, 2)]).items(), key=lambda x: x[1], reverse=True)

#print(one, two)
if one[0][0] != two[0][0]:
	print(n - one[0][1] - two[0][1])
else:
	if len(one) == 1 and len(two) == 1:
		print(n // 2)
	elif len(one) == 1:
		print(n // 2 - two[1][1])
	elif len(two) == 1:
		print(n // 2 - one[1][1])
	else:
		print(min(n - one[0][1] - two[1][1], n - one[1][1] - two[0][1]))

Measured memory_bytes: 20692
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);//高速化、endlは使わない

  int N, K, diff, ans;
  priority_queue<int> Q;
  queue<int> q;

  cin >> N >> K;

  for(int i = 0; i < N; ++i){
    int buff;
    cin >> buff;
    Q.push(buff);
  }
  
  ans = 1000000000;

  for(int i = 0; i < K; ++i){//qの初期化
    q.push(Q.top());
    Q.pop();
  }

  for(int i = 0; i < (N-K+1); ++i){
    diff = q.front() - q.back();
    // cout << "diff: " << diff << endl;
    ans = min(ans, diff);

    q.pop();
    q.push(Q.top());
    Q.pop();
  }

  // cout << "ans: " << ans << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,X,lsd,sum=0;
    cin>>N;
    X=N;
    while(N!=0){
        lsd=N%10;
        sum+=lsd;
        N/=10;
    }
    if(X%sum==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int>s(N);
  for( int i = 0 ; N > i ; i++ ){
    cin >> s.at(i);
  }
  sort( s.begin() , s.end() );
  int b = 0,sum = 0;
  for( int i = 0 ; N > i ; i++){
    if ( s.at(i) > b ){
      b = s.at(i);
      sum++;
    }
  }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
main(){
int N,M,i,j;
cin>>N>>M;
vector<int>D(N);
vector<int>C(M);
for(i=0;i<N;){cin>>D[i++];}
for(i=0;i<M;){cin>>C[i++];}
vector<vector<int> >dp(M+1,vector<int>(N+1,1<<30));dp[0][0]=0;
for(i=0;i<M;i++){for(j=0;j<=N;j++){
if(j==0){dp[i+1][j]=dp[i][j];}
else{dp[i+1][j]=min(dp[i][j],dp[i][j-1]+C[i]*D[j-1]);}}}
cout<<dp[M][N]<<endl;
return 0;}

Measured memory_bytes: 5876
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

int main() {
	// your code goes here
	int n,a=0,b=0,i,j,same=1,ans=0,atleastOne= 0;

	cin >> n;
	string s;
	for(i=0;i<n;i++){
		cin >> s;
		
		for(j=0;j<s.length()-1;j++){
			if(s[j]=='A'&&s[j+1]=='B'){
				ans++;
			}
		}

		int in = 0;
		if(s[s.length()-1]=='A'){
			a++;
			in++;
		}
		if(s[0]=='B'){
			b++;
			in++;
		}
		if(in==1)
			same=0;
		if(in>0)
			atleastOne = 1;
	}
	//cout << "a = "
	if(a==b && atleastOne == 1 && same == 1){
		ans = ans + a - 1;
	}
	else{
		ans = ans + min(a,b);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int d;
  cin >> d;
  if (d == 25) {
    cout << "Christmas"
         << "\n";
  } else if (d == 24) {
    cout << "Christmas Eve"
         << "\n";
  } else if (d == 23) {
    cout << "Christmas Eve Eve"
         << "\n";
  } else {
    cout << "Christmas Eve Eve Eve"
         << "\n";
    return 0;
  }
}

Measured memory_bytes: 256
# n, k = map(int, input().split())
# h = []
# for i in range(n):
#     h.append(int(input()))

# h.sort(reverse=True)
# ans = []
# for i in range(k):
#     if i+k-1 >= n:
#         break
#     ans.append(h[i] - h[i+k-1])
# print(min(ans))

from fractions import gcd
a, b, c, d = map(int, input().split())

def lcm(a):
    LCM = a[0]
    n = len(a)
    for i in range(1, n):
        LCM = LCM * a[i] // gcd(LCM, a[i])
    return LCM

lcm = lcm([c,d])

# a~bまでのうち、cの倍数
modC = b//c - (a-1)//c

# a~bまでのうち、dの倍数
modD = b//d - (a-1)//d

modCD = b//(lcm) - (a-1)//(lcm)

ans = b - a + 1 - modC - modD + modCD
# print(modC)
# print(modD)
# print(modCD)
print(ans)

Measured memory_bytes: 5076
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = scan.nextLong();

    if (b > a){
      long g = b;
      b = a;
      a = g;
    }

    ArrayList<Long> c = new ArrayList<Long>();
    ArrayList<Long> d = new ArrayList<Long>();

    long a1 = (long) Math.sqrt(a);
    long b1 = (long) Math.sqrt(b);

    long a2 = a1;
    long b2 = b1;

    if (a1*a1 == a){
        a2 -= 1;
        c.add(a1);
    }

    if (b1*b1 == b){
        b2 -= 1;
        d.add(b1);
    }

    for (int i = (int) a2; i>=1;i--){
      if (a%i == 0){
        c.add((long) i);
        long t = (long) a/i;
        c.add(t);
      }
    }

    for (int i = (int) b2; i>=1;i--){
      if (b%i == 0){
        d.add((long) i);
        long t = (long) b/i;
        d.add(t);
      }
    }

    ArrayList<Long> f = new ArrayList<Long>();
    for (long gg : c){
      if (d.contains(gg)){
        f.add(gg);
      }
    }
    Collections.sort(f);

    int n = f.size();
    HashSet<Long> m = new HashSet<Long>();
    m.add((long) 1);
    int sum = kk(f,m,1,n);

    System.out.println(sum);





  }

  static long find(long a, long b){
    while (b > 0){
      long remain = (long) a%b;
      a = b;
      b = remain;
    }
    return a;
  }

  static int check(HashSet<Long> a, long b){
    for (long g : a){
      if (find(g,b) != 1){
        return 0;
      }
    }
    return 1;
  }

  static int kk(ArrayList<Long> a, HashSet<Long> b, int current, int n){
    if (current == n){
      return b.size();
    }

    long t = a.get(current);
    if (check(b,t) == 0){
      return kk(a,b,current+1,n);
    }
    else{
      HashSet<Long> m = new HashSet<Long>();
      for (long o : b){
        m.add(o);
      }
      m.add(t);
      int a2 = kk(a,m,current+1,n);
      return a2;
    }
  }

}


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

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int a, b, c, k;
	cin >> a >> b >> c >> k;

	cout << ((k & 1) ? b - a : a - b) << endl;


	return 0;
}






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

using namespace std;

const int MAX_N = 2e5 + 200, INF = 0x3f3f3f3f;

#define lson (p << 1)
#define rson ((p << 1) | 1)
#define mid ((l + r) >> 1)

int n, q, nodes[MAX_N << 2], dp[MAX_N], bi[MAX_N];
vector<int> pset[MAX_N];

void build(int l, int r, int p)
{
    if (l == r)
        return (void)(nodes[p] = INF);
    build(l, mid, lson), build(mid + 1, r, rson);
    nodes[p] = min(nodes[lson], nodes[rson]);
}

int query(int ql, int qr, int l, int r, int p)
{
    if (ql <= l && r <= qr)
        return nodes[p];
    int ret = INF;
    if (ql <= mid)
        ret = min(ret, query(ql, qr, l, mid, lson));
    if (mid < qr)
        ret = min(ret, query(ql, qr, mid + 1, r, rson));
    return ret;
}

void update(int qx, int l, int r, int p, int val)
{
    if (l == r)
        return (void)(nodes[p] = min(nodes[p], val));
    if (qx <= mid)
        update(qx, l, mid, lson, val);
    else
        update(qx, mid + 1, r, rson, val);
    nodes[p] = min(nodes[lson], nodes[rson]);
}

int main()
{
    int zeros = 0;
    scanf("%d", &n), build(1, n, 1);
    for (int i = 1; i <= n; i++)
        scanf("%d", &bi[i]), zeros += (1 - bi[i]);
    scanf("%d", &q);
    while (q--)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        pset[l].push_back(r);
    }
    memset(dp, 0x3f, sizeof(dp)), dp[0] = 0;
    for (int l = 1; l <= n; l++)
    {
        for (int r : pset[l])
        {
            int ret = dp[l - 1];
            ret = min(ret, query(max(l - 1, 1), r, 1, n, 1));
            if (ret < dp[r])
                dp[r] = ret, update(r, 1, n, 1, ret);
        }
        dp[l] = min(dp[l], dp[l - 1] + (bi[l] == 1 ? 1 : -1));
    }
    printf("%d\n", dp[n] + zeros);
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  bool flag = true;
  if( !(1 <= a && a <= 9) || !(1 <= b && b <= 9)) {
    flag = false;
  }
  
  if(flag) cout << a*b << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
    int A, B;
    scanf("%d %d", &A, &B);
    int ans = 0;
    if(A > B)
    {
        ans = A + A - 1;
    }else if(B > A)
    {
        ans = B + B - 1;
    }else{
        ans = A + B;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  REP(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<char> vc;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());

int main(){
	long int N;
	int a,b,c,ans;
	cin>>a>>b>>c;
	if(b/a>c){
		ans=c;
	}
	else{
		ans=b/a;
	}
	cout<<ans;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    array<int, 3> num;
    loop(i, 3){
        scanf("%d", &(num[i])); getchar();
    }
    sort(num.begin(), num.end());
    // A <= B <= C
    auto& A = num[0];
    auto& B = num[1];
    auto& C = num[2];
    set<pair<int, int>> history;
    history.emplace(A, B);
    ll result = 0;
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
        tie(A, B, C) = make_tuple((B + C) / 2, (A + C) / 2, (A + B) / 2);
        sort(num.begin(), num.end());
        // A <= B <= C
        if (history.find(make_pair(A, B)) == history.end()){
            history.emplace(A, B);
        }else{
            printf("%d\n", -1);
            return 0;
        }
        ++result;
    }
    printf("%lld\n", result);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
    int n, q;
    cin>> n;
    vll v(n), cnt(mxn, 0);
    ll sum = 0;
    rep(i, 0, n){
        cin>> v[i];
        cnt[v[i]]++;
        sum += v[i];
    }
    cin>> q;
    while(q--){
        int b, c;
        cin>> b>> c;
        sum -= cnt[b]*(ll)b;
        sum += cnt[b]*(ll)c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout<< sum<< "\n"; 
    }
    return 0;
}
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0;i < n - 2;i++) {
        ans += (s.substr(i, 3) == "ABC");
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	N := sc.nextInt()
	Xs := sc.nextInts()
	sort.Ints(Xs)
	var tmp int
	for _, v := range Xs {
		tmp += v
	}

	minV := Xs[0]
	maxV := Xs[len(Xs)-1]

	minValue := 1234567890123456789
	for j := minV; j <= maxV; j++ {
		var sum int
		for i := 0; i < N; i++ {
			sum += powInt(abs(Xs[i]-j), 2)
		}
		if minValue > sum {
			minValue = sum
		}
	}
	fmt.Println(minValue)
}

/* template functions */
var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}


Measured memory_bytes: 640
#include <stdio.h>
#define NOT_FREE -1
#define FREE 1
#define N 8


void printBoard();
void putQueens(int); 

int Queens[N][N];
int col[N];//縦 
int dpos[N * 2 - 1];//右斜め
int dneg[N * 2 - 1];//左斜め
int row[N];//横

int main(){
    int k, r, c;



    for(int i = 0; i < N; i++){
        col[i] = row[i] = FREE;
        for(int j = 0; j < N; j++){
            Queens[i][j] = 0;
        }
    }

    for(int i = 0; i < 2 * N - 1; i++){
        dpos[i] = dneg[i] = FREE;
    }

    scanf("%d", &k);
    for(int i = 0; i < k; i++){
        scanf("%d%d", &r, &c);
        Queens[r][c] = FREE;
    }

    putQueens(0);

    return 0;
}

void putQueens(int i){
    if(i == N){
        printBoard();
        return;
    }

    for(int j = 0; j < N; j++){
        if(col[j] == NOT_FREE || dpos[i + j] == NOT_FREE || dneg[i - j + N - 1] == NOT_FREE){
            continue;
        }
        row[i] = j;
        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
        putQueens(i + 1);
        col[j] = dpos[i + j] = dneg[i - j + N -1] = FREE;
    }

}

void printBoard(){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(Queens[i][j]){
                if(row[i] != j)return;
            }
        }
    }


    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(row[i] == j)printf("Q");
            else printf(".");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2112
#include <iostream>

using namespace std;


int main() {
     int S;
    cin >> S;
    int s = S % 60;
    S = (S - s) / 60;
    int m = S % 60;
    S = (S - m) / 60;
    int h = S;

    cout << h << ':' << m << ':' << s << endl;
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

bool d[3];
char x, y;

int main()
{
  d[0] = true;
  while(scanf("%c,%c", &x, &y) != EOF){
    swap(d[x-'A'], d[y-'A']);
  }

  if(d[0]) cout << "A" << endl;
  if(d[1]) cout << "B" << endl;
  if(d[2]) cout << "C" << endl;

  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<vector<int>> ab(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> ab.at(i).at(1) >> ab.at(i).at(0);
  }
  vector<vector<int>> cd(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> cd.at(i).at(0) >> cd.at(i).at(1);
  }
  sort(ab.begin(), ab.end());
  reverse(ab.begin(), ab.end());
  sort(cd.begin(), cd.end());
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (cd.at(i).at(1) > ab.at(j).at(0) && cd.at(i).at(0) > ab.at(j).at(1)) {
        ans++;
        ab.at(j).at(0) = 200;
        ab.at(j).at(1) = 200; 
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

int main(){
  int a[100010]={0},n,b[100010]={0},ans = 0;
  
  cin >> n;
  
  for(int i=0;i<n;i++)
    cin >> a[i];
  
 sort(a,a+n);
  
  for(int i=0;i<n;i++){
    
    if( a[i] != a[i-1] ){
      ans ++;
    }
    
  }
  
 if(ans % 2 == 1){
  
  cout << ans << endl;
  
}
  
  else{
    cout << ans -1 << endl;
  }
  
}
  


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

int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	int X[100], Y[100];
	int inin;
	for (int i = 0; i < n; ++i)
	{
		cin >> X[i];
	}
	for (int i = 0; i < m; ++i)
	{
		cin >> Y[i];
	}
	sort(X, X+n);
	sort(Y, Y+m);
	bool ok = 0;
	for (int i = x+1; i <= y; ++i)
	{
		if (i > X[n-1] && i <= Y[0])
		{
			ok = 1;
		}
	}
	cout << (ok?"No War":"War") << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N, A = (int(_) for _ in input().split())
    X = [int(_) for _ in input().split()]

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

    dp[0][0][0] = 1
    for i in range(N):
        for j in range(N):
            for k in range(N*A+1):
                dp[i+1][j][k] += dp[i][j][k]
                if k - X[i] >= 0:
                    dp[i+1][j+1][k] += dp[i][j][k-X[i]]
    ret = 0
    for i in range(1, N+1):
        ret += dp[N][i][i*A]
    print(ret)
    return

if __name__ == '__main__':
    main()


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

ll lcm(ll a, ll b)
{
    ll x = (a/__gcd(a, b));
    return x * b;
}

ll store[107];

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

    for (int i = 1; i <= n; i++) cin >> store[i];

    ll ans = store[1];
    for (int i = 2; i <= n; i++) {
        ans = lcm(ans, store[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}


int main() {
  char c;
  cin >> c;
  if (c - 'a'>=0) cout << 'a' << endl;
  else cout << 'A' << endl;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976
#define MAX_N 100010

int main(){
	lint n,m,s=0;cin>>n>>m;
	LIV a(n);rep(i,n)cin>>a[i],s+=a[i];sort(all(a));m-=s;
	lint ans=m/a[0];cout<<n+ans<<endl;
}

//sub-EOF


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int gole = sc.nextInt();
		int big = sc.nextInt();

		int ans = (gole / big) + (gole % big);

		System.out.println(ans);

	}

}

Measured memory_bytes: 26360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  map<int, map<int, int>> len;
  vector<vi> g(n);
  rep(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    len[u - 1][v - 1] = w;
    len[v - 1][u - 1] = w;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  vi ans(n, -1);
  ans[0] = 0;
  queue<int> q;
  q.push(0);
  while(!q.empty()) {
    int i = q.front();
    q.pop();
    for(auto j : g[i]) {
      int w = len[i][j];
      if(w == -1 || ans[j] != -1) continue;
      if(w % 2)
        ans[j] = !ans[i];
      else
        ans[j] = ans[i];
      q.push(j);
    }
  }
  rep(i, n) cout << ans[i] << endl;
}

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

int main(){
  int a,d,n;

  while(cin>>a>>d>>n&&a|d|n!=0){
    int count=0;
    int prime=a;
    int cnt=0;
    while(count!=n){
      prime = a + d * cnt;
      if(prime==2||prime==3){
        count++;
      }else if(prime%2!=0&&prime>=5){
        for(int i=2;i<=(int)sqrt(prime);i++){
          if(prime%i==0) break;
          if(i==(int)sqrt(prime))count++;
        }
      }
      cnt++;
    }
    cout << prime << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import Control.Applicative
import Data.List
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 整数の入力
    a <- getLine
    -- スペース区切り整数の入力
    l <- map strToInt . words <$> getLine
    -- 出力
    putStrLn $ show $ func l

func :: [Int] -> Int
dup :: Int -> Int
func xs = minimum [dup x | x <- xs]

dup a = if a `mod` 2 /= 0
            then 0
            else 1 + (dup (a `div` 2))


Measured memory_bytes: 1020
#include <stdio.h>

int check(int n1, int n2 , int n3){
	int a,b;
	a = n1*n1;
	b = n2*n2 + n3*n3;
	return (a==b)? 1 : 0 ;
}

int main(){
	int N,n1,n2,n3;

	scanf("%d", &N);
	for(int i=0 ; i<N ; i++){
		scanf("%d %d %d", &n1 , &n2 , &n3);
		if( check(n1,n2,n3)==1 || check(n2,n1,n3)==1 || check(n3,n2,n1)==1){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}

	return 0;
}

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

#define pb push_back
#define lli long long int

int main ()
{
    string a ;
    cin >> a ;

    for (int i = 0 ; i < a.size() ; i++)
    {
        cout << "x" ;
    }

    cout << endl ;
    return 0 ;
}



Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;


int main(){
  int n; cin >> n; ll a[n]; ll cnt[101010] = {};
  ll sum = 0;
  rep(i, n){
    cin >> a[i]; cnt[a[i]]++; sum+=a[i];
  }
  int q; cin >> q; 
  while(q--){
    ll b, c; cin >> b >> c;
    sum-=cnt[b]*b;
    sum+=cnt[b]*c;
    cout << sum << endl;
    cnt[c]+=cnt[b]; cnt[b]=0;
  }  
}


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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()  
{ 
    FAST_INP;
    int n,k; 
    cin >> n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<k;i++){
    	ans+=v[i];
	}
	cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main(){
 int A, B, C, D, a, b;
 cin >> A >> B >> C >> D;
 if(A<=B){
  a = A;
 }else{
  a = B;
 }

 if(C<=D){
  b = C;
 }else{
  b = D;
 }
 cout << a+b << endl;
 return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	string S;
	cin>>S;
	int ans=0;
	for(int i=0;i<3;i++)
		if(S[i]=='o')
			ans++;
	cout<<700+ans*100<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACB061A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            if (c>=a&&c<=b)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092