akhauriyash/Code-Regression huggingface dataset:
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int main(void){
    int n;cin >> n;
    vector<int> a(n);rep(i,n)cin >> a[i];
    sort(all(a));
    bool check = true;
    if(a[0] == a[n-1]){
        if(a[0] != n - 1 and 2*a[0] > n)check = false;
    }else{
        int cnt = 0;
        rep(i,n)if(a[i] == a[0])cnt++;
        if(a[0] < cnt){
            check = false;
        }
        if((a[n-1] - cnt)*2 > (n - cnt))check = false;
    }


    if(check) cout << "Yes" << endl;else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		int N = 0;
		int v = 0;
		int i = 0;
		int j = 0;
		int A[];
		String str = "";
		
		N = Integer.parseInt(as.next());
		
		A = new int[N];
		
		for(i=0;i<N;i++){
			
			A[i] = Integer.parseInt(as.next());
				
			if(i == N - 1){
				
				sb.append(String.valueOf(A[i]));
				
			}
			else{
			
				sb.append(String.valueOf(A[i])).append(' ');
			
			}
			
		}
		System.out.println(sb.toString());
		
		sb.setLength(0);
		
		for(i=1;i<=N-1;i++){
			
			v = A[i];
			j = i - 1;
			while(j >= 0 && A[j] > v){
				
				A[j+1] = A[j];
				j--;
				
			}
			A[j+1] = v;
			
			for(int k=0;k<N;k++){
				
				if(k == N - 1){
					
					sb.append(String.valueOf(A[k]));
					
				}
				else{
				
					sb.append(String.valueOf(A[k])).append(' ');
				
				}
				
			}
			
			System.out.println(sb.toString());
			sb.setLength(0);
			//System.out.println("!!");
			
		}
		
		//System.out.println("::");

	}

}

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

typedef long long LL;

int main() {
	LL X, Y;
	while(~scanf("%lld%lld", &X, &Y)) {
		bool ans = X + 1 == Y || X == Y || X == Y + 1; 
		printf("%s\n", !ans ? "Alice" : "Brown");
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

typedef long long ll;
using namespace std;

bool is_1pair(int* cards){
	sort(cards,cards+5);
	map<int,int> freq;
	for(int i=0;i<5;i++){
		freq[cards[i]]++;
	}
	
	int count = 0;
	for(map<int,int>::iterator it = freq.begin(); it != freq.end(); it++){
		if(it->second == 2){
			count++;
		}
		if(it->second == 3){
			return false;
		}
	}

	return count == 1;
}

bool is_2pair(int* cards){
	sort(cards,cards+5);
	map<int,int> freq;
	for(int i=0;i<5;i++){
		freq[cards[i]]++;
	}
	
	int count = 0;
	for(map<int,int>::iterator it = freq.begin(); it != freq.end(); it++){
		if(it->second == 2){
			count++;
		}
	}

	return count == 2;
}

bool is_3card(int* cards){
	sort(cards,cards+5);
	map<int,int> freq;
	for(int i=0;i<5;i++){
		freq[cards[i]]++;
	}
	
	int count = 0;
	for(map<int,int>::iterator it = freq.begin(); it != freq.end(); it++){
		if(it->second == 3){
			count++;
		}
		if(it->second == 2){
			return false;
		}
	}

	return count == 1;
}

bool is_straight(int* cards){
	sort(cards,cards+5);
	map<int,int> freq;
	for(int i=0;i<5;i++){
		freq[cards[i]]++;
	}
	
	int count = 0;
	for(map<int,int>::iterator it = freq.begin(); it != freq.end(); it++){
		if(it->second > 1){
			return false;
		}
	}

	if(freq[1]==1){
		int ans[][5] = {{1,2,3,4,5},{1,10,11,12,13}};

		bool isok1 = true;
		for(int i=0;i<5;i++){
			if(cards[i] != ans[0][i]) isok1 = false;
		}

		bool isok2 = true;
		for(int i=0;i<5;i++){
			if(cards[i] != ans[1][i]) isok2 = false;
		}

		return (isok1 || isok2);
	}

	else{
		for(int i=0;i+1<5;i++){
			if(cards[i+1] - cards[i] != 1) return false;
		}
	}

	return true;
}

bool is_fullhouse(int* cards){
	sort(cards,cards+5);
	map<int,int> freq;
	for(int i=0;i<5;i++){
		freq[cards[i]]++;
	}
	
	int count = 0;
	bool isok1=false,isok2=false;
	for(map<int,int>::iterator it = freq.begin(); it != freq.end(); it++){
		if(it->second == 3){
			isok1 = true;
		}
		else if(it->second == 2){
			isok2 = true;
		}
	}

	return isok1 && isok2;
}

bool is_4card(int* cards){
	sort(cards,cards+5);
	map<int,int> freq;
	for(int i=0;i<5;i++){
		freq[cards[i]]++;
	}
	int count = 0;
	for(map<int,int>::iterator it = freq.begin(); it != freq.end(); it++){
		if(it->second == 4){
			return true;
		}
	}

	return false;
}
int main()
{
	int cards[5];
	while(~scanf("%d,%d,%d,%d,%d",cards,cards+1,cards+2,cards+3,cards+4)){
		if(is_1pair(cards)) cout << "one pair" << endl;
		else if(is_2pair(cards)) cout << "two pair" << endl;
		else if(is_3card(cards)) cout << "three card" << endl;
		else if(is_straight(cards)) cout << "straight" << endl;
		else if(is_fullhouse(cards)) cout << "full house" << endl;
		else if(is_4card(cards)) cout << "four card" << endl;
		else cout << "null" << endl;

	}
}

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

bool isEven(vector<int> vt) {
    bool even = true;
    rep(i, vt.size()) {
        even = even && vt.at(i) % 2 == 0;
    }
    return even;
}

int main() {
    vector<int> c(3);
    rep(i, 3) cin >> c.at(i);

    if(!isEven(c)) {
        cout << 0 << endl;
        return 0;
    }

    if(c.at(0) == c.at(1) && c.at(1) == c.at(2)) {
        cout << -1 << endl;
        return 0;
    }
    
    int ans = 0;
    while(isEven(c)) {
        vector<int> ci = {
            (c.at(1) + c.at(2)) /2,
            (c.at(0) + c.at(2)) / 2,
            (c.at(0) + c.at(1)) / 2
        };
        c = ci;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

const LL MOD = 1e9 + 7;

LL pot(LL a, LL b) {
	if(b == 0)
		return (LL) 1;
	if(b % 2 == 1) {
		LL x = pot(a, b-1) % MOD;
		LL y = (x * a) % MOD;
		return y;
	}
	else {
		LL x = pot(a, b/2) % MOD;
		LL y = (x*x) % MOD;
		return y;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	LL w = pot(10, n);
	w = (w - ((LL) 2 * pot(9, n))) % MOD;
	w = (w + pot(8, n)) % MOD;
	w += MOD;
	w %= MOD;
	cout<<w;
}


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

int main()
{
  string S;
  
  cin >> S;
  
  if(S[0]==S[1] && S[1]==S[2] && S[0]==S[2]){cout <<"No"<<endl;}
  else{cout <<"Yes"<<endl;}
  
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  char s[10]={0};
  int i,sum=0;
  scanf("%s",s);
  sum=700;
  for(i=0;i<3;i++)
  {
    if(s[i]=='o')
    {
      sum+=100;
    }
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
  int n, a;
  cin >> n;
  bool found = false;
  while(n-- > 0)
  {
    cin >> a;
    if(a % 2 != 0) found = true;
  }
  if(found) cout << "first";
  else cout << "second";
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 1e5 + 5;
int n;
pii a[maxn], b[maxn];
int p[maxn];

void ReadInput()
{
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    for(int i = 0; i < n; ++i)
    {
        cin >> b[i].first;
        b[i].second = i;
    }
    sort(a, a + n);
    sort(b, b + n);
}

void Solve()
{
    for(int i = 0; i < n; ++i)
        if(a[i].first > b[i].first)
        {
            cout << "No\n";
            return;
        }
    for(int i = 0; i < n - 1; ++i)
        if(a[i + 1].first <= b[i].first)
        {
            cout << "Yes\n";
            return;
        }
    for(int i = 0; i < n; ++i)
        p[a[i].second] = b[i].second;

    int x = 0;
    int cnt = 0;
    do
    {
        x = p[x];
        ++cnt;
    }
    while(x != 0);

    if(cnt == n)
        cout << "No\n";
    else cout << "Yes\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll h,w;
    cin >> h >> w;
    ll ans;
    if(h==1||w==1){
        ans=1;
    }
    else if(h%2==0||w%2==0){
        ans=h*w/2;
    }
    else {
        ans=(h*w/2)+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
import collections


def solve(a, b, c, k):
    ans = 0
    ans += min(a, k)
    k -= min(a, k)

    if k == 0:
        return ans

    k -= min(b, k)

    if k == 0:
        return ans

    return ans - k


[a, b, c, k] = list(map(int, input().strip().split()))
print(solve(a, b, c, k))


Measured memory_bytes: 64672
from collections import deque

N = int(input())

l = deque(['a'])

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

for i in range(1, N):
    #print(i)
    len_l = len(l)
    for k in range(len_l):
        x = l.popleft()
        for j in range(len(set(x))+1):
            #print(i, k, j)
            l.append(x+alpha[j])
            #print(l)

#l =sorted(l)

for i in l:
    print(i)

Measured memory_bytes: 13036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b-1);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

ll a[200010];
ll b[200010];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int n;
	cin>>n;
	for (int i=1; i<=n; i++){
		cin>>a[i]>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
//	for (int i=1; i<=n; i++) cout<<a[i]<<' ';
//	cout<<endl;
//	for (int i=1; i<=n; i++) cout<<b[i]<<' ';
//	cout<<endl;
	if (n&1) cout<<b[(n+1)/2]-a[(n+1)/2]+1;
    else cout<<b[n/2]+b[n/2+1]-a[n/2]-a[n/2+1]+1;
	return 0;
}


Measured memory_bytes: 6780
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n,m ;
int Arr[500005] ;
int Size[500005] ;
string str ;
void ini()
{
    for(int i=0 ; i<=n ; i++)
    {
        Arr[i] = i ;
        Size[i] = 1 ;
    }
}
int root(int i)
{
    while(i!=Arr[i])
    {
        Arr[i] = Arr[Arr[i]] ;
        i = Arr[i] ;
    }
    return i ;
}
void Union(int a,int b)
{
    a = root(a) ;
    b = root(b) ;
    if(a==b)
        return ;
    if(Size[a]>Size[b])
    {
        Size[a] += Size[b] ;
        Arr[b] = Arr[a] ;
    }
    else
    {
        Size[b] += Size[a] ;
        Arr[a] = Arr[b] ;
    }
}
void solve()
{
    cin >> n >> m ;
    ini() ;
    for(int i=0 ; i<m ; i++)
    {
        int u,v ;
        cin >> u >> v ;
        Union(u,v) ;
    }
    set<int> r ;
    for(int i=1 ; i<=n ; i++)
        r.insert(root(i)) ;
    int ans = 0 ;
    for(auto it : r)
        ans = max(ans,Size[it]) ;
    cout << ans ;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int tt = 1;
	//cin >> tt ;
	while(tt--)
	{
	     solve() ;
	}
}


Measured memory_bytes: 16020
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//えびちゃんの気持ちが分かってきた気がしたが
char cn[2400000], * ci = cn, * di = cn, ct, buf[8];
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	memcpy(buf, ci, 8);
	ll tmp = *(ll*)buf;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = (tmp << dig) & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3) + 1;
	return tmp;
}

inline void putint(ll X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[20];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int A[200000];
int B[200010];

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


	fread(cn, 1, 1400100, stdin);

	int N = getint();
	ll kotae = 0;
	rep(i, N) kotae += B[(A[i] = getint())]++;
	rep(i, N) putint(kotae - B[A[i]] + 1);
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 5888
#include<iostream>
 
using namespace std;
 
int main(){
  int A;
  cin >> A ;
  if (A<10){
  	cout <<"Yes" << endl;
  }else if(A<20 && A%2==0){
  	cout <<"Yes"<<endl;
  }else if(A<30 && A%3==0){
    cout << "Yes" << endl;
  }else if(A<40 && A%4==0){
    cout << "Yes" << endl;
  }else if(A<50 && A%5==0){
    cout << "Yes" << endl;
  }else if(A<60 && A%6==0){
    cout << "Yes" << endl;
  }else if(A<70 && A%7==0){
    cout << "Yes" << endl;
  }else if(A<80 && A%8==0){
    cout << "Yes" << endl;
  }else if(A<90 && A%9==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace abc100_d
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long[,] cakes = new long[x[0], 3];
            for (int i = 0; i < x[0]; i++)
            {
                long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
                for (int j = 0; j < 3; j++) cakes[i, j] = a[j];
            }
            long ret = long.MinValue;
            for (int i = 0; i < Math.Pow(2, 3); i++)
            {
                long[] now = new long[x[0]];
                for (int j = 0; j < x[0]; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        now[j] += (i >> k) % 2 == 0 ? cakes[j, k] : -cakes[j, k];
                    }
                }
                Array.Sort(now); Array.Reverse(now);
                long a = 0;
                for (int j = 0; j < x[1]; j++) a += now[j];
                ret = Math.Max(ret, Math.Abs(a));
            }
            Console.WriteLine(ret);
        }
    }
}

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

using namespace std;

bool contains(vector<string>& x,string& key){
  for(auto &i:x){
    if(i==key){
      return true;
    }
  }
  return false;
}

int main(){
  int N;
  cin >> N;
  char before;
  string n;
  cin >> n;
  before=n.back();
  vector<string> x;
  x.push_back(n);
  
  for(int i=1;i<N;i++){
    string m;
    cin >> m;
    if(m[0]!=before||contains(x,m)){
      cout << "No";
      return 0;
    }
    x.push_back(m);
    before=m.back();
  }
  cout << "Yes";
}


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

int main() {
    ll n,k;
    cin>>n>>k;
    vector<vector<ll>> to(n,vector<ll>());
    rep(i,n-1){
        ll a,b;
        cin>>a>>b;
        to[a-1].push_back(b-1);
        to[b-1].push_back(a-1);
    }
    vector<bool> used(n,false);
    ll sum=0;
    ll mod=1e9+7;

    used[0]=true;
    sum+=k;
    queue<ll> que;
    for(ll i=0;i<to[0].size();i++){
        que.push(to[0][i]);
        sum*=(k-1-i);
        sum=(sum+mod)%mod;
        used[to[0][i]]=true;
    }
    while(que.size()){
        ll p=que.front();
        que.pop();
        ll cnt=0;
        for(ll i=0;i<to[p].size();i++){
            if(!used[to[p][i]]){
                cnt++;
                sum*=k-1-cnt;
                sum=(sum+mod)%mod;
                used[to[p][i]]=true;
                que.push(to[p][i]);
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 7284
while True:
    n, x = [int(i) for i in input().split()]
     
    if n == x == 0:
        break
         
    count = 0
    for s in range(1, n - 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == sum([s, m, e]):
                    count += 1
                     
    print(count)
    

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  int ans = 1e9;
  for (int x = -100; x <= 100; x++) {
    int tmp = 0;
    for (int i = 0; i < N; i++) {
      tmp += (a[i] - x) * (a[i] - x);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  string s;
  vector<int> freqs(26, 0);
  for (int i = 0; i < N; ++i) {
    cin >> s;
    ++freqs[s[0] - 'A'];
  }
  vector<int> cands = { 'M' - 'A', 'A'- 'A', 'R' - 'A', 'C' - 'A', 'H' - 'A' };
  ll ans = 0;
  for (int i = 0; i < 5; ++i) {
    for (int j = i + 1; j < 5; ++j) {
      for (int k = j + 1; k < 5; ++k) {
        ans += 1LL * freqs[cands[i]] * freqs[cands[j]] * freqs[cands[k]];
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
s = input()
ans = 0
tmp = 0
i = 0
while i < len(s)-1:
    if s[i] == "A":
        tmp += 1
    elif s[i] == "B":
        if s[i+1] == "C":
            ans += tmp
            i += 1
        else:
            tmp = 0
    else:
        tmp = 0
    i += 1
print(ans)

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

typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define all(obj) (obj).begin(), (obj).end()
const ll INF = 1e10;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

ll aN[3000];
// メモ[左端位置][右端位置] = この局面からの結果
ll memo[3010][3010];
bool visited[3010][3010];

ll rec(int turn, int l, int r) {
	// 全部取り切ったので終了
	if (l > r) return 0;
	// 既に見た局面ならメモの内容を返す
	if (visited[l][r]) return memo[l][r];
	// 先手番
	if (turn == 0) {
		ll mx = -INF;
		mx = max(rec(1, l+1, r) + aN[l], rec(1, l, r-1) + aN[r]);
		// 訪問済にする
		visited[l][r] = true;
		// ここより深い所を探し終わったので結果をメモする
		return memo[l][r] = mx;
	// 後手番
	} else {
		ll mn = INF;
		mn = min(rec(0, l+1, r) - aN[l], rec(0, l, r-1) - aN[r]);
		visited[l][r] = true;
		return memo[l][r] = mn;
	}
}

int main() {
	int N;
	cin >> N;
	rep(i, 0, N) cin >> aN[i];
	cout << rec(0, 0, N-1) << endl;
	return 0;
}


Measured memory_bytes: 78592
N,M=map(int,input().split())
mod=10**9+7
if abs(N-M)>1:
    print(0)
else:
    now=1
    for i in range(max(N,M)):
        now=(now*(i+1))%mod
        if i+1==N:
            Nkai=now
        if i+1==M:
            Mkai=now
    if N==M:
        print((Nkai*Mkai*2)%mod)
    else:
        print((Nkai*Mkai)%mod)

Measured memory_bytes: 3060
# coding: utf-8

s = int(input())

a = [s]
cnt1 = 0
for i in range(1, 1000000):
    n = a[i - 1]
    a.append(int(n / 2) if n % 2 == 0 else 3 * n + 1)
    if (a[-1] == 1):
        cnt1 += 1
        if (cnt1 == 2):
            break
            
m = 0
for i in range(0, len(a)):
    an = a[i]
    for j in range(i + 1, len(a)):
        if (an == a[j]):
            m = j
            break
    else:
        continue
    break

print(m + 1)


Measured memory_bytes: 3064
A, B, C, D = map(int, input())
for i in range(8):
    sum = 0
    op1 = "+" if i // 4 % 2 == 0 else "-"
    op2 = "+" if i // 2 % 2 == 0 else "-"
    op3 = "+" if i % 2 == 0 else "-"
    if op1 == "+":
        sum = A + B
    else:
        sum = A - B
    if op2 == "+":
        sum += C
    else:
        sum -= C
    if op3 == "+":
        sum += D
    else:
        sum -= D
    if sum == 7:
        print(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7")
        break

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int x, n, a, ans, maxv = 1000,curdif;
int main(){
    cin >> x >> n;
    bool q[102];
    for (int i = 0;i<102;i++){
        q[i] = false;
    }
    for (int i = 0;i<102;i++){
        cin >> a;
        q[a] = true;
    }
    for(int i = 0;i<102;i++){
        if(q[i]){
            continue;
        }
        curdif = abs(x - i);
        if(maxv == curdif){
            cout << ans << endl;
            return 0;
        }
        if(maxv > curdif){
            maxv = curdif;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long LL;
const int N=2e5+10;

LL l,r,ans[26],g[110],sum[N][26],sm[110][26];
int len,plen,nxt[N];
char s[N];

void Init() {
	scanf("%s",s);
	scanf("%lld%lld",&l,&r);
}

void Getnext(char *s,int len) {
	nxt[0]=0;nxt[1]=0;
	for (int i=1,k=0;i<len;++i) {
		while (k && s[i]!=s[k]) k=nxt[k];
		if (s[i]==s[k]) ++k;
		nxt[i+1]=k;
	}
}

void Calc(int dep,LL *ans,LL _l,LL _r,int op) {
	if (_r==g[dep] && _l==1) {
		for (int j=0;j<26;++j) ans[j]=ans[j]+op*sm[dep][j];
		return ;
	}
	if (dep==0 || dep==1) {
		for (int j=0;j<26;++j) ans[j]=ans[j]+op*(sum[_r][j]-sum[_l-1][j]);
		return ;
	}
	if (_r>g[dep-1] && _l<=g[dep-1]) {
		Calc(dep-1,ans,_l,g[dep-1],op);
		Calc(dep-2,ans,1,_r-g[dep-1],op);
	}else if (_r<=g[dep-1]) Calc(dep-1,ans,_l,_r,op);
	 else Calc(dep-2,ans,_l-g[dep-1],_r-g[dep-1],op);
}

void Solve() {
	len=strlen(s);len/=2;
	Getnext(s,len);
	for (int i=1;i<=len;++i) {
		for (int j=0;j<26;++j) sum[i][j]=sum[i-1][j];
		sum[i][s[i-1]-'a']++;
	}
	plen=len-nxt[len];
	g[0]=plen; for (int j=0;j<26;++j) sm[0][j]=sum[plen][j];
	g[1]=len; for (int j=0;j<26;++j) sm[1][j]=sum[len][j];
	for (int i=2;i<=100;++i) {
		g[i]=g[i-1]+g[i-2];
		for (int j=0;j<26;++j) sm[i][j]=sm[i-1][j]+sm[i-2][j];
	}
	
	for (int i=1;i<=100;++i) 
		if (g[i]>r) { Calc(i,ans,l,r,1); break; }
	for (int i=0;i<26;++i) printf("%lld%c",ans[i],(i==25)?'\n':' ');
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 22400
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int		countHB(char *S)
{
	int		countHB;

	countHB = 0;
	for (int i = 0; S[i]; i++)
	{
		if (i % 2 == 0)
		{
			if (S[i] == '0')
			{
				//S[i] = '1';
				countHB++;
			}
		}
		else
		{
			if (S[i] == '1')
			{
				//S[i] = '0';
				countHB++;
			}
		}
	}
	//printf("HB:%s\n",S);
	return (countHB);
}

int		countBH(char *S)
{
	int		countBH;

	countBH = 0;
	for (int i = 0; S[i]; i++)
	{
		if (i % 2 == 0)
		{
			if (S[i] == '1')
			{
				//S[i] = '0';
				countBH++;
			}
		}
		else
		{
			if (S[i] == '0')
			{
				//S[i] = '1';
				countBH++;
			}
		}
	}
	//printf("BH:%s\n",S);
	return (countBH);
}


int		main(void)
{
	char	S[100001];
	// char	*S2;
	int		N;
	int		HB;
	int		BH;

	N = 0;
	scanf("%s", S);
	//S2 = (char *)malloc(strlen(S) + 1);
	// while (S[N])
	// {
	// 	S2[N] = S[N];
	// 	N++;
	// }
	// S2[N] = '\0';
	HB = countHB(S);
	BH = countBH(S);
	if (HB >= BH)
		printf("%d",BH);
	else
		printf("%d",HB);
	return (0);
}


Measured memory_bytes: 256
n = int(input())
mons = list(map(int,input().split()))
yusya = list(map(int,input().split()))
mons[::-1]
yusya[::-1]

ans = 0
for i in range(n):
    if yusya[i] >= mons[i]:#今の村を倒しきれるとき
        ans += mons[i]
        if yusya[i]-mons[i] >= mons[i+1]:#次の村を倒しきれる
            ans += mons[i+1]
            mons[i+1] = 0
        else:#次の村を倒しきれない
            ans += yusya[i] - mons[i]
            mons[i+1] -= yusya[i] - mons[i]
    else:#今の村を倒しきれない
        ans += yusya[i]
            

print(ans)

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

// O(n*n + m*m*lim)
int main(){
    int lim, n, m, x;
    string s;
    while(cin >> lim >> n >> m >> x, lim){
        vector<int> v[11], dps(1001, 0);
        for(int i = 0; i < n; i++){
            int a, b;
            cin >> s >> a >> b;
            v[a].push_back(b);
        }
        for(int i = 1; i <= 10; i++)    sort(v[i].rbegin(), v[i].rend());
        for(int i = 1; i <= 10; i++){
            if(v[i].size() == 0)    continue;
            dps[i] = max(dps[i], v[i][0]);
            if(v[i].size() != 1)    dps[2*i] = max(dps[2*i], v[i][0]+v[i][1]);
            for(int j = 1; j <= 10; j++){
                if(i == j)  continue;
                if(v[j].size() == 0)    continue;
                dps[i+j] = max(dps[i+j], v[i][0]+v[j][0]);
            }
        }
        for(int i = 1; i <= lim; i++)   dps[i] = max(dps[i], dps[i-1]);

        for(int i = 1; i <= 10; i++)    v[i].clear();
        for(int i = 0; i < m; i++){
            int a, b;
            cin >> s >> a >> b;
            v[a].push_back(b);
        }
        for(int i = 1; i <= 10; i++)    sort(v[i].rbegin(), v[i].rend());
        vector<vector<int>> dp(m+1, vector<int>(1001, -1));
        dp[0][0] = 0;
        for(int w = 1; w <= 10; w++){
            if(v[w].size() == 0)    continue;
            for(int i = m-1; i >= 0; i--){
                for(int j = lim; j >= 0; j--){
                    if(dp[i][j] == -1)  continue;
                    int val = 0;
                    for(int x = 0; i+x+1 <= m && j+(x+1)*w <= lim && x < v[w].size(); x++){
                        val += v[w][x];
                        dp[i+x+1][j+(x+1)*w] = max(dp[i+x+1][j+(x+1)*w], dp[i][j] + val);
                    }
                }
            }
        }
        vector<int> dpn(lim+1, 0);
        for(int i = x; i <= m; i++){
            for(int j = 0; j <= lim; j++){
                dpn[j] = max(dpn[j], dp[i][j]);
            }
        }
        
        for(int j = 1; j <= m; j++) dpn[j] = max(dpn[j], dpn[j-1]);

        int ans = 0;
        for(int i = 0; i <= lim; i++)   if(dps[i])  ans = max(ans, dps[i] + dpn[lim-i]);
        cout << ans << endl;
    }
    return 0;
}


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


int main()
{
 
	//freopen("output.in","r",stdin);
    //freopen("output2.txt","w",stdout);

	long long int a,b,c;
	cin>>a>>b>>c;
	cout<<min(a*b,c);

	return 0;
}

Measured memory_bytes: 764
N, K = map(int,input().split())
A = list(map(int,input().split()))
A = [0] + A
for i in range(N):
    A[i+1] += A[i]

L = []
for i in range(N):
    for j in range(i+1, N+1):
        L.append(A[j] - A[i])

ans = 0

for i in range(40, -1, -1):
    cnt = 0
    for l in L:
        if (ans + (1 << i)) & l == ans + (1 << i):
            cnt += 1
    if cnt >= K:
        ans += 1 << i

print(ans)

Measured memory_bytes: 107756
#include<iostream>
#include<set>
#include<cstring>
#include<queue>
using namespace std;
struct edge{int to,color;};
vector<edge> w[100010];
int n,m,d[100010];
set<int> s[100010];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	while(m--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		w[a].push_back({b,c});
		w[b].push_back({a,c});
	}
	memset(d,0x3f,sizeof d);
	d[1]=0;
	priority_queue<pair<int,int>> q;
	q.push({-d[1],1});
	while(!q.empty())
	{
		int now=q.top().second,cost=-q.top().first;q.pop();
		if(d[now]<cost) continue;
		for(edge j:w[now])
		{
			int dis=d[now];
			if(!s[now].count(j.color))dis++;
			if(dis<d[j.to])
			{
				d[j.to]=dis;
				s[j.to].clear();
				s[j.to].insert(j.color);
				q.push({-d[j.to],j.to});
			}
			else if(dis==d[j.to])s[j.to].insert(j.color);
		}
	}
	if(d[n]>4e5)cout<<-1<<endl;
	else cout<<d[n]<<endl;
	return 0;
}


Measured memory_bytes: 21108
#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 f(ll x){
    int t = 0;
    while(x/2){
        x /= 2;
        t++;
    }
    return t;
}

int main(void){
    /*
    int a = 2;
    cout << a/2 << endl;
    */

    ll h;
    cin >> h;
    int t;
    // hを2で何回割れるか
    t = f(h);
    ll c = 1;
    ll ans = 1;
    rep(i,t){
        c *= 2;
        ans += c;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  
  string S[N];
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }
  
  int ac = 0,wa = 0,tle = 0,re = 0;
  for(int i = 0; i < N; i++){
    if(S[i] == "AC"){
      ac++;
    }else if(S[i] == "WA"){
      wa++;
    }else if(S[i] == "TLE"){
      tle++;
    }else{
      re++;
    }
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 6744
#include <iostream>
#include <cmath>
#include <limits>
using namespace std;

int main() {
    
    int N,a,b,keta;
    cin >> N;
    keta = log10(N)+1;
    b = N;
    a = 0;
    for (int i = 0; i < keta;i++) {
        a += b % 10;
        b = (b - b % 10) / 10;
        
    };
    if (N % a==0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
       

}


Measured memory_bytes: 384
package main

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

// const abcd = "abcdefghijklmnopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}

var inf int = 1e13
var mod = 1000000007

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	n := next.Int()
	k := next.Int()
	l := make([]int, n)
	for i := 0; i < n; i++ {
		l[i] = next.Int()
	}
	sort.Ints(l)
	log.Println(l)
	ans := sum(l[len(l)-k:]...)

	fmt.Println(ans)
}

// ---------------------------------------------------------

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a ...int) int {
	r := a[0]
	if len(a) > 1 {
		for i := 1; i < len(a); i++ {
			r += a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0

for i in range(0, A + 1):
    for j in range(0, B + 1):
        for k in range(0, C + 1):
            total = i * 500 + j * 100 + k * 50
            if total == X:
                count += 1

print(count)

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

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

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	ll H,W,h,w; cin >> H >> W >> h >> w;
	ll x = (INTINF/10)/(h*w);
	V<V<ll>> A(H,V<ll>(W,x));
	ll y = -((h*w-1)*x + 1);
	for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) if(i%h==h-1 && j%w==w-1) A[i][j] = y;
	ll sum = 0;
	for(int i = 0; i < H; ++i) sum += accumulate(ALL(A[i]),0LL);
	Yn(sum>0);
	if(sum<=0) return 0;
	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) cout << A[i][j] << " ";
		cout << endl;
	}
	return 0;
}


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

long gcd(long a, long b){
  if(a > b) return gcd(b, a);
  long k = b % a;
  if(k == 0) return a;
  return gcd(a, k);
}
long lcm(long a, long b){
  return a / gcd(a, b) * b;
}
int main(){
  cin.tie(0);
 	ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long T[N];
  for(int i = 0; i < N; i++){
    cin >> T[i];
  }
  long l = T[0];
  for(int i = 1; i < N; i++){
    l = lcm(l, T[i]);
  }
  cout << l <<"\n";
  return 0;
}

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

int ok[2020];

int main(){
  int n; cin >> n;
  int* A = new int[n];
  for( int i = 0; i < n; i++ ) cin >> A[i];

  for( int bit = 0; bit < ( 1 << n ); bit++ ){
    int sum = 0;
    for( int i = 0; i < n; i++ ){
      if( bit & ( 1 << i ) ){
	sum += A[i];
      }
    }

    if( sum < 2010 ){
      ok[sum] = 1;
    }
  }

  int q; cin >> q;
  for( int i = 0; i < q; i++ ){
    int m; cin >> m;
    if( ok[m] ) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}



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

int main(){
  int N;
  cin >> N;
  vector<int> V(N),C(N);
  for(int i=0;i<N;i++){
    cin >> V.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> C.at(i);
  }
  int X=0;
  for(int i=0;i<N;i++){
    if(V.at(i)-C.at(i)>0){
      X+=V.at(i)-C.at(i);
    }
  }
  cout << X << endl;
}
      

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC136A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, max;
            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            max = A + B;
            if (max < A - B)
                max = A - B;
            if (max < A * B)
                max = A * B;

            Console.WriteLine(max);

            Console.ReadKey();


        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		int[][] m=new int[101][101];
		int[] p=new int[101];
		for(int i=1;i<=n;i++){
			p[i-1]=scanner.nextInt();
			p[i]=scanner.nextInt();
		}
		
		for(int i=1;i<=n;i++)
			m[i][i]=0;
		for(int l=2;l<=n;l++){
			for(int i=1;i<=n-l+1;i++){
				int j=i+l-1;
				m[i][j]=(1<<21);
				for(int k=i;k<=j-1;k++){
					m[i][j]=Math.min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
				}
			}
		}
		System.out.println(m[1][n]);
	}

}



Measured memory_bytes: 26408
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;

void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const ll MAXN = 1e6 + 10;
const ll N = 4000 + 10;
const ll MN = 200 + 10;
const ll mod = 1e6;

ll a[MAXN];

int main()
{
	faster();
	int n;
	cin >> n;
	for (int i = 0; i < 2 * n; i++)
		cin >> a[i];
	sort(a, a + n + n);
	ll ans = 0;
	for (int i = 0; i < n + n; i+=2)
	{
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n,k;
  string s;
  cin>>n>>k>>s;
  int cnt = 0;
  for(int i = 0; i < n-1; i++){
    if(s[i]==s[i+1]) cnt++;
  }
  int ans = cnt+2*k;
  if(ans>=n) ans=n-1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
N = int(input())
E = list(map(int, input().split()))

E.sort(reverse=True)
pre = 0
nums = []
for e in E:
    if pre == e:
        nums.append(e)
        pre = 0
    else:
        pre = e
    if len(nums) == 2:
        print(nums[0]*nums[1])
        quit()
print(0)

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

int main()
{
    llong H, W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        REP(i,H){
            REP(j,W) (j%2+i%2)%2==1?cout << ".":cout << "#";
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
 long long  int r = 0;
  for(int i=0; i< n; i++){
      if((i+1) %5 != 0)
        if((i+1)%3!= 0)
            r += i+1;
  }   
cout << r;
  return 0;
}

Measured memory_bytes: 3652
import Foundation

let n = readInt()
let a = readIntArray().lazy

var acc = 0
var min = 0

for num in a {
  if min > num {
    acc = acc &+ (min - num)
  } else {
    min = num
  }
}

print(acc)

@inlinable @inline(__always) func readString() -> String { readLine()! }
@inlinable @inline(__always) func readInt   () -> Int    { Int(readString())! }
@inlinable @inline(__always) func readDouble() -> Double { Double(readString())! }

// .map(String.init) を挟まないと [String.SubSequence] になって遅くなる（は？）
@inlinable @inline(__always) func readStringArray(_ separator: __shared Character = " ") -> [String] { readString().split(separator: separator).map(String.init) }
@inlinable @inline(__always) func readIntArray   (_ separator: __shared Character = " ") -> [Int]    { readStringArray(separator).map { Int($0)! } }
@inlinable @inline(__always) func readDoubleArray(_ separator: __shared Character = " ") -> [Double] { readStringArray(separator).map { Double($0)! } }


Measured memory_bytes: 26480
# coding: utf-8
# Here your code !

def func():
    try:
        line=input().rstrip()
        numbers=line.split(" ")
        for i,item in enumerate(numbers):
            numbers[i]=int(item)
    except:
        print("input error")
        return -1
    
    numbers.sort()
    
    result=""
    for num in numbers:
        result+=str(num)+" "
    
    print(result.rstrip(" "))

func()

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

typedef long long ll;

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> v(m);
    for(int i = 0; i < m; i++)  cin >> v[i];
    ll sum = accumulate(v.begin(), v.end(), 0ll);
    cout << (sum <= n ? n-sum : -1) << endl;
    return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n+1),b(n);
  rep(i,n+1){
    cin >> a.at(i);
  }
  rep(i,n){
    cin >> b.at(i);
  }
  ll ans=0,q=0;
  rep(i,n){
    if(a.at(i)+a.at(i+1)<=b.at(i)){
      ans+=a.at(i)+a.at(i+1);
      a.at(i)=0;
      a.at(i+1)=0;
    }else if(a.at(i)<=b.at(i)){
      ans+=b.at(i);
      a.at(i+1)-=b.at(i)-a.at(i);
      a.at(i)=0;
    }else{
      ans+=b.at(i);
    }
  }
  cout << ans;
}
    

Measured memory_bytes: 4680
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAXOP 100
#define NUMBER '0'

int getop(char []);
void push(double);
double pop(void);

main()
{
	int type;
	double op2;
	char s[MAXOP];

	while((type = getop(s)) != EOF && type <= 99) {
		switch (type) {
		case NUMBER:
			push(atof(s));
			break;
		case '+':
			push(pop() + pop());
			break;
		case '*':
			push(pop() * pop());
			break;
		case '-':
			op2 = pop();
			push(pop() - op2);
			break;
		case '\n':
			printf("%.8g\n", pop());
			break;
		default:
			printf("error: unknown command %s\n", s);
			break;
		}
	}
	return 0;
}

#define MAXVAL 100

int sp = 0;
double val[MAXVAL];

void push(double f)
{
	if (sp < MAXVAL)
		val[sp++] = f;
	else
		printf("error: stack full, can't push %g\n", f);
}

double pop(void)
{
	if (sp > 0)
		return val[--sp];
	else {
		printf("error: stack empty\n");
		return 0.0;
	}
}

#include <ctype.h>

int getch(void);
void ungetch(int);

int getop(char s[])
{
	int i, c;

	while ((s[0]= c = getch()) == ' ' || c == '\t')
		;
	s[1] = '\0';
	if (!isdigit(c) && c != '.')
		return c;	
	i = 0;
	if (isdigit(c)) 
		while (isdigit(s[++i] = c = getch()))
			;
	if (c == '.') 
		while (isdigit(s[++i] = c = getch()))
			;
	s[i] = '\0';
	if (c != EOF)
		ungetch(c);
	return NUMBER;
}

#define BUFSIZE 100

char buf[BUFSIZE];
int bufp =0;

int getch(void) 
{
	return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c) 
{
	if (bufp >= BUFSIZE)
		printf("ungetch: too many characters\n");
	else
		buf[bufp++] = c;
}



Measured memory_bytes: 2144
#include<iostream>
 #include<cstdio>
 #include<cmath>
 #include<algorithm>
 //#include<cstring>
 using namespace std;
 struct knife
 {
     int ai;
     bool f;
 }m[2000018];
 inline int read()
 {
   int p=0,f=1;char c=getchar();
   while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
   while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}
   return f*p;}
 int N,H,ans;
 bool cmp(knife x,knife y)
 {
     return x.ai>y.ai;
 }
 int main()
 {
     N=read(),H=read();
     for(int i=1;i<=N;i++)
         m[i].ai=read(),
   	  m[i+N].ai=read(),
         m[i+N].f=true; 
     sort(m+1,m+1+N*2,cmp); 
     int ans=0;           
     for(int i=1;i<=2*N;i++) 
        {
          if(m[i].f) 
	        {ans++;
	         H-=m[i].ai;}
          else
             {
              int u=H%m[i].ai;
	          ans+=H/m[i].ai;
              if(u)ans++;
	  	    H=-1;
             }
           if(H<=0)
             {printf("%d",ans);
              return 0;}
        }
 }

Measured memory_bytes: 5284
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
using namespace std;

#define chmin(x, y) x = min(x, y)
typedef long long ll;

// 入力
int n;
vector<ll> a;
// dp[left][right] := 区間 [left,right) におけるコストの最小値
vector<vector<ll>> dp(405, vector<ll>(405, -1));
ll sum[405];

// メモ化再帰
ll memo_rec(int left, int right){
    if(dp[left][right] != -1)   return dp[left][right];
    if(right - left == 1)   return dp[left][right] = a[left];
    if(right - left < 1)    return 0;

    ll res = numeric_limits<ll>::max();
    for(int pos = left + 1; pos < right; ++pos){
        ll tmp = 0;
        if(pos - left > 1)  tmp += memo_rec(left, pos) + sum[pos] - sum[left];
        else    tmp += memo_rec(left, pos);
        if(right - pos > 1) tmp += memo_rec(pos, right) + sum[right] - sum[pos];
        else    tmp += memo_rec(pos, right);
        chmin(res, tmp);
    }
    return dp[left][right] = res;
}

int main(){
    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    cout << memo_rec(0, n) << endl;
}

Measured memory_bytes: 1536
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        for(int i=0;i<a;i++){in[i] = sc.nextInt();
                            }
        int search = 1; 
        for(int i=0;i<a;i++){if(in[i]==search){search++;}
                            }
        int ans = a-search+1;
        if(ans==a){ans=-1;}
		System.out.println(ans);
	}
}


Measured memory_bytes: 89536