akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main(){
    string t;
    cin >> t;
    int ans = 0;
    while(1){
        string st;
        cin >> st;
        if(st != "END_OF_TEXT"){
            rep(i,st.length())if(st[i] <= 90)st[i] += 32;
            if(st == t)ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3180
import itertools
n,m=map(int,input().split())
p=[[False]*n for i in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    p[a][b]=True
    p[b][a]=True
ans=0
for i in itertools.permutations(range(n),n):
    if i[0]==0:
        for j in range(n):
            if j==n-1:
                ans+=1
                break
            if not p[i[j]][i[j+1]]:
                break
print(ans)   

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int main(void) {
    int i, j, h, w;
    cin >> h >> w;
    REP (i,h) REP (j,w) {
        string s;
        cin >> s;
        if (s == "snuke") {
            cout << (char) (j + 'A') << i+1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
//	-*- mode: C++ -*-
//	Swapping Two Numbers
//	Write a program which reads two integers x and y, and prints them in ascending order.
//
//	Input
//		The input consists of multiple datasets. Each dataset consists of two integers x and y separated by a single space.
//
//		The input ends with two 0 (when both x and y are zero). Your program should not process for these terminal symbols.
//
//	Output
//		For each dataset, print x and y in ascending order in a line. Put a single space between x and y.
//
//	Constraints
//		0 ≤ x, y ≤ 10000
//		the number of datasets ≤ 3000
//	Sample Input
//		3 2
//		2 2
//		5 3
//		0 0
//	Sample Output
//		2 3
//		2 2
//		3 5

#include <iostream>
#include <vector>
#include <utility>

int	main(int	argc,
		 char*	argv[])
{
	int	x	= 0;
	int	y	= 0;

	std::vector<std::pair<int, int> >	vect;

	for(int i = 0; i < 3000; i++){
		std::cin >> x >> y;

		if((x == 0) && (y == 0)){
			break;
		}

		if(x < y){
			vect.push_back(std::make_pair(x, y));
		}
		else{
			vect.push_back(std::make_pair(y, x));
		}
	}

	for(std::pair<int, int> p : vect){
		std::cout << p.first << ' ' << p.second << '\n';
	}
}



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

/*vector<long long int>::iterator position;
position=lower_bound(a.begin(),a.end(),b[i]);
key=distance(a.begin(),position);*/

/**/

int main(){
    int i,n,m,sum=0;
    cin>>n>>m;
    vector<int> a(n);
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        sum+=a[i];
    }

    sort(a.begin(),a.end(),greater<int>());

    for(i=0;i<m;i++){
        if(sum>4*m*a[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
fn = []
for i in range(5):
  num = int(input())
  fn.append(int(num))

fcn = []   
for f in fn:
  if f%10 != 0:
    fcn.append([f,f%10-10])
  else :
    fcn.append([f,0])

fcn.sort(key=lambda x: x[1],reverse=True)    

sum = 0
for i in range(len(fcn)):
  if i != len(fcn)-1:
    sum += fcn[i][0] - fcn[i][1]
  else :
    sum += fcn[i][0]
  
print(sum)


Measured memory_bytes: 9052
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
	ll a,b,n,x;
	cin>>a>>b>>n;
	if(n>=b)
		 x=b-1;
	else
 x=n;
	
	ll sum=(a*x/b)-a*(x/b);
	cout<<sum;
}

Measured memory_bytes: 3676
// 2013 7/2
import java.lang.*;
import java.util.*;
//0022
public class Main
{
    static Scanner sc = new Scanner(System.in);
    static int n = 8;
    
    public static void main(String args[])
    {
        while( sc.hasNext() ){
            int[][] m = new int[n+6][n+6];

            for(int i=1; i<=n; i++){
                int p = sc.nextInt();
                for(int j=n; j>=1; j--){
                    if(p==0) m[i][j] = 0;
                    else {
                        m[i][j] = p % 10;
                        p /= 10;
                    }
                }
            }
            
            // for(int i=1; i<=n; i++){
            //     System.out.println();    
            //     for(int j=1; j<=n; j++){
            //         System.out.print(m[i][j]);    
            //    }
            // }
            
            String ans = "";
            for(int i=1; i<=n; i++){
                for(int j=1; j<=n; j++){
                    
                    if(m[i][j] + m[i+1][j] + m[i][j+1] + m[i+1][j+1] == 4)   ans = "A";
                    if(m[i][j] + m[i+1][j] + m[i+2][j] + m[i+3][j] == 4)     ans = "B";
                    if(m[i][j] + m[i][j+1] + m[i][j+2] + m[i][j+3] == 4)     ans = "C";
                    if(m[i][j] + m[i+1][j] + m[i+1][j-1] + m[i+2][j-1] == 4) ans = "D";
                    if(m[i][j] + m[i][j+1] + m[i+1][j+1] + m[i+1][j+2] == 4) ans = "E";
                    if(m[i][j] + m[i+1][j] + m[i+1][j+1] + m[i+2][j+1] == 4) ans = "F";
                    if(m[i][j] + m[i][j+1] + m[i+1][j] + m[i+1][j-1] == 4)   ans = "G";
                    
                    if(ans != "") break;
                }
            }
            System.out.println(ans);
            
        }
    }
}


	    

Measured memory_bytes: 20592
#include <stdio.h>

#define N 1000000

int divide(int, int *);
void shellsort(int *, int);
void insertionsort(int *, int, int, int *);

int main() {
    int Arrlength, Array[N]; 

    scanf("%d", &Arrlength);
    for(int i=0; i<Arrlength; ++i) {
        scanf("%d", (Array+i));
        //printf("%d\n", *(Array+i));
    }

    shellsort(Array, Arrlength);
    return 0;
}

int divide(int length, int *G) {
    //const int limitlen = 5;
    //length = limitlen;
    int i, divide = 0;
    for(i=0; 3*divide < length; ++i) {
        *(G+i) = divide = 3*divide + 1;
        //printf("%d : %d\n", i+1, *(G+i));
    }
    return i;
}

void shellsort(int *Array, int length) {
    int cnt = 0, m = 0;
    int G[9];
    int *Gtail, *p;
    m = divide(length, G);
    p = Gtail = &G[m-1];
    
    printf("%d\n", m);
    //printf("*Gtail = %d\n", *Gtail);
    
    for(int i=0; i<m; ++i) {
        if(i) printf(" ");
        printf("%d", *(p-i));
    }
    printf("\n");
    for(int i=0; i<m; ++i) {
        insertionsort(Array, length, *(Gtail-i), &cnt);
    }
    printf("%d\n", cnt);
    for(int i=0; i<length; ++i) {
        printf("%d\n", *(Array+i));
    }
    
}

void insertionsort(int *Array, int length, int divide, int *cnt) {
    int i, j, v;
    for(i=divide; i<length; ++i) {
        v = Array[i];
        j = i - divide;
        while(j>=0 && Array[j] > v) {
            Array[j+divide] = Array[j];
            j = j - divide;
            *cnt += 1;
        }
        Array[j+divide] = v;
    }
}


Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  int odd = 0;
  rep(i, 0, N) {
    VAR(ll, Ai);
    odd += Ai % 2;
  }
  if (odd % 2) {
    print("NO");
  } else {
    print("YES");
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pll pair<ll,ll>
#define sll set<ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define vpl vector<pll>
#define gll greater<ll>
#define spl set<pll>
#define lb lower_bound
#define ub upper_bound
#define prq priority_queue
#define mp make_pair
#define pb push_back
#define mem(x,y) memset(x, y, sizeof x)
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef long double ld;
ll mx=INT_MAX;
ll mn=INT_MIN;
ll mod=1e9+7;
const ll maxs=1e6+6;
ll max2d=1e3+3;
ll INF = 9e18;
 
int main(){
    ll N; cin>>N;
    ll a[N+1]; 
    for(ll i=1; i<=N; i++) cin>>a[i];
    ll dp[N+1]; mem(dp, 0);
    ll pref[N+1]; mem(pref, 0);
    pref[1] = a[1]; pref[2] = a[2];
    dp[1] = 0; dp[2] = max(a[1],a[2]);
    for(ll i=3; i<=N; i++){
        pref[i] = a[i] + pref[i-2];
        if(i&1) dp[i] = max(a[i]+dp[i-2] , dp[i-1]); 
        else dp[i] = max(a[i]+dp[i-2] , pref[i-1]);
    }
    cout<<dp[N];
    return 0;
}

Measured memory_bytes: 8232
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n;cin>>n;
  for(int i=0;i<n;i++){
    int k,p;cin>>k>>p;
    if(k%p==0){
      cout<<p<<endl;
    }else{
      cout<<k%p<<endl;
    }
  }
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int N, K;
	cin >> N >> K;

	set<int> likes = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
	int cur = 0;
	for (int i = 0; i < K; i++) {
		cin >> cur;
		likes.erase(cur);
	}

	for (int j = N; j < 10 * N; j++) {
		string str(to_string(j));
		bool ok(true);
		for (int k = 0; k < str.size(); k++) {
			int c = str[k] - '0';
			if (likes.find(c) == likes.end()) {
				ok = false;
				break;
			}
		}
		if (ok) {
			cout << j << endl;
			break;
		}
	}

	return 0;
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , k;
string s;

int main()
{
    _FastIO;
    cin >> n >> k;
    int ans = n * k;
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n,k,q;
  cin >>n >>k >>q;
  vector <int> a(n,k); //持ち点
  vector <int> b(q);
  for (int i=0;i<q;i++)
    cin >> b.at(i); //正解者の番号
  
  for(int i=0;i<n;i++)
  a.at(i)-=q;
  for(int i=0;i<q;i++)
  a.at(b.at(i)-1)++;
  for (int i=0;i<n;i++){
    if(a.at(i)<=0)
      cout << "No" <<endl;
  if(a.at(i)>0)
    cout<<"Yes"<<endl;
  }
  
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int n,m,p1,p2;
long long ans=0;
vector<pair<int,int> > v;
int main() {
    cin>>n>>m;
    for (int i=0; i<n; i++) {cin>>p1; v.push_back({p1,1});}
    for (int i=0; i<m; i++) {
        cin>>p1>>p2;
        v.push_back({p2,p1});
    }
    sort(v.begin(),v.end(),greater<pair<int,int> >());
    int cur=0;
    for (int i=0; i<n; i++) {
        if (v[i].second+cur>=n) {ans+=(((long long)(n-cur))*v[i].first); break;}
        ans+=(1LL*v[i].first*v[i].second);
        cur+=v[i].second;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 5320
#include <iostream>
#include <cstdio>
#include <map>
#include <bitset>
using namespace std;
int n;
char str[1000];
typedef long long ll;
ll a[10000];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",str);
		if(str[0]=='M')a[0]++;
		if(str[0]=='A')a[1]++;
		if(str[0]=='R')a[2]++;
		if(str[0]=='C')a[3]++;
		if(str[0]=='H')a[4]++;
	}
	ll ans=0;
	for(int s=0;s<(1<<5);s++){
		ll cnt=0;
		for(int j=0;j<5;j++)cnt += ((s&(1<<j))!=0);
		if(cnt == 3){
			ll ttt = 1;
			for(int i=0;i<5;i++){
				if(s&(1<<i)){
					ttt *= a[i];
				}
			}
			ans += ttt;
		}
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ll r,d,x;cin>>r>>d>>x;
    ll ans[11];
    ans[0]=x;
    rep(i,1,11){
        ans[i]=ans[i-1]*r-d;
    }
    rep(i,1,11)cout<<ans[i]<<endl;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

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

int fact(int n){
	if(n == 0) return 1;
	return n * fact(n - 1);
}

bool equal(const vi &a, const vi &b){
	rep(i, a.size()){
		if(a[i] != b[i]) return false;
	}
	return true;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	vi p(n), q(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];

	vi perm;
	for(int i = 1; i <= n; i++){
		perm.push_back(i);
	}
	int a;
	for(a = 0; a < fact(n); a++){
		if(equal(p, perm)) break;
		next_permutation(all(perm));
	}
	sort(all(perm));
	int b;
	for(b = 0; b < fact(n); b++){
		if(equal(q, perm)) break;
		next_permutation(all(perm));
	}

	cout << abs(a - b) << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, a, b) = readLongList()

    val MOD = 1000000007L
    val all = pow(2, n.toLong(), MOD) - 1

    val nPa = calcNPermutationM(n, a, MOD)
    val nCa = (nPa * inverse(calcFactorial(a, MOD), MOD)) % MOD

    val nPb = calcNPermutationM(n, b, MOD)
    val nCb = (nPb * inverse(calcFactorial(b, MOD), MOD)) % MOD
    
    println(ModInt(all, MOD) - ModInt(nCa, MOD) - ModInt(nCb, MOD))
}

fun calcNPermutationM(n: Long, m: Long, MOD: Long): Long {
    var ret = 1L
    for (i in (n - m + 1)..n) {
        ret = (ret * i) % MOD
    }
    return ret
}

fun calcFactorial(x: Long, MOD: Long) = calcNPermutationM(x, x, MOD)

fun pow(n: Long, m: Long, MOD: Long): Long {
    var ret = 1L
    var x = n
    var k = m
    while (k > 0) {
        if ((k and 1L) == 1L) {
            ret = (ret * x) % MOD
        }
        x = (x * x) % MOD
        k = k shr 1
    }

    return ret
}

fun inverse(n: Long, MOD: Long) = pow(n, MOD - 2L, MOD)

// always positive number
// Use for minus
class ModInt(x: Long, private val MOD: Long) {
    val x = ((x % MOD) + MOD) % MOD

    operator fun unaryMinus() = ModInt(-x, MOD)

    operator fun plus(other: ModInt): ModInt {
        var value = x + other.x
        if (value >= MOD) {
            value -= MOD
        }
        return ModInt(value, MOD)
    }

    operator fun minus(other: ModInt): ModInt {
        var value = x + MOD - other.x
        if (value >= MOD) {
            value -= MOD
        }
        return ModInt(value, MOD)
    }

    operator fun times(other: ModInt): ModInt {
        val value = (x * other.x) % MOD
        return ModInt(value, MOD)
    }

    operator fun div(other: ModInt): ModInt = this * other.inverse()

    override fun toString(): String {
        return x.toString()
    }

    private fun pow(n: Long): ModInt {
        var ret = ModInt(1L, MOD)
        var x = this
        var k = n
        while (k > 0) {
            if ((k and 1L) == 1L) {
                ret *= x
            }
            x *= x
            k = k shr 1
        }

        return ret
    }

    private fun inverse() = pow(MOD - 2)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


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

int main() {
    
    int x, y, z;
    cin >> x >> y >> z;
    for (int i=1; i<100005; i++) {
		if (y * i + z * (i + 1) > x) {
			cout << i-1 << endl;
			exit(0);
		}
	}
    
}


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

int num(char x)
{
  return (x-'a');
}

int main()
{
	int a[26];
  for(int i=0;i<26;i++)
  {
    a[i]=0;
  }
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++)
  {
    a[num(s[i])]++;
  }
  for(int i=0;i<26;i++)
  {
    if(a[i]%2!=0)
    {
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
    
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
ll A, B, C, K;
int main()
{
    cin >> A >> B >> C >> K;
    ll D1 = A - B;
    ll D2 = B - A;
    if (K % 2 == 0)
    {
        cout << D1 << endl;
    }
    else
    {
        cout << D2 << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end())
using namespace std;
using lint     = long long;
const lint MOD = 1e9 + 7;
const lint INF = 1e18;

lint gcd(lint a, lint b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

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

lint lcm(lint a, lint b) {
  return a * b / gcd(a, b);
}
int main() {
  lint a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(){
  long int h;
  scanf("%ld",&h);
  int count=1;
  long int sum=0;
  while(h!=1){
    h=h/2;
    count++;
  }
  for(int i=1;i<=count;i++){
    sum+=pow(2.0,i-1);
  }
  printf("%ld\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

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

    bool err = 0;
    if(n%2!=0){
        cout << "No" << endl;
    }else{
        for(int i=0;i<n/2;i++){
            if( s[i] != s[i+n/2]) err = 1;
        }
        if(err) cout << "No" << endl;
        else cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define MAX 1000001

bool is_prime[MAX];
bool is_pay[MAX];

int main(int argc,char* argv[]){
  is_prime[0] = is_prime[1] = false;
  for(int i = 2; i < MAX; i++){
    is_prime[i] = true;
  }
  for(int i = 2; i < 1001; i++){
    if(is_prime[i]){
      for(int j = 2*i; j < MAX; j += i){
	is_prime[j] = false;
      }
    }
  }
  
  while(true){
    int n,x;
    std::cin >> n >> x;
    
    if(n == 0 && x == 0){
      break;
    }
    
    for(int i = 1; i <= x; i++){
      is_pay[i] = false;
    }

    is_pay[0] = true;
    
    int array[n];
    for(int i = 0; i < n; i++){
      std::cin >> array[i];
    }
    
    for(int t = 0; t < n; t++){
      for(int i = x; i >= 0; i--){
	if(is_pay[i]){
	  for(int j = i + array[t]; j <= x; j += array[t]){
	    is_pay[j] = true;
	  }
	}
      }
    }

    bool found = false;
    for(int i = x; i >= 0; i--){
      if(is_pay[i] && is_prime[i]){
	found = true;
	std::cout << i << std::endl;
	break;
      }
    }

    if(!found){
      std::cout << "NA" << std::endl;
    }
  }


  return 0;
  
}

Measured memory_bytes: 3112
#include <iostream>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;

ll sum(ll n){
    ll tmp = 0;
    for(ll i = 0; i <= n; i++){
	tmp += i;
    }
    return tmp;
}

int main(){
    /*input*/
    ll n;  cin >> n;
    /*calculation*/
    /*output*/
    cout << sum(n-1) << endl;
}


Measured memory_bytes: 256
# -*- coding: UTF-8 -*-
# ABC109_C


def LCM(num1, num2):
    m = max(num1, num2)
    n = min(num1, num2)
    r = m % n
    while(r != 0):
        m = n
        n = r
        r = m % n
    return n


N, x = map(int, input().split())
D = 1

if (N == 1):
    tmp = int(input())
    print(abs(x - tmp))
else:
    tmp = input()
    list = []
    list = tmp.split()
    for i in range(N):
        list[i] = abs(x - int(list[i]))
    D = list[0]
    for i in range(N):
        D = LCM(D, list[i])
    print(D)


Measured memory_bytes: 11480
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const int di[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

char a[810][810];
int d[810][810];
pii q[640010];

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	int n,m,k;scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++) scanf("%s",a[i]+1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			d[i][j]=k+1;
	int f=1,r=1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (a[i][j]=='S')
			{
				q[1]=mp(i,j);
				d[i][j]=0;
			}
	while (f<=r&&d[q[f].x][q[f].y]<k)
	{
		for (int p=0;p<4;p++)
		{
			int dx=q[f].x+di[p][0],dy=q[f].y+di[p][1];
			if (dx>0&&dx<=n&&dy>0&&dy<=m&&d[dx][dy]==k+1&&a[dx][dy]=='.')
			{
				q[++r]=mp(dx,dy);d[dx][dy]=d[q[f].x][q[f].y]+1;
			}
		}
		f++;
	}
	int ans=n*m;
	for (int i=1;i<=r;i++)
	{
		ans=min(ans,(q[i].x-1+k-1)/k);
		ans=min(ans,(q[i].y-1+k-1)/k);
		ans=min(ans,(n-q[i].x+k-1)/k);
		ans=min(ans,(m-q[i].y+k-1)/k);
	}
	printf("%d\n",ans+1);
	return 0;
}


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

int main() {
	double rz,p,c,m,r;

	cin >> r;
	p = 3.141592653589;

	m = r * r * p;
	
	c = r * 2 * p;
		
	cout <<fixed<<setprecision(20)<< m << " " <<setprecision(20)<< c << endl;

	return 0;


}


Measured memory_bytes: 3224
n =int(input())
for i in range(1,n + 1):
        s = i
        if i % 3 == 0:
                print(" %d" % i,end = "")
        elif i / 10 != 0:
                for k in range(5):
                        if s % 10 == 3:
                                print( " %d"% i ,end = "")
                                break
                        elif s == 0:
                                break
                        s //= 10
print('')



Measured memory_bytes: 5876
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;
    cout << "ABC" << n << endl;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



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


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long counter = 0;
		for(int i=0;i<n;i++) {
			long num = in.nextLong();
			counter += countNumberDividingTwo(num);
		}
		System.out.println(counter);

	}
	
	public static long countNumberDividingTwo(long num) {
		long counter = 0;
		while(num%2==0) {
			num /= 2;
			counter++;
		}
		return counter;
	}

}

Measured memory_bytes: 35948
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;

class Main{
    public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final Deque<Integer> list = new ArrayDeque<Integer>(1000000);
        final int n = Integer.parseInt(br.readLine());
        for(int i = 0; i<n; i++){
            final String in = br.readLine();
            if(in.charAt(0)=='i'){
                list.offerFirst(Integer.valueOf(in.substring(7)));
            }else if(in.charAt(6)=='F'){
                list.removeFirst();
            }else if(in.charAt(6)=='L'){
                list.removeLast();
            }else{
                list.remove(Integer.valueOf(in.substring(7)));
            }
        }
        out.print(list.poll());
        for(final Integer e:list){
            out.print(' ');
            out.print(e);
        }
        out.println();
        out.flush();
    }
}

Measured memory_bytes: 125552
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string sa, sb, sc; cin >> sa >> sb >> sc;

  int p=0, a=1, b=0, c=0;
  int al = sa.length(), bl = sb.length(), cl = sc.length();
  bool ok = true;
  string result;
  while(ok){
    if (p==0&&sa[a-1]=='a') {p=0; a++;}
    if (p==0&&sa[a-1]=='b') {p=1; b++;}
    if (p==0&&sa[a-1]=='c') {p=2; c++;}
    if (p==1&&sb[b-1]=='a') {p=0; a++;}
    if (p==1&&sb[b-1]=='b') {p=1; b++;}
    if (p==1&&sb[b-1]=='c') {p=2; c++;}
    if (p==2&&sc[c-1]=='a') {p=0; a++;}
    if (p==2&&sc[c-1]=='b') {p=1; b++;}
    if (p==2&&sc[c-1]=='c') {p=2; c++;}

    if (a==al+1) {result="A"; ok=false;}
    if (b==bl+1) {result="B"; ok=false;}
    if (c==cl+1) {result="C"; ok=false;}
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <random>
#include <algorithm>
#include <unordered_set>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define Sort(a) sort(a.begin(),a.end())
#define cSort(a,cmp) sort(a.begin(),a.end(),cmp)
#define reSort(a) sort(a.rbegin(), a.rend())
static const ll llMAX = numeric_limits<long long>::max();
static const int intMAX = numeric_limits<int>::max();
static const ll  llMIN = numeric_limits<long long>::min();
static const int intMIN = numeric_limits<int>::min();
static const ll d_5 = 100000;
static const ll d9_7 = 1000000007;
static const ll d_9 = 1000000000;
static const double PI=3.14159265358979323846;
template<class T>
T gcd(T a,T b){
  if(a==0){
    return b;

  }else if(b==0){
    return a;
  }
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
ll digitpower(ll a,ll b){//aのb乗を計算
  if(b==1){
    return a;
  }else if(b==0){
    return 1;
  }
  int mode=1;
  if(mode==0){
    if(b%2==1){
      ll tmp = digitpower(a,(b-1)/2);
      tmp%=d9_7;
      tmp*=tmp;
      tmp%=d9_7;
      tmp*=a;
      return (tmp)%d9_7;
    }else{
      ll tmp = digitpower(a,(b)/2);
      tmp%=d9_7;
      tmp*=tmp;
      tmp%=d9_7;
      return (tmp)%d9_7;
    }
  }else{
    if(b%2==1){
      ll tmp = digitpower(a,(b-1)/2);
      tmp*=tmp;
      tmp*=a;
      return (tmp);
    }else{
      ll tmp = digitpower(a,(b)/2);
      tmp*=tmp;
      return (tmp);
    }
  }
  return 0;
  
}
template<class T>
void Printvector(std::vector<T> &a){
  int size = a.size();
  rep(i,size){
    cout<<a[i]<<" ";
  }
  cout<<endl;
}
template<class T>
void Printvector(std::vector<std::vector<T>> &a){
  int size = a.size();
  rep(i,size){
    int size2=a[i].size();
    rep(j,size2){
      cout<<a[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<endl;
}
int main(void){
  int n,k,c;
  string s;
  std::cin>>s;
  if(s[0]=='7' || s[1]=='7' || s[2]=='7'){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}

//clang++ -g -fsanitize=address -fno-omit-frame-pointer 1.cpp -o test.exe

//<<std::setprecision(30)

//重複削除
 /* std::sort(vec.begin(), vec.end());
 
  vec.erase(std::unique(vec.begin(), vec.end()), vec.end());*/

  //ペアの全探索
  /*do{
		int s=0;
		for(int i=0;i<n/2;i++)s+=v[i]^v[i+n/2];
		r=max(s,r);
		reverse(v.begin()+n/2,v.end());
	}while(next_permutation(v.begin(),v.end()));*/


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=2e5+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,to[N<<1],nxt[N<<1],d[N],ww[N<<1],tt=1,col[N],h[N],m;
bool vis[N];

void adde(int u,int v) {
	to[++tt]=v;nxt[tt]=h[u];h[u]=tt;
	to[++tt]=u;nxt[tt]=h[v];h[v]=tt;
}

void dfs(int u,int c=0) {
	col[u]=c;vis[u]=1;
	for(int i=h[u],v;v=to[i],i;i=nxt[i])
		if(~ww[i]&&!vis[v]) dfs(v,c^1);
}

int main() {//
	memset(ww,-1,sizeof(ww));
	cin>>n>>m;
	for(int i=1;i<=n;i++) d[i]=gi();
	for(int i=1,u,v;i<=m;i++) u=gi(),v=gi(),adde(u,v);
	for(int u=1;u<=n;u++) {
		pii mn=mp(2e9,0);int e=0;
		for(int i=h[u],v;v=to[i],i;i=nxt[i])
			if(mp(d[v],v)<mn) mn=mp(d[v],v),e=i>>1;
		if(mn.fi>d[u]) return cout<<-1,0;
		if(e) ww[e<<1]=ww[e<<1|1]=d[u];
	}
	for(int i=1;i<=n;i++) if(!vis[i]) dfs(i);
	for(int i=1;i<=n;i++) putchar(col[i]?'W':'B');
	cout<<'\n';
	for(int i=1;i<=m;i++) {
		if(!~ww[i<<1]) ww[i<<1]=1e9;
		cout<<ww[i<<1]<<'\n';
	}
	return 0;
}


Measured memory_bytes: 8704
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;
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; }

// ****************************************CODE***************************************//

ll n, w, weight[110], value[110];

ll dp[110][100100];

int main() {
    cin >> n >> w;
    for(int i = 0; i < n; i++) cin >> weight[i] >> value[i];

    for(int i = 0; i < n; i++){
        for(int sum_w = 0; sum_w <= w; sum_w++){
            if(sum_w - weight[i] >= 0) {
                dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[n][w] << endl;
}

Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(vi) (vi.begin(),vi.end())
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
#define MAX 100005
vi adj[MAX];
int n;

vi bfs(int node){
    vi dist(n+1,-1);
    queue<int> q;
    dist[node]=0;
    q.push(node);
    
    while(!q.empty()){
        int t=q.front();
        q.pop();
        
        for(auto ch:adj[t]){
            if(dist[ch]==-1){
                dist[ch]=dist[t]+1;
                q.push(ch);
            }
        }
    }
    
    return dist;
}
int main() {
    int x,y;
    si(n);
    
    for(int i=0;i<n-1;i++){
        si(x);si(y);
        adj[x].pb(y);
        adj[y].pb(x);
    }
    
    vi d1 = bfs(1);
    vi d2 = bfs(n);
    
    int s=0,f=0;
    
    for(int i=1;i<=n;i++){
        if(d1[i]<=d2[i]) f++;
        else s++;
    }
    
    if(f>s) cout<<"Fennec\n";
    else cout<<"Snuke\n";
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <algorithm>
using namespace std;
int n, h;
int dp[20001];
int a[1001], b[1001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> h >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i];
	}
	
	for (int i = 1; i <= 2*h; i++)
	{
		dp[i] = 100000000;
		for (int j = 1; j <= n; j++)
		{
			dp[i] = min(dp[i], dp[max(0,i - a[j])] + b[j]);
		}
	}
	int ans = 100000000;
	for (int i = h; i <= 2 * h; i++)
		if (dp[i] < ans) ans = dp[i];
	cout << ans;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    int d[n][2];
    for (int i = 0; i < n; i++) {
        cin >> d[i][0] >> d[i][1];
    }
    for (int i = 0; i < n-2; i++) {
        if (d[i][0] == d[i][1] && d[i+1][0] == d[i+1][1] && d[i+2][0] == d[i+2][1]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3616
def solve():
    from collections import defaultdict
    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.par = [-1] * n

        def find(self, x):
            if self.par[x] < 0:
                return x
            else:
                self.par[x] = self.find(self.par[x])
                return self.par[x]

        def unite(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.par[x] > self.par[y]:
                x, y = y, x

            self.par[x] += self.par[y]
            self.par[y] = x

        def size(self, x):
            return -self.par[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    c = list(map(int, input().split()))
    mp = defaultdict(int)
    uf = UnionFind(n)

    for i in range(n):
        uf.unite(i, p[i] - 1)

    for i in range(n):
        mp[uf.find(i)] += c[i]# 根にループ一周のポイントを加算

    ans = -10 ** 14
    for i in range(n):
        roop = uf.size(i) # ループに関連する要素数
        times = (k - 1) // roop if mp[uf.find(i)] > 0 else 0# 一周後のポイントが正ならループ回数をストック
        over = max(min(roop, k - roop * times), 1)# 最終周の移動数
        tmp = 0
        s = -10 ** 10
        idx = i
        for j in range(over):# 最終周のポイント最大値
            tmp += c[idx]
            s = max(s, tmp)
            idx = p[idx] - 1
        s += times * mp[uf.find(i)]# 最終週までの累積ポイント加算
        ans = max(ans, s)
    print(ans)


solve()


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

int main() {
    int n, m;
    long k;
    cin>>n >>m >>k;
    vector<long> a(n);
    vector<long> b(m);
    vector<long> a_sum(n+1);
    vector<long> b_sum(m+1);
    rep(i,n){
        cin>>a.at(i);
        a_sum.at(i+1)=a_sum.at(i)+a.at(i);
    }
    rep(i,m){
        cin>>b.at(i);
        b_sum.at(i+1)=b_sum.at(i)+b.at(i);
    }
    int ans=0;
    int h=m;
    rep(i,n+1){
        if(a_sum.at(i)>k) break;
        for(int p=h;p>=0;p--){
            if(a_sum.at(i)+b_sum.at(p)<=k){
                h=p;
                ans=max(ans,p+i);
                break;
            }
        }
    }
    cout<<ans<<endl;
}

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

int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  long long int a,b,c,d,x,y;
  cin >> a >> b >> c >> d;
  x=max(a*c,b*d);
  y=max(a*d,b*c);
  cout << max(x,y) <<endl;
}


int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
//#define PRAGMA 448
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
 
#ifdef LUCARIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
 
//typedef pair<long long,long long> pll;
typedef pair<int,int> pii;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define int long long
#define pb push_back
#define bs binary_search
#define up upper_bound
#define lb lower_bound
#define f first 
#define s second 
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define mp make_pair    
#define endl "\n"
 
#define fore(i,a,b) for(ll i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = b - 1; i >= a; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define ing(g,u,v)  g[u].pb(v); g[v].pb(u);
#define ingp(g,u,v,c) (g[u].pb({v,c});g[v].pb({u,c});)
#define mm(a,b) memset(a , b , sizeof a) 
#define trans(a,b) trasform(a.begin(),a.end(),a.begin(),b)
#define np(a) next_permutation(a.begin(), a.end())
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())
#define sfind(s,t) (s.find(t) != string::npos)
 
#define infll (ll)1e18+3
#define infi  (int)(1e9+1)
#define PI 3.14159265359 
#define mod (ll)(1e9+7)
#define eps  1e-10

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

typedef pair<int,pair<int,int>> pll;

pair<int,pair<int,int>> dp[500][500];
int a[500];
int n;

pll solve(int l,int r){
    if(l == r)return {a[l],{a[l],0}};
    //if(r-l == 1)return {a[l]+a[r],0};
    pll &rr = dp[l][r];
    if(~rr.f)return rr;
    rr = {infll,{infll,infll}};
    fore(i,l,r){
        auto x = solve(l,i);
        auto y = solve(i+1,r);
        //cout<<l<<" "<<r<<" "<<i<<" "<<x.f<<" "<<x.s<<" "<<y.f<<" "<<y.s<<endl;
        rr = min(rr,{x.f+y.f+x.ss+y.ss,{x.sf+y.sf,x.sf+y.sf}});
    }
    return rr;
}

int32_t main(int32_t argc, char const *argv[]){
    FIN;
    cin>>n;
    fore(i,0,n)cin>>a[i];
    mm(dp,-1);
    cout<<solve(0,n-1).f;

    return 0;
}





/*
Para las DP:

Los arreglos donde estén los valores en lo posible se declaran como INT
siempre hacer int &r = dp...
int res y trabajas todo con res
luego haces return r = res
cuando se trabaja se hace solve(...)+a[x];


Fórmulas:

priority_queue < int,vector<int>,greater<int> > q; calse contenedor y comparacion

cero = r/k  - (l/k + (l%k!=0)) +1; cantidad de números divisibles por k en el intervalo [l, r]
cantidad de inmeros en un rango lower_bound(r) -lowerbound(l-1)
upper_bound primer elemento mayor estricto
lower_bound primer elemento mayor o igual
Al hacer BFS con distancia recordar simpre antes de visitar preguntar si ya llegue antes con
un peso menor 
setprecision(15)
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
getline(cin,s); donde s es un string
si luego se van a haces unuevos cins hacer cin.ignore


*/




Measured memory_bytes: 6144
nCr = {}
def cmb(n, r):
    if n == 0: return 0
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
s = input().split()
print(cmb(int(s[0]),2) + cmb(int(s[1]),2))


Measured memory_bytes: 3064
#include<iostream>

using namespace std;
   
void sumOfIntegers()
{
    int n;
    int count;
    
    while(cin>>n)
    {
        count=0;
        
        for(int a=0;a<10;a++)
        {
            for(int b=0;b<10;b++)
            {
                for(int c=0;c<10;c++)
                {
                    for(int d=0;d<10;d++)
                    {
                        if(a+b+c+d==n)
                        {
                            count++;
                        }
                    }
                }
            }
        }
        
        cout<<count<<endl;
    }
    
    return;
}
     
int main()
{     
    sumOfIntegers();
    return 0;
}

Measured memory_bytes: 1156
import math

N, M = map(int, input().split())
mod = 10 ** 9 + 7

if abs(N - M) > 1:
    print(0)
elif abs(N - M) == 1:
    f = math.factorial(min(N, M))
    res = f % mod
    res *= f * max(N, M) % mod
    print(res % mod)
else:
    f = math.factorial(N)
    res = 2 * f % mod
    res *= f
    print(res % mod)


Measured memory_bytes: 4092
import itertools
n, m = map(int, input().split())
e = [[] for _ in range(n)]
ans = 0

for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    e[u].append(v)
    e[v].append(u)

for route in itertools.permutations(range(1, n), n - 1):

    visited = [False] * n
    visited[0] = True
    route = list(route)
    route.insert(0, 0)
    for i in range(1, n):
        now = route[i - 1]
        nxt = route[i]
        if str(nxt) in str(e[now]) and not(visited[nxt]):
            visited[nxt] = True
            if i == n - 1:
                ans += 1
        else:
            break

print(ans)

Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <complex>

#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define rtr(c, i) for (typeof((c).rbegin()) i = (c).rbegin(); i != (c).rend(); --i)
#define contains(c, x) ((c).find(x) != (c).end())
#define Contains(c, x) (find(all(c), x) != (c).end())
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, (n))
#define To_String to_string< char,std::char_traits<char>,std::allocator<char> >

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int a[20][20];
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	while (scanf("%d", &n), n) {
		memset(a, 0, sizeof(a));
		int r = n/2+1, c = n/2;
		int k = 1;
		a[r][c] = 1;
		r++, c++;
		while (k < n*n) {
			if (0 <= r && r < n) {
				if (0 <= c && c < n) {
					if (a[r][c] == 0) {
						a[r][c] = ++k;
						r++, c++;
					}
					else {
						r++, c--;
					}
				}
				else if (c >= n) { c = 0; }
				else if (c < 0) { c = n-1; }
			}
			else if (r >= n) { r = 0; }
		}
		rep(i, n) {
			rep(j, n) printf("%4d", a[i][j]);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;

class Main {

	static int moves(int die, int limit)
	{
		int cnt = 0;
		if(die>=limit) return 0;
		
		while(die < limit)
		{
			cnt++;
			die = 2*die;
		}
		return cnt;
	}
	public static void main(String[] args) {
		
		FastScanner s = new FastScanner();
		int r = s.nextInt();
		int d = s.nextInt();
		int x = s.nextInt();
		int y = x;
		for(int i = 2001 ;i<=2010;i++)
		{
			x = r*x - d;
			System.out.println(x);
		}
		
		
		//System.out.println();
		
	}

static   class FastScanner {
		
	    private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		
		}	

	}

}


Measured memory_bytes: 22484
n,y = map(int,input().split())

l=[]
for i in range(n+1):
    for j in range(n+1):
        if 10000*i + 5000*j + 1000*(n-i-j)==y:
            l+=[[i,j,n-i-j]]
    
for k in range(len(l)):
    if l[k][0]>=0 and l[k][1]>=0 and l[k][2]>=0:
        print(*l[k])
        break
else:
    print(-1,-1,-1)

Measured memory_bytes: 3064