akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>

using namespace std;

int cal(int y[], int z[], int d){
    int distance = 0;
    for(int i = 0; i < d; i++) distance += (y[i] - z[i]) * (y[i] - z[i]);
    if(sqrt((double)distance) == (int)sqrt((double)distance)) return 1;
    else return 0;
}

int main(){
    int n, d, x[10][10], count = 0;
    cin >> n >> d;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }
    int y[10], z[10];
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            for(int k = 0; k < d; k++){
                y[k] = x[i][k];
                z[k] = x[j][k];
            }
            count += cal(y, z, d);
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n, *d = map(int, open(0).read().split())
MOD = 998244353
c = Counter(d)
if d[0] != 0 or c[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, max(d)+1):
        ans *= pow(c[i-1], c[i]) % MOD
print(ans % MOD)

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

typedef unsigned long long ull;

mt19937_64 r(std::chrono::high_resolution_clock::now().time_since_epoch().count());

ull const MASK30 = (1<<30)-1;
ull const MASK31 = INT_MAX;
ull const MOD = (1LL<<61)-1;
ull const MOD5 = MOD*5;
ull const base = r()%MOD;

struct RollingHash {
private:
    vector<ull> power,hash;
public:
    inline ull mul(ull a,ull b) {
        ull au = a>>31;
        ull ad = (a&MASK31);
        ull bu = b>>31;
        ull bd = (b&MASK31);
        ull mid = au*bd+ad*bu;
        return ((au*bu)<<1)+ad*bd+(mid>>30)+((mid&MASK30)<<31);
    }

    inline ull calcmod(ull a) {
        a = (a&MOD)+(a>>61);
        if (a > MOD) a -= MOD;
        return a;
    }

    RollingHash(string& s) {
        int n = s.size();
        power.resize(n+1);
        hash.resize(n+1);
        power[0] = 1;
        hash[0] = 0;
        for (int i = 0;i < n;++i) power[i+1] = calcmod(mul(power[i],base));
        for (int i = 0;i < n;++i) hash[i+1] = calcmod(mul(hash[i],base)+s[i]);
    }

    inline ull get(int l, int r)  {
        if (l) return calcmod(hash[r]+MOD5-mul(hash[l],power[r-l]));
        return hash[r];
    }

    ull connect(ull h1,int l,int r) {
        ull h2 = get(l,r);
        return calcmod(mul(h1,power[r-l])+h2);
    }

    // [l,r)
    int LCP(int l1,int r1,RollingHash& rh,int l2,int r2) {
        int ok = 0,ng = min(r1-l1,r2-l2)+1;
        while (ng-ok > 1) {
            int mid = (ok+ng)/2;
            if (get(l1,l1+mid) == rh.get(l2,l2+mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
};

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    RollingHash rh(s);
    for (int i = 0;i < n-1;++i) for (int j = i+1+ans;j < n-ans;++j) {
        ans = max(ans,min(j-i,rh.LCP(i,j,rh,j,n)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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; }

int main() {

	int n;
	string s; 
	cin >> n >> s;
	vector<vector<int> > hoge(6, vector<int>());
	//rgb,rbg,grb,gbr,brg,bgr
	vector<int> rafterg;
	vector<int> bafterg;
	int countr = 0, countb=0, countg = 0;
	rep(i,n) {
		if(s[i] == 'B') {
			countb++;
			hoge[1].pb(countr);
			hoge[3].pb(countg);
		}
		if(s[i] == 'R') {
			hoge[2].pb(countg);
			hoge[4].pb(countb);
			countr++;
		}
		if(s[i] == 'G') {
			countg++;
			hoge[0].pb(countr);
			hoge[5].pb(countb);
		}
			
	}
	countr = 0;
	countb=0;
	countg = 0;
	//rgb,rbg,grb,gbr,brg,bgr
	vector<vector<int> > fuga(6, vector<int>());
	for(int i=n-1; i>=0; i--) {
		if(s[i] == 'R') {
			countr++;
			fuga[2].pb(countb);
			fuga[4].pb(countg);
		}
		if(s[i] == 'G') {
			countg++;
			fuga[0].pb(countb);
			fuga[5].pb(countr);
		}
		if(s[i] == 'B') {
			countb++;
			fuga[1].pb(countg);
			fuga[3].pb(countr);
		}
		if(s[i] == 'G') bafterg.pb(countb);
	}
	rep(i,6) {
		reverse(fuga[i].begin(), fuga[i].end());
	}
	ll ans = 0;
	rep(i,6) {
		rep(j, fuga[i].size()) {
			ans += fuga[i][j] * hoge[i][j];
		}
	}
	/*rep(i, rbeforeg.size()) {
		ans += rbeforeg[i] * bafterg[i];
		cout << rbeforeg[i] << " " << bafterg[i] << endl;
	}*/
	
	//reverse(bafterg.begin(), bafterg.end());
	for(int i=1;i <= (n-1)/2; i++) {
		rep(j,n) {
			if(j + 2*i >= n) continue;
			if(s[j] == 'R' && s[j+i] == 'G' && s[j+2*i] == 'B') ans--;
			if(s[j] == 'R' && s[j+i] == 'B' && s[j+2*i] == 'G') ans--;
			if(s[j] == 'B' && s[j+i] == 'R' && s[j+2*i] == 'G') ans--;
			if(s[j] == 'B' && s[j+i] == 'G' && s[j+2*i] == 'R') ans--;
			if(s[j] == 'G' && s[j+i] == 'B' && s[j+2*i] == 'R') ans--;
			if(s[j] == 'G' && s[j+i] == 'R' && s[j+2*i] == 'B') ans--;
		}
	}

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


Measured memory_bytes: 3760
while True:
    try:
        n = input()
        count = 0

        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if a+b+c+d == n:
                            count = count + 1
        print count
    except EOFError:
        break

Measured memory_bytes: 6252
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int dp[101][4][4][4];

int main() {
    int N; cin >> N;
    
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                if(i==0 && j==1 && k==2) continue;
                if(i==0 && j==2 && k==1) continue;
                if(i==1 && j==0 && k==2) continue;
                dp[3][i][j][k] = 1;
            }
        }
    }
    
    
    for(int len=3; len<=N; len++){
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                for(int k=0; k<4; k++){
                    for(int l=0; l<4; l++){
                        if(j==0 && k==1 && l==2) continue;
                        if(j==0 && k==2 && l==1) continue;
                        if(j==1 && k==0 && l==2) continue;
                        if(i==0 && k==1 && l==2) continue;
                        if(i==0 && j==1 && l==2) continue;
                        dp[len+1][j][k][l] += dp[len][i][j][k];
                        dp[len+1][j][k][l] %= MOD;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                ans += dp[N][i][j][k];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  int H, A;
  cin >> H >> A;
  cout << (H+A-1) / A << endl;
  return 0;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    
    vector<int> a(n);
    vector<int> b(n+1);
    rep(i,n){
        cin >> a[i];
        b[a[i]] = i;
    }

    set<int> s;
    int ans = 0;
    for(int i = 1; i<=n ;i++){
        s.insert(b[i]);
        auto r = s.upper_bound(b[i]);
        int R;
        if(r == s.end()){
            R = n-b[i];
        }else{
            R = *r - b[i];
        }
        int L;
        if(s.lower_bound(b[i]) == s.begin()){
            L = b[i] + 1;
        }else{
            auto l = s.find(b[i]);
            l--;
            L = b[i] - *l;
        }
        cerr << "i:" << i << " b[i]:" << b[i] << " R:" << R << " L:" << L << endl;
        ans += i*R*L;
    }
    cout << ans << endl;


    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://arc060.contest.atcoder.jp/tasks/arc060_a

Measured memory_bytes: 12800
#!/usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def S(): return input().rstrip()


def LS(): return S().split()


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


mod = 1000000007
inf = 1e10

#solve


def solve():
    def dfs(i):
        if c[i]:
            return
        for e in edg[i]:
            dfs(e)
        c[i] = 1
        top.append(i)
    n, m = LI()
    edg = [[] for i in range(n)]
    rev_edg = [[] for i in range(n)]
    for i in range(n + m - 1):
        a, b = LI_()
        edg[a].append(b)
        rev_edg[b].append(a)
    for i, e in enumerate(rev_edg):
        if len(e):
            continue
        root = i
        break
    c = defaultdict(int)
    top = []
    dfs(root)
    ind = [0] * n
    for i in range(n):
        ind[top[i]] = i
    ans = [-1] * n
    for i in range(n):
        tmp = [n, -1]
        for e in rev_edg[i]:
            if ind[e] < tmp[0]:
                tmp = [ind[e], e]
        ans[i] = tmp[1]
    print("\n".join(map(str, map(lambda x: x + 1, ans))))

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 193620
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long int
#define P pair<ll, ll>
#define VII vector<P>
#define P_B push_back

#define MOD 1000000007
#define pi 3.141592653589793238
int DP[3001][3001];


int main() {
	
	// ll T; cin>>T; while(T--) 
	{
		string a, b;
		cin>>a>>b;
		int a_l = a.length(), b_l = b.length();
		memset(DP, 0, sizeof(DP));

		for (int i = 1; i <= a_l; i++) {
			for (int j = 1; j <= b_l; j++) {
				if(a[i-1] == b[j-1]) DP[i][j] = DP[i-1][j-1]+1;
				else DP[i][j] = max(DP[i-1][j], DP[i][j-1]);
			}
		}


		int i = a_l, j = b_l;
		int li = DP[a_l][b_l];
		char answer[li+1];
		answer[li] = '\0';

		while(i > 0 && j > 0) {

			if(a[i-1] == b[j-1]) {
				answer[li-1] = a[i-1];
				i--, j--, li--;
			}

			else if(DP[i-1][j] > DP[i][j-1]) i--;
			else j--;
		}

		cout<<answer;
	}	
	return 0;
}

Measured memory_bytes: 38804
S = input()

a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'

while len(S) != 0:
    if S[-5:] == a or S[-5:] == c:
        S = S[:-5]
    elif S[-7:] == b:
        S = S[:-7]
    elif S[-6:] == d:
        S = S[:-6]
    else:
        break
    
if len(S) == 0:
    print('YES')
else:
    print('NO')

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


def solve(N: int, K: int):
    ret = N - K + 1
    print(ret)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
const int MOD = 1e9 + 7;
const int INF = 2e9;
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 (a>b) { a=b; return 1; } return 0; }
int GCD(int x, int y) { return y ? GCD(y, x % y) : x; }
int LCM(int x, int y) { return x * y / GCD(x, y); }

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<pair<int, ll>> ab(n);
    for(int i=0; i<n; i++){
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab.begin(), ab.end());
    for(int i=0; i<n; i++){
        k -= ab[i].second;
        if(k<=0){
            cout << ab[i].first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1792
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const inputs = input.trim().split('\n');

const COLORS = ['r','g','b'];
class Worm {
  constructor(id, depth) {
    this.id = id;
    this.depth = depth;
    this.colors = id.split('');
  }
  getNextWormIds() {
    const nextWormIds = [];
    for (let i = 0; i < this.colors.length - 1; i++) {
      const color = this.colors[i];
      const nextColor = this.colors[i + 1];
      if (color === nextColor) {
        continue;
      }
      const changedColor = COLORS.filter(s => s !== color && s !== nextColor)[0];
      const changedColors = this.colors.slice(); // copy
      changedColors.splice(i, 2, changedColor, changedColor); // 置き換え
      nextWormIds.push(changedColors.join(''));
    }
    return nextWormIds;
  }
}

class Graph {
  constructor() {
    this.map = new Map();
  }
  has(id) {
    return this.map.has(id);
  }
  get(id) {
    return this.map.get(id);
  }
  set(id, depth) {
    this.map.set(id, new Worm(id, depth));
  }
  bfs(wormId) {
    this.queue = [];
    this.set(wormId, 0);
    this.queue.push(wormId);
    while(this.queue.length) {
      const wormId = this.queue.shift();
      const worm = this.get(wormId);
      const wormIds = worm.getNextWormIds();
      if (!wormIds.length) {
        return worm;
      }
      wormIds.forEach(wormId => {
        if (this.has(wormId)) {
          return;
        }
        this.set(wormId, worm.depth + 1);
        this.queue.push(wormId);
      })
    }
  }
  print() {
    for (let i = 1; i <= this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

inputs.forEach(wormId => {
  if (wormId === '0') {
    return;
  }
  const graph = new Graph();
  const worm = graph.bfs(wormId);
  console.log(worm ? worm.depth : 'NA');
});



Measured memory_bytes: 59340
#include <bits/stdc++.h>  // ver1.9.5
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  int n;
  cin >> n;
  Vi a(n),b(n);
  int suma=0,sumb=0;
  rep(i,0,n){
    cin >> a[i];
    suma += a[i];
  }
  rep(i,0,n){
    cin >> b[i];
    sumb += b[i];
  }
  if(suma < sumb) {cout<<-1<<endl;return 0;}
  int minus=0,ans=0;
  Vi plus(0);
  
  rep(i,0,n){
    if(a[i]>b[i]) plus.pb(a[i]-b[i]);
    if(a[i]<b[i]) {
      ans++;
      minus += b[i]-a[i];
    }
  }
  
  sort(ALL(plus));
  reverse(ALL(plus));
  int ct = 0;
  while(minus > 0){
    minus -= plus[ct];
    ans++;
    ct++;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 2428
//2018.10.06

#include <iostream>
using namespace std;

int main() {

    int n,T;
    cin >> n >> T;
    int i;
    int c[n];
    int t[n];
    for(i=0; i<n;i++){
        cin >> c[i] >> t[i];
    }

    int min_c = 1001;

    for(i=0;i<n;i++){
        if(c[i] < min_c && t[i] <= T) min_c = c[i];
    }

    if(min_c == 1001) cout << "TLE" << endl;
    else cout << min_c << endl;

}


Measured memory_bytes: 256
N = int(input())
T = [int(input()) for i in range(N)]
ans = 1

def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

for i in range(N):
    ans = (ans*T[i])//gcd(ans,T[i])

print(ans)

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

sa = sorted(a)
v=10**9
for i in range(n-k+1):
	if v > sa[i+k-1]-sa[i]:
		v = sa[i+k-1]-sa[i]
print(v)

Measured memory_bytes: 8280
#include<stdio.h>
int n,m;
bool g[111111];
int cnt[111111];
int main(){
	scanf("%d%d",&n,&m);
	g[1] = true;
	for(int i=1; i<=n; i++)
		cnt[i] = 1;
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);
		if(g[x])g[y]=true;
		cnt[y] ++;
		if(--cnt[x] == 0)g[x] = false;
	}
	int res = 0;
	for(int i=1; i<=n; i++)
		if(g[i])res++;
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 100004
#define INF 1e9+7

using namespace std;

ll n,a,b;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;

    if(n == 1)
    {
        cout << "Hello World\n";
    }
    else
    {
        cin >> a >> b;

        cout << a + b << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

const int maxn = 1e6 + 5;
int p[maxn];

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  ll a, b;
  cin >> a >> b;
  int cnt = 1;
  memset(p, 1, sizeof p);
  ll g = __gcd(a, b);
  for(ll i = 2; i < maxn; i++){
    if(p[i]){
      for(ll j = i * i; j < maxn; j += i)
        p[j] = 0;
    }
  }
  for(ll i = 2; i * i <= g; i++){
    if(p[i] && (g % i == 0)){
      while(g > 1 && (g % i == 0)){
        g /= i;
      }
      cnt++;
    }
  }
  cnt += (g > 1);
  cout << cnt;
}

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

int main(){
  int N; cin >> N;
  int a[N]; REP(i,N){cin>>a[i];}
  
  int r=0;
  for(int i=1;i<N;i++){
    if(a[i-1]==a[i]){
      a[i] = 1000;
      r++;
    }
  }
  cout << r << "\n";
}

Measured memory_bytes: 256
#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif

/*
    This ain't a milly rock
    This a money dance
    And my D' ain't hard
    That's a '30 in my pants
*/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <set>
#include <ctime>
#include <map>
#include <random>
#include <iomanip>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <bitset>
#include <deque>
#include <utility>

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ld long double

using namespace std;

// mt19937 rnd(time(nullptr));

inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void solve() {
    int n;
    vector <int> mas(3);
    cin >> n >> mas[0] >> mas[1] >> mas[2];
    vector < string > v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    vector <char> ans;
    for(int i = 0; i < n - 1; ++i) {
        string s = v[i];
        int a = v[i][0] - 'A';
        int b = v[i][1] - 'A';
        if(mas[a] <= 0 && mas[b] <= 0) {
            cout << "No\n";
            return;
        }
        // a -> b
        bool ok = true;
        mas[a]--;
        mas[b]++;
        if(mas[a] < 0) ok = false;
        int a1 = v[i + 1][0] - 'A';
        int b1 = v[i + 1][1] - 'A';
        if(mas[a1] == 0 && mas[b1] == 0) {
            ok = false;
        }
        if(ok) {
            ans.push_back(char('A' + b));
        } else {
            mas[a] += 2;
            mas[b] -= 2;
            ans.push_back(char('A' + a));
        }
        if(mas[0] < 0 || mas[1] < 0 || mas[2] < 0) {
            cout << "No\n";
            return;
        }
    }
    int a = v.back()[0] - 'A';
    int b = v.back()[1] - 'A';
    if(mas[a] == 0 && mas[b] == 0) {
        cout << "No\n";
        return;
    }
    if(mas[a] > 0) {
        ans.push_back(char('A' + b));
    } else {
        ans.push_back(char('A' + a));
    }
    if(mas[0] < 0 || mas[1] < 0 || mas[2] < 0) {
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
    for(auto i : ans) cout << i << '\n';
}

signed main() {
#ifdef lolipop
    freopen("input.txt", "r", stdin);
#else
    fastio();
#endif

    int T = 1;
//    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5476
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  cout << string(w + 2, '#') << '\n';
  while (h--) {
    string s; cin >> s;
    cout << '#' << s << '#' << '\n';
  }
  cout << string(w + 2, '#') << '\n';
}

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

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

    double ans = 0;
    rep(i, 1000) rep(j, 1000) {
        double k = l - i - j;
        if (i + j + k == l && k > 0) {
            ans = max(ans, i*j*k);
        }
    }

    printf("%.12f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
long double n, m, d, ans=0;
cin >> n >> m >> d;
ans=(d)?2*(n-d)*(m-1)/(n*n):(n-d)*(m-1)/(n*n);
cout << setprecision(15) << ans << "\n";
}

Measured memory_bytes: 3796
S = input()
#Aの探索
for i in range(len(S)):
    if S[i] == "A":
        S = S[i:]
        break

#Zの探索
if S[-1] == "Z":
    print(len(S))
    exit()
for i in range(1, len(S)+1):
    if S[-i] == "Z":
        S = S[:-i+1]
        break
print(len(S))

Measured memory_bytes: 9148
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int n, m;

vector<pair<int, int>> e[100000];

int pos[100000];


bool dfs(int i,int p) {
	if (pos[i]!= INF) {
		return p == pos[i];
	}
	pos[i] = p;
	for (auto u :e[i]) {
		if (!dfs(u.first, p + u.second))return false;
	}
	return true;
}


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

	cin >> n >> m;
	rep(i,m) {
		int l, r,d;
		cin >> l >> r >> d;
		l--; r--;
		e[l].emplace_back(r,d);
		e[r].emplace_back(l, -d);
	}

	//memset(pos, -1, sizeof(pos));
	rep(i, n)pos[i] = INF;
	bool ok = true;
	rep(i,n) if(pos[i]== INF){
		if (!dfs(i, 0)) {
			ok = false;
			break;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;



	return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main(int argc, const char * argv[]) {
    double a, b;
    double c;
    double S, L, h;
    
    cin >> a >> b >> c;
    
    S=a*b*sin(M_PI*c/180)/2;
    L=sqrt(a*a+b*b-2*a*b*cos(M_PI*c/180));
    L+=a+b;
    h=b*sin(M_PI*c/180);
    
    cout << fixed;
    cout << setprecision(10) << S << endl;
    cout << setprecision(10) << L << endl;
    cout << setprecision(10) << h << endl;
    
    return 0;
}


Measured memory_bytes: 3556
// https://atcoder.jp/contests/abc155/tasks/abc155_c

#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;

    map<string, int> cnt;

    int ma = 0;
    while(N--) {
        string s;
        cin >> s;

        cnt[s]++;
        ma = max(ma, cnt[s]);
    }

    for(pair<string, int> x: cnt) {
        if(x.second == ma) {
            cout << x.first << endl;
        }
    }
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

string vow = "aeiou";

void solve ( int test_case )
{
    string s ; cin >> s ;

    int n = s.size() ;
    for ( int i=0 ; i < n ; i++ )
    {
        if ( i % 2 == 1 && s[i] == 'R' ) { cout << "No" ; R ; }
        if ( i % 2 == 0 && s[i] == 'L' ) { cout << "No" ; R ; }
    }

    cout << "Yes" ;
}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


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

int n,m;
int ans=0;
int a[4];
bool v[4];
int main(){
	cin >> n >> m;
	if (n==1){
		for (int i=1,s,c;i<=m;i++){
			cin >> s >> c;
			if (s!=1){cout <<"-1";return 0;}
			if (i>1 && a[1]!=c){cout <<"-1";return 0;}
			a[i]=c;
		}
		cout << a[1];
		return 0;
	}
	for (int i=1,s,c;i<=m;i++){
		cin >> s >> c;
		if (s>n || s<=0){cout << "-1";return 0;}
		if (s==1 && c==0){cout << "-1";return 0;} 
		if (v[s]){
			if (a[s]==c)continue;
			cout << "-1";
			return 0;	
		}
		v[s]=1;
		a[s]=c;
	}
	a[1]=max(a[1],1);
	for (int i=1,pw=1;i<=n;i++){
		ans += a[n-i+1]*pw;
		pw*=10;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
s=input()

n = len(s)

countC = 0

alf = [chr(ord('a') + i) for i in range(26)]

for i in range(n):
    #print(i)
    if i == 0 and s[i] != 'A':
        print('WA')
        exit()
    elif i == 0 and s[i] == 'A':
        continue
    elif s[i] == 'C' and 1 < i and i < n-1:
        countC += 1
    elif s[i] in alf:
        continue
    else:
        print('WA')
        exit()
    
if countC == 1:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 38396
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void renketu(char *S,char*T){

    int l_t=strlen(T);
    for(int i=0;i<l_t;i++){
        printf("%c",T[i]);
    }
    int l_s=strlen(S);
    for(int i=0;i<l_s;i++){
        printf("%c",S[i]);
    }

}


int main() {
    char S[100],T[100];
    scanf("%s%s",S,T);

    renketu(S,T);

    return 0;
}




Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= b) cout << a << endl;
	else cout << a - 1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	long long int A,B,C,K,sum;
  	
  scanf("%lld%lld%lld%lld",&A,&B,&C,&K);
  
  if(A>K)
  {
  printf("%lld",K);
  }else if(A+B>K){
  printf("%lld",A);
  }else{
    printf("%lld",A-K+A+B);
  }  
	return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int x = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(Math.abs(a - x) < Math.abs(b - x) ? "A" : "B");
        }
    }
}


Measured memory_bytes: 21716
#include <stdio.h>
#include <queue>
#include <iostream>
using namespace std;
priority_queue<int> pq;

int main()
{
	int N,M,i;
	scanf("%d%d",&N,&M);
	for(i=0;i<N;i++){
		int x;
		scanf("%d",&x);
		pq.push(x);
	}

	for(i=0;i<M;i++){
		int price = pq.top(); pq.pop();
		price /=2;
		pq.push(price);
	}

	long long sum = 0;
	i=0;
	while(i<N){
		sum += pq.top(); pq.pop();
		i++;
	}
	printf("%lld\n", sum);
}

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

namespace ABC049C_Daydream
{
    class MainClass
    {
        private static string[] dic = { "dream", "dreamer", "erase", "eraser" };

        static void Main()
        {
            string inp = Console.ReadLine();
            inp = new string(inp.Reverse().ToArray());
            while (true)
            {
               string sub = dic.Select(e => new String(e.Reverse().ToArray())).FirstOrDefault(e => inp.StartsWith(e));
                if (String.IsNullOrEmpty(sub))
                {
                    break;
                }
                inp = inp.Remove(0, sub.Length);
            }
            Console.WriteLine(inp.Length == 0 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 33016
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>

using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int N, Y, M, D;

int solve() {
  int ret = 1;
  // 日を満たす
  if (Y % 3 == 0) {
    ret += 20 - D;
  } else {
    if (M % 2) ret += 20 - D;
    else ret += 19 - D;
  }
  // 月を増加
  ++M;
  if (M != 11) {
    for (; M < 11; ++M) {
      if (Y % 3 == 0) { ret += 20; }
      else {
        if (M % 2) ret += 20;
        else ret += 19;
      }
    }
  }
  // 年を増加
  ++Y;
  for (; Y <= 999; ++Y) {
    if (Y % 3 == 0) ret += 200;
    else ret += 195;
  }
  return ret;
}

int main() {
  scanf("%d", &N);
  rep(z,N) {
    scanf("%d%d%d", &Y, &M, &D);
    printf("%d\n", solve());
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
    char a[4];
    for(int i=0;i<4;i++){
        cin>>a[i];
    }

    if(a[0]==a[1] && a[1]==a[2]){
        cout<<"Yes"<<endl;
        return 0;
    }else if(a[1]==a[2] && a[2]==a[3]){
        cout<<"Yes"<<endl;
        return 0;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

int N, L[212];
int ans;

int main(void)
{
	scanf("%d", &N);
	for (int i = 0; i < 2*N; ++i) { scanf("%d", &L[i]); }

	std::sort(L, L + 2*N);
	for (int i = 0; i < 2*N; i += 2)
	{
		ans += L[i];
	}

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

Measured memory_bytes: 128
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	string a, b, c;
	cin >> a >> b >> c;
	
	if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
n,q = map(int,input().split())
g = [[] for i in range(n)]
c = [0]*n
reach = [False]*n
for i in range(n-1):
    a,b = map(lambda x: int(x)-1,input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(q):
    p,x = map(int,input().split())
    c[p-1] += x

reach[0] = True
q = [0]
while q:
    cur = q.pop()
    reach[cur] = True
    for i in g[cur]:
        if not reach[i]:
            c[i] += c[cur]
            q.append(i)
print(*c)

Measured memory_bytes: 106752
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int gcd(int a, int b) {
	while (a % b != 0 && b % a != 0) {
		if (a > b) {
			a %= b;
		} else {
			b %= a;
		}
	}
	return min(a, b);
}

int main() {
	int n;
	cin >> n;
	vector<int> v(n + 1, 0);
	for (int i = 0; i <= n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		v[i] = v[i + 1] - v[i];
	}
	v.pop_back();
	int res = v[0];
	for (int i = 1; i < n; i++) {
		res = gcd(res, v[i]);
	}
	cout << res << endl;
}


Measured memory_bytes: 3704
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    for(int i = 0; i <= 25; i++){
        for(int j = 0; j < 15; j++) if(i*4 + j*7 == n){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 256
while true
    h,w = gets.split.map(&:to_i)
    break if h.zero? && w.zero?
    
    h.times{|row|
        if row%2==0 then
            puts ('#.'*w)[0,w]
        else
            puts ('.#'*w)[0,w]
        end
    }
    puts 
    
end

Measured memory_bytes: 6168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// AISing_B
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int cnt = 0;
		int a = 0;

		for(int i=1; i <= N; i++) {
			a = sc.nextInt();
			if(i%2==1 && a%2==1) {
				cnt++;
			}
		}

		System.out.println(cnt);

	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}

}


Measured memory_bytes: 35880
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1e9+7
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define M 110


int main(){
    IOS;
 
 	ll x,n;cin>>x>>n;
 	ll cnt[M]={0},ans=-1,mn=inf;
 	rep(i,0,n){
 		ll x;cin>>x;cnt[x]=1;
 	}
 	rep(i,0,M){
 		if(cnt[i])continue;
 		ll t=abs(i-x);
 		if(t<mn)mn=t,ans=i;
 	}
 	cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n, k;
	string s;
	cin >> n >> k >> s;
	vector<int> v;
	int cnt = 1;
	for(int i = 1; i < s.length(); i++){
		if(s[i] != s[i - 1]){
			v.push_back(cnt);
			cnt = 1;
		} else {
			cnt++;
		}
	}
	v.push_back(cnt);
	int vsum[100001];
	vsum[0] = 0;
	vsum[1] = v[0];
	for(int i = 2; i <= v.size(); i++){
		vsum[i] = vsum[i - 1] + v[i - 1];
	}
	int ans = 0;
	for(int l = 0; l < v.size(); l++){
		int r = ((s[0] == '0' && l % 2 == 0) || (s[0] == '1' && l % 2 == 1)) ? l + 2 * k : l + 2 * k + 1;
		r = min(r, (int)v.size());
		ans = max(ans, vsum[r] - vsum[l]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1272
import java.util.Scanner;
public class Main{
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    int x = 0;

    for(int i = s.length()-1 ; i>0 ; i--){
      s = s.substring(0,i);
      String s1 = s.substring(0,i/2);
      String s2 = s.substring(i/2,i);

      if(s1.equals(s2)){
        x = i;
        break;
      }
    }
    System.out.println(x);
  }
}


Measured memory_bytes: 21844
#include<stdio.h>
int main(){
  int h,i,j,c,s,f,k;
  while(scanf("%d",&h),h){
    int d[20][6]={0};
    for(i=s=0;i<h;i++){
      for(j=0;j<5;j++)scanf("%d",&d[h-i-1][j]);
    }
    /*for(i=0;i<20;i++){
      for(j=0;j<5;j++){
	printf("%d ",d[i][j]);
      }
      printf("\n");
      }printf("\n");//*/
    f=1;
    while(f){
      for(i=f=0;i<h;i++){
	c=1;
	for(j=0;j<5;j++){
	  if(d[i][j]==d[i][j+1]&&d[i][j])c++;
	  else{
	    if(c>2){
	      f=1;
	      for(k=0;k<c;k++){
		s+=d[i][j-k];
		d[i][j-k]=0;
	      }
	    }
	    c=1;
	  }//printf("%d ",c);
	}//printf("\n");
      }//printf("\n");
      for(i=0;i<5;i++){
	for(j=c=0;j-c<h;j++){
	  d[j-c][i]=d[j][i];
	  if(d[j][i]==0&&j<h)c++;
	}
      }
      /*for(i=0;i<20;i++){
	for(j=0;j<5;j++)printf("%d ",d[i][j]);
	printf("\n");
	}printf("\n");//*/
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <stdlib.h>
 
int main(){
  int n;
  unsigned long long int ans;
  scanf("%d", &n);
  int i;
  unsigned long long int m=0,a=0,r=0,c=0,h=0;
  
  char s[n+1][12];
  
  for(i=0;i<=n;i++)	gets(s[i]);
  
  for(i=0;i<=n;i++){
    switch(s[i][0]){
      case 'M':m++;break;
      case 'A':a++;break;
      case 'R':r++;break;
      case 'C':c++;break;
      case 'H':h++;break;
      
    }
  }
  ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
  
  printf("%llu", ans);
  
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	double t, a;
	cin >> t >> a;

	int ans = 0;
	double mn = 10000;
	rep(i, n) {
		double h;
		cin >> h;
		double d = abs(t - h * 0.006 - a);
		if (d < mn) {
			mn = d;
			ans = i + 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys

n= int(sys.stdin.readline())
p= [ int(x) for x in sys.stdin.readline().split() ]
q= sorted(p)

c= 0
for i in range(n):
    if p[i]!=q[i]: c+=1
    if c>2: break
#
if c<=2: print( 'YES' )
else: print('NO' )

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, M, R;
	cin >> N >> M >> R;
	vector<int>r(R);
	rep(i, R) {
		int input;
		cin >> input;
		input--;
		r[i] = input;
	}
	vector<vector<int>>dp(N, vector<int>(N, INF));
	rep(i, N)dp[i][i] = 0;
	rep(i, M) {
		int A, B, C;
		cin >> A >> B >> C;
		A--; B--;
		dp[A][B] = C;
		dp[B][A] = C;
	}
	for (int k = 0; k < N; k++) { //経由する頂点
		for (int i = 0; i < N; i++) { //始点
			for (int j = 0; j < N; j++) { //終点
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
	sort(r.begin(), r.end());
	int ans = INF;
	do {
		int dist = 0;
		for (int i = 1; i < R; i++)dist += dp[r[i - 1]][r[i]];
		ans = min(dist, ans);
	} while (next_permutation(r.begin(), r.end()));
	cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define gc() getchar()
using namespace std;
const int N = 4010;
int a,b,n,t,ans[N],q[N],tmp[N],cnt,tcnt,fa[N];
vector<int> threw;
int get_fa(int x) {
  return x == fa[x] ? x : fa[x] = get_fa(fa[x]);
}
bool ask(int x,int y) {
  static char tmp;
  printf("? %d %d\n",x,y);
  fflush(stdout);
  for (tmp = gc() ; tmp != 'Y' && tmp != 'N' ; tmp = gc());
  return (tmp == 'Y');
}
void solve() {
  if (cnt == 0) return;
  tcnt = 0;
  for (int i = 0 ; i+1 < cnt ; i += 2) {
    if (ask(q[i],q[i+1]) == 1 && ask(q[i+1],q[i]) == 1) {
      fa[q[i+1]] = q[i];
      tmp[tcnt++] = q[i];
    } else threw.push_back(q[i]), threw.push_back(q[i+1]);
  }
  if (cnt&1) t = q[cnt-1], threw.push_back(q[cnt-1]);
  for (int i = 0 ; i < tcnt ; ++ i) q[i] = tmp[i];
  cnt = tcnt;
  solve();
}
int main() {
  scanf("%d%d",&a,&b);
  if (a <= b) return 0 * printf("Impossible\n");
  n = a + b;
  for (int i = 0 ; i < n ; ++ i)
    q[i] = i, fa[i] = i;
  cnt = n;
  solve();
  for (int i = 0 ; i < n ; ++ i) get_fa(i);
  for (int i = 0 ; i < (int)threw.size() ; ++ i) {
    if (threw[i] == t) continue;
    ans[threw[i]] = ask(t,threw[i]);
  }
  ans[t] = 1;
  for (int i = 0 ; i < n ; ++ i)
    ans[i] = ans[fa[i]];
  printf("! ");
  for (int i = 0 ; i < n ; ++ i)
    printf("%d",ans[i]);
  puts("");
  return 0;
}

Measured memory_bytes: 848
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    int ans = max(max(a+b, a+a-1), b+b-1);
    PUTS(ans);
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


from collections import defaultdict


def main():
    n, m, k = map(int, input().split())
    fr_ed_c = defaultdict(int)  # node -> count

    parents = {}  # node -> parent_node
    root_2_nc = {}  # node -> count

    for i in range(m):
        a, b = map(int, input().split())
        fr_ed_c[a] += 1
        fr_ed_c[b] += 1

        p_a = get_root(parents, a)
        p_b = get_root(parents, b)

        if p_a == p_b:
            # already same cluster. do nothing.
            pass
        else:
            # cluster integration
            p_a_c = root_2_nc.get(p_a, 1)
            p_b_c = root_2_nc.get(p_b, 1)
            p_a, p_b = (p_a, p_b) if p_a_c < p_b_c else (p_b, p_a)
            parents[p_a] = p_b
            if p_b not in root_2_nc:
                root_2_nc[p_b] = 1
            root_2_nc[p_b] += root_2_nc.pop(p_a, 1)

    br_ed = defaultdict(set)  # node -> set()
    for i in range(k):
        c, d = map(int, input().split())
        br_ed[c].add(d)
        br_ed[d].add(c)

    ans_list = []
    for i_m in range(n):
        i = i_m + 1
        root = get_root(parents, i)
        block_count = 0
        for b in br_ed[i]:
            b_root = get_root(parents, b)
            block_count += 1 if root == b_root else 0
        ans = root_2_nc.get(root, 1) - 1 - fr_ed_c.get(i, 0) - block_count
        ans_list.append(str(ans))
    print(" ".join(ans_list))


def get_root(parents, i):
    if i not in parents:
        return i
    return get_root(parents, parents[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 69316
#include <iostream>

using namespace std;

int main()
{
int x,y;
for(int i=1;i<=3000;i++)
{cin >> x >> y;
if(x+y!=0)
{
if(x<=y)
{cout << x << " " << y << endl;}
else if(x>=y)
{cout << y << " " << x << endl;}
}
}
}


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

const int N = 2e3 + 5, M = 4e6 + 5;

int n, sum;
int a[N];
bitset <M> dp;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    dp[0] = true;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
        dp |= (dp << a[i]);
    }
    int x = (sum + 1) / 2;
    while (1){
        if (dp[x]) return cout << x, 0;
        x++;
    }
}

Measured memory_bytes: 5116