akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <map>
#include <stack>
#include <vector>

using namespace std;

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

vector<veci> adj;

void solve() {
    int n, m;
    cin >> n >> m;

    veci v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        v[i] -= 1;
    }

    adj.clear();
    adj.resize(n);
    int x, y;
    for (int i = 0; i < m; ++i) {
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    vecii vis(n);
    for (int i = 0; i < n; ++i) vis[i] = {0, i};

    int odr = 1;
    for (int i = 0; i < n; ++i) {
        if (!vis[i].fi) {
            vis[i].fi = odr;
            stack<int> st;
            st.push(i);
            while (!st.empty()) {
                int t = st.top();
                st.pop();
                for (auto e : adj[t]) {
                    if (!vis[e].fi) {
                        vis[e].fi = odr;
                        st.push(e);
                    }
                }
            }
            odr++;
        }
    }

    sort(vis.begin(), vis.end());
    int ans = 0;
    int p = 1;
    int pp = 0;
    while (p < odr) {
        map<int, int> mp;
        while (pp < n && vis[pp].fi == p) {
            mp[vis[pp].se]++;
            mp[v[vis[pp].se]]++;
            pp += 1;
        }
        for (auto&& e : mp) {
            if (e.se == 2) ans++;
        }
        p += 1;
    }

    cout << ans << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
        solve();
}


Measured memory_bytes: 11648
#include <iostream>
//#include <set>
//#include <map>
#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    double r;
    double ans;
    cin >> r;
    ans = 2*r*M_PI;

    cout << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 3764
s=[i for i in input()]
op_num = len(s)-1
sum=0

for i in range(2**op_num):
    op=['-' for i in range(op_num)]
    for j in range(op_num):
        if (i>>j)&1:
            op[j]='+'
    op+='+'
    sn=0
    for k in range(len(op)):
        if op[k]=='+':
            sum+=int(''.join(s[sn:k+1]))
            sn=k+1
print(sum)

Measured memory_bytes: 3064
S = input()
n, s, w, e = 0, 0, 0, 0
if 'N' in S:
    n = 1
if 'S' in S:
    s = 1
if 'W' in S:
    w = 1
if 'E' in S:
    e = 1
if n == s and w == e:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void print_vec(vector<int>& a){
		int n=a.size();

	for(int i=0;i<a.size();i++)
		cout << a[i] << (i<n-1 ? " ":"\n");
}

void print_vec(vector<bool>& a){
		int n=a.size();

	for(int i=0;i<a.size();i++)
		if(a[i])
			cout << i << (i<n-1 ? " ":"\n");
}

void print_vec(vector<long long>& a){
	int n=a.size();
	for(int i=0;i<a.size();i++)
		cout << a[i] << (i<n-1 ? " ":"\n");
	cout << "\n";
}

void solve(){
	int n;
	cin >> n;
	int st = int(floor(n/105));
	for(int i=int(floor(n/105));i<=int(ceil(n/100));i++){
		// cout << i << endl;
		// vector<bool> curr(i*5+1,false), prev(i*5+1,false);		
		// prev[0]=true;
		// for(int j=0;j<i;j++){
		// 	for(int k=0;k<=5;k++){
		// 		for(int p=0;p<min(5*(j+1),int(prev.size()));p++){
		// 			if(prev[p]){
		// 				if(p+k<curr.size())
		// 					curr[p+k]=true;
		// 			}
		// 		}
		// 	}
		// 	print_vec(curr);
		// 	cout <<"\n";
		// 	if(j<i-1){
		// 		for(int k=0;k<prev.size();k++){
		// 			prev[k]=curr[k];
		// 			curr[k]=false;
		// 		}
		// 	}
		// }

		// if(n-100*i >= 0 && n-100*i<curr.size() && curr[n-100*i]){
		// 	cout << "1\n";
		// 	return;
		// }

		if(n-100*i >= 0 && n-100*i <= 5*i){
			cout << "1\n";
			return;
		}
	}
	cout<<"0\n";
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	
	solve();
	
	return 0;
}

Measured memory_bytes: 256
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

S = input()
T = input()

stlist = [[sc, tc] for sc, tc in zip(S, T)]


from operator import itemgetter

#まずはsでソート
stlist = sorted(stlist, key=itemgetter(0))

#同じ文字なのに違うことがあるか
prevsc = 'Z'
prevtc = 'Z' #これは無意味だが、とりあえず宣言しておく
for sc, tc in stlist:
  if prevsc == sc and prevtc != tc:
    print('No')
    exit()
  else:
    prevsc = sc
    prevtc = tc


#tでソート
stlist = sorted(stlist, key=itemgetter(1))

#同じ文字なのに違うことがあるか
prevsc = 'Z' #これは無意味だが、とりあえず宣言しておく
prevtc = 'Z'
for sc, tc in stlist:
  if prevtc == tc and prevsc != sc:
    print('No')
    exit()
  else:
    prevsc = sc
    prevtc = tc

print('Yes')



Measured memory_bytes: 101552
A = []
for _ in range(3):
  A.append(list(map(int, input().split())))

B = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
N =int(input())
for _ in range(N):
  b = int(input())
  for k in range(3):
    for j in range(3):
      if A[k][j] == b:
        B[k][j] = 1

if sum(B[0]) == 3 or sum(B[1]) == 3 or sum(B[2]) == 3:
  print('Yes')
elif B[0][0] + B[1][0] + B[2][0] ==3:
  print('Yes')
elif B[0][1] + B[1][1] + B[2][1] ==3:
  print('Yes')
elif B[0][2] + B[1][2] + B[2][2] ==3:
  print('Yes')
elif B[0][0] + B[1][1] + B[2][2] ==3:
  print('Yes')
elif B[0][2] + B[1][1] + B[2][0] ==3:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int zero = 0,one = 0;
    rep(i,s.size()){
        if (s[i] - '0') one++;
        else zero++;
    }
    PRINT(min(one,zero)*2);
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int n;
    long long x;
    cin >> n >> x;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans=0;
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        x -= a[i];
        if(x<0){
            break;
        }else{
            ans++;
        }
    }
    if(x>0){
        ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
    AUTHOR : TANMAY SINHA
    INORMATION TECHNOLOGY
    BIT MESRA ,RANCHI
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define rep(j,L,R) for(j=L;j<R;j++)
#define per(i,L,R) for(i=L;i>= R;i--)
#define all(con) (con).begin(),(con).end()
#define fi first
#define se second
#define foreach(iter,con) for(auto iter=(con).begin(); iter!=(con).end(); iter++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll power1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
const ll INF = 1e18l+10;
int main()
{
   SPEED
   string a,b;
   cin>>a>>b;
   ll i,j,n = a.length(),m = b.length();
   vvl dp(n+1,vl(m+1,0));
   for(i=0;i<n;i++)
   {
       for(j=0;j<m;j++)
       {
           if(a[i]==b[j])
            dp[i+1][j+1]=1+dp[i][j];
           else
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
       }
   }
   vector <char>v;
   i=n;j=m;
   while(i>0&&j>0)
   {
       if(a[i-1]==b[j-1])
       {
           v.pb(a[i-1]);
           i--;
           j--;
       }
       else if(dp[i-1][j]>dp[i][j-1])
        i--;
       else
        j--;
       //deb1(i,j);
   }
   for(i=v.size()-1;i>=0;i--)
    cout<<v[i];
}







Measured memory_bytes: 70784
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
//int dy[] = {0, 0, -1, 1};
//int dx[] = {1, -1, 0, 0};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = 0;
    int ler = 0;
    rep(i, s.size()) {
        if (s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T') {
            cnt++;
        } else {
            ler = max(ler, cnt);
            cnt = 0;
        }
        
    }
    ler = max(ler, cnt);
    cout << ler << endl;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &p[i]);
    }

    double MAX = 0;
    int sum = 0;
    for (int i = 0; i < K; i++) {
        sum += p[i];
    }
    for (int i = K - 1; i < N; i++) {
        double x = (sum + K) / 2.0;
        MAX = max(MAX, x);
        if (i < N - 1) {
            sum -= p[i - K + 1];
            sum += p[i + 1];
        }
    }

    printf("%.10lf\n", MAX);

    return 0;
}


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

int main() {
  int s; cin >> s;
  ll dp[2010];
  dp[0] = 1;
  for(int i = 1; i <= s; i++){
    if(i>=3){
      dp[i] = dp[i-1]+dp[i-3];
      dp[i] %= mod;
    }
  }
  cout << dp[s] << endl;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1ll<<60;
int dx[]={0,0,1,-1},dy[]={-1,1,0,0};

int a[5];
string s,t;
int ma=INF;

signed main() {
    IOS();
    rep(i,0,5)cin>>a[i];
    rep(i,0,5){
        rep(j,0,5){
            if(j==i)continue;
            rep(k,0,5){
                if(k==i||k==j)continue;
                rep(l,0,5){
                    if(l==k||l==i||l==j)continue;
                    rep(m,0,5){
                        if(m==l||m==k||m==i||m==j)continue;
                        int now=0;
                        now+=a[i];
                        if(now%10)now+=10-(now%10);
                        now+=a[j];
                        if(now%10)now+=10-(now%10);
                        now+=a[k];
                        if(now%10)now+=10-(now%10);
                        now+=a[l];
                        if(now%10)now+=10-(now%10);
                        now+=a[m];
                        chmin(ma,now);
                    }
                }
            }
        }
    }
    
    cout<<ma<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class AtCoderD
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        int[] a = new int[n];
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(words[i]);
            }
        }
        Dictionary<int, int> dic = new Dictionary<int, int>();
        for (int i = 1; i <= n; i++)
        {
            dic.Add(i, 0);
        }

        for (int i = 0; i < n; i++)
        {
            dic[a[i]]++;
        }

        long total = 0;
        for (int i = 1; i <= n; i++)
        {
            int count = dic[i];
            total += (long)count * (long)(count - 1) / 2;
        }

        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(total - dic[a[i]] + 1);
        }
    }
}

Measured memory_bytes: 40380
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll sum = 0, ans = 0;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll l = 0, r = 0;
    while(r < n){
        while(r < n){
            bool add = true;
            rep(j,22){
                if(a[r]>>j & 1 && sum>>j & 1) add = false;
            }
            if(!add) break;
            sum += a[r];
            ++r;
            ans += r - l;
        }
        sum -= a[l];
        ++l;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/

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

    ll N,K;
    cin>>N>>K;
    ll ans = 0;
    if(K ==0){
        cout<<N*N<<endl;
        return 0;
    }
    for(ll b = K+1; b <= N; b++){
        /*
        aの候補を考える
        bの倍数 + Kであれば良い
        */
        if(N % b == 0){
            ans += (N/b) * (b-K);
        }
        else{
            ans += (N/b) * (b-K);
            if(K > N % b)continue;
            ans += (N%b) - K +1;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
	int n, d;

	while (scanf("%d %d", &n, &d) && n){
		char dir[100][2], pos[100];

		int ltime = 0;

		for (int i = 0; i < n; i++){
			scanf("%s %d", dir[i], pos + i);
			ltime = max(ltime, dir[i][0] == 'L' ? pos[i] : d - pos[i]);
		}

		int occ[128];
		for (int i = 0; i < ltime; i++){
			for (int j = 0; j < d; j++) occ[j] = -1;
			for (int j = 0; j < n; j++){
				dir[j][0] == 'L' ? pos[j]-- : pos[j]++;
				if (0 < pos[j] && pos[j] < d){
					if (~occ[pos[j]]){
						dir[occ[pos[j]]][0] ^= ('L' ^ 'R');
						dir[j][0] ^= ('L' ^ 'R');
					}
					else {
						occ[pos[j]] = j;
					}
				}
			}
		}

		int lant = 0;

		for (int i = 0; i < n; i++){
			if (pos[i] == 0) lant = i + 1;
			if (pos[i] == d && !lant) lant = i + 1;
		}

		printf("%d %d\n", ltime, lant);
	}

	return (0);
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

int n;

int f(int n, int k) {
	if (k == 1) return n;
	if (k % 2 == 0) {
		int t = f(n, k / 2);
		return t * t % MOD;
	}
	return n * f(n, k - 1) % MOD;
}

signed main() {
	cin >> n;
	cout << ((f(10, n) + f(8, n) - 2 * f(9, n)) % MOD + MOD) % MOD;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

void test();

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll lc = (c*1ll*d)/__gcd(ll(c),ll(d));
	ll terms1,terms2,terms3;
	terms1 = max(ll(0),-(a+c-1)/c+b/c+1);
	terms2 = max(ll(0),-(a+d-1)/d+b/d+1);
	terms3 = max(ll(0),-(a+lc-1)/lc+b/lc+1);
	ll ans =terms1+terms2-terms3;
	ans = (b-a+1-ans);
	cout << ans << "\n";
	return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(all(l));

  int ans = 0;
  for (int a = 0; a < n - 2; ++a) {
    for (int b = a + 1; b < n - 1; ++b) {
      int mini = l[b] - l[a] + 1;
      int maxi = l[a] + l[b] - 1;
      vector<int>::iterator begin = l.begin() + b + 1;
      int lb = lower_bound(begin, l.end(), mini) - l.begin();
      int ub = upper_bound(begin, l.end(), maxi) - l.begin();
      ans += max(0, ub - lb);
      /*
      for (int c = b + 1; c < n; ++c) {
        if (mini <= l[c] && l[c] <= maxi) ++ans;
      }
      */
    }
  }
  out(ans);
}


Measured memory_bytes: 256
s=input()
l=len(s)
ans=1
for i in range(1,l//2):
	s1=s[:l//2-1-i]
	s2=s[l//2-i:l-2*i-1]
	if s1==s2:
		ans=l//2-i
		break
print(ans*2)

Measured memory_bytes: 3060
#include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int a,b,c,x,n;
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            a=b=c=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d",&x);
                if(!(x%4)) a++;
                else if(x&1) b++;
                else c++;
            }
            if(!c) b--;
            puts(a>=b?"Yes":"No");
        }
        return 0;
    }

Measured memory_bytes: 256
/*
 * SAD
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define S second
#define F first
#define pb push_back
const int inf = 1e9;
using ii = pair<int, int>;
using ll = long long;
using db = long double;

const int N = 2e5 + 5, M = 1000 * 1000 * 10 + 5, K = 55, Base = 27, MOD = 1e9
		+ 7, MOD2 = 998244353;
const ll MX = 1e15;
const int blkSz = 200;
const db EPS = 1e-7;
const int PI = 3;
int dp[100005][205], n, x, a[205];
int prefix[100005], cnt[100005];
int solve(int val, int larger){
//	cout << val << " " << larger << '\n';
	if(prefix[val] == -1 && larger == 0){
		return val;
	}
	int &ret = dp[val][larger];
	if(~ret)
		return ret;
	///choose to put wa7d mallosh lazma
	ret = 0;
	if(larger){
		ret = 1ll * larger * solve(val,larger-1) % MOD;
	}
	///choose to mod but who to choose as mod
	if(prefix[val] != -1){
		for(int k = prefix[val]; ~k; --k){
			///update larger
			int to = val % a[k];
			int newLarge = cnt[to] - cnt[val] - 1;
			ret += solve(to,newLarge+larger);
			if(ret >= MOD)
				ret -= MOD;
		}
	}
	return ret;
}
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif

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

	memset(prefix,-1,sizeof prefix);
	for(int i = 0; i <= 100000; i++)
		for(int j = 0; j < n; j++)
			if(a[j] <= i)
				prefix[i] = j;
			else
				cnt[i]++;

	memset(dp,-1,sizeof dp);
	cout << solve(x,cnt[x]) << '\n';


	return 0;
}


Measured memory_bytes: 81152
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
    char c;
    int t = 0, ans = 0;
    while((c = getchar()) != EOF) {
        if('0' <= c && c <= '9') {
            t *= 10;
            t += c - '0';
        }
        else {
            ans += t;
            t = 0;
        }
    }
    cout << ans << endl;
}

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

int main() {
  string b;
  cin >> b;
  if (b=="A") {
    cout << "T" << endl;
  }
  
  if (b=="T") {
    cout << "A" << endl;
  }
  
  if (b=="C") {
    cout << "G" << endl;
  }
  
  if (b=="G") {
    cout << "C" << endl;
  }
  
}    


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

int main() {
    long long X;
    cin >> X;
    for (long long A = -200; A <= 200; ++A) {
        for (long long B = -200; B <= 200; ++B) {
            if (A*A*A*A*A - B*B*B*B*B == X) {
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3580
a,b = map(int,input().split())
s=input()

for i in range(a+b+1):
    if i < a and '-' != s[i]:
        continue
    elif  a < i and i < a+b+1 and '-' != s[i]:
        continue
    elif i == a and '-' == s[i]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 38384
/**
* Copyright(c)
* All rights reserved.
* Author : Universal
* Description : sample
*/
#include <bits/stdc++.h>
#define MAXN 100005
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef long long ll;

priority_queue <double,vector<double>,greater<double> > q;

int main(){
    int n;
    scanf("%d",&n);
    double a;
    for(int i=0;i<n;i++){
        cin>>a;
        q.push(a);
    }
    double ans = q.top();
    for(int i=0;i<n-1;i++){
        double b = q.top();
        q.pop();
        double c = q.top();
        q.pop();
        ans = (b+c)/2;
        q.push(ans);
    }
    cout<<ans<<endl;
    return 0;
}


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

int a[100000];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int xor_sum = 0;
  for (int i = 0; i < n; i++)
    xor_sum ^= a[i];
  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (((1 << bit) & xor_sum) == 0) {
      continue;
    }
    int x = (1 << (bit + 1)) - 1;

    for (int i = 0; i < n; i++) {
      int y = a[i] ^ (a[i] - 1);
      if (y == x) {
        xor_sum ^= y;
        ans += 1;
        break;
      }
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 512
n = int(input())
M = [[0]*n for _ in range(n)]
st = [0]*n
d = [0]*n
f = [0]*n
tt = 0

def dfs(u,t):
    st[u] = 1
    t += 1
    d[u] = t
    for v in range(n):
        if M[u][v] == 0: continue
        if st[v] == 0: t = dfs(v,t)
    st[u] = 2
    t += 1
    f[u] = t
    return t

for _ in range(n):
    i = [int(i) for i in input().split()]
    u = i[0]
    k = i[1]
    V = i[2:]
    for v in V: M[u-1][v-1] = 1

for i in range(n):
    if st[i] == 0: tt = dfs(i,tt)

for i in range(n): print(i+1,d[i],f[i])


Measured memory_bytes: 5792
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    S[K-1]=tolower(S[K-1]);
    
    cout<<S<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>>a(h+2,vector<char>(w+2));
    rep(i,h) rep(j,w) cin >> a.at(i+1).at(j+1);
    rep(i,h+2) {
        a.at(i).at(0)='#';
        a.at(i).at(w+1)='#';
    }
    rep(i,w+2){
        a.at(0).at(i)='#';
        a.at(h+1).at(i)='#';
    }
    rep(i,h+2){
        rep(j,w+2) cout << a.at(i).at(j);
        cout << endl;
    }

}

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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// 0.input
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int C = sc.nextInt();
		
		int D[][] = new int[C][C];
		for(int i=0; i<C; i++) {
			for(int j=0; j<C; j++) {
				D[i][j] = sc.nextInt();
			}
		}
		
		int c[][] = new int[N][N];
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				c[i][j] = sc.nextInt();
			}
		}
		
		// 1.Gridをスキャンしてmod3の0,1,2のグループに各色が何個ずつあるか調べる
		int[] mod3_0 = new int[C];
		int[] mod3_1 = new int[C];
		int[] mod3_2 = new int[C];
		
		Arrays.fill(mod3_0, 0);
		Arrays.fill(mod3_1, 0);
		Arrays.fill(mod3_2, 0);
		
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				if(((i+1)+(j+1)) % 3 == 0) {
					mod3_0[c[i][j]-1] += 1;
				}
				else if(((i+1)+(j+1)) % 3 == 1) {
					mod3_1[c[i][j]-1] += 1;
				}
				else {
					mod3_2[c[i][j]-1] += 1;
				}
			}
		}
		
		// 2.C^3ずつ塗り分けて全探索。i=j,j=k,k=iのときはpass
		int ans = Integer.MAX_VALUE;
		
		for(int col1=0; col1<C; col1++) {
			for(int col2=0; col2<C; col2++) {
				if(col1 == col2) {
					continue;
				}
				for(int col3=0; col3<C; col3++) {
					if(col1 == col3 || col2 == col3) {
						continue;
					}
					
					int ans_temp = 0;
					
					//col1以外のもの
					for(int col=0; col<C; col++) {
						ans_temp += mod3_0[col] * D[col][col1];
						ans_temp += mod3_1[col] * D[col][col2];
						ans_temp += mod3_2[col] * D[col][col3];
					}
					
					ans = Math.min(ans, ans_temp);
					
				}
			}
		}
		
		System.out.println(ans);
		
	}

}

Measured memory_bytes: 90088
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<ll> B(N);
  ll out=0;
  rep(i,N){
    cin >> B[i];
  }
  for(int i=1;i<N-1;i++){
    out += min(B[i-1], B[i]);
  }
  out += (B[0] + B[N-2]);
  
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	void run(){

		HashMap<Character, String> hash = new HashMap<Character, String>();

		hash.put(' ',"101");

		hash.put('\'',"000000");

		hash.put(',',"000011");

		hash.put('-',"10010001");

		hash.put('.',"010001");

		hash.put('?',"000001");

		hash.put('A',"100101");

		hash.put('B',"10011010");

		hash.put('C',"0101");

		hash.put('D',"0001");

		hash.put('E',"110");

		hash.put('F',"01001");

		hash.put('G',"10011011");

		hash.put('H',"010000");

		hash.put('I',"0111");

		hash.put('J',"10011000");			

		hash.put('K',"0110");

		hash.put('L',"00100");

		hash.put('M',"10011001");

		hash.put('N',"10011110");

		hash.put('O',"00101");

		hash.put('P',"111");

		hash.put('Q',"10011111");

		hash.put('R',"1000");

		hash.put('S',"00110");

		hash.put('T',"00111");

		hash.put('U',"10011100");

		hash.put('V',"10011101");

		hash.put('W',"000010");

		hash.put('X',"10010010");

		hash.put('Y',"10010011");

		hash.put('Z',"10010000");

		

		HashMap<String, Character> hash2 = new HashMap<String, Character>();

		hash2.put("00000",'A');

		hash2.put("00001",'B');

		hash2.put("00010",'C');

		hash2.put("00011",'D');

		hash2.put("00100",'E');

		hash2.put("00101",'F');

		hash2.put("00110",'G');

		hash2.put("00111",'H');

		hash2.put("01000",'I');

		hash2.put("01001",'J');

		hash2.put("01010",'K');

		hash2.put("01011",'L');

		hash2.put("01100",'M');

		hash2.put("01101",'N');

		hash2.put("01110",'O');

		hash2.put("01111",'P');

		hash2.put("10000",'Q');

		hash2.put("10001",'R');

		hash2.put("10010",'S');

		hash2.put("10011",'T');

		hash2.put("10100",'U');

		hash2.put("10101",'V');

		hash2.put("10110",'W');

		hash2.put("10111",'X');

		hash2.put("11000",'Y');

		hash2.put("11001",'Z');

		hash2.put("11010",' ');

		hash2.put("11011",'.');

		hash2.put("11100",',');

		hash2.put("11101",'-');

		hash2.put("11110",'\'');

		hash2.put("11111",'?');

		

		for(;sc.hasNextLine();){

			String buffer = sc.nextLine();

			String dec ="";

			for(char ch : buffer.toCharArray()){

				dec += hash.get(ch);

			}

			String ret ="";

			for(;dec.length()>0;){

				String st="";

				if(dec.length()>5){

					st = dec.substring(0,5);

					dec = dec.substring(5);

				}else{

					st = (dec+"00000").substring(0,5);

					dec = "";

				}

				ret += hash2.get(st);

			}

			System.out.println(ret);

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
long long n,m,k,cnt=0,ans=0;
string s,t;
int main(){
  cin >> n;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  cout << a[n-1]-a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
A = []
3.times do
  A << gets.chomp.split.map(&:to_i)
end
n = gets.chomp.to_i
b = []

n.times do |i|
  b << gets.chomp.to_i
end

3.times do |i|
  3.times do |j|
    flag = false

    n.times do |k|
      flag = true if b[k] == A[i][j]
    end


    if flag == true
      A[i][j] = 1
    else
      A[i][j] = 0
    end
  end
end

if A[0][0] == 1 && A[1][1] == 1 && A[2][2] == 1
  puts 'Yes'
  exit
end

if A[0][2] == 1 && A[1][1] == 1 && A[2][0] == 1
  puts 'Yes'
  exit
end


3.times do |i|
  if A[i][0] == 1 && A[i][1] == 1 && A[i][2] == 1
    puts 'Yes'
    exit
  end
end

3.times do |j|
  if A[0][j] == 1 && A[1][j] == 1 && A[2][j] == 1
    puts 'Yes'
    exit
  end
end


puts 'No'

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }
  
  
  
  
  
  
  const int mod = 1000000007 ;//998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}   ;
  
  
  
  
  
  
  int main() {
   ll n ;cin>> n ;
   vector<ll> A(n) ; rep(i,n) cin>>A[i] ;
   map<ll,ll> mp ;
  mint lcm=1 ;
  rep(i,n){
    map<ll,ll> so= factor(A[i]) ;
     for(auto p :so){
      ll  unti=p.second-mp[p.first] ;
      if(unti>0){
         mp[p.first]=p.second ;
         rep(i,unti) lcm*=p.first ;
      }
     }
  }
  mint ans= 0;
  rep(i,n){
   ans+= lcm/A[i] ; 
  }
    cout<<ans<<endl ;
  return 0;
}

Measured memory_bytes: 896
S,T=input(),input()
S_l=len(S)
T_l=len(T)
score=[]

for i in range(S_l-T_l+1):
  score_1=0
  S0=S[i:i+T_l]
  for j in range(T_l):
    if T[j]==S0[j]:
      score_1=score_1+1
  score.append(T_l-score_1)

print(min(score))  

Measured memory_bytes: 73832
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());
#define OUT(d) cout << (d);
#define OUT_L(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define CEIL(x, y) ((x + y - 1) / (y))

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

const ll MOD = 1000000007; // 10^9 + 7

const int MAX_N = 100;
ll N;
ll dp[MAX_N][MAX_N];
vector<ll> p(MAX_N + 1);

ll solve(int l, int r) {
  if (dp[l][r] != 0) return dp[l][r];
  if (l == r) return 0;

  ll ret = __INT_MAX__;
  REP(i, r - l) {
    ret = min(ret, solve(l, l + i) + solve(l + i + 1, r) + p[l] * p[l + i + 1] * p[r + 1]);
  }
  return dp[l][r] = ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  cin >> N;

  cin >> p[0];
  for(int i = 1; i <= N - 1; i++) {
    cin >> p[i];
    cin >> p[i];
  }
  cin >> p[N];
  memset(dp, 0, sizeof(dp));

  OUT_L(solve(0, N - 1))
}



Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(a) (a).begin(),(a).end()


int main(){
  ll x,y;
  cin >> x >> y;
  for(ll i=0;i<=50;++i){
    for(ll j=0;j<=25;++j){
      if( i*2 + j*4 == y && i+j == x ){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
int a_1(int a) {										//素数判定
	int x = 0;
	for (int i = 2; i < a; i++) {
		if (a % i == 0)x++;
	}
	if (x == 0) {
		return 0;//素数であるとき
	}
	if (x != 0) {
		return 1;//素数でないとき
	}
}
int gcd(int a, int b) {
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
int main() {
	string s, t;
	int ans = 0;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) != t.at(i)) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 2e5 + 5;
    
  
void solve() {

   int n,k,ans=-infl;
   cin>>n>>k;
   vi a(n+1), c(n+1);
   fr(i,1,n)
     cin>>a[i];
   fr(i,1,n)
     cin>>c[i];
   vi comp(n+1),l(n+1),sum(n+1);
   fr(i,1,n){
     int v = i;
     while (!comp[v]){
       comp[v]=i;
       l[i]++;
       sum[i]+=c[v];
       v=a[v];
     }
   }
   fr(i,1,n){
     int j = k, t = 0, mx = -infl, pre=0,v=i;
     int s = sum[comp[i]], len=l[comp[i]];

    if(j>=2*len){
       j=j%len+len;
       if(s>0){
         t=(k/len-1)*s;
         mx=0;
       }
       rep(_,0,j)
         pre+=c[v], mx=max(mx,pre), v = a[v];
     }else{
       rep(_,0,j)
         pre+=c[v], mx=max(mx,pre), v = a[v];
     }
     ans=max(ans,t+mx);
   }
   cout<<ans;
}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}


int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}


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

int main()
{
    int num;
    scanf("%d",&num);
    vector<int> v;
    for(int i=0;i<num;i++){
        int current;
        scanf("%d",&current);
        v.push_back(current);
    }
    printf("%d\n",*max_element(v.begin(),v.end())-*min_element(v.begin(),v.end()));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    string s;
    cin>>s;
    int res=0;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]!=s[i+1])res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
    u64 N, M;
    cin >> N >> M;

    u64 lM = M / 2;
    u64 lN = N / 2;
    u64 rM = M - lM;
    u64 rN = N - lN;

    if(lN == rN) {
        lN--;
    }

    for(u64 i=0, l=1, r=lN; i<lM; i++, l++, r--) {
        cout << l << " " << r << endl;
    }

    for(u64 i=0, l=N/2+1, r=N; i<rM; i++, l++, r--) {
        cout << l << " " << r << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000;
const char ENDL = '\n';

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll H, W;
	char S[100][100];
	cin >> H >> W;
	rep(i, H) {
		rep(j, W)
			cin >> S[i][j];
	}
	bool flag = true;
	rep(i, H) {
		rep(j, W) {
			if (S[i][j] == '#')
				if ((S[i - 1][j] == '#') || (S[i + 1][j] == '#') || (S[i][j - 1] == '#') || (S[i][j + 1] == '#'));
				else
					flag = false;
		}
	}
	if (flag == true)
		cout << "Yes" << ENDL;
	else
		cout << "No" << ENDL;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N;
    cin >> N;
    vector<int> vec(N);
    REP(i, N) cin >> vec.at(i);
    
    // calculation
    cout << *MAX(vec) - *MIN(vec) << "\n";
    
    return 0;
}


Measured memory_bytes: 256