akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,j,n) for(int i = j; i < n; i++)


int main(){

	while(1){

		vector< vector<int> > map (21, vector<int>(21,0));
		vector< vector<int> > map2 (21, vector<int>(21,0));

		int px = 10, py = 10;

		int N;
		cin >> N;

		if(N == 0){
			break;
		}

		vector<int> tx(N);
		vector<int> ty(N);

		rep(i,N){
			cin >> tx[i];
			cin >> ty[i];
			map2[ty[i]][tx[i]] = 1;
		}

		int M;
		cin >> M;

		string str;
		int v;

		rep(i,M){
			cin >> str >> v;

			if(str == "N"){
				for(int i = py; i <= py + v; i++){
					map[i][px] = 1;
				}
				py += v;
			}
			else if(str == "E"){
				for(int i = px; i <= px + v; i++){
					map[py][i] = 1;
				}
				px += v;
			}
			else if(str == "S"){
				for(int i = py; i >= py - v; i--){
					map[i][px] = 1;
				}
				py -= v;
			}
			else if(str == "W"){
				for(int i = px; i >= px - v; i--){
					map[py][i] = 1;
				}
				px -= v;
			}
			  // rep(i,21){
			  // 	rep(j,21){
			  // 		cout << map[i][j] << " ";
			  // 	}
			  // 	cout << endl;
			  // }
			  // cout << endl;
		}

		int sum = 0;

		rep(i,21){
			rep(j,21){
				if(map[i][j] == 0 && map2[i][j] == 1){
					sum++;
				}
			}
		}

		if(sum == 0){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" <<endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <math.h>

#define Pi 3.14159265359

int main()
{
	int i, N, L, T[3001];
	scanf("%d %d", &N, &L);
	for (i = 1; i <= N; i++) scanf("%d", &(T[i]));
	
	int j;
	long double t[3001], sum[2] = {}, tmp[2], x = 0.0, y = 0.0, l;
	for (i = 1; i <= N; i++) {
		t[i] = (long double)T[i] * Pi * 2.0 / L;
		sum[0] += cos(t[i] / 2);
		sum[1] += sin(t[i] / 2);
	}
	for (i = 1; i <= N - 2; i++) {
		sum[0] -= cos(t[i] / 2);
		sum[1] -= sin(t[i] / 2);
		for (j = i + 1, tmp[0] = sum[0], tmp[1] = sum[1]; j <= N - 1; j++) {
			tmp[0] -= cos(t[j] / 2);
			tmp[1] -= sin(t[j] / 2);
			l = sin((t[j] - t[i]) / 4) * 2.0;
			x += cos((t[i] + t[j]) / 2) * (N - j) - l * (tmp[0] * sin((t[i] + t[j]) / 4) + tmp[1] * cos((t[i] + t[j]) / 4));
			y += sin((t[i] + t[j]) / 2) * (N - j) + l * (tmp[0] * cos((t[i] + t[j]) / 4) - tmp[1] * sin((t[i] + t[j]) / 4));
		}
	}
 
	printf("%.15Lf %.15Lf\n", x * 6.0 / N / (N - 1) / (N - 2), y * 6.0 / N / (N - 1) / (N - 2));
	fflush(stdout);
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define peek(v)      \
	for (auto i : v) \
		cout << i << ' ';
#define rep(i, begin, end) \
	for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

void solve()
{
	string s;
	cin >> s;
	s.replace(5, 1, " ");
	s.replace(13, 1, " ");
	cout << s;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
/*
std::vector<std::pair<std::set<int>, std::set<int>>> list;

int root_idx;

std::vector<int> FindLongestPathToRoot(int n){
	if(n == root_idx) {
      std::vector<int> v;
      v.push_back(n);
      return v;
    }
  	std::vector<int> max_path;
  	for(int parent : list[n].first){
    	auto tmp = FindLongestPathToRoot(parent);
    	if(tmp.size() > max_path.size()) max_path = tmp;
    }
  max_path.push_back(n);
  return max_path;
}

int main(){
  int N, M;
  scanf("%d %d", &N, &M);
  for(int i = 0; i < N; i++){
    list.push_back(std::make_pair(std::set<int>(), std::set<int>()));
  }
  for(int i = 0; i < N - 1 + M; i++){
  	int from, to;
    scanf(" %d %d", &from, &to);
    list[to - 1].first.insert(from - 1);	// in
    list[from - 1].second.insert(to - 1);	// out
  }
  for(int i = 0; i < N; i++){
  	if(list[i].first.size() == 0){
      root_idx = i;
      break;
    }
  }
  for(int i = 0; i < N; i++){
    if(list[i].first.size() == 0){
    	printf("0\n");
      continue;
    }
    if(list[i].first.size() <= 1){
      printf("%d\n", *list[i].first.begin() + 1);
      continue;
    }
    auto path = FindLongestPathToRoot(i);
    for(int p : path){
    }
    int p = 0;
    while(path.size()){
      p = path.back();
      path.pop_back();
      if(list[i].first.find(p) != list[i].first.end()){
        break;
      }
    }
    for(auto it = list[i].first.begin(); it != list[i].first.end(); )
        if(*it != p){
          list[*it].second.erase(list[*it].second.find(i));
          it = list[i].first.erase(it);
        }
      else ++it;
    printf("%d\n", *list[i].first.begin() + 1);
  }
  return 0;
}
*/

std::vector<int> list;
std::vector<int> distlist;

int main(){
  int N, M;
  scanf("%d %d", &N, &M);
  for(int i = 0; i < M; i ++){
  	int tmp;
    scanf(" %d", &tmp);
    list.push_back(tmp);
  }
  std::sort(list.begin(), list.end());
  auto left = list.begin();
  auto right = left + 1;
  while(right != list.end()){
  	distlist.push_back(std::abs(*left - *right));
    left = right;
    ++right;
  }
  std::sort(distlist.begin(), distlist.end());
  auto it = distlist.rbegin();
  for(int i = 0; i < N - 1; i++){
    if(it == distlist.rend()) break;
  	++it;
  }
  int sum = 0;
  while(it != distlist.rend()) {
    sum += *it;
    it++;
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 1400
#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;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

vi to[100005];
int ans = 0;
vb visited;

void bfs(int s) {
  queue<int> q;
  q.push(s);
  while(q.size()) {
    int u = q.front(); q.pop();
    visited[u] = true;
    for (int v : to[u])
    {
      if (!visited[v]) {
        q.push(v);
      }
    }
  }
}

int main() {
  int n,m; cin >>n>>m;
  rep(i,m) {
    int x,y,z; cin >> x >> y >> z;
    x--; y--;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  visited.resize(n, false);
  rep(i,n) {
    if (!visited[i]) {
      bfs(i);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6520
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

int main(int argc, char const *argv[])
{
    int A, B, C;
    cin >> A >> B >> C;

    cout << max({A, B, C}) - min({A, B, C}) << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0; i<(int)(n); i++)

using ll = long long;

const ll MOD = 1000000007;

int n,m;
int dat[125252];

int root(int x){
	return dat[x]<0?x:dat[x]=root(dat[x]);
}
void unite(int a, int b){
	a=root(a); b=root(b);
	if(a==b)return;
	if(dat[a]>dat[b])swap(a,b);
	dat[a]+=dat[b];
	dat[b]=a;
}

int main(){
	while(true){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		fill(dat,dat+n,-1);
		REP(i,m){
			int a,b;
			scanf("%d%d",&a,&b);
			--a; --b;
			unite(a,b);
		}
		int c = 0;
		REP(i,n)if(root(i)==i)c++;
		ll ans = 1;
		REP(i,c)ans=ans*2%MOD;
		if(c != n){
			ans = (ans+1)%MOD;
		}
		printf("%lld\n",ans);
	}
	return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

double ev(int n) { return n * (n + 1) / 2.0 / n; }

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> p(n);
  rep(i, n) std::cin >> p[i];

  double sum = 0;
  rep(i, k) { sum += ev(p[i]); }
  double maxv = sum;
  for (int i = k; i < n; i++) {
    sum = sum - ev(p[i - k]) + ev(p[i]);
    maxv = max(maxv, sum);
  }

  std::cout << fixed << setprecision(10) << maxv << std::endl;
  return 0;
}


Measured memory_bytes: 4008
n, m = map(int, input().split())
a = list(map(int, input().split()))

bc = [tuple(map(int, input().split())) for i in range(m)]

a.sort(key=lambda x: -x)
bc.sort(key=lambda x: -x[1])

s = sum(a)
ans = s

i = n - 1
index = 0
while i >= 0:
    if index >= m:
        break
    for j in range(bc[index][0]):
        if i < 0:
            break
        s -= a[i]
        s += bc[index][1]

        ans = max(ans, s)
        i -= 1
    index += 1

print(ans)


Measured memory_bytes: 25660
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)

inline vll move(vll p, char d) {
	if (d == 'U') {
		p[0]--;
	}
	else if (d == 'D') {
		p[0]++;
	}
	else if (d == 'R') {
		p[1]++;
	}
	else if (d == 'L') {
		p[1]--;
	}
	return p;
}

int main() {
	ll n, m;
	in(n);
	in(m);
	vector<string> a(n), b(m);
	string s = "", t;
	rep(i, 0, n) {
		in(a[i]);
	}
	rep(i, 0, m) {
		in(b[i]);
		s += b[i];
	}

	rep(i, 0, n - m + 1) {
		rep(j, 0, n - m + 1) {
			t = "";
			rep(k, 0, m) {
				t += a[i + k].substr(j, m);
			}
			if (s == t) {
				outn("Yes");
				return 0;
			}
		}
	}
	
	outn("No");
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int d,n;
  cin >> d >> n;
  if(d == 0){
    if(n < 100) cout << n << endl;
    else cout << 101 << endl;
  }
  if(d == 1){
    if(n < 100) cout << n*100 << endl;
    else cout << 10100 << endl;
  }
  if(d == 2){
    if(n < 100) cout << n*10000 << endl;
    else cout << 1010000 << endl;
  }
}

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

int main(){
  unsigned N;
  std::cin>>N;
  unsigned num = N*3;
  std::vector<unsigned long long> ary(num);
  for(auto &x:ary)
    std::cin>>x;
  std::sort(ary.begin(),ary.end());

  unsigned long long sum = 0;
  for(int i=num-2;i>num-2-2*N;i-=2){
    sum += ary[i];
  }

  std::cout<<sum<<std::endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  st s,t="";
  cin >> n >> s;
  ll mn=0,mx=0,cnt=0,tnc=0;
  rep(i,n){
    if(s[i]=='('){
      cnt++;
    }
    else{
      cnt--;
    }
    mn=min(cnt,mn);
    if(s[n-1-i]=='('){
      tnc++;
    }
    else{
      tnc--;
    }
    mx=max(tnc,mx);
  }
  st a,b;
  rep(i,(ll)abs(mn)){
    a+='(';
  }
  rep(i,(ll)abs(mx)){
    b+=')';
  }
  cnt+=abs(mn)-abs(mx);
  t=a+s+b;
  if(cnt>0){
    rep(i,cnt){
      t+=')';
    }
    cout << t << endl;
  }
  else{
    rep(i,abs(cnt)){
      t='('+t;
    }
    cout << t << endl;
  }
}

Measured memory_bytes: 256
N, K = map(int, input().split())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
tmp = Base_10_to_n(N, K)
tmp = str(tmp)
print(len(tmp))

Measured memory_bytes: 38484
#include<stdio.h>
using namespace std;

int main()
{
	int n,k,x;
	double v=0.0,w;
	scanf("%d%d",&n,&k);
	
	for(int i=1;i<=n;i++){
		x=i;
		w=1.0;
		while(x<k){
			x*=2;
			w*=(1.0/2.0);
		}
		v+=(1.0/n)*w;
	}
	
	printf("%.10f\n",v);
	
	return 0;
}


Measured memory_bytes: 128
#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());
  reverse(vec.begin(), vec.end());
  int a = 0, b = 0;
  for(int i = 0; i < N; i++) {
    if(i % 2 == 0) {
      a += vec.at(i);
    }
    else {
      b += vec.at(i);
    }
  }
  cout << a - b << endl;
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

typedef long long LL;

struct UnionFind {
	std::vector<int> _parent;
	std::vector<int> _size;
	UnionFind(int size) : _parent(size, -1), _size(size, 1) { }
	void unite(int a, int b) {
		int ra = root(a), rb = root(b); if (ra == rb) { return; }
		if (_size[ra] >= _size[rb]) { _parent[rb] = ra, _size[ra] += _size[rb]; } else { _parent[ra] = rb, _size[rb] += _size[ra]; }
	}
	int root(int a) {
		int p = _parent[a];
		if (p < 0) { return a; }
		while (_parent[p] >= 0) { p = _parent[p]; }
		return _parent[a] = p;
	}
	int size(int a) { return _size[root(a)]; }
};

int main(int argc, char *argv[]) {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; ++i) {
		cin >> s[i];
	}
	UnionFind uf(h * w);
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (i > 0) {
				if (s[i - 1][j] != s[i][j]) {
					uf.unite((i - 1) * w + j, i * w + j);
				}
			}
			if (j > 0) {
				if (s[i][j - 1] != s[i][j]) {
					uf.unite(i * w + j - 1, i * w + j);
				}
			}
		}
	}
	vector<LL> a(h * w), b(h * w);
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			int r = uf.root(i * w + j);
			if (s[i][j] == '#') {
				a[r]++;
			} else {
				b[r]++;
			}
		}
	}
	LL ans = 0;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			int k = i * w + j;
			if (uf.root(k) == k) {
				ans += a[k] * b[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	string s;
	while (cin >> s) {
		int tot = 0;
		int remind = 15 - (int)s.size();
		for (auto it : s) {
			tot += (it == 'o');
		}
		puts((tot + remind >= 8) ? "YES" : "NO");
	}
	return 0;
}


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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long n;
	cin>>n;
	for(long long i=0;i<n;i++){
		string s,t;
		cin>>s>>t;
		long long ss=s.size(),ts=t.size();
		vector<vector<long long>> dp(ss+1,vector<long long>(ts+1,-1));
		dp.at(0).at(0)=0;

		for(long long j=0;j<=ss;j++){
			for(long long k=0;k<=ts;k++){
				if(j==0 || k==0){
					dp.at(j).at(k)=0;
					continue;
				}

				if(s.at(j-1)==t.at(k-1)){
					dp.at(j).at(k)=dp.at(j-1).at(k-1)+1;
				}else{
					dp.at(j).at(k)=max(dp.at(j-1).at(k),dp.at(j).at(k-1));
				}
			}
		}

		cout<<dp.at(ss).at(ts)<<endl;
	}

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}



Measured memory_bytes: 10788
#include <bits/stdc++.h>
#define I 100007

using namespace std;

long long a[I], b[I], n, x, k;

int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 2; i <= n; i ++){
        x = 1000000000000000007;
        for(int j = 1; j <= k; j ++){
            if(i - j <= 0)break;
            x = min(x, abs(a[i] - a[i - j]) + b[i - j]);
        }
        b[i] = x;
    }
    cout << b[n] << endl;
    return 0;
}


Measured memory_bytes: 1792
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n = int(input())
a = list(map(int, input().split()))
c1, c2 = [0, a[0]], [a[n - 1]]
x, y = a[0], a[n - 1]
for i in range(n - 2):
    x = gcd(x, a[i + 1])
    y = gcd(y, a[n - 2 - i])
    c1.append(x)
    c2.append(y)
c2.reverse()
c2.append(0)
ans = 0
for i in range(n):
    if c1[i] != 0 and c2[i] != 0:
        m = gcd(c1[i], c2[i])
        ans = max(ans, m)
    else:
        ans = max(ans, max(c1[i], c2[i]))
print(ans)

Measured memory_bytes: 14524
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  	var one = nextIntArray();
	var N = one[0];
	var K = one[1];
	var set = new Set();
	for(var i = 0; i < K; i++){
		var d = nextInt();
		var dlist = nextIntArray();
		for(var j = 0; j < d; j++){
			set.add(dlist[j]);
		}
	}
	myout(N - set.size);
}

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

int a[12];
bool canMakeRectangle()
{
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (a[i * 4 + j] != a[i * 4 + j + 1]) return false;
		}
	}
	return true;
}

int main()
{
	for (int i = 0; i < 12; i++) cin >> a[i];
	sort(begin(a), end(a));
	if (canMakeRectangle()) cout << "yes" << endl;
	else cout << "no" << endl;

	return 0;
}

Measured memory_bytes: 3116
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  i32 N, L;
  cin >> N >> L;
  
  priority_queue<string, vector<string>, greater<string>> list;
  for(i32 i = 0; i < N; ++i) {
    string s;
    cin >> s;
    list.emplace(s);
  }
  string ans;
  ans.reserve(N*L);
  for(i32 i = 0; i < N; ++i) {
    auto s = list.top();
    list.pop();
    ans += s;
  }
  cout << ans << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
//なんかむずいんだけどw
// fuck
signed main(){
	int ans=0;
	int n,a,b; cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		string s=to_string(i);
		int m=s.size();
		int c=0,d=i;
		for(int j=0;j<=m;j++){
			c+=(d%(10));
			d/=(10);
		}
		if(c>=a && c<=b)ans+=i;
	}
	cout<<ans<<endl;
		
	
	return 0;
}

Measured memory_bytes: 3660
import math

k = int(input())

count = 0
value = 0
remain_sum = 7
digit_remain = 7

while True:
    if count > k:
        print(-1)
        break
    if remain_sum % k == 0:
        print(count+1)
        break
    digit_remain = digit_remain * 10 % k
    remain_sum += digit_remain

    count += 1

Measured memory_bytes: 9112
#include<iostream>
#include<cmath>
using namespace std;
int a,b;
int getlen(int x)
{
	int d=0,k=x;
	while(k)
	{
		d++;
		k/=10;
	}
	return d;
}
int main()
{
	cin>>a>>b;
	int len=getlen(b);
	int f=1;
	for(register int i=1;i<=len;i++)
		f*=10;
	int p=a*f+b;
	for(register int i=1;i<=350;i++)
		if(i*i==p){cout<<"Yes";return 0;}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
using namespace std;

int main()
{
    int n,  m,a,b;
    vector<int> h,state;
    int height;
    cin >> n >> m;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> height;
        h.push_back(height);
        state.push_back(1);
    }

    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        if (h[a - 1] > h[b - 1]) {
            state[b - 1] = 0;
        }
        else if (h[a - 1] < h[b - 1]) {
            state[a - 1] = 0;
        }
        else {
            state[a - 1] = 0;
            state[b - 1] = 0;
        }
    }

    for (int i = 0; i < n; i++) {
        if (state[i] == 1)ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int main()
{
  ll n,k;
  cin>>n>>k;
  ll a[n+1];
  for(ll i=1;i<=n;i++)
      cin>>a[i];

  ll dp[n+1][k+1];
  memset(dp,0,sizeof(dp));

  dp[0][0]=1;
  for(ll i=1;i<=n;i++)
  {
    ll pref[k+1]={0};
    pref[0]=dp[i-1][0]%mod;
    for(ll j=1;j<=k;j++)
      pref[j]=(pref[j-1]+dp[i-1][j])%mod;
    for(ll j=0;j<=k;j++)
    {
      if(j<=a[i])
        dp[i][j]=pref[j]%mod;
      else
      {
        dp[i][j]=(pref[j]-pref[j-a[i]-1]+mod)%mod;
      }
    }
  }

  cout<<dp[n][k]<<endl;
  return 0;
}

Measured memory_bytes: 83256
#include <stdio.h>

#define MAX_N 100002

typedef struct { char *p; int tm; } Q;
Q que[(MAX_N<<1)+2]; int top, end;
char name[MAX_N][20];

char buf[20], *p;
int in()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int  n, q, tm, i;
	Q  t;

	fgets(p=buf, 20, stdin);
	n = in(), q = in();
	for (i = 0; i < n; i++) {
		fgets(p=name[i], 20, stdin);
		while (*p > ' ') p++; *p++ = 0;
		que[i].p = name[i], que[i].tm = in();
	}

	tm = 0, top = 0, end = n;
	while (top != end) {
		t = que[top]; if (++top == MAX_N) top = 0;
		if (t.tm <= q) {
			printf("%s %d\n", t.p, tm+t.tm);
			tm += t.tm;
		} else {
			t.tm -= q;
			que[end] = t; if (++end == MAX_N) end = 0;
			tm += q;
		}
	}
	return 0;
}



Measured memory_bytes: 4208
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn = 100000;
const int mhw = 300;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main() {

	int h, w, d, q;
	vector<vector<ll>> distfs(mhw*mhw);
	map < ll, pair<int, int >> b;
	int l[maxn], r[maxn];

	cin >> h >> w >> d;

	rep(i, h) {
		rep(j, w) {
			ll c; cin >> c;
			b[c] = pair<int, int>(i, j);
		}
	}

	cin >> q;

	rep(i, q) {
		cin >> l[i] >> r[i];
	}

	for (int s = 0; s < d; s++) {
		distfs[s].push_back(0);
		for (int i = 0; s + d * (i+1) <= h * w; i++) {
			int np = s + d * i;
			ll pdist = distfs[s][distfs[s].size() - 1];
			ll ndist = abs(b[np].first - b[np + d].first) + abs(b[np].second - b[np + d].second);
			distfs[s].push_back(pdist + ndist);
		}
	}

	rep(i, q) {
		int s = l[i] % d;
		cout << distfs[s][(r[i] - s) / d] - distfs[s][(l[i] - s) / d] << endl;
	}

	return 0;
}

Measured memory_bytes: 11776
import sys


def culc(time):
    h=int(time[:2])
    m=int(time[3:5])
    s=int(time[6:8])

    return 3600*h+60*m+s


R=60*60*24
while True:
    n=int(input())
    if n==0:
        sys.exit()
    
    L=[0]*(R+1)
    for i in range(n):
        leave,arrive=map(str,input().split())
        leave=culc(leave)
        arrive=culc(arrive)
        L[leave]+=1
        L[arrive]-=1
    
    for i in range(1,R):
        L[i]+=L[i-1]
    
    ans=0
    for i in range(R):
        ans=max(ans,L[i])
    print(ans)

        


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

#define ll long long
#define pb push_back
int main()
{

  string ss,s;
  cin>>ss>>s;
  int len=ss.size();
  string s1=s.substr(0,len);
  if(ss==s1)cout<<"Yes";
  else cout<<"No";
  
}

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

int imos[30][100005];

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

  rep(i,N) {
    int s,t,c;
    cin >> s >> t >> c;
    --s;--c;
    imos[c][s]++;
    imos[c][t]--;
  }
  rep(c,C) rep(i,100005) if ( i > 0) imos[c][i] += imos[c][i-1];  
  rep(c,C) rep(i,100005) if (imos[c][i] > 1) imos[c][i] = 1; //各チャンネルで重なっているところは1台で連続して録画できる

  int res = 0;

  rep(i,100005) {
    int cnt = 0;
    rep(c,C) cnt += imos[c][i];
    res = max(res,cnt);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 11904
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int K; cin >> K;
	
	int N = (1 << K);
	
	multiset<int> data;
	
	F0R(i, N) {
		int cur; cin >> cur; data.insert(cur*-1);
	}
	
	vi vals;
	vals.pb(*data.begin());
	data.erase(data.begin());
	
	F0R(iteration, K) {
		vi newVals;
		F0R(i, sz(vals)) {
			if (data.upper_bound(vals[i]) == data.end()) {
				cout << "No" << endl; return 0;
			}
			newVals.pb(*(data.upper_bound(vals[i])));
			data.erase(data.upper_bound(vals[i]));
		}
		
		F0R(i, sz(newVals)) {
			vals.pb(newVals[i]);
		}
		
	}
	
	cout << "Yes" << endl; return 0;	
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 13984
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl a(n),b(n+1,0);
	cin>>a;
	partial_sum(all(a),b.begin()+1);
	vvl dp(n+1,vl(n,LINF));
	rep(i,n)dp[1][i]=a[i];
	range(len,1,n+1){
		rep(st,n){
			if(st+len>n)continue;
			range(l,1,len){
				chmin(dp[len][st],dp[l][st]+dp[len-l][st+l]+b[st+len]-b[st]);
			}
		}
		//puta(dp[len]);
	}
	puta(dp[n][0]-b[n]);
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <iostream>

#define LENGTH 10

int main() {
    char S[LENGTH + 1];
    char T[LENGTH + 2];
    int i = 0;

    scanf("%s", S);
    //printf("%s\n", S);
    scanf("%s", T);
    //printf("%s\n", T);

    while (S[i] != '\0') {
        //printf("%c %c\n", S[i], T[i]);
        if (S[i] != T[i]) {
            printf("No\n");
            exit(0);
        }
        i++;
    }

    printf("Yes\n");

    return 0;
}

Measured memory_bytes: 3136
H, W = map(int, input().split())
if H < W:
    a = H
    H = W
    W = a

if (H * W) % 3 == 0:
    print(0)
else:
    ans = [0, 0, 0, 0]
    for i in range(2):
        H_left = H - (H // 3 + i)
        first = (H // 3 + i) * W
        if (H_left * W) % 2 == 0:
            second = third = H_left * W / 2
        else:
            second = (H_left * W) - (max(H_left, W) // 2) * min(H_left, W)
            third = (H_left * W) - second
        ans[i] = max(first, second, third) - min(first, second, third)
    for i in range(2):
        W_left = W - (W // 3 + i)
        first = (W // 3 + i) * H
        if (W_left * H) % 2 == 0:
            second = third = W_left * H / 2
        else:
            second = (W_left * H) - (max(W_left, H) // 2) * min(W_left, H)
            third = (W_left * H) - second
        ans[i+2] = max(first, second, third) - min(first, second, third)
    print(int(min(ans)))


Measured memory_bytes: 3064
#include <stdio.h>
int main(){
 int a;
 scanf("%d",&a);
  if (a == 22)
    printf("Christmas Eve Eve Eve");
  else if (a == 23)
    printf("Christmas Eve Eve");
  else if (a == 24)
    printf("Christmas Eve");
  else 
    printf("Christmas");
  return 0;
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
}

Measured memory_bytes: 128
//abc136_c.cpp
//Sun Aug  4 21:09:55 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

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

	for (int i=0;i<n-1;i++){
		if (h[i]-h[i+1]>1){
			cout << "No" << endl;
			return 0;
		}else if (h[i]-h[i+1]<=1 && 
				  (i==0 || h[i]-h[i-1]>=1)){
			h[i]--;
		}
	}

	for (int i=1;i<n;i++){
		if (h[i]>=h[i-1]){
			continue;
		}else {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 640
package main

import "fmt"

func trace(A []int, N int) {
	for i := 0; i < N; i++ {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Printf("%d", A[i])
	}
	fmt.Println("")
}

func insertionSort(A []int, N int) {
	var i, j, v int
	for i = 1; i < N; i++ {
		v = A[i]
		j = i - 1
		for j >= 0 && A[j] > v {
			A[j+1] = A[j]
			j--
		}
		A[j+1] = v
		trace(A, N)
	}
}

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	trace(A, N)
	insertionSort(A, N)
}



Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N, L;
    cin >> N >> L;

    int ans = INF32;
    int mn  = INF32;
    int all = 0;
    REP(i, N) { all += L + i; }
    REP(i, N) {
        int sum = 0;
        REP(j, N) {
            if (i == j)
                continue;
            sum += L + j;
        }
        if (chmin(mn, abs(sum - all))) {
            ans = sum;
        };
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
def main():
    from itertools import accumulate

    n, q, s, *lr = open(0).read().split()
    n = int(n)
    *l, = map(int, lr[::2])
    *r, = map(int, lr[1::2])
    c = [1 if s[i] == 'C' and s[i - 1] == 'A' else 0 for i in range(n)]
    a = list(accumulate(c))
    ans = ''
    for i,j in zip(l,r):
        ans += str(a[j-1]-a[i-1]) + '\n'
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30592
s=input()
alp='abcdefghijklmnopqrstuvwxyz'

if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

d={}
e={}
for i in range(len(alp)):
    d[alp[i]]=i
    e[i]=alp[i]

n=len(s)
if n!=26:
    ans=[]
    for i in range(n):
        ans.append(d[s[i]])

    for j in range(26):
        if j not in ans:
            ans.append(j)
            break

    st=''
    for k in ans:
        st+=e[k]
else:
    arr=[]

    dp=[]
    for i in range(n):
        dp.append(d[s[i]])
    
    while True:
        v=dp.pop()

        tmp=[j for j in arr if j>v]
        if len(tmp)!=0:
            dp.append(min(tmp))
            break
        
        arr.append(v)
        
    st=''
    for k in dp:
        st+=e[k]



print(st)

Measured memory_bytes: 8924
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

const ll inf = 1e18+7;
const ll mod = 1e9+7;

int main(){
	ll k,n,ans=0,ma=0;
	cin >> k >> n;
	vector<ll> A(n,0);
	vector<ll> S(n,0);
	rep(i,n){cin >> A[i];
	ma = max(ma,A[i]);
	}

	for(ll i = 0;i<n;i++){
		if(i==n-1){
			S[i] = k - ma + A[0];
		}else{
		    S[i] = abs(A[i]-A[i+1]);
		}
	}

	sort(S.begin(),S.end());

	for(ll i=0;i<n-1;i++){
		ans += S[i];
	}

	cout << ans << endl;

	return 0;

}

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

using namespace std;

int main(){
	string s; cin >> s;
	if(s.front() == s.back()){
		if(s.size()%2 == 0){
			cout << "First" << endl;
		}
		else{
			cout << "Second" << endl;
		}
	}
	else{
		if(s.size()%2 == 1){
			cout << "First" << endl;
		}
		else{
			cout << "Second" << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <functional>
#include <cmath>
#include <map>
using namespace std;

long long n, a, b, c, d;

long long miniman(long long p, long long q) {
	if (p < q) swap(p, q);
	long long S = p + q;
	return (S / (q + 1));
}

long long solve(long long p, long long q) {
	long long Z1 = p / q, Z2 = p%q;
	return Z1*(q + 1) + Z2;
}

string query(long long p, long long q, long long rr, long long ss) {
	long long G = miniman(p, q);
	if (p >= q) {
		long long L = 0, R = q + 1, M, maxn = 0, maxid = 0;
		for (long long i = 0; i < 30; i++) {
			M = (L + R) / 2;
			long long F1 = M*(G + 1), F2 = solve(q - M, G); F2 = (p + q) + 1 - F2;
			if (F1 < F2) { if (maxn < M) { maxn = M; maxid = F2; } L = M; }
			else { R = M; }
		}
		string S = "";
		for (long long i = rr; i <= ss; i++) {
			if (i <= maxn*(G + 1)) {
				if (i % (G + 1) == 0) S += "B";
				else S += "A";
			}
			else {
				if (i < maxid) S += "A";
				else if ((p + q - i + 1) % (G + 1) == 0) S += "A";
				else S += "B";
			}
		}
		return S;
	}
	return "";
}

int main() {
	cin >> n;
	for (long long i = 0; i < n; i++) {
		cin >> a >> b >> c >> d; bool flag = false;
		if (a < b) { swap(a, b); c = (a + b + 1) - c; d = (a + b + 1) - d; swap(c, d); flag = true; }
		string SS = query(a, b, c, d);
		if (flag == true) {
			reverse(SS.begin(), SS.end());
			for (long long j = 0; j < SS.size(); j++) { if (SS[j] == 'A')SS[j] = 'B'; else SS[j] = 'A'; }
		}
		cout << SS << endl;
	}
	return 0;
}

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

int main () {
  int n;
  cin >> n;
  long long sum = 0;
  rep(i, n) if (i % 3 != 0 && i % 5 != 0) sum += i;
  cout << sum << endl;
}

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

int main()
{
    int n,i;
    cin>>n;
    vector<long long> a(n);
    for(i=0;i<n;++i)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(i=0;i<a.size()-1;++i)
    {
        if(a[i]==a[i+1])
        {
            cout<<"NO\n";
            return 0;
        }
    }
    cout<<"YES\n";
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int mod=1e9+7;
const int N=1e5+5;
ll cnt[N];
ll n,k,ans;

ll pow(ll num){
    ll res=1,m=n;
while(m>0){
    if(m&1)
    res=res*num%mod;
    num=num*num%mod;
    m>>=1;
}
//cout<<res<<'.'<<endl;
return res;
}

int main(){
ios::sync_with_stdio(0);
cin>>n>>k;
for(ll i=k;i>=1;i--){
    cnt[i]=pow(k/i);
    for(ll j=2;j*i<=k;j++){
        cnt[i]-=cnt[j*i];
    }
    ans+=(mod+(cnt[i]*i)%mod)%mod;
    ans=(ans+mod)%mod;
    //cout<<ans<<endl;
}
cout<<ans<<endl;
return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}
template<class T>
void DEBUG_DP(T* viewdp, int ilen, int jlen){
    REP(i,ilen){
        REP(j,jlen){
            if(viewdp[i][j] != -1)
                printf("[% 4d]", viewdp[i][j]);
            else
                printf("[    ]");
        }
        puts("");
    }
}

ll n;
int ans;

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int solve(ll a, ll b){
    return max(to_string(a).size(), to_string(b).size());
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    auto fact = divisor(n);
    //DEBUG_VEC(fact);
    ll d = 1;
    
    ans = to_string(n).size();
    for(auto i : fact){
        if(n/i < i) break;
        chmin(ans, solve(n/i, i));
    }

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

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int dis[N][3];
vector<int> v[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	while (m--)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
	}
	int s, t;
	cin >> s >> t;
	queue<pair<int,int>> q;
	q.emplace(s, 0);
	dis[s][0] = 1;
	while (!q.empty())
	{
		int x, o;
		tie(x, o) = q.front();
		q.pop();
		int d = dis[x][o];
		o++;
		if (o == 3) o = 0;
		for (auto& y : v[x])
		{
			if (dis[y][o]) continue;
			dis[y][o] = d + 1;
			q.emplace(y, o);
		}
	}
	int ans = dis[t][0] / 3;
	if (ans == 0) puts("-1");
	else printf("%d\n", ans);
	return 0;
}

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

int main() {
  string ans;
  int n;
  cin >> n;
  int A = n / 100, B = n % 100;
  if (A < 1 || 12 < A) {
      if (B < 1 || 12 < B) {
          ans = "NA";
      }
      else {
          ans = "YYMM";
      }
  }
  else {
      if (B < 1 || 12 < B) {
          ans = "MMYY";
      }
      else {
          ans = "AMBIGUOUS";
      }
  }
  cout << ans << endl;
}

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M;
	cin >> N >> M;
	vector<int> P(M), cnt(N + 1);
	for (int i = 0; i < M; i++) {
		cin >> P[i];
	}
	for (int i = 1; i < M; i++) {
		int mi = min(P[i - 1], P[i]), ma = max(P[i - 1], P[i]);
		cnt[mi]++; cnt[ma]--;
	}
	ll res = 0;
	for (int i = 1; i < N; i++) {
		cnt[i] += cnt[i - 1];
		ll A, B, C;
		cin >> A >> B >> C;
		res += min(A * cnt[i], C + B * cnt[i]);
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3564
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    print(Yes if input()==input()[:-1] else No)

main()



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

int main(){
  int n;
  string s;
  vector<int> count(4,0);
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=="AC")
      count[0]++;
    else if(s=="WA")
      count[1]++;
    else if(s=="TLE")
      count[2]++;
    else if(s=="RE")
      count[3]++;
  }
  cout<<"AC x "<<count[0]<<endl;
   cout<<"WA x "<<count[1]<<endl;
   cout<<"TLE x "<<count[2]<<endl;
   cout<<"RE x "<<count[3]<<endl;
  return 0;
}


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

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

    int ans = 0;
    int end_with_a = 0;
    int start_with_b = 0;
    int start_with_b_and_end_with_a = 0;
    string s;
    for (int i = 0; i < N; i++)
    {
        cin >> s;
        for (int i = 0; i + 1 < s.size(); i++)
        {
            if (s[i] == 'A' && s[i + 1] == 'B')
            {
                ans++;
            }
        }

        if (s.front() == 'B' && s.back() == 'A')
        {
            start_with_b_and_end_with_a++;
        }
        else
        {
            if (s.front() == 'B')
            {
                start_with_b++;
            }
            if (s.back() == 'A')
            {
                end_with_a++;
            }
        }
    }

    if (start_with_b_and_end_with_a > 0)
    {
        if (start_with_b > 0 || end_with_a > 0)
        {
            ans += min(start_with_b, end_with_a);
            ans += start_with_b_and_end_with_a;
        }
        else
        {
            ans += start_with_b_and_end_with_a - 1;
        }
    }
    else
    {
        ans += min(start_with_b, end_with_a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256