akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstddef>
#include <utility>
#include <vector>


template <class Abelian> class PotentializedUnionFind {

public:
	using value_type = Abelian;
	using difference_type = std::ptrdiff_t;
	using container_type = std::vector<std::pair<difference_type, value_type>>;
	using const_reference = const value_type &;
	using size_type = typename container_type::size_type;

protected:
	container_type c;

private:
	value_type potential(size_type x) {
		value_type ret = {};
		while (c[x].first >= static_cast<difference_type>(0)) {
			if (c[static_cast<size_type>(c[x].first)].first >=
				static_cast<difference_type>(0)) {
				c[x].second =
					c[static_cast<size_type>(c[x].first)].second + c[x].second;
				c[x].first = c[static_cast<size_type>(c[x].first)].first;
			}
			ret = ret + c[x].second;
			x = static_cast<size_type>(c[x].first);
		}
		return std::move(ret);
	}

public:
	PotentializedUnionFind() : c() {}
	explicit PotentializedUnionFind(const size_type size)
		: c(size, std::make_pair(-1, value_type())) {}

	size_type size() const { return c.size(); }
	bool empty() const { return c.empty(); }

	size_type find(size_type x) {
		assert(x < size());
		while (c[x].first >= static_cast<difference_type>(0)) {
			if (c[static_cast<size_type>(c[x].first)].first >=
				static_cast<difference_type>(0)) {
				c[x].second =
					c[static_cast<size_type>(c[x].first)].second + c[x].second;
				c[x].first = c[static_cast<size_type>(c[x].first)].first;
			}
			x = static_cast<size_type>(c[x].first);
		}
		return x;
	}
	value_type diff(const size_type x, const size_type y) {
		assert(x < size());
		assert(y < size());
		return potential(y) + (-potential(x));
	}
	bool same(const size_type x, const size_type y) {
		assert(x < size());
		assert(y < size());
		return find(x) == find(y);
	}
	size_type size(const size_type x) {
		assert(x < size());
		return static_cast<size_type>(-c[find(x)].first);
	}

	bool unite(size_type x, size_type y, value_type d) {
		assert(x < size());
		assert(y < size());
		d = d + diff(y, x);
		x = find(x);
		y = find(y);
		if (x == y)
			return false;
		if (c[x].first > c[y].first)
		std::swap(x, y), d = -d;
		c[x].first += c[y].first;
		c[y] = std::make_pair(static_cast<difference_type &&>(x), std::move(d));
		return true;
	}
};

#include<iostream>
int main(void) {
	int n, m;
	std::cin >> n >> m;
	PotentializedUnionFind<int> T(n);
	while (m--) {
		int l, r, d;
		std::cin >> l >> r >> d;
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) {
				std::cout << "No" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n;char G[10000];
vector<int>p(26,0),q(26,0);
int main(){
	while(true){
		cin>>n;if(n==0)break;
		for(int i=0;i<n;i++)cin>>G[i];
		for(int i=0;i<26;i++)p[i]=0;
		bool flag=false;
		for(int i=0;i<n;i++){
			p[G[i]-'A']++;q=p;
			sort(q.begin(),q.end());
			if(q[25]-q[24]>=n-i){
				for(int j=0;j<26;j++){
					if(q[25]==p[j])cout<<(char)('A'+j)<<' ';
				}
				cout<<i+1<<endl;flag=true;break;
			}
		}
		if(flag==false)cout<<"TIE"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3160
S = input()

ans = 0
N = len(S)
if S == S[::-1]:
    ans += 1

s2 = S[0:(N - 1) // 2]
if s2 == s2[::-1]:
    ans += 1

s3 = S[(N + 3) // 2 - 1:N]
if s3 == s3[::-1]:
    ans += 1

if ans == 3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
/* ALDS1_10_C: Longest Common Sequence */

#include <iostream>
#include <cstdio>

const int MAX_LENGTH = 1000 + 1;

int max_lcs(char X[], char Y[]) {
    int lcs[MAX_LENGTH + 1][MAX_LENGTH + 1];
    int i, xsize, ysize;

    for(i = 0; X[i]; i++)
        lcs[i][0] = 0;
    xsize = i;

    for(i = 0; Y[i]; i++)
        lcs[0][i] = 0;
    ysize = i;

    for (int ix = 1; ix <= xsize; ix++) {
        for (int iy = 1; iy <= ysize; iy++) {
            if (X[ix - 1] == Y[iy - 1]) {
                lcs[ix][iy] = lcs[ix - 1][iy - 1] + 1;
            }
            else {
                int above = lcs[ix - 1][iy];
                int left  = lcs[ix][iy - 1];
                lcs[ix][iy] = above < left ? left : above;
            }
        }
    }
    return lcs[xsize][ysize];
}

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

    char X[MAX_LENGTH], Y[MAX_LENGTH];
    for (int i = 0; i < n_pairs; i++) {
        scanf("%s\n%s", X, Y);
        printf("%d\n", max_lcs(X, Y));
    }

    return 0;
}

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

class stack
{
    int S[10001], top;
    int MAX;
public:
    stack();
    void initialize(){ top = 0; }
    bool isFull(){ return top >= MAX - 1; }
    bool isEmpty(){ return top == 0; }
    void push(int x){ if(isFull()){ return; } top++; S[top] = x; }
    int pop(){ if(isEmpty()){ return -1; } top--; return S[top + 1]; }
    int front(){ return S[top]; }
    int get_top(){ return top; }
    void docking(){ if(top < 2){ return; } S[top - 1] = S[top - 1] + S[top]; top--; }
    void show();
};

stack::stack() : MAX(10001){}

void stack::show()
{
    if(isEmpty()){ cout << endl; return; }
    for(int i = 1; i <= top; i++) cout << " " << S[i];
    cout << endl;
}

int main()
{
    char data[20000], ch;
    stack stk1, ponds, stk2;
    int i = 0, left, Area = 0;

    stk1.initialize();
    ponds.initialize();
    stk2.initialize();

    cin >> data;

    while(data[i]){
        ch = data[i];
        if(ch == '\\'){
            stk1.push(i);
            stk2.push(i);
        }else if(ch == '/'){
            if(stk1.isEmpty()){ i++; continue; }
            left = stk1.pop();
            Area = Area + i - left;
            ponds.push(i - left);
            while(stk2.front() > left){
                stk2.pop();
                ponds.docking();
            };
        }else{}
        i++;
    };

    cout << Area << endl;
    cout << ponds.get_top();
    ponds.show();

    return 0;
}

Measured memory_bytes: 1236
l,r=map(int,input().split())
m,ans=2019,2018
r=min(r,l+2019*2)
for i in range(l,r+1):
  for j in range(i+1,r+1):
    i%=m
    j%=m
    ans=min(ans,(i*j)%m)
print(ans)


Measured memory_bytes: 65984
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static readonly char[] chars = new[] { '3', '5', '7' };

        static long Solve(long n, string value)
        {
            if (long.Parse(value) > n)
            {
                return 0;
            }

            long ans = 0;
            if (chars.All(c => value.Contains(c)))
            {
                ans++;
            }

            foreach (var c in chars)
            {
                ans += Solve(n, value + c);
            }

            return ans;
        }

        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            Console.WriteLine(Solve(n, "0"));
        }
    }
}

Measured memory_bytes: 17248
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
int main()
{
    fast();
    int n=D();
    string s;
    cin>>s;
    for(int i=0;i<s.length();++i){
        int x=n;
        while(x--){
            if(s[i]=='Z')s[i]='A';
            else
                s[i]++;
        }
    }
    cout<<s<<endl;
}


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int H, W; cin >> H >> W;
    vs s(H); REP(i, H) cin >> s[i];
    REP(i, W+2) cout << "#";
    cout << endl;
    REP(i, H) cout << "#" << s[i] << "#" << endl;
    REP(i, W+2) cout << "#";
    cout << endl;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  int n, l;
  char a[26], s[10010];
  scanf("%d", &n);
  scanf("%s", s);
  l = strlen(s);
  for (int i = 0; i < 26; i++) {
    a[i] = 'A' + (i + n) % 26;
  }
  for (int i = 0; i < l; i++) {
    printf("%c", a[s[i] - 'A']);
  }
  printf("\n");
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
C = sum(A)
Z = {}
for n in range(N):
    Z[A[n]] = 0
for n in range(N):
    Z[A[n]] += 1
D = []
Q = int(input())
for q in range(Q):
    x, y = map(int, input().split())
    if x in Z:
        C = C - x*Z[x]
        C = C + y*Z[x]
        D.append(C)
        if x == y:
            continue
        if y in Z:
            Z[y] += 1*Z[x]
        else:
            Z[y] = Z[x]
        Z.pop(x)
    else:
        D.append(C)
for d in D:
    print(d)


Measured memory_bytes: 21828
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
map<int, int> prime_factor(int n) {
    map<int, int> ret;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }

    if (n != 1) ret[n] = 1;
    return move(ret);
};

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

    map<int, int> factor = prime_factor(P);
    map<int, int> :: iterator it;

    int ret = 1;

    for (it = factor.begin(); it != factor.end(); it++) {
        if (it->second >= N) {
            ret *= pow(it->first, it->second / N);
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 512
until (n, p = gets.split.map(&:to_i)) == [0, 0]
  c = Array.new(n, 0)
  np = p
  i = 0
  while c[i] < p
    if np == 0 then
      np = c[i]
      c[i] = 0
    else
      c[i] += 1
      np -= 1
    end
    i += 1
    i %= n
  end
  puts i
end

Measured memory_bytes: 8536
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
const int maxn=400+10,maxm=100000+10;
int a[maxm],b[maxm];
bool bz[maxn][maxn],p[maxn],czy;
int i,j,k,l,r,t,x,y,n,m,ans;
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,m) scanf("%d%d",&a[i],&b[i]);
	fo(i,1,n){
		p[i]=1;
		bz[i][i]=1;
		fd(j,m,1){
			x=a[j];y=b[j];
			if (!bz[i][x]&&!bz[i][y]) continue;
			if (bz[i][x]&&bz[i][y]){
				p[i]=0;
				break;
			}
			bz[i][x]=bz[i][y]=1;
		}
	}
	fo(i,1,n-1)
		fo(j,i+1,n)
			if (p[i]&&p[j]){
				czy=1;
				fo(k,1,n)
					if (bz[i][k]&&bz[j][k]){
						czy=0;
						break;
					}
				if (czy) ans++;
			}
	printf("%d\n",ans);
}

Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll N, K;
vector<ll> A;
ll dp[22][1010];
void solve(){
  COMinit();
  cin >> N >> K;
  A.resize(K);
  rep(i, K) cin >> A[i];
  dp[0][0] = 1;
  rep(i, K)rep(j, N+1)rep(k, N+1){
    if(j+k>N) continue;
    dp[i+1][j+k] += dp[i][j] * comb(N-j, k) % MOD * comb(N-k, A[i]-k) % MOD;
    dp[i+1][j+k] %= MOD;
  }
  cout << dp[K][N] << endl;
}


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


Measured memory_bytes: 5120
X, N = (map(int, input().split()))
p = list(sorted(map(int, input().split())))
lmin = 10000
if(X not in p):
    print(X)
    exit()
for i in range(1, 200):
    if(X+i in p and X-i in p):
        continue
    if((X-i not in p) and (X+i in p)):
        print(X-i)
        exit()
    elif((X-i in p) and (X+i not in p)):
        print(X+i)
        exit()
    elif((X-i not in p) and (X+i not in p)):
        print(X-i)
        exit()

Measured memory_bytes: 9220
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    // 数値
    let n = {
        let i = read::<isize>();
        (i[0])
    };

    if n == 1 {
        println!("Hello World");
        return;
    }
    let a = {
        let i = read::<isize>();
        (i[0])
    };
    let b = {
        let i = read::<isize>();
        (i[0])
    };

    println!("{}", a + b);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    while(n--)
    {
        int x;
        cin>>x;
        if(x&1)
        {
            cout<<"first"<<endl;
            return 0;
        }
    }
    cout<<"second"<<endl;
    return 0;
}


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

using namespace std;

const int N = 1e5 + 2;

int n, w[N], v[N], s;
long long dp[105][N];

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

    for(int i = 1; i <= n; i ++){
        cin >> w[i] >> v[i];
        for(int j = 1; j <= s; j ++)
            dp[i][j] = dp[i - 1][j];
        for(int j = w[i]; j <= s; j ++){
            dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
        }
    }

    cout << dp[n][s] << endl;
}


Measured memory_bytes: 79360
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 20000;

int N;
vector<int> S;

int d[10] = {2, 3, 4, 5, 6, 8, 9, 10, 12, 14};

void Ans() {
  if (N == 3) {
    vector<int> S2 = {2, 5, 63};
    S = S2;
    return;
  }

  S.push_back(2);
  S.push_back(3);
  S.push_back(5);
  S.push_back(20);
  N -= 4;
  int base = 30;
  while (N >= 21) {
    S.push_back(base);
    REP(i, 10) {
      S.push_back(base+d[i]);
      S.push_back(base+30-d[i]);
    }
    base += 30;
    N -= 21;
  }
  if (N%2 == 1) {
    S.push_back(base);
    --N;
  }
  REP(i, N/2) {
    S.push_back(base+d[i]);
    S.push_back(base+30-d[i]);
  }
  return;
}

signed main() {
  cin >> N;
  S.reserve(kMaxN);

  Ans();

  REP(i, S.size()-1) { cout << S[i] << " "; }
  cout << S[S.size()-1] << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *x, const void *y) {
  return *(double *)x - *(double *)y;
}

int main() {
  int n;
  scanf("%d", &n);
  double v[n], ans=0;
  for (int i=0; i<n; i++) scanf("%lf", v+i);
  qsort(v, n, sizeof(double), cmp);
  ans = v[0];
  for (int i=1; i<n; i++) {
    ans += v[i];
    ans = ans/2;
  }
  printf("%lf\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

ll getrndll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

void solve() {
    int n;
    cin >> n;
    
    vector<pair<int, int>> a;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        
        int b = 0, mn = 0;
        for (int j = 0; j < s.size(); ++j) {
            if (s[j] == '(') ++b;
            else --b;
            relax(mn, b);
        }
        a.emplace_back(b, mn);
    }
    sort(a.begin(), a.end(), [&](pair<int, int> a, pair<int, int> b) {
        return min(a.first + b.second, a.second) > min(b.second, b.first + a.second);
    });
    
    int s = 0, mn = 0;
    for (int i = 0; i < n; ++i) {
        if (s < 0 || s + a[i].second < 0) {
            cout << "No\n";
            return;
        }
        relax(mn, s + a[i].second);
        s += a[i].first;
    }
    
    if (s == 0 && mn == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}



Measured memory_bytes: 11604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);    
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    
    REP(i,h) cin >> s[i];
    REP(i,h){
        REP(j,w){
            if(s[i][j]=='#') {
                cout << '#';
                continue;
            }
            int sum= 0;
            REP(k,9){
                int ii,jj;
                ii= i+k/3-1; jj= j+k%3-1;
                if(ii==-1 || ii==h || jj==-1 || jj==w) continue;
                if(s[ii][jj]=='#') sum++;
            }
            cout << sum;
        }cout << endl;
    }
}

Measured memory_bytes: 256
# 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)
# define UB upper_bound 

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

	int a, b;
	cin >> a >> b;
	cout << max(0LL, a - 2 * b) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


signed main(){
    int x;cin>>x;
    x^=1;
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 3612
public class Main {

  private static void solve() {
    int n = ni();
    int[] d = na(n);

    long ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        ret += d[i] * d[j];
      }
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 20948
#include <stdio.h>
#include <string.h>
 
#define DEF_ELEM_MAX 100000
 
typedef long long llong;
 
int W[DEF_ELEM_MAX];
    int N;
    int K;
/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
// ??????§????????? P ??? k ???°??????????????????§?????????????????????????????????
int check(int P)
{
    int i = 0;
    int j;
    llong s;
 
    for ( j = 0; j < K; j++ ) {
        s = 0;
        while( s + W[i] <= P ) {
            s += W[i];
            i++;
            if ( i == N ) return N;
        }
    }
    return i;
}
 
/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int solve()
{
    llong v;
    llong left = 0;
    llong right = 100000 * 10000; // ???????????????° ?? 1?????????????????????§??????
    llong mid;
 
    while ( right - left > 1 ) {
        mid = (left + right) / 2;
        v = check((int)mid); // mid == P ?????±???????????????????????????????§??????
        if ( v >= N ) {
            right = mid;
        } else {
            left = mid;
        }
    }
 
    return (int)right;
}
 
/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int main(void)
{
    int i;
//
    scanf("%d %d", &N, &K);
    for ( i = 0 ; i < N ; i++ ) {
        scanf("%d", &W[i] );
    }
 
    printf("%d\n", solve());
 
    return 0;
}

Measured memory_bytes: 984
from collections import Counter

S = input()
N = len(S)
mod = [0] * (N+1)
now = 0
for i in range(N):
    now += int(S[N-1-i]) * pow(10,i,2019) % 2019
    now %= 2019
    mod[N-i-1] = now

ans = 0
for l in Counter(mod).values():
    ans += l * (l-1) // 2
print(ans)

Measured memory_bytes: 75968
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	vector<int> l;
	int k, n;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int kari;
		cin >> kari;
		l.push_back(kari);
	}

	sort(l.begin(), l.end());
	reverse(l.begin(), l.end());

	int sum=0;
	for (int i = 0; i < k; i++) {
		sum += l[i];
	}

	cout << sum;

}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n ;
  cin >> n ;
  int a[n] ;
  for(int i=0;i<n;++i)
    cin >> a[i] ;
   sort(a, a+n, greater<int>());


   cout << abs(a[0]-a[n-1]) << "\n" ;

  return 0;
}


Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Thu Mar 12 15:30:03 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

H, W = na()
M = nsn(H)
ans = [[-1] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if M[i][j] != '#':
            cnt = 0
            for a in range(-1, 2):
                for b in range(-1, 2):
                    ni, nj = i + a, j + b
                    if ni >= 0 and ni < H and nj >= 0 and nj < W and M[ni][nj] == '#':
                        cnt += 1
            ans[i][j] = cnt

for i in range(H):
    for j in range(W):
        if ans[i][j] == -1:
            print("#", end="")
        else:
            print(ans[i][j], end="")
    print()

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double pi = 3.14159265359;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

ll a, b, x;

int main()
{
	cin >> a >> b >> x;
	if (a % x) {
		cout << (b / x) - (a / x) << endl;
	}
	else {
		cout << (b / x) - (a / x) + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
    var N = input[0];
	var vals = input[1].split(" ").map(Number);
	var org = input[1].split(" ").map(Number);
  
  	var count = 0;
  	vals.sort((a, b) => {return a - b});
  	for(var i=0; i<N; i++)
    {
      if( vals[i] !== org[i] ) count++;
    }
  
  	var ans = (count<=2) ? "YES" : "NO";
  	//出力
	console.log(ans);
}

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

Measured memory_bytes: 7372
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

n = ni()
a = list(map(int, readall().split()))
l = a[::2]
h = a[1::2]
l.sort()
h.sort()
ml = l[n//2] if n&1 else (l[n//2] + l[n//2-1])
mh = h[n//2] if n&1 else (h[n//2] + h[n//2-1])
print(mh - ml + 1)


Measured memory_bytes: 53048
N=int(input())
S=input()

w = [0] * N
b = [0] * N

if S[0] == '#':
    w[0] = 1
for i in range(1, N):
    if S[i] == '#':
        w[i] = w[i-1] + 1
    else:
        w[i] = w[i-1]

if S[N-1] == '.':
    b[N-1] = 1
for i in range(N-2, -1, -1):
    if S[i] == '.':
        b[i] = b[i+1] + 1
    else:
        b[i] = b[i+1]

m = min(b[0], w[N-1])
for n in range(N-1):
    v = w[n] + b[n+1]
    if v < m:
        m = v
print(m)


Measured memory_bytes: 43872
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
vi dx = {1,1,0,-1,-1,-1,0,1};
vi dy = {0,1,1,1,0,-1,-1,-1};


int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    vector<vector<char>> data(h+2,vector<char>(w+2,'.'));
    rep(i,h){
        rep(j,w){
            cin >>data[i+1][j+1];
        }
    }
    rep(i,h){
        rep(j,w){
            int cnt = 0;
            if(data[i+1][j+1]=='#') cout << '#';
            else{
                rep(k,8){
                    if(data[i+1+dx[k]][j+1+dy[k]]=='#') cnt++;
                }
                cout << cnt;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, A, B = MAP()

print("Alice" if (B-A)%2 == 0 else "Borys")

Measured memory_bytes: 5588
#include <cstdio>
#include <algorithm>
#define maxn 1000010
using namespace std;
int a[maxn],prime[maxn],not_prime[maxn],tot,vis[maxn];
void linear_shaker(int x){
	int i,j;
	for(i=2;i<=x;i++){
		if(!not_prime[i])prime[++tot]=i;
		for(j=1;prime[j]*i<=x;j++){
			not_prime[i*prime[j]]=prime[j];
			if(i%prime[j]==0)break;
		}
	}
}
int main(){
	int n,i,m=0,b,c,cnt=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]),m=max(m,a[i]);
	linear_shaker(m);
	for(i=1;i<=n;i++){
		b=a[i];
		while(not_prime[b]){
			c=not_prime[b];
			vis[c]++,cnt=max(cnt,vis[c]);
			while(b%c==0)b/=c;
		}
		if(b!=1)vis[b]++,cnt=max(cnt,vis[b]);
	}
	if(cnt<=1)printf("pairwise coprime\n");
	else if(cnt<n)printf("setwise coprime\n");
	else printf("not coprime\n");//cnt>=n
	return 0;
}

Measured memory_bytes: 13640
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

counter = Counter(A)

res = 0
for x in counter.keys():
    y = counter[x]
    if y == x:
        continue
    elif y > x:
        res += (y-x)
    else:
        res += y 
print(res)

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

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> kuku(9,vector<int>(9));
    repi(i,1,10) {
        repi(j,1,10) {
            kuku.at(i-1).at(j-1) = i * j;
        }
    }

    repi(i,0,9){
        repi(j,0,9){
            if (N == kuku.at(i).at(j)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> v( n ), c( n ), o( n );
	for ( int i = 0; i < n; i++ ) cin >> v[i];
	for ( int i = 0; i < n; i++ ) cin >> c[i];
	int r = 0;
	for ( int i = 0; i < n; i++ ) {
		if ( v[i] <= c[i] ) continue;
		r += v[i] - c[i];
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
a,b,k=io.read("*n","*n","*n")
for i=1,k do
	if i%2==1 then
		if a%2==1 then a=a-1 end
		b=b+a/2
		a=a/2
	else
		if b%2==1 then b=b-1 end
		a=a+b/2
		b=b/2
	end
end
print(a.." "..b)

Measured memory_bytes: 256
import itertools

N = [ i+1 for i in range(int(input()))]
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
V = []

for v in itertools.permutations(N, len(N)):
    V.append(v)
P_ind = V.index(P)
Q_ind = V.index(Q)

print(abs(P_ind - Q_ind))

Measured memory_bytes: 44912
R, G, B, N = map(int, input().split())
ls = [R, G, B]
ls.sort()
ans = 0
m = ls[-1]
r, g, b = 0, 0, 0
for i in range(N//m+1):
    for j in range((N-m*i)//ls[1] + 1):
        if (N - m*i - ls[1]*j)%ls[0] == 0:
            ans += 1
print(ans)

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int B[N-1];
    REP(i,N-1){
        cin>>B[i];
    }
    int ANS=0;
    ANS+=B[0];
    REP(i,N-2){
        ANS+=min(B[i],B[i+1]);
    }
    ANS+=B[N-2];
    print(ANS);
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
using namespace std;
int next(char s){
    if (s=='a'){
        return 0;
    }
    else if (s=='b'){
        return 1;
    }
    else {
        return 2;
    }
}
int main(){
    string sa,sb,sc;
    cin >> sa >> sb >> sc;
    int x=sa.size();
    int y=sb.size();
    int z=sc.size();
    int a=0,b=0,c=0;
    int turn=0;
    while(true){
        if (turn==0){
            if (a==x){
                cout << "A" ;
                exit(0);
            }
            else {
                turn =next(sa[a]);
                a++;
            }
        }
        else if (turn ==1){
            if(b==y){
                cout << "B";
                exit(0);
            }
            else {
                turn =next(sb[b]);
                b++;
            }
        }
        else if (turn==2){
            if (c==z){
                cout <<"C";
                exit(0);
            }
            else {
                turn=next(sc[c]);
                c++;
            }
        }
    }
}

Measured memory_bytes: 256
/*
	In the name of ALLAH
	Author : Raashid Anwar
*/

#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define mod 1000000007


int power(int a,int b) {
	int r=1;
	while(b) {
		if(b&1)
			r=(r*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return r;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,cnt=0;
	string s;
	cin>>n;
	cin>>s;
	for(int i=0;i<=n-3;i++)
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
			cnt++;
	cout<<cnt<<"\n";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    String x = in.next();
    if (x.charAt(1) == 'R') {
      out.println("ABC");
    } else {
      out.println("ARC");
    }
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


Measured memory_bytes: 32876
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << setprecision(7) << (x) << endl;

long double pi = 3.14159265359;
int n,cnt=0;
string s;

int main(){
    cin >> n;
    cin >> s;
    rep(i,s.size()-1){
        if(s[i] != s[i+1]){
            cnt++;
        }
    }
    cout << cnt+1 << endl;


return 0;
}

Measured memory_bytes: 3760
import java.util.PriorityQueue;
import java.util.Scanner;

class Pair implements Comparable<Pair> {
	int cnt;
	int num;

	Pair(int cnt, int num) {
		this.cnt = cnt;
		this.num = num;
	}

	@Override
	public int compareTo(Pair o) {
		if (this.num > o.num) return -1;
		else if (this.num < o.num) return 1;
		return 0;
	}
}

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			PriorityQueue<Pair> a = new PriorityQueue<>();

			for (int i = 0; i < n; i++) a.add(new Pair(1, sc.nextInt()));
			for (int i = 0; i < m; i++) a.add(new Pair(sc.nextInt(), sc.nextInt()));

			long sum = 0;
			int cnt = 0;
			while (cnt < n) {
				Pair pair = a.poll();
				for (int i = 0; i < pair.cnt; i++) {
					sum += pair.num;
					cnt++;
					if (cnt >= n) break;
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 102768
#include<stdio.h>
int main(void)
{
	int a[1000],b[1000],c[1000],d,i,j,m,n;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++) c[i]=0;
	for(i=1;i<=m;i++){
		scanf("%d",&a[i]);
		}
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&b[j]);
			if(b[j]==a[i]) c[j]++;
			else	{
				d=a[i];
				c[d]++;
			}
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",c[i]); 
	}
	return 0;
}
	
	
	


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
    if (ch=='A') return 1;
    else if(ch=='C') return 2;
    else if(ch=='G') return 3;
    else if(ch=='T') return 4;
    else return 0;
}

// 文字列から数値へ変換してkeyを生成する
long long getKey(char str[]) {
    long long sum=0, p=1, i;
    for (i=0; i<strlen(str); i++) {
        sum += p*getChar(str[i]);
        p *= 5;
    }
    return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1+key%(M-1); }

int find(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for (i=0; ; i++) {
        h = (h1(key) + i*h2(key)) % M;
        if( strcmp(H[h], str) == 0) return 1;
        else if( strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for (i=0; ; i++) {
        h = (h1(key) + i*h2(key)) % M;
        if( strcmp(H[h], str) == 0) return 1;
        else if( strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main() {
    int i, n, h;
    char str[L], com[9];
    for (i=0; i<M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf("%s %s", com, str);
        
        if(com[0] == 'i') {
            insert(str);
        } else {
            if(find(str)) {
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 16988
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

template<class T>T gcd(T a, T b){if(a<b){a^=b;b^=a;a^=b;}return b?gcd(b,a%b):a;}
template<class T>T lcm(T a, T b){return a/gcd(a,b)*b;}

int K;

int main(){
    cin>>K;

    int ans=0;
    repn(i,K){
        repn(j,K){
            repn(l,K){
                ans+=gcd(gcd(i,j),l);
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3636