akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;

ll keta(ll n)
{
  ll k = 0;
  while(n != 0)
  {
    n /= 10;
    k++;
  }
  return k;
}  

ll ll_pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
  return ret;
}  

int main() 
{
  ll S; cin>>S;
  ll K=keta(S)-1;
  ll sum=0;
  ll kijun=10;
  rep(i,1<<K)
  {
    ll S2=S;
    ll i2=i;
    rep(j,K)
    {
      if(i2&1)
      {
        sum+=S2%kijun;
        S2/=kijun;
        kijun=1;
      }
      //cout<<sum<<endl;
      i2>>=1;
      kijun*=10;
    }
    sum+=S2;
    kijun=10;
    //cout<<sum<<endl;
  }  
  cout<<sum<<endl;
  return 0;
}

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

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

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

const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

/***************************************************************************/

int F[26];

int main() {

	boost;
	int n; cin>>n;
	string s; cin>>s;
	for(auto &it : s) {
		F[it-'a']++;
	}
	ll ans = 1;
	for(int i=0; i<26; i++) {
		ans = (ans * (F[i]+1)) % MOD;
	}
	ans--;
	if(ans < 0) ans += MOD;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
   int a,b;scanf("%2d%2d",&a,&b);
   if((a>12 || a==0 )&& b>0 && b<=12)cout <<"YYMM";
   else if(a>0&&a<=12&&(b>12 ||b==0))cout <<"MMYY";
   else if(a>0&&b<=12&&a<=12&&b>0)cout<<"AMBIGUOUS";
   else if(a>12&&b>12 || a==0&&b==0)cout<<"NA";
   else cout <<"NA";
}

Measured memory_bytes: 256
#include <iostream>
    using namespace std;
    
    int main() {
        int N; cin >> N;
        int A[N];
        for (int i = 0; i < N; ++i) cin >> A[i];
        
        int count = 0;
        for (int i = 0; i < N-1; ++i) {
            int min = i;
            for (int j = i + 1; j < N; ++j) {
                if (A[j] < A[min]) min = j;
            }
            if (i != min) {
                swap(A[i], A[min]);
                ++count;
            }
        }
        for (int i = 0; i < N; ++i) {
            if (i > 0) cout << " ";
            cout << A[i];
        }
        cout << endl;
        cout << count << endl;
        return 0;
    }


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		for(int j=i;j<s.size();j++)
		{
			bool yes=1;
			for(int n=i;n<=j;n++)
			if(s[n]!='A'&&s[n]!='C'&&s[n]!='G'&&s[n]!='T')
			yes=0;
			if(yes)
			ans=max(ans,j-i+1);
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b[105],c,d;
int main(){
	cin>>a;
	for(int i=1;i<=a;i++) cin>>b[i],b[i]*=-1,c+=b[i];
	sort(b+1,b+a+1);
	for(int i=1;i<=a/2;i++)
	d+=b[i*2];
	cout<<2*d-c<<endl;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const llint mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
//I hate math.
int main(void){
	bool prime[100004]={};
	int imos[100004]={};
	int i,j;
	for(i=2;i<=100000;i++){prime[i]=true;}
	for(i=2;i<=100000;i++){
		if(prime[i]){
			for(j=i+i;j<=100000;j+=i){prime[j]=false;}
		}
	}
	for(i=1;i<=100000;i++){
		imos[i]=imos[i-1];
		if(prime[i]&&prime[(i+1)/2]){imos[i]++;}
	}
	int q;cin>>q;
	while(q--){
		int l,r;cin>>l>>r;
		cout<<imos[r]-imos[l-1]<<endl;
	}
	RE;
}

Measured memory_bytes: 1784
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
int a,b,h;
int main()
{
scanf("%d%d%d",&a,&b,&h);
printf("%d\n",(a+b)*h/2);
return 0;
}


Measured memory_bytes: 256
void main(){
	
	//auto NM = readLine!long();
	if( readStr() == "ABC" ){
		writeln("ARC");
	} else {
		writeln("ABC");
	}
}



import std;

string readStr(){
	return readln().chomp();
}
T[] readLine( T = long )(){
	return readln().split().to!(T[])();
}

Measured memory_bytes: 3592
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
int n,x,num[1000005],ok=1,g;
int main()
{
	cin>>n;
	for(int i=0;i<n;++i)
	{
		scanf("%d",&x);
		++num[x];
		g=gcd(x,g);
	}
	for(int i=2;i<=1000000;++i)
	{
		int tot=0;
		for(int j=i;j<=1000000;j+=i)
		 tot+=num[j];
		if(tot>1){ok=0;break;}
	}
	if(ok) cout<<"pairwise coprime";
	else if(g==1) cout<<"setwise coprime";
	else cout<<"not coprime";
	return 0;
}

Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll factorial(ll a){return a < 2 ? 1 : factorial(a - 1) * a;}
ll summation(ll a){return a < 1 ? 0 : (a * a + a) / 2;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const string ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//ll dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
ll n, m, x, y, z, w, h;
string s, t;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> x >> y){
        ll ans = abs(abs(x) - abs(y)), tmp = 0, cnt = 0, mx = -INF, mn = INF;
        ll a[] = {}, b[] = {}, c[] = {};
        vll v;
        print(ans ? (x == 0 ? (y > 0 ? ans : ans + 1) : (y == 0 ? (x < 0 ? ans : ans + 1) : (x > y ? (x > 0 == y > 0 ? ans + 2 : ans + 1) : (x > 0 != y > 0 ? ans + 1 : ans)))) : (x == y ? 0 : 1));
    }
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m, q;
	cin >>n >>m >>q;
	vector<VI> b(q, VI(4));
	rep(i, q){
		cin >>b[i][0] >>b[i][1] >>b[i][2] >>b[i][3];
		b[i][0]--; b[i][1]--;
	}
	
	VI sq(n+m-1, 9);
	rep(i, n) sq[i] =1;
	ll ans = 0;
	do {
		VI v; int zct= 0;
		rep(i, n+m-1){ if(sq[i]==1) v.push_back(zct); else zct++;}
		ll sm = 0;
		for(auto& x: b){
			if(v[x[1]] - v[x[0]] == x[2]) sm += x[3];
		}
		ans = max(ans, sm);
	} while ( next_permutation(all(sq)) );

	cout <<ans <<"\n";
	return 0;
}


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

int m, d, ans;
int main() {
    cin >> m >> d;
    for (int i = 22; i <= d; i++) {
        if (i % 10 < 2) {
            continue;
        }
        int k = (i / 10) * (i % 10);
        if (k <= m) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

//#define mod      1e9+7
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
long long mod=1e9+7;
ll binpow(int a,int b){
	ll ans=1;
	while(b--){
		ans*=a;
		if(ans>=mod)
			ans%=mod;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n,num;
	cin>>n;
	map<int,int> mp;
	for(int i=0;i<n;i++){
		cin>>num;
		mp[num]++;
	}
	if(n&1 && mp[0]!=1){
		cout<<"0\n";
		return 0;
	}
	if(n%2==0 && mp[0]!=0){
		cout<<"0\n";
		return 0;
	}
	if(n&1){
		for(int i=2;i<n;i+=2){
			if(mp[i]!=2){
				cout<<"0\n";
				return 0;
			}
		}
	}
	if(n%2==0){
		for(int i=1;i<n;i+=2){
			if(mp[i]!=2){
				cout<<"0\n";
				return 0;
			}
		}
	}
	ll ans=binpow(2,n/2);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    i64 v;
    cin >> n >> v;
    akari<i64> as(n), bs(n), cs(n), ds(n);
    for (int i = 0; i < n; i++)
        cin >> as[i];
    for (int i = 0; i < n; i++)
        cin >> bs[i];
    for (int i = 0; i < n; i++)
        cin >> cs[i];
    for (int i = 0; i < n; i++)
        cin >> ds[i];
    map<i64, i64> mp[2];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            mp[0][as[i] + bs[j]]++;
        }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            mp[1][cs[i] + ds[j]]++;
        }
    i64 ans = 0;
    for (auto &p : mp[0])
    {
        ans += mp[1][v - p.first] * p.second;
    }
    cout << ans << endl;
}

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



Measured memory_bytes: 190524
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int m[4] = {0, 100000, 200000, 300000};
  int X, Y;
  cin >> X >> Y;
  cout << m[max(0, 4 - X)] + m[max(0, 4 - Y)] + (int)(X == 1 && Y == 1)*400000 << endl;
  return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;
// const ll MOD = 1000000007;


int main() {
    ll n,d,a;
    scanf("%lld %lld %lld",&n, &d, &a);
    vector<pair<ll,ll>> ps;
    for (ll i = 0; i < n; i++) {
        ll x,h;
        scanf("%lld %lld",&x,&h);
        ps.push_back(make_pair(x, h));
    }
    sort(ps.begin(),ps.end());
    vector<ll> X(n,0),Rside(n,0);
    for (ll i = 0; i < n; i++) X[i] = ps[i].first;
    for (ll i = 0; i < n; i++) {
        ll x = X[i];
        auto itr = lower_bound(X.begin(), X.end(), x + 2 * d);
        if (itr == X.end()) Rside[i] = n - 1;
        else if (*itr == x + 2 * d) Rside[i] = itr - X.begin();
        else Rside[i] = itr - X.begin(), Rside[i]--;
    }
    vector<ll> at(n + 1, 0), hp(n + 1, 0);
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        if (i > 0) hp[i] = hp[i - 1] + at[i];
        ll tmp = ps[i].second - hp[i];
        if (tmp > 0) {
            ll res;
            if (tmp % a) res = tmp / a + 1;
            else res = tmp / a;
            hp[i] += res * a;
            at[Rside[i] + 1] -= res * a;
            ans += res;
        }
    } 
    printf("%lld\n",ans);
}

Measured memory_bytes: 10348
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1e15+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> p(n);
    int c = 0;
    int flag = 0;
    rep(i,0,n){
      cin >> p[i];
      if(p[i]==i+1 && flag==0){
        c++;
        flag++;
      }
      else{
        flag = 0;
      }
    }
    cout << c << endl;
}

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

struct UnionFind {
  vector<int> par;

  UnionFind(int N) : par(N, -1){};

  // Aのrootを調べる
  int root(int A) {
    if (par[A] < 0) return A;  // マイナスならそれはroot
    return par[A] = root(par[A]);
  }

  // rootの値をプラスに戻して返す(サイズ)
  int size(int A) {
    return -par[root(A)];
  }

  // くっつける関数
  bool connect(int A, int B) {
    // AとBのroot同士をくっつける
    A = root(A);  // ここのAは、"rootの場所"の意味
    B = root(B);
    if (A == B) return false;  // 既にくっついている
    if (size(A) < size(B))
      swap(A, B);            // 大きい方にくっつけるために中身交換
    par[A] += par[B];  // 中身更新
    par[B] = A;
    return true;
  }
};


const ll mod = 1e9 + 7;
int main() {
    int n, m;
    cin >> n >> m;
    
    UnionFind tree(n);

    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree.connect(a, b);
    }
    int ans = 0;
    rep(i,n){
        ans = max(ans, tree.size(i));
    }
    cout <<ans<<endl;
}


Measured memory_bytes: 4028
ans = 10**9 # anserの最大値は10の9乗
N =  int(input())
A = list(map(int, input().split()))
for i in A:
    p = 0
    while i % 2 == 0:
        i /= 2 # i = i/2 と同義
        p += 1
    if p < ans:
        ans = p
print(ans)

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

int main(){
    int N;
    vector<vector<int>> A(3,vector<int>(3));
    rep(i,3){
        rep(j,3){
            cin >> A[i][j];
        }
    }
    cin >> N;
    vector<int> B(N);
    rep(i,N){
        cin >> B[i];
        rep(j,3){
            rep(k,3){
                if(A[j][k] == B[i]){
                    A[j][k] = -1;
                }
            }
        }
    }
    bool flag = false;
    rep(i,3){
        if(A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1)flag =true;
    }
    rep(j,3){
        if(A[0][j] == -1 && A[1][j] == -1 && A[2][j] == -1)flag =true;
    }
    if(A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1)flag=true;
    if(A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1)flag=true;
    cout << (flag?("Yes"):("No")) << endl;
}


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

int main(){
  
  int a[3];

  cin>>a[0]>>a[1]>>a[2];

  sort(a,a+3);

  cout<<(a[2]-a[1])+(a[1]-a[0])<<endl;

  return 0;

}
		  


Measured memory_bytes: 256
// ref: https://www.dropbox.com/sh/arnpe0ef5wds8cv/AAA0c7bOd45pMFGk9D8av1Uqa/ARC091/C?dl=0&subfolder_nav_tracking=1
// WA: overflow. cnv int32 -> int64.

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int64 N, M; cin >> N >> M;
    if      (N==1 && M==1){ cout << 1 << endl;
    }else if(N==1 && M>=2){ cout << (M-2) << endl;
    }else if(N>=2 && M==1){ cout << (N-2) << endl;
    }else if(N>=2 && M>=2){ cout << (N-2)*(M-2) << endl; }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define MAX 100000

using namespace std;

int visited[MAX];
//adjacent list
vector<int> G[MAX];

//can go from s to t or not
int color[MAX];

void dfs(int s,int c){
  color[s]=c;
  visited[s]=1;
  for(int i=0;i<G[s].size();i++){
    if(visited[G[s][i]]==0){
      dfs(G[s][i],c);
    }
  }
}

int main(){
  int n,m; cin >> n >> m;
  for(int i=0;i<m;i++){
    int x,y; cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  //coloring
  for(int i=0;i<n;i++){
    visited[i]=0;
    color[i]=-1;
  }
  int c=0;
  for(int i=0;i<n;i++){
    if(color[i]==-1){
      dfs(i,c);
      c++;
    }
  }

  //question
  int q; cin >> q;
  for(int i=0;i<q;i++){
    int s,t; cin >> s >> t;
    if(color[s]==color[t]) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

Measured memory_bytes: 12500
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

	public static void solve() {
		int n=s.nextInt();
		allpermutation=new ArrayList<String>();
		visited= new boolean[n+1];
		recur(1, new StringBuilder(), n);
		StringBuilder first = new StringBuilder();
		for(int i=0;i<n;i++) {
			first.append(s.nextInt());
		}
		int a = find(first.toString());
		StringBuilder second= new StringBuilder();
		for(int i=0;i<n;i++) {
			second.append(s.nextInt());
		}
		int b= find(second.toString());
		out.println(Math.abs(b-a));
	}
	
	public static int find(String str) {
		for(int i=0;i<allpermutation.size();i++) {
			String current = allpermutation.get(i);
			if(current.equals(str)) {
				return i;
			}
		}
		return -1;
	}

	public static ArrayList<String> allpermutation;
	public static boolean[] visited;
	
	public static void recur(int pos,StringBuilder str,int n) {
		if(pos>n) {
			allpermutation.add(str.toString());
			return;
		}
		for(int i=1;i<=n;i++) {
			if(!visited[i]) {
				visited[i]=true;
				StringBuilder temp = new StringBuilder(str);
				temp.append(i);
				recur(pos+1, temp, n);
				visited[i]=false;
			}
		}
	}
	
	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}


Measured memory_bytes: 37408
#include <limits>
using ll = long long;
constexpr int INF = std::numeric_limits<int>::max() / 2;
constexpr ll LNF = std::numeric_limits<ll>::max() / 2;

#include <bits/stdc++.h>
using namespace std;
int main() {
    int X;
    cin >> X;
    int ma = 1;
    for (int b = 2; b <= X; b++) {
        for (int c = b * b; c <= X; c *= b) { ma = max(ma, c); }
    }
    cout << ma << endl;
    return 0;
}


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

int main(){
  int N;
  cin >>N;
  vector<long long> a(N);
  for(int i=0;i<N;i++){
    long long x;
    cin >>x;
    a[i] = x;
  }
  
  long long total=0;
  
  for(int i=0;i<N;i++){
    total += a[i];
  }
  
  vector<long long> b(N,total);
  
  for(int i=0;i<N;i+=2){
    for(int j=0;j<i;j+=2) b[i] -= a[j]*2;
    for(int j=N-1;j>i;j-=2) b[i] -= a[j-1]*2;
  }
  
  for(int i=1;i<N-1;i+=2){
    b[i] = a[i-1]+a[i]-(b[i-1]+b[i+1])/2;
  }
  
  for(int i=0;i<N;i++){
    cout << b[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2944
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        an:[i64;n],
    }
    let mut cp = an.clone();
    let mut count =0;
    cp.sort();
    for i in 0..n {
        if an[i] != cp[i]{
            count += 1;
        }
    }
    if count <= 2{
        println!("YES");
    }else {
        println!("NO");
    }
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 4352
a,b,c,d = map(int,input().split())

#a~bの整数の数-(bまでのc,dで割り切れる数-(a-1)までのc,dで割り切れる数)
#ans = x-(y-z)

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

e = c*d//gcd(c,d)
#eはlcm(最小公倍数)
x = b-a+1
f = a-1
y = b//c+b//d-b//e
z = f//c+f//d-f//e

ans = x-(y-z)
#print("x:"+str(x))
#print("y:"+str(y))
#print("z:"+str(z))
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
using namespace std;
long long fan(long long x){
    if(x==1){
        return 1;
    }
    return 2*fan(x/2)+1;
}

int main(){
    long long h;
    long long c=0;
    cin>>h;
    cout<<fan(h);
}


Measured memory_bytes: 1144
#include <iostream>
using namespace std;
int main()
{
  int l , r ,d ;
  cin >> l >> r >> d; 
  int count = 0 ;
  for(int i  = l ;  i<=r ;i++)
  {
    if(i%d == 0 )
      count++;
  }
 	cout << count << endl;
}

Measured memory_bytes: 3624
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1];
	if(A+B >= 10) "error".writeln;
	else (A+B).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

int n,m;
std::vector<std::vector<int>> s;
std::vector<int> p;

void input()
{
    std::cin>>n>>m;
    s.resize(m);p.resize(m);
    for(int i=0;i<m;i++){
        int k;std::cin>>k;
        s[i].resize(k);
        for(int j=0;j<k;j++){
            std::cin>>s[i][j];
            s[i][j]--;
        }
    }
    //電球の付く状態
    for(int i=0;i<m;i++)std::cin>>p[i];
}



int main()
{
    input();
    long long res = 0;

    //考えられるすべてのスイッチの状態（2^n）について
    for(int bit = 0;bit < (1<<n); bit++){
        bool ok = true;
        //その条件において、電球ごとにいくつのスイッチに接続しているかを調べる
        for(int i=0;i<m;i++){
            int cnt = 0;
            //与えられた条件のうち、各電球に接続している電球の数を調べる
            for(auto v : s[i]){
                if(bit & 1<<v)cnt++;
            }
            if(cnt%2!=p[i])ok = false;
        }
        if(ok)res++;
    }
    std::cout<<res<<std::endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<string>
#include<string.h>
#include<memory.h>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<sstream>
#include<cmath>
#include<list>
#include<deque>
#include<stack>
#include<ctime>
using namespace std;
int n,k,ans,num;
int A,B;
vector<int> r[2500];
int dfs(int a,int h,int fa)
{
int num=1;
if(h<k/2)
{for(auto it:r[a])
if(it!=fa) num+=dfs(it,h+1,a);}            //int类型dfs累加法
return num;
}
int main()
{//freopen("short.txt","r",stdin);
cin>>n>>k;
for(int i=0;i<n-1;i++)
{cin>>A>>B;
r[A].push_back(B);
r[B].push_back(A);}

if(k%2==0)
for(int i=1;i<=n;i++)
{//cout<<ans<<" ";
ans=max(ans,dfs(i,0,-1));
}
else
{for(int i=1;i<=n;i++)
for(auto j:r[i])
{//cout<<ans<<" ";
ans=max(ans,dfs(i,0,j)+dfs(j,0,i));
}}
cout<<n-ans;
return 0;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
using namespace std;
int n,m;
int f[100004];
int Find(int x){return f[x]==x?f[x]:f[x]=Find(f[x]);}
set<int>tr;
int LiangJiaJun(){
    tr.clear();
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)f[i]=i;
    for(int i=1;i<=m;i++){
        int x,y,z;scanf("%d%d%d",&x,&y,&z);
        int p=Find(x),q=Find(y);
        if(p!=q){
            f[p]=q;
        }
    }

    for(int i=1;i<=n;i++)tr.insert(Find(i));
    printf("%d\n",tr.size());
    return 0;
}


Measured memory_bytes: 5376
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


immutable LIM = 10^^4 + 10;

int N;
Tuple!(int, "w", int, "s", long, "v")[] T;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      T.length = N;
      foreach (i; 0 .. N) {
        T[i].w = readInt();
        T[i].s = readInt();
        T[i].v = readLong();
      }
      T.sort!((a, b) => (a.w + a.s < b.w + b.s));
      debug {
        writeln(T);
      }
      auto dp = new long[LIM + 1];
      dp[] = 0;
      foreach (i; 0 .. N) {
        foreach_reverse (x; 0 .. T[i].s + 1) {
          const xx = min(x + T[i].w, LIM);
          chmax(dp[xx], dp[x] + T[i].v);
        }
      }
      long ans;
      foreach (x; 0 .. LIM + 1) {
        chmax(ans, dp[x]);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 2556
#include <stdio.h>
#define max(p,q)((p)>(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int a[16][16];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)a[i][j]=-1;
	for(int i=0;i<n;i++){
		int j;
		scanf("%d",&j);
		while(j--){
			int x,y;
			scanf("%d%d",&x,&y);
			x--;
			a[i][x]=y;
		}
	}		
	int ans=0;
	for(int b=0;b<1<<n;b++){
		int ng=0;
		for(int i=0;i<n;i++)if(bit(b,i))for(int j=0;j<n;j++){
			if(a[i][j]!=-1 && a[i][j]!=bit(b,j)){
				ng=1;
			}
		}
		if(!ng)ans=max(ans,__builtin_popcount(b));
	}
	printf("%d",ans);
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,c=1;
    char s[10001];
    cin>>s;
    int l=strlen(s);
    for(i=0;i<l;i++)
    {
        if(s[i]=='R')
        {
         if((i+1)%2!=1)
         {
            c=0;
            break;
         }
        }else if(s[i]=='L')
        {
            if((i+1)%2!=0)
            {
                 c=0;
                 break;
            }
        }
    }
    if(c==1)
    {
        cout<<"Yes"<<endl;
    }else
    {
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
int n;
int p;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>p;
		if(p!=i)
			cnt++;
	}
	cout<<(cnt<=2?"YES":"NO")<<endl;
	return 0;
}


Measured memory_bytes: 256
use std::io;
use std::io::Read;

fn main() {
    let mut stdin = io::stdin();
    let mut lines = String::new();
    let _ = stdin.read_to_string(&mut lines);
    let vec = lines.lines().collect::<Vec<&str>>();
    let n :usize = vec[0].trim().parse().unwrap();
    let vec2 = vec[1].split(' ').collect::<Vec<&str>>();
    let mut a :Vec<usize> = Vec::new();
    for i in 0..n*3 {
        a.push(vec2[i].trim().parse().unwrap());
    }
    a.sort_by(|a,b|b.cmp(a));
    let a = a;
    let mut sum = 0;
    for i in 0..n {
        sum += a[i*2+1];
    }
    println!("{}",sum);
}


Measured memory_bytes: 19696
#include<stdio.h>

#define min(a,b) ((a)<(b)?(a):(b))
#define INF 2000000000

int n;
long long dis[500][500];
long long lis[500][500];

void warshall_floyd(){
	int i,j,k;
	for(k=0;k<n;k++){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}
}

void warshall_floydd(){
	int i,j,k;
	for(k=0;k<n;k++){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				lis[i][j]=min(lis[i][j],lis[i][k]+lis[k][j]);
			}
		}
	}
}

int main(){
	int m,i,j,k,l;
	for(i=0;i<500;i++){
		for(j=0;j<500;j++){
			dis[i][j]=INF;
		}
	}
	scanf("%d%d%d",&n,&m,&l);
	for(i=0;i<m;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a--,b--;
		dis[a][b]=c;
		dis[b][a]=c;
	}
	warshall_floyd();
	for(i=0;i<500;i++){
		for(j=0;j<500;j++){
			lis[i][j]=INF;
		}
	}
	for(i=0;i<500;i++){
		for(j=0;j<500;j++){
			if(dis[i][j]<=l){
				lis[i][j]=1;
			}
		}
	}
	warshall_floydd();
	int q;
	scanf("%d",&q);
	for(i=0;i<q;i++){
		int s,t;
		scanf("%d%d",&s,&t);
		s--,t--;
		if(lis[s][t]<INF)printf("%lld\n",lis[s][t]-1);
		else puts("-1");
	}
	return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX_N = 500010, MOD = 1000000007;
vector<ll> an(MAX_N), bn(MAX_N), hunn(MAX_N), comb(MAX_N);

void make_vec(int a,int n, vector<ll> &vec){
    ll temp = 1;
    rep(i,n*2+10){
        vec.at(i) = temp;
        (temp *= a)%=MOD;
        //if(a == 50) cout<<temp<<endl;
    }
}

ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}
//a>b を守る
void makecomb(ll n, vector<ll> &vec){
    ll temp = 1;
    //comb.at(i)が(i-1)C(N-1)になるので、iはNから2N-1
    //つまりi=M
    reps(i,n,n*2){
        vec.at(i) = temp;
        (temp *= i)%=MOD;
        (temp *= fastpow(i-n+1,MOD-2))%=MOD;
    }
    return;
}

int main() {
    ll p = 0,q;
    cin>>N>>A>>B>>M;
    make_vec(A,N,an);
    make_vec(B,N,bn);
    make_vec(100-M,N,hunn);
    //makecomb(N,comb);
    //cout<<100-M<<endl;
    ll temp = 1;
    reps(i,N,N*2+5){
        comb.at(i) = temp;
        (temp *= i)%=MOD;
        //temp /= i+1-N;
        //逆元をかけないとだめです
        (temp *= fastpow(i+1-N,MOD-2))%=MOD;
    }
    q = hunn.at(N*2);
    reps(i,N,N*2){
        ll t = i*100;
        (t *= comb.at(i)) %=MOD;
        //if(i == N*2-1) cout<<t<<endl;
        ll ab = an.at(N)*bn.at(i-N);
        ab %= MOD;
        (ab += an.at(i-N)*bn.at(N))%=MOD;
        (t *= ab)%=MOD;
        //cout<<an.at(N)*bn.at(i-N) + an.at(i-N)*bn.at(N)<<endl;
        //if(i == N*2-1) cout<<t<<endl;
        (t *= hunn.at(N*2-i-1))%=MOD;
        //if(i == N*2-1) cout<<t<<endl;
        (p += t)%=MOD;
        if(p < 0) cout << i << ' ' << p << endl;
    }
    ll ans = fastpow(q,MOD-2);
    (ans *= p)%=MOD;
    //cout<<p<<' '<<q<<endl;
    cout<<ans<<endl;
    //cout<<an.at(1)<<' '<<bn.at(1)<<' '<<hunn.at(2)<<endl;
}

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

using namespace std;

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

    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if(s == "AC") {
            ac++;
        } else if(s == "WA") {
            wa++;
        } else if(s == "TLE") {
            tle++;
        } else {
            re++;
        }
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 5010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

int fa[maxn],X[maxn],V[maxn],f[maxn],g[maxn];

vector<int> G[maxn];

void dfs(int u){
	for(auto v:G[u])dfs(v);
	memset(f,0x3f,sizeof(f));f[0]=0;
	for(auto v:G[u]){
		memcpy(g,f,sizeof(g));memset(f,0x3f,sizeof(f));
		for(int i=X[u];i>=0;i--){
			if(i>=X[v])f[i]=min(f[i],g[i-X[v]]+V[v]);
			if(i>=V[v])f[i]=min(f[i],g[i-V[v]]+X[v]);
		}
	}
//	REP(i,0,X[u])cout<<f[i]<<' ';cout<<endl;
	V[u]=0x3f3f3f3f;
	REP(i,0,X[u])V[u]=min(V[u],f[i]);
	if(V[u]>=0x3f3f3f3f){
		puts("IMPOSSIBLE");
		exit(0);
	}
}

void Work(){
	dfs(1);
//	REP(i,1,n)cout<<V[i]<<' ';cout<<endl;
//	cout<<0x3f3f3f3f<<endl;
	puts("POSSIBLE");
}

void Init(){
	read(n);
	REP(i,2,n)read(fa[i]),G[fa[i]].PB(i);
	REP(i,1,n)read(X[i]);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 512
n = int(input())
s = [int(input()) for _ in range(n)]

s.sort()
ans = sum(s)
if ans % 10 != 0:
    print(ans)
    quit()
else:
    for i in range(n):
        if (ans-s[i]) % 10 != 0:
            print(ans-s[i])
            quit()

print(0)

Measured memory_bytes: 2940
import collections as c
ip = lambda : map(int, input().split())

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

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
k = int(input())

for i in [A,B,C,D,E]:
    for j in [A,B,C,D,E]:
        if abs(i-j)>k:
            print(':(')
            exit()
print('Yay!')

Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n;
        string s, t;
        in >> n;
        in >> s;
        in >> t;
        ll ans = n;
        for (int i = 0; i < n; i++) {
            bool ok = true;
            for (int j = i; j < n; j++) {
                ok &= s[j] == t[j - i];
            }
            if (ok) {
                ans = i;
                break;
            }
        }
        out << ans + n << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    in_arr(int, a, n);
    sort(a.begin(), a.end());
    a[n - 1] /= 2;
    cout << accumulate(a.begin(), a.end(), 0) << endl;
    return 0;
}


Measured memory_bytes: 256
s = input()

x = [1 if c == 'B' else 0 for c in s]

cum = [0]
for i in range(len(s)):
    cum.append(cum[-1] + x[i])

ans = 0
for idx, c in enumerate(s):
    if c == 'W':
        ans += cum[idx+1]
print(ans)

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

int main()
{
  int t, n, a, b, sub;
  
  while(cin >> t, t) {
    cin >> n;
    vector<int> s, f;
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      s.push_back(a);
      f.push_back(b);
    }

    int sum = 0;
    for (int i = 0; i < s.size(); i++) {
      sub = f[i] - s[i];
      sum += sub;
    }

    if(sum >= t) {
      cout << "OK" << endl;
    }
    else {
      cout << t-sum << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

int main(){
  long long int N,K;
  cin >> N >> K;
  long long int a[111111],b[111111];
  vector<pair<long long int,long long int>> pairs(111111);
  long long int i;
  for(i=0;i<=N-1;i++)
    cin >> a[i] >> b[i];
  for(i=0;i<=N-1;i++)
    pairs[i] = make_pair(a[i],b[i]);
  sort(pairs.begin(), pairs.end());
  long long int sum = 0;
  long long int k = 0;
  while(sum < K){
    sum += pairs[k].second;
    k++;
  }
  if(k >= 1)  cout << pairs[k-1].first << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    string s;
    cin >> s;
    bool ans = 0;
    rep(i,3) {
        if(s[i] == '7') ans = 1;
    }
    if(ans) cY
    else cN
    
}



Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

long long func(long long k,long long n) {
    vector<int> p{3,5,7};
    if(k > n) {
        return 0;
    }
    long long ret = 0;
    for(int i = 0; i < 3; i++) {
        long long x = k*10+p[i];
        ret += func(x,n);
    }
    string S = to_string(k);
    set<char> X;
    for(int i = 0; i < S.size(); i++) {
        X.insert(S[i]);
    }
    if(X.size() == 3) {
        ret++;
    }
    return ret;
}

int main() {
    long long n;
    cin >> n;
    long long ans = func(0,n);
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func binarySearch1(a []int, b, e, k int) (bool, int) {
	n := len(a)

	if k <= a[b] {
		return true, b
	} else if a[e-1] < k {
		return true, n
	}

	if e-b <= 2 {
		if a[b] < k && k <= a[b+1] {
			return true, b + 1
		} else if a[b+1] < k && k <= a[b+2] {
			return true, b + 2
		}
	}

	mid := (b + e) / 2
	if a[mid] < k && k <= a[mid+1] {
		return true, mid + 1
	}

	if a[mid] >= k {
		okLeft, iLeft := binarySearch1(a, b, mid+1, k)
		if okLeft {
			return true, iLeft
		}
	}
	okRight, iRight := binarySearch1(a, mid, e, k)
	if okRight {
		return true, iRight
	}

	return false, -1
}

func binarySearch2(a []int, b, e, k int) (bool, int) {
	n := len(a)

	if k < a[b] {
		return true, b
	} else if a[e-1] <= k {
		return true, n
	}

	if e-b <= 2 {
		if a[b] <= k && k < a[b+1] {
			return true, b + 1
		} else if a[b+1] <= k && k < a[b+2] {
			return true, b + 2
		}
	}

	mid := (b + e) / 2
	if a[mid] <= k && k < a[mid+1] {
		return true, mid + 1
	}

	if a[mid] > k {
		okLeft, iLeft := binarySearch2(a, b, mid+1, k)
		if okLeft {
			return true, iLeft
		}
	}
	okRight, iRight := binarySearch2(a, mid, e, k)
	if okRight {
		return true, iRight
	}

	return false, -1
}

func main() {
	scanner.Split(bufio.ScanWords)
	sizeA := nextInt()
	a := make([]int, sizeA)
	for i := 0; i < sizeA; i++ {
		a[i] = nextInt()
	}
	nQueries := nextInt()
	for i := 0; i < nQueries; i++ {
		qi := nextInt()
		_, l := binarySearch1(a, 0, sizeA, qi)
		_, u := binarySearch2(a, 0, sizeA, qi)
		fmt.Println(l, u)
	}
}



Measured memory_bytes: 5896