akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';

int kaijou(int i){
  if(i==0)return 0;
  return i == 1 ?  1 : i * kaijou(i - 1);
}
int nanbanme(vector<int> P){
  int ban = 0;
  vector<int> temp;
  for(int i=0;i<P.size();i++){
    temp.push_back(i + 1);
  }
  for(int i=0;i<P.size();i++){
    int num;
    for(int j=temp.size()-1;j>=0;j--){
      if(temp[j] == P[i]){
        num = j;
        temp.erase(temp.begin() + j);
        break;
      }
    }
    int ans = num*kaijou(temp.size()-1-i);
    ban += num*kaijou(P.size()-i-1);
  }
  return ban+1;
}

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

  int N = input();

  vector<int> P;
  for(int i=0;i<N;i++){
    int p = input();
    P.push_back(p);
  }

  vector<int> Q;
  for(int i=0;i<N;i++){
    int q = input();
    Q.push_back(q);
  }

  output(abs(nanbanme(P) - nanbanme(Q)));

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

  VAR(int, N, K);
  
  int ans = 0;
  FOR(i, 1, N + 1) {
    int a = (K + i) % K;
    if (((K - a) * 2 + K) % K == 0) {
      ans += ((N + a) / K) * ((N + a) / K);
    }
  }

  OUT(ans)BR;
  return 0;
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<ll, ll>
#define sz size()

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args)
{const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" , ";__f(comma+1, args...);} 
#define traceloop(x,a) { cerr<<#a<<": "; for(ll ix=0;ix<x;ix++) cerr<<a[ix]<<" "; cerr<<endl; }

int main()
{
	ios::sync_with_stdio(0);
	int i, n, j, k;
	cin>>n;
	int a[n+5][3];
	int dp[n+5][3][2];

	for(i=0;i<n+4;++i)
		for(j=0;j<3;++j)
			dp[i][j][0] = dp[i][j][1] = -1;
	memset(a, 0, sizeof a);

	for(i=2;i<n+2;++i)
		cin>>a[i][0]>>a[i][1]>>a[i][2];

	for(j=0;j<3;++j)
		dp[1][j][0] = dp[1][j][1] = 0;

	for(i=2;i<n+2;++i)
	{
		for(j=0;j<3;++j)
		{
			for(k=0;k<3;++k)
			{
				if(k == j)
				{
					dp[i][j][1] = max(dp[i][j][1], dp[i-1][k][0] + a[i][j]);
				}
				else
				{
					dp[i][j][1] = max(dp[i][j][1], dp[i-1][k][1] + a[i][j]);
					//dp[i][j][1] = min(dp[i][j][1], dp[i-1][k][0] + a[i][j]);
				}
			}
		}

		for(j=0;j<3;++j)
		{
			for(k=0;k<3;++k)
			{
				if(k != j)
					dp[i][j][0] = max(dp[i][j][0], dp[i][k][1]);
			}
			//trace(i, dp[i][j][0], dp[i][j][1]);
		}

	}

	cout << max(max(dp[n+1][0][1], dp[n+1][1][1]), dp[n+1][2][1])<<"\n";

	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

ll attack(ll x){
  if(x==1) return 1;
  return 1+2*attack(x/2);
}

int main(){
  ll n;
  cin >> n;
  cout << attack(n) << endl;
}

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

int main(){
    int n;
    cin >> n;
    for(int i=1;i;i++){
        if(n==4 || n==2 || n==1){
            cout << i+3 << endl;
            return 0;
        }

        if(n % 2 == 0){
            n /= 2;
        }else{
            n = (3 * n) + 1;
        }
    }
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

pub fn main() {
    loop {
        let v: Vec<i32> = read_vec();
        let (n, x) = (v[0], v[1]);
        if let (0, 0) = (n, x) {
            break;
        }
        let mut cnt = 0;
        for i in 1..n+1 {
            for j in i+1..n+1 {
                for k in j+1..n+1 {
                    if i + j + k == x {
                        cnt += 1;
                    }
                }
            }
        }
        println!("{}", cnt);
    }
}



Measured memory_bytes: 5028
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };

signed main() {
	string s; cin >> s;
	int ans1 = 0, ans2 = 0;
	rep(i, s.size()) {
		if (s[i] == '0' && (i & 1))ans1++;
		if (s[i] == '0' && !(i & 1))ans2++;
		if (s[i] == '1' && (i & 1))ans2++;
		if (s[i] == '1' && !(i & 1))ans1++;
	}
	cout << min(ans2, ans1) << endl;
}	


Measured memory_bytes: 512
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int,int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for(int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for(int i = L; i != (int)R; --i)
#define IOS cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int cnt = 0;
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    FOR(i, 0, 3)
    {
        FOR(j, i + 1, 3)
        {
            if(v[i] == v[j])
            {
                ++cnt;
            }
        }
    }
    if(cnt == 1)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<string> S(N);
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i] >> A[i];
	}
	string X;
	cin >> X;
	int res = 0;
	bool nemuri = false;
	for (int i = 0; i < N; i++) {
		if (nemuri) {
			res += A[i];
		}
		if (X == S[i]) {
			nemuri = true;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include "iostream"
using namespace std;

int main()
{
	int count[4][3][10] = { 0 };

	int ken;//件数

	cin >> ken;

	int tou, kai, gou, nin;

	for (int i = 0; i < ken; i++){//インプット

		cin >> tou >> kai >> gou >> nin;
		//tou--;
		//kai--;
		//gou--;
		count[tou - 1][kai - 1][gou - 1] += nin;
	}

	//アウトプット
	for (int i = 0; i < 4; i++){//棟
		for (int j = 0; j < 3; j++){//階
			for (int k = 0; k < 10; k++){//号
				cout << " ";
				cout << count[i][j][k];
			}
			cout << endl;
		}
		if (i <= 2){
			cout << "####################"
				<< endl;
		}
		if (i == 3){
			//cout << endl;
		}
	}
	return 0;
}



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

int main()
{
  int T,N;
  while(cin >> T,T)
    {
      vector<int> t(T+1);
      for(int i=0;i<T;i++)
	cin >> t[i];
      cin >> N;

      vector<int> D(101);
      for(int i=0;i<101;i++)
	D[i] = (1<<29);

      int mexday = 0;
      for(int i=0;i<N;i++)
	{
	  int d,m;
	  cin >> d >> m;
	  D[d] = min(D[d],m);
	  mexday = max(mexday,d);
	}
      //cout << "mexday = " << mexday << endl;
      int dayMin[mexday+1];
      int dp[T][mexday+1];
      for(int i=0;i<T;i++)
	for(int j=0;j<=mexday;j++)
	  dp[i][j] = dayMin[j] = (1<<29);

      dp[0][1] = 0;
      dayMin[1] = dp[0][1];

      for(int i=2;i<=mexday;i++)
	{
	  for(int j=0;j<min(i+1,T);j++)
	    {
	      if(!j)
		{
		  dp[j][i] = min(dp[j][i],dayMin[i-1]+1); 
		  dp[j][i] = min(dp[j][i],dp[T-1][i-1]+(D[i]>=t[j]?0:1));
		  dayMin[i] = min(dp[j][i],dayMin[i]);
		  continue;
		}
	      if(dp[j-1][i-1] == (1<<29))
		continue;
	      //dp[j][i] = min(dp[j][i],dp[j-1][i-1]+(D[i]>=t[j]?0:1));
	      if(D[i]>=t[j])
		dp[j][i] = min(dp[j][i],dp[j-1][i-1]);
	      else
		dp[0][i] = min(dp[0][i],dp[j][i]+1);
	      dayMin[i] = min(dp[j][i],dayMin[i]);	    
	    }
	}
      /*
      cout << "dayMin = " << endl;
      for(int i=1;i<=mexday;i++)
	cout << dayMin[i] << " ";
      cout << endl << endl;

	  for(int j=0;j<T;j++)      
	    {
	      for(int i=1;i<=mexday;i++)
		cout << dp[j][i] << " ";
	      cout << endl;
	}
      */
      int ans = (1<<29);
      for(int i=0;i<T;i++)
	ans = min(ans,dp[i][mexday]);
      assert(ans != (1<<29));
      cout << ans << endl;
    }
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>

using namespace std;

const int Z = 1e6+3;

int fp(int a, int x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return 1ll * a * fp(a, x - 1) % Z;
    }
    int t = fp(a, x / 2);
    return 1ll * t * t % Z;
}

int inv(int a) {
    return fp(a, Z - 2);
}

int main() {
    int fac[Z];
    fac[0] = 1;
    for (int i = 1; i < Z; i++) {
        fac[i] = 1ll * fac[i-1] * i % Z;
    }

    int q;
    cin >> q;

    while (q--) {
        int x, d, n;
        cin >> x >> d >> n;

        int ans;
        if (d == 0) {
            ans = fp(x, n);
        } else {
            int k = 1ll * (Z - x) * inv(d) % Z;
            ans = k < n ? 0 : 1ll * fp(d, n) * fac[Z-k+n-1] % Z * inv(fac[Z-k-1]) % Z;
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4736
########10進法からn進法への変換関数部分##############
def format(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
############################
########10進法からn進法への変換関数(m桁埋める)部分##############
def format0(X, n, m):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    if len(out) < m:
        out = "0" * (m - len(out)) + out
    return out
############################
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for i in range(n)]
mo=10000000000000
import numpy
for i in range(1,pow(2,n)):
  i=format0(i,2,n)
  money=0
  aaa=[0]*m
  aaa=numpy.array(aaa)
  for j in range(n):
    if i[j]=="1":
      money+=ca[j][0]
      aaa = aaa + numpy.array(ca[j][1:])
  if aaa.min()>=x:
    mo=min(mo,money)
  else:
    if i=="1"*n:
      print("-1")
      exit()
print(mo)

Measured memory_bytes: 27268
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		//for (var i = 3; i < 1000; i++) Solve(i);
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		WriteLine(string.Join(" ", Solve(F())));
		Out.Flush();
	}
	IList<int> Solve(int N)
	{
		if (N == 3) return new[] { 2, 3, 25 };
		var M = 30000;
		var good = new SortedSet<int>();
		for (var p = 2; p <= M; p += 2) good.Add(p);
		for (var p = 3; p <= M; p += 3) good.Add(p);
		var ans = new HashSet<int>();
		var tmp = good.ToArray();
		for (var i = 0; i < N - 2; i++) ans.Add(tmp[i]);
		var s = ans.Sum(i => (long)i);
		for (var j = 0; j < 6; j++)
			for (var k = j; k < 6; k++)
				if ((s + j + k) % 6 == 0)
					for (var a = j; a <= M; a += 6)
						if (!ans.Contains(a))
							for (var b = k; b <= M; b += 6)
								if (!ans.Contains(b) && a != b && GCD(s + b, a) > 1 && GCD(s + a, b) > 1 && a > 1 && b > 1)
								{
									ans.Add(a);
									ans.Add(b);
									return ans.ToList();
								}
		return null;
	}
	public static long GCD(long a, long b)
	{
		var n = (ulong)Abs(a); var m = (ulong)Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Min(zm, zn);
	}
}


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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<8>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<int>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1e9+7

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

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

int main()
{
    int n, d;
    ci >> n >> d;

    d = d * 2 + 1;

    co << n / d + (n % d != 0) << en;
  
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int min,a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  min=a+b;
  if(min>a+c)min=a+c;
  if(min>b+c)min=b+c;
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
string s;
int L;
main(){
  cin>>s;
  L=s.size();
  for(int l=L;l>=0;l--)for(int i=0;i<=L-l;i++)
  {
    int f=1;
    for(int j=0;j<l;j++)f&=s[i+j]=='A'||s[i+j]=='T'||s[i+j]=='G'||s[i+j]=='C';
    if(f){
      printf("%d",l);
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  string s;
  cin >> s;
  // cout << s.size() << endl;
  int ans0 = 0;
  int ans1 = 0;
  for (size_t i = 0; i < s.size(); i++) {
    if (i % 2) {
      if (s[i] == '0') {
        ans0++;
      } else {
        ans1++;
      }
    } else {
      if (s[i] == '0') {
        ans1++;
      } else {
        ans0++;
      }
    }
  }
  cout << (ans0 < ans1 ? ans0 : ans1) << endl;
  return 0;
}


Measured memory_bytes: 512
N,K=map(int,input().split())
mylist=[]
temp=0
amount=9999999999
for i in range(N):
    mylist.append(int(input()))

mylist.sort()
#print(mylist)

for i in range(N-K+1):
    #print(mylist[i:i+K])
    #temp=sum(mylist[i:i+K])
    temp=mylist[i+K-1]-mylist[i]
    
    amount=min(temp,amount)
    
print(amount)

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

using namespace std;

int main()
{
  int N, K, ans = 0;
  cin >> N >> K;
  vector<int> A(N, 0);
  for (int i = 0; i < N;i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < K;i++){
    ans += A[i];
  }
  cout << ans << endl;
  return 0;
}

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

const int Max = 50;
int F[Max];

int Fib(int n)
{
    F[0] = 1;
    F[1] = 1;
    if(n==0 || n==1) return F[n];
    if(!F[n-1])
        F[n-1] = Fib(n-1);
    if(!F[n-2])
        F[n-2] = Fib(n-2);
    return F[n-1]+F[n-2];
}
int main()
{
    int n;
    cin >> n;
    memset(F, 0, sizeof(F));
    cout << Fib(n) << endl;
}



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

namespace ALDS1_10_B
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] r = new int[n + 1];
            for (int i = 0 ; i < n ; i++)
            {
                int[] tmp = ReadIntAr();
                r[i] = tmp[0];
                r[i + 1] = tmp[1];
            }

            long[,] dp = new long[n, n];
            for (int i = 0 ; i < n ; i++)
            {
                for (int j = 0 ; j < n ; j++)
                {
                    dp[i, j] = (i == j) ? 0 : long.MaxValue;
                }
            }

            for (int k = 1 ; k < n ; k++)
            {
                for (int i = 0 ; i + k < n ; i++)
                {
                    int j = i + k;

                    for (int m = i ; m < j ; m++)
                    {
                        long tmp = dp[i, m] + dp[m + 1, j] + r[i] * r[m + 1] * r[j + 1];
                        dp[i, j] = Math.Min(dp[i, j], tmp);
                    }
                }
            }

            Console.WriteLine(dp[0, n - 1].ToString());

        }



        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



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

int main() {
    int N,K;
    cin >> N >> K;
    int cnt = 0;
    int power = 0;
    while(N > power){
        power = pow(K, cnt + 1) - 1;
        cnt ++;
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, H, W;
	char s[52][52] = {};
	scanf("%d %d", &H, &W);
	for (i = 1; i <= H; i++) scanf("%s", &(s[i][1]));
	for (i = 0; i <= W + 1; i++) {
		s[0][i] = '#';
		s[H+1][i] = '#';
	}
	for (i = 1; i <= H; i++) {
		s[i][0] = '#';
		s[i][W+1] = '#';
	}
	
	int j, k, l, min, sum = 0, dist[52][52] = {}, flag[52][52] = {};
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			dist[i][j] = 1000;
			if (s[i][j] == '.') sum++;
		}
	}
	i = 1;
	j = 1;
	dist[i][j] = 0;
	while (1) {
		flag[i][j] = 1;
		if (s[i][j+1] == '.' && flag[i][j+1] == 0) dist[i][j+1] = (dist[i][j] + 1 < dist[i][j+1])? dist[i][j] + 1: dist[i][j+1];
		if (s[i+1][j] == '.' && flag[i+1][j] == 0) dist[i+1][j] = (dist[i][j] + 1 < dist[i+1][j])? dist[i][j] + 1: dist[i+1][j];
		if (s[i][j-1] == '.' && flag[i][j-1] == 0) dist[i][j-1] = (dist[i][j] + 1 < dist[i][j-1])? dist[i][j] + 1: dist[i][j-1];
		if (s[i-1][j] == '.' && flag[i-1][j] == 0) dist[i-1][j] = (dist[i][j] + 1 < dist[i-1][j])? dist[i][j] + 1: dist[i-1][j];
			
		min = 999;
		for (k = 1; k <= H; k++) {
			for (l = 1; l <= W; l++) {
				if (flag[k][l] == 0 && dist[k][l] < min) {
					i = k;
					j = l;
					min = dist[k][l];
				}
			}
		}
		if (min == 999) break;
	}
	
	if (flag[H][W] == 1) printf("%d\n", sum - dist[H][W] - 1);
	else printf("-1\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int r[20][20],ans,w,h;
char C[20][20];
int search(int x,int y){
    if(x<0||x>=w||y<0||y>=h||C[y][x]=='#'||r[y][x]) return 0;
    r[y][x]=1;
    ans++;
    search(x+1,y);search(x-1,y);search(x,y+1);search(x,y-1);
}
int main(){
    while(true){
        cin>>w>>h;
        if(w==0) break;
        int sx,sy;
        rep(i,h)rep(j,w){
            cin>>C[i][j];
            if(C[i][j]=='@') sx=j,sy=i;
        }
        rep(i,h)rep(j,w) r[i][j]=0;
        ans=0;
        search(sx,sy);
        cout<<ans<<endl;
    }
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    const i64 mod = 1'000'000'007;

    string K;
    i64 D;
    cin >> K >> D;

    const i64 max_digit=10010;
    const i64 max_d=100;
    static i64 memo[max_digit][2][max_d];
    static bool done[max_digit][2][max_d];
    fill_n((i64*)memo,max_digit*2*max_d,0);
    fill_n((bool*)done,max_digit*2*max_d,false);

    assert(K.size()<max_digit);

    reverse(begin(K),end(K));
    while(K.size()<max_digit) K+='0';
    vector<i64> val(max_digit);
    rep(i,0,max_digit){
        val[i]=K[i]-'0';
    }

    function<i64(i64,i64,i64)> rec=[&](i64 d,i64 b,i64 r){
        if(d==-1){
            return i64(r==0?1:0);
        }

        auto& res=memo[d][b][r];
        if(done[d][b][r]) return res;
        done[d][b][r]=true;

        if(b==0){
            rep(i,0,10){
                res+=rec(d-1,0,(r+i)%D);
                res%=mod;
            }
        }else{
            rep(i,0,val[d]){
                res+=rec(d-1,0,(r+i)%D);
                res%=mod;
            }
            res+=rec(d-1,1,(r+val[d])%D);
            res%=mod;
        }

        return res;
    };

    cout << (rec(max_digit-1, 1, 0)-1+mod)%mod << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 19584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int key;
  cin >> key;
  int flag;
  if(a-c >= 0 && a-c <= key)
    cout << "Yes" << endl;
  else if(c-a > 0 && c-a<= key)
    cout << "Yes" << endl;
  else if(a-b <= key && a-b >=-1*key && b-c <= key && b-c >= -1*key)
      cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
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<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

string s,t;
map<char,int>mp;
int now;

int dfs(){
	if('a'<=s[now]&&s[now]<='d'){
		now++;
		return t[mp[s[now-1]]]-'0';
	}
	int ret = 0;
	now++;
	int kigou = mp[s[now]];
	now++;
	int a = dfs();
	int b = dfs();
	if(kigou==0)ret = a|b;
	else if(kigou==1)ret = a&b;
	else ret = a^b;
	now++;
	return ret;
}


pair<int,int>solve(){
	now = 0;
	int hash = dfs();
	int cnt = 0;
	rep(i,0,10){
		rep(j,0,10){
			rep(k,0,10){
				rep(l,0,10){
					t="";
					t+=i+'0';
					t+=j+'0';
					t+=k+'0';
					t+=l+'0';
					now=0;
					int gethash = dfs();
					if(gethash==hash)cnt++;
				}
			}
		}
	}
	return {hash,cnt};
}
 
signed main(){
	IOS();
	vector<pair<int,int>>ans;
	rep(i,0,4)mp['a'+i]=i;
	mp['+']=0;
	mp['*']=1;
	mp['^']=2;
	while(1){
		cin>>s;
		if(s==".")break;
		cin>>t;
		ans.push_back(solve());
	}
	for(auto e:ans){
		cout<<e.fi<<" "<<e.se<<endl;
	}
}


Measured memory_bytes: 3164
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    cin>>n;
    double ans=0;
    if(n%2==0) cout<<"0.5000000000"<<endl;
    else if(n==1) cout<<"1.0000000000"<<endl;
    else
    {
        ll x=(n+1)/2;
        ans=((x*1.00)/(n*1.00))*1.00;
        printf("%.10lf\n",ans);
    }
    return 0;
}
/*
5
4
3
2
3
4
4
3
3
4
2
3
*/


Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>


int main(void){
    long long int n, m, a[100005]={}, b[100005]={}, l=0, s=1;
    scanf("%lld %lld", &n, &m);
    a[0]=-1;
    for(int i=1; i<=m; i++){
        scanf("%lld", &a[i]);
    }
    a[m+1]=n+1;
    for(int i=0; i<=m; i++){
        a[i]=a[i+1]-a[i]-1;
    }
    for(int i=0; i<=m; i++){
        if(a[i]>l){
            l=a[i];
        }
    }
    b[0]=0;
    b[1]=1;
    for(int i=2; i<=l; i++){
        b[i]=(b[i-1]+b[i-2])%1000000007;
    }
    for(int i=0; i<=m; i++){
        s=(s*(b[a[i]]%1000000007))%1000000007;
    }
    printf("%lld", s);
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define fr(i,a) for(i=0;i<a;i++)
#define pb push_back
#define ul unsigned long long
using namespace std;
main()
{
	ul x,y,a,b,c,i,p,s=0;
	vector<ul>red,grn,no;
	cin>>x>>y>>a>>b>>c;
	fr(i,a){
		cin>>p;
		red.pb(p);
	}
	fr(i,b){
		cin>>p;
		grn.pb(p);
	}
	fr(i,c){
		cin>>p;
		no.pb(p);
	}
	sort(red.begin(),red.end(),greater<ul>());
	sort(grn.begin(),grn.end(),greater<ul>());
	sort(no.begin(),no.end(),greater<ul>());
	vector<ul>ans(no.begin(),no.end());
	fr(i,y){
		ans.pb(grn[i]);
	}
	fr(i,x){
		ans.pb(red[i]);
	}
	sort(ans.begin(),ans.end(),greater<ul>());
	fr(i,x+y) s+=ans[i];
	cout<<s<<'\n';
}

Measured memory_bytes: 7268
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int n ;
	while (n = readln.chomp.to!int, n) {
		auto dice = [1, 6, 2, 5, 3, 4];
		int sum = 1;
		while (n--) {
			auto str = readln.chomp;
			if (str == "North") {
				swap(dice[0], dice[2]);
				swap(dice[2], dice[1]);
				swap(dice[1], dice[3]);
			} else if (str == "East") {
				swap(dice[0], dice[5]);
				swap(dice[5], dice[1]);
				swap(dice[1], dice[4]);
			} else if (str == "West") {
				swap(dice[1], dice[4]);
				swap(dice[5], dice[1]);
				swap(dice[0], dice[5]);
			} else if (str == "South"){
				swap(dice[1], dice[3]);
				swap(dice[2], dice[1]);
				swap(dice[0], dice[2]);			
			} else if (str == "Left") {
				swap(dice[2], dice[5]);
				swap(dice[5], dice[3]);
				swap(dice[3], dice[4]);
			} else {
				swap(dice[3], dice[4]);
				swap(dice[5], dice[3]);
				swap(dice[2], dice[5]);
			}
			sum += dice[0];
		}
		sum.writeln;
	}
}

Measured memory_bytes: 1064
#include <iostream>
#include <algorithm>
#include <cstring>
 
constexpr int MAX=5010;
 
int n,k;
 
int a[MAX];
bool dp[MAX][MAX];
 
bool C(int x){
 
    for(int i=std::max(k-x,0);i<k;++i){
        if(dp[n-1][i])
            return true;
    }
    return false;
}
 
int main() {
 
    std::cin>>n>>k;
 
    for(int i=0;i<n;++i)
        std::cin>>a[i];
 
    std::sort(a,a+n);
 
    int lb=-1,ub=n;
 
    while(ub-lb>1){
 
        int mid=(lb+ub)/2;
 
        std::memset(dp,false,sizeof(dp));
 
        dp[0][0]=true;
 
        if(mid!=0&&k>a[0])
            dp[0][a[0]]=true;
 
        for(int i=1;i<n;++i){
            for(int j=0;j<k;++j){
 
                if(!(dp[i][j]=dp[i-1][j])
                    &&i!=mid&&j>=a[i])
                    dp[i][j]=dp[i-1][j-a[i]];
            }
        }
        
        if(C(a[mid]))
            ub=mid;
        else
            lb=mid;
    }
 
    std::cout<<ub<<std::endl;
 
    return 0;
}

Measured memory_bytes: 24832
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{

    
    class Program
    {


        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int M = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            str = Console.ReadLine().Split(' ');
            int[] b = new int[M];
            for(int i = 0; i < M; i++)
            {
                b[i] = int.Parse(str[i]);
            }

            int ans = 0;
            for(int i = 0; i < N; i++)
            {
                int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

                int sum = C;
                for(int j = 0; j < M; j++)
                {
                    sum += a[j] * b[j];
                }

                if(sum > 0)
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);


        }
    }
}


Measured memory_bytes: 13268
n,k=gets.chomp.split(" ").map{|s| s.to_i}
s=gets.chomp

case s[k-1]
  when "A"
    s[k-1]="a"
  when "B"
    s[k-1]="b"
  when "C"
    s[k-1]="c"
end
puts s


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll a[200001];
ll d[200001]={};
int main(){

	ll n;
	cin>>n;
	rep(i,n){
		cin>>a[i];
		d[i+1]=d[i]+a[i];
	}
	ll t=INF;
	for(int i=1; i<n; i++){
		if(t>=labs(d[n]-d[i]-d[i]))t=labs(d[n]-d[i]-d[i]);
	}
	cout<<t<<endl;
	return 0;

}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;
int fen[maxn], ans[maxn], qtd[maxn];
vector<int> divs[maxn], bck[maxn];
void add(int x, int v){
	for(; x < maxn; x += x & - x) fen[x] += v;
}
int sum(int x){
	int ans = 0;
	for(; x; x -= x & - x) ans += fen[x];
	return ans;
}
int main(){
	int n, m; cin >> n >> m;
	for(int i = 1; i <= m; i++) for(int j = i; j <= m; j += i) divs[j].push_back(i);
	for(int i = 1; i <= n; i++){
		int l, r; cin >> l >> r;
		qtd[r]++;
		bck[l].push_back(r);
	}
	for(int i = m; i >= 1; i--){
		add(i, qtd[i]);
		for(int q: divs[i]) ans[q] += sum(i + q - 1);
		for(int q: bck[i]) add(q, -1);
	}
	for(int i = 1; i <= m; i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 22016
N = gets.to_i
a = gets.split.map(&:to_i)

sum = a.inject(&:+)
b = [a[0]]
(N-1).times do |i|
  b << b[i] + a[i+1]
end

min = Float::INFINITY
(N-1).times do |i|
  x = b[i]
  y = sum - b[i]
  min = [min, (x - y).abs].min
end
puts min

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

int main() {
  int N, K, a, b, c;
  cin >> N >> K;
  a = 1;
  
  for (int i = 0; i < N; i++) {
    b = a * 2;
    c = a + K;
    
    if (b <= c) {
      a = b;
    }
    
    else {
      a = c;
    }
  }
  
  cout << a << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){
  int min,max,*R,i,n;

  scanf("%d",&n);
  R=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&R[i]);

  max=R[1]-R[0];
  min=R[0];
  for(i=1;i<n;i++){
    max=(max>R[i]-min)?max:R[i]-min;
    min=(min<R[i])?min:R[i];
  }
  printf("%d\n",max);

  return 0;
}

Measured memory_bytes: 1380
a  = int  (input  ())
b,c  = map (int,input().split ())
flag = False
for i in range  (b,c+1):
      if  i%a == 0:
            print  ('OK')
            flag = True 
            break
      else:
            continue 
if flag == False:
      print  ('NG')

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=7;
const ll ms=1e6+5;
const ll inf=-1e17;



int main()
{
    idfc;

    int n;
    cin>>n;

    while(n--)cout<<"ACL";


    return 0;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,a,b,ans;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if((b<a)||(n==1&&a!=b))putchar('0');
	else printf("%lld",max(0ll,(n-2)*(b-a)+1));
}

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

struct mat {
	int r, c;
	
	mat(int rv,int cv)
		:r{ rv }, c{ cv }{}
	mat() :r{}, c{} {}
	friend auto
		operator >> (std::istream&is, mat& m)->std::istream& {
		return
			is >> m.r >> m.c;
	}
};


using ui = unsigned int;
int main() {

	/*
	for (int l{ 2 }; l < 6; ++l) {

		for (int i{ 1 }; i < 6 - l + 1; ++i) {

			int j = i + l - 1;
			std::cout << "[ i, j ] = ( " << i << ", " << j << " ) >> k:";

			for (int k = i; k < j ; ++k)
				std::cout << " " << k;
			
			std::cout << "\n";
		}
		std::cout << std::endl;
	}*/
	

	int n;
	std::cin >> n;


	using ull = unsigned long long;
	using vu_t = std::vector<ull>;
	std::vector<vu_t> tab( n+1, vu_t(n+1, 0) );

	std::vector<mat> mv(n);
	for (auto&e : mv)
		std::cin >> e;

	
//	for (int i{}; i < n - 1; ++i) {
//		tab[i][i + 1] = mv[i].r * mv[i].c * mv[i + 1].c;
	//	std::cout << tab[i][i + 1] << " ";
//	}
	//std::cout << "\n";
	

	
	
	for (int l{ 2 }; l <= n; ++l) {
		for (int i{ 1 }; i <= n - l + 1; ++i) {
			ull t = (1 << 21);
			auto j = i + l - 1;
			for (int k{ i }; k <= j-1; ++k) {

				auto tt = tab[i][k] + tab[k + 1][j];
				auto c = mv[i-1].r * mv[k-1].c * mv[j-1].c;
				//std::cout << tt + c << "\t=\t" << tt << " + " << c << "\n";
				//std::cout << i << " " << k << " " << j << "\n";
				t = std::min(tt + c, t);
			}
			tab[i][j] = t;
		}
	}


//	for (const auto& e : tab) {
//		for (const auto&ee : e) {
//			std::cout << ee << "\t";
//		}std::cout << "\n";
//	}

//	put();
	std::cout << tab[1][n] << "\n";
	return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N;
    cin >> N;
    vec<plint> ratio(N);
    range(i, 0, N) {
        lint T, A;
        cin >> T >> A;
        ratio.at(i) = {T, A};
    }
    lint cur_T = ratio.at(0).first, cur_A = ratio.at(0).second;
    range(i, 1, N) {
        lint T = ratio.at(i).first, A = ratio.at(i).second;
        lint m = max(cur_T / T + (cur_T % T == 0 ? 0 : 1), cur_A / A + (cur_A % A == 0 ? 0 : 1));
        m = max(1LL, m);
        cur_T = m * T, cur_A = m * A;
    }
    cout << cur_T + cur_A << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
   
   ll h,n,sum=0;
   cin>>h>>n;
   for(ll i=0;i<n;i++)
   {
       ll t;
       cin>>t;
       sum=sum+t;
   }
   if(sum>=h)
   cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
   return 0;
}

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

using namespace std;
typedef long long llint;

const int maxn = 1e5+10;
const llint inf = 1e9+10;

int n;
llint m;
llint a[maxn];
int cnt[maxn];

int main() {
    scanf("%d%lld", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%lld", a+i);
        a[i] /= 2;
    }

    for (int i = 0; i < n; i++) {
        llint tren = a[i];
        while (tren % 2 == 0) cnt[i]++, tren /= 2;
    }

    bool flag = true;
    for (int i = 1; i < n; i++) {
        if (cnt[i] != cnt[i - 1]) flag = false;
    }

    if (!flag) {
        printf("0\n");
        return 0;
    }

    llint lc = a[0];
    for (int i = 0; i < n; i++) {
        lc = min(inf, lc * a[i] / __gcd(lc, a[i]));
    }

    llint x = m / lc;
    printf("%lld", (x + 1) / 2);
    return 0;
}


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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define ll             long long
#define int 	       long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC
using namespace std;


template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

int solve(){
 	int n;cin>>n;
 	vector<int>a(n+1);
 	rep(i,1,n+1){
 		cin>>a[i];
 	}
 	int c=1000;
 	for(int i=2;i<=n;i++){
 		if(a[i]>a[i-1]){
 			int s=c/a[i-1];
 			c=c%a[i-1]+s*a[i];
 		}
 	}cout<<c<<endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 3652
#include <stdio.h>

int main() {
	int a;
	int b;

	scanf("%d %d", &a, &b);
	if (a >= 13) {
		printf("%d\n", b);
	}
	else if (a >= 6) {
		printf("%d\n", b / 2);
	}
	else {
		printf("0\n");
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;
 
int main()
{
    string s,t;
    cin>>s;
    cin>>t;
    ll cnt = 0;
    for(int i = 0;i < s.length();i++){
        if(s[i] != t[i]) cnt++;
    }
    
    cout<<cnt<<"\n";
    
	return 0;
}

Measured memory_bytes: 3908
#include<stdio.h>

#define N 10000

int main(){

  int n,i,j,q,count=0;
  int a[N],b[N];

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

  scanf("%d",&q);
  for( i = 0 ; i < q ; i++){
    scanf("%d",&b[i]);
    for( j = 0 ; j < n ; j++){
      if(b[i] == a[j]){
         count++;
	 break;
      }
    }      
  }

  printf("%d\n",count);
  return 0;

}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
int main(){

 int n,m,c,cnt=0;
  cin>>n>>m>>c;
  int b[m],a[n];

  for(int i=0;i<m;i++) cin>>b[i];

  while(n--){

  int sum =0;
  for(int j=0;j<m;j++) cin>>a[j];

  for(int i=0;i<m;i++){
    sum += a[i]*b[i];
  }

   sum = sum + c;

   if(sum > 0) cnt++;
  }

   cout<<cnt<<endl;

return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 1e9
#define C 998244353
#define pi 3.14159265359
#define loop(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define rloop(i,a,b) for(ll i = ll(a); i >= ll(b); --i)
#define sloop(i,a) for (std::set<ll>::iterator i = a.begin(); i != a.end(); ++i)
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;

vector<ll> primes;
ll ans=0;

void sieve_of_eratosthenes(int n) 
{ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
       
        if (prime[p] == true) 
        {  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.pb(p); 
} 

void solve(){
    ll n,i,j,count=0;
    cin >> n;
    sieve_of_eratosthenes(sqrt(n)+1);
    loop(i,2,1000005){
        ll cur=0;
        while(n%i==0){
            cur++;
            n/=i;
        }
        loop(j,1,1000005){
            if(cur<j)
                break;
            ans++;
            cur-=j;
        }
    }
    if(n>1)
        ans++;
    cout << ans << "\n";
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    loop(f,0,t){    
        solve();
    }   
}

Measured memory_bytes: 5212
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}
int main(){
  int n;
  scanf("%d", &n);
  int v[n];
  int i;
  for(i=0;i<n;i++){
    scanf("%d", &v[i]);
  }
  qsort(v, n, sizeof(int), compare);
  double ans = v[0];
  for(i=0;i<n-1;i++){
    ans = (ans + v[i + 1]) / 2.0;
  }
  printf("%lf\n", ans);
  return 0;
}


Measured memory_bytes: 128
S = input()

if S == ("SUN"):
    print(7)
elif S == ("MON"):
    print(6)
elif S == ("TUE"):
    print(5)
elif S == ("WED"):
    print(4)
elif S == ("THU"):
    print(3)
elif S == ("FRI"):
    print(2)
elif S == ("SAT"):
    print(1)

Measured memory_bytes: 3060