akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

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

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

ll gcd(ll a, ll b){
    if (a < b) {
        ll tmp = a;
        a = b;
        b = tmp;
    }
    if (b == 0) return a;
    return gcd(b, a  % b);
}

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

    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> r(N), l(N);
    REP(i, N){
        if (i == 0){
            l[0] = A[0];
            r[N - 1] = A[N - 1];
        }
        else{
            l[i] = gcd(l[i - 1], A[i]);
            r[N - 1 - i] = gcd(r[N -  i], A[N - 1 - i]);
        }
    }
    ll ans = 1;
    REP(i, N){
        if (i == 0) ans = max(ans, r[1]);
        else if (i == N - 1) ans = max(ans, l[N - 2]);
        else ans = max(ans, gcd(l[i - 1], r[i + 1]));
    }
    cout << ans << endl;
    //cout << gcd(21, 14) << endl;
    // REP(i, N) cout << r[i] << " ";
    // cout << endl;
    // REP(i, N) cout << l[i] << " ";

    return 0;
}

Measured memory_bytes: 2560
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in();vector<ll>a(n);for(int i=0;i<n;++i)a[i]=in();
    sort(a.begin(),a.end());
    cout<<(unique(a.begin(),a.end())-a.begin()==n?"YES":"NO")<<endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int n, ma;
V<int> e[N];
V<P<int, int>> v;
map<P<int, int>, int> C;
void dfs(int a, int p, int c){
  int _c = -1;
  for(int b:e[a]) if(b!=p){
    _c++;
    if(_c == c) _c++;
    (a<=b ? C[mp(a, b)] : C[mp(b, a)]) = _c;
    dfs(b, a, _c);
  }
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    if(a>b) swap(a, b);
    e[a].pb(b);
    e[b].pb(a);
    maxs(ma, sz(e[a]));
    maxs(ma, sz(e[b]));
    v.pb(mp(a, b));
  }
  dfs(0, -1, -1);
  printf("%d\n", ma);
  for(auto p:v) printf("%d\n", C[p]+1);
}

Measured memory_bytes: 15868
from collections import defaultdict,deque
import math
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)

def main():
    n = int(input())
    a=[int(i) for i in input().split()]
    money = 1000
    for i in range(n-1):
        stocks = 0
        if(a[i] < a[i+1]):
            stocks = money//a[i]
        money += stocks*(a[i+1]-a[i])
    print(money)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9464
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	// 最大公約数を求める
	r := a % b
	for r != 0 {
		a = b
		b = r
		r = a % b
	}

	if b == 1 {
		fmt.Println(1)
		return
	}
	g := b
	// 素因数分解していく
	var primes []int
	for i := 2; i*i <= g; i++ {
		if g%i == 0 {
			primes = append(primes, i)
		} else {
			continue
		}
		for g%i == 0 {
			g /= i
		}
	}
	// 最後に残るやつを処理
	if g > 1 {
		primes = append(primes, g)
	}
	fmt.Println(len(primes) + 1)
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>)
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) a.size()
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl
#define debgp(a) cout<<#a<<" "<<a.fi<<" "<<a,se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(const auto&y:a){for(const auto&x:y)cout<<x<<" ";cout<<endl;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define PQ priority_queue
typedef long long ll;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<PL> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T gcd(T a,T b){return (b==0?a:gcd(b,a%b));}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*a;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  VL a(n);
  rep(i,n)cin>>a[i];

  VL range,tf(n,0);
  int cnt=0;
  rep(i,n)if(a[i]==i+1)tf[i]=1;
  rep(i,n){
    if(tf[i])cnt++;
    else{
      range.pb(cnt);
      cnt=0;
    }
  }
  if(*tf.end()-1)range.pb(cnt);

  int ans=0;
  for(auto num:range){
    ans+=num/2+num%2;
  }
  out(ans);

  
  
  
  return 0;
}


Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
struct edge{int from,to,t;};

#define MAX_N 100005

typedef long long ll;

struct UF{
  int group;
  
  int par[MAX_N];
  int flg[MAX_N];
  int size[MAX_N];
  ll dat[MAX_N];
  
  void init(int n){
    group=n;
    for(int i=0;i<MAX_N;i++){
      par[i]=i;
      flg[i]=0;
      size[i]=1;
      dat[i]=0;
    }
  }
  
  int find(int x){
    if(x==par[x])return x;
    return find(par[x]);
  }
  
  bool same(int x,int y){
    return find(x)==find(y);
  }
  
  void unite(int x,int y,int tim=0){
    x=find(x);
    y=find(y);
    if(x==y)return;

    
    group--;
    if(size[x]<size[y])swap(x,y);
    
    par[y]=x;

    dat[y]+= (ll)(tim-flg[y])*size[y];
    
    dat[x]+= (ll)(tim-flg[x])*size[x];

    dat[y]-= dat[x];
    
    flg[x]=tim;

    size[x]+=size[y];
  }
  
  int getSize(int x){
    x=find(x);
    return size[x];
  }
  
  ll getSize(int x,int tim){
    ll res=0;
    while( x!=par[x]){
      res+=dat[x];
      x=par[x];
    }
    res+= (ll)(tim-flg[x])*size[x] + dat[x];
    return res;
  }
};

int N,M,T;
vector<edge> E[MAX_N];
vector<edge> G[MAX_N];
vector<int> g[MAX_N];
map<int,int> h[MAX_N];

UF tree;

int d[MAX_N];

int main(){
  scanf("%d %d %d",&N,&M,&T);
  for(int i=0;i<M;i++){
    int a,b,t;
    scanf("%d %d %d",&a,&b,&t);
    a--,b--;
    G[a].push_back( (edge){a,b,t} );
    G[b].push_back( (edge){b,a,t} );
    E[t].push_back((edge){a,b,t});
  }
  

  
  queue<int> Q;
  Q.push(0);
  memset(d,-1,sizeof(d));
  d[0]=0;
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    g[ d[pos] ].push_back(pos);
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(d[e.to]!=-1)continue;
      if(e.t<=d[pos])continue;
      d[e.to]=d[pos]+1;
      Q.push(e.to);
    }
  }

  
  tree.init(N);
  for(int i=100000;i>=T;i--){
    for(int j=0;j<(int)E[i].size();j++){
      tree.unite(E[i][j].from,E[i][j].to , 0 );
    }
  }
  

  
  for(int i=T-1;i>=0;i--){
    for(int j=0;j<(int)E[i].size();j++){
      tree.unite(E[i][j].from,E[i][j].to , T-i );
    }
  }

  //  for(int v=0;v<N;v++)
  //    cout<<v<<' '<<tree.flg[v]<<' '<<tree.size[v]<<' '<<tree.dat[v]<<endl;
  
  ll maxm=0;
  for(int i=0;i<N;i++){
    if(d[i]==-1||d[i]>T)continue;
    
    ll count=tree.getSize(i,T);
    //cout<<i<<' '<<count<<endl;
    maxm=max(maxm,count);
  }
  
  cout<<maxm<<endl;
  return 0;
}

Measured memory_bytes: 28004
H,W,K = map(int,input().split())
s = [list(input()) for i in range(H)]
ans = 0

for i in range(1<<H):
  for j in range(1<<W):
    cnt = 0
    for h in range(H):
      for w in range(W):
        if (i>>h)&1 == 1 and (j>>w)&1==1:
          if s[h][w]=='#':
            cnt += 1
    if cnt==K:
      ans += 1
print(ans)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
#include<string>
using namespace std;
typedef long long int ll;
#pragma GCC optimize "trapv"
#define fi first
#define sec second
#define pb push_back
//#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solve(){
	int n,m,k;
	cin>>n>>m>>k;
	ll a[n+1];
	ll b[m+1];
	a[0]=0;
	b[0]=0;
	for(int  i=1;i<=n;i++){
		ll num;
		cin>>num;
		a[i]=a[i-1]+num;
	}
	for(int  i=1;i<=m;i++){
		ll num;
		cin>>num;
		b[i]=b[i-1]+num;
	}
	int ans=0;
	for(int i=0;i<=n;i++){
		ll taken=a[i];
		if(taken>k){continue;}
		else{
			ll tobe=k-taken;
			auto it=upper_bound(b,b+m+1,tobe);
			int elems=it-b-1;
			ans=max(ans,i+elems);
		}
	}
	cout<<ans<<endl;
}
int main(){
	fio;
	int test;
	//cin>>test;
	test=1;
	while(test--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 6704
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
const int maxn = 200005;  
long long f[maxn], s[maxn];  
long long ans;  
int main(){  
    int n, x; cin >> n;  
    for(int i = 1; i <= n; i++){  
        scanf("%d", &x);  
        f[i] = f[i-1] + x;    
        s[i] = s[i-1] ^ x;   
    }  
    int l = 1;  
    ans=0;  
    for(int r = 1; r <= n; r++){     
        for(; f[r] - f[l-1] != (s[r] ^ s[l-1]); l++);
        ans += r - l + 1;  
    }  
    printf("%lld\n", ans);  
    return 0;  
}  

Measured memory_bytes: 3328
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

bool ispal(string str) {
	string cp = str;
	reverse(cp.begin(), cp.end());
	return cp == str;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	string str;
	cin >> str;
	cout << (ispal(str) && ispal(str.substr(0, str.size() / 2))? "Yes": "No") << '\n';
}



Measured memory_bytes: 256
#include <iostream>
#define llint long long

using namespace std;

llint n, t;
llint h[100005];
llint L[100005], I[100005];

int main(void)
{
  cin >> n >> t;
  for(int i = 1; i <= n; i++) cin >> h[i];

  L[1] = h[1], I[1] = 0;
  for(int i = 2;i <= n; i++){
    I[i] = I[i-1] + h[i-1];
    if(h[i] <= L[i-1]) L[i] = L[i-1];
    else L[i] = h[i];
  }

  for(int i = 1; i <= n; i++){
    if(t < I[i]){
      cout << 1 << endl;
      continue;
    }
    else{
      llint ans = (t-I[i])/L[i] + 1;
      if((t-I[i])%L[i] >= h[i]) ans++;
      cout << ans << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 5428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m = 1000000000+7;
ll pow_mod(ll a, ll b) {
    if (b == 0) return 1;
    ll res = pow_mod(a, b/2);
    res = (res*res) % m;
    if (b % 2 == 0) return res;
    return (res*a) % m;
}
map<ll, ll> mm;
ll nbikkuri(ll n) {
    if (n == 0) return 1;
    if (mm.find(n) != mm.end()) return mm[n];
    return mm[n] = (nbikkuri(n-1)*n)%m;
}
ll nCr(ll n, ll r) {
    // (n!)/(r!)/((n-r)!)
    ll X = nbikkuri(n), Y = (nbikkuri(r)*nbikkuri(n-r))%m;
    return X*pow_mod(Y, m-2)%m;
}
int main () {
    ll S, ans = 0;
    cin >> S;
    for (int i = 1; i*3 <= S; i++) {
        int SS = S-i*3;
        ans += nCr(SS+i-1, SS);
        ans %= m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3744
use std::cmp::min;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let mut a: i64 = sc.read();
    let mut b: i64 = sc.read();
    let mut k: i64 = sc.read();

    let eat = min(a, k);
    a -= eat;
    k -= eat;

    let eat = min(b, k);
    b -= eat;
    k -= eat;

    println!("{} {}", a, b);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define REV(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector <string>
#define vvs vector <vector<string>>
#define pq  priority_queue<int>
using ll = long long;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 2000000000;
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/*---------------------template----------------------*/
/*----------------------end--------------------------*/
/* --------------------ライブラリ--------------------*/
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }
    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
/*---------------------臨時--------------------------*/
/*----------------------end-------------------------*/
signed main(){
  int A,B,H;cin>>A>>B>>H;
  printf("%ld",(A+B)*H/2);
}


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

const int N = 1e5 + 100;

int n, l, t, dex, x[N], w[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> l >> t;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> w[i];
		if (w[i] == 1)
			dex = (dex + (t + x[i]) / l);
		else
			dex = (dex - (t - x[i] + l - 1) / l);
		dex = (dex % n + n) % n;
		x[i] = ((x[i] + (w[i] == 1? : -1) * t) % l + l) % l;
	}
	sort(x, x + n);
	for (int i = 0; i < n; i++)
		cout << x[(dex + i) % n] << '\n';
}

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

typedef long long int64;
typedef pair<int,int> PII;

int n,m;

vector<PII> biEdge[123456];
vector<int> uniEdge[123456];

vector<int> nodes[123456];

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

vector<Edge> edge[2345678];

//a vertex can reach all
// <- <- <- nadj
// -> -> -> nadj

void addE(int u,int v,int w){
	edge[u].push_back(Edge(v,w));
}

int findNode(int u,int id,int tp){
	int pos = lower_bound(biEdge[u].begin(),biEdge[u].end(),make_pair(id,-1)) - biEdge[u].begin();

	return nodes[u][2 + biEdge[u].size() * tp + pos];
}

int indeg[2345678];

int main(){
	cin>>n>>m;

	rep(it,m){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		--u,--v;

		if(w==2){
			biEdge[u].push_back(make_pair(it,v));
			biEdge[v].push_back(make_pair(it,u));
		} else {
			uniEdge[u].push_back(v);
		}
	}

	int V = 0;
	rep(i,n){
		nodes[i].push_back(V++); //in:0
		nodes[i].push_back(V++); //out:1

		sort(biEdge[i].begin(),biEdge[i].end());

		rep(it,biEdge[i].size()){
			nodes[i].push_back(V++);
			nodes[i].push_back(V++);
			nodes[i].push_back(V++);
		}

		int m = biEdge[i].size();

		rep(it,biEdge[i].size()){
			int lt = it + 2;
			int rt = m + it + 2;
			int ct = m * 2 + it + 2;

			if(it>0)
				addE(nodes[i][lt],nodes[i][lt-1],0);
			if(it+1<m)
				addE(nodes[i][rt],nodes[i][rt+1],0);
		}
	}

	//build edge
	rep(i,n){
		rep(it,uniEdge[i].size()){
			int v = uniEdge[i][it];//i->v

			addE(nodes[i][1],nodes[v][0],1);
		}

		int m = biEdge[i].size();

		if(m > 0){
			rep(it,biEdge[i].size()){
				int lt = it + 2;
				int rt = m + it + 2;
				int ct = m * 2 + it + 2;

				if(it > 0){
					int id = biEdge[i][it-1].first;
					int v = biEdge[i][it-1].second;

					addE(nodes[i][lt],findNode(v,id,2),1);
				}

				if(it + 1 < m){
					int id = biEdge[i][it+1].first;
					int v = biEdge[i][it+1].second;

					addE(nodes[i][rt],findNode(v,id,2),1);
				}

				addE(nodes[i][ct],nodes[i][lt],0);

				addE(nodes[i][ct],nodes[i][rt],0);

				addE(nodes[i][ct],nodes[i][1],0);
			}
			addE(nodes[i][0],nodes[i][2+m],0);
			{
				int id = biEdge[i][0].first;
				int v = biEdge[i][0].second;

				addE(nodes[i][0],findNode(v,id,2),1);
			}
		}

		addE(nodes[i][0],nodes[i][1],0);
	}

	//graph built
	rep(i,V){
		rep(j,edge[i].size())
			indeg[edge[i][j].t]++;
	}

	static int que[2345678],qh=0,qt=0;

	rep(i,V) if(indeg[i]==0) que[qt++]=i;

	while(qh<qt){
		int u = que[qh++];
		rep(j,edge[u].size()){
			int v = edge[u][j].t;
			indeg[v]--;
			if(!indeg[v])
				que[qt++] = v;
		}
	}

	static int dp[2345678];

	if(qt!=V){
		puts("Infinite");
	} else {
		rep(i,V){
			int u = que[V-1-i];
			dp[u]=0;
			rep(j,edge[u].size()){
				int v = edge[u][j].t;
				dp[u] = max(dp[u],dp[v] + edge[u][j].w);
			}
		}
		int ans=*max_element(dp,dp+V);
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 106640
#include <iostream>
using namespace std;
#define int long long int
int n, m, ans = 0;
signed main()
{
    cin >> n >> m;
    if (n > 1)
        ans = n * (n - 1) / 2;
    if (m > 1)
        ans += m * (m - 1) / 2;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int N=200005;
const int INF=1061109567;
int n;
int p[N],q[N];
int ida[N],cnta;
int idb[N],cntb;
struct Edge
{
	int to,flow;
	int next;
}edge[N<<1];
int head[N],cnt=1;
void add_edge(int u,int v,int flow)
{
	cnt++;
	edge[cnt].to=v;
	edge[cnt].flow=flow;
	edge[cnt].next=head[u];
	head[u]=cnt;
	return;
}
void add(int u,int v,int flow)
{
	add_edge(u,v,flow);
	add_edge(v,u,0);
	return;
}
int s,t;
int dep[N];
bool bfs()
{
	memset(dep,-1,sizeof(dep));
	queue<int>q;
	q.push(s);
	dep[s]=0;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int i=head[u];i;i=edge[i].next)
		{
			int v=edge[i].to;
			if(dep[v]!=-1||edge[i].flow<=0) continue;
			dep[v]=dep[u]+1;
			q.push(v);
		}
	}
	return dep[t]!=-1;
}
int cur[N];
int dfs(int u,int flow)
{
	if(u==t) return flow;
	int used=0;
	for(int &i=cur[u];i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(dep[v]!=dep[u]+1||edge[i].flow<=0) continue;
		int now=dfs(v,min(flow,edge[i].flow));
		flow-=now;
		edge[i].flow-=now;
		edge[i^1].flow+=now;
		used+=now;
		if(flow==0) break;
	}
	if(used==0) dep[u]=-1;
	return used;
}
int dinic()
{
	int res=0;
	while(bfs())
	{
		memcpy(cur,head,sizeof(head));
		res+=dfs(s,INF);
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]),p[i]++;
	for(int i=1;i<=n;i++)
		scanf("%d",&q[i]),q[i]++;
	for(int i=1;i<=n;i++)
		if(!ida[i])
		{
			cnta++;
			ida[i]=cnta;
			int u=p[i];
			while(u!=i)
				ida[u]=cnta,u=p[u];
		}
	cntb=cnta;
	for(int i=1;i<=n;i++)
		if(!idb[i])
		{
			cntb++;
			idb[i]=cntb;
			int u=q[i];
			while(u!=i)
				idb[u]=cntb,u=q[u];
		}
	s=0,t=cntb+1;
	int ans=n;
	for(int i=1;i<=n;i++)
		if(p[i]==i&&q[i]==i) ans--;
		else if(p[i]==i&&q[i]!=i) add(s,idb[i],1);
		else if(p[i]!=i&&q[i]==i) add(ida[i],t,1);
		else if(p[i]==q[i]&&p[i]!=i) add(ida[i],idb[i],1),add(idb[i],ida[i],1);
		else add(ida[i],idb[i],1);
	ans-=dinic();
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 14460
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())

if N < 3:
    print("No")
    exit()

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                A[j][k] = 0

yes = False

for i in range(3):
    if A[i][0] == 0 and A[i][1] == 0 and A[i][2] == 0:
        yes = True
    if A[0][i] == 0 and A[1][i] == 0 and A[2][i] == 0:
        yes = True
    if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
        yes = True
    if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
        yes = True


if yes:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
# coding: utf-8
import math
N, D = map(int, input().split(" "))
XY = []
for n in range(N):
    XY.append(list(map(int, input().split(" "))))
cnt = 0
for xy in XY:
    x, y = xy
    d = math.sqrt(x**2 + y**2)
    if d<=D:
        cnt += 1
print(cnt)

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

int n, m;
vector<int> a, b;

ModInt<> solve();

int main() {
  cin >> n >> m;
  a.resize(n);
  for (auto &p : a) cin >> p;
  b.resize(m);
  for (auto &p : b) cin >> p;
  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  a.erase(unique(a.begin(), a.end()), a.end());
  b.erase(unique(b.begin(), b.end()), b.end());
  if (a.size() != n || b.size() != m) return 0;
  ModInt<> res = 1;
  for (int i = n * m, aid = 0, bid = 0, sum = 0; i >= 1; --i) {
    if (aid < n && bid < m && a[aid] == i && b[bid] == i)
      sum += aid++ + bid++;
    else if (aid < n && a[aid] == i) {
      res *= bid;
      sum += bid - 1;
      ++aid;
    } else if (bid < m && b[bid] == i) {
      res *= aid;
      sum += aid - 1;
      ++bid;
    } else
      res *= sum--;
  }
  return res;
}

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

int main() {
    int c[9];
    for (int i = 0; i < 9; ++i) cin >> c[i];

    int sum1 = c[0] + c[4] + c[8];
    int sum2 = c[1] + c[5] + c[6];
    int sum3 = c[2] + c[3] + c[7];
    int sum4 = c[0] + c[5] + c[7];
    int sum5 = c[1] + c[3] + c[8];
    int sum6 = c[2] + c[4] + c[6];

    if (sum1 == sum2 && sum2 == sum3 && sum4 == sum5 && sum5 == sum6) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second


bool dame(int x, int y, int z) {
	if (x == 0 && y == 2 && z == 1)return true;
	else return false;
}
ll dp[100][4][4][4];
void solve() {
	rep(i, 4) {
		rep(j, 4) {
			rep(k, 4) {
				dp[0][i][j][k] = 1;
				if (dame(i,j,k))dp[0][i][j][k] = 0;
				if (dame(j, i, k))dp[0][i][j][k] = 0;
				if (dame(i, k, j))dp[0][i][j][k] = 0;
			}
		}
	}
	rep(l, 99) {
		rep(i, 4) {
			rep(j, 4) {
				rep(k, 4) {
					rep(x, 4) {
						if (dame(i, j, k))continue;
						if (dame(j, k, x))continue;
						if (dame(i, k, x))continue;
						if (dame(k, j, x))continue;
						if (dame(j, x, k))continue;
						if (dame(i, j, x))continue;
						(dp[l + 1][j][k][x] += dp[l][i][j][k])%=mod;
					}
				}
			}
		}
	}
	ll ans = 0;
	int n; cin >> n;
	rep(i, 4) {
		rep(j, 4) {
			rep(k, 4) {
				ans += dp[n - 3][i][j][k];
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
}
int main() {
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
if(n==2)or(m==2):
  print(0)
elif(n==1)or(m==1):
  if(n==1)and(m==1):
    print(1)
  else:
    print(max(0,max(n,m)-2))
else:
  print((n-2)*(m-2))


Measured memory_bytes: 9124
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, a, b, c; cin >> n >> a >> b >> c;
  vector<int> l(n); REP(i, n) cin >> l[i];
  vector<int> per(n); REP(i, n) per[i] = i;
  int ans = INF;
  do {
    int tmp = 0, now, aa = 0, point = 0;
    for (now = 0; now < n - 2; ) {
      aa += l[per[now]];
      ++now;
      if (now == n - 2) {
        tmp += abs(aa - a) + point;
        break;
      }
      if (abs(aa-a) <= abs(aa+l[per[now]]-a)+10) {
        tmp += abs(aa - a) + point;
        break;
      }
      point += 10;
    }
    aa = point = 0;
    for (; now < n - 1; ) {
      aa += l[per[now]];
      ++now;
      if (now == n - 1) {
        tmp += abs(aa - b) + point;
        break;
      }
      if (abs(aa-b) <= abs(aa+l[per[now]]-b)+10) {
        tmp += abs(aa - b) + point;
        break;
      }
      point += 10;
    }
    aa = point = 0;
    for (; now < n; ) {
      aa += l[per[now]];
      ++now;
      if (now == n) {
        tmp += abs(aa - c) + point;
        break;
      }
      if (abs(aa-c) <= abs(aa+l[per[now]]-c)+10) {
        tmp += abs(aa - c) + point;
        break;
      }
      point += 10;
    }
    ans = min(ans, tmp);
  } while (next_permutation(ALL(per)));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int INF = -1e9;
double temp_start = 100.0;
double temp_end = 0.01; 
int climb_loop = 3000;
double temp;

int main(){
  int seed = 12345;
  mt19937 eng(seed);
  uniform_real_distribution<> uniform_01;

  // input
  int D;
  cin >> D;
  int c[26];
  rep(i,26) cin >> c[i];
  int s[D+1][26];
  rep(i,D) rep(j,26) cin >> s[i+1][j];
  
  // define parameter
  int last[D+1][26];
  int t[D+1];
  rep(i,D+1) rep(j,26) last[i][j] = 0;
  
  // calculate initial content climbing
  int content = 0;
  for(int day = 1; day <= D; day++) {
    int content_after = -INF;
    int best_kind = 0;
    rep(kind,26) {
      int res = content + s[day][kind];
      rep(j,26) {
        if(j == kind) last[day][j] = day;
        else last[day][j] = last[day-1][j];
        res -= c[j] * (day - last[day][j]);
      }
      if(res > content_after) {
        best_kind = kind;
        content_after = res;
      }
    }
    t[day] = best_kind;
    content = content_after;
    rep(j,26) {
      if(j == t[day]) last[day][j] = day;
      else last[day][j] = last[day-1][j];
    }
  }
   
  // simulated annealing
  rep(x,climb_loop) {
    int d = eng() % D + 1;
    int q = eng() % 26;
    int diff = s[d][q] - s[d][t[d]];
    int cur = d;
    while(cur <= D && last[cur][t[d]] == d) {
      diff -= c[t[d]] * (d - last[cur-1][t[d]]);
      last[cur][t[d]] = last[cur-1][t[d]];
      cur++;
    }
    cur = d;
    while(cur <= D && last[cur][q] < d) {
      diff += c[q] * (d - last[cur][d]);
      last[cur][q] = d;
      cur++;
    }
    if(uniform_01(eng) < exp((double)diff/temp)) {
      t[d] = q;
      content += diff;
    } else {
      int day = d;
      while(day <= D && last[day][t[d]] < d) {
        last[day][t[d]] = d;
        day++;
      }
      day = d;
      while(day <= D && last[day][q] == d) {
        last[day][q] = last[day-1][q];
        day++;
      }
    }
  }
  // output
  for(int day = 1; day <= D; day++) cout << t[day]+1 << endl;
  return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <ll,ll> mp;
vector<int> V;
#define debug(x) cerr << #x << ": " << x << "\n";
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=(int) 2e5;
static const int MOD=(int) 1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
int N;
ll a,ans,sum;
vector<ll> S;
void solve(){
    sort(S.begin(),S.end());
    S.erase(unique(S.begin(),S.end()),S.end());
    for(int i=0;i<S.size();i++){
        ans += (mp[S[i]] - 1)* mp[S[i]] /2;
    }
    cout << ans <<"\n";
}

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin >> N;
    S.push_back(0ll);
    mp[0]=1;
    for(int i=1;i<=N;i++) {
        cin >>a;
        sum += a;
        S.push_back(sum);
        mp[sum]++;
    }
    solve();
    
    return 0;
}


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

int main(){
	string s;
	cin>>s;
	
	bool jud=true;
	for(int i=1;i<s.size();++i){
		if(s[i]!='9'){
			jud=false;
			break;
		}
	}
	
	int ans=s[0]-'0';
	ans+=9*(s.size()-1);
	
	if(jud) cout<<ans<<endl;
	else cout<<ans-1<<endl;
}//解説参考.

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const int MOD=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


int main(){
	ll a,b,q,x,s[M],t[M];
	cin>>a>>b>>q;
	rep(i,0,a)cin>>s[i];
	rep(i,0,b)cin>>t[i];
	rep(i,0,q){
		cin>>x;
		ll itr1r=lower_bound(s,s+a,x)-s;
		ll itr1l=itr1r-1;
		ll itr2r=lower_bound(t,t+b,x)-t;
		ll itr2l=itr2r-1;
		ll ans1,ans2,ans3,ans4;
		//右に進む
		if(itr1r>a-1||itr1r<0)ans1=INF;
		else if(itr2r>b-1||itr2r<0)ans1=INF;
		else ans1=max(s[itr1r],t[itr2r])-x;
		//左に進む
		if(itr1l<0)ans2=INF;
		else if(itr2l<0)ans2=INF;
		else ans2=x-min(s[itr1l],t[itr2l]);
		//左の神社から、右の寺院に進む
		if(itr1l<0)ans3=INF;
		else if(itr2r>b-1||itr2r<0)ans3=INF;
		else ans3=abs(s[itr1l]-x)+abs(t[itr2r]-x)+min(abs(s[itr1l]-x),abs(t[itr2r]-x));
		//右の神社から、左の寺院に進む
		if(itr1r>a-1||itr1r<0)ans4=INF;
		else if(itr2l<0)ans4=INF;
		else ans4=abs(s[itr1r]-x)+abs(t[itr2l]-x)+min(abs(s[itr1r]-x),abs(t[itr2l]-x));
		ll ans=min({ans1,ans2,ans3,ans4});
//		print(ans1<<" "<<ans2<<" "<<ans3<<" "<<ans4);
		print(ans);
	}
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        string ac="AC",re="RE",tle="TLE",wa="WA";
        cin>>n;
        string s;
        a=0,b=0,c=0,d=0;
        for(i=0;i<n;i++)
        {
            cin>>s;
            if(s==ac)a++;
            if(s==re)b++;
            if(s==wa)c++;
            if(s==tle)d++;
        }
        cout<<ac<<" x "<<a<<endl;
        cout<<wa<<" x "<<c<<endl;
        cout<<tle<<" x "<<d<<endl;
        cout<<re<<" x "<<b<<endl;
    }
}


Measured memory_bytes: 3656
function main()
	N=parse(Int,readline())
	A=Tuple{Int,Int,Int}[]
	M=10^9+7
	O=M-1
	for _=1:N
		a,b=map(x->parse(Int,x),split(readline()))
		if a==b==0
			O+=1
		else
			g=gcd(a,b)
			a=div(a,g)
			b=div(b,g)
			if a<0||a==0<b
				a,b=-a,-b
			end
			f=0
			if b<0
				a,b,f=-b,a,1
			end
			push!(A,(a,b,f))
		end
	end
	sort!(A)
	i=1
	ans=1
	while i<=length(A)
		j=i
		x=y=1
		while i<=length(A)&&A[i][1]==A[j][1]&&A[i][2]==A[j][2]
			if A[i][3]==0
				x=x*2%M
			else
				y=y*2%M
			end
			i+=1
		end
		ans=ans*(x+y-1)%M
	end
	println((ans+O)%M)
end
main()


Measured memory_bytes: 214156
#include <iostream>
#include<climits>
using namespace std;
int m[100][100];

int MCM(int p[],int n) {
	for (int i = 0; i <= n; i++)
		m[i][i] = 0;
	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = INT_MAX;
			for (int k = i; k <= j-1; k++) {
				int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
				if (m[i][j] > q) {
					m[i][j] = q;
				}

			}
		}

	}
	return m[1][n];
}

int main() {
	int n, p[200];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i] >> p[i + 1];
	}
	cout << MCM(p, n) << endl;
	return 0;
}

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

int main(){
  int x, y;
  int a[12] = {0,2,0,1,0,1,0,0,1,0,1,0};
  cin >> x >> y;
  if(a[x-1] == a[y-1]) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, c, k, t[100010], ans;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int main()
{
	n = read();
	c = read();
	k = read();
	for(int i = 1; i <= n; i ++)
		t[i] = read();
	sort(t + 1, t + n + 1);
	int now = 1;
	while(now <= n)
	{
		int now_t = t[now];
		now_t += k;
		int wl_t = upper_bound(t + 1, t + n + 1, now_t) - t - 1;
		if(wl_t - now + 1 > c) now += c;
		else now = wl_t + 1;
		ans ++;
	}
	cout << ans;
	return 0;
}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> p(n), c(n);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}
	rep(i, n) {
		cin >> c[i];
	}
	ll ans = -1e18;
	rep(i, n) {
		int now = i;
		vector<ll> s;
		ll tot = 0;
		while (1) {
			now = p[now];
			s.push_back(c[now]);
			tot += c[now];
			if (now == i) break;
		}
		int l = s.size();
		ll t = 0;
		rep(i, l) {
			if (i + 1 > k) break;
			t += s[i];
			ll u = t;
			if (tot > 0) {
				u += tot * ((k - (i + 1)) / l);
			}
			ans = max(ans, u);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)

int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> tmp(N);
    repi(i,N){
        cin >> P[i];
        tmp[i] = P[i];
    }
    sort(all(tmp));
    
    int cnt = 0;
    repi(i,N){
        if(P[i] != tmp[i]){
            cnt ++;
        }
        if(cnt > 2){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

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

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

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

  int64_t sum = 0;

  int64_t num_3 = N / 3;
  int64_t num_5 = N / 5;
  int64_t num_15 = N / 15;
  sum = (N + 1) * N / 2;

  sum -= (num_3 + 1) * num_3 / 2 * 3;
  sum -= (num_5 + 1) * num_5 / 2 * 5;
  sum += (num_15 + 1) * num_15 / 2 * 15;

  cout << sum << endl;
}


Measured memory_bytes: 3672
#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct UnionFind
{
	vector<int> parent;
	vector<int> rank;

	UnionFind(int N) :parent(N, 0), rank(N, 0)
	{
		rep(i, 0, N)
		{
			parent[i] = i;
		}
	}

	int find(int x)
	{
		if (parent[x] == x)
		{
			return x;
		}
		else
		{
			return parent[x] = find(parent[x]);
		}
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (x == y)
		{
			return;
		}

		if (rank[x] < rank[y])
		{
			parent[x] = y;
		}
		else
		{
			parent[y] = x;
			if (rank[x] == rank[y])
			{
				rank[x]++;
			}
		}
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

struct Edge
{
	int s, t, cost;
	Edge(int s, int t, int cost) :s(s), t(t), cost(cost) {}
	Edge() :Edge(-1, -1, -1) {}
	bool operator<(const Edge& e)const
	{
		return cost < e.cost;
	}
};

Edge edges[100000];
int V, E;

int minimum_spaning_tree()
{
	sort(edges, edges + E);
	UnionFind uf(V);

	int ans = 0;
	rep(i,0,E)
	{
		Edge edge = edges[i];
		if (!uf.same(edge.s, edge.t))
		{
			ans += edge.cost;
			uf.unite(edge.s, edge.t);
		}
	}

	return ans;
}

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

	int start, to;
	cin >> V >> E;

	rep(i, 0, E)
	{
		int s, t, c;
		cin >> s >> t >> c;
		edges[i] = Edge(s, t, c);
		//G[s].push_back(Edge(s, t, c));
		//G[t].push_back(Edge(t, s, c));
	}

	cout << minimum_spaning_tree() << endl;

	return 0;
}


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


int tmp[100010];
int p[16][16];


int main(){
	int n,d,x;
	cin >> n >> d >> x;
	for(int i = 0 ; i < d ; i++){
		for(int j = 0 ; j < n ; j++){
			cin >> p[i][j];			
		}
	}
	for(int i = 0 ; i+1 < d ; i++){
		int y = x;
		memset(tmp,0,sizeof(tmp));
		for(int j = 0 ; j < n ; j++){
			for(int k = p[i][j] ; k <= x ; k++){
				tmp[k] = max(tmp[k-p[i][j]]+p[i+1][j],tmp[k]);
				y = max(y,tmp[k]+x-k);
			}
		}
		x = y;
	}
	cout << x << endl;
}

Measured memory_bytes: 3488
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll x;cin>>x;
  cout<<360 / gcd(x,360) << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
#define MAX_N 1234560

bool isPrime[MAX_N * 2 + 1];

int main(void){
  for(int i = 0; i <= MAX_N * 2; i++) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i * i <= MAX_N * 2; i++){
    if(isPrime[i]){
      for(int j = i * i; j <= MAX_N; j += i) isPrime[j] = false;
    }
  }
  int n, cnt;
  while(true){
    cin >> n;
    if(n == 0) break;
    cnt = 0;
    for(int i = n + 1; i <= 2 * n; i++){
      if(isPrime[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    vector<vector<ll>> C(3, vector<ll>(3));

    REP(i,3){
        REP(j,3){
            cin >> C[i][j];
        }
    }

    REP(i, 3){
        if((C[0][i%3]- C[0][(i+1)%3] == C[1][i%3]-C[1][(i+1)%3]) && (C[1][i%3]- C[1][(i+1)%3] == C[2][i%3]-C[2][(i+1)%3])) {
            continue;
        }
        if((C[i%3][0]- C[(i+1)%3][0] == C[i%3][1]-C[(i+1)%3][1]) && (C[i%3][1]- C[(i+1)%3][1] == C[i%3][2]-C[(i+1)%3][2])) {
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  int num = 1;
  rep(i, N) {
    if (num < K) num += num;
    else num += K;
  }

  cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 256