akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);


	ll n;
	cin>>n;
	map<ll, ll> mp;
	while (n % 2 == 0)
    {
        mp[2]++;
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            mp[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        mp[n]++;

	ll ans=0;
	ll cur=1;
	for(auto &x : mp){
	    //cout<<x.fi<<" "x.se<<"\n";
		while(x.se>=cur){
			ans++;
			x.se-=cur;
			cur++;
			
		}
		cur=1;
	}
cout<<ans;
    return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define _USE_MATH_DEFINES
#include <cmath>

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

using namespace std;
typedef long long ll;

const int MAXH = 500100;

void maxHeap(int i, int H, int *A) {
   int l, r, largest;

   l = 2 * i;
   r = 2 * i + 1;

   if (l <= H && A[l] > A[i]) largest = l;
   else largest = i;
   if (r <= H && A[r] > A[largest]) largest = r;

   if (largest != i) {
      swap(A[i], A[largest]);
      maxHeap(largest, H, A);
   }
}

int main() {
   int H, A[MAXH];

   cin >> H;
   for (int i = 1; i <= H; i++) {
      scanf("%d", &A[i]);
   }
   for (int i = H / 2; i >= 1; i--) {
      maxHeap(i, H, A);
   }
   for (int i = 1; i <= H; i++) {
      cout << " " << A[i];
   }
   cout << endl;

   return(0);
}



Measured memory_bytes: 5088
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
a = []
for i in range(n):
    am = list(map(int, input().split()))
    a.append(am)
num = 0
for h in range(n):
    t = 0
    for j in range(m):
        t += a[h][j]*b[j]
    if 0 < t+c:
        num += 1
print(num)

Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,w;
  cin>>n>>w;
  long long int wt[n],val[n];
  for(int i=0;i<n;i++)
  {
    cin>>wt[i]>>val[i];
  }
  long long int dp[n+1][w+1];
  for(int i=0;i<=n;i++)
  {
    dp[i][0]=0;
  }
  for(int i=1;i<=w;i++){
    dp[0][i]=0;
  }
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=w;j++)
    {
      if(wt[i-1]<=j)
        dp[i][j]=max(dp[i-1][j-wt[i-1]]+val[i-1],dp[i-1][j]);
      else
        dp[i][j]=dp[i-1][j];
    }
  }
  cout<<dp[n][w];
}

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

using namespace std;

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));

#define debug(x) std::cout << #x << ": " << x << endl
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

//------------------------------------------------------------------------//
int T;
const int maxn = 1e3+5;
const int maxv = 2e5+5; //max(H+W)
int h, w, n;

ll inv[maxv], fac[maxv], facinv[maxv];

void build(int h, int w)
{
  fac[0] = facinv[0] = 1;
  inv[1] = 1; fac[1] = 1; facinv[1] = 1;
  rep(i, 2, h+w+5)
  {
    fac[i] = fac[i-1]*i%mod;
    inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
    facinv[i] = facinv[i-1]*inv[i]%mod; //type i -> i-1
  }
}

ll calc(ll n, ll m) //C(n+m, m)
{
  return fac[n+m]*facinv[n]%mod*facinv[m]%mod;
}

//compression
void solve()
{
   cin >> h >> w >> n;
   build(h, w);
   //use a^(mod-2) can do a inverse too (O(log(mod)))
   //or extended gcd
   vector<pll> ps;
   ll xi, yi;
   rep(i, 0, n)
   {
     cin >> xi >> yi;
     ps.pb(mp(xi, yi));
   }
   ps.pb(mp(ll(h), ll(w)));

   function<bool(pll&, pll&)> cmp = [&](pll &a, pll &b)
   {
     return a.X+a.Y < b.X+b.Y;
   };
   sort(all(ps), cmp);

   vector<ll> dp(n+1);
   rep(i, 0, n+1)
   {
     dp[i] = calc(ps[i].X-1, ps[i].Y-1);
     //debug(dp[i]);
     rep(j, 0, i) if(ps[j].X <= ps[i].X && ps[j].Y <= ps[i].Y)
     {
       dp[i] -= dp[j] * calc(ps[i].X-ps[j].X, ps[i].Y-ps[j].Y) % mod;
       dp[i] = (dp[i]%mod+mod)%mod;
     }
   }
   cout << dp[n] << endl;

   return;
}


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


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

int main(){
    int N;
    int i;
    string S;
    map<string,int> mp;
    cin >> N;
    for(i=0;i<N;i++){
        cin >> S;
        mp[S]++;
    }
    int ans=0;
    for(auto u : mp)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 19260
#include <stdio.h>

int main()
{
  int i, j, a[100], n, minj, count = 0, temp, b = 0;

  scanf("%d",&n);

  for(i = 0; i < n; i++)
    {
      scanf("%d",&a[i]);
    }

  for(i = 0; i < n; i++)
    {
      minj = i;
      for(j = i; j < n; j++)
	{
	  if(a[j] < a[minj])
	    {
	      minj = j;
	      b++;
	    }
	}
      if(b != 0)
	{
	  temp = a[i];
	  a[i] = a[minj];
	  a[minj] = temp;
	  count++;
	  b = 0;
	}
    }

  for(i = 0; i < n-1; i++)
    {
      printf("%d ",a[i]);
    }

  printf("%d\n",a[n-1]);
  printf("%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N; cin>>N;
  vector<int> button(N+1);
  button[0] = -9;
  for(int i = 1; i <= N; i++) {
    cin >> button[i];
  }

  int next_button = button[1];
  int cnt = 1;
  for(int i = 1; i < N+1; i++) {
    if(next_button == 2) {
      break;
    }
    if(i == N) {
      cnt = -1; break;
    }
    next_button = button[next_button];
    cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	cout << (n%2==0? n*(n-2)/2:(n-1)*(n-1)/2)<<endl;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(n%2==0){
				if(i+j==n+1){
					continue;
				}
			}
			else{
				if(i+j==n){
					continue;
				}
			}
			cout << i << " " <<j<<endl;
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n,a;
    cin>>n>>a;
    cout<<n*n-a<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct NodeB
{
	int parent;
	int left;
	int right;
};
NodeB nodes[30];
int nodeHeight[30];
int nodeDepth[30];
int nodeDegree[30];
string nodeKind[30];
void depth(int id,int count)
{
	if (id == -1)return;
	nodeDepth[id] = count;
	int leftId = nodes[id].left;
	int rightId = nodes[id].right;
	depth(leftId, count + 1);
	depth(rightId,count + 1);
}
int height(int id)
{
	if (id == -1)return -1;
	int leftMax = height(nodes[id].left) + 1;
	int rightMax = height(nodes[id].right) + 1;
	if (leftMax < rightMax)
	{
		return nodeHeight[id] = rightMax;
	}
	else
	{
		return nodeHeight[id] = leftMax;
	}
}
int sibling(int id)
{
	if (nodes[id].parent == -1)return -1;
	if (nodes[nodes[id].parent].left == id)
	{
		return nodes[nodes[id].parent].right;
	}
	else
	{
		return nodes[nodes[id].parent].left;
	}
}
void degree(int id)
{
	int d = 2;
	if (nodes[id].left == -1)d--;
	if (nodes[id].right == -1)d--;
	nodeDegree[id] = d;
}
void kindName(int id)
{
	string s = "internal node";
	if (nodes[id].parent == -1)s = "root";
	else if (nodes[id].left == -1 && nodes[id].right == -1)s = "leaf";
	nodeKind[id] = s;
}

void print(int id)
{
	degree(id);
	kindName(id);
	cout << "node " << id << ": parent = " << nodes[id].parent << ", ";
	cout << "sibling = " << sibling(id) << ", degree = " << nodeDegree[id] << ", ";
	cout << "depth = " << nodeDepth[id] << ", height = " << nodeHeight[id] << ", ";
	cout << nodeKind[id] << endl;
}
void B()
{
	int n;
	int rootId;
	cin >> n;
	for (int i = 0; i < n; i++)nodes[i].parent = -1;
	for (int i = 0; i < n; i++)
	{
		int id, left, right;
		cin >> id >> left >> right;
		nodes[id].left = left;
		nodes[id].right = right;
		if (left != -1)nodes[left].parent = id;
		if (right != -1)nodes[right].parent = id;
	}

	for (int i = 0; i < n; i++)
	{
		if (nodes[i].parent == -1)rootId = i;
	}

	depth(rootId,0);
	height(rootId);
	for (int i = 0; i < n; i++)
	{
		print(i);
	}
}

int main()
{
	B();
	return 0;
}

Measured memory_bytes: 1212
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[2][200010] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll a[110];
    rep(i,0,N) cin >> a[i];
    dp[0][0] = 1;
    ll cur = 0, nxt = 1;
    rep(i,0,N){
        rep(j,0,K+1) dp[nxt][j] = 0;
        rrep(j,K,0){
            dp[nxt][j] += dp[cur][j];
            dp[nxt][j] %= MOD;
            dp[nxt][j+a[i]+1] = (dp[nxt][j+a[i]+1] - dp[cur][j] + MOD) % MOD;
        }
        rep(j,0,K+1) (dp[nxt][j+1] += dp[nxt][j]) %= MOD;
        nxt ^= 1; cur ^= 1;
    }
    print(dp[cur][K]);
    

}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <queue>
#include <vector>
using namespace std;

struct Mycomp {
private:
	bool reverse;
public:
	Mycomp(bool rev = false) : reverse(rev) {};
	bool operator()(const long &lhs, const long &rhs) {
		if (reverse) return rhs < lhs;
		return lhs < rhs; 
	}
};

int main() {
	typedef priority_queue<long, vector<long>, Mycomp> mypq_type;
	//mypq_type pq(Mycomp(true));
	mypq_type pq;
	string s;
	while (cin >> s) {
		if (s == "end") break;
		if (s == "extract") {
			cout << pq.top() << endl;
			pq.pop();
		}
		if (s[0] == 'i') {
			long t;
			cin >> t;
			pq.push(t);
		}
	}
	return 0;
}




Measured memory_bytes: 11256
#include <stdio.h>

#define MAX 100005

typedef long long int lli;

void input(lli *,lli *,int );
lli work(lli *,lli *,int );


int main()
{
	int n;
	lli a[MAX],b[MAX];
	lli count;

	scanf("%d",&n);
	input(a,b,n);

	count=work(a,b,n);

	printf("%lld\n",count);

	return 0;
}

void input(lli *a,lli *b,int n)
{
	for(int i=0; i<n+1; i++)
		scanf("%lld",&a[i]);

	for(int i=0; i<n; i++)
		scanf("%lld",&b[i]);
}

lli work(lli *a,lli *b,int n)
{
	lli count=0;

	for(int i=0; i<n; i++){
		if(a[i]>b[i]){
			a[i]-=b[i];
			count+=b[i];
			b[i]=0;
		}
		else{
			b[i]-=a[i];
			count+=a[i];
			a[i]=0;
		}

		if(b[i]>0){
			if(a[i+1]>b[i]){
				a[i+1]-=b[i];
				count+=b[i];
				b[i]=0;
		}
			else{
				b[i]-=a[i+1];
				count+=a[i+1];
				a[i+1]=0;
			}
		}
	}

	return count;
}

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

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> H(N), A(M), B(M);
    for (int i = 0; i < N; i++) cin >> H[i];
    vector<bool> tmp(N);
    for (int i = 0; i < N; i++) tmp[i] = true;
    for (int i = 0; i < M; i++) cin >> A[i] >> B[i];
    for (int i = 0; i < M; i++){
        if(H[A[i]-1]>H[B[i]-1]){
          tmp[B[i] - 1] = false;
        } else if (H[B[i] - 1] > H[A[i] - 1]) {
          tmp[A[i] - 1]=false;
        }else if(H[B[i]-1]==H[A[i]-1]){
          tmp[A[i] - 1] = false;
          tmp[B[i] - 1] = false;
        }
    }
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
      if (tmp[i] == true) cnt++;
    }
    cout << cnt<< endl;
    return 0;
}

Measured memory_bytes: 5636
#include <stdio.h>
int a[21][21];
int x=10,y=10;

void init(){
	int i,j;
	for(i=0; i<21; i++){
		for(j=0; j<21; j++){
			a[i][j]=0;
		}
	}
	x=10;
	y=10;
}

int check(){
	int i,j;
	for(i=0; i<21; i++){
		for(j=0; j<21; j++){
			if(a[i][j])return 0;
		}
	}
	return 1;
}

int main(){
	int n,s,m;
	int i,j,k,l;
	char c,d;

	while(1){
		scanf("%d",&n);
		if(n==0)break;
		init();
		for(i=0; i<n; i++){
			scanf("%d %d",&j,&k);
			a[j][k]=1;
		}
		scanf("%d",&m);
		for(i=0; i<m; i++){
			scanf("%c%c %d",&d,&c,&l);
			for(j=0; j<l; j++){
				if(c=='N')y++;
				if(c=='S')y--;
				if(c=='E')x++;
				if(c=='W')x--;
				if(a[x][y])a[x][y]=0;
			}
		}
		if(check())printf("Yes\n");
		else printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
typedef long long ll;
ll MOD=(ll)1e9+7;
ll qpow(ll a,ll b){return b?((b&1)?a*qpow(a*a%MOD,b>>1)%MOD:qpow(a*a%MOD,b>>1))%MOD:1;}
ll c(ll n,ll m){
    ll ret=1;
    if(n<m)return 0;
    rep(i,1,m){
        ret*=qpow(i,MOD-2);
        ret%=MOD;
        ret*=n-i+1;
        ret%=MOD;
    }
    return ret;
}
ll p(ll n,ll m){
    ll ret=1;
    if(n<m)return 0;
    rep(i,1,m){
        /* ret*=qpow(i,MOD-2);
        ret%=MOD; */
        ret*=n-i+1;
        ret%=MOD;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    cout<<c(k,n)<<endl;
}


Measured memory_bytes: 3156
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	char s;
	int a = 0;
	REP(i,4) {

		cin >> s;
		if (s == '+') {
			a++;
		}
		else if(s=='-'){
			a--;
		}
	
	}
	cout << a << endl;
	return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long A, long long B, long long C)
{
    set<tuple<ll, ll, ll>> s;
    int ans = 0;
    vector<ll> tmp(3);

    while (1)
    {
        if (A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
        {
            if (A == B && B == C)
            {
                cout << -1 << endl;
                return;
            }
            ll tmpA = B / 2 + C / 2, tmpB = A / 2 + C / 2, tmpC = B / 2 + A / 2;
            A = tmpA;
            B = tmpB;
            C = tmpC;
            ans++;
        }
        else
        {
            cout << ans << endl;
            return;
        }
    }
}

int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

l, r = 1, 10 ** 9
while l < r:
    m = (l + r) // 2
    if sum(map(lambda v: (v - 1) // m, a)) > k:
        l = m + 1
    else:
        r = m
print(l)


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B, N;
	cin >> A >> B >> N;

	int x = min(N, B - 1);

	cout << (A*x / B) - A * (x / B) << endl;

	return 0;
}


Measured memory_bytes: 3648
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
#include <pthread.h>
#include <omp.h>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
#define _USE_MATH_DEFINES
using namespace std;
using namespace std::chrono;

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;
    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;
  
  return m;
}

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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  int p[a], q[b], r[c];
  
  for (int i = 0; i < a; i++)
    cin >> p[i];
  for (int i = 0; i < b; i++)
    cin >> q[i];
  for (int i = 0; i < c; i++)
    cin >> r[i];

  sort(p, p + a, greater<>());
  sort(q, q + b, greater<>());
  sort(r, r + c, greater<>());

  Vi v;
  for (int i = 0; i < x; i++)
    v.pb(p[i]);
  for (int i = 0; i < y; i++)
    v.pb(q[i]);
  for (int i = 0; i < c; i++)
    v.pb(r[i]);

  sort(v.begin(), v.end(), greater<>());
  int ans = 0;
  for (int i = 0; i < x + y; i++)
    ans += v[i];
  cout << ans << endl;
  
}


Measured memory_bytes: 9764
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    string s,t;cin>>s>>t;
    ll n,m;
    n=s.size();
    m=t.size();
    string ans="UNRESTORABLE";
    bool b;
    for(ll i=n-m;i>=0;i--){
        b=true;
        for(ll j=0;j<m;j++){
            if(t[j]==s[i+j] || s[i+j]=='?'){
                
            }else{
                b=false;
            }
        }
        if(b){
            ans="";
            for(ll k=0;k<i;k++){
                if(s[k]=='?'){
                    ans=ans+'a';
                }else{
                    ans=ans+s[k];
                }
            }
            ans=ans+t;
            for(ll k=i+m;k<n;k++){
                if(s[k]=='?'){
                    ans=ans+'a';
                }else{
                    ans=ans+s[k];
                }
            }
            i=-1;
        }
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef tester
    #include "prettyprint.hpp"
#endif
using namespace std;

#define hell 1000000007
#define ll long long
#define all(C) begin(C),end(C)
#define tr(C,it,cond) for(auto it = begin(C); cond and it!=end(C); ++it)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pb push_back
#define hash unordered_map
#define vi vector<ll>
#define pii pair<ll,ll>
#define index(V, ele) distance(V.begin(), find(all(V), ele))
#define N 100005

#define whats(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {} template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
#ifdef tester 
    cerr << *it << " = " << a << endl;	err(++it, args...); 
#endif 
}

ll t,n,k,m,q;
string s;
set<ll> res;

void f(int x, int y, int z){
    if (x+y+z <= 9){
        // form min string
        string le;
        rep(i,0,x)
            le += '3';
        rep(i,0,y)
            le += '5';
        rep(i,0,z)
            le += '7';

        // make permu
        // add permu
        do{
            res.insert(strtol(le.c_str(),NULL,10));
        }while(next_permutation(all(le)));

        // recurr for +1's
        f(x+1,y,z);f(x,y+1,z);f(x,y,z+1);
    }
}

// vim cli: !g++ -Dtester sol.cpp ; ./a.out ; rm a.out
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(20);

    cin >> n;
    f(1,1,1);

    if (res.find(n) == res.end())
        cout << distance(res.begin(),res.lower_bound(n));
    else 
        cout << distance(res.begin(), res.find(n)) + 1;
    // whats(t,v);
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

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

int main()
{
  ll h,w,sx,sy,gx,gy;
  cin>>h>>w>>sx>>sy>>gx>>gy;
  sx--;sy--;gx--;gy--;
  vector<string> field(h);
  for(auto&& e: field) 
  {
    cin>>e;
  }

  vector<vector<ll>> dist(h,
    vector<ll>(w,-1));
  dist[sx][sy]=0;
  vector<vector<bool>> seen(h,
    vector<bool>(w,false));
  queue<pair<ll,ll>> next;
  queue<pair<ll,ll>> next2;
  next.push({sx,sy});
  seen[sx][sy]=true;
  label:
  while(!next.empty())
  {
    ll x=next.front().first;
    ll y=next.front().second;
    next.pop();
    for (int i = -2; i <= 2; ++i)
    {
      for (int j = -2; j <= 2; ++j)
      {
        if(i==0&&j==0) continue;
        ll nx=x+i,ny=y+j;
        if(nx<0||ny<0||nx>=h||ny>=w) continue;
        if(field[nx][ny]=='#') continue;
        if(seen[nx][ny]) continue;
        if((abs(i)+abs(j))>=2)
        {
          next2.push({nx,ny});
          if(dist[nx][ny]==-1) dist[nx][ny]=dist[x][y]+1;
          else dist[nx][ny]=min(dist[nx][ny],dist[x][y]+1);
          continue;
        }
        if(dist[nx][ny]==-1) dist[nx][ny]=dist[x][y];
        else dist[nx][ny]=min(dist[x][y],dist[nx][ny]);
        seen[nx][ny]=true;
        next.push({nx,ny});
      }
    }
  }

  while(!next2.empty())
  {
    ll x=next2.front().first;
    ll y=next2.front().second;
    next2.pop();
    if(seen[x][y]) continue;
    seen[x][y]=true;
    next.push({x,y});
    goto label;
  }

  cout<<dist[gx][gy]<<endl;


}

Measured memory_bytes: 14128
#include <stdio.h>

int main()
{
    int First = 0;
    int Second = 0;
    int Third = 0;
    scanf("%d", &First);
    scanf("%d", &Second);
    scanf("%d", &Third);
    if (First >= Second || Second >= Third)
    {
        puts("No");
        return 0;
    }
    puts("Yes");
    return 0;
}



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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1000005

int n;
int a[MAXX];

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

    for(int i = 1; i <= 100; i++){
        for(int j = 1; j <= 100; j++){
            for(int k = 1; k <= 100; k++){
                int gh = i * i + j * j + k * k + i * j + j * k + i * k;
                a[gh]++;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        cout << a[i] << endl;
    }
    return 0;

}


Measured memory_bytes: 3884
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a;
	int min=1000000, max=0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a < min)min = a;
		if (a > max)max = a;
	}
	cout << max - min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

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

	int tmp = e - a;

	if(tmp<=k){
		cout << "Yay!" << endl;
	}else{
		cout << ":(" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

ll sum,n,a[2000200],ans,mod=1e9+7;

int main()
{
    cin >> n;
    for (int i=0;i<n;i++)
    {
        cin >> a[i];sum+=a[i];
    }
    for (int i=0;i<n;i++)
    {
        sum-=a[i];
        ans+=(a[i]%mod)*(sum%mod);
        ans%=mod;
    }
    cout << ans << endl;
    return 0;
}


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

struct BIT{
    int N;
    vector<int> dat;
    public:
    BIT(int n):N(n),dat(n){}
    void add(int pos,int x){
        pos++;
        while(pos<=N){
            dat[pos-1]+=x;
            pos+=(pos&-pos);
        }
    }
    int query(int r){
        int res=0;
        while(r>0){
            res+=dat[r-1];
            r-=(r&-r);
        }
        return res;
    }
    int query(int l,int r){
        return query(r)-query(l);
    }
};

struct Query{
    bool isGoods;
    int id;
    int l,r;
};

bool cmp(Query lhs,Query rhs){
    return lhs.l>rhs.l || lhs.l==rhs.l && (!lhs.isGoods)<(!rhs.isGoods);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> l(n),r(n);
    for(int i=0;i<n;i++) cin>>l[i]>>r[i];

    BIT bit(m+1);
    vector<Query> query;
    for(int i=0;i<n;i++) query.push_back({true,i,l[i],r[i]});
    for(int d=2;d<=m;d++){
        for(int j=0;j<=m;j+=d){
            int l=j+1,r=min(j+d,m+1);
            if(r-l>=1) query.push_back({false,d-1,l,r});
        }
    }
    sort(query.begin(),query.end(),cmp);

    vector<int> res(m,n);
    for(auto &q:query){
        if(q.isGoods){
            bit.add(q.r,1);
        }
        else{
            int sub=bit.query(q.l,q.r);
            res[q.id]-=sub;
        }
    }
    
    for(int i=0;i<m;i++){
        cout<<res[i]<<"\n";
    }
    return 0;
}

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

s=[]
e=[]
for i in range(n):
  a,b=map(int,input().split())
  s.append(a)
  e.append(b)

s=sorted(s)
e=sorted(e,reverse=True)

x=n//2
if n%2==1:
  ans=(e[x]-s[x]+1)

else:
  ts=(s[x]+s[x-1])/2
  te=(e[x]+e[x-1])/2
  ans=(te-ts)//0.5+1

print(int(ans))

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

int width,height;
int result;
char map[102][103];
int map2[102][102];

int tansaku(int x,int y,int now_cost,int is_hori,int force_hori) {
	int here_is_hori;
	int tansaku_did=0;
	if(x<0 || x>width+1 || y<0 || y>height+1)return 0;
	if(force_hori && map[y][x]!='#')return 0;
	if(is_hori && map[y][x]!='#')now_cost++;
	if(map2[y][x]<=now_cost)return 0;
	map2[y][x]=now_cost;
	here_is_hori=(map[y][x]=='#');
	if(here_is_hori) {
		tansaku_did|=tansaku(x+1,y,now_cost,here_is_hori,1);
		tansaku_did|=tansaku(x,y+1,now_cost,here_is_hori,1)*2;
		tansaku_did|=tansaku(x-1,y,now_cost,here_is_hori,1)*4;
		tansaku_did|=tansaku(x,y-1,now_cost,here_is_hori,1)*8;
	}
	if(!(tansaku_did & 1))tansaku(x+1,y,now_cost,here_is_hori,0);
	if(!(tansaku_did & 2))tansaku(x,y+1,now_cost,here_is_hori,0);
	if(!(tansaku_did & 4))tansaku(x-1,y,now_cost,here_is_hori,0);
	if(!(tansaku_did & 8))tansaku(x,y-1,now_cost,here_is_hori,0);
	return 1;
}

int main(void) {
	int i,j;
	while(1) {
		scanf("%d%d",&width,&height);
		if(width==0 && height==0)break;
		memset(map,0,sizeof(map));
		for(i=1;i<=height;i++) {
			scanf("%s",&map[i][1]);
			map[i][0]='.';
			map[i][width+1]='.';
		}
		for(i=0;i<=width+1;i++) {
			map[0][i]='.';
			map[height+1][i]='.';
			for(j=0;j<=height+1;j++) {
				map2[j][i]=0x7fffffff;
			}
		}
		tansaku(0,0,0,0,0);
		for(i=1;i<=height;i++) {
			for(j=1;j<=width;j++) {
				if(map[i][j]=='&') {
					printf("%d\n",map2[i][j]);
					i=width+1;
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	int n,h[101],flg,box[100],a,i,j,k;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<=n;i++){
			scanf("%d",&h[i]);
		}
		for(i=0;i<=n;i++){
			k=0;
			for(j=0;j<=n;j++){
				if(!(j==i)){
					box[k]=h[j];
					k++;
				}
			}
			a=box[1]-box[0];
			flg=1;
			for(j=0;j<n-1;j++){
				if(!(box[j+1]-box[j]==a)){
					flg=0;
				}
			}
			if(flg==1){
				printf("%d\n",h[i]);
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2076
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n,W=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]

w1=wv[0][0]
wv.sort()
lst=[[],[],[],[]]
for i in range(n):
    w,v=wv[i]
    lst[w-w1].append(v)
# print(lst)
ruilst=[]
for i in range(4):
    ruilst.append(ruiseki(lst[i][::-1]))
# print(ruilst)

ans=0
for i in range(len(ruilst[0])):
    for j in range(len(ruilst[1])):
        for k in range(len(ruilst[2])):
            for l in range(len(ruilst[3])):
                if i*w1+j*(w1+1)+k*(w1+2)+l*(w1+3)<=W:
                    ans=max(ans,ruilst[0][i]+ruilst[1][j]+ruilst[2][k]+ruilst[3][l])
print(ans)

Measured memory_bytes: 66028
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define SZ(x) ((int)(x).size())
#define ll long long
#define int ll
#define el '\n'
template<class T> bool inline rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool inline rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);

int n; cin>>n;
for(double i=0;i<=n;++i){
	if((int)(i*1.08) == n){
		cout<<(int)i<<el;
		return 0;
	}
}
cout<<":("<<el;

return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    if (a % 2 || b % 2 || c % 2) {
      cout << 0 << endl;
      continue;
    }
    set<tuple<int, int, int>> vis;
    int cnt = 0;
    while (true) {
      tuple<int, int, int> t = make_tuple(a, b, c);
      // cout << a << ' ' << b << ' ' << c << endl;
      if (vis.count(t)) {
        cnt = -1;
        break;
      }
      vis.insert(t);
      int A = (b / 2) + (c / 2);
      int B = (a / 2) + (c / 2);
      int C = (a / 2) + (b / 2);
      a = A;
      b = B;
      c = C;
      ++cnt;
      if (a % 2 || b % 2 || c % 2) break;
    }
    cout << cnt << endl;
  }
  
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  ll a[n + 1];
  a[0] = 2;
  a[1] = 1;
  for(int i = 2; i <= n; i++) {
    a[i] = a[i - 1] + a[i - 2];
  }
    
  
  
  
  cout << a[n] << endl;

  return 0;
}

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

namespace _069
{
    class Program
    {
        static void Main(string[] args)
        {
            ProblemC.Solve();
        }
    }

    class ProblemC
    {
        public static void Solve()
        {
            int N = int.Parse(Console.ReadLine());

            long[] arr = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            int cnt4 = 0;
            int cnt2 = 0;

            int limit = N / 2;

            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] % 4 == 0)
                {
                    cnt4++;
                }
                else if (arr[i] % 2 == 0)
                {
                    cnt2++;
                    if (cnt2 == 2)
                    {
                        cnt2 = 0;
                        cnt4++;
                    }
                }


                if (cnt4 >=limit)
                {
                    Console.WriteLine("Yes");
                    return;
                }

            }

            Console.WriteLine("No");

        }

    }
}


Measured memory_bytes: 20832
import sys

a = input().split()
n = int(a[0])
k = int(a[1])

xlist = input().split()
xlist = [int(i) for i in xlist]

mini = sys.maxsize
for i in range(n - k +1):
	if xlist[i] <= 0 and xlist[i + k - 1] <= 0:
		mini = min(mini, (-xlist[i]))
	elif xlist[i] <= 0 and xlist[i + k - 1] >= 0:
		mini = min(mini,(min(-2*xlist[i] + xlist[i + k - 1], -xlist[i] + 2 * xlist[i + k - 1])))
	elif xlist[i] >= 0 and xlist[i + k - 1] >= 0:
		mini = min(mini, (xlist[i + k - 1]))
		
print (mini)

Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;
  
ll f(ll a,ll b){
  return a*a*a*a*a-b*b*b*b*b;
}

int main() {
  ll N,A,B,C,cnt=1;
  cin>>N>>A>>B>>C;
  char c[N];
  string S[N];
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  for(int i=0;i<N;i++){
    string s;
    s=S[i];
    if(s=="AB"){
      if(A==0&&B==0){
        cout<<"No";
        cnt=0;
        break;
      }
      if(A==1&&B==1&&C==0&&i!=N-1){
        string s2=S[i+1];
        if(s2=="AC"){
          A++;
          B--;
          c[i]='A';
          continue;
        }
        if(s2=="BC"){
          A--;
          B++;
          c[i]='B';
          continue;
        }
      }
      if(A>B){
        A--;
        B++;
        c[i]='B';
      }
      else{
        A++;
        B--;
        c[i]='A';
      }
    }
    if(s=="BC"){
      if(C==0&&B==0){
        cout<<"No";
        cnt=0;
        break;
      }
      if(A==0&&B==1&&C==1&&i!=N-1){
        string s2=S[i+1];
        if(s2=="AC"){
          C++;
          B--;
          c[i]='C';
          continue;
        }
        if(s2=="AB"){
          C--;
          B++;
          c[i]='B';
          continue;
        }
      }
      
      if(C>B){
        C--;
        B++;
        c[i]='B';
      }
      else{
        C++;
        B--;
        c[i]='C';
      }
    }
    if(s=="AC"){
      if(A==0&&C==0){
        cout<<"No";
        cnt=0;
        break;
      }
      if(A==1&&B==0&&C==1&&i!=N-1){
        string s2=S[i+1];
        if(s2=="AB"){
          A++;
          C--;
          c[i]='A';
          continue;
        }
        if(s2=="BC"){
          A--;
          C++;
          c[i]='C';
          continue;
        }
      }
      if(A>C){
        A--;
        C++;
        c[i]='C';
      }
      else{
        A++;
        C--;
        c[i]='A';
      }
    }
  }
  if(cnt){
    cout<<"Yes"<<endl;
    for(int i=0;i<N;i++){
      cout<<c[i]<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 6856
#include<stdio.h>

int main(void){
  long long int N,M,i,tmp,ans;
  scanf("%lld %lld",&N,&M);
  if(M<=2*N){
    ans=M/2;
  }else{
    tmp=((M-2*N)/4);
    if((M-2*N)%4) tmp++;
    M-=2*tmp;
    //printf("%lld %lld\n",N,M);
    ans=M/2;
  }
  printf("%lld\n",ans);
  return 0;
}


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

int main(){	
	int n;
	cin >> n;
	int count=0;
	while(n>0){
		int r=n%10;
		if(r==7){
			count++;
		}
		n=n/10;
	}
	
	if(count >0)
		cout << "Yes";
	else
		cout << "No";	
}

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

int main(){
    int n;
    int a[4];
    cin>>n;
    a[3]=n%10;
    n/=10;
    a[2]=n%10;
    n/=10;
    a[1]=n%10;
    a[0]=n/10;

    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<3); ++bit)
    {
        int sum=a[0];
        for(int i=0;i<3;i++){
            if((bit>>i&1)) sum+=a[i+1];
            else sum-=a[i+1];
        }

        if(sum==7){
            cout<<a[0];
            for(int i=0;i<3;i++){
                if((bit>>i&1)) cout<<"+";
                else cout<<"-";
                cout<<a[i+1];
            }
            cout<<"=7"<<endl;
            return 0;
        }

    }
    

}

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

int main() {
  double a;  /* 現在のレーティング */
  double b;  /* 目標のレーティング */
  
  // 
  // ( a + x ) / 2 = b
  // x = 2b -a
  //
  
  cin >> a;
  cin >> b;
  
  cout << (2.0 * b) - a << endl;
  
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll d[110][110];

int main(){
    int v,e;
    cin>>v>>e;
    rep(i,v){
        rep(j,v){
            if(i==j) d[i][j]=0;
            else d[i][j]=1LL<<60;
        } 
    }

    

    rep(i,e){
        int s,t;
        ll c;
        cin>>s>>t>>c;
        d[s][t]=c;
    }

    rep(k,v){
        rep(i,v){
            rep(j,v){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }

    

    rep(i,v){
        if(d[i][i]<0){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
    }

    rep(i,v){
        rep(j,v){
            if(j) cout<<" ";
            if(d[i][j]<(1LL<<60)/2) cout<<d[i][j];
            else cout<<"INF";
        }
        cout<<endl;
    }

    return 0;
}


 


Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
vector<int> v[200010];
vector<int> ans(200010,0);
int n,q;

void dfs(int a, int p){
    for(auto u : v[a]){
        if(u!=p){
            ans[u]+=ans[a];
            dfs(u,a);
        }
    }
}

int main(){
    cin>>n>>q;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    rep(i,q){
        int p,x;
        cin>>p>>x;
        p--;
        ans[p]+=x;
    }
    dfs(0,-1);
    rep(i,n) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 23424
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
    
ll solve(int k, int n){
	if(n > k - n){
		n = k -n;
	}
	ll num = 1, den = 1;
	for(int i=1; i <= n; i++){
		num *= (k - i + 1);
		den *= i;
		num %= mod;
		den %= mod;
	}	
	return (num * power(den, mod - 2, mod)) % mod;
}

int run_test(){
	int x, y;
	cin >> x >> y;
	if((x + y) % 3){
		cout << 0 << "\n";
		return 0;
	}
	if((2*x - y) < 0 || (2*y - x) < 0){
		cout << 0;
		return 0;
	}
	int k = (x + y)/3;
	int n = (2*x - y)/3;
	ll ans = solve(k, n);
	cout << ans;
	return 0;
}
    
int main(){
   FAST;
    ll t;
    t = 1;
     
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 3640
n = int(input())
s = list(map(int,input().split()))
q = int(input())
t = list(map(int,input().split()))
count = 0

def binarySearch(x,s):
    left = 0
    right = len(s)

    while left < right:
        mid = (left + right) // 2
        if s[mid] == x:
            return mid
        elif x < s[mid]:
            right = mid
        else:
            left = mid+1
    return -1

for x in t:
    if binarySearch(x,s) != -1:
        count += 1
print(count)

Measured memory_bytes: 18812
import java.util.*;
class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
			int n=sc.nextInt();
			int r=sc.nextInt();
			if(n==0||r==0)break;
			int[] dk=new int[n];
			for(int i=0;i<n;i++)dk[n-(i+1)]=i+1;
			while(r--!=0){
				int p=sc.nextInt();p-=1;
				int c=sc.nextInt();
				int[] temp=new int[p];
				for(int i=0;i<p;i++){
					temp[i]=dk[i];
				}
				for(int i=0;i<c;i++){
					dk[i]=dk[i+p];
				}
				for(int i=0;i<p;i++){
					dk[i+c]=temp[i];
				}
			}
			System.out.println(dk[0]);
		}
	}
}

Measured memory_bytes: 30388
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second

#define scn(a) scanf("%d",&a)
#define sccn(a,b) scanf("%d%d",&a,&b)
#define scccn(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scnl(a) scanf("%lld",&a)
#define sccnl(a,b) scanf("%lld%lld",&a,&b)
#define scccnl(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scnc(c) scanf(" %c",&c)

#define rep(i,n) for(int i = 0; i<n; ++i)
#define repab(i,a,b) for(int i = a; i<=b; ++i)
#define repba(i,b,a) for(int i = b-1; i>=a; --i)

#define printar(i,ar,n) for(int i = 1; i<=n; ++i) printf("%d ",ar[i]); puts("")

#define ms(a,val) memset(a,val,sizeof(a))
#define pii pair<int,int>
#define pb(a) push_back(a)
#define pbp(a,b) push_back({a,b});

#define test(x) cout<<#x<<" "<<x<<endl

#define PI acos(-1)
#define MOD 1000000007
#define eps 0.00000001
#define inf 1<<30
#define MX 100005

int main(){
    int n;
    scanf("%d\n",&n);
    int ar[n];
    ll ans = 0;
    for(int i = 0; i<n; ++i){
        scanf("%d",&ar[i]);
        if(i && ar[i]<ar[i-1]){
            ans+=ar[i-1]-ar[i];
            ar[i]=ar[i-1];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4440
#include <iostream>

using namespace std;

int main(){
    long long N;
    long long A[100000];
    long long diff[100000];
    long long sum_A = 0;
    long long sum_N;
    cin >> N;
    sum_N = N*(N+1)/2;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum_A+=A[i];
        if(i >= 1) diff[i] = A[i] - A[i-1];
    }
    diff[0] = A[0] - A[N-1];
    if(sum_A%sum_N != 0){
        cout << "NO" << endl;
        return 0;
    }else{
        long long d = sum_A/sum_N;
        long long cnt = 0;
        for(int i = 0; i < N; i++){
            if((diff[i]-d)%N != 0){
                cout << "NO" << endl;
                return 0;
            }
            if(d-diff[i] < 0){
                cout << "NO" << endl;
                return 0;
            }
            cnt += (d-diff[i])/N;
        }
        if(cnt == d){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 1792