akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import *
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return

#B
def B():
    k, x = LI()
    ans = []
    for i in range(x - k + 1, x + k):
        ans.append(i)
    print(*ans)
    return

#C
def C():
    n = II()
    d = defaultdict(int)
    for _ in range(n):
        s = S()
        s.sort()
        d[tuple(s)] += 1
    ans = 0
    for i in d.values():
        ans += i * (i - 1) // 2
    print(ans)
    return

#D
def D():
    n, m = LI()
    ab = LIR(n)
    ab.sort(key=lambda x: (x[1], x[0]), reverse=True)
    ans = 0
    for i in range(n):
        if m >= ab[i][0]:
            ans += ab[i][1]
            m -= 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    C()


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, K; cin >> N >> K;
  ll H[N]; rep(i,N) cin >> H[i];
  sort(H,H+N);
  ll result = 0;
  rep(i,N-K) result += H[i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main() {
	int m; cin >> m;
	cout << 48 - m << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[200002][33];
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=1e9+7;
bool cmp(ii x, ii y) {
    return (x.first)*(y.second+1)>y.first*(x.second+1);
}
vector<int> zero;
vector<ii> notzero;
signed main() {
    int n,t,k;
    cin>>n>>t;
    for(int i=0 ; i<n ; i++) {
        int u,v;
        cin>>u>>v;
        if(u==0) zero.push_back(v);
        else notzero.push_back(ii(u,v));
    }
    sort(notzero.begin(),notzero.end(),cmp);
    sort(zero.begin(),zero.end());
    n=notzero.size();
    k=zero.size();
    for(int i=0 ; i<=n ; i++) {
        for(int j=0 ; j<=30 ; j++) {
            dp[i][j]=inf;
        }
    }
    for(int i=0 ; i<=n ; i++) dp[i][0]=0;
    for(int i=1 ; i<=n ; i++) {
        for(int j=1 ; j<=min(n,30ll) ; j++) {
            if(i==j) {
                dp[i][j]=min(inf,dp[i-1][j-1]+1+notzero[i-1].first*(dp[i-1][j-1]+1)+notzero[i-1].second);
            }
            else {
                dp[i][j]=min({inf,dp[i-1][j],dp[i-1][j-1]+1+notzero[i-1].first*(dp[i-1][j-1]+1)+notzero[i-1].second});
            }
        }
    }
    int ans=0;
    for(int i=0 ; i<=30 ; i++) {
        if(dp[n][i]<=t) {
            int cnt=i,cur=dp[n][i];
            for(int j=0 ; j<k ; j++) {
                if(cur+zero[j]<t) {
                    cur+=zero[j]+1;
                    cnt++;
                }
            }
            ans=max(ans,cnt);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 55148
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if (A==5 && B==7 && C==5)
        printf("YES");
    else if (A==7 && B==5 && C==5)
        printf("YES");
    else if (A==5 && B==5 && C==7)
        printf("YES");
    else
        printf("NO");
    return 0;
}



Measured memory_bytes: 1656
N,shift = map(int,input().split())
R,S,P=map(int,input().split())
Prediction= input()

def janken_caliculater(s):
    if s == 'r':
        return P
    elif s =='s':
        return R
    else:
        return S

flag = [False]*shift
answer = 0

#processing unit
for i in range(N):
    if i<shift:
        answer+=janken_caliculater(Prediction[i])
    else:
        if Prediction[i] == Prediction[i-shift]:
            if flag[i%shift]:
                answer+=janken_caliculater(Prediction[i])
                flag[i%shift] = False
            else:
                flag[i%shift] = True
        else:
            flag[i%shift] = False
            answer+=janken_caliculater(Prediction[i])


print(answer)


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

const ll mod = 1000000007;
const int N = 5e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int a[N];
char s[N];
void init() {
	mt(a, 0);
}
int main() {
	while(~scanf("%s", s + 1)) {
		init();
		int n = strlen(s + 1);
		rep(i, 1, n + 1) {
			if(s[i] == '<') a[i + 1] = a[i] + 1;
		}
		repd(i, n, 1) {
			if(s[i] == '>') a[i] = max(a[i + 1] + 1, a[i]);
		}
		ll ret = 0;
		rep(i, 1, n + 2) ret += a[i];
		printf("%lld\n", ret);
	}
    return 0;
}


Measured memory_bytes: 2688
def main():
    a, b, c = (int(i) for i in input().split())
    ans = 0
    finite = True
    while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        next_a = b//2 + c//2
        next_b = a//2 + c//2
        next_c = a//2 + b//2
        if next_a == a and next_b == b and next_c == c:
            print(-1)
            finite = False
            break
        ans += 1
        a = next_a
        b = next_b
        c = next_c
    if finite:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x, y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x, y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=pow(10,9)+7;
bool cmp(pair<long double ,int > x, pair<long double , int> y){ return x.F<y.F; }
const ll maxn=2*1e4+5;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }

int main(){ 
    
//    #ifndef ONLINE_JUDGE
//  	freopen("input.txt", "r", stdin);
//    #endif
    
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	ll n,k,s;
	cin>>n>>k>>s;
	
	ll lim=1e9;
	for (int i=0;i<n;i++){
		if (i<k) cout<<s<<" ";
		else{
			if (s<lim){
				cout<<s+1<<" ";
			}
			else cout<<"1"<<" ";
		}
	}
		
	return 0;
}

Measured memory_bytes: 1280
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <queue>

using namespace std;

const int N = 2e6 + 14;
const int INF = 1e9;
const int mod = 1e9;
const int SZ = (1 << 17) - 1;
const int K = 320;

#define eb emplace_back
#define sz(s) (int)(s.size())
#define ppb pop_back

#define ll long long

#define int ll

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (a < b)
		return cout << 1, 0;
	cout << (a / b) + (a % b != 0);
	return 0;
}


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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    set<int> s;
    rep (i, n) {
        int d;
        cin >> d;
        s.insert(d);
    }
    cout << s.size() << endl;
    
    return 0;
}



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

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	bool same = true;
	int sum = 0;
	for(int i = 0; i < n; i++){
		if((a[i] - a[0]) % 2 != 0) same = false;
		sum ^= (a[i] & 1);
	}
	if(same){
		cout << 0 << '\n';
	} else {
		if(sum & 1){
			cout << n-1 << '\n';
		} else {
			cout << n-2 << '\n';			
		}
	}
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
int main(void){
    string s; cin>>s;
    if(s[s.size()-1]=='s'){
        cout<<s<<"es"<<endl;
    }else{
        cout<<s<<'s'<<endl;
    }
    
}


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

using ll = long long;

// 辺の情報
struct edge {
   ll to, cost;
};

const ll INF = 1e18;
ll N, M; // Nはノードの個数、Mは辺の個数
ll dist[1010]; // 最短距離
vector<edge> Graph[2010]; // グラフ

void bellmanFord(int start, ll init) {
   for (int i = 0; i < N; i++) dist[i] = init;

   dist[start] = 0;
   for (int i = 0; i < N-1; i++) {
      for (int from = 0; from < N; from++) {
         if (dist[from] == -INF) continue;
         for (edge e : Graph[from]) {
            dist[e.to] = dist[from] + e.cost;
         }
      }
   }
}

int main() {
   cin >> N >> M;
   for (int i = 0; i < M; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      a--, b--;
      Graph[a].push_back(edge{b, c});
   }

   for (int i = 0; i < N; i++) dist[i] = -INF;
   
   dist[0] = 0;
   for (int i = 0; i < N-1; i++) {
      for (int j = 0; j < N; j++) {
         if (dist[j] == -INF) continue;
         for (edge e : Graph[j]) {
            dist[e.to] = max(dist[e.to], dist[j] + e.cost);
         }
      }
   }
   ll ans1 = dist[N-1];

   for (int i = 0; i < N-1; i++) {
      for (int j = 0; j < N; j++) {
         if (dist[j] == -INF) continue;
         for (edge e : Graph[j]) {
            dist[e.to] = max(dist[e.to], dist[j] + e.cost);
         }
      }
   }
   ll ans2 = dist[N-1];

   if (ans1 != ans2) {
      puts("inf");
   } else {
      cout << ans1 << endl;
   }

   return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include<climits>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
const double pi=acos(-1.0);
#define boost  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define sl(n) scanf("%lld",&n)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define f(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i > (ll)(b); i--)
#define ms(a,b) memset((a),(b),sizeof(a))
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))
#define vec(g1) int temp;cin>>temp;g1,push_back(temp);
#define abs(x) ((x<0)?(-(x)):(x))
#define MAX 1000005
#define inf LLONG_MAX
#define MIN INT_MIN
//typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int mod = 1e9 + 7 ;
ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
// ll fac[200005];
// ll inverse(ll n){return powmod(n, mod-2);}
// ll nCr(ll n, ll r){return (fac[n] * inverse(fac[r]) % mod * inverse(fac[n-r]) % mod) % mod;}

/**.................................................................................................................................*/
ll lcm(ll a, ll b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
int main() {
 
  ll a,b,c,d; cin >> a >>b >> c >> d;
  ll divc = b/c-(a-1)/c;
  ll divd = b/d-(a-1)/d;
  ll res= lcm(c,d);
  ll divcd = b/res-(a-1)/res;
  
  cout  << (b-a+1) - divc - divd + divcd << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
typedef long long ll;
const int INF = 1<<29;
const int N = 1e6 + 9;
ll a[N];
int main()
{
    fio;
    ll a, b, c;
    cin >> a >> b >> c;
    if((a == b && b != c) || (a == c && a != b) || (b == c && a != b)){
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}


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

int main()
{
    string s;cin>>s;
    int k;cin>>k;
    int i,j,h;
    vector<string> a(0);
    int n=s.length();
    for(i=0;i<n;i++)
    {
        for(h=i;h<min(i+k,n);h++)
        {
            string put="";
            for(j=i;j<=h;j++)
            {
                put+=s.at(j);
                a.push_back(put);
            }
        }
    }
    sort(a.begin(),a.end());
    int count=1;
    int nn=a.size();
    i=0;
    while(count<k)
    {
        i++;
        if(a.at(i)!=a.at(i-1))count++;
    }
    cout<<a.at(i)<<endl;
}


Measured memory_bytes: 4344
#!/usr/bin/env python3
import sys
INF = float("inf")


def main():
    s = input()
    t = input()
    T = len(t)

    candidate = []

    for i in range(len(s)-T+1):
        buf = s[i:i+T]
        flag = True
        for b, tc in zip(buf, t):
            if b == "?" or b == tc:
                continue
            else:
                flag = False
                break
        if flag == True:
            candidate.append(i)

    if len(candidate) == 0:
        print("UNRESTORABLE")
    else:
        print((s[:candidate[-1]] + t + s[candidate[-1]+T:]).replace("?", "a"))

    pass


if __name__ == '__main__':
    main()


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

int main(){
    double x[4],y[4];
    while(cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3]){
        double a[3],b[3],c[3],d[3];
        for(int i=0;i<3;i++){
            a[i]=x[(i+1)%3]-x[i];
            b[i]=y[(i+1)%3]-y[i];
        }
        for(int i=0;i<3;i++){
            c[i]=x[3]-x[i];
            d[i]=y[3]-y[i];
        }
        int suc=1;
        for(int i=0;i<3;i++){
            
            if((a[i]*b[(i+1)%3]-a[(i+1)%3]*b[i])*(a[i]*d[(i+1)%3]-c[(i+1)%3]*b[i])<0){
                suc=0;
                break;
            }
        }
        if(suc==0)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
}

Measured memory_bytes: 1216
import copy
import itertools
import sys

if sys.version[0] == '2':
    range, input = xrange, raw_input

drc = [(-1, 0), (0, 1), (1, 0), (0, -1)]
C_NUM = 6


def dfs(r, c, now_c, next_c):
    tmp_board[r][c] = next_c
    for dr, dc in drc:
        nr, nc = r + dr, c + dc
        if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == now_c:
            dfs(nr, nc, now_c, next_c)


while True:
    H, W, C = map(int, input().split())
    if not (H | W | C):
        break
    board = [[int(x) - 1 for x in input().split()] for _ in range(H)]
    ans = 0
    for ope in itertools.product(range(C_NUM), repeat=4):
        if ope[0] == board[0][0] or ope[-1] == C - 1 or any(ope[i] == ope[i + 1] for i in range(3)):
            continue
        tmp_board = copy.deepcopy(board)
        for color in ope:
            dfs(0, 0, tmp_board[0][0], color)
        dfs(0, 0, tmp_board[0][0], C - 1)
        dfs(0, 0, tmp_board[0][0], -1)
        cand = sum(row.count(-1) for row in tmp_board)
        if cand > ans:
            ans = cand
    print(ans)

Measured memory_bytes: 8156
n = int(input())
sp = []
for i in range(n):
    s,p = map(str,input().split())
    sp.append([s,int(p),i+1])

sp.sort(key=lambda x:x[1],reverse = True)
sp.sort(key=lambda x:x[0])

for e in sp:
    print(e[2])

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    string ans;
    while (true){
        C -= B;
        if (C <= 0){ans = "Yes"; break;}
        A -= D;
        if (A <= 0){ans = "No"; break;}
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3656
import bisect
a = []
for pw in range(2,1001):
    for x in range(1,1001):
        nw = x**pw
        if nw > 1000:
            break
        a.append(nw)
a = sorted(a)
x = int(input())
y = bisect.bisect_right(a,x)
print(a[y-1])        


Measured memory_bytes: 3060
use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

fn solve(n: i64, x: i64, m: i64) -> i64 {
    let mut seq = vec![];
    let mut index = vec![None; 1e5 as usize + 10];
    let mut sum_at = vec![0; 1e5 as usize + 10];

    let mut num = x;
    let mut sum = 0;

    while index[num as usize].is_none() && seq.len() < n as usize {
        index[num as usize] = Some(seq.len());
        sum_at[num as usize] = sum;

        sum += num;
        seq.push(num);
        num = (num * num) % m;
    }

    if seq.len() == n as usize {
        return sum;
    }

    let left = n as usize - seq.len();
    let len = seq.len() - index[num as usize].unwrap();
    let chunk_sum = sum - sum_at[num as usize];

    let whole = left / len;
    sum += chunk_sum * whole as i64;

    let left = left % len;
    for _ in 0..left {
        sum += num;
        num = (num * num) % m;
    }

    sum
}

fn main() {
    let mut reader = TokenReader::new();
    let n = reader.next();
    let x = reader.next();
    let m = reader.next();

    let res = solve(n, x, m);
    println!("{}", res);
}


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


using namespace std ; 

int n ; 

int main(){
        ios_base::sync_with_stdio(0) ; 
        cin.tie(0) ;
        //freopen("in.in" , "r" , stdin) ; 
        long long x ; 
        cin>>x ; 
        map<long long , int> fac ; 
        for(long long  i =2 ;i*i<=x ;i ++)
        {               
                while(x%i==0){
                        x/=i ; 
                        fac[i]++;
                }
        }
        if(x > 1){
                fac[x]++ ; 
        }
        long long ans = 0; 
        for(auto u : fac){
                int v = u.second ; 
                for(int i = 1 ; ; i++){
                        if(v>=i){
                                ans++ ; 
                                v-=i ; 
                        }
                        else break ;
                }
        }
        cout<< ans ; 
        return 0 ; 
}

Measured memory_bytes: 3664
N = int(input())
S = input()
rcnt = S.count('R')
gcnt = S.count('G')
bcnt = S.count('B')
ans = rcnt * gcnt * bcnt

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == S[j]:
            continue
        if j + (j - i) >= N:
            break
        if S[i] != S[j] and S[j] != S[j + (j - i)] and S[i] != S[j + (j - i)]:
            ans -= 1
print(ans)

Measured memory_bytes: 67988
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
mod =10**9 +7
ans =0
if N ==1:
    ans =0
elif N ==2:
    ans =2
else:
    ans =(10**N -9**N -9**N +8**N ) %mod
print(ans)

Measured memory_bytes: 11104
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	int small=0,big=0,zhong=0;
	scanf("%d %d %d",&n,&a,&b);
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(x<=a)
		    small++;
		else if(x>=(b+1))
		    big++;
		else
		    zhong++;
	}
	printf("%d\n",min(zhong,min(small,big)));
	return 0;
}


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

int main(){
  int n,a[4][13]={},b;
  string c;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c>>b;
    if(c=="S") a[0][b-1]=true;
    else if(c=="H") a[1][b-1]=true;
    else if(c=="C") a[2][b-1]=true;
    else if(c=="D") a[3][b-1]=true;
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<13;j++){
      if(a[i][j]==false){
	if(i==0) cout<<'S'<<" "<<j+1<<endl;
	else if(i==1) cout<<'H'<<" "<<j+1<<endl;
	else if(i==2) cout<<'C'<<" "<<j+1<<endl;
	else if(i==3) cout<<'D'<<" "<<j+1<<endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3068
#include <cstdio>
#include <algorithm>
using namespace std;
char s[101], t[101];
int main() {
    int n;
    scanf("%d %s %s", &n, s, t);
    for(int i = 0; i <= n; i++) {
        if(equal(t, t + n - i, s + i)) {
            printf("%d\n", n + i);
            return 0;
        }
    }
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    while(1){
        char ch;scanf("%c",&ch);
        if('a'<=ch&&ch<='z') ch-=32;
        else if('A'<=ch&&ch<='Z') ch+=32;
        printf("%c",ch);
        if(ch=='\n') break;
    }
}


Measured memory_bytes: 3140
S = list(input())
S1 = S[0] + S[1]
S2 = S[2] + S[3]
S1 = int(S1)
S2 = int(S2)

if 1 <= S1 <= 12 and 1 <= S2 <= 12:
  print('AMBIGUOUS')
elif (1 > S1 or S1 > 12) and 1 <= S2 <= 12:
  print('YYMM')
elif (1 > S2 or S2 > 12) and 1 <= S1 <= 12:
  print('MMYY')
else:
  print('NA')


Measured memory_bytes: 8924
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

/****
 * N-K個赤が並んでいると考えて
 * 赤ボールの愛だと左端、右端の中からi箇所選んで青いボールをK個置くので
 * n-k+1 C i通りある
 * 青のボールを隙間に何個づつ割り当てるかは
 * それぞれ１個以上必要なためk-1Ci-1
 * これは組み合わせ問題のためn-k+1Ci×k-1Ci-1
 ****/
ll MOD = (1000000000+7);
const ll N = 500001;
long long fact[N];
long long invfact[N];

long long Inv(long long a) {
        long long res = 1;
        long long n = MOD - 2;
        while (n > 0) {
                if (n & 1) res = res * a % MOD;
                a = a * a % MOD;
                n >>= 1;
        }
        return res;
}

void init() {
        fact[0] = fact[1] = 1;
        for (int i = 2; i < N; i ++) fact[i] = fact[i - 1] * i % MOD;
        invfact[0] = invfact[1] = 1;
        for (int i = 2; i < N; i ++) invfact[i] = invfact[i - 1] * Inv(i) % MOD;
}

ll power(ll x, ll y){
    if(y == 0) {return 1;}
    else if (y == 1) {return x % MOD;}
    else if (y % 2 == 0) {return power(x, y/2)*power(x, y/2) % MOD;}
    else {return power(x, y/2)*power(x, y/2) * x % MOD;}
}

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

ll div(ll x,ll y){
    return mult(x, power(y, MOD-2));
}

ll kaijo(ll n){
    ll total = 1;
    for(ll i = 1;i <= n;++i){
        total = mult(total, i);
    } 
    return total;
}

ll COM(ll n, ll k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fact[n] * (invfact[k] * invfact[n-k] % MOD) % MOD;
}


int main() {
    ll n,k;
    init();
    scanf("%lld %lld", &n, &k);
    for(ll i = 1;i <= k;++i){
        ll c1, c2;
        c1 = COM(n-k+1, i);
        c2 = COM(k-1, i-1);
        printf("%lld\n",mult(c1, c2));
    }
    return 0;
}




Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
bool isperfect(ll n){
    ll y=sqrt(n);
    if(n%y==0&&y*y==n)return true;
    return false;
}
bool comp(pair<ll,ll> a,pair<ll,ll> b){
    return a.second<b.second;
}
ll powi(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1)ans=ans*a;
        b=(b>>1);
        a=a*a;
    }
    return ans;
}

int main() {
  int n;
  cin>>n;
  vil v(n);
  map<ll,ll> m;
  loop(0,n){
      cin>>v[i];
     // m[v[i]]++;
  }
  ll ans=0;
  loop(0,n){
      ll x=v[i]-i;
      ans+=m[x];
      m[-(i+v[i])]++;
  }
  cout<<ans;
}



Measured memory_bytes: 27388
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int R(int a, int b){return rand()%(b-a+1)+a;}

const int MXD = 400;
int contest[MXD];
int s[MXD][28];
int c[28];

int last[28];
set<int> when[28];
int D;
int sc;
void random_sol()
  {
  FOR(i, 1, D)contest[i] = R(1, 26);
  }
void get_score()
  {
  sc = 0;

  FOR(i, 1, D)
    {
    sc += s[i][contest[i]];
    last[contest[i]] = i;
    FOR(j, 1, 26)
      sc -= c[j] * (i - last[j]);

    when[contest[i]].insert(i);
    }
  }
void zachlan()
  {
  sc = 0;

  FOR(i, 1, D)
    {
    int best = -1;
    int best_val = -1e9;

    int minus = 0;

    FOR(j, 1, 26)
      {
      int cand = s[i][j] + c[j] * (i - last[j]);
      minus += c[j] * (i - last[j]);
      if(cand > best_val)
        {
        best_val = cand;
        best = j;
        }
      }
    contest[i] = best;

    when[contest[i]].insert(i);
    sc += best_val - minus;
    last[contest[i]] = i;
    }
  }

int main()
  {
  cin >> D;

  FOR(i, 1, 26)scanf("%d", &c[i]);
  FOR(i, 1, D)
    {
    FOR(j, 1, 26)scanf("%d", &s[i][j]);
    }

  zachlan();
  

  debug(I(sc));
  FOR(i, 1, D)cout << contest[i] << endl;
  }


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

int main() {
  int n;
  bool y = false;
  cin >> n;  
  for (int i = 0; i < n; i++) {    
  	string s;
    cin >> s;
	if( s[0] == 'Y' ) {
      y = true;
      break;
    }
  }
  if( y ) {
  	cout << "Four" << endl;
  } else {
  	cout << "Three" << endl;
  }  
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let _n: usize = input();
    let m: usize = input();
    let lr: Vec<(i32, i32)> = (0..m).map(|_| (input(), input())).collect();

    let mut lmax = 0;
    let mut rmin = i32::max_value();
    for (l, r) in lr {
        lmax = std::cmp::max(lmax, l);
        rmin = std::cmp::min(rmin, r);
    }
    println!("{}", std::cmp::max(0, rmin - lmax + 1));
}


Measured memory_bytes: 4352
#coding:utf-8
import numpy as np
c = []
c.append (list(map(int, input().split())))
c.append (list(map(int, input().split())))
c.append (list(map(int, input().split())))
c = np.array(c)
if np.sum(c)/3 == c[0][0]+c[1][1]+c[2][2]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 21404
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//こんなクソコードを生み出してしまうなんて趣味は罪ね

const int mod = 1e9 + 7;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

const ull ma = (1ull << 52) - 1;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;
	ull AB[200001];
	int a0 = 0, b0 = 0;
	int ab00 = 0;
	int n = 0;
	rep(i, N) {
		ll a, b;
		cin >> a >> b;

		if (a == 0 && b == 0) {
			ab00++;
			continue;
		}
		if (a == 0) {
			a0++;
			continue;
		}
		if (b == 0) {
			b0++;
			continue;
		}

		if (a < 0) {
			a = -a;
			b = -b;
		}
		bool p = (b > 0);
		if (!p) {
			b = -b;
			swap(a, b);
		}

		ull tmp = 0;
		rep(i, 3) {
			tmp *= 3;
			if (b) {
				int k = __builtin_clzll(a) - __builtin_clzll(b);
				if (k > 0) a <<= k;
				else b <<= -k;
				if (a > b) {
					b <<= 1;
					k--;
				}
				double d = double(b) / a;
				ull tmp1 = *(ull*)& d;
				ull c = tmp1 & ma | (1ull << 52);
				lll sa = (lll(b) << 52) - lll(a) * c;
				while (sa >= 0) {
					sa -= a;
					c++;
				}
				while (sa < 0) {
					sa += a;
					c--;
				}
				tmp += ull(k + 63) << 53 | c;
				b = sa;
			}
		}

		if (p) AB[n++] = tmp << 1 | 1ull;
		else AB[n++] = tmp << 1;
	}
	sort(AB, AB + n);

	ll kotae = 1;
	ull mae = AB[0] >> 1;
	int k1 = 0, k2 = 0;
	rep(i, n) {
		if (mae != AB[i] >> 1) {
			kotae = kotae * (modpow(2, k1) + modpow(2, k2) - 1) % mod;
			k1 = 0;
			k2 = 0;
			mae = AB[i] >> 1;
		}
		if (AB[i] & 1ull) k1++;
		else k2++;
	}
	kotae = kotae * (modpow(2, k1) + modpow(2, k2) - 1) % mod;

	kotae = kotae * (modpow(2, a0) + modpow(2, b0) - 1) % mod;

	co((kotae - 1 + ab00 + 2 * mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 5092
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
 
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
 
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
 
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;
 
const int INF = MOD;
 
int n,m,q;
vector<pii> g[125252];             // グラフ
int depth[125252];        // 根付き木の深さ
int par[125252];
int query[125252];

int data[125252];
int init(){
  REP(i,125252)data[i]=-1;
}
int root(int x){
  return data[x]<0?x:data[x]=root(data[x]);
}
void unite(int a,int b){
  a=root(a);b=root(b);
  if(a!=b){
    if(data[a]>data[b])swap(a,b);
    data[a] += data[b];
    data[b] = a;
  }
}
int size(int x){
  return -data[root(x)];
}
 
int main(){
  scanf("%d%d",&n,&m);
  ll ans = 0;
  {
    set< pair<int,pii> > S;
    init();
    REP(i,m){
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      --a;
      --b;
      S.insert(make_pair(c,pii(a,b)));
    }
    while(size(0)!=n){
      pair<int,pii> P = *S.begin(); S.erase(S.begin());
      int c = P.first;
      int a = P.second.first;
      int b = P.second.second;
      if(root(a)!=root(b)){
        unite(a,b);
        g[a].push_back(pii(b,c));
        g[b].push_back(pii(a,c));
        ans += c;
      }
    }
  }

  queue<int> Q;

  REP(i,n) depth[i]=INF;
  depth[0] = 0;
  Q.push(0);
  while(!Q.empty()){
    int pos = Q.front(); Q.pop();
    int d = depth[pos];
    REP(i,g[pos].size()){
      int to = g[pos][i].first;
      int c = -g[pos][i].second;
      if(depth[to]!=INF)continue;
      depth[to] = d+1;
      par[to] = pos;
      Q.push(to);
      query[to] = c;
    }
  }
  scanf("%d",&q);
 
  while(q--){
    int s,t;
    scanf("%d%d",&s,&t);
    --s; --t;
    ll x = INF;

    int a,b;
    a = s;
    b = t;
    if(depth[a]>depth[b])swap(a,b);
    while(depth[b]!=depth[a]){
      CHMIN(x,(ll)query[b]);
      b = par[b];
    }
    while(par[a]!=par[b]){
      CHMIN(x,(ll)query[a]);
      CHMIN(x,(ll)query[b]);
      a=par[a];b=par[b];
    }
    if(a!=b){
      CHMIN(x,(ll)query[a]);
      CHMIN(x,(ll)query[b]);
    }
    printf("%lld\n",ans+x);
  }
  return 0;
}


Measured memory_bytes: 29952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

struct UnionFind
{
	vector<ll> par;

	UnionFind(ll N = 20001) : par(N)
	{
		for (ll i = 0; i < N; ++i) par[i] = i;
	}

	ll root(ll x)
	{
		if (par[x] == x) return x;
		else return par[x] = root(par[x]);
	}

	void unite(ll x, ll y)
	{
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		else par[rx] = ry;
	}

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

int main(int argc, char **argv)
{
	ll n, m; cin >> n >> m;
	vector<ll> p(n);
	for (ll i = 0; i < n; ++i) cin >> p[i], --p[i];

	UnionFind tree(n);
	
	for (ll i = 0; i < m; ++i)
	{
		ll a, b; cin >> a >> b;
		--a, --b;
		tree.unite(a, b);
	}

	ll cnt{0};
	for (ll i = 0; i < n; ++i)
	{
		if (tree.same(i, p[i]))
			++cnt;
	}
	std::cout << cnt << std::endl;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const ll MOD = 1000000007;
const int MN = 100010;

int acc[MN];
ll dp[MN];
int nx[MN][3];

int main() {
	string s; cin >> s;
	int n = s.size();

	rep(i, n) {
		acc[i + 1] = (acc[i] + (s[i] != 'a') + 1) % 3;
	}

	rep(j, 3) nx[n][j] = n + 1;

	for (int i = n; i >= 1; --i) {
		rep(j, 3) {
			nx[i-1][j] = nx[i][j];
		}
		nx[i-1][acc[i]] = i;
	}

	bool alt = true;
	rep(i, n-1) {
		if (s[i] == s[i+1]) {
			alt = false;
		}
	}

	if (alt) {
		puts("1");
		return 0;
	}

	dp[0] = 1;

	rep(i, n) {
		for (int c = 1; c <= 2; ++c) {
			int m = (acc[i] + c) % 3;
			if (nx[i][m] <= n) {
				int p = nx[i][m];
				dp[p] = (dp[p] + dp[i]) % MOD;
			}
		}
	}

	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (acc[n] == acc[i]) {
			ans = (ans + dp[i]) % MOD;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int cnt = 0;
  for(int i=1;i<S.size();++i){
    if(S.at(i-1)==S.at(i)){
      if(S.at(i)=='0'){
        S.at(i) = '1';
        ++cnt;
      }else{
        S.at(i) = '0';
        ++cnt;
      }
    }
  }
  cout << cnt;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main()
{
    cin>>a>>b>>c>>d;
    if(a+b>c+d)puts("Left");
    else if(a+b==c+d)puts("Balanced");
    else if(a+b<c+d)puts("Right");
    return 0;
}

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

struct Edge {
    int src, dst, cost, color;
    Edge(int s,int d,int c=1,int co=0) : src(s), dst(d), cost(c), color(co){}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

struct Query {
    int color, cost, qid, d;
    Query(int co, int c, int q, int d) : color(co), cost(c), qid(q), d(d) {}
};

template<typename T>
struct LCA {
    vector<T> cost;
    vector<int> depth;
    vector<vector<int>> par;
    Graph g;
    int logn;

    LCA(int n, Graph g) : cost(n), depth(n), g(g) {
        logn = 0;
        while((1<<logn) < n) ++logn;

        par.assign(n+1, vector<int>(logn, n));
        dfs(0, -1, 0, 0);

        for(int i = 0; i < logn-1; ++i) {
            for(int v = 0; v < n; ++v) {
                par[v][i+1] = par[par[v][i]][i];
            }
        }
    }

    void dfs(int v, int p, int d, T c) {
        if(p != -1) par[v][0] = p;
        depth[v] = d;
        cost[v] = c;

        for(Edge e : g[v]) {
            if(e.dst == p) continue;
            dfs(e.dst, v, d+1, cost[v] + e.cost);
        }
    }

    int get_lca(int x, int y) {
        if(depth[x] > depth[y]) swap(x, y);

        for(int i = logn-1; i >= 0; --i) {
            if(((depth[y] - depth[x])>>i) & 1) y = par[y][i];
        }
        if(x == y) return y;

        for(int i = logn-1; i >= 0; --i) {
            int nx = par[x][i], ny = par[y][i];
            if(nx != ny) x = nx, y = ny; 
        }
        return par[y][0];
    }

    T get_length(int x, int y) {
        int z = get_lca(x, y);
        return cost[x] + cost[y] - cost[z] * 2;
    }
};

Graph g;
vector<Query> qs[100010];
long sum[100010], cnt[100010], ans[100010];

int N, Q, a, b, c, d;

void solve(int v, int p) {
    for(Query q : qs[v]) {
        long x = -sum[q.color];
        x += (long)q.cost * cnt[q.color];
        ans[q.qid] += x*q.d;
    }

    for(Edge e : g[v]) {
        if(e.dst == p) continue;
        sum[e.color] += e.cost; ++cnt[e.color];
        solve(e.dst, v);
        sum[e.color] -= e.cost; --cnt[e.color];
    }
}

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

    g.resize(N);
    for(int i = 0; i < N-1; ++i) {
        cin >> a >> b >> c >> d;
        --a, --b;
        g[a].emplace_back(a, b, d, c);
        g[b].emplace_back(b, a, d, c);
    }

    LCA<long> lca(N, g);

    for(int i = 0; i < Q; ++i) {
        cin >> a >> b >> c >> d;
        --c, --d;
        qs[c].emplace_back(a, b, i, 1);
        qs[d].emplace_back(a, b, i, 1);
        qs[lca.get_lca(c,d)].emplace_back(a, b, i, -2);
        ans[i] = lca.get_length(c, d);
    }
    solve(0, -1);

    for(int i = 0; i < Q; ++i) cout << ans[i] << '\n';
    return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> A(h);
    for (auto &a: A)
        cin >> a;
    
    int cnt = 0;
    for (const auto &a: A)
        cnt += count(a.begin(), a.end(), '#');

    puts(cnt == h + w - 1 ? "Possible" : "Impossible");
}

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

int main() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  for (auto &&w : h) {
    cin >> w;
  }

  int ans = 1;
  int x = abs((1000 * (a - t) + h[0] * 6)), y;
  for (int i = 0; i < n; i++) {

    y = abs(1000 * (a - t) + h[i] * 6);
    if (y < x) {
      ans = i + 1;
      x = y;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int N= Integer.parseInt(s);

        s = sc.nextLine();
        String[] array = s.split(" ");

        int D= Integer.parseInt(array[0]);
        int X= Integer.parseInt(array[1]);//SUM


        for (int i = 0; i < N; i++) {
        	s = sc.nextLine();
        	int a= Integer.parseInt(s);

        	for(int k=0;;k++) {
        		if(a*k > D-1) {
        			X+=k;
        			break;
        		}
        	}
        }

        System.out.println(X);

	}

}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
	long long n,ba=0,bz;
	cin>>n;
	for(long long t=2;t*t<=n;t++)
	{
		if(n%t==0)
		{
		    while(n%t==0)
		    {
		    	//cout<<t<<" ";
		    	a[ba]++; 	
		        n/=t;
			}
			ba++;
		}
	}
	if(n!=1)
	{
		ba++;
		a[ba-1]=1;
		//cout<<n<<" ";
	}
	//cout<<ba<<endl;
	bz=ba;
	for(int t=0;t<bz;t++)
	{
		int l=0;
	    while(a[t]>=0)
	    {
	    	//cout<<"l="<<l<<" t="<<t<<" a[t]="<<a[t]<<" ";
	    	l++;
	    	a[t]-=l;
		}
		ba+=l-2;
		//cout<<"ba="<<ba<<endl;
	}
	cout<<ba; 
	return 0;
}

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

bool second_compare(pair<int, int> a, pair<int, int> b) {
    if (a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> bridge(M, pair<int, int>());
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        bridge[i] = {a, b};
    }
    sort(bridge.begin(), bridge.end(), second_compare);
    int cnt= 0;
    int r = bridge[0].second;
    for (int i = 0; i < M; i++) {
        if (bridge[i].first >= r) {
            cnt++;
            r = bridge[i].second;
        }
    }
    cout << cnt+1 << "\n";
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int N, H;
  cin >> N >> H;
  vector<int> a(N), b(N);
  rep(i, 0, N) { cin >> a[i] >> b[i]; }
  sort(all(a));
  sort(all(b));
  int ans = 0;
  int i = N - 1;
  while (H) {
    if (i >= 0 and a[N - 1] < b[i])
      H = max(0ll, H - b[i--]);
    else {
      ans += (H + a[N - 1] - 1) / a[N - 1];
      break;
    }
    ans++;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  int m,f = 0;
  long long a,b = 0;
  for (int i = 0; i < n; i++) {
    m = 0;
    for (int j = 0; j < n; j++) {
      if (vec.at(j) > m) {
        m = vec.at(j);
        f = j;
      }
    }
    vec.at(f) = 0;
    if (i % 2 == 0) {
      a += m;
    } else {
      b += m;
    }
  }
  int ans = abs(a - b);
  cout << ans << endl;
}

Measured memory_bytes: 3564
import sys

n = int(sys.stdin.readline())

arr = [[]] * 3
dp = [0] * 3

for i in range(n):
    arr = list(map(int, sys.stdin.readline().split()))
    new_dp = [0] * 3
    for j in range(3):

        for k in range(3):

            if j != k:

                new_dp[k] = max(new_dp[k], dp[j] + arr[k])
    dp = new_dp

print(max(dp))

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

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

  int count = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) != T.at(i)) count++; 
  }
  cout << count << endl;
}

Measured memory_bytes: 3860
N,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
#A=[[i[1],i[0]] for i in A]
#A.sort()
#print(A)
dp=[[0 for j in range(W+1)] for i in range(N)]

for i in range(N):
    for j in range(W+1):
        if i==0:
            if j-A[0][1]>=0:
                dp[i][j]=dp[i][j-A[0][1]]+A[0][0]
        else:
            if j-A[i][1]<0:
                dp[i][j]=dp[i-1][j]
            else:
                dp[i][j]=max(dp[i-1][j],dp[i][j-A[i][1]]+A[i][0])
    #print(dp[i])

print(dp[N-1][W])


Measured memory_bytes: 16016