akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
    static short st[30];short tp=0;
    if(x<0) putchar('-'),x=-x;
    do st[++tp]=x%10,x/=10; while(x);
    while(tp) putchar('0'|st[tp--]);
    putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int P = 998244353;
const int N = 405;
ll inv[N], fac[N], a[N], b[N], A, B, ans, n;
ll fpw(ll x, ll mi) {
    ll res = 1;
    for (; mi; mi >>= 1, x = x * x % P)
        if (mi & 1) res = res * x % P;
    return res;
}
ll g[N][N], f[N][N];
int main() {
    read(n);
    inv[0] = fac[0] = inv[1] = fac[1] = 1;
    for (int i = 2;i <= 400; i++) inv[i] = (P - P / i) * inv[P % i] % P;
    for (int i = 2;i <= 400; i++)
        inv[i] = inv[i-1] * inv[i] % P,
        fac[i] = fac[i-1] * i % P;

    for (int i = 1;i <= n; i++) {
        read(a[i]), read(b[i]);
        A += a[i], B += b[i];
    }
    f[0][0] = -1;
    /* for (int i = 1;i <= 50; i++) write(inv[i], ' '), write(fac[i]); */
    for (int i = 1;i <= n; i++) {
        memcpy(g, f, sizeof(g));
        for (int s = A;s >= 0; s--) {
            for (int j = B;j >= 0; j--) {
                if (s < a[i]) { f[s][j] = 0; continue; }
                ll t = a[i];
                f[s][j] = f[s-a[i]][j];
                for (int k = 1;k < b[i]; k++, t = t * a[i] % P) 
                    f[s][j] = (f[s][j] + t * inv[k] % P * f[s-a[i]][j-k]) % P;
            }
        }
        for (int j = 0;j <= A; j++)
            for (int k = 0;k <= B; k++)
                f[j][k] = (g[j][k] - f[j][k] + P) % P;
    }
    for (int s = 1;s <= A; s++) {
        ll tt = fpw(s, P - 2), t = A * tt % P;
        ll res = 0;
        for (int i = 0;i <= B; i++, t = t * tt % P) 
            res = (res + f[s][i] * fac[i] % P * t) % P;
        res %= P, ans = (ans + res) % P;
    }
    write(ans);
    return 0;
}

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

using namespace std;

struct UnionFind{
    UnionFind(int size):_array(size, -1){
    }

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

    void unify(int x, int y){
        int rootx = root(x);
        int rooty = root(y);
        if( rootx == rooty ){
            return;
        }
        if( size(rootx) < size(rooty) ) swap(rootx,rooty);
        _array[rootx] += _array[rooty];
        _array[rooty] = rootx;
    }

    int root(int x){
        if( _array[x] < 0 ){
            return x;
        }
        return _array[x] = root(_array[x]);
    }

    int size(int x){
        return -_array[root(x)];
    }

    vector<int> _array;
};

void DFS(vector<vector<int>>& graph, int v, vector<int>& visited, int root, UnionFind& uf){
    visited[v] = true;
    uf.unify(v, root);
    for(int i = 0 ; i < graph[v].size(); i++){
        if(visited[graph[v][i]] == false){
            DFS(graph, graph[v][i], visited, root, uf);
        }
    }
}

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

    vector<vector<int>> graph(n);
    for(int i = 0; i < m; i++){
        int v1, v2;
        cin >> v1 >> v2;
        graph[v1].push_back(v2);
        graph[v2].push_back(v1);
    }

    vector<int> visited(n, false);
    UnionFind uf(n);

    for(int i = 0; i < n ; i++){
        if( visited[i] == false ){
            DFS(graph, i, visited, i, uf);
        }
    }

    int q;
    cin >> q;

    for(int i = 0; i < q; i++ ){
        int v1, v2;
        cin >> v1 >> v2;
        if( uf.same(v1, v2) ){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    return 0;

}



Measured memory_bytes: 26296
#include<bits/stdc++.h>
#define INF 99999999

using namespace std;

typedef long long ll;

int main(void){
    ll n,ans=0;
    cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i]-=i;
	}
	sort(a,a+n);
	if(n%2){
		ll b = a[n/2];
		for(int i = 0; i < n; i++)ans += abs(a[i]-b);
	}else{
		ll b = (a[n/2]+a[n/2-1])/2;
		for(int i = 0; i < n; i++)ans += abs(a[i]-b);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q; cin >> N >> Q;
  string T; cin >> T;
  vector<int> a(1001001, 0);
  vector<int> s(1001001, 0);
  for(int i = 0; i < N-1; i++) if(T[i] == 'A' && T[i+1] == 'C') a[i] = 1; 
  for(int i = 0; i < N; i++) s[i+1] = s[i] + a[i]; 
  
  for(int i = 0; i < Q; i++) {
    int l, r; cin >> l >> r;
    cout << s[r-1] - s[l-1] << endl;
  }
}
    
  

Measured memory_bytes: 8832
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}


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

int main(){
    int n;
    while(cin>>n,n){
        while(n--){
            int a,b,c;cin>>a>>b>>c;
            if((a==100||b==100||c==100)||a+b>=180||a+b+c>=240){
                cout<<"A"<<endl;
            }
            else if(a+b+c>=210||(a+b+c>=150&&(a>=80||b>=80))){
                cout<<"B"<<endl;
            }
            else cout<<"C"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1156
S = input()
s = S.split()

W,H,x,y,r = list(map(int,s))

x_max = x+r 
x_min = x-r

y_max = y+r
y_min = y-r


if W >= x_max and 0 <= x_min and H >= y_max and 0 <= y_min :
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const ll INF = 1001001001;
const ll MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  int a[10] = {111, 222,333,444,555,666,777,888,999};
  cout << *lower_bound(a, a + 10, n) << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 N;
  cin >> N;
  i64 cnt = 0;
  for(int i = 1;i <= N;i++) if(i & 1) cnt++;
  cout << fixed << setprecision(10) << 1.0 * cnt / N << endl;
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a + b) > (c + d)) {
    cout << "Left" << endl;
  }
  else if ((a + b) < (c + d)) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val in = new Scanner(System.in)
  val V = in.nextInt()
  val E = in.nextInt()
  val dinitz = new Dinitz(V)
  for (_ <- 0 until E) {
    val s = in.nextInt()
    val t = in.nextInt()
    val c = in.nextInt()
    dinitz.addEdge(s, t, c)
  }

  val f = dinitz.maxFlow(0, V - 1)
  println(f)
}

import java.util

class Dinitz(val V: Int) {

  class Edge(var to: Int, var cap: Long, var rev: Int)

  private val graph = (for (_ <- 0 until V) yield new ArrayBuffer[Edge]()).toArray
  private val level = new Array[Int](V)
  private val iter = new Array[Int](V)


  def addEdge(from: Int, to: Int, cap: Long): Unit = {
    graph(from).append(new Edge(to, cap, graph(to).size))
    graph(to).append(new Edge(from, 0, graph(from).size - 1))
  }

  private def dfs(v: Int, t: Int, f: Long): Long = {
    if (v == t) return f

    while (iter(v) < graph(v).size) {
      val e = graph(v)(iter(v))
      if (e.cap > 0 && level(v) < level(e.to)) {
        val d = dfs(e.to, t, Math.min(f, e.cap))
        if (d > 0) {
          e.cap -= d
          graph(e.to)(e.rev).cap += d
          return d
        }
      }

      iter(v) += 1
    }
    0
  }
  
  def maxFlow(s: Int, t: Int): Long = {
    var flow = 0L

    while (true) {
      val queue = new mutable.Queue[Int]()
      util.Arrays.fill(level, -1)
      level(s) = 0
      queue.enqueue(s)
      while (queue.nonEmpty) {
        val v = queue.dequeue()
        for (e <- graph(v)) {
          if (e.cap > 0 && level(e.to) < 0) {
            level(e.to) = level(v) + 1
            queue.enqueue(e.to)
          }
        }
      }

      if (level(t) < 0) return flow
      util.Arrays.fill(iter, 0)

      var f = 1L
      while (f > 0) {
        f = dfs(s, t, Long.MaxValue)
        flow += f
      }
    }

    throw new IllegalStateException()
  }
}

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

int main(int argc, char const *argv[])
{
	int n;
	long long c;
	cin>>n>>c;
	long long x[n],v[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>x[i]>>v[i];
	}
	long long l[n],lb[n];
	l[0]=v[0]-x[0];
	lb[0]=max(0LL,l[0]);
	for (int i = 1; i < n; ++i)
	{
		l[i]=l[i-1]+v[i]-abs(x[i]-x[i-1]);
		lb[i]=max(lb[i-1],l[i]);
	}
	long long r[n],rb[n];
	r[n-1]=v[n-1]-abs(c-x[n-1]);
	rb[n-1]=max(0LL,r[n-1]);
	for (int i = n-2; i >= 0; --i)
	{
		r[i]=r[i+1]+v[i]-abs(x[i]-x[i+1]);
		rb[i]=max(rb[i+1],r[i]);
	}
	long long ans=0LL;
	for (int i = 0; i < n-1; ++i)
	{
		long long nans=l[i]+max(0LL,rb[i+1]-x[i]);
		ans=max(ans,nans);
	}
	ans=max(ans,l[n-1]);
	for (int i = 1; i < n; ++i)
	{
		long long nans=r[i]+max(0LL,lb[i-1]-abs(c-x[i]));
		ans=max(ans,nans);
	}
	ans=max(ans,r[0]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        string o, t;
        in >> o >> t;
        out << (o[0] == t[0] ? '=' : o[0] > t[0] ? '>' : '<') << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int r,c,n;
stack<int>st;
vector<P>v[4];
bool used[100010];
signed main(){
    cin>>r>>c>>n;
    rep(i,n){
        int x[2],y[2];
        rep(j,2)cin>>x[j]>>y[j];
        rep(j,2){
            if(x[j]!=0&&x[j]!=r&&y[j]!=0&&y[j]!=c)goto no;
        }
        rep(j,2){
            if(x[j]==0&&y[j]!=c)v[0].pb({y[j],i});
            if(x[j]!=r&&y[j]==c)v[1].pb({x[j],i});
            if(x[j]==r&&y[j]!=0)v[2].pb({y[j],i});
            if(x[j]!=0&&y[j]==0)v[3].pb({x[j],i});
        }
        no:;
    }
    rep(i,4){
        sort(all(v[i]));
        if(i>=2)reverse(all(v[i]));
    }
    rep(_,4){
        for(P i:v[_]){
            if(!st.empty()&&st.top()==i.se)st.pop();
            else{
                if(used[i.se]){
                    puts("NO");
                    return 0;
                }
                st.push(i.se);
                used[i.se]=true;
            }
        }
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 4944
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  int Ma, Mb;
  scanf("%zu %d %d", &N, &Ma, &Mb);

  std::vector<int> a(N), b(N), c(N);
  for (size_t i=0; i<N; ++i)
    scanf("%d %d %d", &a[i], &b[i], &c[i]);

  size_t Na=N/2, Nb=N-Na;
  struct Pack { 
    int a, b, c;
    Pack(int a, int b, int c): a(a), b(b), c(c) {}
    bool operator <(const Pack &rhs) const {
      return (
          a != rhs.a? a < rhs.a 
          : b != rhs.b? b < rhs.b
          : c < rhs.c
          );
    }
  };

  std::vector<Pack> X, Y;
  for (int i=0; i<(1<<Na); ++i) {
    int a_=0, b_=0, c_=0;
    for (size_t j=0; j<Na; ++j)
      if (i>>j & 1) {
        a_ += a[j];
        b_ += b[j];
        c_ += c[j];
      }

    X.emplace_back(a_, b_, c_);
  }

  for (int i=0; i<(1<<Nb); ++i) {
    int a_=0, b_=0, c_=0;
    for (size_t j=0; j<Nb; ++j)
      if (i>>j & 1) {
        a_ += a[Na+j];
        b_ += b[Na+j];
        c_ += c[Na+j];
      }
  
    Y.emplace_back(a_, b_, c_);
  }

  std::sort(Y.begin(), Y.end());

  int inf=10000, res=inf;
  for (size_t i=0; i<X.size(); ++i) {
    int ma=Ma, mb=Mb;
    for (int r=1; r<=10; ++r, ma+=Ma, mb+=Mb) {
      if (ma < X[i].a || mb < X[i].b) continue;

      auto lb=std::lower_bound(
          Y.begin(), Y.end(), Pack(ma-X[i].a, mb-X[i].b, 0));

      if (lb < Y.end() && lb->a == ma-X[i].a && lb->b == mb-X[i].b) 
        res = std::min(res, X[i].c+lb->c);
    }
  }

  printf("%d\n", res<inf? res:-1);
}


Measured memory_bytes: 32872
#!/usr/bin/env python
S = input()
T = input()
map_table = {}
imap_table = {}
fail = False
for i, c in enumerate(S):
    if S[i] not in map_table and T[i] not in imap_table:
        map_table[S[i]] = T[i]
        imap_table[T[i]] = S[i]
    if S[i] not in map_table or map_table[S[i]] != T[i]:
        fail = True
        break
    if T[i] not in imap_table or imap_table[T[i]] != S[i]:
        fail = True
        break
print('No' if fail else 'Yes')


Measured memory_bytes: 3632
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(int i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
using namespace std;
int main() {
    IO;
    ll n,m; cin>>n>>m;
    n=n*(n-1)/2;
    m=m*(m-1)/2;
    cout<<n+m;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<algorithm>

using namespace std;

bool isKaibun(string str, int length) {
    //cout << str << endl;
    for (int i = 0; i < length / 2; i++) {
        if (str[i] != str[length - 1 - i]) {
            /*cout << str << endl;
            cout << i << " : " << length - 1 - i << endl;*/
            return false;
        }
    }
    return true;
}

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

    int N = S.size();
    if (isKaibun(S, N) && isKaibun(S.substr(0, (N - 1) / 2), (N - 1) / 2) && isKaibun(S.substr(((N + 3) / 2)-1), ((N - 3) / 2)+1)) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	char a[3];
	scanf("%s",&a);
	if((a[0]==a[1]&&a[1]==a[2])||(a[1]==a[2]&&a[2]==a[3])){
	printf("Yes\n");
	}else{
	printf("No\n");
	}

	return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }

void dfs(int v, mat &chi, int n, mat &g){
    g[n].push_back(v);
    for(int c: chi[v]) dfs(c, chi, n + 1, g);
}

void dfs2(int v, mat &chi, bools &used, int n){
    used[v] = true;
    if(n == 0) return;
    for(int c: chi[v]) if(!used[c]) dfs2(c, chi, used, n - 1);
}

signed main(){

    int N, K; cin >> N >> K;
    vec a(N); readi(a);
    int ans = 0;
    if(a[0] != 0){
        a[0] = 0;
        ans++;
    }

    mat chi(N), g(N);
    FOR(i, 1, N) chi[a[i]].push_back(i);
    dfs(0, chi, 0, g);

    bools used(N, false);
    IFOR(i, K + 1, N){
        for(int v: g[i]){
            if(used[v]) continue;
            ans++;
            int p = v;
            REP(j, K - 1) p = a[p];
            dfs2(p, chi, used, K - 1);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int cnt = 0;
    int n; cin >> n;
    bool bl = 0;
    while(n--){
        int a, b; cin >> a >> b;
        if(a == b) cnt++;
        else cnt = 0;
        if(cnt >= 3) bl = 1;
    }
    if(bl) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

int N;
ll A[SIZE];

int main(){

	scanf("%d",&N);
	for(int i = 0; i < N; i++){

		scanf("%lld",&A[i]);
	}

	ll plus,sum;

	if(A[0] <= 0){

		plus = abs(1-A[0]);
		sum = 1;

	}else{

		plus = 0;
		sum = A[0];
	}

	for(int i = 1; i < N; i++){

		sum += A[i];

		if(i%2 == 1){ //マイナス

			if(sum < 0)continue;
			plus += abs(-1-sum);
			sum = -1;

		}else{ //プラス

			if(sum > 0)continue;
			plus += abs(1-sum);
			sum = 1;
		}
	}

	ll minus;

	if(A[0] >= 0){

		minus = abs(-1-A[0]);
		sum = -1;
	}else{

		minus = 0;
		sum = A[0];
	}

	for(int i = 1; i < N; i++){

		sum += A[i];

		if(i%2 == 1){ //プラス

			if(sum > 0)continue;
			minus += abs(1-sum);
			sum = 1;

		}else{ //マイナス

			if(sum < 0)continue;

			minus += abs(-1-sum);
			sum = -1;
		}
	}

	printf("%lld\n",min(plus,minus));

	return 0;
}


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

char s[ 200010 ];

int main( int argc, char *argv[] )
{
int i;
int iSize;
int iStart;
int iEnd;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> s;
	iSize = strlen( s );

	for( i = 0; i < iSize; i++ )
	{
		if( s[ i ] == 'A' )
		{
			iStart = i;

			break;
		}
	}

	for( i = iSize - 1; i >= 0; i-- )
	{
		if( s[ i ] == 'Z' )
		{
			iEnd = i;

			break;
		}
	}

	cout << iEnd - iStart + 1 << endl;

	return 0;
}




Measured memory_bytes: 512
#include<iostream>
using namespace std;
bool solv(long long d)
{
  for (long i=2;i*i<=d;i++)
  {
  if(d%i==0)return 0;
  }
  return 1;
}
int main(){
  long long a;
  cin>>a;
  for (long long s=a;s>0;s++)
  {
    if (solv(s))
    {
      cout<<s<<endl;
      break;
    }
  }
}

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

using namespace std;

int main(void){

    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int n;
    cin >> n;

    cout << a[n-1] << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N=intput()
C=[]
ans=0
for _ in range(N):
    C.append(lint())
C.sort(reverse=True,key=sum)
for i in range(N):
    ans+=((-1)**(i%2))*C[i][i%2]
print(ans)

Measured memory_bytes: 96304
/*
    ThunderClap and Flash
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod) + (b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod) * (b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod) - (b%mod) + mod)%mod;}

void Flash(){
    ll n;
    cin>>n;
    ll b;
    ll ans = 0;
    for (ll i = 1; i < n; i++) {
        b = (n / i);
        ans += b;
        if ((i * b) == n) {
            --ans;
        }
    }   
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){ 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    ThunderClap;
    ll t = 1;
    //cin>>t;
    for(ll i = 1; i <= t; i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std; 
using ll = long long;
#define int ll
signed main() { 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; 
	cin>>n;
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		if(i%3 && i%5)
			sum += i;
	}
	cout << sum;
}


Measured memory_bytes: 3652
input = [int(x) for x in input().split()]

numContests = input[0]
ratingDisplayed = input[1]
innerRating = 0
#displayed rating = innerrating -100*(10-N)
#innerRat

if (numContests>10):
    innerRating = ratingDisplayed
else:
    innerRating = ratingDisplayed+100*(10-numContests)

print(innerRating)


Measured memory_bytes: 2940
#include <time.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
int main(int argc, char const *argv[]) {
  string S;
  cin >> S;
  int ans = 0;
  int temp = 0;
  bool flag = false;
  for (size_t i = 0; i < S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'G' || S[i] == 'C' || S[i] == 'T') {
      flag = true;
      temp++;
      //cout << temp << endl;
      if (ans <= temp) {
        ans = temp;
      }
      flag = false;
    } else {
      temp = 0;
    }
  }

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


Measured memory_bytes: 256
n=int(input())
l=[0]+list(map(int,input().split()))
for i in range(1,n+1):
  l[i]+=l[i-1]
d={}
for i in l:
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
ans=0
for a in d.values():
  ans+=a*(a-1)//2
print(ans)

Measured memory_bytes: 36372
#include <cstdio>

const int MaxN = 300 + 5;

int N;
int Cnt[4];
double Dp[MaxN][MaxN][MaxN];
bool Vis[MaxN][MaxN][MaxN];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    int x;
    scanf("%d", &x);
    Cnt[x]++;
  }
}

double dfs(int i, int j, int k) {
  if (i == 0 && j == 0 && k == 0) return 0;
  if (Vis[i][j][k] == true) return Dp[i][j][k];
  Vis[i][j][k] = true;
  if (k != 0) Dp[i][j][k] += dfs(i, j + 1, k - 1) * k / N;
  if (j != 0) Dp[i][j][k] += dfs(i + 1, j - 1, k) * j / N;
  if (i != 0) Dp[i][j][k] += dfs(i - 1, j, k) * i / N;
  Dp[i][j][k]++;
  Dp[i][j][k] /= 1.0 * (i + j + k) / N;
  return Dp[i][j][k];
}

void solve() {
  printf("%.10lf\n", dfs(Cnt[1], Cnt[2], Cnt[3]));
}

int main() {
  init();
  solve();
  return 0;
}

Measured memory_bytes: 246016
import java.util.Scanner;

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

        int i , j;

        while(true){
            int x = sc.nextInt();
            int y = sc.nextInt();

            for(i = 0;i < x;i++){
                for(j = 0;j < y;j++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }

            if(x == 0 && y == 0)break;

            System.out.printf("\n");

        }
    }
}


Measured memory_bytes: 63324
#include <stdio.h>

#define gc() getchar()

int bits['T' + 1];
char dic[33554432];

int main(void){
    int t, n, c;
    bits['A'] = 0; bits['C'] = 1; bits['G'] = 2; bits['T'] = 3;
    scanf("%d", &n);
    c = gc(); // 改行読み捨て
    while (n--) {
        c = gc();
        if (c == 'i') {
            t = 7;
            while (--t) gc();
            t = 1;
            while ((c = gc()) >= ' ') {
                t <<= 2;
                t |= bits[c];
            }
            dic[t] = 1;
        } else {
            t = 5;
            while (--t) gc();
            t = 1;
            while ((c = gc()) >= ' ') {
                t <<= 2;
                t |= bits[c];
            }
            if (dic[t]) printf("yes\n");
            else printf("no\n");
        }
    }
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, t;
    cin >> a >> b >> t;
    int ans = 0;
    for(int i = a; i <= t; i += a) {
        ans += b;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main{
    public static void main(String[] args){
	try{
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    int je, x, y, z;
	    int[] ini = new int[100];
	    z=0;
	    while(true){
		je=Integer.valueOf(br.readLine());
		if(je==0)
		    break;
		for(int i=0; i<je; i++){
		    String s = br.readLine();
		    x=Integer.parseInt(s.substring(0,s.indexOf(" ")));
		    y=Integer.parseInt(s.substring(s.indexOf(" ")+1,s.length()));
		    if(x>y)
			ini[z]+=(x+y);
		    else if(x==y){
			ini[z]+=x; ini[z+1]+=y;
		    }
		    else
			ini[z+1]+=(x+y);
		}
		z+=2;
	    }
	    for(x=0; x<z; x=x+2)
		System.out.println(ini[x]+ " "+ ini[x+1]);
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 11000
#include <cstdio>
#include <algorithm>
#include <cstring> 

using namespace std;

const int N = 2e5 + 10;
 
int n, T, p[N];
char s[N];
long long L, R, num[N][30];

long long fib(long long len, int c) {
	if (len <= n) return num[len][c];
	if (len <= n * 2) return num[n][c] + num[len - n][c];
	long long f1 = num[n][c], f2 = num[n][c] + num[T][c], l1 = n, l2 = n + T;
	while (len > l1 + l2) {
		long long t = f2;
		f2 += f1, f1 = t;
		t = l2, l2 += l1, l1 = t;
	}
	return f2 + fib(len - l2, c);
}

long long calc(long long len, int c) {
	if (len <= n) return num[len][c];
	if (n % T == 0) {
		long long re = 1ll * (len - n) / T * num[T][c] + num[n][c];
		len -= n, len %= T;
		return re + num[len][c];
	}
	else return fib(len, c);
}

int main() {
	scanf("%s%lld%lld", s + 1, &L, &R);
	n = strlen(s + 1) / 2;
	p[1] = 0;
	for (int j = 0, i = 2; i <= n; i ++) {
		for (; j && s[j + 1] != s[i];) j = p[j];
		if (s[j + 1] == s[i]) j ++;
		p[i] = j;
	}
	for (int i = 1; i <= n; i ++) {
		for (int j = 0; j < 26; j ++) num[i][j] = num[i - 1][j];
		num[i][s[i] - 'a'] ++;
	}
	T = n - p[n];
	for (int i = 0; i < 26; i ++) printf("%lld%c", calc(R, i) - calc(L - 1, i), i == 25 ? 10 : 32);
	return 0;
}

Measured memory_bytes: 27136
from itertools import permutations

N = int(input())
p = tuple([int(x) for x in input().split()])
q = tuple([int(x) for x in input().split()])

a = -1
b = -1
for i,v in enumerate(permutations(range(1,N+1), N)):
    if v==p:
        a = i
    if v==q:
        b = i


print(abs(a-b))


Measured memory_bytes: 3060
// #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define FOR(i,n) for(int i=0; i<n; i++)
#define X first
#define Y second
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define arrsum for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define sz(a) (int)(a.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);

ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

bool vowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return true;
    else return false;
}

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
    vi p, rank, setSize;                       // remember: vi is vector<int>
    int numSets;
public:
    UnionFind(int N) {
        setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
        p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
    int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
    bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
    void unionSet(int i, int j) { 
        if (!isSameSet(i, j)) { numSets--; 
        int x = findSet(i), y = findSet(j);
        // rank is used to keep the tree short
        if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
        else                   { p[x] = y; setSize[y] += setSize[x];
                                 if (rank[x] == rank[y]) rank[y]++; } } }
    int numDisjointSets() { return numSets; }
    int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, m;
    cin>>n>>m;
    if(m > 2*n) {
        cout<<n + (m-2*n)/4;
    }
    else {
        cout<<m/2;
    }

    return 0;
}   

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

#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define ld long double
#define EPS (1e-15)
#define mod 1000000007
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define SIZE(x) (int) x.size()
#define to_string(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
#define lp(i, a, n) for (int(i) = (a); (i) <= (int)(n); ++(i))
#define lpd(i, n, a) for (int(i) = (n); (i) >= (a); --(i))
#define bitcount(n) __builtin_popcountll(n)
#define readi(x) scanf("%d", &x);
#define readl(x) scanf("%lld", &x);
#define reads(x) scanf("%s", &x);
#define readc(x) scanf("%c", &x);
#define readd(x) scanf("%lf", &x);

using namespace std;
const int N = 200005;
const int K = (int)log2(N) + 2;
const ll infi = 1ll << 60;

int main() {
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
    io;
    ll a, b;
    string s;
    set<string> ss;
    map<string, ll> cnts, cntt;
    cin >> a;
    while (a--) {
        cin >> s;
        ss.insert(s);
        ++cnts[s];
    }
    cin >> b;
    while (b--) {
        cin >> s;
        ++cntt[s];
    }
    ll ans = 0;
    for (auto x : ss)
        ans = max(ans, cnts[x] - cntt[x]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    string X; cin >> X;

    int popbase = 0;
    REP(i,n) if (X[i] == '1') popbase++;
    int modp = 0, modm = 0; // あまり
    int popp = popbase+1, popm = popbase-1;

    REP(i,2) {
        int p = (i == 0) ? popp:popm; 
        if (p == 0) continue;
        ull a = 0;
        size_t j = 0;
        while(j < X.size()) {
            string s = X.substr(j,32);
            a = (a << s.size()) + bitset<32>(s).to_ullong();
            a %= p;
            j += s.size();
        }
        if (i == 0) modp = a;
        else modm = a;
    }


    auto calc = [](int x,int m){
        int ret = 0;
        do {
            x %= m;
            bitset<32> bs(x);
            m = bs.count();
            ret++;
        } while (x > 0);
        return ret;
    };

    int powp = 1,powm = 1;
    vector<int> ans(n);
    RREP(i,n-1) {
        int a = 0;
        if (X[i] == '0') {
            a = modp + powp;

            ans[i] = calc(a,popp);
        } else {
            if (popm == 0) continue;

            a = modm - powm;
            if (a < 0) a += popm;

            ans[i] = calc(a,popm);
        }

        powp = powp * 2 % popp;
        if (popm != 0) powm = powm * 2 % popm;
    }

    REP(i,n) cout << ans[i] << '\n';

    return 0;
}


Measured memory_bytes: 4392
def run():
  N = int(input())
  ans = 0
  di = {}
  for a in range(1, 10):
    for b in range(1, 10):
      key = str(a)+str(b)
      di[key] = 0
  for n in range(1, N+1):
    if n%10 == 0:
      continue
    n = str(n)
    start, end = n[0], n[-1]
    di[start+end] += 1
    if start == end:
      ans += max(0, di[end+start]*2-1)
    else:
      ans += di[end+start]*2
  print(ans)
    

if __name__ == '__main__':
  run()

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

int main(){
  int N, x; cin >> N >> x;
  int X=x;
  vector<int> A(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    sum+=A[i];
  }
  sort(A.begin(),A.end());
  int ans=0;
  for(int i=0;i<N;i++){
    if(x>=A[i]){
      ans++;
      x-=A[i];
    }
    else break;
  }
  if(ans==N && sum!=X){
    ans--;
  }
  cout << ans << endl;
}

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

int main() {
  int N = 0,A = 0,B = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
  	cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  for (int i = 0; i < N; i += 2) A += a.at(i);
  for (int i = 1; i < N; i += 2) B += a.at(i);
  
  cout << A - B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
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;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a, bool g){
	if(g){
		if(a[index]<key){
			return true;
		}
	}
	else{
		if(a[index]>key){
			return true;
		}
	}
	return false;
}

ll bin_search(ll key, vector<ll> &a, bool g){
	
	ll l=-1;
	ll r=a.size();

	if(g){
		l=a.size();
		r=-1;
	}

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a, g)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

int main(){

	string s;
	cin>>s;

	ll month=(s[5]-'0')*10+(s[6]-'0');
	ll day=(s[7]-'0')*10+(s[8]-'0');

	if(month<4){
		cout<<"Heisei"<<endl;
	}
	else if(month==4){
		if(day<=30){
			cout<<"Heisei"<<endl;
		}
		else{
			cout<<"TBD"<<endl;
		}
	}
	else{
		cout<<"TBD"<<endl;
	}
	
    return 0;
}


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

#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;

//#define int long long;
typedef long long ll;


//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}
//---------------//

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

    cin >> N;
    int a[N];
    int ans = 0;
    REP(i, 0, N){
        cin >> a[i];
        ans += a[i] - 1;
    } 

    cout << ans << endl;
}


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

int main(){
  int n=1,r=1,p,c;
  vector<int> deck,temp,ans;

  while(1){
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=n; i>0; --i)deck.push_back(i); //???????????????
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      copy(deck.begin()+p-1,deck.begin()+p+c-1,back_inserter(temp));
      deck.erase(deck.begin()+p-1,deck.begin()+p+c-1);
      copy(deck.begin(),deck.end(),back_inserter(temp));
      deck=temp;
      temp.clear();
    }
    ans.push_back(deck[0]);
    deck.clear();
  }
  for(auto x: ans)cout << x << endl;
  return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll K,S;
    cin >> K >> S;
    ll ans = 0;
    REP(i,K+1){
        REP(l,K+1){
            if(S-l-i<=K&&S-l-i>=0)ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3636
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


class EColorfulHats2 {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        int a[100010];
        in >> n;
        rep(i, n){
            in >> a[i];
        }

        int zero = 3;
        int b[100010];
        map<int, int> cnt;
        rep(i, n){
            if(a[i] == 0){
                b[i] = zero;
                zero--;
            }else{
                b[i] = cnt[a[i]-1] - cnt[a[i]];
            }
            cnt[a[i]]++;
        }

        ll res = 1;
        ll mod = 1e9+7;
        rep(i, n){
            res *= b[i];
            res %= mod;
        }

        //adeb(b, n);
        //mdeb(cnt);

        out << res << endl;
	}
};


int main() {
	EColorfulHats2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 5760
import java.util.*;

public class Main {
  public static int[] kai;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    kai = new int[9];
    kai[0] = 1;
    for(int i = 1; i < 9; i++) {
      kai[i] = (i * kai[i - 1]);
    }
    int n = sc.nextInt();
    ArrayList<Integer> listp = new ArrayList<Integer>();
    ArrayList<Integer> listq = new ArrayList<Integer>();
    for(int i = 0; i < n; i++) {
      listp.add(sc.nextInt());
    }
    for(int i = 0; i < n; i++) {
      listq.add(sc.nextInt());
    }
    int a = dfs(listp.get(0), listp);
    int b = dfs(listq.get(0), listq);
    System.out.println(Math.abs(a - b));
  }

  public static int dfs(int p, ArrayList<Integer> list) {
    int t = list.size();
    int ret = (p - 1) * kai[t - 1];
    if(t == 1) {
      return 1;
    } else {
      ArrayList<Integer> list2 = new ArrayList<Integer>();
      for(int i = 1; i < t; i++) {
        list2.add(list.get(i));
      }
      int k = 1;
      for(int i = 0; i < (t - 1); i++) {
        if(list2.get(0) > list2.get(i)) k++;
      }
      ret += dfs(k, list2);
      return ret;
    }
  }
}

Measured memory_bytes: 35724