akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}

int n, m;
ll ans = 1;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin >> n >> m;
	vector<ll> F(n + 3), a(m + 3);
	rep(i, 0, m)
	{
		cin >> a[i + 1];
	}
	F[0] = 0;
	F[1] = 1;
	rep(i, 2, n+3){
		F[i] = (F[i - 1] + F[i - 2])%MOD;
	} 
	a[0] = -1;
	a[m + 1] = n+1;
	rep(i,1,m+2){
		ans = (ans * F[a[i] - a[i - 1]-1]) % MOD;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

// vu64 A;
vector <vu64> counter(2, vu64(64, 0));

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

    int N;
    cin >> N;

    //A.resize(N);
    u64 A;
    u64 maxA = 0;
    rep (i, N)
    {
        cin >> A;
        maxA = MAX(A, maxA);
        rep (j, 64)
        {
            ++counter[A&1][j];
            A >>= 1;
        }
    }

    u64 ans = 0;
    for (int i = 0; i < 64 && (maxA >> i); ++i)
    {
        u64 temp;
        temp = (counter[0][i] * counter[1][i]) % MOD;
        rep (j, i)
        {
            temp = (temp * 2) % MOD;
        }
        ans = (ans + temp) % MOD;
    }

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



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main(){
    string s;cin >>s;
    int a[4] = {};
    rep(i,s.size()){
        if(s.at(i)=='S'){
            a[0]++;
        }else if(s.at(i)=='N'){
            a[1]++;
        }else if(s.at(i)=='E'){
            a[2]++;
        }else{
            a[3]++;
        }
    } 
    bool aFrag = true;
    bool bFrag = true;
    if( (a[0]>0 && a[1]==0)||(a[0]==0 && a[1]>0)) aFrag = false;
    if( (a[2]>0 && a[3]==0)||(a[2]==0 && a[3]>0)) bFrag = false;
    if(aFrag && bFrag){
      cout << "Yes\n";
    }else{
      cout << "No\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

double solve( vector<vector<double> > &dp ,int coins,int head,vector<double> &prob)
{
    if(head < 0)
        return 0.0;
    if(coins < 0)
        return head==0;
    if(dp[coins][head]!=-1)
        return dp[coins][head];
    return dp[coins][head] =(prob[coins]*solve(dp,coins-1,head-1,prob) + (1-prob[coins])*solve(dp,coins-1,head,prob));

}

int32_t main()
{
    int coins;
    cin>>coins;
    vector<double> prob(coins);
    for(int i=0;i<coins;i++)
        cin>>prob[i];
    vector<vector<double> > dp(coins+1,vector<double> (coins+1,-1));

    double ans=0;
    for(int head=(coins+1)/2;head<=coins;head++)
    {
        ans+=solve(dp,coins-1,head,prob);
    }
            cout<<setprecision(10);
        cout<<ans<<endl;
}

Measured memory_bytes: 74076
#include<bits/stdc++.h>
using namespace std;
#define forr(x,n) for(int x = 0; x < n; ++x)
#define pr pair<int,int>
#define ll long long int
const int mod=998244353;
vector<int> v(1e5+1);
vector<int> sz(1e5+1);
int root(int a)
{
    int b=a;
    while(v[a]!=a)
    a=v[a];
    v[b]=a;
    return a;
}
void un(int a,int b)
{
    int root_a=root(a);
    int root_b=root(b);
    v[root_b]=root_a;
    if(root_a!=root_b)
    {
        sz[root_a]+=sz[root_b];
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    forr(i,v.size())
    v[i]=i;
    forr(i,sz.size())
    sz[i]=1;
    int n,m,k;
    cin>>n>>m>>k;
    vector<int> degree(n,0);
    int a,b;
    forr(i,m)
    {
        cin>>a>>b;
        a--;
        b--;
        degree[a]++;
        degree[b]++;
        un(a,b);
    }
    vector<int> bl(n,0);
    forr(i,k)
    {
        cin>>a>>b;
        a--;
        b--;
        if(root(a)==root(b))
        {
            bl[a]++;
            bl[b]++;
        }
    }
    forr(i,n)
    {
        cout<<sz[root(i)]-1-degree[i]-bl[i]<<" ";
    }
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main()
{
	long long int x, y;
	char a[55][55], b[55][55];
	cin >> x >> y;
	bool f = 0;
	for (int i = 0; i < x; i++) for (int j = 0; j < x; j++) cin >> a[i][j];
	for (int i = 0; i < y; i++) for (int j = 0; j < y; j++) cin >> b[i][j];
	for (int i = 0; i <= x - y; i++) {
		for (int j = 0; j <= x - y; j++) {
			if (a[i][j] == b[0][0]) {
				for (int k = 0; k < y; k++) {
					for (int l = 0; l < y; l++) {
						if (a[i + k][j + l] != b[k][l]) {
							f = 1;
							break;
						}
					}
					if (f)break;
				}
				if (!f) {
					cout << "Yes" << endl;
					return 0;
				}
				f = 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n)cin >> a[i];
    int first=a[0],end;
    for(int i=1;i<n-(k-1);i++){
        end = a[k-1+i];
        if(first>=end)COUT("No");
        else COUT("Yes");
        first = a[i];
        
    }
}

Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

struct Timer {
    chrono::system_clock::time_point start;
    int ms;
    Timer(int ms) : start(chrono::system_clock::now()), ms(ms) {}
    bool stop() {
        chrono::system_clock::time_point curr = chrono::system_clock::now();
        double t = static_cast<double>(chrono::duration_cast<chrono::microseconds>(curr - start).count() / 1000.0);
        return t > ms;
    }
};

using ulint = unsigned long long;
struct RandomNumberGenerator {
    mt19937_64 mt;
    RandomNumberGenerator() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}
    ulint operator()(ulint a, ulint b) { // [a, b)
        uniform_int_distribution<ulint> dist(a, b - 1);
        return dist(mt);
    }
    ulint operator()(ulint b) { // [0, b)
        return (*this)(0, b);
    }
    ulint operator()() { return mt(); }
};

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

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

    Timer t(1950);
    RandomNumberGenerator r;

    int d;
    cin >> d;
    vector<lint> c(26);
    for (int i = 0; i < 26; ++i) {
        cin >> c[i];
    }
    vector<vector<lint>> s(d, vector<lint>(26));
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < 26; ++j) {
            cin >> s[i][j];
        }
    }
    vector<lint> ret(d, -1);
    vector<lint> mx(d, -1);
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < 26; ++j) {
            if (chmax(mx[i], s[i][j]))
                ret[i] = j;
        }
    }
    lint score = 0;
    vector<lint> last(26, 0);
    for (int i = 0; i < d; ++i) {
        score += s[i][ret[i]];
        last[ret[i]] = i + 1;
        for (int j = 0; j < 26; ++j) {
            score -= c[j] * (i + 1 - last[j]);
        }
    }

    // cerr << score << endl;

    while (!t.stop()) {
        for (int i = 0; i < 100; ++i) {
            int idx  = r(d);
            int curr = ret[idx];
            int newr = r(26);
            if (curr == newr)
                continue;
            ret[idx]    = newr;
            lint nscore = 0;
            vector<lint> last(26, 0);
            for (int i = 0; i < d; ++i) {
                nscore += s[i][ret[i]];
                last[ret[i]] = i + 1;
                for (int j = 0; j < 26; ++j) {
                    nscore -= c[j] * (i + 1 - last[j]);
                }
            }
            // cerr << nscore << "\n";
            if (nscore < score) // revert
                ret[idx] = curr;
            else
                score = nscore;
        }
    }
    // cerr << score << endl;
    for (int i = 0; i < d; ++i) {
        cout << ret[i] + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
typedef long long ll;
const int MOD = 1000000007;
#define PI 3.141592653589
using namespace std;

int main() {
	ll x;
	cin >> x;
	ll v = 100, y = 0;
	while (v < x) {
		v *= 1.01;
		y++;
	}
	cout << y << endl;
	return 0;
}


Measured memory_bytes: 3632
N = int(input())

X = []
R = {}

for i in range(N):
    S, P = list(input().split())
    if S not in X:
        X.append(S)
    try:
        R[S].append([int (P), i+1])
    except:
        R[S] = []
        R[S].append([int (P), i+1])

for key in R:
    R[key].sort(reverse = True)

X.sort()

for i in X:
    for j in range(len (R[i])):
        print (R[i][j][1])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define M 300005
int read() {
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
	{
	    if(ch=='-') w=-1;
	    ch=getchar();
	}
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
    return s*w;
}
int n,a[M],sum;
int s[M],a1,a2;
bool check(int lim) {
    int p=0;
    for(int i=1;i<=n+1;i++)
	{
	    if(i&1) continue ;
	    if(s[i-1]-s[p]>=lim)
		{
		    if(i==n+1) return 1;
		    if(s[i]<s[p]) p=i;
		}
	}
    return 0;
}
void work() {
    for(int i=1;i<=n;i++) s[i]=s[i-1]+(i&1?a[i]:-a[i]);
    for(int i=2;i<=n;i+=2) a1+=a[i];
    int l=-sum,r=sum,mid,ans;
    do{
	mid=(l+r)>>1;
	if(check(mid)) ans=mid,l=mid+1;
	else r=mid-1;
    }while(l<=r);
    a1+=ans,a2=sum-a1;
}
int main()
{
    n=read();
    for(int i=1;i<=n;i++) {a[i]=read();sum+=a[i];}
    if(!(n&1))
	{
	    int x=0;
	    for(int i=1;i<=n;i+=2) x+=a[i];
	    if(x>a1) a1=x,a2=sum-x;
	    x=0;
	    for(int i=n;i>=1;i-=2) x+=a[i];
	    if(x>a1) a1=x,a2=sum-x;
	}
    else work();
    cout<<a1<<' '<<a2<<'\n';
    return 0;
}

Measured memory_bytes: 2560
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  string s,t;
  cin>>s>>t;
  vector<char> ss(s.size());
  vector<char> tt(t.size());
  loop(i,s.size())ss[i]=s[i];
  loop(i,t.size())tt[i]=t[i];
  sort(all(ss));
  sort(all(tt));
  reverse(all(tt));
  string S,T;
  loop(i,s.size())S+=ss[i];
  loop(i,t.size())T+=tt[i];
  if(S<T)putout("Yes");
  else putout("No");
}

Measured memory_bytes: 256
def print_matrix(m):
    for cnt in range(len(m)):
        print(" ".join(map(str, m[cnt])))


def mul(lhs, rhs):
    n = len(lhs)
    m = len(rhs)
    l = len(rhs[0])

    ret = [
        [
            sum([lhs[i][k] * rhs[k][j] for k in range(m)])
            for j in range(l)
            ]
        for i in range(n)
        ]

    return ret


if __name__ == '__main__':
    from sys import stdin

    n, m, l = (int(_) for _ in stdin.readline().rstrip().split())

    A = []
    for _ in range(n):
        A.append([int(_) for _ in stdin.readline().rstrip().split()])

    B = []
    for _ in range(m):
        B.append([int(_) for _ in stdin.readline().rstrip().split()])

    C = mul(A, B)

    print_matrix(C)



Measured memory_bytes: 6832
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }


        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var cnd = new Dictionary<long, long>();
            for (var i = 0; i < M; ++i)
            {
                var sc = Sarray();
                var s = sc[0] - 1;
                var c = sc[1];
                if (cnd.ContainsKey(s) && cnd[s] != c)
                {
                    WriteLine(-1);
                    return;
                }
                cnd[s] = c;
            }
            var ans = new string('0', (int)N).ToCharArray();
            if (N != 1)
                ans[0] = '1';
            foreach (var c in cnd)
                ans[(int)c.Key] = (char)(c.Value + '0');
            if (N != 1 && ans[0] == '0')
                WriteLine(-1);
            else
                WriteLine(ans);
            //Out.Flush();
        }
    }
}

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

using namespace std;

int n, m, l, a, b, d[100010], dt[100010][20];

int main()
{
    scanf("%d", &n);
    for(int i = 0 ; i < n ; i++ ) scanf("%d", d+i);
    scanf("%d%d", &l, &m);
    for(int i = 0 ; i < n ; i++ )
        dt[i][0] = (int)(upper_bound(d+i, d+n, d[i]+l) - d) - 1;
    for(int k = 1 ; k < 20 ; k++ ) for(int i = 0 ; i < n ; i++ )
        dt[i][k] = dt[dt[i][k-1]][k-1];
    while( m-- )
    {
        int ans = 1;
        scanf("%d%d", &a, &b), a--, b--;
        if( a < b ) swap(a, b);
        for(int i = 19 ; i >= 0 ; i-- )
            if( dt[b][i] < a ) b = dt[b][i], ans+=(1<<i);
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define each(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define out(x) rep(i, 0, (x).size()) cout << (x)[i] << ((i != (x).size() - 1) ? " " : "\n")
const double PI = 3.14159265;
const int MAXN = 1 << 15;
const int LINF = 1LL << 60;
const int INF = 1 << 30;
#define Pr(a) (#a) << "=" << (a) << " "
#define pr(a) cout << Pr(a) << '\n'
///////////////////////////////////////////////////////
signed main() {
  int n;
  cin >> n;
  char pre, now;
  cin >> pre;
  n--;
  int cnt = 1;
  while (n--) {
    cin >> now;
    if (pre != now) {
      pre = now;
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 256
line = input().split(' ')
N = int(line[0])
Y = float(line[1])/10000

num_list = ([i, j, N-i-j] for i in range(N+1) for j in range(N+1-i))

for i in num_list:
	if (i[0]+float(i[1])/2+float(i[2])/10) == Y:
		print(" ".join(map(lambda x: str(int(x)), i)))
		break
else:
	print('-1 -1 -1')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
//#define mod 987654321
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-9
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 2000025

set<II> S;

int n, m;

bool inside(int r, int c){
	return r >= 1 && c >= 1 && r <= n && c <= m;
}

int main() {

//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	vector<int> V1, V2;
	V1.pb(1); V1.pb(2); V1.pb(n); V1.pb(n - 1);
	V2.pb(1); V2.pb(2); V2.pb(m); V2.pb(m - 1);

	ll res = n * 1ll * m;
//	cout << res << endl;
	Rep(i, sz(V1)) Rep(j, sz(V2)){
		int u = V1[i], v = V2[j];
		if(inside(u, v) && !S.count(mp(u,v))){
			S.insert(mp(u, v));
			int number = 0;
			for(int addr = -1; addr <= 1; addr++) for(int addc = -1; addc <= 1; addc++){
				int rr = u + addr, cc = v + addc;
				if(inside(rr, cc)){
					number++;
				}
			}
			if(number % 2 == 0){
//				cout << u << " " << v << endl;
				res--;
			}
		}
	}

//	cout << res << endl;

	if(m > 1) res -= max(0, n + n - 8);
	if(n > 1) res -= max(0, m + m - 8);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)			
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}	
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
int main(){
	int k,a,b;cin>>k>>a>>b;
	if(b-a<=1){
		cout<<1+k<<endl;
	}else{
		if(1+k<a)cout<<1+k<<endl;
		else{
			ll ans=a+1ll*((1+k-a)/2)*(b-a)+((1+k-a)%2);
			cout<<ans<<endl;
		}
	}
	return 0;
}

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

#define DIV 1000000007
using namespace std;
using ll = long long;

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

    vector<ll> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    if (a[0] > x) {
        ans += a[0] - x;
        a[0] = x;
    }
    for (int i = 1; i < N; i++) {
        if (a[i - 1] + a[i] > x) {
            ans += a[i] + a[i - 1] - x;
            a[i] -= (a[i - 1] + a[i]) - x;        
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();return 0;}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(int i=0;i<(int)n;++i)
#define _rep1(i,k,n) for(int i=k;i<(int)n;++i)
#define _rep2(i,k,n,d) for(int i=k;d>0?i<(int)n:i>(int)n;i+=d)
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

template<class T>
class SegmentTree{
private:
    ll n = 1;
    function<T(T, T)> dot;
    T unit;
    vector<T> tree;
public:
    constexpr SegmentTree(const vector<T> &A, function<T(T, T)> dot, T unit) : dot(dot), unit(unit) {
        while(n < (ll)A.size()) n <<= 1;
        tree.resize(2 * n, unit);
        copy(A.begin(), A.end(), tree.begin() + n);
        rep(i, n - 1, 0, -1) tree[i] = dot(tree[i << 1], tree[i << 1 | 1]);
    }
    constexpr void update(ll i, T v){
        i += n;
        tree[i] = v;
        while(i >>= 1) tree[i] = dot(tree[i << 1], tree[i << 1 | 1]);
    }
    constexpr void add(ll i, T v){update(i, tree[i + n] + v);}
    constexpr T sum(ll l, ll r) const {
        l += n; r += n;
        T l_val = unit, r_val = unit;
        while(l < r){
            if(l & 1) l_val = dot(l_val, tree[l++]);
            if(r & 1) r_val = dot(tree[--r], r_val);
            l >>= 1; r >>= 1;
        }
        return dot(l_val, r_val);
    }
};

void solve(){
    ll n, q; cin >> n >> q;
    vector<ll> C(n);
    rep(i, n){
        cin >> C[i];
        C[i] --;
    }
    vector<tuple<ll, ll, ll>> queries(q);
    rep(i, q){
        ll l, r; cin >> l >> r;
        queries[i] = make_tuple(l - 1, r, i);
    }
    sort(queries.rbegin(), queries.rend());

    vector<ll> A(n), next(n, -1), used(n, -1);
    rep(i, n - 1, -1, -1){
        ll c = C[i];
        A[i] = 1;
        if(used[c] != -1){
            next[i] = used[c];
            A[used[c]] = 0;
        }
        used[c] = i;
    }
    SegmentTree<ll> tree(A, [](ll a, ll b){return a + b;}, (ll)0);

    vector<ll> ans(q);
    rep(l, n){
        while((!queries.empty()) && get<0>(queries.back()) == l){
            auto [l, r, i] = queries.back();
            queries.pop_back();
            ans[i] = tree.sum(l, r);
        }
        if(next[l] != -1){
            tree.add(next[l], 1);
        }
    }
    for(auto a : ans) cout << a << '\n';
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



int h, w;
string s[1010];
void solve(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> s[i];
	}
	
	int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '.') continue;
			bool ok = 0;
			for(int k = 0; k < 4; k++){
				int nx = i+dx[k], ny = i+dy[k];
				if(i+dx[k]<0 || i+dx[k]>=h) continue;
				if(j+dy[k]<0 || j+dy[k]>=w) continue;
				if(s[i+dx[k]][j+dy[k]] == '.') continue;
				ok = 1;
			}
			if(!ok){
				cout << "No" << endl;
				return;
			}
		}
	}
	cout << "Yes" << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

int main()
{
       int test,i,j;
       int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
       
       cin>>test;
       cout<<arr[test-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int inf = 1e9;
int n;
int p[20001];
int a[20001];
int b[20001];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", p + i);
        a[p[i]] += i;
        
        a[i] += 1 + i * 30001;
        b[i] += inf - i * 30001;
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d ", a[i]);
    }
    printf("\n");
    for (int i = 1; i <= n; ++i) {
        printf("%d ", b[i]);
    }
    printf("\n");
	return 0;
}


Measured memory_bytes: 896
import sys
import math
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
a,b=map(int,input().split())
c=int((2*a-b)/3)
if (a+b)%3!=0:
    print('0')
    sys.exit()
if c<0 or (a+b)//3<c:
    print('0')
    sys.exit()
print(cmb((a+b)//3,c)%1000000007)

Measured memory_bytes: 102028
#include <algorithm>
#include <iostream>

using namespace std;

bool is_ok(long long N, long long k) {
  while (N % k == 0) {
    N /= k;
  }
  return N % k == 1;
}

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

  long long ans = 0;
  // N の約数を調べる
  for (long long k = 1; k * k <= N; k++) {
    if (N % k != 0) {
      continue;
    }
    if (k != 1) {
      ans += is_ok(N, k);
    }
    if (N / k != k) {
      ans += is_ok(N, N / k);
    }
  }

  // N-1 の約数を調べる
  for (long long k = 1; k * k <= N - 1; k++) {
    if ((N - 1) % k != 0) {
      continue;
    }
    if (k != 1) {
      ans++;
    }
    if ((N - 1) / k != k) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3644
N = int(input())

C = [0] * (60001)

for x in range(1, 100):
    for y in range(x, 100):
        for z in range(y, 100):
            v = x * x + y * y + z * z + x * y + y * z + z * x
            k = 6
            if x == y == z:
                k = 1
            elif x == y or y == z:
                k = 3
            C[v] += k

for i in range(1, N + 1):
    print(C[i])


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  int a,b; cin >> a >> b;
  if(a <= b) cout << a << endl;
  else cout << a-1 << endl;
}

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

int main(){
  int N, count;
  cin >> N;
  int Max = 0;
  count = 0;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  for(int i=0; i<vec.size();i++){ 
    if(Max < vec.at(i)){
      Max = vec.at(i);
    }
  }
  for(int i=1; i<= Max; i++){
    for(int j=0; j<vec.size(); j++){
      if(i == vec.at(j)){
        count += 1;
        break;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n;
    cin>>n;
    vi d(n);
    cin>>d;
    ll s=0;
    REP(i,n-1){
        REP(j,i+1,n){
            s+=d[i]*d[j];
        }
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
const int N=1e5+5;
vector<int>g[N];
int n,m;
int corr=0, penal=0;

int32_t main(){
	IOS;
	//code
	cin>>n>>m;
	for(int i=0;i<m;i++){
	    int p;
	    string s;
	    cin>>p>>s;
	    if(s=="AC")
	        g[p-1].push_back(1);
	    else
	        g[p-1].push_back(-1);
	}
	for(int i=0;i<n;i++){
	    if(g[i].size()){
	        int ind=0, cou=0;
	        while(g[i][ind]!=1 && ind<g[i].size()-1){
	            cou++;
	            ind++;
	        }  
	        if(g[i][ind]==1){
	            corr++;
	            penal+=cou;
	            continue;
	        }
	    }
	}
	cout<<corr<<" "<<penal<<endl;
	//code
	return 0;

}



Measured memory_bytes: 5760
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))

using namespace std;

const int maxn = 10100;

int a[maxn];

int main()
{
    int n;
    while(scanf("%d", &n) != EOF)
    {
        for(int i = 0; i < n; i ++)
        {
            scanf("%d", &a[i]);
        }
        sort(a, a + n);
        LL sum = 0;
        for(int i = 0; i < n; i ++)
        {
            if(a[i] > sum + 1)
            {
                break;
            }
            sum += a[i];
        }
        printf("%lld\n", sum + 1);
    }
    return 0;
}

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

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>K;
	int x=0;
	while(K--){
		cin>>N>>M;
		if(M<=64){
			vector<int>v(M+1);
			for(int i=M-1;i>0;i--){
				if(i*2>M||i==1)v[i]=!v[i+1];
				else if(v[i+1]+v[i*2]==1)v[i]=2;
				else if(!v[i+1]||!v[i*2])v[i]=1;
			}
			x^=v[N];
		}
		else{
			map<long long int,pair<int,int>>mp;
			mp[M]={0,1};
			long long int box=M/2;
			while(box>64){
				long long int a=box+1;
				long long int b=box*2;
				
				
				int fst=0;
				auto ita=*mp.lower_bound(a);
				auto itb=*mp.lower_bound(b);
				int numa=0,numb=0;
				if(ita.first%2==a%2){
					numa=ita.second.first;
				}
				else{
					numa=ita.second.second;
				}
				if(itb.first%2==b%2){
					numb=itb.second.first;
				}
				else{
					numb=itb.second.second;
				}
				if(numa+numb==1)fst=2;
				else if(!numa||!numb)fst=1;
				//cout<<box<<" "<<numa<<" "<<numb<<endl;
				
				int snd=0;
				b=box*2-2;
				auto itc=*mp.lower_bound(b);
				numa=0,numb=0;
				if(itc.first%2==b%2){
					numb=itc.second.first;
				}
				else{
					numb=itc.second.second;
				}
				if(fst+numb==1)snd=2;
				else if(!fst||!numb)snd=1;
				mp[box]={fst,snd};
				box/=2;
			}
			vector<int>v(box+1);
			for(int i=box;i>0;i--){
				int a,b;
				if(i+1>box){
					auto ita=*mp.lower_bound(i+1);
					if(ita.first%2==(i+1)%2){
						a=ita.second.first;
					}
					else{
						a=ita.second.second;
					}
				}
				else{
					a=v[i+1];
				}
				if(i*2>box){
					auto itb=*mp.lower_bound(i*2);
					if(itb.first%2==(i*2)%2){
						b=itb.second.first;
					}
					else{
						b=itb.second.second;
					}
				}
				else{
					b=v[i*2];
				}
				if(a+b==1)v[i]=2;
				else if(!a||!b)v[i]=1;
			}
			if(N<=box){
				x^=v[N];
			}
			else{
				auto it=*mp.lower_bound(N);
				if(it.first%2==N%2)x^=it.second.first;
				else x^=it.second.second;
			}
		}
		//cout<<x<<endl;
	}
	if(x)cout<<"mo3tthi"<<endl;
	else cout<<"tubuann"<<endl;
	return 0;
}


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

#define MAX_N 10000
#define MAX_L 2000

int n;
int c[MAX_N][MAX_L];
int K[MAX_N];
string S[MAX_N];

int main() {
	while (true) {
		cin >> n;
		for (int i = 0; i < MAX_N; i++) {
			for (int j = 0; j < MAX_L; j++) {
				c[i][j] = 10;
			}
		}
		for (int i = 0; i < MAX_N; i++) {
			K[i] = 0;
		}
		for (int i = 0; i < MAX_N; i++) {
			S[i] = "";
		}
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> S[i];
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < S[i].size(); j++) {
				if (S[i][j] == '.') {
					c[i][j] = 3;
					K[i]++;
				}
				else {
					c[i][j] = 0;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < S[i].size(); j++) {
				if (c[i][j] == 3 && c[i][j + 1] == 0) {
					c[i][j] = 1;
				}
			}
		}
		int zenkai = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < S[i].size(); j++) {
				if (c[i][j] == 1) {
					zenkai = i;
					for (int k = i + 1; k < n; k++) {
						if (c[k][j] == 1) {
							for (int l = zenkai + 1; l < k; l++) {
								c[l][j] = 2;
							}
							zenkai = k;
						}
						if (c[k][j] == 0) {
							break;
						}
					}
				}
			}
		}

		int cnt = 0;

		for (int i = 0; i < n; i++) {
			cnt = 0;
			for (int j = 0; j < S[i].size(); j++) {
				if (c[i][j] == 0) {
					cout << S[i][cnt + K[i]];
					cnt++;
				}
				if (c[i][j] == 1) {
					cout << '+';
				}
				if (c[i][j] == 2) {
					cout << '|';
				}
				if (c[i][j] == 3) {
					cout << ' ';
				}
			}
			cout << endl;
		}
	}
	return 0;
}

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

using P = pair<int, int>;

int nmul(int x, int y, int z){
    return x*y*z;
}

int main(){
    int n; cin >> n;
    vector<int> M(n+1);
    int dummy;
    for(int i=0; i<n; ++i){
        cin >> M[i] >> dummy;
    }
    M[n] = dummy;
    vector<vector<int>> dp(n+1, vector<int>(n+1, numeric_limits<int>::max()));
    // dp[i][i+l] = M_i から M_{i+l} までの行列乗算の最適コスト
    for(int l=0; l<n; ++l) dp[l][l] = 0;

    for(int L=1; L<n; ++L){
        for(int l=0; l<n-L; ++l){
            for(int k=0; k<L; ++k){
                dp[l][l+L] = min(dp[l][l+L], dp[l][l+k] + dp[l+k+1][l+L] + nmul(M[l],M[l+k+1],M[l+L+1]));
            }
        }
    }
    cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> a_(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a_[i] = a[i];
	}
	
	sort(a_.begin(), a_.end(), [](int& i, int& j) {return i > j; });

	for (int i = 0; i < n; i++) {
		if (a_[0] == a[i])cout << a_[1] << endl;
		else cout << a_[0] << endl;
	}

}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int n,h,w;
	cin >> n >> h >> w;

	cout << (n-h+1)*(n-w+1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a = 0;
	int b = 0;
	int c = 0;
	cin >> a >> b >> c;
	if (a < b&&b< c){
		cout << "Yes" <<endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

const ll p = 1e9+7;

ll d[55][55];
ll n, a[55], b[55];
ll at[55][55];

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

	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
		cin >> b[i];

	for (int i = 0; i <= 50; ++i)
		for (int j = 0; j <= 50; ++j) {
			d[i][j] = 60;
			if (i == j)
				d[i][j] = -1;
		}

	for (int i = 0; i <= 50; ++i)
		for (int j = 1; j <= 50; ++j) {
			d[i][i%j] = min(d[i][i%j], 1LL*j);
		}

	for (int l = 1; l <= 50; ++l)
		for (int i = 0; i+l <= 50; ++i) {
			for (int j = i+1; j < i+l; ++j)
				d[i+l][i] = min(d[i+l][i], max(d[i+l][j], d[j][i]));
		}


	ll ans = 0;

	for (int i = 0; i < n; ++i)
		at[i][a[i]] = 1;

	for (int k = 50; k >= 0; --k) {
		bool z = 0;
		//am i forced to use k sometime?
		for (int i = 0; i < n; ++i) {
			int best = 60;
			for (int j = 0; j <= 50; ++j)
				if (at[i][j] == 1)
					best = min(1LL*best, d[j][b[i]]);
			if (best == k)
				z = 1;
			if (best == 60) {
				cout << "-1\n";
				return 0;
			}
		}

		if (z == 1) {
			ans += (1LL<<k);
			for (int i = 0; i < n; ++i)
				for (int j = 0; j <= 50; ++j)
					at[i][j%k] |= at[i][j];
		}

		for (int i = 0; i < n; ++i)
			for (int j = 0; j <= 50; ++j)
				if (d[j][b[i]] >= k)
					at[i][j] = 0;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> vec = {500,100,50,10,5,1};
    int N;
    cin >> N;
    while(N != 0){
        N = 1000 - N;
        int ans = 0;
        for(int i=0; i<6; i++){
            while(vec[i] <= N){
                N -= vec[i];
                ans++;
            }
        }
        cout << ans << enld;
        cin >> N;
    }
    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  string s,t;
  cin>>s>>t;
  int n,m;
  n = s.size();
  m = t.size();
  
  vector<char> temps;
  vector<char> tempt;
  REP(i,n){
    temps.push_back(s[i]);
  }
  sort(ALL(temps));
  REP(i,m){
    tempt.push_back(t[i]);
  }
  sort(ALL(tempt), greater<char>());
  
  s="",t="";
  REP(i,n){
    s += temps[i];
  }
  REP(i,m){
    t += tempt[i];
  }
  if(s<t){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
    char c;  cin >> c;
    if(c == 'A')  cout << "T";
    else if(c == 'T')  cout << "A";
    else if(c == 'C')  cout << "G";
    else  cout << "C";
    return 0;
}


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

#define fi first
#define se second

const int N = 100100;

using namespace std;

int n;
long long a[N];
long long d[N];
long long E, T;
long long pref[N];

int main()
{
        ios_base::sync_with_stdio(false);

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

        cin >> n >> E >> T;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        long long inf = 1e18;
        pref[0] = inf;
        for(int i = 1, h = 0; i <= n; i++){
                d[i] = inf;
                pref[i] = pref[i - 1];
                while(2 * (a[i] - a[h + 1]) >= T){
                        h += 1;
                }
                if(h > 0){
                        d[i] = 3 * a[i] + pref[h];
                }

                for(int dx = -1; dx <= 1; dx++){
                        int j = h + dx;
                        if(j < 1 || j > i){
                                continue;
                        }
                        long long D = a[i] - a[j];
                        d[i] = min(d[i], d[j - 1] + D + max(D * 2, T) + a[j] - a[j - 1]);
                }
                pref[i] = min(pref[i], - 2 * a[i] - a[i - 1] + d[i - 1]);
        }
        cout << d[n] + E - a[n] << "\n";
}


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

int main() 
{
  string s;
  cin >> s;
  int n = s.length();
  int count[2] = {};
  rep (i, n) ++count[(int)s[i] - 48];
  cout << 2 * min(count[0], count[1]) << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
#define PI 3.141592653589

int main()
{
	double r,S,l ;

	cin >>  r ;

	S = (r * r) * PI;
	l = (2.0 * r) * PI ;
	
	cout << fixed  << S << ' ' << fixed << l << endl; 

	return 0;
}

Measured memory_bytes: 1284
from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())

    xs = set()
    ys = set()
    rect = []
    for _ in range(N):
        x1, y1, x2, y2 = map(int, input().split())
        xs.add(x1)
        xs.add(x2)
        ys.add(y1)
        ys.add(y2)
        rect.append((x1, y1, x2, y2))
    X = sorted(xs)
    Y = sorted(ys)
    dx = {x: i for i, x in enumerate(X)}
    dy = {y: i for i, y in enumerate(Y)}

    H = len(xs)
    W = len(ys)
    grid = [[0] * (W + 1) for _ in range(H + 1)]
    for x1, y1, x2, y2 in rect:
        grid[dx[x1]][dy[y1]] += 1
        grid[dx[x2]][dy[y1]] -= 1
        grid[dx[x1]][dy[y2]] -= 1
        grid[dx[x2]][dy[y2]] += 1

    for i in range(H):
        grid[i] = list(accumulate(grid[i]))
    for i in range(H):
        for j in range(W):
            grid[i + 1][j] += grid[i][j]

    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j]:
                ans += (X[i + 1] - X[i]) * (Y[j + 1] - Y[j])
    return ans


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 343844
import bisect
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
s = sum(a)
if x > s:
    print(N - 1)
elif s == x:
    print(N)
else:
    a_cum = [0] * (N + 1)
    for i in range(N):
        a_cum[i + 1] = a_cum[i] + a[i]
    ans = bisect.bisect_right(a_cum, x)
    print(ans - 1)


Measured memory_bytes: 38384