akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

    unsigned int P; cin>>P;
    vector<int> A(P); for (auto& a : A) cin>>a;

	vector<unsigned int> fact(P);
	fact[0] = 1;
	for (unsigned int i = 1; i < P; i++)
        fact[i] = (fact[i-1] * i) % P;
    vector<unsigned int> vfact(P);
    {
        unsigned int t = 1;
        unsigned int u = fact[P-1];
        auto y = P-2;
        while (y) {
            if (y & 1) {
                t *=u; t %= P;
            }
            u *= u; u %= P;
            y >>= 1;
        }
        vfact[P-1] = t;
    }
	for (int i = P-2; i >= 0; i--)
	    vfact[i] = vfact[i+1]*(i+1)%P;
	auto comb = [&](unsigned int x, unsigned int y) {
	    return fact[x]*(vfact[y]*vfact[x-y]%P)%P;
	};
	vector<unsigned int> B(P, 0);
	for (unsigned int i = 0; i < P; i++) {
	    if (A[i] == 0)
	        continue;
	    B[0]++;
	    unsigned int k = 1;
	    for (int j = P-1; j >= 0; j--) {
            B[j] += P-comb(P-1, j)*k%P; B[j] %= P;
            k *= P-i; k %= P;
	    }
	}
	for (auto b : B)
	    cout << b << ' ';
	cout << endl;

    return 0;
}


Measured memory_bytes: 384
S = input()
MOD = 10**9+7
A = 0
AB = 0
ABC = 0
cnt = 1
for c in S:
  if c=='A':
    A += cnt
    A %= MOD
  elif c=='B':
    AB += A
    AB %= MOD
  elif c=='C':
    ABC += AB
    ABC %= MOD
  else:
    nA = 3*A+cnt
    nAB = 3*AB+A
    nABC = 3*ABC+AB
    cnt *= 3
    A,AB,ABC = nA%MOD,nAB%MOD,nABC%MOD
    cnt %= MOD
print(ABC)

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	ll a, b,cnt = 1;
	cin >> a >> b;
	ll c = __gcd(a,b);
	for(ll i = 2;i <= c/i; ++i){
		if(c % i == 0){
			cnt ++;
			while(c % i == 0) c /= i;
			
		}
	}
	if(c > 1) cnt++;
	cout << cnt ;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
def resolve():
    N,=pin()
    A=tupin()
    
    if 1 not in A:print(-1);return
    suuji=0
    ans=0
    for a in A:
        if a==suuji+1:
            suuji+=1
        else:ans+=1
    print(ans)
#%%submit!
resolve()

Measured memory_bytes: 28380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

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

    int h,w;
    cin >> h >> w;

    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    sx--;sy--;gx--;gy--;

    string sur[h];

    for(int i = 0; i < h; i++) cin >> sur[i];
    queue<pair<int,int>> p,q;

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

    p.push(make_pair(sx,sy));

    int can = 0;

    while(!p.empty()){
        while(!p.empty()){
            pair<int,int> now = p.front();
            p.pop();
            q.push(now);
            for(int i = 0; i < 4; i++){
                pair<int,int> nxt = make_pair(now.first+dx[i],now.second+dy[i]);
                if(0 <= nxt.first && nxt.first < w && 0 <= nxt.second && nxt.second < h){
                    if(sur[nxt.second][nxt.first] == '.'){
                        if(nxt == make_pair(gx,gy)){
                            cout << can << endl;
                            return 0;
                        }
                        p.push(nxt);
                        sur[nxt.second][nxt.first] = '#';
                    }
                }
            }
        }
        can++;
        while(!q.empty()){
            pair<int,int> now = q.front();
            q.pop();
            for(int i = -2; i < 3; i++){
                for(int j = -2; j < 3; j++){
                    pair<int,int> nxt = make_pair(now.first+i,now.second+j);
                    if(0 <= nxt.first && nxt.first < w && 0 <= nxt.second && nxt.second < h){
                        if(sur[nxt.second][nxt.first] == '.'){
                            if(nxt == make_pair(gx,gy)){
                                cout << can << endl;
                                return 0;
                            }
                            p.push(nxt);
                            sur[nxt.second][nxt.first] = '#';
                        }
                    }
                }
            }
        }
    }

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


Measured memory_bytes: 4672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

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

int main() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  combination c(3e5 + 1);
  mint ans = 0;
  for(ll i = 0; i * a <= k; i++) {
    ll j = (k - i * a) / b;
    if(i * a + b * j != k) continue;
    ans += c(n, i) * c(n, j);
  }
  cout << ans << endl;
}

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

int n, c[4];
string s;

int main(){
    scanf("%d", &n);
    for (int i=0; i<n; ++i){
        cin>>s;
        if (s == "AC") ++c[0];
        else if (s == "WA") ++c[1];
        else if (s == "TLE") ++c[2];
        else ++c[3];
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d", c[0], c[1], c[2], c[3]);
}


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


int main() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  vector<vector<int>> vec(h, vector<int>(w, 0));
  rep(i,h){
    rep(j,w){
      if(i<b && j<a || i>=b && j>=a){
        vec[i][j] = 1;
      }
      cout << vec[i][j];
      if(j==(w-1)) cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
  int n,m,t1,t2,c[100000]={}; vector <int> g[100000];
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>t1>>t2;
    g[t1].push_back(t2);
    g[t2].push_back(t1);
  }
  int l;cin>>l;
  for(int i=0;i<n;i++) if(!c[i]){
      queue <int> q; bool f[100000]={};
      q.push(i);f[i]=true;c[i]=i+1;
      for(;!q.empty();){
        for(int j=0;j<g[q.front()].size();j++){
          int v=g[q.front()][j];
          if(!f[v]){
            f[v]=true;c[v]=i+1;
            q.push(v);
          }
	}
          q.pop();
      }
    }
  for(int i=0;i<l;i++){
    cin>>t1>>t2;
    if(c[t1]==c[t2]) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 9076
#include <stdio.h>
int main(){
  int a,b,i,c,count=0;
  scanf("%d %d",&a,&b);
   for(i=0;i<a+1;i++){
     c=2*i+4*(a-i);
     if(c==b)count+=1;
     }
  if(count==0)printf("No");
  else printf("Yes");
  return 0;
  }


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

int main(void){
    int N; //1-200
    int count=1; //105以上なら105は含まれるので、1からスタートする
    int sho=0;
    int amari=0;
    int yakusu_i;

    cin >> N;

    //1-104の場合は0個
    if(N < 105)
    {
        cout << 0 << endl;
        return 0;
    }

    //105-106の場合は1個
    if(N < 107)
    {
        cout << count << endl;
        return 0;
    }

    //107-199だけ考えれば良い（問題文より、奇数のみ）
    //奇数のみ考えるため、偶数の約数はもたない
    for(int i=107; i<N+1; i=i+2)
    {
        yakusu_i = 0;

        //約数カウント
        for(int j=1; j<i+1; j=j+2)
        {
            sho = i/j; //商
            amari = i%j; //余り

            //1～iまでの奇数について、余りが0なら割り切れる＝約数
            if(amari == 0)
            {
                yakusu_i ++;
            }
        }

        if(yakusu_i == 8)
        {
            //debug
            //cout << "i" << i << endl;
            //約数の数がちょうど8個ならインクリ
            count ++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mod = 1000000007;

int main(){
    ll K;
    cin >> K;
    
    int N = 50;
    cout << N << endl;
    
    vector<ll> ans(N);
    for(int i = 0; i < N; i++){
        ans[i] = i;
    }
    
    if(K < N){
        for(int i = 0; i < K; ++i){
            for(int i = 0; i < N; ++i){
                if(ans[i] == 0){
                    ans[i] += N;
                }
                else{
                    ans[i]--;
                }
            }
        }
    }
    else{
        ll add = K / N;
        ll mod = K % N;
        
        for(int i = 0; i < N; ++i){
            ans[i] += add;
        }
        for(int i = 0; i < mod; ++i){
            ll min_e = *min_element(ans.begin(), ans.end());
            for(int i = 0; i < N; ++i){
                if(ans[i] == min_e){
                    ans[i] += N;
                }
                else{
                    ans[i]--;
                }
            }
        }
    }
    
    for(int i = 0; i < N; ++i){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(25):
            if S[25-i] > S[25-i-1]:
                break
        for j in range(25): # index out of rangeにならない？大丈夫？
            if chr(ord(S[25-i-1])+1+j) not in S[0:25-i-1]:
                break
        Ans = S[0:25-i-1]+chr(ord(S[25-i-1])+1+j)
print(Ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
 
int main(){
    string S,T;
    int ans = 0;

    cin >> S >> T;

    for(int i = 0;i < S.length();i++){
        if(S[i] != T[i])ans++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
inline int xmod(int a, int b) {
    int ret = a % b;
    return (ret >= 0) ? ret : ret + b;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    int len=1000050;
    vector<int> li(len);
    int fi=0, la=0;

    string op;
    int key;
    vector<int>::iterator pos;

    for (int i=0; i<n; ++i) {
        cin >> op;
        if (op[0] == 'i') {
            cin >> key;
            fi = xmod(fi-1, len);
            li[fi] = key;
        } else if (op.size() > 6 && op[6] == 'F') {
            while (li[fi] == -1) {
                fi = (fi+1) % len;
            }
            fi = (fi+1) % len;
        } else if (op.size() > 6 && op[6] == 'L') {
            while (li[xmod(la-1, len)] == -1) {
                la = xmod(la-1, len);
            }
            la = xmod(la-1, len);
        } else {
            cin >> key;
            for (int j=fi; j!=la; j=(j+1)%len) {
                if (li[j] == key) {
                    li[j] = -1;
                    break;
                }
            }
        }
    }

    bool nospace = true;
    for (int i=fi; i!=la; i=(i+1)%len) {
        if (li[i] == -1) {
            continue;
        }
        if (nospace) {
            cout << li[i];
            nospace = false;
        } else {
            cout << " " << li[i];
        }
    }
    cout << endl;
    return 0;
}

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

int main(){
    long long N,A,B;
    cin >> N >> A >> B;
    long long count,syo,amari;
    syo = N / (A + B);
    amari = N % (A + B);
    count = syo * A;
    if(amari > A){
        count += A;
    }else{
        count += amari;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> C(N), S(N+1), F(N);
	for (int i = 1; i < N; i++)cin >> C[i] >> S[i] >> F[i];
	for (int i = 1; i < N; i++) {
		int ans = 0,x;
		for (int j = i; j < N; j++) {
			x = S[j];
			while (ans > x) {
				x += F[j]; 
			}
			ans = x;
			ans += C[j];
		}
		cout << ans << endl;
	}
	cout << 0 << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-9;
const ll mod=1e9+7;
ll dp[100010][3];
ll a;char c;int n;
int main()
{
    cin>>n>>a;
    memset(dp,-0x3f3f3f3f3f3f3f3f,sizeof(dp));
    dp[0][0]=a;
    for(int i=1;i<n;i++)
    {
        scanf(" %c%d",&c,&a);
        if(c=='+')
        {
            dp[i][2]=dp[i-1][2]+a;
            dp[i][1]=max(dp[i-1][1]-a,dp[i-1][2]+a);
            dp[i][0]=max(dp[i-1][0]+a,max(dp[i-1][1]-a,dp[i-1][2]+a));
        }
        else
        {
            dp[i][2]=max(dp[i-1][1]+a,dp[i-1][2]-a);
            dp[i][0]=dp[i][1]=max(dp[i-1][1]+a,max(dp[i-1][2]-a,dp[i-1][0]-a));
        }
    }
    printf("%lld\n",max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])));
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int P[222];

vint ans;

void s(int k){
    for(int i=k;i<N;i++)swap(P[i],P[i-k]);
    ans.pb(k);
}

signed main(){
    cin>>N;
    rep(i,N)cin>>P[i];


    rep(i,N){
        rep(j,N-1){
            s(1);
            if(P[N-1]>P[0])s(N-1);
        }
        s(1);
    }

    cout<<ans.size()<<endl;
    rep(i,ans.size())cout<<ans[i]<<endl;

    return 0;
}


Measured memory_bytes: 1016
w, h, n = [int(i) for i in input().split()]

point_list = [input().split() for i in range(n)]

area = [[1]*w for i in range(h)]


for point in point_list:

    if point[2] == "1":
        for i in range(h):
            for j in range(int(point[0])):
                area[i][j] = 0
    elif point[2] == "2":
        for i in range(h):
            for j in range(int(point[0]), w):
                area[i][j] = 0
    elif point[2] == "3":
        for i in range(int(point[1])):
            for j in range(w):
                area[i][j] = 0
    elif point[2] == "4":
        for i in range(int(point[1]), h):
            for j in range(w):
                area[i][j] = 0

print(sum([sum(i) for i in area]))

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] e = new int[4];
        for(int i = 0; i < 4; i++) {
            e[i] = sc.nextInt();
        }
        Arrays.sort(e);

        System.out.println(e[0] + e[2] == e[1] + e[3] ? "yes" : "no");
    }
}

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

int main(){
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  string ans = (t > s)? "Yes": "No";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    string s;
    cin >> s;

    int res = 1e9;
    for (int i = 0; i < s.size() - 2; i++)
    {
        int n = 0;

        int p = 100;
        REP(j, 3)
        {
            n += (s[i + j] - '0') * p;
            p /= 10;
        }

        res = min(res, abs(753 - n));
    }

    cout << res << endl;

    return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    double D, S, T;
    cin >> D >> T >> S;
    if (D / S <= T)
        cout << "Yes\n";
    else
        cout << "No\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
};

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

using namespace std;

int main(void){
    int n, m, x;
    cin >> n >> m >> x;
    
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    
    for (int i = 0; i < n; i++){
        int b;
        cin >> b;
        c[i]= b;
        
        for (int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    
    int ans = 1e9 + 7;
    
    for (int tmp = 0; tmp < (1<<n); tmp++){
        
        bitset<13> s(tmp);
        int money = 0;
        vector<int> algo(m);
        
        for (int i = 0; i < n; i++){
            if (s.test(i)){
                money += c[i];
                for (int j = 0; j < m; j++) algo[j] += a[i][j]; 
            }
        }
        
        bool check = true;
        for (int i = 0; i < m; i++){
            if (algo[i]< x) check = false;
        }
        
        if (check) ans = min (ans,money);
    }
    if (ans == 1e9+7) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3620
#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;

int n;
int cnt[3];

int main(){
  scanf("%d",&n);
  REP(i,n){
    int x;
    scanf("%d",&x);
    cnt[x%3]+=1;
  }
  if(cnt[0]==n){
    puts("1");
  }else{
    int ans = 0;
    int x;
    int tmp[3];
    REP(i,3)tmp[i]=cnt[i];
    {
      x=0;
      if(cnt[1]>0){
        cnt[1]--;
        x++;
      }else{
        x=-10000000;
      }
      x+=cnt[0];
      CHMAX(ans,x);
      if(cnt[1]>0){
        cnt[1]--;
        x++;
        while(true){
          if(cnt[2]>0){
            cnt[2]--;
            x++;
          }else break;
          if(cnt[1]>0){
            cnt[1]--;
            x++;
          }else break;
        }
      }
      if(cnt[1]+cnt[2]>0)x++;
      CHMAX(ans,x);
    }
    {
      x=0;
      REP(i,3)cnt[i]=tmp[i];
      if(cnt[2]>0){
        cnt[2]--;
        x++;
      }else{
        x=-10000000;
      }
      x+=cnt[0];
      CHMAX(ans,x);
      if(cnt[2]>0){
        while(true){
          if(cnt[2]>0){
            cnt[2]--;
            x++;
          }else break;
          if(cnt[1]>0){
            cnt[1]--;
            x++;
          }else break;
        }
      }
      if(cnt[1]+cnt[2]>0)x++;
      CHMAX(ans,x);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> M;
	vector< int > A(M);
	rep(i, M) cin >> A[i];
	int s = 0;
	rep(i, M) s += A[i];
	if (s > N) {
		cout << -1 << endl;
	} else {
		cout << N - s << endl;
	}
	return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+100;
const int mod = 1e9+7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f3f;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
inline bool read(ll &num) {
    char in;bool IsN=false;
    in=getchar();
    if(in==EOF) return false;
    while(in!='-'&&(in<'0'||in>'9')) in=getchar();
    if(in=='-'){ IsN=true;num=0;}
    else num=in-'0';
    while(in=getchar(),in>='0'&&in<='9'){
            num*=10,num+=in-'0';
    } 
    if(IsN) num=-num;
    return true;
}
queue<int> G[N];
int maxx[N];
bool vis[N];
ll a[2000][2000];
int main(){
   //freopen("1.in", "r", stdin);
    ll n;
    read(n);
    rep(i,1,n){
        maxx[i]=0;
        rep(j,1,n-1){
            read(a[i][j]);
            G[i].push(a[i][j]);
        }
    }
    int ans=0;
    while(1){
        bool flag=0;
        rep(i,1,n){
            if(G[i].empty()) continue;
            if(G[G[i].front()].front()==i){
                maxx[i]=maxx[G[i].front()]=max(maxx[i],maxx[G[i].front()])+1;
                G[G[i].front()].pop();
                G[i].pop();
                flag=1;
            }
        }
        if(flag==0){
            cout<<-1<<endl;
            return 0;
        }
        ll num=0;
        rep(i,1,n){
            num+=G[i].size();
        }
        if(num==0){
            break;
        }
    }
    rep(i,1,n){
        ans=max(ans,maxx[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 695168
#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(){
	double deg;
	double PI = acos(-1);
	double rad;
	
	double a, b;
	cin >> a >> b >> deg;
	rad = PI / 180 * deg;
	printf("%.8lf\n", a * b * sin(rad) / 2);
	printf("%.8lf\n", a + b + sqrt(a*a + b*b - 2*a*b*cos(rad)));
	printf("%.8lf\n", b * sin(rad));
		
	return 0;
}

Measured memory_bytes: 1240
def RotN():  
    N = int(input())
    alfabet = input()
    
    alfabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    count = []
    chara = ""
    for alfa in alfabet:
        for i, alfa2 in enumerate(alfabet2):
            if alfa2==alfa:
                c = i+N
                if c>=26:
                    c=c-26
                    chara+=alfabet2[c]
                    
                else:
                    chara+=alfabet2[c]
    print(chara)
if __name__ == "__main__":
    RotN()

Measured memory_bytes: 3064
n = int(input())
s = input()

yes = 0
no = n // 2 + 1
while abs(yes - no) > 1:
	center = (yes + no) // 2
	d = set()
	for i in range(n - 2 * center + 1):
		d.add(s[i:i+center])
		if (s[i+center:i+2*center] in d):
			yes = center
			#print(tempS)
			break
	if (yes != center):
		no = center
print(yes)

Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
main()
{
    string s;
    int n,m,c;
    cin>>n>>m;
    cin>>s;

    if(s[n]=='-' && s.size()==(n+m+1))
    {
        for(int j=0 ;j<s.size();j++)
    {
        if(j==n) continue;
        if(isdigit(s[j])) c=0;
        else
        {
            c=1;
            break;
        }
    }
       if(c==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
 else cout<<"No"<<endl;
}


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

const int N = 22;
const int mod = 1e9 + 7;

int n, a[N][N];
int f[N][1 << N];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= n; ++j) scanf("%d", &a[i][j]);
	}
	f[0][0] = 1;
	for(int i = 1; i <= n; ++i) {
		for(int k = 0; k < n; ++k) {
			if(a[i][k + 1]) {
				for(int j = 0; j < (1 << n); ++j) {
					if(!((j >> k) & 1)) {
						(f[i][j | (1 << k)] += f[i - 1][j]) %= mod;
					}
				}
			}
		}
	}
	printf("%d\n", f[n][(1 << n) - 1]);
}

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

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define IN1(x) ll x; cin >> x;

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <typename T>
vector<T> pows(int n) {
    vector<T> ret;
    T x = 1;
    while (ret.size() < n) {
        ret.push_back(x);
        x *= 10;
    }
    return ret;
}

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

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }

template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }



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

    IN1(N);
	IN1(X);

	ll b = X;
	vector<ll> dd(N);
	REP(i, N) {
		ll x; cin >> x;
		dd[i] = abs(b - x);
		b = x;
	}
	ll ans = dd[0];
	REP(i, N-1) {
		ans = gcd(ans, dd[i+1]);
	}
	out(ans);
	

    return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
x = 0
for a in A:
  x ^= a
now = 0
for i in range(59, -1, -1):
  if x>>i & 1:
    continue
  for j in range(now, n):
    if A[j]>>i & 1:
      A[now], A[j] = A[j], A[now]
      for k in range(n):
        if k != now and A[k]>>i & 1:
          A[k] ^= A[now]
      now += 1
      break
b = 0
for a in A:
  b ^= a
ans = b + (x^b)
print(ans)

Measured memory_bytes: 91464
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m,s;
	cin>>n>>m>>s;
	int a=0,b=0,c=n,d=m;
	while(s--){
		int x,y,q;
		cin>>x>>y>>q;
		if(q==1)a=max(a,x);
		else if(q==2)c=min(c,x);
		else if(q==3)b=max(b,y);
		else if(q==4)d=min(d,y);
	}
	int x=c-a,y=d-b;
	if(x<0||y<0)cout<<0<<endl;
	else cout<<x*y<<endl;
}
/*int main(){
	int n,m,s;
	while(cin>>n>>m>>s,n+m+s){
		vvi in(n,vi(3));
		rep(i,n)rep(j,3)cin>>in[i][j];
		vvp area(n);
		rep(i,n)rep(j,n){
			
		}
	}
}//*/












Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char str[1001];
	int i;
	
	scanf("%s", str);
	
	i = 0;
	while (str[i] != '\0'){
		str[i] -= 3;
		if (str[i] < 'A'){
			str[i] = 'Z' + str[i] - 'A' + 1;
		}
		i++;
	}
	
	printf("%s\n", str);
	
	return (0);
}

Measured memory_bytes: 524
//author:satwik_bhv1
#include<bits/stdc++.h>
//datatypes
#define ll long long 
#define ld long double
//loops
#define fr(i,z,n) for(ll i=z;i<n;i++)
#define br(i,z,n) for(ll i=z;i>n;i--)
//operations
#define mp  make_pair
#define ff  first
#define ss  second
#define pub push_back
#define all(v) v.begin(),v.end()
//map
#define mi map<ll,ll>
//vectors
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
//constants
#define pi 3.1415926535897932384626
#define mod 1000000007 
#define MAXN 100001
/*notes
    Don't use inbuilt fun for power
    Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
    INT_MAX = 2147483647(aprox 2*10^10)
    INT_MIN = -2147483648
    LLONG_MAX = 9223372036854775807 
    LLONG_MIN = -9223372036854775808
    __gcd is the function in built for hcf
    priority queue is max heap by default
    topological sort -> khan's algo use bfs and indegree of node  
    sssp(positive weighted edges) -> Dijkstras
    apsp -> Floydwarshall
    MST -> kruskal(DSU)
*/
using namespace std;
//functions
ll power(ll x,ll y){ll res=1;while(y){if(y%2){res*=x;}y/=2;x*=x;} return res;}
ll power(ll x,ll y,ll z){ll res=1;while(y){if(y%2){res=(res*x)%z;}y/=2;x=(x*x)%z;} return res;}
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b) { return (a.second > b.second); }
ll ceil(ll x,ll y){return (x/y)+(x%y!=0);}
ll n;
ll v[100001][3];
ll dp[100001][3];
ll fun(ll pos,ll task)
{
    ll ans=0;
    if(pos==n)
    {
        return 0;
    }
    fr(i,0,3)
    {
        if(i==task)
        {
            continue;
        }
        if(dp[pos+1][i]==-1)
        {
            ans=max(ans,fun(pos+1,i)+v[pos][i]);
        }
        else
        {
            ans=max(ans,dp[pos+1][i]+v[pos][i]);
        }
    }
    return dp[pos][task]=ans;
}
void solve()
{
    cin>>n;
    fr(i,0,n)
    {
        fr(j,0,3)
        {
            cin>>v[i][j];
            dp[i][j]=-1;
        }
    }
    cout<<max(max(fun(0,0),fun(0,1)),fun(1,1));
}
int main()
{
    fast();
    ll t;
    t=1;
    //cin>>t;
    fr(i,0,t)
    {
        solve();
    }
}
/*





























*/

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

int main() {
  int N, count;
  int P = 0, Y = 0, G = 0, W = 0;
  char ch;
  cin >> N;
  
  rep(i, N) {
    cin >> ch;
    if (ch == 'P') {
      P++;
    }
    else if (ch == 'Y') {
      Y++;
    }
    else if (ch == 'G') {
      G++;
    }
    else if (ch == 'W') {
      W++;
    }
  }
  if (P) count++;
  if (Y) count++;
  if (G) count++;
  if (W) count++;
  
  if (count == 3) {
    cout << "Three" << endl;
  }
  else if (count == 4) {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
/*#include <bits/stdc++.h>
using namespace std;
int main(){
	int n , m ;
	scanf("%d%d",&n,&m);
	int x , y , t;
	for( int i = 0 ; i < m ; i++ ){
		scanf("%d%d%d",&x,&y,&t);
		
	}
	return 0;
}*/
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int AX = 2e5+66;
LL a[AX];
LL b[AX];
LL c[AX];
int n ;	

LL Binary(LL k)
{
    int l = 1 , r = n + 1;
    while( l < r ){
        int mid = ( l + r ) >> 1;
        if(c[mid] >= k) r = mid ; 
        else l = mid + 1 ;
    }
    return l;
}

int main(){
	cin >> n ;
	for( int i = 1 ; i <= n ; i++ ){
		cin >> a[i];
	}
	for( int i = 1 ; i <= n ; i++ ){
		cin >> b[i];
	}
	LL res = 0 ;
	for( int k = 1 ; k <= 29 ; k ++ ){
		LL tmp = (1<<k) - 1;
		for( int i = 1 ; i <= n ; i++ ){
			c[i] = b[i] & tmp;
		}
		LL cnt = 0;
		sort( c + 1, c + n + 1 );
		for( int i = 1 ; i <= n ; i++ ){
			cnt += n - Binary( ( (1<<(k-1)) -(tmp & a[i]) ) )+1;
		}
		for( int i = 1 ; i <= n ; i++ ){
			cnt -= Binary( (1<<k)+(1<<(k-1))-(tmp&a[i])) - Binary((1<<k)-(tmp&a[i]));
		}
		if( cnt & 1 ) res += (1<<(k-1));
	}
	cout << res << endl;
	return 0 ;
}

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


int main(){
int N;
cin >>N;
int B[110];
for(int i = 0; i<N-1;i++)cin >>B[i];
int sum = B[0]+B[N-2];

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

}

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

#define EPS 1e-10

int rel_s_s( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double *x, double *y ) {
	double dn = ( x2 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y2 - y1 );
	double nm = ( x3 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y3 - y1 );

	if ( fabs( dn ) < EPS )
		if ( fabs( nm ) < EPS ) {
			double norm = hypot( x2 - x1, y2 - y1 );
			// double h1 = x1 == x2 ? ( y3 - y1 ) / ( y2 - y1 ) : ( x3 - x1 ) / ( x2 - x1 );
			double h1 = hypot( x3 - x1, y3 - y1 ) / norm;
			// double h2 = x1 == x2 ? ( y4 - y1 ) / ( y2 - y1 ) : ( x4 - x1 ) / ( x2 - x1 );
			double h2 = hypot( x4 - x1, y4 - y1 ) / norm;

			if ( ( h1 < h2 ? h1 : h2 ) < 0.0 && fabs( h1 < h2 ? h2 : h1 ) < EPS ) {
				*x = x1;
				*y = y1;
				return 4;
			} else if ( fabs( ( h1 < h2 ? h1 : h2 ) - 1.0 ) < EPS && 1.0 < ( h1 < h2 ? h2 : h1 ) ) {
				*x = x2;
				*y = y2;
				return 4;
			} else if ( h1 < 0.0 && h2 < 0.0 || 1.0 < h1 && 1.0 < h2 )
				return 3;
			else
				return 5;
		} else
			return 2;
	else
		if ( fabs( nm / dn - 0.5 ) < 0.5 + EPS && fabs( ( ( x3 - x1 ) * ( y2 - y1 ) - ( x2 - x1 ) * ( y3 - y1 ) ) / dn - 0.5 ) < 0.5 + EPS ) {
			*x = x1 + nm / dn * ( x2 - x1 );
			*y = y1 + nm / dn * ( y2 - y1 );

			if ( fabs( ( x2 - x1 ) * ( x4 - x3 ) + ( y2 - y1 ) * ( y4 - y3 ) ) < EPS )
				return 1;
			else
				return 0;
		} else
			return 6;
}

int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		double x0, y0, x1, y1, x2, y2, x3, y3;
		double a, b, c, d, x, y;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3 );

		rel_s_s( x0, y0, x1, y1, x2, y2, x3, y3, &x, &y );

		printf( "%.8f %.8f\n", x, y );
	}

	return 0;
}

Measured memory_bytes: 668
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_N 40
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n, m;
int a[50], b[50];
int dp[102][51][51][2][3];

int dfs(int x, int y, int sx, int sy, int turn, int enc){
    if(dp[x+y-sx-sy][sx][sy][turn][enc] != -INF) return dp[x+y-sx-sy][sx][sy][turn][enc];
    if(x == n && y == m && sx == n && sy == m) return 0;
    int ret;
    if(turn == 0){
        ret = -1*INF;
        if(x != n) ret = dfs(x+1,y,sx,sy,turn^1,0);
        if(x == sx && y == sy){
            if(enc <= 1) ret = max(ret,dfs(x,y,sx,sy,turn^1,enc+1));
            else ret = max(ret,0);
        } else{
            bool stoa = false, stob = false;
            int xx = x-1, yy = y-1;
            int cntx = 0, cnty = 0;
            while(true){
                int end = 0;
                if(yy < sy){
                    end++;
                } else{
                    if(b[yy] == -1){
                        stoa = true;
                    } else if(!stob){
                        cnty += b[yy];
                    }
                    yy--;
                }
                if(xx < sx){
                    end++;
                } else{
                    if(a[xx] == -1){
                        stob = true;
                    } else if(!stoa){
                        cntx += a[xx];
                    }
                    xx--;
                }
                if(end == 2) break;
            }
            ret = max(ret,cntx-cnty+dfs(x,y,x,y,turn^1,0));
        }
    } else{
        ret = INF;
        if(y != m) ret = dfs(x,y+1,sx,sy,turn^1,0);
        if(x == sx && y == sy){
            if(enc <= 1) ret = min(ret,dfs(x,y,sx,sy,turn^1,enc+1));
            else ret = min(ret,0);
        } else{
            bool stoa = false, stob = false;
            int xx = x-1, yy = y-1;
            int cntx = 0, cnty = 0;
            while(true){
                int end = 0;
                if(xx < sx){
                    end++;
                } else{
                    if(a[xx] == -1){
                        stob = true;
                    } else if(!stoa){
                        cntx += a[xx];
                    }
                    xx--;
                }
                if(yy < sy){
                    end++;
                } else{
                    if(b[yy] == -1){
                        stoa = true;
                    } else if(!stob){
                        cnty += b[yy];
                    }
                    yy--;
                }
                if(end == 2) break;
            }
            ret = min(ret,cntx-cnty+dfs(x,y,x,y,turn^1,0));
        }
    }
    dp[x+y-sx-sy][sx][sy][turn][enc] = ret;
    return ret;
}

int main(){
    cin >> n >> m;
    rep(i1,102) rep(i2,51) rep(i3,51) rep(i4,2) rep(i5,3) dp[i1][i2][i3][i4][i5] = -INF;
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    
    cout << dfs(0,0,0,0,0,0) << endl;
}

Measured memory_bytes: 9324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,H,K,L,M,N,T,W,X;
  string S;
  cin >> K >> X;
  
  vector<long long> vec(X);
  vector<long long> sa(X);
  for (long long i=0;i<X;i++) {cin >>vec.at(i);}
  
  A=0;
  B=0;
  
  for (long long i=0;i<X;i++) {
  if (i<X-1) {sa.at(i)=vec.at(i+1)-vec.at(i);}
  else {sa.at(i)=vec.at(0)+K-vec.at(i);}
  //A+=sa.at(i);
   // cout << sa.at(i) << endl;
  if (sa.at(i)>B) {B=sa.at(i);}
  }
  
  cout << K-B << endl;
  
  
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long int
const ll mod = 1e9 + 7;

using namespace std;

ll modexpo(ll a, ll b) {
	ll ans = 1;
	a = a % mod;
	while (b > 0) {
		if (b & 1) ans = (ans*a) % mod;
		b >>= 1;
		a = (a*a) % mod;
	}
	return ans;
}

inline ll inv_mod(ll a) {
	return modexpo(a, mod-2);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m, i, par, ans = 0;
	cin >> n >> m;
	vector<ll> fac(m+1, 1), fac_inv(m+1, 1);
	for (i=1; i<=m; ++i) {
		fac[i] = (i*fac[i-1]) % mod;
		fac_inv[i] = inv_mod(fac[i]);
	}
	par = 1;
	for (i=0; i<=n; ++i) {
		ll temp1 = (((fac[m] * fac_inv[i]) % mod) * fac_inv[m-i]) % mod;
		ll temp2 = (((fac[n] * fac_inv[i]) % mod) * fac_inv[n-i]) % mod;
		ll temp3 = ((fac[m-i] * fac_inv[m-n]) % mod);
		/* cout << i << " " << temp1 << " " << temp2 << " " << temp3 << "\n"; */
		ans = (ans + par*((((((((temp1*temp2) % mod) * fac[i]) % mod) * temp3) % mod) * temp3) % mod) + mod) % mod;
		par *= -1;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 11084
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=998244353;
#define N 444
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
#define ck(x) ((x)>=mod?(x)-mod:(x))
int dp[N][N][2],pw2[N],n,h[N],ans,siz[N];
int st[N],top;
int root;
struct Tree{
	int ch[2];
}t[N];
#define ls t[u].ch[0]
#define rs t[u].ch[1]
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void dfs(int u,int l,int r,int las){
	if(ls)dfs(ls,l,u-1,h[u]);
	if(rs)dfs(rs,u+1,r,h[u]);
	siz[u]=siz[ls]+siz[rs]+1;
	for(int i=0;i<=siz[ls];++i){
		for(int j=0;j<=siz[rs];++j){
			int p=i+j;
			int A=1LL*dp[ls][i][0]*dp[rs][j][0]%mod;
			int B=(1LL*dp[ls][i][1]*(dp[rs][j][0]+dp[rs][j][1])+1LL*dp[ls][i][0]*dp[rs][j][1])%mod;
			dp[u][p][0]=ck(dp[u][p][0]+A);
			dp[u][p][1]=ck(dp[u][p][1]+B);
			dp[u][p+1][0]=ck(dp[u][p+1][0]-A+mod);
			dp[u][p+1][1]=ck(dp[u][p+1][1]+A);
		}
	}
	for(int i=0;i<=siz[u];++i){
		for(int k=0;k<2;++k){
			dp[u][i][k]=1LL*dp[u][i][k]*qpow(pw2[siz[u]-i]-k,h[u]-las)%mod;
		}
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		h[i]=read();
	}
	pw2[0]=1;
	for(int i=1;i<=n;++i){
		pw2[i]=ck(pw2[i-1]<<1);
	}
	for(int i=1;i<=n;++i){
		while(top&&h[i]<h[st[top]])t[i].ch[0]=st[top--];
		if(top)t[st[top]].ch[1]=i;
		st[++top]=i;
	}
	root=st[1];
	dp[0][0][0]=1;
	dfs(root,1,n,0);
	for(int i=0;i<=n;++i){
		ans=ck(ans+ck(dp[root][i][0]+dp[root][i][1]));
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 5128
def find_diff():
    if area % 2 == 0:
        return 0
    if A == B and B == C:
        return A * B
    else:
        sorted_lengths = sorted([A,B,C])
        return sorted_lengths[0] * sorted_lengths[1]


if __name__ == '__main__':
    A, B, C = [int(x) for x in input().split()]
    area = A * B * C
    diff = find_diff()
    print(diff)





Measured memory_bytes: 3188
s=input().split()
a=[]
for i in s:
    if i in ["+","-","*"]:
        a1=str(a.pop())
        a2=str(a.pop())
        t = eval(a2+i+a1)
        a.append(t)
    else:
        a.append(int(i))
print(a.pop())

Measured memory_bytes: 7716
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t n, m;
  cin >> n >> m;

  using city_t = size_t;
  using ken_t = size_t;
  vector <size_t> city_num (n + 1);
  vector <string> id (m);

  vector <tuple <int, city_t, ken_t>> input;
  rep (i, m)
  {
    ken_t p;
    int y;
    cin >> p >> y;
    input.emplace_back (y, i, p);
  }
  sort (ALL (input));

  for (auto && elem : input)
  {
    ken_t p;
    city_t c;
    tie (ignore, c, p) = elem;
    ++ city_num [p];

    ostringstream ss;
    ss << setw (6) << setfill ('0') << p;
    ss << setw (6) << setfill ('0') << city_num [p];
    id [c] = ss.str ();
  }

  for (auto && ans : id)
  {
    cout << ans << endl;
  }
}


Measured memory_bytes: 10736