akhauriyash/Code-Regression huggingface dataset:
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

typedef long long ll;

using namespace std;

int main() {
    // your code goes here

    ll n ;

    string ans;

    cin>>n;

    ll power = 1;

    ll base = 26;

    while(n>0){
        n--;
        ans.push_back('a'+n%base);
        n/=base;

    }

    reverse(ans.begin(),ans.end());

    cout<<ans;

    return 0;
}


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

int main(){
    int n;
    vector<int> A;

    cin >> n;
    for(int i = 0; i < n; ++i) {
        int buffer;
        cin >> buffer;
        A.emplace_back(buffer);
    }

    auto rmvItr = remove_if(A.begin(), A.end(), [](int x) {
        return (x % 2) != 0;
    });

    A.erase(rmvItr, A.end());

    bool ans = true;

    for(auto i = A.begin(); i < A.end(); ++i){
        if((*i % 3 != 0) && (*i % 5 != 0) ){
            ans = false;
            break;
        }
    }

    cout << ((ans)? "APPROVED": "DENIED");
}

Measured memory_bytes: 256
def bfs(q_list):
    cnt = -1
    while q_list:
        cnt += 1
        new_q_list = []
        for h, w in q_list:
            if not m_list[h][w+1]:
                m_list[h][w+1] = True
                new_q_list.append((h, w+1))
            if not m_list[h+1][w]:
                m_list[h+1][w] = True
                new_q_list.append((h+1, w))
            if not m_list[h][w-1]:
                m_list[h][w-1] = True
                new_q_list.append((h, w-1))
            if not m_list[h-1][w]:
                m_list[h-1][w] = True
                new_q_list.append((h-1, w))
        q_list = new_q_list
    print(cnt)


if __name__ == "__main__":
    h_len, w_len = map(int, input().split())
    m_list = [[True for _ in range(w_len+2)]]
    q_list = []
    for i in range(h_len):
        tmp = [True]
        s_in = input()
        for j, s in enumerate(s_in):
            if s == '#':
                q_list.append((i+1, j+1))
                tmp.append(True)
            else:
                tmp.append(False)
        tmp.append(True)
        m_list.append(tmp)
    m_list.append([True for _ in range(w_len+2)])
    bfs(q_list)


Measured memory_bytes: 129640
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
  int n,ans = 0;
  int l[105];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }

  for(int i = 0; i < n; i ++){
    for(int j = i+1; j < n; j++){
      for(int k = j+1; k < n; k++){
        if(i == j || i == k || j == k) continue;
        int a,b,c;
        a = l[i]; b=l[j]; c=l[k];

        if(a == b || a == c || b == c) continue;
        if(a + b <= c || a + c <= b || b + c <= a) continue;
        //cout << i << ' ' << j << ' ' << k << endl;
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}


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

int main() {
  int n, sum=0;
  bool canFinish = true;
  cin >> n;
  vector<pair<int, int>> job(n);
  for(int i=0; i<n; i++) {
    cin >> job[i].second >> job[i].first;
  }
  sort(job.begin(), job.end());
  for(auto v:job) {
    sum+=v.second;
    if(sum>v.first) {
      canFinish=false;
      break;
    }
  }
  if(canFinish) cout << "Yes" << endl;
  else if(!canFinish) cout << "No" << endl;
}


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

int main()
{
    int n,i,x=0;
    long long int m=1;
    double l=0;

    cin>>n;

    long long int a[n+5];

    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0){
            x=1;
        }
    }
    for(i=0;i<n;i++){
        l=l+log10((double)a[i]);
    }
    if(x==1){
        m=0;
    }
    else if(l>18){
        m=-1;
    }
    else{
        for(i=0;i<n;i++){
            m=m*a[i];
            if(m==0){
                break;
            }
            if(m>1000000000000000000){
                m=-1;
                break;
            }
        }
    }
    cout<<m<<endl;

    return 0;
}



Measured memory_bytes: 4812
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 5e5 + 5;
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

void solve() 
{
	// int n;
	// cin >> n;
	// int cnt = 0;
	// while(n)
	// {
	// 	cnt += (n % 10 == 7);
	// 	n /= 10;
	// }
	// if(cnt)
	// {
	// 	cout << "Yes" << endl;
	// }
	// else
	// {
	// 	cout << "No" << endl;
	// }
	int ans = 0;
	int k;
	cin >> k;
	for(int i = 1; i <= k; i++)
	{
		for(int j = 1; j <= k; j++)
		{
			for(int l = 1; l <= k; l++)
			{
				int g = __gcd(i, j);
				g = __gcd(g, l);
				ans += g;
			}
		}
	}
	cout << ans << endl;
}

 
 
int32_t main() 
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

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

using namespace std;

int main()
{
    char a[11], b[11], c[11];
    cin>>a>>b>>c;
    if(a[strlen(a)-1]==b[0])
    {
        if(b[strlen(b)-1]==c[0])
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Array
import Data.Maybe

readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

calc :: Array Int Int -> Array Int Int -> [[Int]] -> [Int]
calc as bs [] = []
calc as bs ([s, t, u] : css) = val : calc as bs css
  where
    val = as ! s + bs ! t - u

main = do
  [a, b, m] <- getIntList
  as <- getIntList
  bs <- getIntList
  css <- getIntNList m
  let as' = listArray (1, length as) as
  let bs' = listArray (1, length bs) bs
  let noCoupon = minimum as + minimum bs
  print $ minimum (noCoupon : calc as' bs' css)


Measured memory_bytes: 38652
/* created   : 2019-08-29 11:34:01
 * accepted  : 2019-08-29 11:46:32
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n; cin >> n;
  vector<vector<int>> a(n);
  for (int i = 0; i < n; i++) {
    string x; cin >> x;
    vector<int> cnt(26);
    for (int j = 0; j < (int) x.size(); j++) {
      cnt[x[j] - 'a']++;
    }
    a[i] = cnt;
  }
  map<vector<int>, int> mp;
  for (int i = 0; i < n; i++) {
    mp[a[i]]++;
  }
  ll ans = 0;
  for (auto it : mp) {
    ans += (ll) (it.y - 1) * it.y / 2;
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 32256
D = gets.to_i
c = gets.split.map(&:to_i)
s = Array.new D
D.times do |i|
  s[i] = gets.split.map(&:to_i)
end

t = Array.new D
D.times do |i|
  t[i] = gets.to_i
end

score = 0
last = Array.new 26, 0
D.times do |i|
  best = -99999999999
  res = nil
  base_c = 0
  26.times do |t|
    base_c += (i - last[t] + 1) * c[t]
  end
  
  26.times do |t|
    diff = s[i][t]
    diff -= base_c
    diff += c[t] * (i - last[t] + 1)

    if diff > best
      best = diff
      res = t
    end
  end
  score +=  best
  last[res] = i + 1
  puts res + 1
end

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

int partition(vector<pair<char, int>> &a, int p, int r) {
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (a[j].second <= a[r].second) {
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i+1], a[r]);
    return i+1;
}

void quick_sort(vector<pair<char, int>> &a, int p, int r) {
    if (p < r) {
        int q = partition(a, p, r);
        quick_sort(a, p, q-1);
        quick_sort(a, q+1, r);
    }
}

void merge(vector<pair<char, int>> left, vector<pair<char, int>> right, vector<pair<char, int>> &merged_a) {
    int i = 0, j = 0;
    while (i < left.size() || j < right.size()) {
        if ((i < left.size() && left[i].second <= right[j].second) || j == right.size()) {
            merged_a[i+j] = left[i];
            i++;
        } else {
            merged_a[i+j] = right[j];
            j++;
        }
    }
}

void merge_sort(vector<pair<char, int>> &a) {
    if (a.size() > 1) {
        int l_size = a.size() / 2;
        int r_size = a.size() - l_size;
        vector<pair<char, int>> left(l_size);
        vector<pair<char, int>> right(r_size);
        rep(i, l_size) {
            left[i] = a[i];
        }
        rep(i, r_size) {
            right[i] = a[l_size + i];
        }
        merge_sort(left);
        merge_sort(right);
        merge(left, right, a);
    }
}

bool stable(vector<pair<char, int>> a, vector<pair<char, int>> b) {
    rep(i, a.size()) {
        if (a[i].first != b[i].first) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<pair<char, int>> a(n);

    rep(i, n) {
        cin >> a[i].first >> a[i].second;
    }

    vector<pair<char, int>> a_copy = a;

    quick_sort(a, 0, n-1);
    merge_sort(a_copy);

    if (stable(a, a_copy)) printf("Stable\n");
    else printf("Not stable\n");
    
    rep(i, n) {
        printf("%c %d\n", a[i].first, a[i].second);
    }
}


Measured memory_bytes: 6164
#include<bits/stdc++.h>
using namespace std;
int niwari(int x);
int main(){
    int N;
    cin >> N;
    int sum = 0;
    for(int i = 0;i < N;i++){
        int x;
        cin >> x;
        sum+=niwari(x);
    }
    cout << sum << endl;
    return 0;
}
int niwari(int x){
    int i = 0;
    while(1){
        if((x%2)!=0 || x == 0){
            return i;
        }
        else{
            i++;
            x/=2;
        }
    }
}


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

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

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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N;
   cin >> N;
   vector<ll> a(N);
   int ans = 0;
   for (int i = 0; i < N; i++) {
     cin >> a.at(i);
     while (a.at(i) % 2 == 0) {
       ans++;
       a.at(i) /= 2;
     }
   }

   cout << ans << endl;
 }


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
# define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	int n,q,s=0;
	cin>>n;
	int x[100002],y[100002]={0},i;
	for(i=1;i<=n;i++)
	{
		cin>>x[i];
		s+=x[i];
		y[x[i]]++;
		
	}
	cin>>q;
	while(q--)
	{
		int b,c;
		cin>>b>>c;
		s-=(y[b]*b);
		s+=(y[b]*c);
		y[c]+=y[b];
		y[b]=0;
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 5132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double a[] = new double[n];
		double sum = 0.0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextDouble();
			a[i] = 1 / a[i];
			sum += a[i];
		}
		System.out.println(1 / sum);
	}

}

Measured memory_bytes: 25172
/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';

using namespace std;

void solve(){
	int i,j;
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	for (int i = 0; i < n; ++i)
	{
		int x,y;cin >> x >> y;
		a[i]=x+y;
		b[i]=x-y;
	}

	int ans=max(*max_element(a.begin(),a.end())-*min_element(a.begin(),a.end()),*max_element(b.begin(),b.end())-*min_element(b.begin(),b.end()));

	printf("%d\n",ans);
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    
	int T=1;
	// cin >> T;
	while (T--){
		solve();
	}
}


Measured memory_bytes: 4776
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
A4 = [A1[0], A2[0], A3[0]]
A5 = [A1[1], A2[1], A3[1]]
A6 = [A1[2], A2[2], A3[2]]
A7 = [A1[0], A2[1], A3[2]]
A8 = [A1[2], A2[1], A3[0]]




N = int(input())
b = set([int(input()) for _ in range(N)])

flag = False
if len(b&set(A1)) == 3: flag = True
if len(b&set(A2)) == 3: flag = True
if len(b&set(A3)) == 3: flag = True
if len(b&set(A4)) == 3: flag = True
if len(b&set(A5)) == 3: flag = True
if len(b&set(A6)) == 3: flag = True
if len(b&set(A7)) == 3: flag = True
if len(b&set(A8)) == 3: flag = True
  
print('Yes' if flag else 'No')


Measured memory_bytes: 3064
#include<iostream>
#include<cassert>
using namespace std;
#define MAX 250
#define rep(i, n) for ( int i = 0; i < n; i++ )
int G[MAX+2][MAX+2], D[MAX+2];

main(){
  int m, n; 
  int tcase = 0;
  while(cin >> m){
    if ( m == 0 ) break;
    cin >> n;
    tcase++;
    rep(i, n+2) rep(j, n+2) G[i][j] = 0;
    D[0] = D[n+1] = 0;
    for ( int i = 1; i <= n; i++ ) cin >> D[i];
    for ( int i = 0; i <= n; i++ ){
      assert( -n <= D[i] && D[i] <= n );
      for ( int k = 1; k <= m; k++ ){
	int t = min(i+k, n+1);
	if ( D[t] > 0 ) t = min(n+1, t + D[t]);
	else if ( D[t] < 0 ) t = max(0, t + D[t]);
	G[i][t] = 1;
      }
    }
    rep(k, n+2) rep(i, n+2) rep(j, n+2){
      if ( G[i][k] && G[k][j] ) G[i][j] = 1;
    }
    bool valid = true;
    for ( int i = 0; i <= n; i++ ){
      if ( G[0][i] && !G[i][n+1]) valid = false;
    }
    cout << (valid?"OK":"NG") << endl;
  }
}

Measured memory_bytes: 1404
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

    int main(){
      int n;
      cin >> n;
      ll a[n],b[n];
      vector<ll> v;
      ll ans=0;
      rep(i,n)cin >> a[i];
      rep(i,n)cin >> b[i];
      ll dif=0;
      rep(i,n){
       if(a[i]<b[i]){
         dif+=b[i]-a[i];
         ans++;
       }
         else v.push_back(a[i]-b[i]);
      }
      sort(v.begin(),v.end());
      reverse(v.begin(),v.end());
      int cnt=0;
      while(dif>0 && cnt<v.size()){
        ans++;
        dif-=v[cnt];
        cnt++;
      }
      if(dif>0){
        cout << -1 << endl;
        return 0;
      }else cout << ans << endl;
      return 0;}

Measured memory_bytes: 2808
import java.util.Scanner;

public class Main {
	public static final String OK = "Yay!";
	public static final String NO = ":(";
	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();
		sc.close();
		if(e - a > k) System.out.println(NO);
		else System.out.println(OK);
	}
}

Measured memory_bytes: 23892
import java.util.Scanner;

class Main{
  public static void main(String[] ags){
    Scanner nyuryoku = new Scanner(System.in);
    int N = nyuryoku.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++){
      A[i] = nyuryoku.nextInt();
    }
      show(A, N);
      insertionSort(A, N);
  }
  static void insertionSort(int[] A, int N){
    for(int i = 1; i < N; i++){
      int tmp = A[i];
      int j;
      for (j = i; j > 0 && A[j-1] > tmp; j--)
        A[j] = A[j - 1];
      A[j] = tmp;
      show(A, N);
    }
  }
  static void show(int[] A, int N){
    System.out.print(A[0]);
    for (int i = 1; i < N; i++){
      System.out.print(" " + A[i]);
    }
    System.out.println();
  }
}



Measured memory_bytes: 31572
#include <vector>
#include <list>
#include <map>
#include <set>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS = 1e-9;
#define rep(i,s,n) for(int i=(s); i < int(n); ++i)

const int N = 101;
const int V = 1e5 + 1;
int v[N], w[N];
int n, wlim;
int tv[N];

int dp[N][V];
const int INF = 0x2fffffff;
const int DEBUG = 0;

int solve(void) {
  dp[0][0] = 0;
  int total_v = 1;
  rep(i, 0, n) {
    total_v += v[i];
  }
  rep(j, 1, total_v) {
    dp[0][j] = INF;
  }
  rep(i, 1, n + 1) {
    rep(j, 0, total_v) {
      int res = dp[i-1][j];
      int val = v[i-1];
      int wei = w[i-1];
      if (val <= j) {
	res = min(res, dp[i - 1][j - val] + wei);
      } else {
	res = min(res, wei);
      }
      if(DEBUG) {
	cout << "dp[" << i << "][" << j << "] = " << res << endl;
      }
      dp[i][j] = res;
    }
  }
  int q = 0;
  rep(i,0,total_v) {
    if (dp[n][i] <= wlim) {
      q = i;
    }
  }
  if(DEBUG) {
    cout << "q = " << q << endl;
  }
  int rem = q;
  int sum = 0;
  for (int i = n; i > 0; --i) {
    int val = v[i-1];
    int wei = w[i-1];
    if (val <= rem && dp[i][rem] - wei == dp[i - 1][rem - val]) {
      // output (i - 1)
      sum += tv[i - 1];
      rem -= val;
    }
  }
  return sum;
}


int main(void) {
  cin >> n >> wlim;
  double max_v = 0.0;
  rep(i, 0, n) {
    cin >> tv[i] >> w[i];
    max_v = max(max_v, (double) tv[i]);
  }
  double k = 200;
  double scale = max(1.0, max_v / (k + 1) / n);
  rep(i, 0, n) {
    v[i] = (int) floor(tv[i] / scale);
  }
  cout << solve() << endl;
}

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

#define DEBUG(x) cerr << #x << " = " << x << endl

enum FACE { TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM }; // 1..6
typedef array<int, 6> Dice;

FACE tbl[6][4] = {
  { TOP, BACK, BOTTOM, FRONT },
  { TOP, RIGHT, BOTTOM, LEFT },
  { TOP, FRONT, BOTTOM, BACK },
  { TOP, LEFT, BOTTOM, RIGHT },
  { FRONT, RIGHT, BACK, LEFT },
  { FRONT, LEFT, BACK, RIGHT }
};

enum MOVE { TOP_TO_BACK, TOP_TO_RIGHT, TOP_TO_FRONT, TOP_TO_LEFT, FRONT_TO_RIGHT, FRONT_TO_LEFT };

void rotate(Dice &d, FACE t[4]) {
  int tmp = d[t[3]];
  d[t[3]] = d[t[2]]; d[t[2]] = d[t[1]]; d[t[1]] = d[t[0]]; d[t[0]] = tmp;
}

vector<Dice> generate_all(Dice dice) {
  vector<Dice> res;
  for(int i = 0; i < 6; ++i) {
    for(int j = 0; j < 4; ++j) {
      res.emplace_back(dice);
      rotate(dice, tbl[FRONT_TO_RIGHT]);
    }
    if(i % 2 == 0) rotate(dice, tbl[TOP_TO_BACK]);
    else rotate(dice, tbl[TOP_TO_RIGHT]);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  Dice d;
  cin >> d[TOP];
  cin >> d[FRONT];
  cin >> d[RIGHT];
  cin >> d[LEFT];
  cin >> d[BACK];
  cin >> d[BOTTOM];
  int N; cin >> N;
  for(int i = 0; i < N; ++i) {
    int a, b; cin >> a >> b;
    auto gen = generate_all(d);
    for(auto it : gen) {
      if(it[TOP] == a && it[FRONT] == b) cout << it[RIGHT] << endl;
    }
  }
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	int a,b,x;
	cin >>x>>a >> b;
	if(abs(a-x)<abs(b-x))cout<< "A" << endl;
	else cout << "B" << endl;
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let n: u32 = read();
    println!("{}", n * n * n);
}





//**********************************************************************************************************************************************//

// 標準入力から一行を読み取り、指定の型に変換する関数
pub 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()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec2<T: std::str::FromStr>(n: u64) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

// 10進数での各桁の和
pub fn sum_dights(x: isize) -> isize {
    if x % 10 == 0 {
        return 0
    }
    let m = x % 10;
    m + sum_dights((x - m) / 10)
}


Measured memory_bytes: 4352
n,x,y,z=map(int,input().split())
mod=10**9+7
mask=1<<(x+y+z-1)
dp=[[0 for i in range(mask+1)] for j in range(n+1)]
dp[0][0]=1
ng=(1<<(x+y+z-1))|(1<<(y+z-1))|(1<<(z-1))
for i in range(n):
    dp[i+1][mask]=(dp[i][mask]*10)%mod
    for j in range(mask):
        for k in range(1,11):
            nmask=(j<<k)|(1<<(k-1))
            if nmask&ng==ng:
                nmask=mask
            else:
                nmask&=mask-1
            dp[i+1][nmask]=(dp[i+1][nmask]+dp[i][j])%mod
print(dp[n][mask])

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

char s_str[200001],t_str[200001];
int s_ch_count[26] = {},t_ch_count[26] = {};

int comp(const void *x,const void *y){
    return *(int*)x - *(int *)y;
}

int main(void){
    scanf("%s \n %s",s_str,t_str);
    int length = strlen(s_str);

    for(int i = 0;i < length;i++){
        s_ch_count[s_str[i] - 'a']++;
        t_ch_count[t_str[i] - 'a']++;
    }


    qsort(s_ch_count,26,sizeof(int),comp);
    qsort(t_ch_count,26,sizeof(int),comp);

    for(int i = 0;i < 26;i++)if(s_ch_count[i] != t_ch_count[i]){
        puts("No");
        return 0;
    }
    
    puts("Yes");

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

const int mod =(int) 1e9+7;

int modu(ll a) {
    return (a%mod+mod)%mod;
}

int mult(ll a, ll b) {
    ll res=(ll) modu(a)*modu(b)%mod;
    return res;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());

    ll product=1;
    if(a[n-1]==0 && k%2==1) {
        cout << 0 << endl;
        return;
    }

    if(a[n-1]<=0 && k%2==1) {
        for(int i=n-1; i>=n-k; i--)
            product=mult(product, a[i]);
        cout << product << endl;
        return;
    }

    int l=0, r=n-1;
    // TODO check
    if(k%2==1) {
        product=mult(product, a[r]);
        r--;
        k--;
    }

    k>>=1;
    for (int it=0; it<k; it++) {
        ll left_product=a[l]*a[l+1];
        ll right_product=a[r]*a[r-1];
        if(left_product>right_product) {
            product=mult(product, left_product);
            l+=2;
        } else {
            product=mult(product, right_product);
            r-=2;
        }
    }

    cout << product << endl;
}

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


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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  long long s = 0;
  for(int i = 0; i < N; ++i){
    cin >> A[i];
    s += A[i];
  }
  long long t = 0, ans = 1e18;
  for(int i = 0; i < N; ++i){
    t += A[i];
    ans = min(ans,abs(t-(s-t)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<cstdio>

int main(){
	int w,a,b;
	int ans;
	scanf("%d %d %d",&w,&a,&b);
	if(a+w<b) ans = b - a - w;
	else if(b+w<a) ans = a - b - w;
	else ans = 0;
	printf("%d\n",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
	string s;
	cin >> s;
	ll N = s.size();
	ll K;
	cin >> K;
	FOR(i,0,N-1){
		if(!K || s[i] == 'a')continue;
		if('a'+26-s[i] <= K){
			K -= 'a'+26-s[i];
			s[i] = 'a';
		}
	}
	if(K){
		s[N-1] = (s[N-1]-'a'+K)%26 + 'a';
	}
	cout << s << endl;
}

Measured memory_bytes: 592
#include <iostream>
#include <cassert>
//#define NDEBUG
int main(void){
    static const int ConstraintsMin = 1;
    static const int ConstraintsMax = 100;
    int num;
    std::cin >> num;
    assert(ConstraintsMin <= num && num <= ConstraintsMax); /* Precondition */
    std::cout << num*num*num << std::endl;
    return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,max=0,x=0;string s;
    cin>>n>>s;
    for(i=0;i<n;i++){
	    if(s[i]=='I')x++;else x--;
	    if(x>max)max=x;
    }
    cout<<max<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n; cin >> n;
  cout << (n-1)*n/2 << endk;
  return 0;
}


Measured memory_bytes: 3608
s = input()
upper = int(s[0:2])
lower = int(s[2:4])

isYYMM = False
isMMYY = False
if 1 <= lower and lower <= 12  : 
    isYYMM = True
if 1 <= upper and upper <= 12 : 
    isMMYY = True

if isYYMM and isMMYY : 
    print("AMBIGUOUS")
elif isYYMM : 
    print("YYMM")
elif isMMYY : 
    print("MMYY")
else : 
    print("NA")


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

int main() {
  int K;
  string S;
  cin >> K >> S;
  
  if (S.size() <= K) {
    cout << S << endl;
  }
  
  else {
    for (int i = 0; i < K; i++) {
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
}


Measured memory_bytes: 3628
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

class BIT():
    # 作りたい要素数nで初期化, 1-index
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n+1)

    #bit_indexにxをO(log(n))で加算する
    def add(self,i,x):
        #if(i<=0 or i>n):return iに0以下の数字は代入しない
        while i <= self.n:
            self.bit[i] += x
            i += (i & -i)
    #bit_1 + bit_2 + …  + bit_n をO(log(n))で求める
    def sum(self,i):
        s = 0
        #iに0以下の数字は代入しない。
        while i > 0:
            s+=self.bit[i]
            i -= (i & -i)
        return s
    
    def rangesum(self,i,k):
        return self.sum(k) - self.sum(i)
    #a_1 + a_2 + … + a_i >= x となるような最小のiを求める(a_k >= 0)
    #xが0以下の場合は該当するものなし→0を返す
    def lower_bound(self,x):
        if x <= 0:
            return 0
        else:
            i = 0
            r = 1
            #最大としてありうる区間の長さを取得する
            #n以下の最小の二乗のべき(BITで管理する数列の区間で最大のもの)を求める
            while(r<self.n):
                r=r<<1
            len = r
            while len > 0:
                if(i+len<self.n and self.bit[i+len]<x):
                    x-=self.bit[i+len]
                    i+=len
                len = len >> 1
            return i+1

def main():
    N, Q = MI()
    X, Y = BIT(N), BIT(N)
    xmin = N-2
    ymin = N-2
    X.add(1, N-2)
    X.add(N-1, -(N-2))
    Y.add(1, N-2)
    Y.add(N-1, -(N-2))

    res = (N-2)**2
    for i in range(Q):
        a, b = MI()
        if a == 1:
            x = X.sum(b-1)
            if ymin > b-2:
                temp = Y.sum(1)
                Y.add(1, b-2-temp)
                Y.add(x+1, -(b-2-temp))
                ymin = b-2
            res -= x
        else:
            y = Y.sum(b-1)
            if xmin > b-2:
                temp = X.sum(1)
                X.add(1, b-2-temp)
                X.add(y+1, -(b-2-temp))
                xmin = b-2
            res -= y
            
    print(res)
    
if __name__ == "__main__":
    main()

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

int main() {
	int n;
	cin >> n;
	if (n <= 111) {
		cout << 111 << endl;
	}
	else if (112 <= n && n <= 222) {
		cout << 222 << endl;
	}
	else if (223 <= n && n <= 333) {
		cout << 333 << endl;
	}
	else if (334 <= n && n <= 444) {
		cout << 444 << endl;
	}
	else if (445 <= n && n <= 555) {
		cout << 555 << endl;
	}
	else if (556 <= n && n <= 666) {
		cout << 666 << endl;
	}
	else if (667 <= n && n <= 777) {
		cout << 777 << endl;
	}
	else if (778 <= n && n <= 888) {
		cout << 888 << endl;
	}
	else {
		cout << 999 << endl;
	}
	return 0;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    int maxCake = n / 4;
    int maxDonuts = n / 7;
    bool check = false;
    for (int i = 0; i <= maxCake; i++){
        for (int j = 0; j <= maxDonuts; j++){
            if (i * 4 + j * 7 == n){
                check = true;
                break;
            }
        }
    }
    
    if(check) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int binpow(int n, int k) {
    if (k == 0) return 1;
    if (k == 1) return n;
    if (k % 2 == 0) {
        int nn = binpow(n, k / 2);
        return nn*nn;
    }
    if (k % 2 == 1) {
        return n * binpow(n, k - 1);
    }
}

void solve() {
    int n, k;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int res = a[n - 1] - a[0];
    for (int i = 1; i < n; i++) {
        res = min(res, k - (a[i] - a[i - 1]));
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    ios::sync_with_stdio(false);
    ll a,b,c; cin >> a >> b >>c;
    if(2*sqrtl(a*b)<(c-a-b)) cout << "Yes";
    else cout <<"No";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll r1,r2,c1,c2;
ll ans;
ll n;
ll fac[2000005],inv[2000005];
inline void read(ll &x)
{
	ll f;char c;
	for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
inline ll qpow(ll a,ll b)
{
	ll rest=1;
	while(b)
	{
		if(b&1) rest=(rest*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return rest;
}
inline ll C(ll n,ll m)
{
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
inline ll mx(ll _x,ll _y)
{
	return _x>_y?_x:_y;
}
int main()
{
	read(r1);read(c1);read(r2);read(c2);
	n=mx(r2,c2)*2+1;
	fac[0]=1;
	for(ll i=1;i<=n;i++) 
		fac[i]=fac[i-1]*i%mod;
	inv[n]=qpow(fac[n],mod-2);
	for(ll i=n-1;i>=0;i--) 
		inv[i]=inv[i+1]*(i+1)%mod;
	for(ll i=r1;i<=r2;i++)
	{
		ans=(ans+(C(i+c2+1,i+1)-C(i+c1,i+1))%mod)%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}


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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

vector <int> g[N];
int par[N], vis[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int n, m, x, y, i, done, node;
	cin>>n>>m;
	while(m--){
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	for(i=1; i<=n; i++) par[i] = 0;
	queue <int> q;
	q.push(1); par[1] = 1;
	done = 0;
	while(!q.empty()){
		node = q.front();
		q.pop();
		done++;
		for(auto it : g[node]){
			if(par[it]) continue;
			par[it] = node;
			q.push(it);
		}
	}
	if(done < n){
		cout<<"No";
		return 0;
	}
	cout<<"Yes\n";
	for(i=2; i<=n; i++){
		cout<<par[i]<<"\n";
	}
	return 0;
}

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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(false);
    int k,x;
    cin >> k >> x;
    k--;

    for(int i = x-k; i <= x+k; i++) cout << i << " ";
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=100;
int a[N],b[N],c[N],d[N],p[N];
int ans=0;
int n,m,q;
void dfs(int x) {
	int cnt=0,i;
	if (x==n+1) {
		for (i=1;i<=q;i++)
			if (p[b[i]]-p[a[i]]==c[i]) cnt+=d[i];
		ans=max(cnt,ans);
		return;
	}
	for (p[x]=p[x-1];p[x]<=m;p[x]++)
		dfs(x+1);
}
int main() {
	int i;
	cin>>n>>m>>q;
	for (i=1;i<=q;i++)
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	p[0]=1;
	dfs(1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3592
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;

bool solve() {
  char s[500100];
  if (scanf("%s", s) != 1) { return false; }
  int n = (int)strlen(s) + 1;
  vector<int> a(n);
  for (int i = 0; i < n;) {
    int j = i;
    while (j < n - 1 && s[j] == '>') {
      j++;
    }
    a[j] = 0;
    for (int k = j - 1; k > i; --k) {
      a[k] = a[k + 1] + 1;
    }
    if (i + 1 < n && s[i] == '>') {
      a[i] = max(a[i], a[i + 1] + 1);
    }
    if (i > 0) {
      a[i] = max(a[i], a[i - 1] + 1);
    }
    i = j + 1;
  }

  ll sum = 0;
  for (int x : a) {
    sum += x;
  }
  printf("%lld\n", sum);
  return true;
}

int main() {
  int tt = -1;
  //scanf("%d", &tt);
  while (tt-- && solve());
  return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
ll n,x,ans=1e18;
ll a[200010],pre[200010];
int main()
{
	cin>>n>>x;
	for(int i=1;i<=n;i++) cin>>a[i],pre[i]=pre[i-1]+a[i];
	for(int i=1;i<=n;i++)
	{
		ll c=3,sum=0;
		for(int j=n;j>=1;j-=i)
		{
			sum+=(pre[j]-pre[max(0,j-i)])*max(c,5ll),c+=2;
			if(sum>=ans) break;
		}
		ans=min(ans,sum+(i+n)*x);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define f first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010


int main(){
	IOS;
	ll n;cin>>n;
	ll a[n],b[n];
	rep(i,0,n)cin>>a[i];
	rep(i,0,n)cin>>b[i];
	ll c[n];rep(i,0,n)c[i]=i+1;
	ll x=0,y=0;
	do{
		x++;
		bool ok=1;
		rep(i,0,n)if(a[i]!=c[i])ok=0;
		if(ok){
			break;
		}
	}while(next_permutation(c,c+n));
	rep(i,0,n)c[i]=i+1;
	do{
		y++;
		bool ok=1;
		rep(i,0,n)if(b[i]!=c[i])ok=0;
		if(ok){
			break;
		}
	}while(next_permutation(c,c+n));
	ll z=abs(x-y);
	cout<<z;
	return 0;
}



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




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

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;

  if(S==U){
    A -= 1;
  }else{
    B -= 1;
  }

  cout << A << " " << B << endl;
}

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

namespace ABC107_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var H = HW[0];
            var W = HW[1];

            var grid = new char[H, W];
            var ignoreRow = new List<int>();
            for (int i = 0; i < H; i++)
            {
                var line = Console.ReadLine();
                if (!line.Contains("#")) ignoreRow.Add(i);
                for (int j = 0; j < line.Length; j++)
                {
                    grid[i, j] = line[j];
                }
            }

            var ignoreCol = new List<int>();
            for (int j = 0; j < W; j++)
            {
                var sharpcnt = 0;
                for (int i = 0; i < H; i++)
                {
                    if (grid[i, j] == '#') sharpcnt++;
                }
                if (sharpcnt == 0) ignoreCol.Add(j);
            }

            for (int i = 0; i < H; i++)
            {
                if (ignoreRow.Contains(i)) continue;
                for (int j = 0; j < W; j++)
                {
                    if (ignoreCol.Contains(j)) continue;
                    Console.Write(grid[i, j]);
                }
                Console.WriteLine();
            }
        }
    }
}


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

int main() {
    ll n,l;
    cin >> n >> l;
    vector <ll> arr(n);
    ll sum = 0;
    for (int z=1;z<=n;z++){
        arr[z-1] = l+z-1;
        sum += arr[z-1];
    }
    ll mini = LLONG_MAX;
    ll ans = 0;
    for (int z=0;z<n;z++){
        ll temp = sum-arr[z];
        if (abs(temp-sum) < mini){
            mini = abs(temp-sum);
            ans = temp;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import heapq

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
h = []
for i in A:
    heapq.heappush(h, -i)

if len(A) == 1:
    print(A[0] // 2 ** M)
    exit()

used_discount_num = 0
for i in range(M):
    ma = -heapq.heappop(h)
    next_ma = -heapq.heappop(h)
    for j in range(used_discount_num, M):
        ma //= 2
        used_discount_num += 1
        if next_ma > ma:
            heapq.heappush(h, -ma)
            heapq.heappush(h, -next_ma)
            break
    if next_ma <= ma:
        heapq.heappush(h, -ma)
        heapq.heappush(h, -next_ma)
        break

print(-sum(h))







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

int main(){
    int X,Y;
    cin >> X >> Y;
    bool isOK = false;
    for(int i = 0; i <= X; i++){
        for(int j = 0; j <= X; j++){
            if(i + j == X && i + j != 0){
                if(Y - (i*2 + j*4) == 0) isOK = true;
            }
        }
    }

    if(isOK) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>

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

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

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

	return 0;

}

Measured memory_bytes: 128
#include <iostream>
const int MAX = 101;
int main() {
	int n, m;
	std::cin >> n >> m;
	int matrix[MAX][MAX];
	int vector[MAX];
	for (auto i = 0; i < n; ++i)
	{
		for (auto j = 0; j < m; ++j)
		{
			std::cin >> matrix[i][j];
		}
	}
	for (auto i = 0; i < m; ++i)
	{
		std::cin >> vector[i];
	}
	for (auto i = 0; i < n; ++i)
	{
		auto res = 0;
		for (auto j = 0; j < m; ++j)
		{
			res += matrix[i][j] * vector[j];
		}
		std::cout << res << std::endl;
	}
}


Measured memory_bytes: 3120
# 解説放送見てAC
# 包除原理の演習が足りてないのを感じた
MOD = 10**9 + 7
m = 5 * 10**5 + 500
fac = [0] * m
finv = [0] * m
inv = [0] * m


def COMBinitialize(m):
    fac[0] = 1
    finv[0] = 1
    if m > 1:
        fac[1] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, m):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD


def COMB(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


def PERM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[n - k] % MOD) % MOD


COMBinitialize(m)


def main():
    N, M = (int(i) for i in input().split())
    ans = 0
    for k in range(N+1):
        ans += PERM(M-k, N-k) * COMB(N, k) * (-1)**(k % 2)
        ans %= MOD
    print(ans * PERM(M, N) % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 78604
#include <stdio.h>

void draw(int h, int w) {
    int i, j;

    for (i=0; i<h; i++) {
        for (j=0; j<w; j++) {
	    printf("#");
	}
	printf("\n");
    }
}

void process() {
    int h, w;

    do {
        scanf("%d %d", &h, &w);
	if (h == 0 && w == 0) break;
	draw(h, w);
	printf("\n");
    } while (h != 0 || w != 0);
}

int main(void) {
    process();
    return 0;
}


Measured memory_bytes: 2036
# coding: utf-8
N = int(input())

list = input().split(" ")
num_list = []

for num in list:
    num_list.append(int(num))

num_list.sort(reverse=True)

alice = 0
bob = 0

for (i,num) in enumerate(num_list):
    if i%2 == 0:
        alice += num
    else:
        bob += num

print(alice - bob)

Measured memory_bytes: 3064