akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
	int m, f, r;

	while (1)
	{
		cin >> m >> f >> r;

		if (m == -1 && f == -1 && r == -1)
			break;
		else if (m==-1 || f==-1)
			cout << "F" << endl;
		else if (m + f < 30)
			cout << "F" << endl;
		else if (m + f >= 30 && m + f < 50)
		{
			if (r >= 50)
				cout << "C" << endl;
			else
				cout << "D" << endl;
		}
		else if (m + f >= 50 && m + f < 65)
			cout << "C" << endl;
		else if (m + f >= 65 && m + f < 80)
			cout << "B" << endl;
		else if (m + f >= 80)
			cout << "A" << endl;

	}

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
vector<ll> vec[N];
ll n,m,a[N],par[N],sz[N];
void init(ll n){
    for(ll i=0;i<n;i++)par[i]=i,sz[i]=1;
}
ll dsu_parent(ll node){
    if(node==par[node])return node;
    return par[node]=dsu_parent(par[node]);
}
void dsu_union(ll a,ll b){
    a=dsu_parent(a);
    b=dsu_parent(b);
    if(a==b)return;
    if(sz[a]<sz[b])swap(a,b);
    sz[a]+=sz[b];
    par[b]=a;
}
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    for(ll i=0;i<n;i++)cin>>a[i];
    init(n);
    for(ll i=0;i<m;i++){
        ll u,v;cin>>u>>v;
        dsu_union(u,v);
    }
    ll cnt=0;
    for(ll i=0;i<n;i++){
        ll pr=dsu_parent(i);
        if(pr==i)cnt++;
        vec[pr].push_back(a[i]);
    }
    if( (cnt-1)*2 > n)return cout<<"Impossible" , 0;
    if(cnt==1)return cout<<"0" , 0;

    ll ans = 0;
    vector<ll> nodes;
    for(ll i=0;i<n;i++){
        if(dsu_parent(i)!=i)continue;
        sort(vec[i].begin(),vec[i].end());
        ans+=vec[i][0];
        for(ll j=1;j<(ll)vec[i].size();j++)nodes.push_back(vec[i][j]);
    }
    sort(nodes.begin(),nodes.end());
    for(ll i=0;i<cnt-2;i++)ans+=nodes[i];
    cout<<ans;
}

Measured memory_bytes: 8064
from heapq import heappush, heappop

def main():
    INF = float("inf")

    N, M, *LRC = map(int, open(0).read().split())

    E = [[] for _ in range(N)]
    for i in range(N - 1):
        E[i + 1].append((i, 0))
    for l, r, c in zip(*[iter(LRC)] * 3):
        E[l - 1].append((r - 1, c))

    D = [INF] * N
    D[0] = 0

    Q = [0]
    while Q:
        dist, cur = divmod(heappop(Q), 100010)
        for nxt, cost in E[cur]:
            cand = dist + cost
            if D[nxt] > cand:
                D[nxt] = cand
                heappush(Q, cand * 100010 + nxt)

    print(-1 if D[N - 1] == INF else D[N - 1])

main()


Measured memory_bytes: 50172
def merge(A, left, mid, right):
    cnt_local = 0
    leftA = A[left:mid]
    rightA = A[mid:right]
    leftA.append(INF)
    rightA.append(INF)
    l = 0
    r = 0
    for i in range(left, right):
        if leftA[l] <= rightA[r]:
            A[i] = leftA[l]
            l += 1
        else:
            A[i] = rightA[r]
            r += 1
            cnt_local += len(leftA) - l - 1
    return cnt_local


def mergeSort(A, left, right):
    if right - left < 2:
        return 0
    mid = left + (right - left) // 2
    v1 = mergeSort(A, left, mid)
    v2 = mergeSort(A, mid, right)
    v3 = merge(A, left, mid, right)
    return v1 + v2 + v3


if __name__ == "__main__":
    INF = 10000000000
    n = int(input())
    S = list(map(int, input().split()))
    num = 0
    cnt = mergeSort(S, 0, len(S))
    print(cnt)

Measured memory_bytes: 30328
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    char x,y;
    cin>>x>>y;
    if (x>y)
        cout<<">\n";
    else if (x<y)
        cout<<"<\n";
    else
        cout<<"=\n";
}

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;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> ans(n);
    rep(i,n){
        ans[a[i]-1] = i+1;
    }
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskEE solver = new TaskEE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskEE {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long res = solveMe(n);
            out.println(res);
            //loop();
        }

        private long solveMe(long n) {
            if (n % 2 == 1)
                return 0;
            long res = 0;
            long divi = 10;
            while (true) {
                long nb = n / divi;
                if (nb == 0)
                    break;
                res += nb;
                divi *= 5;
            }

            return res;
        }

    }
}



Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(0, c - (a - b)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  vi a(26,0);
  rep(i,s.size())a[s[i]-'a']++;
  rep(i,26)if(a[i]==0){
    cout<<(char)('a'+i)<<endl;
    return 0;
  }
  cout<<"None"<<endl;
}


Measured memory_bytes: 512
for _ in range(int(input())):
  n=int(input())
  a=list(map(int,input().split()))
  s=input()
  b=[]
  ans=0
  for i in range(n-1,-1,-1):
    for j in b:
      a[i]=min(a[i],a[i]^j)
    if a[i]!=0:
      if s[i]=="0":
        b.append(a[i])
      else:
        ans=1
  print(ans)

Measured memory_bytes: 8824
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int k;
char s[110];
int main() {
	scanf("%d%s", &k, s + 1);
	int n = strlen(s + 1);
	if (n <= k) {
		for (int i = 1; i <= n; i++) {
			cout << s[i];
		}
	} else {
		for (int i = 1; i <= k; i++) {
			cout << s[i];
		} cout << "...";
	}
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#define ll long long
using namespace std;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  ll ab = b-a;
  if (ab%2 == 0){
    cout << ab/2 << endl;
    return 0;
  }
  else{
    cout << min (a-1, n-b) + 1 + (b-a-1)/2 << endl;
  }
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  int ans = 0;
  for(int i = 0; i < m; ++i) ans |= 1 << i;
  
  for(int i = 0; i < n; ++i)
  {
    int k, tmp = 0;
    cin >> k;
    for(int c = 0; c < k; ++c)
    {
      int a;
      cin >> a;
      tmp |= 1 << a - 1;
    }
    ans &= tmp;
    tmp = 0;
  }
  int sum = 0;
  for(int i = 0; i < m; ++i) sum += 0 < (ans & 1 << i);
  cout << sum << endl;
}

Measured memory_bytes: 256
n, q = map(int, input().split())

# 各ノードのリンクを記録
link_set = [set() for _ in range(n-1)]
for i in range(n-1):
  a, b = map(int, input().split())
  link_set[a - 1].add(b)

# カウンターの計算を実施 (O(QN)の計算を避けることがポイント)

## O(Q)の計算
counters = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  counters[p - 1] += x
  
## O(N)の計算
for i in range(n - 1):
  for node in link_set[i]:
    counters[node - 1] += counters[i]

str_counters = [str(c) for c in counters]
print(' '.join(str_counters))

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

int a, b, c;

int main() {
    cin >> a >> b >> c;
    cout << min(c, b/a) << endl;
}

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

using namespace std;

void PrimalFactorize(int Nin, vector<int> &ans)
{

  int p = 2;
  const int Nsqrt = sqrt(Nin);

  while(Nin != 1 && p <= Nsqrt)
  {

    for(int i = 0; i < ans.size(); ++i)
    {
      if(p % ans[i] == 0 && p != ans[i])
      {
	p += 2;
	continue;
      }
    }

    if(Nin % p == 0)
    {
      ans.push_back(p);
      Nin /= p;
    }
    else 
    {
      if(p == 2)
	++p;
      else 
	p += 2;
    }
  }

  if(Nin != 1)
    ans.push_back(Nin);

  return;
}

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

  vector<int> ans;

  PrimalFactorize(N, ans);

  cout << N << ":";

  for(int i = 0; i < ans.size(); ++i)
    cout << " " << ans[i];
  cout << endl;

  return 0;
}



Measured memory_bytes: 3164
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	string s; cin >> s;
	reverse(s.begin(), s.end());
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define LP(i, a, n) for(int i = a; i < n; i++)
#define lpp(i, n) for(int i = 0; i < n; i++)
using namespace std;
struct node {
  struct node *prev;
  struct node *next;
  int key;
};
typedef struct node node;
int main() {
  node* head;
  head = (node*)malloc(sizeof(node));
  head->key = 10000000;
  head->prev = head;
  head->next = head;
  int n;
  string cmd;
  int num;
  node *nn;
  cin >> n;
  lp(n) {
    cin >> cmd;
    if(cmd == "insert") {
      cin >> num;
      nn = (node*)malloc(sizeof(node));
      if(nn == NULL)exit(1);
      nn->next = head->next;
      nn->prev = head;
      nn->key = num;
      head->next->prev = nn;
      head->next = nn;
    }
    else if(cmd == "delete") {
      cin >> num;
      for(node *a = head->next; a != head; a = a->next){
	if(a->key == num) {
	  
	  a->prev->next = a->next;
	  a->next->prev = a->prev;
	  
	  break;
	}
      }
    }
    else if(cmd == "deleteFirst") {
      head->next = head->next->next;
      head->next->prev = head;
    }
    else if(cmd == "deleteLast") {
      head->prev = head->prev->prev;
      head->prev->next = head;
    }
  }
  for(node *a = head->next; a != head; a = a->next) cout << a->key << ((a->next == head)? "\n" : " ");
  return 0;
}




Measured memory_bytes: 37452
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int DP[301][3];
string name[301];
int C[301];
int Para[301][3];
int main(void){
  int N,M;
  while(cin>>N>>M){
    REP(i,301)REP(k,3)DP[i][k]=0;
    REP(i,N){
      cin.ignore();
      getline(cin,name[i]);
      cin>>C[i]>>Para[i][0]>>Para[i][1]>>Para[i][2];
    }
    for(int i=0; i<N; i++){
      for(int j=0; j<=M; j++){
        REP(k,3){
          if(j-C[i]>=0)
            DP[j][k] = max(DP[j][k], DP[j-C[i]][k] + Para[i][k]);
        }
      }
    }
    int ans = 0;
    REP(k,3){
      ans = max(ans, DP[M][k]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 956
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N;
    cin >> N;
    ll x[N], y[N], h[N];
    for(ll i = 0; i < N; i++) cin >> x[i] >> y[i] >> h[i];
    for(ll cx = 0; cx <= 100; cx++){
        for(ll cy = 0; cy <= 100; cy++){
            ll H = -1;
            for(ll i = 0; i < N; i++){
                if(!h[i]) continue;
                ll xcx = abs(x[i] - cx);
                ll ycy = abs(y[i] - cy);
                H = h[i] + xcx + ycy;
                break;
            }
            if(H == -1) break;
            bool suc = 1;
            for(ll i = 0; i < N; i++){
                ll xcx = abs(x[i] - cx);
                ll ycy = abs(y[i] - cy);
                if(max<ll>(H - xcx - ycy, 0) != h[i]){
                    suc = 0;
                    break;
                }
            }
            if(suc){
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

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

// const int mxN = 1e9 + 7;
const int M = 1e9 + 7;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % M;
		b = (b * b) % M;
		e >>= 1; // e/=2;
	}
	return res;
}

// ll fact[mxN + 1], inv[mxN + 1];
// ll C(ll n, ll k)
// {
// 	return (((fact[n] * inv[k]) % M) * inv[n - k]) % M;
// }
// ll f1[M + 1], f2[M + 1];
// ll C(int n, int k)
// {
// 	return (((f1[n] * f2[k]) % M) * f2[n - k]) % M;
// }

int main()
{
	fast;
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (u == s)
	{
		cout << a - 1 << " " << b;
	}
	else
	{
		cout << a << " " << b - 1;
	}
}

Measured memory_bytes: 3584
S = input()
Cs = [i for i, c in enumerate(S) if c == "C" and 2 <= i <= len(S) - 2]
if S[0] == "A" and len(Cs) == 1 and (S[1 : Cs[0]] + S[Cs[0] + 1 :]).islower():
    print("AC")
else:
    print("WA")


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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
ll sum(ll num){
  ll ret=0;
  while(num>0){
    ret+=num%10;
    num/=10;
  }
  return ret;
}
int main(){
  ll a,b,c;
  string s1,s2;
  cin>>a;
  ll ans=llINF;
  for(ll i=1;i<a;i++){
    ans=min(ans,sum(i)+sum(a-i));
  }
  cout<<ans<<endl;
  return 0;
}


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

#ifdef SG
	#include <debug.h>
#else
	template<typename T> struct outputer;
	struct outputable {};
	#define PRINT(...)
	#define OUTPUT(...)
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
	#define fbegin(...)
	#define fend
	#define pbegin(...)
	#define pend
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb emplace_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t ui;
typedef uint16_t us;
typedef uint8_t uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 100000;

struct Input {
	int n;
	vi e[N];
	
	bool read () {
		if (!(cin >> n)) {
			return 0;
		}
		forn (i, n - 1) {
			int x, y;
			scanf("%d%d", &x, &y);
			--x;
			--y;
			e[x].pb(y);
			e[y].pb(x);
		}
		return 1;
	}

	void init (const Input &input) {
		*this = input;
	}
};

struct Data: Input {
	bool ans;
	
	void write () {
		puts(ans ? "Alice" : "Bob");
	}
};


namespace Main {
	
	struct Solution: Data {
		int dfs (int v, int pr) {
			int res = 0;
			for (int to : e[v]) {
				if (to == pr) {
					continue;
				}
				res ^= dfs(to, v) + 1;
			}
			return res;
		}
		
		void solve () {
			ans = dfs(0, -1);
		}
		
		void clear () {
			*this = Solution();
		}
	};
}


Main::Solution sol;

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);

	#ifdef SG
		freopen((problemname + ".in").c_str(), "r", stdin);
//		freopen((problemname + ".out").c_str(), "w", stdout);
		while (sol.read()) {
			sol.solve();
			sol.write();
			sol.clear();
		}
	#else
		sol.read();
		sol.solve();
		sol.write();
	#endif
	
	/*
	int t;
	cin >> t;
	forn (i, t) {
		sol.read();
		sol.solve();
		sol.write();
		sol.clear();
	}
	*/
	
	return 0;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


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

    ll ans = 0;

    ll a[n];
    rep(i,n){
        cin >> a[i];
    }
    sort(a,a+n);

    srep(i,1,n){
        ll times = (a[i]-a[0])/(n+1);
        a[i] -= n*times;
        ans += times;
        rep(j,n){
            if(j!=i){
                a[j] += times;
            }
        }
    }

    sort(a,a+n);

    ll times = max((ll)0,a[0]-(ll)n);

    rep(i,n){
        a[i] -= times;
        ans += times;
    }

    int flag = 0;

    while(true){
        rep(i,n){
            if(a[i]>=n){
                flag = 1;
                rep(j,n){
                    a[j]++;
                }
                a[i] -= n+1;
                ans++;
            }
        }
        if(flag==0)break;
        flag = 0;
    }



    cout << ans << endl;
    return 0;
}
 
 


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  if(s=="ABC") cout<<"ARC"<<endl;
  else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3640
main :: IO ()
main = do
    line <- getLine
    let
        nums = string2Ints line
    if [0,0] == nums
       then return ()
       else do
           putStrLn $ ints2String $ qsort $ string2Ints line
           main

string2Ints :: String -> [Int]
string2Ints str = map (\x -> read x :: Int) (words str)

qsort :: [Int] -> [Int]
qsort [] = []
qsort (n:ns) = (qsort lower) ++ [n] ++ (qsort upper)
    where
        lower = [x | x <- ns, x <= n]
        upper = [x | x <- ns, n <  x]

ints2String :: [Int] -> String
ints2String ns = unwords $ map show ns

Measured memory_bytes: 4088
import java.util.*;

class Main{
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int tarou = 0;
		int hanako = 0;

		for (int i = 0; i < n; i++) {
			String t = sc.next();
			String h = sc.next();
			if (t.compareTo(h) > 0)
				tarou += 3;
			else if (t.compareTo(h) < 0)
				hanako += 3;
			else {
				tarou += 1;
				hanako += 1;
			}
		}
		System.out.println(tarou + " " + hanako);
	}
}


Measured memory_bytes: 30716
#include <stdio.h>

void matrixChainOrder(int *);

int n;
double m[100][100];

int main() {
  int r[100],c[100],p[100],i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&r[i],&c[i]);
  }

  for(i=0;i<n;i++){
    p[i]=r[i];
  }
  p[n]=c[n-1];

  matrixChainOrder(p);

   printf("%d\n",(int)m[1][n]);


  return 0;
}

void matrixChainOrder(int *p){
  int len,l,q,i,j,k;
  len = n-1;
  for(i=1;i<=len;i++) m[i][i]=0;
  for(l=2;l<=len+1;l++){

    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j] = (double)1.0/0.0;
      for(k=i;k<=j-1;k++){
	q=m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	if(m[i][j]>q)  m[i][j] = q;
      }
    }
  }
}

Measured memory_bytes: 668
#include<bits/stdc++.h>
#define MAX 100000
using namespace std;
int n,a[MAX+5],cnt_first[MAX+5],cnt_second[MAX+5],cnt[MAX+5];
vector<int>q;
void run()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	scanf("%d",&a[i]);
}
int rule(int a,int b)
{
	return a>b;
}
void solve()
{
	for(int i=1; i<=n; i++)
	{
	   if(i%2==1)
		cnt_first[a[i]]++;
		 else
		  cnt_second[a[i]]++;
	}
	for(int i=1; i<=100000; i++)
	{
		q.push_back(max(cnt_first[i],cnt_second[i]));
	}
	sort(q.begin(),q.end(),rule);
	int ans=0;
	for(int i=0; i<2; i++)
	{
	    ans+=n/2-q[i];
	}
	printf("%d",ans);
}
int main()
{
	run();
	solve();
	return 0;
} 

Measured memory_bytes: 2044
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        int zeroStart = 0;
        for (int i = 0; i < S.length(); i++) {
            if (i % 2 == 0) {
                if (S.charAt(i) != '0') {
                    zeroStart++;
                }
            } else {
                if (S.charAt(i) != '1') {
                    zeroStart++;
                }
            }
        }

        int oneStart = 0;
        for (int i = 0; i < S.length(); i++) {
            if (i % 2 == 0) {
                if (S.charAt(i) != '1') {
                    oneStart++;
                }
            } else {
                if (S.charAt(i) != '0') {
                    oneStart++;
                }
            }
        }

        out.print(Math.min(oneStart, zeroStart));
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    int A0 = 0, A1 = 0;
    for (int i = N - 1; i > 0; i--) {
        if (A[i] == A[i - 1]) {
            if (A0 == 0) {
                A0 = A[i];
                i--;
            } else if (A1 == 0) {
                A1 = A[i];
                break;
            }
        }
    }
    cout << 1LL * A0 * A1 << endl;
}

Measured memory_bytes: 640
T = input().strip()

result = []
score = 0
prev = None
for c in T:
	if c == "D" or c == "?":
		if prev == "P":
			score += 2
		else:
			score += 1
		result.append("D")
		prev = "D"
	elif c == "P":
		result.append("P")
		prev = "P"

print("".join(result))
#print(score)


Measured memory_bytes: 11020
#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
//#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(bool);
void precalc();
clock_t start;
int main() {
#ifdef AIM
  freopen("/home/alexandero/ClionProjects/ACM/input.txt", "r", stdin);
  //freopen("/home/alexandero/ClionProjects/ACM/output.txt", "w", stdout);
  //freopen("out.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  start = clock();
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
    //cout << "Case #" << testNum++ << ": ";
    //cerr << testNum << endl;
    solve(true);
    //cerr << testNum - 1 << endl;
  }
  cout.flush();
#ifdef AIM1
  while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif

  return 0;
}

//BE CAREFUL: IS INT REALLY INT?

template<typename T>
T binpow(T q, T w, T mod) {
  if (!w)
    return 1 % mod;
  if (w & 1)
    return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template<typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
  sort(all(a));
  a.erase(unique(all(a)), a.end());
}

void precalc() {}

template<typename T>
void relax_min(T& cur, T val) {
  cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
  cur = max(cur, val);
}

//#define int li
//const int mod = 1000000007;

void solve(bool read) {
    int h, w;
    cin >> h >> w;
    vector<int> num(26);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            ++num[c - 'a'];
        }
    }

    int need_four = (h / 2) * (w / 2);
    for (int i = 0; i < 26; ++i) {
        while (num[i] >= 4 && need_four) {
            --need_four;
            num[i] -= 4;
        }
    }
    if (need_four > 0) {
        cout << "No\n";
        return;
    }

    int need_two = 0;
    if (h % 2 == 1) {
        need_two += (w / 2);
    }
    if (w % 2 == 1) {
        need_two += (h / 2);
    }
    for (int i = 0; i < 26; ++i) {
        while (num[i] >= 2 && need_two) {
            --need_two;
            num[i] -= 2;
        }
    }
    if (need_two > 0) {
        cout << "No\n";
        return;
    }

    cout << "Yes\n";

}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX_N (10^6)
#define MAX_M (10^4)

int main(){
    int N;
    int M;
    int a;
    long long int shukudai = 0;

    scanf("%d %d", &N, &M);
    for(auto i=0; i<M; i++){
        scanf("%d", &a);
        shukudai += a;
    }

    if(shukudai <= N){
        printf("%lld", N - shukudai);
    }else{
        printf("-1");
    }

    return(0);
}

Measured memory_bytes: 1732
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int main()
{
	ll n,ans=0; cin>>n;
	for(ll i=1;i<=n;i++)
	{
		if(i%3!=0&&i%5!=0) ans+=i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int a[100];
int main(){
	int n, x;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int co = 0;
	for (int j = 0; j < n; j++) {
		if (x >= a[j]) {
			co++;
			x -= a[j];
		}
	}
	if (co == n) {
		if (x != 0) {
			co--;
		}
	}
	cout << co << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    long long h, w;
    cin >> h >> w;
    if(h % 3 == 0 || w % 3 == 0){
        cout << 0 << endl;
        return 0;
    }

    long long ans = min(h, w);
    for(int i=0; i<2; ++i){
        for(long long y1=1; y1<h; ++y1){
            long long y2 = h - y1;
            long long x1 = w / 2;
            long long x2 = (w + 1) / 2;
            vector<long long> v = {y1 * w, y2 * x1, y2 * x2};
            sort(v.begin(), v.end());
            ans = min(ans, v[2] - v[0]);
        }
        swap(h, w);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long

int main () {
  ll n;
  cin >> n;
  ll abc[n][3], dp[n][3];
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < 3; j++) {
      cin >> abc[i][j];
      dp[i][j] = abc[i][j];
      if (i != 0) {
        ll max = 0;
        for (ll l = 0; l < 3; l++) {
          if (j != l) {
          	if (max <= dp[i - 1][l]) {
              max = dp[i - 1][l];
            }  
          }
        }
        dp[i][j] += max;
      }
    }
  }
  ll max = 0;
  for (ll i = 0; i < 3; i++) {
    if (max <= dp[n - 1][i]) {
      max = dp[n - 1][i];
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define FOR(i,l,r) for(int i=l,END=r;i<=END;i++)
#define DOR(i,r,l) for(int i=r,END=l;i>=END;i--)
#define loop(i,n) for(int i=0,END=n;i<END;i++)
#define sf scanf
#define pf printf
#define push_back pb
#define mms(a,x) memset(a,x,sizeof a)
#define pii pair<int,int>
#define ll long long
#define db long double
using namespace std;
const int N=2e5+5,P=1e9+7;
int n,ans;
int a[N],sum[N];
int main(){
	sf("%d",&n);
	FOR(i,1,n)sf("%d",&a[i]);
	ans=1;
	sum[a[1]]=1;
	FOR(i,2,n){
		if(a[i]!=a[i-1])ans=(ans+sum[a[i]])%P;
		sum[a[i]]=ans;
//		pf("i:%d ans:%d\n",i,ans);
	}
	pf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=310;
const int inf=0x3f3f3f3f;
int n,m,l,q;
int w[N][N];
int main()
{
    scanf("%d%d%d",&n,&m,&l);
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
        w[i][j]=inf;
        if(i==j)
        w[i][j]=0;
    }
    for(int i=1;i<=m;i++)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        w[a][b]=c; w[b][a]=c;
    }
    for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
        if(w[i][k]+w[k][j]<w[i][j])
        w[i][j]=w[i][k]+w[k][j];
        //w[i][j]=min(w[i][j],w[i][k]+w[k][j]);
    }
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
        if(w[i][j]<=l)
        w[i][j]=1;
        else
        w[i][j]=inf;
    }
    for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
        if(w[i][k]+w[k][j]<w[i][j])
        w[i][j]=w[i][k]+w[k][j];
        //w[i][j]=min(w[i][j],w[i][k]+w[k][j]);
    }
    scanf("%d",&q);
    while(q--)
    {
        int s,t;
        scanf("%d%d",&s,&t);
        if(w[s][t]==inf)
            printf("-1\n");
        else
            printf("%d\n",w[s][t]-1);
    }
    return 0;
}


Measured memory_bytes: 768
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

class IntMutableList {
  private val initialCapacity = 10
  private var innerArray = IntArray(initialCapacity)
  var size = 0
    private set

  fun add(x: Int) {
    if (size == innerArray.size) {
      innerArray = innerArray.copyOf(innerArray.size * 2)
    }
    innerArray[size] = x
    size++
  }

  fun toIntArray(): IntArray = innerArray.copyOfRange(0, size)
}

fun main(args: Array<String>) {
  val (n, k, q) = fastReadInts(3)
  val xs = fastReadInts(n)

  var ans = Int.MAX_VALUE

  // Define here for performance.
  val forbidden = BooleanArray(n)
  for (l in xs) {
    forbidden.fill(false)

    for (i in 0 until n) {
      if (xs[i] < l) {
        forbidden[i] = true
      }
    }

    val mutCandidates = IntMutableList()
    var s = 0
    while (s < n) {
      if (forbidden[s]) {
        s++
      } else {
        var t = s
        while (t + 1 < n && !forbidden[t + 1]) {
          t++
        }
        // xs[s]..xs[t] is a valid range.
        val segmentLength = t - s + 1
        if (segmentLength >= k) {
          val segmentValues = mutableListOf<Int>()
          for (i in s..t) {
            segmentValues.add(xs[i])
          }
          segmentValues.sort()
          for (i in 0 until segmentLength - k + 1) {
            mutCandidates.add(segmentValues[i])
          }
        }
        s = t + 1
      }
    }

    if (mutCandidates.size < q) continue

    val candidates = mutCandidates.toIntArray()
    candidates.sort()
    val u = candidates[q - 1]
    ans = Math.min(u - l, ans)
  }
  println(ans)
}


Measured memory_bytes: 107784
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;


ll N, M;
pair<int,bool> box[100001];


int main() {

	box[1].second = true;
	
	cin >> N >> M;
	
	FOR(i, 0, N+1)box[i].first = 1;
	FOR(i, 0, M) {

		int a, b;
		cin >> a >> b;

		if (box[a].second == true) {
			box[b].second = true;
			if (box[a].first == 1)box[a].second = false;
		}
		
		
		box[a].first--;
		box[b].first++;


	}

	int ans = 0;
	FOR(i, 1, N + 1)if (box[i].second == true)ans++;
	ct(ans);

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int d, c = 0;
    d = i;
    while (d) {
      c += d % 10;
      d /= 10;
    }
    if (a <= c && c <= b)
      ans += i;
  }
  cout << ans << endl;
}


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

int main() {
  int D;
  cin >> D;
  if(D==22){
    cout << "Christmas Eve Eve Eve";
  }else if(D==23){
    cout << "Christmas Eve Eve";
  }else if(D==24){
    cout << "Christmas Eve";
  }else{
    cout << "Christmas";
  }
}


Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl

//毎回変える場所
#define N_MAX 200
#define A_MAX 100000

//問題文のとおり
int N,temp;
vector<int> a;
int num[A_MAX];

int main() {
	cin >> N;
	REP(i, N) {
		cin >> temp;
		num[temp]++;
	}
	int ans = 0;
	FOR(i, 1, A_MAX - 1) {
		ans = max(ans, num[i - 1] + num[i] + num[i + 1]);
	}
	cout << ans << endl;
	cin >> N;

	return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
#define N 100
#define INFTY -1

int min(int,int);
void Matrix(int);

int p[N+1],m[N+1][N+1];

int main() {

  int n,i;

  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d %d",&p[i-1],&p[i]);

  Matrix(n);

  printf("%d\n",m[1][n]);

  return 0;

}

int min(int a,int b) {
  if(a>=b) return b;
  else return a;
}

void Matrix(int n) {
  
  int i,j,k,l;

  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++) {
    for(i=1;i<=n-l+1;i++) {
      j = i+l-1;
      m[i][j] = (1 << 21);
      for(k=i;k<=j-1;k++) {
	m[i][j] = min( m[i][j] , m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j] );
      }
    }
  }
}



Measured memory_bytes: 2088
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	s := getNextString(scanner)
	l := 0
	r := n
	var ans int
	for l < r {
		for l < n && s[l] == 'R' {
			l++
		}
		for r > 0 && s[r-1] == 'W' {
			r--
		}
		if l < r {
			ans++
			l++
			r--
		}
	}
	fmt.Fprintln(writer, ans)
}


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

using namespace std;


int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N - 1);

  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  for(int i = 0; i < N; ++i){
    cin >> B[i];
  }
  for(int i = 0; i < N - 1; ++i){
    cin >> C[i];
  }

  int count = 0;
  int pre = -2;

  for(int i = 0; i < N; ++i){
    count += B[A[i] - 1];
    if (i != 0 && A[i] == pre + 1){
      count += C[pre - 1];
    }
    pre = A[i];
  }
  cout << count << endl;

  return 0;
};


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

s = readline()
n = len(s)
count = 0
max = 0
for i in range(n):
    if s[i] in 'ACGT':
        count +=1
        if max < count:
            max = count
    else:
        count = 0
print(max)


Measured memory_bytes: 3060
from sys import stdin
K,A,B=[int(x) for x in stdin.readline().rstrip().split()]

ans1 = K + 1
ans2 = 0

K = K - (A-1)
if K > 0:
    ans2 += A
    ans2 += (K//2)*(B-A)
    ans2 += (K%2)
print(max(ans1,ans2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
  ll n,a[10005]={0};
  cin>>n;
  for(int i=1;i<100;i++)
  {
    for(int j=1;j<100;j++)
    {
      for(int k=1;k<100;k++)
      {
        ll v=i*i +j*j + k*k + i*j + j*k + i*k;
        if(v<=10004)
          a[v]++;
      }
    }
  }  
  for(int i=1;i<=n;i++)
    cout<<a[i]<<"\n";
  return 0;
}

Measured memory_bytes: 3696
#include<stdio.h>
int main(void){
	long long a,b,c,d,e;
	long long g;
	long long r;
	while(scanf("%lld%lld",&d,&e)==2){
		if(d!=e){
		
			a=d>e?d:e;
			b=d>e?e:d;
		r=a*b;
		while(a%b!=0){
			c=b;
			b=a%b;
			a=c;
		}
		g=b;
		}
		else {
			r=d*e;
			g=d;
		}

		printf("%lld %lld\n",g,r/g);
	}
	return 0;
}

Measured memory_bytes: 592
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long ans1 = 0;
			{
				long cnt = Math.Min(a[0], Math.Min(a[3], a[4]));
				if (cnt > 0) {
					ans1 += 3;
					ans1 += (a[0] - 1) / 2 * 2;
					ans1 += a[1];
					ans1 += (a[3] - 1) / 2 * 2;
					ans1 += (a[4] - 1) / 2 * 2;
				}
			}

			long ans2 = 0;
			{
				ans2 += a[0] / 2 * 2;
				ans2 += a[1];
				ans2 += a[3] / 2 * 2;
				ans2 += a[4] / 2 * 2;
			}

			Console.WriteLine(Math.Max(ans1, ans2));
		}
	}
}

Measured memory_bytes: 13396
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7



def solve(n, k):
    if n % k == 0:
        return n // k
    diff = (n // k) + 1
    target = n - n % k
    r = n % k
    if r % diff == 0:
        return solve(target, k)
    n -= -((-(n - target)) // diff) * diff
    return solve(n, k)


n = I()
ret = 0
for i in range(n):
    a, k = LI()
    ret ^= solve(a, k)

print("Takahashi" if ret else "Aoki")


Measured memory_bytes: 113404
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,m;
  cin>>n>>m;
  vector<ll> x(n);
  vector<ll> y(m);
  rep(i,n)cin>>x[i];
  rep(i,m)cin>>y[i];
  ll a=0;
  ll b=0;
  const ll p = 1e9+7;
  rep(i,n) {
    a+=(2*(i+1)-n-1)*x[i];
    a%=p;
  }
  rep(i,m) {
    b+=(2*(i+1)-m-1)*y[i];
    b%=p;
  }
  cout << (a*b)%p << endl;
  return 0;
}


Measured memory_bytes: 1792
n,a,b=map(int,input().split())
def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

x=pow(2,n,10**9+7)-1
y=comb(n,a)+comb(n,b)
ans=x-y





while ans<0:
          ans+=10**9+7
print(ans)






Measured memory_bytes: 3188