akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

// #define mod (int) 998244353
// #define MOD (int) 1e9+7
// // Big two primes
// #define X 1001100011100001111ll
// #define all(a) a.begin(),a.end()
// #define for0(i, n) for (int i = 0; i < n; i++)
// #define for1(i, n) for (int i = 1; i <= n; i++)
// #define loop(i,a,b) for (int i = a; i < b; i++)
// #define bloop(i,a,b) for (int i = a ; i>=b;i--)
// #define tc(t) int t; cin >> t; while (t--)
// //#define int long long
// #define ll long long
// #define pb emplace_back
// #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
// #define in(x) scanf("%d", &x)
// #define rr return 0
// #define prec(n) fixed<<setprecision(n)
// #define maxpq priority_queue<int>
// #define minpq priority_queue<int, vector<int>, greater<int> >
// #define inf (int)(1e18)
// #define ini(a, i) memset(a, i, sizeof(a))
// #define vi vector<int>
// #define fi first
// #define se second
// #define endl "\n"
// #define ii pair<int, int>
// #define vii vector<ii>
// #define sz(s) s.size()


int main(){
    int n,k;
    cin>>n>>k;
    int a[n],i,dp[k+1];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<k+1;i++)
        dp[i]=0;
    for(i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(a[j]<=i && dp[i-a[j]]!=1)
                dp[i]=1;
        }
    }    
    int ans=dp[k];   
    if(ans)
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;            
    return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def _make_minimum_prime(N: int):
    # xの最小の素因数表を作成
    min_prime = [x for x in range(N + 1)]
    # min_prime[0] = 0  # 0と1は素数ではない
    # min_prime[1] = 1
    for i in range(2, int(N ** 0.5) + 1):
        if min_prime[i] == i:  # 素数だったら更新
            for j in range(2 * i, N + 1, i):  # iの倍数は素数でない
                if min_prime[j] == j:
                    min_prime[j] = i
    return min_prime


min_prime = _make_minimum_prime(10**6)


from collections import Counter


def fast_factorization(N: int):
    # -> List[Tuple[int,int]] (素数,冪数)を格納
    # 最小素数配列min_primeを使ってO(log N)で因数分解
    if N == 1:
        return Counter()  # 1は素数ではない
    # 素因数分解
    arr = []
    tmp = N
    while tmp != 1:
        p = min_prime[tmp]
        tmp //= p
        arr.append(p)

    return Counter(arr)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
import random
from math import gcd


N = a_int()
A = ints()
random.shuffle(A)

# setかはすぐわかる
# setでなければ not coprime
# pairは互いに素かをみればいいのか
# つまり因数分解して足してったときにすべての素数のべき数が1以下であれば良い

g_set = 0
cnt = defaultdict(lambda: 0)
flg = 1  # pairwiseであるフラグ
for a in A:
    g_set = gcd(g_set, a)
    if flg:
        for p, n in fast_factorization(a).items():
            if cnt[p] != 0:
                flg = 0
            cnt[p] += n


# print(cnt)
# for v in cnt.values():
#     if v > 1:
#         flg = 0
#         break

if g_set > 1:
    print('not coprime')
elif flg:
    print('pairwise coprime')
else:
    print('setwise coprime')


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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll t,i,x,j,y,z,k,n;

cin>>x>>n;		
rep(i,0,n,1){
	cin>>y;
	x-=y;
}

if(x>0){
	ce("No")
}
else
ce("Yes")
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
ll dp[105][100005];
int main(){
    int n;
    cin>>n;
    V<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    ll L;
    cin>>L;
    for(int i=0;i<n;i++){
        int ite=lower_bound(all(a),a[i]+L+1)-a.begin();
        dp[1][i]=ite-1;
    }
    for(int i=1;i<100;i++){
        for(int j=0;j<n;j++){
            dp[i+1][j]=dp[i][dp[i][j]];
        }
    }
    int q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        a--;b--;
        if(a>b)swap(a,b);
        ll l=0,r=(1e5)+10;
        while(r-l>1){
            ll mid=(l+r)/2;
            int now=a;
            ll tmp=mid;
            int cnt=1;
            bool ok=false;
            while(tmp){
                if(tmp&1)now=dp[cnt][now];
                tmp>>=1;
                if(now>=b){
                    ok=true;
                    break;
                }
                cnt++;
            }
            if(ok)r=mid;
            else l=mid;
        }
        cout<<r<<"\n";
    }
}

Measured memory_bytes: 80768
import java.io.*;
import java.math.*;
import java.util.*;





public class Main {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    int N;
    static int max = 200001;
    static int [] dr = {1,-1,0,0};
    static int [] dc={0,0,-1,1};
    static boolean [][] grid;
    static int [] bishopr = {-1,1,-1,1};
    static int [] bishopc = {1,1,-1,-1};
    static long H,W,cnt;
    public static void main(String args[]) throws IOException {
            H =in.nextInt();
            W = in.nextLong();
            if(H==1||W==1){
                out.println(1);
            }else{
                out.println((H*W+1)/2);
            }
        



        out.flush();
        }
       static boolean isValid (int r, int c){
           if(r>=0&&r<H&&c>=0&&c<W){
               return true;
           }
           return false;
       }
        private static void dfs(int r, int c) {
            for(int i=0;i<4;i++){
                int nr = bishopr[i] +r;
                int nc = bishopc[i]+c;
                if(isValid(nr, nc)&&!grid[nr][nc]){
                    cnt++;
                    grid[nr][nc] = true;
                    dfs(nr, nc);
                }
            }
        }

        static boolean isEven(long a) {
            return (a&1)==0;
        }
       static  void swap (int a, int b){

        int temmp = b;
        b=a;
        a = temmp;
        }
    

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	bool flg=false;
	int i,j;
	cin>>n;
	for(i=0;i<26;i++){
		for(j=0;j<16;j++){
			int x=4*i;
			int y=7*j;
			if(i>0&&j>=0||i>=0&&j>0){
				if(n%(x+y)==0){
					flg=true;
				}
			}
		}
	}
	cout<<((flg)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio> 
#define EPS (1e-10)
using namespace std;
class Point{
public:
    double x,y;
    Point(double x=0, double y=0):x(x),y(y){}
    Point operator +(const Point &p){
        return Point(x+p.x,y+p.y);
    }
    Point operator -(const Point &p){
        return Point(x-p.x,y-p.y);
    }
    Point operator *(double k){
        return Point(k*x,k*y);
    }
    Point operator /(double k){
        return Point(x/k,y/k);
    }

    double norm(){
        return x*x+y*y;
    }
    double abs(){
        return sqrt(norm());
    }
};
typedef Point Vector;
double dot(const Vector &v1,const Vector &v2){
    return v1.x*v2.x+v1.y*v2.y;
}
double cross(const Vector &v1,const Vector &v2){
    return v1.x*v2.y-v1.y*v2.x;
}
bool isParallel(const Vector &v1,const Vector &v2){
    if(fabs(cross(v1,v2)-0.0)<EPS)return true;
    return false;
}
bool isOrthogonal(const Vector &v1,const Vector &v2){
    if(fabs(dot(v1,v2)-0.0)<EPS)return true;
    return false;
}
Point projection( Point &p, Point &p1, Point &p2){
    Vector a=p-p1;
    Vector b=p2-p1;
    double r=dot(a,b);
    double pro_abs=r/b.norm();
    Vector res=b*pro_abs;
    return Point(res.x+p1.x,res.y+p1.y);
}
int main()
{
//    int q,p0x,p0y,p1x,p1y,p2x,p2y,p3x,p3y;
//    cin>>q;
//    while(q>0){
//        cin>>p0x>>p0y>>p1x>>p1y>>p2x>>p2y>>p3x>>p3y;
//        Point P0(p0x,p0y);
//        Point P1(p1x,p1y);
//        Point P2(p2x,p2y);
//        Point P3(p3x,p3y);
//        Vector v1=P1-P0;
//        Vector v2=P3-P2;
//        //cout<<'('<<v1.x<<','<<v1.y<<')'<<' ';
//        //cout<<'('<<v2.x<<','<<v2.y<<')'<<' '<<endl;
//        if(isOrthogonal(v1,v2))cout<<1<<endl;
//        else if(isParallel(v1,v2))cout<<2<<endl;
//        else cout<<0<<endl;
//        q--;
//    }
    int p1x,p1y,p2x,p2y,q,x,y;
    cin>>p1x>>p1y>>p2x>>p2y;
    Point p1(p1x,p1y);
    Point p2(p2x,p2y);
    //Vector a=p2-p1;
    cin>>q;
    while(q>0){
        cin>>x>>y;
        Point p(x,y);
        //Vector b=p-p1;
        Point res=projection(p,p1,p2);
        //cout<<res.x<<' '<<res.y<<endl;
        printf("%.8f %.8f\n",res.x,res.y);
        q--;
    }
    return 0;
}


Measured memory_bytes: 3220
#include <stdio.h>

int main(void) {
  int a, b, c;

  scanf("%d%d%d", &a, &b, &c);

  int max = a;
  if (max < b) {
    max = b;
  }
  if (max < c) {
    max = c;
  }

  if (a + b + c - max == max) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
A - Odds of Oddness
https://atcoder.jp/contests/abc142/tasks/abc142_a

"""
import sys


def solve(N):
    odds = sum(1 for n in range(1, N+1) if n % 2)
    return odds / N


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
n = int(input())
l = [[0, 0, 0]]
ans = "No"
for _ in range(n):
    l.append(list(map(int, input().split())))

for i in range(n):
    dt = abs(l[i + 1][0] - l[i][0])
    dx = abs(l[i + 1][1] - l[i][1])
    dy = abs(l[i+1][2]-l[i][2])
    if dt < dx + dy:
        break
    elif dt % 2 != (dx + dy) % 2:
        break
else:
    ans = "Yes"

print(ans)


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

int main(void){
    int n,m;
    cin >> n;
    int ans = 0;
    if(n>=105)ans++;
    if(n>=135)ans++;
    if(n>=165)ans++;
    if(n>=189)ans++;
    if(n>=195)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100010;
char str1[N],ans[N];
int n;
bool check(){
	for(int i=3;i<=n;i++){
		if(ans[i-1]=='W'){
			if(str1[i-1]=='o'){
				if(ans[i-2]=='W')ans[i]='S';
				else ans[i]='W';
			}else{
				if(ans[i-2]=='W')ans[i]='W';
				else ans[i]='S';
			}
		}else{
			if(str1[i-1]=='o'){
				if(ans[i-2]=='W')ans[i]='W';
				else ans[i]='S';
			}else{
				if(ans[i-2]=='W')ans[i]='S';
				else ans[i]='W';
			}
		}
	}
	if(ans[1]=='W'){
		if(str1[1]=='x'&&ans[2]!=ans[n])return false;
		if(str1[1]=='o'&&ans[2]==ans[n])return false;
	}else{
		if(str1[1]=='o'&&ans[2]!=ans[n])return false;
		if(str1[1]=='x'&&ans[2]==ans[n])return false;
	}
	if(ans[n]=='W'){
		if(str1[n]=='x'&&ans[1]!=ans[n-1])return false;
		if(str1[n]=='o'&&ans[1]==ans[n-1])return false;
	}else{
		if(str1[n]=='o'&&ans[1]!=ans[n-1])return false;
		if(str1[n]=='x'&&ans[1]==ans[n-1])return false;
	}
	return true;
}
void print(){
	for(int i=1;i<=n;i++)printf("%c",ans[i]);
}
int main(){
	scanf("%d",&n);scanf("%s",str1+1);
	ans[1]='S';
	ans[2]='S';if(check()){print();return 0;}
	ans[2]='W';if(check()){print();return 0;}
	ans[1]='W';
	ans[2]='S';if(check()){print();return 0;}
	ans[2]='W';if(check()){print();return 0;}
	printf("-1");
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    int a,b,c;

    cin >> n;

    for(int i=0; i<n;++i ){
        cin >> a >> b >> c;
        if(a < b){
            swap(a,b);
        }
        if(a < c){
            swap(a,c);
        }

        if((a*a) != (b*b + c*c)){
            cout << "NO" << endl;
        }
        else{
            cout << "YES" << endl;
        }
    }

    return 0;
}

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

using namespace std;

#define ll long long

int main()
{

    ll a,n,s=0;
    cin >> a >> n;
    while(n--)
    {
        ll b;
        cin >> b;
        s+=b;
    }
    if(s>=a)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

#include <bits/stdc++.h>
#define rep(i,a,n) for(ll i = a;i < n;i++)
typedef long long ll;
using namespace std;


bool is_banned[10];
bool check(ll n){
    string t = "";
    while(n){
        if(is_banned[n % 10]) return false;
        n /= 10;
    }

    return true;
}

int main(){
    ll n,k;
    cin >> n >> k;

    rep(i,0,k){
        ll d;
        cin >> d;
        is_banned[d] = true;
    }

    ll ans = n;
    while(1){
        if(check(ans)) break;
        ans++;
    }

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


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

int N ,A[200];

int main(){
  int dmin = 100;
  cin >> N ;
  for(int i=0; i<N; i++){
    int A;
    cin >> A;
    int d=0;
    while(A%2==0){
      A /= 2;
      d++;
    }
    dmin = min(dmin, d);
  }
  cout << dmin;
}

Measured memory_bytes: 256
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

transportations = [A, B, C, D, E]
minCap = min(transportations)
minIdx = transportations.index(minCap)
transportations.pop(minIdx)

time = N // minCap
if N % minCap != 0:
	time += 1
	
time += 4

print(time)
	


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

typedef long long ll;
using namespace std;

int main() {
  ll x,y;
  cin >> x >> y;
  ll count = 0;
  ll a = x;
  for(;a <= y;){
    count++;
    a *= 2;
  }
  printf("%lld\n",count);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long n,a,b;
  cin >> n >> a >>b;
long long ans=n / (a+b);
  ans *=a;
  long long r= n % (a+b);
 
  ans += min(r,a);
  cout << ans <<endl;
}
  


Measured memory_bytes: 3644
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<bool> v(n);
	ll d,x;
	rep(i,0,k) {
		cin>>d;
		rep(j,0,d) {
			cin>>x;
			x--;
			v[x]=1;
		}
	}
	int ans=0;
	rep(i,0,n) {
		if(!v[i]) ans++;
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

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


int main(){

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


    sort( a, a+n );
    int half[2], dif[2];

    for( int i = 0; i < n; i++ ){
        if( a[i] <= a[n-1]/2 ){
            half[0] = a[i];
            dif[0] = a[n-1]/2 - half[0];
        }else{
            half[1] = a[i];
            dif[1] = half[1] - a[n-1]/2;
            break;
        }
    }
    
    if( a[n-1] % 2 == 0 ){
        if( dif[0] <= dif[1] ) cout << a[n-1] << " " << half[0] << endl;
        else cout << a[n-1] << " " << half[1] << endl;
    }else{
        if( dif[0] < dif[1] ) cout << a[n-1] << " " << half[0] << endl;
        else cout << a[n-1] << " " << half[1] << endl;
    }

    return 0;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using ll = long long;
const ll INF_LL = 1000000000000;
#define fir first
#define sec second

int main()
{
    int n,m;
    std::cin >> n >> m;
    std::vector<std::vector<ll>> A(3,std::vector<ll>(n));
    for(int i = 0; i < n; i++)std::cin >> A[0][i] >> A[1][i] >> A[2][i];

    ll max = -1;
    for(int bit = 0; bit < (1 << 3); bit++){
        auto a = A;
        for(int i = 0; i < 3; i++){
            if(bit & (1 << i)){
                for(int j = 0; j < n; j++)a[i][j] *= -1;
            }
        }
        std::vector<ll> sum(n);
        for(int i = 0; i < n; i++)sum[i] = a[0][i] + a[1][i] + a[2][i];
        std::sort(sum.begin(), sum.end(), std::greater<ll>());
        ll cur = 0;
        for(int i = 0; i < m; i++){
            cur += sum[i];
        }
        max = std::max(cur,max);
    }
    std::cout << max << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int  main(){
    int n,s=0;
    cin >> n;
    int t = n;
    while(t > 0){
        s += t%10;
        t /= 10;
    }
    if(n%s == 0)
        cout <<"Yes";
    else
        cout <<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long LL;
int main()
{
    int a[100],b=0,c=0,i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {scanf("%d",&a[i]);
    b=b+a[i];
}
b=b*1.0/n+0.5;
for(i=0;i<n;i++){
    c=c+(a[i]-b)*(a[i]-b);
}
printf("%d",c);}


Measured memory_bytes: 128
N, M ,C = [int(v) for v in input().split()]
b = [int(v) for v in input().split()]

ans = 0
for i in range(N):
    a = [int(v) for v in input().split()]
    sumv = C
    for j in range(M):
        sumv += a[j] * b[j]
    if sumv > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#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 INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int a[N]; rep(i,N) { cin >> a[i]; a[i]--; }

  int result = 0;
  rep(i,N) if (a[a[i]]==i) result++;
  result /= 2;

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 640
n = gets.to_i
as = gets.split.map &:to_i
money = 1000
stocks = 0
prev = 10000
(0..n-2).each do |i|
  price, forecast = as[i], as[i+1]
  if price < forecast
    x = money / price
    stocks += x
    money -= x * price
  elsif price > forecast
    money += price * stocks
    stocks = 0
  end
end
money += as[-1] * stocks
stocks = 0

p money

Measured memory_bytes: 14288
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int need_g[100001] = { 0 };

int main()
{
	string s;
	int cnt = 0, my_g = 0, point = 0;

	cin >> s;

	rrep(i, s.size()) {
		if (s[i] == 'g') need_g[i] = max(0, need_g[i + 1] - 1);
		else need_g[i] = need_g[i + 1] + 1;
	}
	rep(i, s.size()) need_g[i] = need_g[i + 1];

	rep(i, s.size()) {
		if (my_g == 0) {
			if (s[i] == 'p') point--;
			my_g++;
		}
		else if (s[i] == 'p') {
			if (my_g > 0) my_g--;
			else {
				point--;
				my_g++;
			}
		}
		else if (need_g[i] < my_g) {
			my_g--;
			point++;
		}
		else my_g++;
	}

	cout << point << endl;

	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include<string>
#include<cstring>
#include<complex>
#include<cmath>
using namespace std;
#define rep(i, n)   for(int i = 0; i < (int)(n); i++)
#define rrp(i, n)   for(int i = ((int)(n)); i >=0; i--)
#define mpp(i,j,k)  make_pair((int)(i),make_pair((int)(j),(int)(k)))
typedef pair<int,pair<int,int > > pp;
typedef vector<int> vi;
typedef vector<vi>  vvi;
int n,a,b;
vector<long long> c(50,0);
long double ma;
long long ps[51][51];
int pas(int n){
   rep(i,n){ps[i][0]=ps[i][i]=1;
   rep(j,i)if(j>0&&i>1)ps[i][j]=ps[i-1][j-1]+ps[i-1][j];
   }
}


int main(){
pas(51);
cin>>n>>a>>b;
rep(i,n)cin>>c[i];
sort(c.begin(),c.end(),greater<long int>());
ma=0.0;
long double am=0.0;
rep(i,a)am+=c[i];
am/=a;
int x=0;
int y=0;
rep(i,n){if(c[i]==c[a-1]){x+=1;if(i<a){y+=1;}}}
cout.precision(20);
cout<<fixed<<am<<endl;
long long z=0LL;
if(c[a-1]==c[0]){rep(i,n){if((i>=a-1)&&(i<b)&&(c[a-1]==c[i])){z+=ps[x][i+1];}}cout<<z<<endl;}
else{cout<<ps[x][y]<<endl;}
  return 0;}




Measured memory_bytes: 256
# p (0..6).to_a.map{|j| [6 ** j, 9 ** j] }.flatten.uniq.sort
a = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049, 531441]
 
m, dp = gets.to_s.to_i, [0]
(1..m).each {|i|
  t = 987654321
  idx = (a.bsearch_index{|j| i < j } || a.size ) - 1
  (a[0..idx]).map{|j| i - j }.each{|c| t = dp[c] if t > dp[c] }
  dp.push(t + 1)
}
puts dp[-1]

Measured memory_bytes: 2812
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, A, B = mi()
    if (B-A)%2==0:
        print((B-A)//2)
    else:
        print(min(A+(B-A-1)//2, N-B+1+(B-A-1)//2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 79832
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>a(n + 3), b(n + 3), c(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    int dp[n + 3][4];
    dp[1][0] = a[1], dp[1][1] = b[1], dp[1][2] = c[1];
    for(int i = 2; i <= n; i++){
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    int mx = max(dp[n][0], dp[n][1]);
    mx = max(mx, dp[n][2]);
    cout << mx;
    return 0;
}

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

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

    int n, d;
    cin >> n >> d;

    int a = d * 2 + 1;
    cout << (n + a - 1) / a << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int a,b,ans,mx=0;
	cin>>a>>b;
	ans=max(a+b,a-b);
	ans=max(ans,a*b);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
ll N,A,B;
vector<ll>h(100005);
bool isOK(ll mid){
	ll ret=0;
	for(int i=0;i<N;i++){
		if(h[i]-mid*B>0){
			ret+=(h[i]-mid*B+(A-B)-1)/(A-B);
		}
	}
	return ret<=mid;
}


int main(){
	init();
	ll N;cin>>N;
	vector<ll>A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
		A[i]--;
	}
	vector<bool>lightup(N,false);
	
	lightup[0]=true;
	ll u=0;
	ll count=0;
	while(1){
		ll next=A[u];
		count++;
		if(next==1){
			cout<<count<<endl;
			return 0;
		}
		if(lightup[next])break;
		lightup[next]=true;
		u=next;
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
    int A,P;
    cin >> A >> P;
    cout << (A*3+P)/2 << endl;

    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  string s; cin >> s;
  int n = s.size();
  vector<int> a;
  map<int, bool> mp;
  for(int i=0;i<n;++i) {
    if(s[i] == '1') {
      a.push_back(i+1);
      mp[i+1] = true;
    }
  }
  int sz = a.size();
  if(!mp[1] || mp[n]) {
    cout << "-1" << endl;
    return 0;
  }
  for(int i=0;i<sz;++i) {
    if(!mp[n - a[i]]) {
      cout << "-1" << endl;
      return 0;
    }
  }
  vector<int> tmp;
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  tmp.push_back(1);
  int now = 1;
  for(int i=0;i<sz;++i) {
    int next = n - a[i] + 1;
    if(now >= next) break;
    tmp.push_back(next);
    now = next;
  }
  vector<P> ans;
  for(int i=0;i<(int)(tmp.size())-1;++i) {
    for(int j=tmp[i]+1;j<=tmp[i+1];++j) {
      ans.push_back({tmp[i], j});
    }
  }
  for(int i=0;i<(int)(ans.size());++i) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}


Measured memory_bytes: 7924
#include <bits/stdc++.h>
	#define endl '\n'
	using namespace std;
	int n;
	void INP()
	{
		cin >> n;
	}
	void SOLVE()
	{
	    if(n>=30) cout << "Yes";
	    else cout << "No";
	    return;
	}
	int main()
	{
	   ios_base::sync_with_stdio(false);
	   cin.tie(0);
	   cout.tie(0);
	   INP();
	   SOLVE();
	   return 0;
	}


Measured memory_bytes: 3636
#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 <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 2140000000000000LL
#define MOD 1000000007

int main() {
	long long x, y, z, k;

	cin >> x >> y >> z >> k;

	vector<long long > a(x);
	vector<long long > b(y);
	vector<long long > c(z);
	vector<long long > ab(x * y);

	for (int i = 0; i < x; ++i) {
		cin >> a[i];
	}

	for (int i = 0; i < y; ++i) {
		cin >> b[i];
	}

	for (int i = 0; i < z; ++i) {
		cin >> c[i];
	}

	long long m = 0;

	for (int i = 0; i < x; ++i) {
		for (int j = 0; j < y; ++j) {
			ab[m] = a[i] + b[j];
			m++;
		}
	}

	sort(ab.begin(), ab.end());

	vector<long long > ind(z);

	for (int i = 0; i < z; ++i) {
		ind[i] = ab.size() - 1;
	}

	while (k--) {
		long long maxx = -INF, maxxind = -1;

		for (int i = 0; i < z; ++i) {
			if (ind[i] >= 0) {
				if (c[i] + ab[ind[i]] > maxx) {
					maxx = c[i] + ab[ind[i]];
					maxxind = i;
				}
			}
		}

		cout << maxx << endl;
		ind[maxxind]--;
	}

	return 0;
}

Measured memory_bytes: 8064
h, w, k = map(int, raw_input().split())
arr = [1, 2, 3, 5, 8, 13, 21, 34]


def p(num):
    return max(0, num)

r = [[0 for i in range(w)] for i in range(h+1)]
for i in range(h+1):
    for j in range(w):

        if i == 0:
            if j == 0:
                r[i][j] = 1
            else:
                r[i][j] = 0
        else:
            y = r[i - 1][j]
            if j - 1 < 0:
                x = 0
            else:
                x = r[i - 1][j - 1]
            if j + 1 > w - 1:
                z = 0
            else:
                z = r[i - 1][j + 1]
            r[i][j] = (x * arr[p(j-2)] * arr[p(w-j-2)] + \
                y * arr[p(j-1)] * arr[p(w-j-2)] + \
                z * arr[p(j-1)] * arr[p(w-j-3)]) % (10**9+7)
    

print r[h][k-1]

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
#define pii             pair <int, int>
#define ff              first
#define ss              second
#define eps             1e-10
#define LL              long long
#define pb              push_back
#define mk              make_pair
#define inf             0x3f3f3f3f
#define vi              vector <int>
#define all(a)          a.begin(), a.end()
#define Unique(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define Iterator(a)     __typeof__(a.begin())
#define rIterator(a)    __typeof__(a.rbegin())
#define FOR(a,it)       for(Iterator(a) it = a.begin();it != a.end(); it++)
#define rFOR(a,it)      for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define MAX             256
#define ULL             unsigned long long

const int N = 2000006;
const int MOD = 1e9 + 7;

ULL L[100];

int main()
{
    L[0] = 2;
    L[1] = 1;
    for(int i = 2; i <= 100; i++) L[i] = L[i - 1] + L[i - 2];
    int n; cin >> n;
    cout << L[n] << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define Max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
int dp[1005][1005],w[1005],v[1005];
int main(){
	int i,j,n,m,wl;
	n=1;
	while(1){
		scanf("%d",&wl);
		if(wl==0)break;
		scanf("%d",&m);
		for(i=1;i<=m;i++)scanf("%d,%d",&v[i],&w[i]);
		memset(dp,0,sizeof(dp));
		for(i=1;i<=m;i++){
			for(j=0;j<=wl;j++){
				if(j>=w[i]){
					dp[i][j]=Max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
				}else{
					dp[i][j]=dp[i-1][j];
				}
			}
		}
		j=wl;
		for(i=0;i<=wl;i++)if(dp[m][wl]==dp[m][i])j=min(j,i);
		printf("Case %d:\n",n++);
		printf("%d\n%d\n",dp[m][wl],j);
	}
	
	return 0;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()

sum = 0
cnt = 0
for ab in AB:
    a,b = ab[0], ab[1]
    if cnt + b < M:
        sum += a * b
        cnt += b
    else:
        sum += a * (M-cnt)
        break
print(sum)


Measured memory_bytes: 27880
#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    S = input()
    
    if 'RRR' in S:
        print(3)
    elif 'RR' in S:
        print(2)
    elif 'R' in S:
        print(1)
    else:
        print(0)
main()


Measured memory_bytes: 9084
from bisect import bisect_left

s = input()
n = len(s)

p = []
st = set()
for i, (sl, sr) in enumerate(zip(s, s[1:])):
    if sl == 'R' and sr == 'L':
        st.add(i)
        st.add(i + 1)
        p.append(i)

ans = [0] * n
for i, ss in enumerate(s):
    if i in st:
        ans[i] += 1
    else:
        idx = bisect_left(p, i)
        if ss == 'R':
            # p[idx]まで移動して、その後ループ
            loop_start_pos = p[idx]
            if (loop_start_pos - i) % 2 == 0:
                ans[loop_start_pos] += 1
            else:
                ans[loop_start_pos + 1] += 1
        else:
            # p[idx-1]まで移動して、その後ループ
            loop_start_pos = p[idx - 1]
            if (i - loop_start_pos) % 2 == 0:
                ans[loop_start_pos] += 1
            else:
                ans[loop_start_pos + 1] += 1

print(*ans)


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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int main(){
	int N;
	cin >> N;
	int W[N];
	int sum=0;
	int s1[N];
	int ans = 100000000;

	rep(i,N) {
		cin >> W[i];
		sum+=W[i];
		s1[i]=sum;
	}

	rep(t,N){
		ans=min(ans,(abs(sum-2*s1[t])));
	}
	cout << ans;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main(){
	var num_string string
	var num int
	fmt.Scan(&num_string)
	num_string = strings.TrimLeft(num_string,"0")
	num,_ = strconv.Atoi(num_string)
	first := num/1000
	second := (num/100)%10
	third := (num/10)%10
	forth := num%10
	if(first+second+third+forth==7){
		fmt.Printf("%d+%d+%d+%d=7",first,second,third,forth)
	}else if first+second+third-forth==7 {
		fmt.Printf("%d+%d+%d-%d=7",first,second,third,forth)
	}else if first+second-third+forth==7{
		fmt.Printf("%d+%d-%d+%d=7",first,second,third,forth)
	}else if first+second-third-forth==7{
		fmt.Printf("%d+%d-%d-%d=7",first,second,third,forth)
	}else if first-second+third+forth==7{
		fmt.Printf("%d-%d+%d+%d=7",first,second,third,forth)
	}else if first-second+third-forth==7{
		fmt.Printf("%d-%d+%d-%d=7",first,second,third,forth)
	}else if first-second-third+forth==7{
		fmt.Printf("%d-%d-%d+%d=7",first,second,third,forth)
	}else if first-second-third-forth==7{
		fmt.Printf("%d-%d-%d-%d=7",first,second,third,forth)
	}
}

Measured memory_bytes: 640
a,b,c,d=map(int,input().split())
mod=998244353
dp=[(d+1)*[0]for _ in range(c+1)]
for i in range(a,c+1):
  for j in range(b,d+1):
    if i==a and j==b:
      dp[i][j]=1
      continue
    if i==a:
      dp[i][j]=dp[i][j-1]*i%mod
      continue
    if j==b:
      dp[i][j]=dp[i-1][j]*j%mod
      continue
    dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1))%mod
print(dp[c][d])


Measured memory_bytes: 133928
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String name;
		int num;
		int compare;
		String waku="";
		String waku2="";

		int[] a=new int[2];
		int i=0;
		while(true){

			try{
				name=br.readLine();
				StringTokenizer st=new StringTokenizer(name," ");
				while (st.hasMoreTokens()) {
					a[i]=Integer.parseInt(st.nextToken());
					i++;
				}i=0;

				if(a[0]==0 && a[1]==0){
					System.exit(0);
				}

				else{
					for(int k=0; k<a[1]; k++){
						if(k%2==0){
							waku=waku+"#";
							waku2=waku2+".";
						}
						if(k%2==1){
							waku=waku+".";
							waku2=waku2+"#";
						}
					}

					for(int j=0; j<a[0]; j++){
						if(j%2==0)System.out.println(waku);
						if(j%2==1)System.out.println(waku2);
					}
					System.out.println("");
					waku="";
					waku2="";
				}
			}

			catch(Exception e){
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 25508
#include <bits/stdc++.h>
#define int long long 
using namespace std;
using Graph = vector<vector<int>>;

signed main(){
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> P(A);
  for( int i = 0; i < A; i++ ) cin >> P.at(i);
  vector<int> Q(B);
  for( int i = 0; i < B; i++ ) cin >> Q.at(i);
  vector<int> R(C);
  for( int i = 0; i < C; i++ ) cin >> R.at(i);
  sort(P.rbegin(), P.rend());
  sort(Q.rbegin(), Q.rend());
  
  for( int i = 0; i < X; i++ ) R.push_back(P.at(i));
  for( int i = 0; i < Y; i++ ) R.push_back(Q.at(i));
  sort(R.rbegin(), R.rend());
  int ans = 0;
  for( int i = 0; i < X+Y; i++ ) ans += R.at(i);
  cout << ans << endl;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int[] prices = { a, b, c };
        Arrays.sort(prices);

        System.out.println(prices[0] + prices[1]);
    }
}


Measured memory_bytes: 21716
/*連鎖行列積*/
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define INF 1000000000

int min(int,int);

int main(){
  int n, i, j, l, k;
  int left[N], right[N];
  int m[N][N];
  
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    for(j = 0; j < n; j++)
      m[i][j] = INF;
  
  for(i = 0; i < n; i++){
    scanf("%d%d", left + i, right + i);
    m[i][i] = 0;
  }
  
  for(l = 1; l < n; l++){
    for(i = 0; i < n - l; i++){
      j = i + l;
      for(k = i; k < j; k++){
	m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + left[i] * right[k] * right[j]);
      }
    }
  }
  
  printf("%d\n", m[0][n - 1]);
  
  return 0;
}

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



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

int main(){
  string S;
  cin >> S;

  for(int i=0;i<S.size();i++){
    if(S.at(i)=='C'){
      for(;i<S.size();i++){
        if(S.at(i)=='F'){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())

def factorization(n):
    d = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            d[i] = cnt

    if temp!=1:
        d[temp] = 1

    if d.keys()==[]:
        d[n] = 1

    return d

def get_a(n):
    N = n
    if n == 1:
        return [1]
    elif n==2:
        return [2]
    else:
        a = [1]

    while 1:
        n_temp = n - a[-1]
        #print(n_temp, a)
        if n_temp<0:
            a.pop()
            a[-1] = N - sum(a[:-1])
            break
        elif n_temp == 0:
            break
        else:
            n = n_temp
        a.append(a[-1]+1)
    #print(n_temp, a)
    return a

ans = 0
fact_dict = factorization(n)
#print(fact_dict)

for key, val in fact_dict.items():
    #print(key, val, get_a(val))
    ans += len(get_a(val))

if ans>0:
    print(ans)
else:
    print(0)


Measured memory_bytes: 9508
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a+b+2-1)/2 << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
if __name__ == '__main__':
    h, w, n = [int(x) for x in input().split()]
    coords = []
    count = defaultdict(int)
    ans = [0 for x in range(10)]
    ans[0] = (h-2) * (w-2)
    adjacent = [(-1, 1), (0, 1), (1, 1), (-1, 0), (0, 0), (1, 0), (-1, -1), (0, -1), (1, -1)]
    for i in range(n):
        y, x = [int(v) for v in input().split()]
        coords.append((x,y))
    for x,y in coords:
        for dx, dy in adjacent:
            new_x = x + dx
            new_y = y + dy
            if 2 <= new_x <= w-1 and 2 <= new_y <= h-1:
                count[(new_x, new_y)] += 1
    for i in count.values():
        ans[i] += 1
        ans[0] -= 1

    for a in ans:
        print(a)

Measured memory_bytes: 180460
#include<iostream>
#include<string>
#include<algorithm>
#include<cassert>
#define rep(i, n) for ( int i = 0; i < (int)n; i++)
using namespace std;

int state[10];

bool valid2(int pos){
  if (pos == 4 ) return true;

  for ( int i = 1; i <= 9; i++){
    if ( state[i] >= 3 ){
      state[i] -= 3;
      if ( valid2(pos+1) ) return true;
      state[i] += 3;
    }
    if ( i >= 8 ) continue;
    if ( state[i] > 0 && state[i+1]> 0 && state[i+2]> 0 ){
      state[i]--;
      state[i+1]--;
      state[i+2]--;
      if ( valid2(pos+1) ) return true;
      state[i]++;
      state[i+1]++;
      state[i+2]++;
    }
  }
  return false;
}

bool valid(string str){
  sort(str.begin(), str.end());

  int cnt[10];
  for ( int i = 1; i <= 9; i++ ) cnt[i] = 0;
  for ( int i = 0; i < str.size(); i++ ) cnt[str[i]-'0']++;
  for ( int i = 1; i <= 9; i++ ) if (cnt[i] > 4) return false;

  for ( int i = 0; i < str.size()-1; i++ ){
    if ( str[i] == str[i+1] ){
      rep(p, 10) state[p] = 0;
      rep(j, str.size()){
	if ( j == i || j == i+1 ) continue;
	state[str[j]-'0']++;
      }
      if ( valid2(0))	return true;

    }
  }
  return false;
}

main(){
  string number;
  while( cin >> number){
    bool f = true;
    for ( char a = '1'; a <= '9'; a++ ){
      if ( valid(number + a) ){
	if ( !f ) cout << " ";
	cout << a;
	f = false;
      }
    }
    if ( f ) cout << "0" << endl;
    else cout << endl;
  }
}

Measured memory_bytes: 0
s[50],j,p,q;
main(i){for(;j=i=atoi(gets(s));printf("%d\n",i)){
for(;i;s[j-i--]=strlen(gets(s+j)));
for(;q>0||j&&(p=i++,j=117933);j/=9)for(q=j%9;q>1;)q-=s[p++];
}}

Measured memory_bytes: 532
import sys

x = input()
d = {}
result = 0

for line in sys.stdin:
    n, = line.strip().split(" ")
    n = int(n)
    if n-1 in d:
        d[n] = d[n-1] + 1
    else:
        d[n] = 1
    result = max(d[n], result)

print(int(x) - result)


Measured memory_bytes: 32648
#include<stdio.h>
int main(void)
{
	int h,r,sum;
	scanf("%d %d",&h,&r);
	sum=0;
	sum=h+r;
	if(sum==0){
		printf("0\n");
	}
	else if(sum<0){
		printf("-1\n");
	}
	else{
		printf("1\n");
	}
	return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, m;
int ok[105] = {0};
vector<int> l, a;
vector<int> ans;

void solve();

int main() {
  cin >> n >> m;
  l.resize(m);
  a.resize(m);
  ans.assign(n + 1, 0);
  for(int i = 0; i < m; ++i) cin >> a[i] >> l[i];
  solve();
  for(int i = n; i > 0; --i)
    if(ans[i] > 0) cout << i << " " << ans[i] << endl;
  return 0;
}

void solve() {
  int num = -1;
  for(int i = 0; i < m; ++i)
    for(int j = 0; j < l[i]; ++j) ++ok[(a[i] + j) % n];
  for(int i = 0; i < n; ++i)
    if(ok[i] == 0) {
      num = i;
      break;
    }
  if(num == -1) {
    ans[n] = 1;
    return;
  }
  for(int i = num + 1; i <= num + n; ++i) {
    int now = i, cnt = 0;
    while(ok[now % n] > 0 && now <= (num + n)) {
      ++cnt;
      ++now;
    }
    ++ans[cnt];
    i = now;
  }
}


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

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
  	cin >> n;
  	cout << (n * n * n);
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: usize,
        a: [i64;n],
        q: usize,
        bc: [(i64, i64);q],
    }

    let mut hm: HashMap<i64, i64> = HashMap::new();
    let mut sum = 0;
    for i in a {
        sum += i;
        *hm.entry(i).or_insert(0) += 1;
    }

    for (b, c) in bc {
        if let Some(&count) = hm.get(&b) {
            sum = sum + (c - b) * count;
            *hm.entry(c).or_insert(0) += count;
            hm.insert(b, 0);
        }

        println!("{}", sum);
    }
}


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

int a[1000123];

int n;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    int mx = -1;
    int mn = 10000000000;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }
    if(2 <= mx - mn){
        cout << "No";
        return 0;
    }
    if(mx == mn){
        bool cnt1 = 1, cnt2 = 1;
        for(int i = 1; i <= n; i++){
            if(2 * a[i] > n){
                cnt1 = 0;
            }
            if(n - 1 != a[i]){
                cnt2 = 0;
            }
        }
        if(cnt1 == 0 && cnt2 == 0){
            cout << "No";
            return 0;
        }
        cout << "Yes";
        return 0;
    }
    int x = 0;
    int y = 0;
    for(int i = 1; i <= n; i++){
        if(a[i] == mn){
            x++;
        }
        else{
            y++;
        }
    }
    if(x + 1 <= mx && mx <= x + y / 2){
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 640