akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}


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

    ll A, B, C, N; cin >> A >> B >> C >> N;
    ll area = 2 * (A * B + B * C + C * A);

    map<tuple<ll,ll,ll>,bool> mp;

    REP(i, N) {
        ll x, y, z; cin >> x >> y >> z;
        area += 6;
        if (x == 0) area -= 2;
        if (x == A-1) area -= 2;
        if (y == 0) area -= 2;
        if (y == B-1) area -= 2;
        if (z == 0) area -= 2;
        if (z == C-1) area -= 2;
        if (mp.count(make_tuple(x-1, y, z))) area -= 2;
        if (mp.count(make_tuple(x+1, y, z))) area -= 2;
        if (mp.count(make_tuple(x, y-1, z))) area -= 2;
        if (mp.count(make_tuple(x, y+1, z))) area -= 2;
        if (mp.count(make_tuple(x, y, z-1))) area -= 2;
        if (mp.count(make_tuple(x, y, z+1))) area -= 2;
        mp[make_tuple(x, y, z)] = 1;
    }

    cout << area << endl;

    return 0;
}



Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  long long s=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {
   k=i+1;
    if((k%3!=0) && (k%5!=0) &&(k%15!=0))
    {
        s=s+k;
    }
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define precision(x) cout << setprecision(x) << fixed;
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i]; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;



int32_t main()
{
   fast;
   #ifndef ONLINE_JUDGE
   freopen("goodluckin.txt","r",stdin);
   freopen("goodluckout.txt","w",stdout);
   #endif
   int n;
   cin >> n;
   pair<int,int>a[n];
   int x,y;
   for(int i = 0 ; i < n ; i++){
    cin >> x >> y;
    a[i].first = x;
    a[i].second = y;
   }
   bool ok = false;
   for(int i = 2 ; i < n ; i++){
      if(a[i].first == a[i].second && a[i-1].first == a[i-1].second && a[i-2].first == a[i-2].second){
        ok = true;
        break;
      }
   }
   if(ok){
    cout << "Yes";
   }
   else{
    cout << "No";
   }
}


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

int main() {
    int X;
    cin >> X;
    int ttl=0;
   
        
        if(X>=500){
        ttl += X/500 * 1000;
         X= X%500;
        }
    if(5<=X && X<=500)
    {
        ttl += X/5 * 5;
    }
    cout << ttl << endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <numeric>

using namespace std;

typedef long long int lo;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e9
#define N (lo)1e5 * 5
#define all(x) (x).begin(), (x).end()
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
#define si pair<string,lo>
#define vi vector <lo> 
#define vii vector <ii> 

int main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0);
    lo n,k;
    cin >> n >> k;
    map <lo,lo> m;
    for(lo i = 0 ; i < k ; i++){
	lo b;
	cin >> b;
	for(lo i = 0 ; i < b ; i++){
	    lo a;
	    cin >> a;
	    m[a] = 1;
	}
    }
    lo ans = 0;
    for(lo i = 1 ; i <= n ; i++){
	if(!m[i]){
	    ans++;
	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

void sort_asc(int *a, int *b)
{
    int tmp;
    if (*a > *b) {
        tmp = *a;
        *a = *b;
        *b = tmp;
    }
}

int main(void)
{
    int a, b, c;

    scanf("%d %d %d", &a, &b, &c);

    sort_asc(&a, &b);
    sort_asc(&b, &c);
    sort_asc(&a, &b);

    printf("%d %d %d\n", a, b, c);
    
    return 0;
}




Measured memory_bytes: 2048
#include<stdio.h>

int l[7];

void dice(int num){
    l[0] = l[1];
    l[1] = l[num];
    l[num] = l[6];
    l[6] = l[7-num];
    l[7-num] = l[0];
}

int main(void){
    int n,u,f;
    for(int i=0; i<6; i++) scanf("%d", &l[i+1]);
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d%d", &u, &f);
        if(f==l[3] || f==l[4]) dice(4);
        while(f!=l[2]) dice(2);
        while(u!=l[1]) dice(4);
        printf("%d\n", l[3]);
    }
    return 0;
}


Measured memory_bytes: 2028
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
int32_t main(){
    fast;
    int k,a,b;
    cin>>k>>a>>b;
    if(b/k-(a-1)/k)
        cout<<"OK";
    else
        cout<<"NG";
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
typedef pair<int,int> P;
int n,A[N];


signed main(){
  
  P Idx[N];
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i],Idx[i] = P(A[i],i);
  sort(Idx,Idx+n);
  Idx[n] = P(-1,-1);  

  set<int> S;
  S.insert(-1);
  S.insert(n);

  int ans = 0;
  vector<int> ls;
  for(int i=0;i<n;i++){
    int h = Idx[i].first;
    int idx = Idx[i].second;
    int l =idx-(*(--S.upper_bound(idx)))-1;
    int r =(*S.upper_bound(idx)) -idx-1;
    ans=max(ans,(r+l+1)*h);
    ls.push_back(idx);
    if(Idx[i+1].first!=h){
      for(int j:ls)S.insert(j);
      ls.clear();
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

long long gcd(long long a, long long b) {
  while (a > 0 && b > 0) {
    if (a > b) a %= b;
    else b %= a;
  }
  return a + b;
}

long long lcm(long long a, long long b) {
  return a/gcd(a, b) * b;
}

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

  long long n, t; 
  cin >> n;
  long long res = 1;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    res = lcm(res, t);
  }
  cout << res << endl;

  return 0;
}



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

int min(int a, int b){
  if(a>b){
    return b;
  }else{
    return a;
  }
}

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

  int A[N];
  int B[N-1];
  int sum_a = 0;
  for(int i=0; i<N-1; i++){
    cin >> B[i];
  }

  sum_a = B[0] + B[N-2];
  for(int i=0; i<N-2; i++){
    int res = min(B[i], B[i+1]);
    sum_a += res;
  }
  cout << sum_a << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] s = Console.ReadLine().Split(' ');
            String s1 = s[1];
            String ss = s1.Substring(0,1);

            Console.WriteLine("A" + ss + "C");
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

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

int a, d, n;
int p[1000001];

int solve() {
	int c = 0;
	for(int i=a; i<=1000000; i+=d) {
		if(p[i] == 1) c++;
		if(c == n) {
			return i;
		}
	}
	return -1;
}

int main() {
	// compute prime
	fill(p, p+1000001, 1);
	p[0] = p[1] = 0;
	repa(i,2,1000000) {
		if(p[i] == 1) {
			int j = i << 1;
			while(j <= 1000000) {
				p[j] = 0;
				j += i;
			}
		}
	}

	while(cin>>a>>d>>n, a|d|n) {
		cout << solve() << endl;
	}
}

Measured memory_bytes: 5064
#include<cstdio>


int num[10];
int m;

int main() {
	scanf("%d\n", &m);
	bool flag = true;
	while(m--)
	{ 
	    int l = 0;
	    int r = 0;
		flag = true;
		for (int i = 0; i < 10; i++)
			scanf("%d", &num[i]);
		for (int i = 0; i < 10; i++)
		{
			if (num[i] > l)
				l = num[i];
			else if (num[i] > r)
				r = num[i];
			else
			{
				flag = false;
				break;
			}
		}
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
	}


	return 0;
}


Measured memory_bytes: 2516
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
    char name[100];
    int t;
}P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}
 
P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}
 
int min(int a, int b) { return a < b ? a : b; }
 
int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
 
    for (i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1, tail = n + 1;
 
    while (head != tail) {
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if (u.t > 0)enqueue(u);
        else {
            printf("%s %d\n", u.name, elaps);
        }
    }
    return 0;
}

Measured memory_bytes: 11864
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) :x((x% mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  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 { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

mint comb(ll n, ll a) {
  mint x = 1, y = 1;
  for (ll i = 0; i < a; i++) {
    x *= (i + 1);
    y *= (n - i);
  }
  return y / x;
}

int main(void) {
  ll x, y;
  cin >> x >> y;

  mint ans = 0;
  if ((2 * x - y) % 3 == 0 && (2 * y - x) % 3 == 0) {
    ll d1 = (2 * x - y) / 3;
    ll d2 = (2 * y - x) / 3;
    ll dsum = d1 + d2;
    ll dsmall = d1 < d2 ? d1 : d2;
    ans = (dsum > 0 && dsmall >= 0) ? comb(dsum, dsmall) : 0;
  }
  else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import bisect

n = int(input())
alist = list(sorted(map(int, input().split())))
blist = list(map(int, input().split()))
clist = list(sorted(map(int, input().split())))

ans = 0
for b in blist:
  ai = bisect.bisect_left(alist, b)
  ci = bisect.bisect_right(clist, b)
  if ai == 0 or ci == len(clist):
    continue
  else:
    ans += ai * (len(clist) - ci)
print(ans)


Measured memory_bytes: 23744
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

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

int main(){
    ll n; cin >> n;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    ll ans = INF;
    rep(i,101){
        ll temp = 0;
        rep(j,n){
            temp += (x[j] - i) * (x[j] - i) ;
        }
        chmin(ans, temp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
def comb(n, k, mod=10**9+7):
    num = den = 1
    for i in range(k):
        num *= n - i
        den *= i + 1
    return num // den

N, P = map(int, input().split())
A = list(map(int, input().split()))
cnt = [0] * 2
for a in A:
    cnt[a % 2] += 1
even = 0
odd = [0] * 2
for i in range(N+1):
    even += comb(cnt[0], i)
    odd[i % 2] += comb(cnt[1], i)
print(even * odd[P])

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

#define ll long long
#define ull unsigned long long

const int MaxN(1003);
const int Mod(1e9 + 7);

struct Matrix_t
{
	int a[2][2];
	inline	Matrix_t operator * (const Matrix_t &T)
	{
		Matrix_t Ans;
		Ans.a[0][0] = ((ull) a[0][0] * T.a[0][0] + (ull) a[0][1] * T.a[1][0]) % Mod;
		Ans.a[0][1] = ((ull) a[0][0] * T.a[0][1] + (ull) a[0][1] * T.a[1][1]) % Mod;
		Ans.a[1][0] = ((ull) a[1][0] * T.a[0][0] + (ull) a[1][1] * T.a[1][0]) % Mod;
		Ans.a[1][1] = ((ull) a[1][0] * T.a[0][1] + (ull) a[1][1] * T.a[1][1]) % Mod;
		return Ans;
	}
};

Matrix_t fexp(Matrix_t x, ll k)
{
	Matrix_t res = x;
	for(--k; k; k >>= 1, x = x * x)
		if(k & 1) res = res * x;
	return res;
}

int fexp(int x, ll k)
{
	int res = 1;
	for(; k; k >>= 1, x = (ull) x * x % Mod)
		if(k & 1) res = (ull) res * x % Mod;
	return res;
}

char a[MaxN][MaxN];

int main()
{
	ll K;
	int H, W;
	scanf("%d%d%lld", &H, &W, &K);
	if(K == 1) return puts("1"), 0;
	for(int i = 1; i <= H; i++)
		scanf("%s", a[i] + 1);
	int lr = 0, ud = 0, ev = 0, eh = 0, v = 0;
	for(int i = 1; i <= H; i++)
		for(int j = 1; j <= W; j++)
			v += (a[i][j] == '#');
	for(int i = 1; i <= H; i++)
		if(a[i][1] == '#' && a[i][W] == '#') ++lr;
	for(int i = 1; i <= W; i++)
		if(a[1][i] == '#' && a[H][i] == '#') ++ud;
	for(int i = 1; i <= H; i++)
		for(int j = 1; j < W; j++)
			if(a[i][j] == '#' && a[i][j + 1] == '#') ++eh;
	for(int i = 1; i < H; i++)
		for(int j = 1; j <= W; j++)
			if(a[i][j] == '#' && a[i + 1][j] == '#') ++ev;
	if(lr && ud) puts("1");
	else if(!lr && !ud) printf("%d\n", fexp(v, K - 1));
	else
	{
		if(lr) swap(ud, lr), swap(ev, eh);
		Matrix_t A;
		A.a[0][0] = v, A.a[0][1] = 0;
		A.a[1][0] = ev, A.a[1][1] = ud;
		A = fexp(A, K - 1);
		printf("%d\n", (A.a[0][0] - A.a[1][0] + Mod) % Mod);
	}
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>
 
const int64_t cc = pow( 10, 9 );
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< std::string, int64_t > origin, std::pair< std::string, int64_t > another )
{
    return origin.second  > another.second;
}
 
int main()
{
    std::string word = "aa";
    int64_t a,b,c,d,e;
    std::cin>> a;
    std::cin>> b;

    c = a / b;

    if( a % b != 0 )
    {
        c += 1;
    }

    std::cout<< c;
    
}


Measured memory_bytes: 256
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

n = I()
a = [I() for i in range(n)]
b = sorted(a)
for i in range(n):
    if(a[i] == b[-1]):print(b[-2])
    else:print(b[-1])

Measured memory_bytes: 61136
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

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

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

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

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


int main() {
  ll N;

  cin>>N;
  string S;
  ll p[26];
    FOR(i,0,25){
    p[i]=1;
  }

    cin>>S;

  FOR(i,0,N-1){
    if(S[i]=='a'){
      p[0]++;
    }
    if(S[i]=='b'){
      p[1]++;
    }
    if(S[i]=='c'){
      p[2]++;
    }
    if(S[i]=='d'){
      p[3]++;
    }
    if(S[i]=='e'){
      p[4]++;
    }
    if(S[i]=='f'){
      p[5]++;
    }
    if(S[i]=='g'){
      p[6]++;
    }
    if(S[i]=='h'){
      p[7]++;
    }
    if(S[i]=='i'){
      p[8]++;
    }
    if(S[i]=='j'){
      p[9]++;
    }
    if(S[i]=='k'){
      p[10]++;
    }
    if(S[i]=='l'){
      p[11]++;
    }
    if(S[i]=='m'){
      p[12]++;
    }
    if(S[i]=='n'){
      p[13]++;
    }
    if(S[i]=='o'){
      p[14]++;
    }
    if(S[i]=='p'){
      p[15]++;
    }
    if(S[i]=='q'){
      p[16]++;
    }
    if(S[i]=='r'){
      p[17]++;
    }
    if(S[i]=='s'){
      p[18]++;
    }
    if(S[i]=='t'){
      p[19]++;
    }
    if(S[i]=='u'){
      p[20]++;
    }
    if(S[i]=='v'){
      p[21]++;
    }
    if(S[i]=='w'){
      p[22]++;
    }
    if(S[i]=='x'){
      p[23]++;
    }
    if(S[i]=='y'){
      p[24]++;
    }
    if(S[i]=='z'){
      p[25]++;
    }
  }


  ll ans = 1;

    FOR(i,0,25){
    ans=ans*p[i]%MOD;
  }


  cout<<ans-1<<endl;
  return 0;


 
}
 


Measured memory_bytes: 512
fun main(args: Array<String>) {
    val (N, K) = readInputLine().split(" ").map { it.toLong() }
    val AArr = readInputLine().split(" ").map { it.toLong() }.sorted().toLongArray()
    val BArr = readInputLine().split(" ").map { it.toLong() }.sortedDescending().toLongArray()

    if (N == 1L) {
        println(Math.max(0L, AArr[0]) * BArr[0])
        return
    }
    
    var lb = -1L
    var ub = 1000000000000L
    
    while (ub - lb > 1L) {
        val mid = (lb + ub) / 2L
        
        var cnt = 0L
        var ok = true
        
        for (i in 0 until N.toInt()) {
            cnt += Math.max(0L, Math.ceil((AArr[i].toDouble() * BArr[i].toDouble() - mid) / BArr[i]).toLong())
            if (cnt > K) {
                ok = false
                break
            }
        }
        
        if (ok) {
            ub = mid
        } else {
            lb = mid
        }
    }
    
    println(ub)
}

fun readInputLine(): String {
    return readLine()!!
}


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

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

  int W, H, N;
  cin >> W >> H >> N;

  int x_min = 0, x_max = W, y_min = 0, y_max = H;

  for (int i = 0; i < N; ++i) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      x_min = max(x_min, x);
    }
    else if (a == 2) {
      x_max = min(x_max, x);
    }
    else if (a == 3) {
      y_min = max(y_min, y);
    }
    else if (a == 4) {
      y_max = min(y_max, y);
    }
  }

  int value;
  if (x_max - x_min <= 0 || y_max - y_min <= 0) {
    value = 0;
  }
  else {
    value = (x_max - x_min) * (y_max - y_min);
  }
  cout << value << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;


int main(void){
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    if(x > y){
        ll ans = c*x*2;
        ans = min(ans,(x-y)*a+min(c*y*2,a*y+b*y));
        cout<<ans<<endl;
    }
    else if(y > x){
        ll ans = c*y*2;
        ans = min(ans,(y-x)*b+min(c*x*2,a*x+b*x));
        cout<<ans<<endl;
    }
    else{
        cout<<min(c*x*2,a*x+b*x)<<endl;
    }
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 1e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 1e5 + 3;

int dp[101][MAXN];
int W;
int w[101];
int v[101];

void solve() {
  int n;
  cin >> n;
  cin >> W;

  for (int i = 1; i <= n; ++i)
    cin >> w[i] >> v[i];

  dp[0][0] = 0;
  for (int i = 1; i < MAXN; ++i) {
    dp[0][i] = INF;
  }
  for (int i = 1; i <= n; ++i) {
    dp[i][0] = 0;
    for (int j = 1; j < MAXN; ++j) {
      if (j >= v[i])
        dp[i][j] = min(w[i] + dp[i - 1][j - v[i]], dp[i - 1][j]);
      else
        dp[i][j] = dp[i - 1][j];
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < MAXN; ++j) {
      if (dp[i][j] <= W)
        ans = max(ans, j);
    }
  }

  cout << ans << endl;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t = 1;

#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

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

using namespace std;

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


	int a,b,c,xa,yb;

	cin>>a>>b>>c>>xa>>yb;

	int cost1 = xa*a + yb*b;

	int cost2;
	int cost3;

	if(xa>yb)
	{
		cost2 = c*(2*yb) + (xa-yb)*a; 
	}
	else if(yb>xa)
	{
		cost2 = c*(2*xa) + (yb-xa)*b;
	}
	else if(xa==yb)
	{
		cost2 = c*(2*xa);
	}

	cost3 = max(yb,xa)*(2*c);

	cout<<min(cost1,min(cost2,cost3))<<'\n';
	return 0;	
}

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

int main(int argc, char const* argv[])
{
	int n, number;
	char suit;
	bool card[4][13];
	for (int i=0; i<4; i++) {
		for (int j=0; j<13; j++) {
			card[i][j] = false;
		}
	}
	cin >> n;

	for (int i=0; i<n; i++) {
		cin >> suit >> number;
		switch (suit) {
			case 'S' :
				card[0][number-1] = true;
				break;
			case 'H' :
				card[1][number-1] = true;
				break;
			case 'C' :
				card[2][number-1] = true;
				break;
			case 'D' :
				card[3][number-1] = true;
				break;
		}
	}

	for (int i=0; i<4; i++) {
		for (int j=0; j<13; j++) {
			if (!card[i][j]) {
				switch (i) {
					case 0 :
						cout << "S" << " " << j+1 << endl;
						break;
					case 1 :
						cout << "H" << " " << j+1 << endl;
						break;
					case 2 :
						cout << "C" << " " << j+1 << endl;
						break;
					case 3 :
						cout << "D" << " " << j+1 << endl;
						break;
				}
			}
		}
	}


	return 0;
}


Measured memory_bytes: 1160
#include <stdio.h>

int main(void) {
    int m,f,r;
    while(1) {
        scanf( "%d %d %d", &m, &f, &r);
        if( m==-1 && f==-1 && r==-1 ) break;
        if( m==-1 || f==-1 ) {
            printf("F\n");
        } else if( 80<=m+f ) {
            printf("A\n");
        } else if( 65<=m+f && m+f<80) {
            printf("B\n");
        } else if( 50<=m+f && m+f<65) {
            printf("C\n");
        } else if( 30<=m+f && m+f<50 ) {
            if( r>=50 ){
                printf("C\n");
            } else {
                printf("D\n");
            }
        } else {
            printf("F\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2584
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
const int N=2e5+10; 
int n,stk[N],top,l[N],r[N];
LL a[N],ans;
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
int main()
{
//	freopen("Minimum Sum.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n);
	for(RG int i=1;i<=n;i++) read(a[i]), l[i]=1, r[i]=n;
	for(RG int i=1;i<=n;i++)
	{
		while(top && a[i]<a[stk[top]]) top--;
		if(top) l[i]=stk[top]+1;
		stk[++top]=i;
	}
	top=0;
	for(RG int i=n;i;i--)
	{
		while(top && a[i]<a[stk[top]]) top--;
		if(top) r[i]=stk[top]-1;
		stk[++top]=i;
	}
	for(RG int i=1;i<=n;i++) ans+=(LL)(i-l[i]+1)*(LL)(r[i]-i+1)*a[i];
	printf("%lld\n",ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a,b,ar[100008],i,j,k,m,x,y,cnt,sum,d,e,f,cr[100000],c;
string s1[1000],s,s2;
ll p;
int main()
{
    ll test;
   cin>>a>>b;
   if(a*500>=b)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;



}









Measured memory_bytes: 256
A,B,C=[input() for i in range(0,3)]

turn='a'
while True:
  if turn == 'a':
    if A =="":
      print('A')
      break
    turn=A[0]
    A=A[1:]
  elif turn=='b':
    if B=="":
      print('B')
      break
    turn=B[0]
    B=B[1:]
  else:
    if C=="":
      print('C')
      break
    turn=C[0]
    C=C[1:]

Measured memory_bytes: 9136
S = input()
l = len(S)
# print(S, l)

ans = 0

def solve(S, b):
    ans = 0
    for s in S:
        ans += int(s) ^ b
        b ^= 1
    return ans

ans = solve(S, 0)
ans = min(ans, solve(S, 1))
print(ans)


Measured memory_bytes: 40940
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
const int N=1e9+7;
#define int long long
#define double long double
int lp[1000001];
void sievefact()
{
	lp[0]=1;
	lp[1]=1;
for (int i = 2; i <1000001 ; i+=2)
{
	/* code */lp[i]=2;
}
for (int i = 3; i < 1000001; i+=2)
{if(!lp[i])
	{
	for (int j = 1; j*i <1000001; j++)
	{
		if(!lp[i*j])
			lp[i*j]=i;
	}
}
}
}
int32_t main()
{
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
 IOS;
 sievefact();
 int n;
 cin>>n;

std::vector<int> a(n);
std::vector<int> v(1000001,0);
std::vector<set<int>> p(n);
bool ispair=1;
int gc=0;
for(int i=0; i<n; i++) {
    cin>>a[i];
    int x = a[i];
  	gc=__gcd(gc,a[i]);
    while(x > 1) {
        p[i].insert(lp[x]);
        x/=lp[x];
    }
    for(int y: p[i]) {
        if(v[y]) {
            ispair = 0;
        }
        v[y] = 1;

    }
 }


if(ispair)
	cout<<"pairwise coprime";
 else if(gc!=1)
	cout<<"not coprime";
else
	cout<<"setwise coprime";



 	



  
 




  
return 0;
}


Measured memory_bytes: 310508
#include <iostream>

int main(int argc, char** argv)
{
	char num[4];
	std::cin >> num;
	for (char x : num)
	{
		if (x == '7')
		{
			std::cout << "Yes" << std::endl;
			return 0;
		}
	}
	std::cout << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 3636
N,X,Y=map(int,input().split())

ans_list=[0]*N
for i in range(N-1):
  for j in range(i+1,N):
    p1=j-i
    p2=abs(X-1-i)+1+abs(Y-1-j)
    p=min(p1,p2)
    #print(i,j,p)
    ans_list[p]+=1
  
#print(ans_list)
for i in range(1,N):
  print(ans_list[i])

Measured memory_bytes: 3444
# coding: utf-8
# Your code here!

while True:
    n = int(input())
    if n == 0:
        break
    
    m = 0
    while n != 1:
        if n % 2 == 0:
            n //= 2
        else:
            n = n * 3 + 1
        m += 1
    print(m)


Measured memory_bytes: 5592
#![allow(non_snake_case)]

use proconio::input;
use proconio::fastout;
use std::cmp::min;
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        N: usize,
        K: usize,
        a: [usize; N],
    }
    let mut dp_l = vec![vec![false; K]; N + 1];
    let mut dp_r = vec![vec![false; K]; N + 1];
    dp_l[0][0] = true;
    for i in 0..N {
        for j in 0..K {
            if j >= a[i] {
                dp_l[i + 1][j] = dp_l[i][j] | dp_l[i][j - a[i]];
            } else {
                dp_l[i + 1][j] = dp_l[i][j];
            }
        }
    }
    dp_r[N][0] = true;
    for i in (0..N).rev() {
        for j in 0..K {
            if j >= a[i] {
                dp_r[i][j] = dp_r[i + 1][j] | dp_r[i + 1][j - a[i]];
            } else {
                dp_r[i][j] = dp_r[i + 1][j];
            }
        }
    }
    let mut dp_r_acc = vec![vec![0; K + 1]; N + 1];
    for i in 0..=N {
        for j in 0..K {
            dp_r_acc[i][j + 1] = dp_r_acc[i][j] + if dp_r[i][j] { 1 } else { 0 };
        }
    }
    let mut result = 0;
    for i in 0..N {
        let mut is_need = false;
        let sum_low = K.saturating_sub(a[i]);
        let sum_high = K;
        for l_sum in 0..sum_high {
            if dp_l[i][l_sum] {
                let r_sum_low = sum_low.saturating_sub(l_sum);
                let r_sum_high = sum_high - l_sum;
                if dp_r_acc[i + 1][r_sum_high] - dp_r_acc[i + 1][r_sum_low] > 0 {
                    is_need = true;
                    break;
                }
            }
        }
        if !is_need {
            result += 1;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 149048
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    static List<String> z;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double[][] za = new double [n][2];
        String s = "";
        for (int i = 0; i < n; i++) {
            za[i][0] = sc.nextDouble();
            za[i][1] = sc.nextDouble();
            s += i;
        }
        z = new ArrayList<>();
        permutation(s,"");
        double ans = 0.0;
        List<Double> l = new ArrayList<>();
        for(int i = 0; i < z.size(); i++) {
            List<Integer> list = new ArrayList<>();
            for(int j=0; j<n; j++) {
                list.add(Integer.parseInt(z.get(i).substring(j, j+1)));
            }
            double total = 0.0;
            for(int j=0; j<n-1; j++) {
                double a = za[list.get(j)][0] - za[list.get(j + 1)][0];
                double b = Math.pow(a, 2);
                double c = za[list.get(j)][1] - za[list.get(j + 1)][1];
                double d = Math.pow(c, 2);
                double e = Math.sqrt(b + d);
                total += e;
            }
            l.add(total);
        }
        for (Double double1 : l) {
            ans += double1;
        }
        System.out.println(ans / (l.size() + 0.0));
    }

    public static void permutation(String q, String ans){
        if(q.length() <= 1) {
            z.add(ans + q);
         }
         else {
            for (int i = 0; i < q.length(); i++) {
                permutation(q.substring(0, i) + q.substring(i + 1),
                ans + q.charAt(i));
            }
         }
    }
}

Measured memory_bytes: 66076
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> to[N],cost(N),cnt(N),T(N);
	for(int i=0;i<N-1;i++){
		int a,b;
		cin >> a >> b;
		a--;b--;
		cnt[a]++;
		cnt[b]++;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	for(int i=0;i<N;i++)cin >> cost[i];
	int start = 0;
	for(int i=0;i<N;i++){
		if(cnt[start]<cnt[i])start = i;
	}
	sort(ALL(cost),greater<int>());
	queue<int> q;
	q.push(start);
	int num = 0;
	int ans = 0;
	T[start]=cost[num];
	num++;
	while(!q.empty()){
		int now = q.front();
		q.pop();
		for(int i=0;i<to[now].size();i++){
			int next = to[now][i];
			if(T[next]==0){
				T[next] = cost[num];
				ans += cost[num];
				num++;
				q.push(next);
			}
		}
	}
	cout << ans << endl;
	for(auto x:T)cout << x << " ";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n,k;
int main()
{
	cin>>n>>k;
	string s;
	cin>>s;
	char c=s[0];
	for(int i=0;i<n;i++)
	{
		if (!k)
			break;
		if (s[i]!=c)
		{
			k--;
			s[i]=c;
			int r=i;
			while(s[++r]!=c&&r<n)
				s[r]=c;
		}
	}
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		if (s[i]==s[i+1])
			ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
h,w = map(int,input().split())
grid = []
curh = h
curw = w
for i in range(h):
    grid.append(list(input()))
i = 0
while i < curh:
    if grid[i] == ["."]*curw:
        for j in range(i,curh-1):
            grid[j] = grid[j+1]
        grid.pop(curh-1)
        curh -= 1
        i -= 1
    i += 1
i = 0
while i < curw:
    for j in range(curh):
        if grid[j][i] == "#":
            break
    else:
        for j in range(curh):
            for k in range(i,curw-1):
                grid[j][k] = grid[j][k+1]
            grid[j].pop(curw-1)
        curw -= 1
        i -= 1
    i += 1
for i in range(curh):
    print("".join(grid[i]))

Measured memory_bytes: 39920
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC052 D - Walk and Teleport

ll INF = 1e18;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, A, B; cin >> N >> A >> B;
  vector<ll> X(N, 0);
  REPLL(i, N){
    cin >> X[i];
  }
  
  vector<ll> dp(N+1, INF);
  dp[0] = 0;
  dp[1] = 0;
  for(ll i = 1; i < N; i++){
    chmin(dp[i+1], min(dp[i]+(X[i]-X[i-1])*A ,dp[i]+B));
  }
  cout << dp[N] << endl;
}

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

int main ()
{
    int n;
    cin>>n;
    vector<int> button(n);
    vector<bool> loop(n+1,1);

    for (int i=0;i<n;i++)
    {
        cin>> button.at(i);
    }
    
    int count=0,p=1;
    do
    {
        count+=1;
        loop.at(p) = 0;
        p = button.at(p-1);
    }
    while(p!=1&&p!=2&& loop.at(p));

    if (p==1|| !loop.at(p))
    cout<<-1<<endl;
    else
    cout<<count<<endl;  
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int  a;
    cin>>a;
    int b[a],c1=0,c2=0,c4=0;
    for(int i=0;i<a;i++) cin>>b[i];
    for(int i=0;i<a;i++){
        if(b[i]%2!=0){c1++; }
        else if(b[i]%4!=0){c2++; }
        else {c4++; }
    }
    if(c1<=c4+1&&c2==0) cout<<"Yes"<<endl;
    else if(c1<=c4&&c2>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

typedef long long ll;

using namespace std;

const ll MOD = 1e9 + 7;

string s;

ll dp[2][2][2][2][3];
// this -> next
// have 0 on even
// have 0 on odd
// this parity
// this size

int f4(int d)
{
    if (d == 0) return 1;
    if (d == 1) return 2;
    if (d == 2) return 1;
}

int f3(int c, int d)
{
    if (d == 1) return c;
    return c ^ 1;
}

int f2(int a, int b, int c, int d)
{
    if (b == 1) return 1;
    if (a == 0) return 0;
    if (c == 1 && d == 0) return 1;
    return 0;
}

int f1(int a, int c, int d)
{
    if (a == 1) return 1;
    if (c == 0 && d == 0) return 1;
    return 0;
}

void Apply(int d)
{
    if (d == 1)
    {
        for (int a = 0; a < 2; a++)
        {
            for (int b = 0; b < 2; b++)
            {
                for (int c = 0; c < 2; c++)
                {
                    for (int d = 0; d < 3; d++)
                    {
                        dp[1][f1(a, c, d)][f2(a, b, c, d)][f3(c, d)][0] =
                       (dp[1][f1(a, c, d)][f2(a, b, c, d)][f3(c, d)][0] + dp[0][a][b][c][d]) % MOD;
                    }
                }
            }
        }
    }
    else
    {
        for (int a = 0; a < 2; a++) for (int b = 0; b < 2; b++) for (int c = 0; c < 2; c++)
        {
            for (int d = 0; d < 3; d++)
            {
                dp[1][a][b][c][f4(d)] = (dp[1][a][b][c][f4(d)] + dp[0][a][b][c][d]) % MOD;
            }
        }
    }
}

int main()
{
    cin >> s;
    dp[0][0][0][0][0] = 1;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '1') Apply(1);
        if (s[i] == '0') Apply(0);
        if (s[i] == '?') Apply(1), Apply(0);
        for (int a = 0; a < 2; a++) for (int b = 0; b < 2; b++)
        for (int c = 0; c < 2; c++) for (int d = 0; d < 3; d++)
            dp[0][a][b][c][d] = dp[1][a][b][c][d], dp[1][a][b][c][d] = 0;
    }
    Apply(1);
    ll ans = 0;
    for (int c = 0; c < 2; c++) for (int d = 0; d < 3; d++)
        ans = ans + dp[1][1][1][c][d];
    cout << ans % MOD;
}


Measured memory_bytes: 900
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string s;

int main() {
	cin >> s;
	int l = s.length();
	int sum = 0;
	for(int i = 0; i < l; i++) sum += s[i] - '0';
	int p = 1, S = 0;
	for(int i = l - 1; i >= 0; i--) {
		S += (s[i] - '0') * p;
		p *= 10;
	}
	if(S % sum == 0) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int s,ans;
int a[1000000],cnt[1000000];
int main()
{
    cin>>s;
    a[0]=s;
    for(int i=0;i<1000000;i++)
    {
        if(a[i]%2==0)a[i+1]=a[i]/2;
        else a[i+1]=3*a[i]+1;
        cnt[a[i]]++;
        if(cnt[a[i]]==2)
        {
            ans=i+1;
            break;
        }
    }
    cout<<ans<<endl;

}

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define LL long long
#define SZ(X) X.size()
#define pii pair<int,int>
#define ALL(X) X.begin(),X.end()

using namespace std;

LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
LL powmod(LL a, LL b, LL MOD) {LL ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
const int N = 2e5 + 11;
struct uzi
{
	int x, y;
} p[N];
int f[N];
double get(int l, int r) {
	return sqrt((p[l].x - p[r].x) * (p[l].x - p[r].x) + (p[l].y - p[r].y) * (p[l].y - p[r].y));
}
int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	double ans = 0;
	for (int i = 1; i <= n; i++) {
		f[i] = i;
		cin >> p[i].x >> p[i].y;
	}
	int res = 0;
	do {
		++res;
		for (int i = 2; i <= n; i++) {
			ans += get(f[i], f[i - 1]);
		}
	} while (next_permutation(f + 1, f + 1 + n));
	cout << fixed << setprecision(10);
	cout << ans / res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define int ll
#define pb push_back
#define sz(i) (int)(i.size())
#define fi first
#define se second
#define ld long double
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << std::endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 3*1e3 + 10;
// make sure N size is correctttt!!!!!!!!!

int dp[N][N], dp2[N][N];
string s, t;
int n, m;
string tt = "";
int len = 0, ma = 0;
string wow = "";

int solve(int idx1, int idx2){
   if(idx1 >= n){
      return 0;
   }
   else if(idx2 >= m){
      return 0;
   }
   int &ans = dp[idx1][idx2];
   if(ans != -1)
      return ans;
   ans = 0;
   if(s[idx1] == t[idx2]){
      ans = 1 + solve(idx1+1, idx2+1);
   }
   else{
      ans = max(solve(idx1+1, idx2), solve(idx1, idx2+1));
   }
   return ans;
}

void solve2(int idx1, int idx2){
   if(idx1 >= n){
      return ;
   }
   else if(idx2 >= m){
      return ;
   }
   if(s[idx1] == t[idx2]){
      wow += s[idx1];
      solve2(idx1+1, idx2+1);
      return;
   }
   if(dp[idx1+1][idx2] > dp[idx1][idx2+1]){
      solve2(idx1+1, idx2);
      return;
   }
   else{
      solve2(idx1, idx2+1);
      return;
   }
}


int32_t main(){_

   cin>>s>>t;

   memset(dp, -1, sizeof dp);
   
   n = sz(s), m = sz(t);

   solve(0,0);
   solve2(0,0);

   cout<<wow;

   //make sure N size is correct!!!!!!!!!
   return 0;
}
/*
axyb
abyxb
*/

Measured memory_bytes: 72448
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include<list>

int main() {
    int n;
    std::cin >> n;
    std::list<int> a;
    std::vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        std::cin >> v[i];
    }

    int flag = 0;
    for (int i = 0; i < n; i++) {
        if(flag%2==0) {
            a.push_back(v[i]);
        }
        else
        {
            a.push_front(v[i]);
        }

        flag++;
    }

    if(flag%2 == 0) {
       for (auto itr = a.begin(); itr != a.end(); itr++) {
               std::cout << *itr << " ";
       } 
    } else {
        for (auto itr = a.rbegin(); itr != a.rend(); itr++)
        {
            std::cout << *itr << " ";
        }
    }
    std::cout << "\n";
}


Measured memory_bytes: 10372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
  long long as[200010];

int main (){
  int N;
  cin>>N;
  vector<long long>A(N);
  rep(i,N){
    int x;
    cin>>x;
    A[i]=x;
    as[x]++;
  }
  long long sum=0;
  rep(i,200010){
    sum+=(as[i]*(as[i]-1))/2;
  }
  rep(i,N){
    cout<<sum-as[A[i]]+1<<endl;
  }
}


Measured memory_bytes: 4736
/*Filename: aoj0009.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

const int size = 999999 + 1;
bool isPrime[size];
vector<int> prime;

void sieveOfEratosthenes() {
	for (int i = 2; i < size; ++i) {
		isPrime[i] = true;
	}

	int sqrtSize = sqrt(size) + 1;

	for (int i = 2; i < sqrtSize; ++i) {
		if (isPrime[i] == true) {
			for (int j = i * i; j < size; j += i) {
				isPrime[j] = false;
			}
		}
	}

	for (int i = 2; i < size; ++i) {
		if (isPrime[i]) {
			prime.push_back(i);
		}
	}
}

int main() {
	sieveOfEratosthenes();

	int n = 0;

	while (cin >> n) {
		int countPrime = 0;

		for(int i = 0; i < prime.size(); ++i){
			if(prime[i] > n){
				break;
			}
			else{
				++countPrime;
			}
		}

		cout << countPrime << endl;
	}

	return 0;
}

Measured memory_bytes: 2564
#include <iostream>
#include <vector>
#include <functional>

using lint = long long;

int main() {
    std::string s;
    std::cin >> s;

    int n = s.length() + 1;
    std::vector<lint> xs(n, -1);

    std::function<lint(int)> dfs =
        [&](int i) {
            if (xs[i] >= 0) {
                return xs[i];
            }

            auto& ret = xs[i];
            ret = 0;

            if (i > 0 && s[i - 1] == '<') {
                ret = std::max(ret, dfs(i - 1) + 1);
            }
            if (i < n - 1 && s[i] == '>') {
                ret = std::max(ret, dfs(i + 1) + 1);
            }
            return ret;
        };

    lint ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += dfs(i);
    }

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


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll sum=0;
	FOR(i,N) {
		cin>>A[i];
		A[i]*=N;
		sum+=A[i];
	}
	sum/=N;
	int be=0;
	for(i=1;i<N;i++) {
		if(abs(A[i]-sum)<abs(A[be]-sum)) be=i;
	}
	cout<<be<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int M, D;
  cin >> M >> D;
  int a = D / 10;
  int b = D % 10;
  int ans = 0;
  for (int i = 2; i < a; i ++) {
    for (int j = 2; j < 10; j ++) {
      if (i * j <= M) ans ++;
    }
  }
  for (int i = 2; i <= b; i ++) {
    if (a * i <= M) ans ++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256