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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30

int main()
{
	int N, M;
	vector<mii> v;
	vector<pii> py;
	int P, Y;

	cin >> N >> M;
	v.resize(N+1);
	py.resize(M);
	rep(i,M){
		cin >> P >> Y;
		py[i] = mp(P, Y);
		v[P][Y] = 0;
	}
	rep(i,N+1){
		int cnt = 1;
		for(auto &iter : v[i]){
			iter.second = cnt;
			cnt++;
		}
	}

	rep(i,M){
		P = py[i].first;
		Y = py[i].second;
		printf("%06d%06d\n", P, v[P][Y]);
	}

	return 0;
}


Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<lint, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const lint INF = 1LL << 60;

struct Edge {
    int to, cost;
};

vector<vector<Edge>> g;
vec dist;

void dijkstra(int r) {
    fill(all(dist), INF);
    dist[r] = 0;

    priority_queue<pint, vector<pint>, greater<pint>> que;
    que.push(pint(0, r));

    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        int v = p.second;

        if (dist[v] < p.first) continue;

        for (auto&& e : g[v]) {
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                que.push(pint(dist[e.to], e.to));
            }
        }
    }
}

int main() {
    int v, e, r;
    cin >> v >> e >> r;
    g.resize(v);
    rep(i, e) {
        int s, t, d;
        cin >> s >> t >> d;
        g[s].push_back((Edge){t, d});
    }

    dist.resize(v);
    dijkstra(r);

    rep(i, v) {
        if (dist[i] == INF) cout << "INF" << endl;
        else cout << dist[i] << endl;
    }

    return 0;
}


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

const int tam=1e5+5;
const int oo=1e9;

int N, memo[tam], h[tam];

int f(int i){
    if(i==N-1) return 0; //Caso base
    if(memo[i] != -1) return memo[i]; //Caso dp

    int ans= f(i+1)+abs(h[i]-h[i+1]);
    if(i+2 < N) ans= min(ans, f(i+2)+abs(h[i]-h[i+2]));
    return memo[i]=ans;

}


int main(){

    cin>>N; 
    memset(memo, -1, sizeof memo);
    for (int i = 0; i < N; i++) cin>>h[i];

    cout<<f(0)<<endl;

    // for (int i = 1; i <= N; i++)
    // {
    //     cout<<memo[i]<<' ';
    // }

    return 0;

}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  string Ans="NO";
  if(A==5){
    if(B==5){
      if(C==7){
        Ans="YES";
      }
    }
    if(B==7){
      if(C==5){
        Ans="YES";
      }
    }
  }
  if(A==7){
    if(B==5 && C==5){
      Ans="YES";
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
n = int(input())
w = [input() for _ in range(n)]

if len(set(w)) != n:
	print("No")
else:
	ok = True
	for i in range(n - 1):
		if w[i][-1] != w[i + 1][0]:
			ok = False
			break
	if ok:
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << 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; }

using namespace std;

int main(){
    ll H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (W % 2 == 0) {
        cout << H * (W/2) << endl;
    } else if (H % 2 == 0) {
        cout << (H / 2) * (W/2) + (H / 2) * (W/2 + 1) << endl;
    } else {
        cout << (H / 2) * (W/2) + (H / 2 + 1) * (W/2 + 1) << endl;
    }

}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d %d', $inputArticles, $inputDiscountCoupons);

$inputPriceStr    = trim(fgets(STDIN));
$articlePriceList = explode(' ', $inputPriceStr);

//優先度付きキュー
$articlesPriceQueue = new SplPriorityQueue();
$articlesPriceQueue->setExtractFlags(SplPriorityQueue::EXTR_PRIORITY);

//商品の値段を追加する
foreach ($articlePriceList as $price){
    $articlesPriceQueue->insert('', $price);
}

//クーポンを高い品物順に使用
$discountTimes = 0;
foreach ($articlesPriceQueue as $articlePrice){

    if ($discountTimes >= $inputDiscountCoupons){
        break;
    }

    $discountPrice = floor($articlePrice / 2);
    $articlesPriceQueue->insert('', $discountPrice);

    $discountTimes++;
}

//合計金額
$sum = 0;
foreach ($articlesPriceQueue as $articlePrice){
    $sum += $articlePrice;
}

echo $sum. PHP_EOL;

Measured memory_bytes: 72892
#include <stdio.h>

int n, A[30];
 
int solve(i, m){
    int res;
    if (m == 0) {
        return 1;
    } else if (i >= n) {
        return 0;
    }
    res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}
 
int main(){
    int q, m, j;
    scanf("%d", &n);
    for (j = 0; j < n; j++) {
        scanf("%d", &A[j]);
    }
    scanf("%d", &q);
    for (j = 0; j < q; j++) {
        scanf("%d", &m);
        if (solve(0, m)) {
            printf("yes\n");
        } else {
            printf("no\n");
        }       
    }
    return 0;
}


Measured memory_bytes: 2044
import java.util.*;

class Main {

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		for(int rept=0; rept<3; rept++){
			int come = toSec(in.nextInt(), in.nextInt(), in.nextInt());
			int out  = toSec(in.nextInt(), in.nextInt(), in.nextInt());
			int ans[] = toDate(out - come);
			System.out.println(ans[0] + " " + ans[1] + " " + ans[2]);
		}
		return ;
	}
	
	static int toSec(int h, int m, int s){
		return h*60*60 + m*60 + s;
	}
	
	static int[] toDate(int sec){
		int ret[] = new int[3];
		ret[0] = sec/3600;
		ret[1] = (sec%3600)/60;
		ret[2] = sec%60;
		return ret;
	}
	
}

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

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

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

void swap(int a,int b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main(void) {
	int l;
	cin >>l;

	double a = double(l) / 3;

	printf("%f",a*a*a);
	return 0;
}

Measured memory_bytes: 3676
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>

typedef long long LL;

int read() {
  int ans = 0, c, f = 1;
  while (!isdigit(c = getchar()))
    if (c == '-') f *= -1;
  do ans = ans * 10 + c - '0';
  while (isdigit(c = getchar()));
  return ans * f;
}

int main() {
  int n = read();
  if (n & (n - 1)) {
    puts("Yes");
#define link(a, b) printf("%d %d\n", a, b)
    link(1, 2); link(2, n+3); link(n+3, n+1);
    link(n+1, n+2); link(n+2, 3);
    for (int i = 4; i < n; i += 2) {
      link(n+1, i); link(i, i+1);
      link(n+1, n+i+1); link(n+i, n+i+1);
    }
    if (~n & 1) {
      int k = 1;
      while ((k << 1) < n) k <<= 1;
      link(n, k);
      link(n+n, n+(n^1^k));
    }
  } else {
    puts("No");
  }
}


Measured memory_bytes: 2688
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

# 0-indexed BIT
class BIT:
    def __init__(self, li):
        self.n, self.data = len(li) + 1, [0] + li
        for i in range(1, self.n):
            if i + (i & -i) < self.n: self.data[i + (i & -i)] += self.data[i]

    def add(self, i, a):
        i += 1
        while i < self.n:
            self.data[i] += a
            i += i & -i

    # sum of [0, i)
    def acc(self, i):
        res = 0
        while i > 0:
            res += self.data[i]
            i -= i & -i
        return res

    # sum of [l, r)
    def get(self, l, r = None):
        if r is None: r = l+1
        return self.acc(r) - self.acc(l)


def main():
    N, Q = LI()
    C = LI()
    lr = sorted(enumerate(LIR(Q)), key=lambda x: x[1][1])
    rightmostIndex = [-1]*(N+1)
    tree = BIT([0]*N)
    left, right = 0, 0
    ans = [None] * Q

    for i, (l, r) in lr:
        while right < r:
            if rightmostIndex[C[right]] < 0:
                rightmostIndex[C[right]] = right
            else:
                tree.add(rightmostIndex[C[right]], -1)
                rightmostIndex[C[right]] = right
            tree.add(right, 1)
            right += 1

        ans[i] = tree.get(l-1, r)


    print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Measured memory_bytes: 239592
MOD = int(1e9)+7


def main():
    n, K = map(int, input().split())
    a = list(map(int, input().split()))

    # dp[i][j] is the number of ways to distribute j candies to first i people
    dp = [[0]*(K+1) for i in range(n+1)]
    prefix = [[0]*(K+1) for i in range(n+1)]
    prefix[0] = [1]*(K+1)
    for i in range(1, n+1):
        for j in range(K+1):
            start = j - min(a[i-1], j)-1
            end = j
            dp[i][j] = (prefix[i-1][end] - \
                (prefix[i-1][start] if start >= 0 else 0))%MOD
            prefix[i][j] = (prefix[i][j-1] + dp[i][j]) % MOD

    print(dp[n][K]%MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 192792
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <cstring>
#include <sstream>
using namespace std;

int main()
{
	int K = 0, S = 0;
	cin >> K >> S;
	long long sum = 0;

	for(int x = 0; x <= K; x++){
		for(int y = 0; y <= K; y++){
			if(x + y <= S && x + y + K >= S) sum++;
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    __int128 ans=1;
    ll n;cin >> n;ll a[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];if(a[i]==0){cout << 0;return 0;}
        
    }
    for (int i = 0; i < n; ++i)
    {
        ll d=a[i];ans*=d;
        if(ans>1000000000000000000){cout << -1;return 0;}
    }
    if(ans>1000000000000000000){cout << -1;return 0;}
    cout << (ll)ans;
    }

Measured memory_bytes: 4392
n = int(input())

res_cnt = 0
for i in range(1, n + 1):
    if i % 2 == 0:
        continue
    cnt = 0
    for j in range(1, i + 1):
        if i % j == 0:
            cnt += 1
    if cnt == 8:
        res_cnt += 1

print(res_cnt)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main() {
	int R, G, B , N;
	int count = 0;

	cin >> R >> G >> B >> N;

	for (int r = 0; r <= N; r += R) {
		for (int g = 0; g + r <= N; g += G) {
			int b = N - r - g;
			if (b < 0) {
				continue;
			}
			if (b % B != 0) {
				continue;
			}
			count ++;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>

using namespace std;

int gcd(int n, int m) {
    if (n == 0) return m;
    return gcd(m % n, n);
}

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

    priority_queue<int, vector<int>, greater<>> a;
    vector<pair<int, int>> b_c(M);
    for (int i = 0; i < N; ++i) {
        int tmp;
        cin >> tmp;
        a.push(tmp);
    }

    for (int i = 0; i < M; ++i) {
        int b,c;
        cin >> b >> c;
        b_c[i] = make_pair(b, c);
    }

    sort(b_c.begin(), b_c.end(), [](const auto a, const auto b) {
        return a.second > b.second;
    });

    for (int i = 0; i < M; ++i) {
        if (a.top() >= b_c[i].second) break;

        for (int j = 0; j < b_c[i].first; ++j) {
            if (a.top() >= b_c[i].second) break;
            a.push(b_c[i].second);
            a.pop();
        }
    }

    uint64_t ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += a.top(); a.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 1660
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int count = 0,count1 = 0;
    while(a > 0)
    {
        a -= d;
        count++;
    }
    while(c>0)
    {
        c -= b;
        count1++;
    }
    if(count>=count1)
        cout << "Yes";
    else
    {
        cout << "No";
    }
    
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n, k, s;
    cin >> n >> k >> s;
    vector<int> ans(n);
    for(int i = 0; i <= n; ++i) {
        if(i < k) {
            ans[i] = s;
        }else{
            if(s != 1e9) {
                ans[i] = s+1;
            }else {
                ans[i] = 1;
            }
        }
    }

    for(auto i : ans) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main (){
    
    int a,b,c;
    
    cin >> a >> b >> c ;
    
    if ((a<b)&&(c>b)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>

int main (void){
  int W, H, x, y, r;

  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if(x - r >= 0 && y - r >= 0 && r + x <= W && r + y <= H){
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

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

using namespace std;

int main(void)
{
    char s[2000];
    char t[2000];
    cin>>s;
    cin>>t;

    int len = strlen(s);
    int lent = strlen(t);
    int ans = lent;
    int w = 0;

    for(int i = 0; i < len-lent+1; i++){
        w = 0;
        for(int j = 0; j < lent; j++){
            if(s[i+j] != t[j]) w++;
            //cout<<"i = "<<i<<", j = "<<j<<endl;
        }
        if(w < ans) ans = w;
    }
    cout<<ans<<endl;
}

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

struct UnionFind
{
    vector<int> par;  // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1)
    {
        init(n);
    }

    void init(int n = 1)
    {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; ++i)
            par[i] = i, rank[i] = 0;
    }

    int root(int x)
    {
        if (par[x] == x)
        {
            return x;
        }
        else
        {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (rank[x] < rank[y])
            swap(x, y);
        if (rank[x] == rank[y])
            ++rank[x];
        par[y] = x;
        return true;
    }
};

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int> > xlist(n), ylist(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        xlist[i] = make_pair(a, i);
        ylist[i] = make_pair(b, i);
    }
    sort(xlist.begin(), xlist.end());
    sort(ylist.begin(), ylist.end());

    vector<pair<ll, pair<int, int> > > difflist;
    for (int i = 0; i < n - 1; i++) {
        int xdiff = xlist[i + 1].first - xlist[i].first;
        int ydiff = ylist[i + 1].first - ylist[i].first;
        difflist.push_back(make_pair(xdiff, make_pair(xlist[i + 1].second, xlist[i].second)));
        difflist.push_back(make_pair(ydiff, make_pair(ylist[i + 1].second, ylist[i].second)));
    }
    sort(difflist.begin(), difflist.end());

    ll ans = 0;
    UnionFind uf(n);
    for (pair<int, pair<int, int> > p : difflist) {
        if (!uf.issame(p.second.first, p.second.second)) {
            uf.merge(p.second.first, p.second.second);
            ans += p.first;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8988
using System;
using System.Linq;

namespace _1609
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int[] points = new int[26]; char[] person = new char[26];
                for (int i = 0; i < 26; i++) person[i] = (char)('A' + i);
                char[] c = Console.ReadLine().Split().Select(char.Parse).ToArray();
                bool ended = false;
                for (int i = 1; i <= n; i++)
                {
                    points[Array.IndexOf(person,c[i - 1])]++;
                    Array.Sort(points,person);
                    if (points[25] > points[24] + n - i)
                    {
                        Console.WriteLine(person[25] + " " + i);
                        ended = true;
                        break;
                    }
                }
                if (!ended) Console.WriteLine("TIE");
            }
        }
    }
}


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

main() {
    int A,B; cin >> A >> B;
    cout << A*B-A-B+1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i) - 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, P: int):
    print((3*A+P)//2)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    solve(A, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<cstdio>
#include<vector>
#define pb push_back
const int MaxN=100010,mod=10000019;
int N,a[MaxN],b[MaxN],c[MaxN],d[MaxN];
struct item{
	int ty,u,v,x;item*next;
	bool eq(int a,int b){return u==a&&v==b||u==b&&v==a;}
	int h(){return(1ll*(u<v?u:v)*N+(u>v?u:v))%mod;}
}E1[MaxN],E2[MaxN],*fir[mod];
int op[MaxN],Q[MaxN],*head=Q,*tail=Q;
void mov(item*e,int x,int y){
	item*it=fir[e->h()];
	if(it==e)fir[e->h()]=e->next;
	else if(it){
		while(it->next!=e)it=it->next;
		it->next=e->next;
	}
	e->u=x;e->v=y;
	e->next=fir[e->h()];
	fir[e->h()]=e;
}
struct edge{int id,to;edge*rev,*next;};
struct tree{
	edge E[MaxN*2],*ne=E,*first[MaxN];
	int deg[MaxN];
	bool del[MaxN];
	void link(int id,int u,int v){
		*ne=(edge){id,v,ne+1,first[u]};first[u]=ne++;
		*ne=(edge){id,u,ne-1,first[v]};first[v]=ne++;
		deg[u]++;deg[v]++;
	}
	void rm(int e,int u,int v){
		del[e]=1;
		deg[u]--;deg[v]--;
	}
	void mig(int u,int v,bool ty){ // u->v
		for(edge*e=first[u],*ex;e;e=ex){
			ex=e->next;
			if(del[e->id])continue;
			e->rev->to=v;
			int&x=(ty?c:a)[e->id],&y=(ty?d:b)[e->id];
			x==u?x=v:y=v;
			if(ty){
				mov(E2+e->id,x,y);
				if(!op[e->id])
					for(item*it=fir[E2[e->id].h()];it;it=it->next)
						if(!it->ty&&it->eq(x,y))op[*tail++=e->id]=it->x;
			}
			else{
				mov(E1+e->id,x,y);
				for(item*it=fir[E1[e->id].h()];it;it=it->next)
					if(it->ty&&!op[it->x]&&it->eq(x,y))op[*tail++=it->x]=e->id;
			}
			e->next=first[v];
			first[v]=e;
		}
		deg[v]+=deg[u];
		deg[u]=0;
	}
}T1,T2;
bool get_dup(int&e1,int&e2){
	if(head==tail)return 0;
	e1=op[e2=*head++];
	return 1;
}
bool solve(){
	for(int i=1;i<N;i++){
		E1[i]=(item){0,a[i],b[i],i,0};
		E1[i].next=fir[E1[i].h()];
		fir[E1[i].h()]=E1+i;
	}
	for(int i=1;i<N;i++){
		E2[i]=(item){1,c[i],d[i],i,0};
		for(item*it=E2[i].next=fir[E2[i].h()];it;it=it->next)
			if(it->eq(c[i],d[i])&&!op[i])op[*tail++=i]=it->x;
		fir[E2[i].h()]=E2+i;
	}
	for(int t=N;--t;){
		int e1,e2,u,v;
		if(!get_dup(e1,e2))return 0;
		u=a[e1],v=b[e1];
		T1.rm(e1,u,v);
		T2.rm(e2,u,v);
		if(T1.deg[u]+T2.deg[u]>T1.deg[v]+T2.deg[v]){
			int w=u;u=v;v=w;
		}
		T1.mig(u,v,0);
		T2.mig(u,v,1);
	}
	return 1;
}
int main(){
	scanf("%d",&N);
	for(int i=1;i<N;i++)scanf("%d%d",a+i,b+i),T1.link(i,a[i],b[i]);
	for(int i=1;i<N;i++)scanf("%d%d",c+i,d+i),T2.link(i,c[i],d[i]);
	puts(solve()?"YES":"NO");
}

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

using namespace std;

bool isValid(int N, vector<int>& A){
    unordered_set<int> s(A.begin(), A.end());
    
    bool allOdd = all_of(s.begin(), s.end(), [](int i){ return i%2 != 0; });
    bool allEven = all_of(s.begin(), s.end(), [](int i){ return i%2 == 0; });

    return (s.size() == N/2 && N%2 == 0 && allOdd) ||
           (s.size() == N/2 + 1 && N%2 != 0 && allEven);
}

int modPow(int base, int power){
    int ans = 1;
    
    for(int i=0; i<power; i++){
        ans = (ans * base) % 1000000007;
    }

    return ans;
}

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


    int N;
    cin >> N;

    vector<int> A(N);
    int zeroes = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        if(A[i] == 0){
            zeroes++;
        }
    }
    
    if(isValid(N, A) && zeroes <= 1) {
        cout << modPow(2, N/2) << "\n"; 
    }else{
        cout << 0 << "\n";
    }

    return 0;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;

int main(){
  int A,B,M,ans,min_a,min_b;
  cin>>A>>B>>M;
  vec a(A);
  vec b(B);
  vec x(M);
  vec y(M);
  vec c(M);
  min_a = 300000;
  min_b = 300000;
  rep(i,A){
    cin>>a.at(i);
    if(a.at(i)<min_a)min_a = a.at(i);
  }
  rep(i,B){
    cin>>b.at(i);
    if(b.at(i)<min_b)min_b = b.at(i);
  }
  ans = 300000;
  rep(i,M){
    int total;
    cin>>x.at(i)>>y.at(i)>>c.at(i);
    total = a.at(x.at(i)-1)+b.at(y.at(i)-1)-c.at(i);
    if(total<ans)ans = total;
  }
  if(ans>(min_a+min_b))ans = min_a+min_b;


  cout<<ans<<endl;
}


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


int main()
{
  long int sum;
  int i;
  long int count,tmp=0;
  cin >> sum;
  count = sum;
  for(i=0;i<10;i++)
  {
    tmp += sum % 10;
    sum /=10;
    if(sum==0)break;
  }
  if(count%tmp==0) cout <<"Yes"<<endl;
  else cout <<"No"<<endl;

}


Measured memory_bytes: 256
while 1:
    try:
        s=input()
        s_c=""
        c1=[" ",".",",","-","'","?"]
        for i in s:
            if 64<ord(i)<91:
                s_c+=str(bin(ord(i)-65)[2:]).zfill(5)
            else:
                s_c+=str(bin(c1.index(i)+26)[2:]).zfill(5)

        ch_3=["101","110","111"]
        re_3=[" ","E","P"]
        ch_4=["0101","0001","0111","0110","1000"]
        re_4=["C","D","I","K","R"]
        ch_5=["01001","00100","00101","00110","00111"]
        re_5=["F","L","O","S","T"]
        ch_6=["000000","000011","010001","000001","100101","010000","000010"]
        re_6=["'",",",".","?","A","H","W"]
        ch_8=["10010001","10011010","10011011","10011000","10011001","10011110","10011111","10011100","10011101","10010010","10010011","10010000"]
        re_8=["-","B","G","J","M","N","Q","U","V","X","Y","Z"]
        ans=""
        while 1:
            if len(s_c)==0 or len(s_c)<5 and int(s_c)==0:break
            elif s_c[:3] in ch_3:
                ans+=re_3[ch_3.index(s_c[:3])]
                s_c=s_c[3:]
            elif s_c[:4] in ch_4:
                ans+=re_4[ch_4.index(s_c[:4])]
                s_c=s_c[4:]
            elif s_c[:5] in ch_5:
                ans+=re_5[ch_5.index(s_c[:5])]
                s_c=s_c[5:]
            elif s_c[:6] in ch_6:
                ans+=re_6[ch_6.index(s_c[:6])]
                s_c=s_c[6:]
            elif s_c[:8] in ch_8:
                ans+=re_8[ch_8.index(s_c[:8])]
                s_c=s_c[8:]
            else:
                s_c+="0"
        print(ans)
    except:break


Measured memory_bytes: 5624
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
long long i,n,c,d,m;
vector<long long> a;
int main()
{
	cin >> m >> n;
	for ( i = 0 ; i < n ; i++ ) 
	{
		cin >> c;
		a.push_back(c);
	}
	c = m; d = m;
	while ( find(a.begin(),a.end(),c) != a.end() ) 
	{
		c--;
	}
	while ( find(a.begin(),a.end(),d) != a.end() ) 
	{
		d++;
	}
	c = m-c; d-=m;
	if ( c <= d ) cout << m-c;
	else cout << m+d;
}

Measured memory_bytes: 3136
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  getline(cin, s);
  for (auto& c : s) {
    if (isupper(c)) c = tolower(c);
    else if (islower(c)) c = toupper(c);
  }
  cout << s << endl;
  return 0;
} 



Measured memory_bytes: 3184
<?php

[$N, $D, $A] = fscanf(STDIN, "%d%d%d");
$mons = [];
for($i=0;$i<$N;$i++){
    [$x, $h] = fscanf(STDIN, "%d%d");
    $mons[$x] = $h;
}
ksort($mons);
$k = [[-1,0]];
$know = 0;
$kmax = 0;
$ksum = 0;
$ans = 0;
foreach($mons as $x => $h){
    for($j=$know;$j<=$kmax;$j++){
        if($x> $k[$j][0]) {
            $ksum -= $k[$j][1];
            if($know == $kmax){
                $kmax++;
                $k[$kmax] = [-1, 0];

                $know++;
                break;
            }else{
                $know++;
            }


        }elseif($x <= $k[$j][0]){
            break;
//        }elseif($x == $k[$j][0]){
//            $h-= $k[$j][1];
//            if($h<=0){
//                continue 2;
//            }
//            $know++;
        }
    }
    $h -= $ksum;
    if($h <= 0){
        continue;
    }
    $hiku = intdiv($h + $A - 1, $A);

    $ans += $hiku;
//    for($j=$know;$j<=$kmax;$j++){
//        $k[$j][1] += $hiku*$A;
//    }
    $kmax++;
    $ksum += $hiku * $A;
    $k[$kmax] = [$x + $D +$D, $hiku * $A];
}
echo $ans;

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

int main() {
  int K;
  cin >> K;
  int ans=-1;
  
  int mod= 7777777%K;
  int amari=70000000%K;
  
  if(7%K==0)ans =1;
  else if(77%K==0)ans=2;
  else if(777%K==0)ans=3;
  else if(7777%K==0)ans=4;
  else if(77777%K==0)ans=5;
  else if(777777%K==0)ans=6;
  else if(7777777%K==0)ans=7;
  else if(K%2!=0 && K%5!=0){
    for(int i=8; i<=K; i++){
      mod += amari;
      mod =  mod%K;
      if(mod==0){
        ans=i;
        break;
      }
      
      amari = amari*10%K;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    long N;
    cin >> N;
 
    for (long h=1; h<=3500; h++) {
        for (long n=1; n<=3500; n++) {
            long double tmp = 4 * h * n - N * n - N * h;
            if (tmp <= 0) continue;
            long double w = N * h * n / tmp;
            if (ceil(w) == floor(w)) {
                cout << h << " " << n << " " << (long)w << endl;
                return 0;
            }
        }
    }
}


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

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

    if((S.at(2)==S.at(3)) && (S.at(4)==S.at(5))){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    if(s == "a" || s == "e" || s == "i" || s == "o" || s == "u")
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
    return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_f

#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << "  = " << x << endl
typedef long long int ll;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

#define dbg2(x, y)                                                       \
    {                                                                    \
        cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; \
    }
#define fo(i, n) for (int i = 0; i < n; i++)
#define fok(i, k, n) for (int i = k; i < n; i++)
#define foA(i, A) for (auto i : A)
const int mxN=100005;
vector<int>adj[mxN];
bool vis[mxN];
int pth[mxN];
int ans=0;

int dfs(int u){
    // dbg2(u, 1);
    vis[u]=1;
    for(int v:adj[u]){
        // dbg2(v, pth[v]);deb(vis[v]);
        if(vis[v]==1){
            pth[u]=max(pth[u], pth[v]+1);
            continue;
        }
        pth[u]=max(pth[u], dfs(v)+1);
        // dbg2(v, pth[v]);
    }
    return pth[u];
}

int main(){
    fast;int n, m;
    cin>>n>>m;
    fo(i, m){
        int x,y;cin>>x>>y;
        adj[x].push_back(y);
    }
    fo(i, n){
        if(vis[i+1]==0)dfs(i+1);
    }
    fo(i, n)ans=max(ans, pth[i+1]);
    cout<<ans;
}

Measured memory_bytes: 7552
#include <atcoder/scc>
#include <cstdio>

using namespace std;
using namespace atcoder;

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

    scc_graph g(n);

    for (int i = 0; i < m; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        g.add_edge(u, v);
    }

    auto scc = g.scc();

    printf("%d\n", int(scc.size()));
    for (auto v : scc) {
        printf("%d", int(v.size()));
        for (int x : v) {
            printf(" %d", x);
        }
        printf("\n");
    }

    return 0;
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll X, ans;
int main(){
	cin >> X;
	ll m = 100;
	while(m < X){
		m *= 1.01;
		ans++;
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 3600
S = input()

if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)

Measured memory_bytes: 3064
H, W, M = map(int, input().split())
 
HB = [0] * H
WB = [0] * W
 
place = []
 
for i in range(M):
    h, w = map(int, input().split())
    place.append((h, w,))
 
    HB[h - 1] += 1
    WB[w - 1] += 1
m_hb = max(HB)
m_wb = max(WB)
result = m_hb + m_wb
 
count = 0
for x, y in place:
    if HB[x - 1] == m_hb and WB[y - 1] == m_wb:
        count += 1


 
if HB.count(m_hb) * WB.count(m_wb) <= count:
    result -= 1
 
print(result)

Measured memory_bytes: 54216
n = gets.to_i
x=Array.new(n)
y=Array.new(n)

for i in 0..n-1
  a,b=gets.split(' ').map(&:to_i)
  x[i]=a
  y[i]=b

end
length = Array.new((n-1)*n/2)
count = 0
for i in 0..n-2
  for j in i+1..n-1
    length[count]=Math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
    count+=1
  end
end

ans = length.inject(:+)*2*(n-1)/n/(n-1)

puts ans



Measured memory_bytes: 1788
from collections import deque

N, M = map(int, input().split())

route = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    route[a - 1].append(b - 1)
    route[b - 1].append(a - 1)

print('Yes')

q = deque()
d = [-1] * N
d[0] = 0
q.append(0)

while q:
    x = q.popleft()
    for i in route[x]:
        if d[i] == -1:
            d[i] = x + 1
            q.append(i)

for i in range(1, N):
    print(d[i])


Measured memory_bytes: 36788
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N; cin>>N;
  vi A(N), B(N);
  vi ab(N);
  rep(i,N) {
    int a, b; cin>>a>>b;
    A[i]=a;
    B[i]=b;
    ab[i] = a+b;
  }
  ll aoki = 0;
  rep(i,N) aoki -= B[i];
  sort(ab.begin(), ab.end(), [](int a, int b){return a>b;});
  rep(i, N) {
    if (!(i&1)) aoki += ab[i];
  }
  cout << aoki << endl;


  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2, m);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

void solve()
{
    int n; cin >> n;
    int a = 0, b = 0, c = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        if (s.front() == 'B' && s.back() == 'A') c++;
        else if (s.front() == 'B') b++;
        else if (s.back() == 'A') a++;
        for (int j = 0; j+1 < sz(s); j++) {
            if (s[j] == 'A' && s[j+1] == 'B')
                ans++;
        }
    }
    if (a == 0 && c > 0) {
        c--; a++;
    }
    cout << ans + min(a, b) + c << endl;
}

int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    cin >> a >>b;
    if((a+b)%2==0){
        cout << (a+b)/2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = getLine >> breads >>= print . solve

solve :: [Int] -> Int
solve = foldl' ff 0 
    where
        ff acc x = acc + count x
        count x
            | even x = 1 + count (x `div` 2)
            | otherwise = 0
            

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

Measured memory_bytes: 1148
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin>>n;
    ll a[200010];
    deque<ll> deq;
    rep(i,n){
        cin>>a[i];
        if(i%2==0){
            if(n%2==0)deq.push_back(a[i]);
            else deq.push_front(a[i]);
        }
        else {
            if(n%2==0) deq.push_front(a[i]);
            else deq.push_back(a[i]);
        }
    }
    rep(i,(ll)deq.size()){
        cout<<deq.at(i);
        if(i!=(ll)deq.size()-1) cout<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
using namespace std;
int main(){
  string sa,sb,sc,ans,count;
  int a = 0,b = 0,c = 0;
  cin >> sa >> sb >> sc;
  bool ok = true;
  count =  sa[a];
  a += 1;

  while(ok){

    if(count == "a"){
      count = sa[a];
      a += 1;
      //cout << "a" << endl;
    }else if(count == "b"){
      count = sb[b];
      b += 1;
      //cout << "b" << endl;
    }else if(count == "c"){
      count = sc[c];
      c += 1;
      //cout << "b" << endl;
    }


    if(a == sa.size()+1){
      ans = "A";
      ok = false;
      //cout << a << endl;
    }else if(b == sb.size()+1){
      ans = "B";
      ok = false;
      //cout << b << endl;
    }else if(c == sc.size()+1){
      ans = "C";
      ok = false;
      //cout << c << endl;
    }

  }


  cout << ans << endl;

  return 0;
}


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

int main() {
  int n,k,x,y; cin>>n>>k>>x>>y;
  if (n<=k) cout<<n*x<<endl;
  else cout<<k*x+(n-k)*y<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 0;
  
  repi(i,1,N-2) {
    string X = S.substr(0,i);
    string Y = S.substr(i,N-i);
    
    set<char> st;
    rep(j,i) {
      rep(k,N-i) {
        if (X.at(j) == Y.at(k)) {
          st.insert(X.at(j));
          continue;
        }
      }
    }
    ans = max(ans, (int)st.size());
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
// 2004à\IF : Name the Crossing

#include <iostream>
#include <map>
#include <string>

using namespace std;

int c[200][200];

// ¯ÌÊèð`FbN
bool check(int A, int B, int size){
	bool flag = false;
	for(int i=0;i<size;i++){
		if(i==A||i==B) continue;
		if(c[i][A]==1&&c[i][B]==1) flag = true;
		if(c[i][A]==1&&c[B][i]==1) return false;
		if(c[A][i]==1&&c[i][B]==1) return false;
		if(c[A][i]==1&&c[B][i]==1) flag = true;
	}
	return flag;
}

int main(){
	int n, m;
	while(cin >> n, n){
		// Ot(×Úsñ)Ìú»
		for(int i=0;i<200;i++)
			for(int j=0;j<200;j++) c[i][j] = 1000000;
		// ÊèÌ¼OÆÔðÎt¯émap
		map<string, int> mp;
		int size = 0;
		for(int i=0;i<n;i++){
			string name; cin >> name;
			int pos = name.find("-");
			string A = name.substr(0,pos);
			string B = name.substr(pos+1);
			if(!mp.count(A)) mp[A] = size++;
			if(!mp.count(B)) mp[B] = size++;
			// AÆBÍá¤ûüÌÊè
			c[mp[A]][mp[B]] = 1;
		}
		// ¯ÈÊèð`FbN
		for(int i=0;i<size;i++){
			for(int j=i+1;j<size;j++){
				// ¯ÈçiÆjÍ¯¶ûüÌÊè
				if(check(i,j,size)) c[i][j] = c[j][i] = 2;
			}
		}
		// Warshall Floyd@
		// Ê|ÈÌÅC ç©¶ßS_ÔÌ£ðßÄµÜ¤
		for(int k=0;k<size;k++)
			for(int i=0;i<size;i++){
				if(k==i) continue;
				for(int j=0;j<size;j++)
					c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
			}
		cout << size << endl; 
		cin >> m;
		for(int i=0;i<m;i++){
			string name; cin >> name;
			int pos = name.find("-");
			string A = name.substr(0,pos);
			string B = name.substr(pos+1);
			// \zµ½OtãÅCA-BÖÌpXª¶ÝµC
			// pXÌ·³ªï(ÙÈéûüÌÊè)ÈçYES
			if(mp.count(A)&&mp.count(B)&&c[mp[A]][mp[B]]%2==1) puts("YES");
			else puts("NO");
		}
	}
}

Measured memory_bytes: 1108
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;


int main() {

    int A, B, C, X, Y;

    cin >> A >> B >> C >> X >> Y;

    int result;

    if ((2 * C) < A + B) {
        result = 2 * C * min(X, Y) + min(2 * C * (X - min(X, Y)), A * (X - min(X, Y))) +
                 min(2 * C * (Y - min(X, Y)), B * (Y - min(X, Y)));
    } else {
        result = A * X + B * Y;
    }

    cout << result << "\n";

    return 0;

}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  auto ok = [&](int x) {
    int ret = 0;         
    int until = sqrt(x) + 1;
    for (int i = 1; i <= until; i++) {
      if (x % i == 0) {
        ret += (x / i == i ? 1 : 2);
      }
    }
    return ret == 8;
  };
  int res = 0;
  for (int i = 1; i <= n; i += 2) {
    res += ok(i);
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n;
string s, t;

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

    t = s.substr(0, n / 2);
    t += t;

    if (s == t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    int row[100] = {0},chair[102] = {0};
    for(int i=0; i<m; i++){
      string s;
      cin >>s;
      if(s == "A"){row[i] = 1;}
      if(s == "B"){row[i] = 2;}
      if(s == "C"){row[i] = 3;}
      if(s == "D"){row[i] = 4;}
    }
    for(int i=0; i<m; i++){
      if(row[i] == 1){
	for(int j=0; j<n; j++){
	  if(!chair[j+1]){
	    chair[j+1] = 1;
	    break;
	  }
	}
      }
      if(row[i] == 2){
	bool non = true;
	for(int j=n-1; j>=0; j--){
	  if(chair[j] != 1 && chair[j+1] == 0 && chair[j+2] != 1){
	    chair[j+1] = 2;
	    non = false;
	    break;
	  }
	}
	if(non){
	  for(int j=0; j<n; j++){
	    if(!chair[j+1]){
	      chair[j+1] = 2;
	      break;
	    }
	  }
	}
      }
      if(row[i] == 3){
	if(!i){
	  if(n%2){chair[(n+1)/2] = 3;}
	  else{chair[n/2+1] = 3;}
	}
	else{
	  for(int j=1; j<=n; j++){
	    if(chair[j] && !chair[j+1] && j < n-1){
	      chair[j+1] = 3;
	      break;
	    }
	    if(chair[j] && !chair[j-1] && j > 1){
	      chair[j-1] = 3;
	      break;
	    }
	  }
	}
      }
      if(row[i] == 4){
	if(!i){chair[1] = 4;}
	else{
	  int r = 0,s = -1;
	  bool non = true;
	  for(int j=0; j<n; j++){
	    if(!chair[j+1]){
	      int x = 200;
	      for(int k=j+1; k<n; k++){
		if(chair[k+1]){
		  if(x > k-j){x = k-j;}
		  break;
		}
	      }
	      for(int k=j-1; k>=0; k--){
		if(chair[k+1]){
		  if(x > j-k){x = j-k;}
		  break;
		}
	      }
	      if(r < x){r = x;s = j;}
	    }
	  }
	  if(s != -1){
	    chair[s+1] = 4;
	    non = false;
	  }
	  if(non){
	    for(int j=0; j<n; j++){
	      if(!chair[j+1]){
		chair[j+1] = 4;
		break;
	      }
	    }
	  }
	}
      }
    }
    for(int i=0; i<n; i++){
      if(chair[i+1] == 0){cout <<"#";}
      if(chair[i+1] == 1){cout <<"A";}
      if(chair[i+1] == 2){cout <<"B";}
      if(chair[i+1] == 3){cout <<"C";}
      if(chair[i+1] == 4){cout <<"D";}
    }
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1200