akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MAXNUM 555555
#define rep(i,s,t) for(int i=s;i<t;i++)
char s1[MAXNUM*4],s2[MAXNUM];
int s1size, s2size;
int snext[MAXNUM],isok[MAXNUM*4];
void getnext()
{
    snext[0] = 0, snext[1] = 0;
    for (int i = 1; i < s2size; i++)
    {
        int j = snext[i];
        while (j && s2[i] != s2[j])
            j = snext[j];
        snext[i + 1] = s2[i] == s2[j] ? j + 1 : 0;
    }
}

int KMP()
{
    int res = 0;
    getnext();
    int j = 0;
    for (int i = 0; i < s1size; i++)
    {
        while (j && s2[j] != s1[i])
            j = snext[j];
        if (s2[j] == s1[i])
            j++;
        if (j == s2size)
            res++,isok[i]=1;
    }
    return res;
}
vector<int> e[MAXNUM*2];int degree[MAXNUM*2];
int q[MAXNUM*2],top,front,dis[MAXNUM*2];
int main()
{
    scanf("%s%s",s1,s2);
    s1size=strlen(s1),s2size=strlen(s2);
    while(s1size<s2size)memcpy(s1+s1size,s1,s1size*sizeof(char)),s1size*=2;
    memcpy(s1+s1size,s1,s1size*sizeof(char)),s1size*=2;
    KMP();
    int tmp=s1size/2;
    rep(i,0,s1size)if(isok[i])
        e[(i+1-s2size)%tmp+1].push_back((i+1)%tmp+1),degree[(i+1)%tmp+1]++;
    rep(i,1,tmp+1)if(degree[i]==0)q[top++]=i,dis[i]=1;
    while(top!=front)
    {
        int x=q[front++];
        for(int k:e[x])
        {
            degree[k]--,dis[k]=max(dis[k],dis[x]+1);
            if(degree[k]==0)q[top++]=k;
        }
    }
    int x=0;
    rep(i,1,tmp+1)
    {
        x=max(x,dis[i]);
        if(degree[i]){printf("-1\n");return 0;}
    }
    printf("%d\n",x-1);
}

Measured memory_bytes: 75776
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

void solve() {
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        string a, b;
        cin >> a >> b;
        ll n = stoi(a + b);
        for (int i = 1; i * i <= n; ++i) {
            if (i * i == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n,m; cin >> n >> m;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    vector<pair<int, int>> ab(n);
    for(int i=0; i<n; i++){
        ab[i] = make_pair(a[i], b[i]);
    }
    sort(ab.begin(), ab.end());
    long long ans=0;
    for(int i=0; i<n; i++){
        //.second()はpair要素の2つ目を指す
        int buy = min(m,ab[i].second);
        ans+=(long long)buy*ab[i].first;
        m-=buy;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
int main(void){
	int i,j,k,M,N;
	double H,W,x,y;
	cin >> W >> H>>x>>y;
	if(W/2==x&&H/2==y){
		cout << (W*H)/2 << " " << 1;
	}else{
		cout << (W*H)/2 << " " << 0;
	}

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = []
cnt = 0
for i in range(n):
    b.append(abs(a[i]))
    if a[i] < 0:
        cnt += 1
if cnt % 2 == 0:
    print(sum(b))
else:
    print(sum(b)-min(b)*2)

Measured memory_bytes: 20032
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> a(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
    }
    sort(a.begin(), a.end());

    ll ans=0;
    if(n%2==0) {
        long k = n/2;
        for(i=0; i<k; i++) {
            if(i==k-1) ans -= a[i];
            else       ans -= 2*a[i];
        }
        for(i=k; i<n; i++) {
            if(i==k)   ans += a[i];
            else       ans += 2*a[i];
        }
    }
    else {
        long k = n/2;
        ll ans0=0;
        for(i=0; i<k+1; i++) {
            if(i>=k-1) ans0 -= a[i];
            else       ans0 -= 2*a[i];
        }
        for(i=k+1; i<n; i++) {
            ans0 += 2*a[i];
        }

        ll ans1=0;
        for(i=0; i<k; i++) {
            ans1 -= 2*a[i];
        }
        for(i=k; i<n; i++) {
            if(i<=k+1) ans1 += a[i];
            else       ans1 += 2*a[i];
        }
        //printf("%lld %lld\n", ans0, ans1);
        ans = MAX(ans0, ans1);
    }

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

    return 0;
}


Measured memory_bytes: 1024
#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 repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }

long long int dp[11][101] = {0};
long long int dpA[11][101] = {0};

int main() {
    int N;
    cin >> N;
    cout << "ABC" << N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    for (ll num = a; num <= b; num++) {
        bool yes = true;
        string s;
        ll ins = num;
        while (ins) {
            s.push_back('0' + ins % 10);
            ins /= 10;
        }
        rep(i, (s.size() - 1) / 2 + 1) {
            if (s[i] != s[s.size() - 1 - i]) yes = false;
        }
        if (yes) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int N, M; cin >> N >> M;
	int ans = 0;
	vector<int> a(M), b(M); rep(i, 0, M) {
		cin >> a[i] >> b[i];
		ans += max(0, N - a[i]);
	}
	sort(all(a));
	dumpc(a);
	dump(ans);
	ans -= max(0, N - a[0]);
	cout << ans << endl;
	return 0;
}

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

#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n;
    cin>>n;
    vector<int>v(n);
    map<int,int>m;
    for(int i=0;i<n;i++){
        cin>>v[i];
        m[v[i]]=i+1;
    }
    for(int i=1;i<=n;i++)
        cout<<30000*i<<" ";
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        cout<<30000*(n-i)+m[i]<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4908
#include <stdio.h>

int main(void)
{
	int X, Y, min, max, N, M, i;
	scanf("%d%d%d%d", &N, &M, &X, &Y);
	min = X + 1;
	for (i = 0; i < N; ++i) {
		int x;
		scanf("%d", &x);
		if (x >= min) min = x + 1;
	}
	max = Y;
	for (i = 0; i < M; ++i) {
		int x;
		scanf("%d", &x);
		if (x < max) max = x;
	}

	if (min <= max) puts("No War");
	else puts("War");

	return 0;
}


Measured memory_bytes: 128
from heapq import heappush, heappop
def resolve():
    INF = float('inf')
    maxMoney = 2502

    def Dijkstra(g):
        ans = {}
        # ある頂点にいて、ある銀貨の枚数を持っているときのこれまでにかかった最短時間
        dp = [[INF] * (maxMoney + 1) for _ in range(N)]
        # (time, node, silver)
        hq = []
        heappush(hq, (0, 0, min(S, maxMoney)))
        while hq:
            t, v, s = heappop(hq)
            if t > dp[v][s]:
                continue
            if v not in ans:
                ans[v] = t
                if len(ans) == N:
                    break

            # buy
            if s < maxMoney:
                c, d = CD[v]
                new_s = min(s + c, maxMoney)
                new_t = t + d
                if new_t < dp[v][new_s]:
                    dp[v][new_s] = new_t
                    heappush(hq, (new_t, v, new_s))

            # move
            for nv, cost, time in G[v]:
                # 払えない
                if s < cost:
                    continue
                # 払って移動した場合、最短時間なら更新
                new_s = s - cost
                new_t = t + time
                if new_t < dp[nv][new_s]:
                    dp[nv][new_s] = new_t
                    heappush(hq, (new_t, nv, new_s))
        return ans

    N, M, S = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        u, v, coin, tm = map(int, input().split())
        u, v = u - 1, v - 1
        G[u].append((v, coin, tm))
        G[v].append((u, coin, tm))
    CD = [list(map(int, input().split())) for _ in range(N)]

    ans = Dijkstra(G)
    for i in range(1, N):
        print(ans[i])


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 24404
#include <stdio.h>

int main(){
int i,j,a,t;
int val[10];
   for(i=0;i<10;i++){
scanf("%d",&val[i]);
}

for(i=0;i<9;i++){
 for(j=0;j<9-i;j++){
if(val[j]<val[j+1]){
t=val[j];
val[j]=val[j+1];
val[j+1]=t;
}
}
}
for(i=0;i<3;i++){
printf("%d\n",val[i]);
}
 return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    string s;
    cin >> s;

    s[k - 1] = s[k - 1] - 'A' + 'a';
    cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
#include<map>
#include<queue>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define LLINF (LLONG_MAX)
#define MAX_V 10000
 
using namespace std;
 
typedef long long ll;
 
typedef pair<ll,ll> P;
struct edge{
  ll to,cap,cost,rev;
  edge(ll to=LLINF,ll cap=LLINF,ll cost=LLINF,ll rev=LLINF):to(to),cap(cap),cost(cost),rev(rev){}
};
int V;
vector<edge> G[MAX_V];
ll h[MAX_V],dist[MAX_V],prevv[MAX_V],preve[MAX_V];
 
void add_edge(ll from,ll to,ll cap,ll cost){
  G[from].push_back(edge(to,cap,cost,(ll)G[to].size()));
  G[to].push_back(edge(from,0,-cost,(ll)G[from].size()-1));
}
 
ll min_cost_flow(ll s,ll t,ll f){
  ll res = 0;
  rep(i,V)h[i] = 0;
  while( f > 0 ){
    priority_queue<P,vector<P>,greater<P> > que;
      rep(i,V)dist[i] = LLINF;
      dist[s] = 0;
      que.push(P(0,s));
      while(!que.empty()){
    P p = que.top(); que.pop();
    ll v = p.second;
    if( dist[v] < p.first )continue;
    for(int i=0;i<G[v].size();i++){
      edge &e = G[v][i];
      if( e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to] ){
        dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
        prevv[e.to] = v;
        preve[e.to] = i;
        que.push(P(dist[e.to],e.to));
      }
    }
      }
      if(dist[t]==LLINF) break;
      for(int v=0;v<V;v++)h[v] += dist[v];
      ll d = f;
      for(int v=t;v!=s;v=prevv[v])d = min(d,G[prevv[v]][preve[v]].cap);
      f -= d;
      res += d * h[t];
      for(int v=t;v!=s;v=prevv[v]){
    edge &e = G[prevv[v]][preve[v]];
    e.cap -= d;
    G[v][e.rev].cap += d;
      }
  }
  return res;
}
 
int main(){
  int N;
  cin >> N;
  int *A = new int[N];
  int *B = new int[N];
  map<int,int> getIndex;
  int dex = 0;
  rep(i,N){
    cin >> A[i] >> B[i];
    if( getIndex.find(A[i]) == getIndex.end() )getIndex[A[i]] = dex++;
    if( getIndex.find(B[i]) == getIndex.end() )getIndex[B[i]] = dex++;
  }
  V = N + (int)getIndex.size();
  int source = V,sink = source+1,grave = sink+1;
  V += 3;
  add_edge(grave,sink,LLINF,0);
  rep(i,N)add_edge(source,i,1,0);
  rep(i,(int)getIndex.size())add_edge(N+i,sink,1,0);
  rep(i,N){
    int to1 = getIndex[A[i]]+N;
    int to2 = getIndex[B[i]]+N;
    add_edge(i,to1,1,-B[i]);
    add_edge(i,to2,1,-A[i]);
    add_edge(i,grave,LLINF,0);
  }
  delete [] A;
  delete [] B;
  cout << -min_cost_flow(source,sink,20000) << endl;
 
  return 0;
}

Measured memory_bytes: 2164
def main():
    N = [x for x in input()]
    if len(set(N)) == 1:
        print("".join(N))
    else:
        print(nex(N))


def nex(n):
    result = int(n[0] * 3)
    if int("".join(n)) > result:
        result = int(str(int(n[0]) + 1) * 3)
    return result


if __name__ == '__main__':
    main()


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll X, K, D;
    cin >> X >> K >> D;
    if (X < 0) X = -X;
    if (X/D > K) cout << X-K*D << "\n";
    else if ((K-X/D)%2LL==0LL) {
        cout << abs(X - D*(X/D)) << "\n";
    } else {
        cout << abs(X-D*(X/D+1LL)) << "\n";
    }
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<n; i++)
template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }
#define MOD 1000000007

void add(long long &x, long long y){
    x = (x + y) % MOD;
}

void sub(long long &x, long long y){
    x = (x + MOD - y) % MOD;
}

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    vector<long long> dp(K+1);
    dp[0] = 1;

    REP(i, N){
        long long sm = 0;
        for(int j=K; j>=K-a[i]; j--) add(sm, dp[j]);
        for(int j=K; j>=0; j--){
            long long tmp = dp[j];
            dp[j] = sm;
            sub(sm, tmp);
            if(j-a[i]-1>=0) add(sm, dp[j-a[i]-1]);
        }
    }
    cout << dp[K] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define N 200001
using namespace std;
const int INF = 1e9;

int main(){
  int n,R[N];
  cin>>n;
  for(int i=0;i<n;i++)cin>>R[i];
  
  int ans = -INF, mn = R[0];
  for(int i=1;i<n;i++){
    ans = max(ans,R[i]-mn);
    mn = min(mn,R[i]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int cnt=0;
  int ans=0;
  REP(i,(int)s.size()){
    if(s[i]=='A' || s[i]=='G' || s[i]=='C' || s[i]=='T') cnt++;
    else{
      ans = max(ans, cnt);
      cnt=0;
    }
  }
  if(cnt>0) ans = max(ans,cnt);

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

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

int main()
{
	//変数宣言
	int h;
	int w;
	int i;
	int j;

	while (1) {

		cin >> h >> w;
		if (h == 0) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i == 0 || i == h-1)
				{
					cout << "#";
				}
				else if (j == 0 || j == w - 1)
				{
					cout << "#";
				}
				else
				{
					cout << ".";
				}

			}
			cout << endl;

		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3040
N, K = map(int, input().split())
MOD = 10**9 + 7
 
p = q = 1
for i in range(N):
    p = p * (N+K-1-i) % MOD
    q = q * (i+1) % MOD
 
print(p * pow(q, MOD-2, MOD) % MOD)


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

int main(){
	int n,c=0;
	vector< pair<int,int> > p(100005),q(100005);
	cin >> n;
	for(int i=0;i<100005;i++){
		p[i].first = 0;
		p[i].second=i;
		q[i].first=0;
		q[i].second=i;
	}
	for(int i=0;i<n;i++){
		int v;
		cin >> v;
		if(i%2==0){
			p[v-1].first++;
		}else{
			q[v-1].first++;
		}
	}

	sort(p.begin(),p.end(),greater<pair<int,int> >());
	sort(q.begin(),q.end(),greater<pair<int,int> >());
	if(p[0].second!=q[0].second){
		c=n-p[0].first-q[0].first;
	}else{
		c=n-max(p[0].first+q[1].first,p[1].first+q[0].first);
	}
	cout << c <<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

// snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;
//cout << N.x << endl;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int K;
    string S;
    cin >> K >> S;
    int N = S.size();
    mint ans = 0;
    mint a=26,b=25;
    combination c(N+K);
    for(int i=0; i<=K; i++){
        mint temp = c(i+N-1,N-1) * a.pow(K-i) * b.pow(i);
        ans += temp;
    }
    cout << ans.x << "\n";
    return 0;
}


Measured memory_bytes: 35672
N = int(input())

money=list(input().split(' ') for _ in range(N))

sum=float()
for i in range(N):
    if(money[i][1]=='JPY'):
        sum+=float(money[i][0])
    else:
        sum+=float(money[i][0])*380000.0

print(sum)
  

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back


using namespace std;
using ll = long long;

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(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<bool> done(n);
    vector<int> reach(n);
    reach[0]=0;
    for(int i=1;i<n;i++) done[i] = false;
    done[0]=true;
    queue<int> que;
    que.push(0);
    vector<int> ans(n);

    while(!que.empty()){
        int v=que.front(); que.pop();


        for(int k:g[v]){
            if(done[k]){
                continue;
            }else{
                que.push(k);
                ans[k]= v;
                done[k]=true;
                
            }
        }

    }
    rep(i,n){
        if(!done[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" <<endl;
    for(int i=1;i<n;i++){
        cout << ++ans[i] << endl;
    }

    
    



    return 0;
}


Measured memory_bytes: 10680
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int poziome, pionowe;
const int nax = 1005;
char sl[nax][nax];

void wstaw_poziomy(int row, int col) {
	if(sl[row][col]) return;
	if(sl[row][col+1]) return;
	//~ assert(!sl[row][col]);
	//~ assert(!sl[row][col+1]);
	sl[row][col] = '<';
	sl[row][col+1] = '>';
	--poziome;
}
void wstaw_pionowy(int row, int col) {
	if(sl[row][col]) return;
	if(sl[row+1][col]) return;
	//~ assert(!sl[row][col]);
	//~ assert(!sl[row+1][col]);
	sl[row][col] = '^';
	sl[row+1][col] = 'v';
	--pionowe;
}

int h, w;

void jebaj() {
	if(h % 2) {
		for(int col = 0; col + 1 < w; col += 2)
			if(poziome)
				wstaw_poziomy(h - 1, col);
	}
	if(w % 2) {
		for(int row = 0; row + 1 < h; row += 2)
			if(pionowe)
				wstaw_pionowy(row, w - 1);
	}
	for(int row = 0; row + 1 < h; row += 2)
		for(int col = 0; col + 1 < w; col += 2) {
			if(pionowe) {
				wstaw_pionowy(row, col);
				if(pionowe) wstaw_pionowy(row, col + 1);
			}
			else if(poziome) {
				wstaw_poziomy(row, col);
				if(poziome) wstaw_poziomy(row + 1, col);
			}
		}
}

int main() {
	cin >> h >> w >> poziome >> pionowe;
	int memo_poziome = poziome;
	int memo_pionowe = pionowe;
	jebaj();
	if(pionowe || poziome) {
		for(int row = 0; row < h; ++row)
			for(int col = 0; col < w; ++col)
				sl[row][col] = 0;
		pionowe = memo_pionowe;
		poziome = memo_poziome;
		
		if(pionowe >= 2 && poziome >= 2 && h >= 3 && w >= 3) {
			wstaw_pionowy(h - 3, w - 3);
			wstaw_poziomy(h - 3, w - 2);
			wstaw_pionowy(h - 2, w - 1);
			wstaw_poziomy(h - 1, w - 3);
		}
		jebaj();
		if(pionowe || poziome) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	for(int row = 0; row < h; ++row) {
		for(int col = 0; col < w; ++col) {
			if(sl[row][col]) printf("%c", sl[row][col]);
			else printf(".");
		}
		puts("");
	}
}


Measured memory_bytes: 2176
# coding: utf-8
import re
import bisect
from datetime import datetime as dt

n = input()
A = map(int, raw_input().split())
minus_count = 0
for a in A:
    if a < 0:
        minus_count += 1
ans = 0
for a in A:
    ans += abs(a)
if minus_count % 2 == 0:
    print ans
else:
    m = 10**10
    for a in A:
        if m > abs(a):
            m = abs(a)
    print ans - 2 * m


Measured memory_bytes: 11396
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, K;
  cin >> N >> K;
  if(K % 2 == 0) { // even
    ll n1 = N / K;
    ll n2 = N / (K / 2) - n1;
    cout << n1*n1*n1 + n2*n2*n2 << endl;
  } else { // odd
    ll n = N / K;
    cout << n*n*n << endl;
  }
  return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int M = 200000;
int n, m, s[M], c[M][2];
bool f[M];
vector<int> g[M];

int main() {
	string ss;
	cin >> n >> m >> ss;
	inc(i, n) { s[i] = (ss[i] == 'A' ? 0 : 1); }
	inc(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].PB(b);
		g[b].PB(a);
		c[a][s[b]]++;
		c[b][s[a]]++;
	}
	
	queue<int> q;
	inc(i, n) {
		if(c[i][0] == 0 || c[i][1] == 0) { f[i] = false; q.push(i); } else { f[i] = true; }
	}
	while(! q.empty()) {
		int v = q.front(); q.pop();
		for(auto && w: g[v]) {
			if(! f[w]) { continue; }
			int & r = c[w][s[v]];
			r--;
			if(r == 0) { f[w] = false; q.push(w); }
		}
	}
	
	cout << (count(f, f + n, true) > 0 ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 13316
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int Q = sc.nextInt();
			
			ArrayList<HashSet<Integer>> tree = new ArrayList<HashSet<Integer>>();
			for(int i = 0; i < N; i++) { tree.add(new HashSet<Integer>()); }
			
			int[] in_degs = new int[N];
			for(int i = 0; i < N - 1; i++) {
				final int a = sc.nextInt() - 1;
				final int b = sc.nextInt() - 1;
				
				tree.get(a).add(b);
				in_degs[b] += 1;
			}
			
			long[] value = new long[N];
			for(int i = 0; i < Q; i++) {
				final int p = sc.nextInt() - 1;
				final long x = sc.nextLong();
				value[p] += x;
			}
			
			
			LinkedList<Integer> queue = new LinkedList<Integer>();
			for(int node = 0; node < N; node++) {
				if(in_degs[node] == 0) { queue.add(node); }
			}
			
			while(!queue.isEmpty()) {
				final int node = queue.poll();
				
				for(final int next : tree.get(node)) {
					value[next] += value[node];

					in_degs[next] -= 1;
					if(in_degs[next] == 0) { queue.add(next); }
				}
			}
			
			
			for(int i = 0; i < N; i++) {
				System.out.print((i == 0 ? "" : " ") + value[i]);
			}
			System.out.println();
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

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

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

int main () {
	int k, s, cnt = 0;
	cin >> k >> s;

	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			int l = s - i - j;
			if (0 <= l && l <= k) cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

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

typedef struct {
    int tx;
    int time;
} DICE;
DICE queue[100000];
int head, tail;

void enq(DICE t)
{
    queue[(tail++) % 100000] = t;
}

void deq(DICE *t)
{
    *t = queue[(head++) % 100000];
}

int main(void)
{
    DICE first, temp;
    static int map[100000];
    static char v[100000];
    int now;
    int i;
    int n;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++){
        scanf("%d", &map[i]);
    }
    
    memset(v, 0, sizeof(v));
    first.tx = first.time = 0;
    v[0] = 1;
    head = tail = 0;
    enq(first);
    
    while (head != tail){
        deq(&temp);
        
        if (temp.tx == n - 1){
            printf("%d\n", temp.time);
            break;
        }
        
        for (i = 1; i <= 6; i++){
            if (temp.tx + i < n && !v[temp.tx + i] && map[temp.tx + i] == 0){
                v[temp.tx + i] = 1;
                first.tx = temp.tx + i;
                first.time = temp.time + 1;
                enq(first);
            }
            else if (temp.tx + i < n && !v[temp.tx + i] && map[temp.tx + i] != 0){
                first.tx = temp.tx + i;
                while (map[first.tx] != 0 && !v[first.tx + map[first.tx]]){
                    v[first.tx + map[first.tx]] = 1;
                    first.tx += map[first.tx];
                }
                if (map[first.tx] == 0){
                    first.time = temp.time + 1;
                    enq(first);
                }
            }
        }
    }
    
    return (0);
}

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

int main()
{
    int A, B;
    cin >> A >> B;
    if ((A + B) % 2 == 0)
    {
        cout << (A + B) / 2 << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,q,temp,sum=0,count=0,f=1;
    string s, t;
    cin>>s>>t;
    for(i=0;i<s.size();i++){
        if(s[i] != t[i]){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
}    
    

Measured memory_bytes: 3616
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
#define Max (int)450
#define MAX2 (int)1e5+5
#define MOD ((int)1e9+7)
using namespace std;

int main(){
	int n,x,a[Max],p,i;
	scanf("%d%d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&p);
		if(i == 0)
			a[i] = p;
		else
			a[i] = a[i-1]+p;
	}

	for(i=0;i<n;i++){
		if(a[i] > x)
			break;
	}
	printf("%d\n",i+1);

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define double long double
#define int long long 
#define f(z) for(int i=1;i<=z;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
int cl(int n ,int m) { if(n%m)return n/m + 1 ;else return n/m ;}
int pw(int a,int b,int M){a%=M;int r=1;while(b>0){if(b&1)r=r*a%M;a=a*a%M;b>>=1;}return r;}
#define mod  1000000007
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1e6 + 5  ;

signed main(){
	int n;
	cin >>n ;
	int sum =0 ;
	REP(i,1,n) REP(j,1,n) REP(k,1,n) sum += __gcd( __gcd(i,j) ,k) ;
	cout << sum; 
}

Measured memory_bytes: 3616
function Main(input){
	input = input.split("\n");
	var mem = input[0].split(" ").map(Number);
	var p = input[1].split(" ").map(Number);
	var sum = 0;
	for(var i=2;i<input.length;i++){
	    var arr = input[i].split(" ").map(Number);
	    var arrsum = 0
	    for(var j=0;j<arr.length;j++){
	        arrsum += arr[j]*p[j];
	    }
	    arrsum += mem[2];
	    if(arrsum>0) sum++;
	}
	console.log(sum)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define REP(i, n) for(int64_t i=0;i<n;i++)
#define REPk(i, k, n) for(int64_t i=k;i<n;i++)

#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal>palvec;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;


ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

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

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    REP(i, n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}

void COMinit(int m, lvec &fac, lvec &finv){
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k, const lvec& fac, const lvec &finv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll powmod(ll x, ll n){
    ll res=1;
    while(n>0){
        if(n&1) res = res*x%MOD;
        x = x*x%MOD;
        n>>=1;
    }
    return res;
}

void perm1(int pos, int n, ivec &used, ivec &perm){
    if(pos==n){
        for (auto v: perm){
            cout << v << ' ';
        }
        cout << endl;
    }
    for (int i = 0; i < n; i++)
    {
        if(!used[i]) {
            used[i] = true;
            perm[pos] = i;
            perm1(pos+1, n, used, perm);
            used[i] = false;
        }
    }
    return;    
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    H,W,K = map(int, readline().split())
    S = [list(map(int, readline().strip())) for j in range(H)]
    
    white = 0
    for line in S:
        white += sum(line)
 
    if white <= K:
        print(0)
        exit()
 
    # 横線の決め方を全探索
    ans = 10**5
    
    #yに横線Patternごとの列合計を作成
    #入力例１のPattern[bin(2)]場合、y=[[1,1,1,0,0], [1,0,1,1,2]]
    for pattern in range(2**(H-1)):
        # 初期化
        impossible = False
        x = 0
        ly = bin(pattern).count("1")
        y = [S[0]]
        line = 0
        for i in range(1,H):
            if (pattern >> i-1) & 1:
                line += 1
                y.append(S[i])
            else:
                y[line] = [y[line][j] + S[i][j] for j in range(W)]
 
        # 各列の値を加算していく
        count = [0]*(ly + 1) 
        for j in range(W):
            for i in range(line+1):
                if y[i][j] > K :
                    impossible = True
                    break
 
                count[i] += y[i][j]
                #print("横Pattern{} 縦列まで　{} カウント数{} 縦線の数{}".format(i, j, count[i], x))
                #横Patten毎にｊ列までのホワイトチョコ合計数をカウント、
                #カウント＞Kとなったら、縦線数を＋１、その列値でカウント数を初期化
                if count[i] > K:
                    x += 1
                    for i in range(line+1):
                        count[i] = y[i][j]
                    break
            #x縦線の数 + ly横線の数がAnsより大きくなったらBreak
            if x + ly > ans or impossible:
                impossible = True
                break
        if impossible:
            x = 10**6
        #x縦線の数 + ly横線の数がAnsより小さくなったらAnsを更新
        ans = min(ans, x + ly)
 
    print(ans)
 
 
main()

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 X,A;
    cin >> X >> A;

    if(X<A) cout << 0 << endl;
    else cout << 10 << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;

int n, m, q;
int lr[509][509];

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

  cin >> n >> m >> q;
  rep(i, 0, m) {
    int L, R;
    cin >> L >> R;
    lr[L][R]++;
  }

  int ctn[509][509];
  rep(i, 1, n+1) {
    rep(j, 1, n+1) { ctn[i][j] = ctn[i][j - 1] + lr[i][j]; }
  }

  vi ans;
  rep(i, 0, q) {
    int P, Q;
    cin >> P >> Q;
    int sum = 0;
    rep(j, P, Q + 1) { sum += ctn[j][Q] - ctn[j][P - 1]; }
    ans.pb(sum);
  }

  rep(i, 0, q) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

const int N = 200005;
int pi[N], n, out[N], on_tree[N], Q[N], sg[N], vis[N], va[N];
VI to[N];

void tok(int x){
	memset(va, 0, sizeof va);
	for (int i = pi[x]; i != x; i = pi[i]){
		RVC(j, to[i]) va[sg[to[i][j]]] = i;
		for (sg[i] = 0; va[sg[i]] == i; ++sg[i]);
	}
	RVC(j, to[x]) va[sg[to[x][j]]] = x;
	int tmp = 0;
	for (; va[tmp] == x; ++tmp);
	if (tmp == sg[x]){
		puts("POSSIBLE");
		exit(0);
	}
}

int main(){
	scanf("%d", &n);
	REP(i, 1, n){
		scanf("%d", &pi[i]);
		to[pi[i]].pb(i);
		++out[pi[i]];
	}
	int hd = 1, tl = 0;
	REP(i, 1, n) if (!out[i]) Q[++tl] = i;
	while (hd <= tl){
		int x = Q[hd++];
		on_tree[x] = 1;
		--out[pi[x]];
		if (!out[pi[x]]) Q[++tl] = pi[x];
	}
	REP(i, 1, tl){
		int x = Q[i];
		RVC(j, to[x]) vis[sg[to[x][j]]] = x;
		for (sg[x] = 0; vis[sg[x]] == x; ++sg[x]);
	}
	REP(i, 1, n) if (!on_tree[i]){
		RVC(j, to[i]) if (on_tree[to[i][j]]) vis[sg[to[i][j]]] = i;
		for (sg[i] = 0; vis[sg[i]] == i; ++sg[i]);
		tok(i);
		for (++sg[i]; vis[sg[i]] == i; ++sg[i]);
		tok(i);
		return puts("IMPOSSIBLE"), 0;
	}
	return 0;
}

Measured memory_bytes: 15616
def attack(players_list, attacker_no, defender_no):
  players_list[defender_no][0] = players_list[defender_no][0] - players_list[attacker_no][1]
  return [players_list, players_list[defender_no][0]]

inputs = input().split(' ')

for i in range(0, 4):
  inputs[i] = int(inputs[i])

tk = [inputs[0], inputs[1]]
ao = [inputs[2], inputs[3]]

players_list = (tk, ao)

order = 0;
while True:
  result = attack(players_list, order % 2, ((order + 1 ) % 2))
  
  if (result[1] <= 0):
    if(order % 2 == 0):
      print("Yes")
    else:
      print("No")
      
    break;
  order+=1;



Measured memory_bytes: 9160
import collections

n = int(input())
v = [int(_) for _ in input().split()]

v_even = v[::2]
v_odd = v[1::2]

a_even = collections.Counter(v_even)
a_odd = collections.Counter(v_odd)

li_even = a_even.most_common()
li_odd = a_odd.most_common()

if li_even[0][0] != li_odd[0][0]:
    print(n - li_even[0][1] - li_odd[0][1])
else:
    if len(li_even) != 1 and len(li_odd) != 1:
        print(min(n - li_even[0][1] - li_odd[1][1],n - li_even[1][1] - li_odd[0][1]))
    elif len(li_even) != 1 and len(li_odd) == 1:
        print(int(n/2) - li_even[1][1])
    elif len(li_even) == 1 and len(li_odd) != 1:
        print(int(n/2) - li_odd[1][1])
    else:
        print(int(n/2))

Measured memory_bytes: 21952
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;

  ll sum = 0;
  ll x = n;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }

  std::string judge = "Yes";
  if (n % sum != 0) {
    judge = "No";
  }

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



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
 
using namespace std;
 
void dice3(){
        int d1,d2,d3,d4,d5,d6;
        cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6; 
 
        int e1,e2,e3,e4,e5,e6;
        cin >> e1 >> e2 >> e3 >> e4 >> e5 >> e6; 
 
        int tmp;
        for ( int i = 0; i < 4; i++){
                tmp = d1; d1 = d2; d2 = d6; d6 = d5; d5 = tmp;  //N 
 
                for ( int i = 0; i< 4; i++){
                        if(d1 == e1 and d2 == e2 and d3 == e3 and d4 == e4 and d5 == e5 and d6 == e6){
                                cout << "Yes" <<endl;
                                return ;
                        }   
                        tmp = d2; d2 = d3; d3 = d5; d5 = d4; d4 = tmp; //spin
                }   
        }    
        tmp = d1; d1 = d4; d4 = d6; d6 = d3; d3 = tmp; //E 
        for ( int i = 0; i< 4; i++){
                if(d1 == e1 and d2 == e2 and d3 == e3 and d4 == e4 and d5 == e5 and d6 == e6){
                        cout << "Yes" <<endl;
                        return ;
                }   
                tmp = d2; d2 = d3; d3 = d5; d5 = d4; d4 = tmp; //spin
        }   
        tmp = d1; d1 = d4; d4 = d6; d6 = d3; d3 = tmp; //E 
        tmp = d1; d1 = d4; d4 = d6; d6 = d3; d3 = tmp; //E 
        for ( int i = 0; i< 4; i++){
                if(d1 == e1 and d2 == e2 and d3 == e3 and d4 == e4 and d5 == e5 and d6 == e6){
                        cout << "Yes" <<endl;
                        return ;
                }   
                tmp = d2; d2 = d3; d3 = d5; d5 = d4; d4 = tmp; //spin
        }   
        cout << "No" << endl;
}
 
int main(){
        dice3();
        return 0;
}

Measured memory_bytes: 3100