akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}

void solve(long long A, long long B, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> x, std::vector<long long> y, std::vector<long long> c){
    ll minA=INF;
    rep(i,A){
        chmin(minA,a[i]);
    }
    ll minB=INF;
    rep(i,B){
        chmin(minB,b[i]);
    }
    ll mi=minA+minB;
    rep(i,M){
        chmin(mi,a[x[i]-1]+b[y[i]-1]-c[i]);
    }
    cout<<mi<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(A);
    for(int i = 0 ; i < A ; i++){
        scanf("%lld",&a[i]);
    }
    std::vector<long long> b(B);
    for(int i = 0 ; i < B ; i++){
        scanf("%lld",&b[i]);
    }
    std::vector<long long> x(M);
    std::vector<long long> y(M);
    std::vector<long long> c(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        scanf("%lld",&c[i]);
    }
    solve(A, B, M, std::move(a), std::move(b), std::move(x), std::move(y), std::move(c));
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  int x, y, z;
  cin >> x >> y >> z;
  
  cout << z << " " << x << " " << y << endl;
  return 0;
}



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

using namespace std;

int solve(int X) {
    bool check = true;
    for (;; ++X) {
        if (X == 1)
            check = false;
        if (X%2 == 0)
            check = false;
        if (X == 2)
            return X;

        double Xsqrt = sqrt(X);
        for (int n=3; n <= Xsqrt; n+=2) {
            if (X%n == 0) {
                check = false;
                break;
            }
        }

        if (check)
            return X;
        check = true;
    }
}

int main() {
    int X;
    cin >> X;
    cout << solve(X);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll count = 0;
  ll pre = -1;
  rep(i, n){
    if(pre != a[i]){
      pre = a[i];
      count++;
    }
  }
  ll ans = count;
  if((n - count) % 2 == 1) ans--;
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.util.Scanner;

/**
 * using DP. O(N)
 * ????????????[x,i]????????§??¨?????????dp[i]??¨?????????(ai??§??????????????§??¨??????)
 * dp[0] = 0
 * dp[i] = max(dp[i-1] + ai, ai) -> ai??§??????????????§??¨?????? = a{i-1}??§??????????????§??¨?????? + ai, ai????????§???
 * ?±???????????????????max(dp[i])
 */
class Main {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);

		while(true) {
			int n = in.nextInt();
			if(n==0) break;

			int ans = Integer.MIN_VALUE;
			int dpi = 0;
			for (int i = 0; i < n; i++) {
				int ai = in.nextInt();
				dpi = Math.max(dpi + ai, ai);
				ans = Math.max(ans, dpi);
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 33836
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
	int n;scanf("%d",&n);
	if(n<1200)printf("ABC\n");
	else if(n<2800)printf("ARC\n");
	else printf("AGC\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	int ans = 2e9;

	for (int i = 0; i <= 2 * max(x, y); i += 2) {
		int tmp = a * max(0, x - i / 2) + b * max(0, y - i / 2) + c * i;
		ans = min(ans, tmp);
		// printf("%2d, %9d\n", i, tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    for(int i=1;i<=10101;i++){
        //if(i == 25) cout << A * 0.08  << " " << B * 0.1 << endl;
        if((i * 8) / 100 == A && (i  / 10 == B)){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
l=[]
c=0
mm=list(range(1,m+1))
for i in range(n):
    ll=list(map(int,input().split()))
    l.append(ll)
    del l[i][0]
for i in range(m):
    t=True
    for j in range(n):
        if mm[i] not in l[j]:
            t=False
    if t:
        c+=1
print(c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N;cin>>N;
  if(N==1){
    cout<<"Hello World"<<"\n";
  }else{
    int A,B;cin>>A>>B;
    cout<<A+B<<"\n";
  }

  return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 1000000007
#define M 2200000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int out=0;
    loop(i,a,c+1)
        (out+=MOD+nCr(i+d+1,d)-nCr(i+b-1+1,b-1))%=MOD;
    cout<<out<<endl;
}


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

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        int answer = 0;
        while (true)
        {
            s = s.Substring(0, s.Length - 2);
            if (s.Substring(0, s.Length / 2) == s.Substring(s.Length / 2, s.Length / 2))
            {
                answer = s.Length;
                break;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-6;
const long INF = 1e10;

char mp[100][100];
int ans[100][100];
int dx[]={2,0,-2,0};
int dy[]={0,2,0,-2};
int main(){
	int w,h;
	while(cin>>w>>h){
		if(w==0&&h==0)break;
		REP(i,100){
			REP(j,100){
				mp[i][j]=(i%2==0||j%2==0)?'#':'o';
			}
		}
		int gx=w*2-1,gy=h*2-1;
		cin.ignore();
		//スタートは(1,1)
		REP(i,2*h-1){
			string str;
			getline(cin,str);
			REP(j,SZ(str)){
				if(str[j]=='0'){
					mp[i+1][j+1]='.';
					//cout<<"!"<<endl;
				}
			}
		}
		CLR(ans);
		queue<PII>qu;qu.push(MP(1,1));ans[1][1]=1;
		
		while(!qu.empty()){
			PII temp=qu.front();
			qu.pop();
			int y=temp.first;
			int x=temp.second;
			REP(i,4)if(mp[y+(dy[i]/2)][x+(dx[i]/2)]=='.'&&ans[y+dy[i]][x+dx[i]]==0){
				qu.push(MP(y+dy[i],x+dx[i]));
				ans[y+dy[i]][x+dx[i]]=ans[y][x]+1;
			}
		}
		cout<<ans[gy][gx]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int a,k;
  string s;
  cin>>a>>k>>s;
  if(s[k-1]=='A') s[k-1]='a';
  if(s[k-1]=='B') s[k-1]='b';
  if(s[k-1]=='C') s[k-1]='c';
  cout<<s;
}


Measured memory_bytes: 3560
#include <cstdio>

int n, a[10010];
char c[10010];

int main(){
	
	scanf("%d%s", &n, c);
	for(int i = 0; c[i] != '\0'; i++)
		a[i] = c[i] - 'A';
	for(int i = 0; c[i] != '\0'; i++)
		a[i] = (a[i] + n) % 26;
	for(int i = 0; c[i] != '\0'; i++)
		putchar(a[i] + 'A');
	
	return 0;
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<int> a(n),t(n);
    vector<lint> ans(n,-1); 
    REP(i,n) cin>>t[i];
    ans[0] = 1; ans[n-1] = 1;
    REP(i,n) cin>>a[i];
    REP(i,n-1){
        if(t[i]!=t[i+1]){
            ans[i+1] = 1;
            if(a[i+1]<t[i+1]) ans[i+1]=0; 
        } 
        else if(a[i]!= a[i+1]){
            ans[i] = 1;
            if(a[i]>t[i]) ans[i]=0;
        } 
    }
    lint cnt = 1;
    REP(i,n){
        if(ans[i]==-1) ans[i] = min(a[i],t[i]);
        cnt*=ans[i];
        cnt%=1000000007;
    }
    if(t[n-1]!=a[0]) cnt= 0;
    print(cnt);
    return 0;
}

Measured memory_bytes: 1792
data class Point(val t: Int, val x: Int, val y: Int)

fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val points = Array(n + 1) {
        if (it == 0) {
            Point(0, 0, 0)
        } else {
            val (t, x, y) = readLine()?.split(" ")?.map { n -> n.toInt() } ?: return
            Point(t, x, y)
        }
    }

    for (t in 0 until n) {
        val dt = points[t + 1].t - points[t].t
        val dist = Math.abs(points[t + 1].x - points[t].x) +
                Math.abs(points[t + 1].y - points[t].y)
        if (dt < dist || dt % 2 != dist % 2) {
            println("No")
            return
        }
    }
    println("Yes")
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int d;
  cin >> d;
  cout << "Christmas";
  if (d == 24) {
    cout << " Eve";
  } else if (d == 23) {
    cout << " Eve Eve";
  } else if (d == 22) {
    cout << " Eve Eve Eve";
  }

  cout << '\n';
  return 0;
}

Measured memory_bytes: 3680
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
struct pos {
  int row;
  int column;
};
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
vector<pair<int, int>> directions = {
    make_pair(0, 1),  make_pair(1, 0),   make_pair(1, 1),  make_pair(0, -1),
    make_pair(-1, 0), make_pair(-1, -1), make_pair(-1, 1), make_pair(1, -1),
};
void traverse(int grid[55][55], bool dp[55][55], int row, int column,
              int maxRow, int maxColumn) {
  dp[row][column] = true;

  for (auto direction : directions) {
    int newRow = row + direction.first;
    int newColumn = column + direction.second;

    if (newRow < 0 || newRow >= maxRow || newColumn < 0 ||
        newColumn >= maxColumn) {
      continue;
    }

    if (grid[newRow][newColumn] == 0) continue;
    if (dp[newRow][newColumn]) continue;

    traverse(grid, dp, newRow, newColumn, maxRow, maxColumn);
  }
}
int main(void) {
  vector<int> results;
  while (true) {
    bool dp[55][55] = {false};
    int grid[55][55] = {0};
    int ROW, COLUMN;
    cin >> COLUMN >> ROW;
    if (ROW == 0 && COLUMN == 0) break;
    rep(row, ROW) {
      rep(column, COLUMN) { cin >> grid[row][column]; }
    }

    int count = 0;
    rep(row, ROW) {
      rep(column, COLUMN) {
        if (grid[row][column] == 0) continue;
        if (dp[row][column]) continue;
        traverse(grid, dp, row, column, ROW, COLUMN);
        count++;
      }
    }

    results.push_back(count);
  }

  for (auto result : results) {
    cout << result << endl;
  }

  return 0;
}


Measured memory_bytes: 3236
N, M = map(int, input().split())
A = []
for i in range(N):
  l = [int(a) for a in input().split()]
  K = l[0]
  A.append(l[1::])

x = A[0]
for a in A[1:]:
  x = list(set(x) & set(a))

print(len(x))



Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 101
#define INFTY 9999999
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

void dijkstra(void){
  int minv;
  int d[MAX],color[MAX];
  int i,j,u,v;

  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }

  d[0]=0;
  color[0]=GRAY;

  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
  
    if(u==-1)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]!=INFTY)printf("%d\n",d[i]);
    else printf("-1\n");
  }
}

int main(){
  int i,j,k,c,u,v;
    
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }
  dijkstra();

  return 0;
}



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

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;　　　　　//人数
            int s;　　　　　//必要な個数
            int i;

            //人数ｎを入力
            n = int.Parse(Console.ReadLine());

            //必要な個数ｓを求める
            //（合計を求めるアルゴリズム）
            s = 0;                      //合計を０に初期化

            for (i = 1; i <= n; i++)
            {
                s = s + i;    //s+=iでもよい
            }
            //ｓを出力（表示）
            Console.WriteLine(s);

            //入力待ち
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

void solve(){
    int n, i = 1;
    while(cin >> n){
        if(n != 0){
            cout << "Case " << i << ": " << n << endl;
            i++;
        }else{
            break;
        }
    }
}

int main() {
    solve();
    return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long s = sc.NextLong();

        long x1 = 0;
        long y1 = 0;
        long x2 = (long)1e9;
        long y2 = 1;
        long y3 = 1 + ((s - 1) / x2);
        long x3 = x2 * y3 - s;

        string answer = x1 + " " + y1 + " " + x2 + " " + y2 + " " + x3 + " " + y3;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

const double EPS = 1e-10;

typedef struct
{
  string f;
  int w, s;
} Food;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<Food> foods(n);
    for (int i = 0; i < n; ++i)
      cin >> foods[i].f >> foods[i].w >> foods[i].s;

    vector<int> index(n);
    for (int i = 0; i < n; ++i)
      index[i] = i;

    double bestG = 1e10;
    vector<string> ans(n);
    do {
      int w = 0, kw = 0;
      bool valid = true;
      for (int i = 0; i < n && valid; ++i) {
	if (foods[index[i]].s < w)
	  valid = false;
	w += foods[index[i]].w;
	kw += (n-i) * foods[index[i]].w;
      }

      if (valid) {
	double G = kw * 1.0 / w;
	if (bestG - G > EPS) {
	  bestG = G;
	  for (int i = 0; i < n; ++i)
	    ans[i] = foods[index[i]].f;
	}
      }
    } while (next_permutation(index.begin(), index.end()));

    reverse(ans.begin(), ans.end());
    for (int i = 0; i < n; ++i)
      cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 920
#include <cstdio>
#define NOT_FOUND -1
using namespace std;

int isXInList(int x, int L[], int N) {
    int left = 0, right = N;
    while (right > left) {
        int mid = (left + right) / 2;
        if (L[mid] == x) {
            return mid;
        }
        else if (L[mid] > x) {
            right = mid;
        }
        else {
            left = mid + 1;
        }
    }
    return NOT_FOUND;  //没找到
}

int main() {
    int sum = 0;
    int n, q;
    int S[100005], T[50005]; 
    scanf("%d", &n);
    for (int i = 0; i < n; i++)  scanf("%d", &S[i]);
    scanf("%d", &q);
    for (int i = 0; i < q; i++)  scanf("%d", &T[i]);
    for (int i = 0; i < q; i++) {
        if (isXInList(T[i], S, n) != NOT_FOUND)  sum++;
    }
    printf("%d\n", sum);
    return 0;
}


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

int main(){
    long long N,flag=1,Min=0x7fffffff;
    long long Sum=0;
    scanf("%d",&N);
    while(N--){
        long long A,B;
        scanf("%lld%lld",&A,&B);
        Sum+=A;
        if(A>B)
            Min=min(Min,B);
        if(A!=B) flag=0;
    }
    if(flag) Min=Sum;
    printf("%lld",Sum-Min);
}

Measured memory_bytes: 128
import sys
from collections import Counter
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
minus_a_ct = Counter([-a-i for i,a in enumerate(a_ls)])
a_ct = Counter([a-i for i,a in enumerate(a_ls)])
_sum = 0
for k, v in a_ct.items():
    _sum += v * minus_a_ct[k]
print(_sum)

Measured memory_bytes: 143640
#include<vector>
#include<iostream>
using namespace std;
template <class data_t>
class dice{
    int comp_dice_spin(dice<data_t> d2);
public:
    vector<data_t> field;
    dice(){}
    dice(vector<data_t> v);
    void roll(char ch);
    data_t top(){return field[0];}
    int comp_dice_type(dice<data_t> d2);
    int comp_dice(dice<data_t> d2);
    void levorotation_spin(){roll('W');roll('N');roll('E');}
};
template <class data_t>
dice<data_t>::dice(vector<data_t> v){
    typename vector<data_t>::iterator vi = v.begin();
    while(vi!=v.end()){
        field.push_back(*vi);
        vi++;
    }
}
template <class data_t>
void dice<data_t>::roll(char ch){
    data_t tmp;
    switch(ch){
        case 'E':
            tmp = field[0];
            field[0] = field[3];
            field[3] = field[5];
            field[5] = field[2];
            field[2] = tmp;
            break;
        case 'N':
            tmp = field[0];
            field[0] = field[1];
            field[1] = field[5];
            field[5] = field[4];
            field[4] = tmp;
            break;
        case 'S':
            tmp = field[0];
            field[0] = field[4];
            field[4] = field[5];
            field[5] = field[1];
            field[1] = tmp;
            break;
        case 'W':
            tmp = field[0];
            field[0] = field[2];
            field[2] = field[5];
            field[5] = field[3];
            field[3] = tmp;
            break;
    }
    return;
}
template <class data_t>
int dice<data_t>::comp_dice(dice<data_t> d2){
    int c;
    for(c=0;c<6;c++){
        if(field[c] != d2.field[c]){
            return field[c] - d2.field[c];
        }
    }
    return 0;
}
template <class data_t>
int dice<data_t>::comp_dice_type(dice<data_t> d2){
    if(comp_dice_spin(d2) == 0)return 0;
    roll('N');
    if(comp_dice_spin(d2) == 0)return 0;
    roll('E');
    if(comp_dice_spin(d2) == 0)return 0;
    roll('E');
    if(comp_dice_spin(d2) == 0)return 0;
    roll('E');
    if(comp_dice_spin(d2) == 0)return 0;
    roll('N');
    if(comp_dice_spin(d2) == 0)return 0;
    return -1;
}
template <class data_t>
int dice<data_t>::comp_dice_spin(dice<data_t> d2){
    int i;
    for(i=0;i<4;i++){
        if(comp_dice(d2) == 0)
            return 0;
        levorotation_spin();
    }
    return -1;
}
int main(){
    int i, j, n;
    bool not_i_differ_all = false;
    vector<int> v(6);
    cin >> n;
    vector<dice<int> > dv;
    for(i=0;i<n;i++){
        cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4]>> v[5];
        dv.push_back(v);
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if(dv[i].comp_dice_type(dv[j]) == 0){
                i=j=n;
                not_i_differ_all++;
            }
        }
    }
    if(not_i_differ_all){
        cout << "No\n";
    }else{
        cout << "Yes\n";
    }
    return 0;
}


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

int main()
{
    int arr[3];
    for (int i = 0; i < 3; i++) {
        cin >> arr[i];
    }
    sort(arr, arr + 3);

    if(arr[0] + arr[1] == arr[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> ans(n+1);
    for (int x = 1; x <= 100; x++)
    {
        for (int y = 1; y <= 100; y++)
        {
            for (int z = 1; z <= 100; z++)
            {
                int m = x * x + y * y + z * z + x * y + y * z + z * x;
                if (m <= n)
                {
                    ans[m]++;
                }
                else
                {
                    break;
                }
            }
        }
    }
    rep(i,n){
        cout << ans[i+1] << "\n";
    }
}

Measured memory_bytes: 3560
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {


    int arr[5][5],n;bool isfail=true;
    for(int i=0;i<3;++i)
    {
    	for(int j=0;j<3;++j)
    	   cin>>arr[i][j];
    }cin>>n;int AofN[n];
    for(int f=0;f<n;++f)
    	cin>>AofN[f];
    for(int a=0;a<n;++a)
    {
    	for(int q=0;q<3;++q)
    	    {

    	    	for(int l=0;l<3;++l)
    	    	{
    	    		if(arr[q][l]==AofN[a])
    	    		{
    	    			arr[q][l]=1;
    	    		}

    	    	}
    	    }


    }
    for(int w=0;w<3;++w)
    {
    	for(int y=0;y<3;++y){

    		if((arr[w][y]==1&&arr[w][y+1]==1 && arr[w][y+2]==1)
    		    			||(arr[w][y]==1&&arr[w+1][y]==1 && arr[w+2][y]==1)
    						||(arr[w][y]==1&&arr[w+1][y+1]==1 && arr[w+2][y+2]==1)
							||(arr[w+2][y]==1&&arr[w+1][y+1]==1 && arr[w][y+2]==1)){
    		    	        	   	    	cout<<"Yes"<<endl;
    		    	        	   	    	isfail=false;
    		    	        	   	    	break;
    		    	}

    	}
    	if(isfail==false)
    	    	break;
    }
    if(isfail==true)
    	cout<<"No"<<endl;






    return 0;
}


Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> A = new TreeMap<Integer, Integer>();
		for(int i = 1; i <= N; i++) {
			A.put(sc.nextInt(), i);
		}
		for(Integer key : A.keySet()) {
			System.out.println(A.get(key) + " ");
		}
	}
}

Measured memory_bytes: 70172
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007; 
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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



int morethan(int a, std::vector<int> &cnt){
    int c(0);
    for(int i(0), i_len(cnt.size()); i < i_len; ++i){
        if(cnt[i] >= a) ++c;
    }
    return c;
}

int main(){
    int N; std::cin >> N;
    std::vector<int> cnt;
    std::vector<bool> prime(N+1, true);
    prime[0] = prime[1] = false;
    for(int i(2); i <= N; ++i){
        if(!prime[i]) continue;
        for(int j(i*2); j <= N; j += i){
            prime[j] = false;
        }
        int c(0);
        for(int j(i); j <= N; j *= i){
            c += N / j;
        }
        cnt.push_back(c);
    }
    int ans(0);
    ans += morethan(75-1, cnt);
    ans += morethan(25-1, cnt) * (morethan(3-1, cnt) - 1);
    ans += morethan(15-1, cnt) * (morethan(5-1, cnt) - 1);
    ans += morethan(5-1, cnt) * (morethan(5-1, cnt) - 1) / 2 * (morethan(3-1, cnt) - 2);
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final long[] cumulativeSum = new long[n];
        cumulativeSum[0] = scanner.nextLong();

        for (int i = 1; i < n; i++) {
            cumulativeSum[i] = cumulativeSum[i - 1] + scanner.nextLong();
        }

        int firstIndex = 0;
        int thirdIndex = 2;
        long answer = Integer.MAX_VALUE;
        for (int secondIndex = 1; secondIndex < n - 2; secondIndex++) {
            for (; firstIndex < secondIndex - 1; firstIndex++) {
                if (Math.abs(cumulativeSum[secondIndex] - cumulativeSum[firstIndex] * 2) <= Math.abs((cumulativeSum[secondIndex] - cumulativeSum[firstIndex + 1] * 2))) {
                    break;
                }
            }

            for (; thirdIndex < n - 2; thirdIndex++) {
                if (Math.abs(cumulativeSum[n - 1] - cumulativeSum[thirdIndex] * 2 + cumulativeSum[secondIndex]) <= Math.abs(cumulativeSum[n - 1] - cumulativeSum[thirdIndex + 1] * 2 + cumulativeSum[secondIndex])) {
                    break;
                }
            }

            long a = cumulativeSum[firstIndex];
            long b = cumulativeSum[secondIndex] - cumulativeSum[firstIndex];
            long c = cumulativeSum[thirdIndex] - cumulativeSum[secondIndex];
            long d = cumulativeSum[n - 1] - cumulativeSum[thirdIndex];

            long tmp = max(a, b, c, d) - min(a, b, c, d);
            answer = Math.min(tmp, answer);
        }

        System.out.println(answer);
    }

    private static long max(final long a, final long b, final long c, final long d) {
        return Math.max(Math.max(a, b), Math.max(c, d));
    }

    private static long min(final long a, final long b, final long c, final long d) {
        return Math.min(Math.min(a, b), Math.min(c, d));
    }
}


Measured memory_bytes: 81384
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, M: int, a: "List[int]", b: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):
    ans = min(a) + min(b)
    for i in range(M):
        xi = x[i]
        yi = y[i]
        ci = c[i]
        t = a[xi-1] + b[yi-1] - ci
        if ans >= t:
            ans = t
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 95296
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

   ll l=n/(a+b);
   ll m=n%(a+b);
   ll ans=a*l + min(a, m);

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


Measured memory_bytes: 3604
#include <iostream>
#include <queue>
#include <algorithm>
#include <climits>
#include <stack>
#include <vector>
#include <random>
#include <string.h>
#include <stdio.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef pair<int, int> ii;
typedef pair<long double, int> id;
typedef pair<long long, long long> llp;
const int N = 1e5+1;
int n, m, k, t;
long long dp[101][N+1];
int main() {
    //freopen("ee.inp", "r", stdin);
    //freopen("ee.OUT", "w", stdout);
    fastIO;
    cin>>n>>m;
    int w, v;
    for(int i=1;i<=n&&cin>>w>>v;i++)
        for(int j=1;j<=m;j++) {
            dp[i][j] = dp[i-1][j];
            if (j-w>=0) dp[i][j] = max(dp[i][j], dp[i-1][j-w]+v);
        }
    cout << dp[n][m];
}


Measured memory_bytes: 81716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int working = 0;
		for (int i = 0; i < m; ++i) {
			working += sc.nextInt();
		}

		int vacation = Math.max(n - working, -1);
		System.out.println(vacation);
	}

}


Measured memory_bytes: 46212
#include <iostream>
#include <string>
using namespace std;
int main(){
int n,sum=0;
int cnt1=0;
int cnt2=0;
cin >>n;
    cnt1=n/500;
    n=n-500*cnt1;
  cnt2=n/5;
  //cout <<cnt1 <<" " <<cnt2 <<endl;
sum=1000*cnt1+5*cnt2;
cout <<sum <<endl;
return 0;
}

Measured memory_bytes: 256
i,z=256,t[65536];main(j,k,l,x){for(;i<z;i++)for(j=i;j<z;j++)for(k=j;k<z;k++)for(l=k;l<z;l++){if((x=i*i+j*j+k*k+l*l)>=z*z)break;t[x]++;}while(scanf("%d",&x),x)printf("%d\n",t[x]);return 0;}

Measured memory_bytes: 536
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 A, B, N;
  cin >> A >> B >> N;
  N = min(N, B - 1);
  cout << A * N / B - A * (N / B) << endl;
  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();

		long a[][]=new long[n][m];
		long b[][]=new long[m][l];
		long c[][]=new long[n][l];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				long num=sc.nextInt();
				a[i][j]=num;
			}
		}
		for(int i=0;i<m;i++){
			for(int j=0;j<l;j++){
				long num=sc.nextInt();
				b[i][j]=num;

			}
		}

		sc.close();

		// 計算
		for(int i=0;i<n;i++){
			for(int j=0;j<l;j++){
				long sum=0;
				for(int k=0;k<m;k++){
					sum+=a[i][k]*b[k][j];
				}
				c[i][j]=sum;

			}

		}

		// 出力
		for(int i=0;i<n;i++){
			for(int j=0;j<l;j++) {
				System.out.print(c[i][j]);
				if(j != l-1) System.out.print(" ");
			}
			System.out.println("");
		}
	}
}


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

using namespace std;
int n, k, q, t, a[100005];

int main () {
	cin >> n >> k >> q;
	for (int i=0;i<q;i++){
		cin >> t;
		a[t]++;
	}
	for (int i=1;i<=n;i++){
		if (k-(q-a[i])>0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i, n) for (int i = 0; i < (int)n; i++)
#define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
//const double PI = acos(-1);
const int mod = 1000000007;

// ----------------------DEBUG TEMPLATE--------------------------
void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif
// ----------------------DEBUG TEMPLATE--------------------------

bool check(int maxi,vi& arr,int k){
    int res=0;
    fo(i,arr.size()){
        res+= ((arr[i]-1)/maxi);
    }
    return (res<=k);
}

int bs(vi &arr,int k){
    int r=INT_MIN;
    fo(i,arr.size()){
        r = max(r,arr[i]);
    }
    int l=1;
    int mid;
    int ans=r;
    while(l<=r){
        mid = l + (r-l)/(int)2;
        // debug(l,mid,r);
        bool c = check(mid,arr,k);
        if(c){
            r=mid-1;
            ans = mid;
        }
        else{
            l=mid+1;
        }
    }
    return ans;


}


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    
    vi arr(n);
    fo(i,n) cin>>arr[i];
    if(k==0){
        cout<<*max_element(all(arr))<<endl;
    }
    else{
        cout<<bs(arr,k);
    }

    





}

Measured memory_bytes: 4704
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;
int main()
{
    int n, ans = INT_MAX;
    string s;
    cin >> n >> s;
    vector<int> v(n+1, 0);
    for(int i = 0; i < n; i++){
        if(s[i] == '.') v[i+1]++;
        v[i+1] += v[i];
    }
    if(v[n] == 0){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 1; i <= n; i++){
        ans = min(ans, v[n] + i - v[i] * 2);
        if(v[i] == 0) ans = min(ans, v[n]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

int n;
vector<int> d;
int dp[102][102];

void solve() {
    for (int i = 0; i < n; ++i) {
        dp[i][i] = 0;
    }
    for (int span = 2; span <= n; ++span) {
        for (int i = 0; i <= n - span; ++i) {
            int j = i + span - 1;
            dp[i][j] = INT_MAX;
            for (int k = i; k <j ; ++k) {
                dp[i][j] = min(dp[i][j], d[i] * d[j+1] * d[k+1] + dp[i][k] + dp[k+1][j]);
            }
        }
    }
}

int main() {
    cin >> n;
    d.resize(n + 1);
    int r, c;
    for (int i = 0; i < n; ++i) {
        cin >> r >> c;
        d[i] = r;
    }
    d[n] = c;
    solve();
    cout << dp[0][n-1] << endl;

    return 0;
}




Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define N 100010
#define pb push_back
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
char s[N];
vector<int> V[N],v[N];
int d[N],vis[N],val[N],dp[N],D;
inline void dfs(int x,int fa) {
    dp[x]=val[x];
    for (auto y:v[x]) if (y!=fa) {
        dfs(y,x),D=max(dp[x]+dp[y],D),dp[x]=max(dp[x],dp[y]+val[x]);
    }
}
int main() {
    int n=read(),cnt=0;
    for (int i=1;i<=n-1;i++) {
        int x=read(),y=read();
        V[x].pb(y),V[y].pb(x); d[x]++,d[y]++;
    }
    scanf("%s",s+1);
    queue<int> q;
    for (int i=1;i<=n;i++)
        if (d[i]==1 && s[i]=='B') q.push(i);
    while (!q.empty()) {
        int x=q.front(); q.pop(); vis[x]=true;
        for (auto y:V[x]) if (!vis[y]) 
            if ((--d[y])==1 && s[y]=='B') q.push(y);
    }
    // for (int i=1;i<=n;i++) printf("%d ",d[i]); puts("");
    int sum=0;
    for (int x=1;x<=n;x++) for (auto y:V[x])
        if (!vis[x] && !vis[y]) v[x].pb(y),++sum;
    for (int i=1;i<=n;i++) if (!vis[i]) {
        if ((s[i]=='B' && (d[i]&1)) || (s[i]=='W' && !(d[i]&1))) val[i]=2,++cnt;
    }
    int rot=0;
    for (int i=1;i<=n;i++)
        if (!vis[i]) {rot=i;break;}
    dfs(rot,0);
    // printf("%d %d %d\n",sum,cnt,D);
    cout<<sum+cnt-D<<endl;
    return 0;
}

Measured memory_bytes: 15232
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <deque>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL;

using namespace std;

LL N, M;

int main() {
	cin >> N >> M;
	if (N > M)
		swap(N, M);
	if (N == 1) {
		if (M == 1)
			cout << "1";
		else
			cout << (M - 2) << endl;
	}
	else
		cout << (N * M - 2 * N - 2 * (M - 2)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
 int n;
  cin>>n;
  int d[50];
  int i;
  i=0;
  while(i<n)
  {
    cin>>d[i];
    i++;
  }
  int ans=0;
  int ii;
  i=0;
  while(i<n)
  {
    ii=i+1;
   while(ii<n) 
   {
     ans+=d[i]*d[ii];
       ii++;
   }
    i++;
  }
  cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long double 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
  cout << fixed ;
  cout << setprecision(8) ;
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int n ;
	cin >> n ;
  ll arr[n] , ans = 0 ;
  for(int i = 0 ; i < n ; i++){
    cin >> arr[i] ;
    ans += (ll)1/arr[i] ;
  }
  cout << (ll)1/ans ;
}


Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

n = ii()
l = iil()
count = 0
for i in l:
    if i%2 == 1:
        count += 1
if count%2 == 0:
    print('YES')
else:
    print('NO')

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

int main(){
  int n,k,r,s,p;
  string t;
  cin>>n>>k>>r>>s>>p>>t;
  queue<char> q;
  int ans=0;
  rep(i,n){ 
    if(i < k){
      if(t[i]=='r') {q.push('p'); ans+=p;} 
      if(t[i]=='s') {q.push('r'); ans+=r;}
      if(t[i]=='p') {q.push('s'); ans+=s;}
    }else{
      if(t[i]=='r'){
        if(q.front()!='p') {q.push('p'); ans+=p;}
        else q.push('a');
        q.pop();
      }
      if(t[i]=='s'){
        if(q.front()!='r') {q.push('r'); ans+=r;}
        else q.push('a');
        q.pop();
      }
      if(t[i]=='p'){
        if(q.front()!='s') {q.push('s'); ans+=s;}
        else q.push('a');
        q.pop();
      }
    }
  }
  cout<<ans<<endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0;i<n;++i) cin >> a[i];
  
  int ans = 0;
  while (1){
    bool odd=false;
    for (int i=0;i<n;++i){
       if (a[i]%2==1) {
         odd=true;
       }
    }
    if (odd) break;//このbreakでwhile文を出る
    for (int i=0;i<n;++i) {
      a[i]/=2;
    }
      ans++;
  }
  cout << ans << endl;
  return 0;
}
    


Measured memory_bytes: 256