akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	int w[11]={},k[11]={},wsum=0,ksum=0;
	for(int i=0;i<10;i++){
		cin>>w[i];
	}for(int i=0;i<10;i++){
		cin>>k[i];
	}
	sort(w,w+10, greater<int>());
	sort(k,k+10, greater<int>());
	for(int i=0;i<3;i++){
		wsum+=w[i];
		ksum+=k[i];
	}
	cout<<wsum<<" "<<ksum<<endl;
	
	return 0;
}

Measured memory_bytes: 1180
from collections import deque

s = deque(input())
q = int(input())
flag = 1
for i in range(q):
    query = input().split()
    if query[0] == '1':
        flag *= -1
    elif query[1] == '1':
        if flag == 1:
            s.appendleft(query[2])
        else:
            s.append(query[2])
    elif query[1] == '2':
        if flag == -1:
            s.appendleft(query[2])
        else:
            s.append(query[2])
if flag == 1:
    print(''.join(s))
else:
    print(''.join(list(s)[::-1]))

Measured memory_bytes: 10100
#include <stdio.h>
#include <math.h>
int main(void) {
    int num,i,count,temp1;
    double limit,temp2;
    while (1) {
        scanf("%d",&num);
        if (num==0) break;
        count=0;
        limit=(sqrt(1+8*num)+1)/2;
        for (i=2; i<limit; i++) {
            temp2=1.0*num/i-(i-1)/2.0;
            temp1=temp2;
            if (temp1*1.0==temp2) count++;
        }
        printf("%d\n",count);
    }
    return 0;
}

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

int main(){
    string s, t;
    int n=0;

    cin >> s >> t;
    rep(i,3) if(s[i]==t[i]) n++;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

map<ll,ll> prime;
//素因数分解
void factor(ll x){
    for (ll i = 2; i<=sqrt(x); i++) {
        if(x%i==0){
            while(x%i == 0){
                x/=i;
                prime[i]++;
            }
        }
        if(x==1)break;
    }
    if(x != 0) prime[x]++;
}
int main(){
    ll n;
    cin >> n;
    ll ans = 0;

    for(ll i = 1; i <= n; i++){
        factor(i);
    }

    for(ll i = 2; i <= 98; i++){
        ll a = prime[i];
        if(a > 73) ans++;
        for(ll j = i+1; j <= 99; j++){
            ll b = prime[j];
            if(a > 3 && b > 13) ans++;
            if(b > 3 && a > 13) ans++;
            if(a > 1 && b > 23) ans++;
            if(b > 1 && a > 23) ans++;
            for(ll k = j+1; k <= 100; k++){
                ll c = prime[k];
                if(a > 1 && b > 3 && c > 3) ans++;
                if(b > 1 && a > 3 && c > 3) ans++;
                if(c > 1 && a > 3 && b > 3) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
arr=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K=input()
K=int(K)
print(arr[K-1])

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(ALL(a)); sort(rALL(f));
  ll l = -1, r = INF64;
  while(r - l > 1ll) {
    ll mid = l+(r-l)/2;
    ll kk = 0;
    rep(i, n) {
      if(a[i]*f[i] <= mid) continue;
      else {
        ll use = (f[i]*a[i] - mid)/f[i];
        if(use*f[i] < f[i]*a[i] - mid) ++use;
        kk += use;
      }
    }
    if(kk <= k) r = mid;
    else l = mid;
  }
  cout << r << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    string ans = "";
    rep(i, s.length()) ans += "x";

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

Measured memory_bytes: 256
using System;

class AtCoder
{    
    static void Main(string[] args)
     {
        var input = Console.ReadLine();

        var date = DateTime.Parse(input);

        var str = date <= new DateTime(2019, 4, 30) ? "Heisei" : "TBD";
        Console.Write(str);
     }
 }

Measured memory_bytes: 13660
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return list(map(proc, rl().split()))
    else:
        return rl().split()

def main():
    N = rl(int)
    for i in range(1, 50000):
        if i*108//100 == N:
            print(i)
            return
    print(":(")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int N,i,j=0,k=0;
    int p[100];
    int q[100];
    cin>>N;
    for(i=0;i<N;i++)
    {
        cin>>p[i];
    }
    for(i=0;i<N;i++)
    {
        q[i]=p[i];
    }
    sort(p,p+N);
    for(i=0;i<N;i++)
    {
        if(p[i]!=q[i])
        {
            k=k+1;
        }
    }
    if(k==0 || k==2)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
takoyaki = gets.split(" ")
takoyaki.map!{|item| item.to_i}
sum = 0
for i in 0..(n-1)
    for j in (i+1)..(n-1)
        sum = sum + takoyaki[i]*takoyaki[j]
    end
end
puts sum

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> wa(n), ac(n);
  for (int i = 0; i < m; i++) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if (ac[p] == false) {
      if (s == "WA")
        wa[p]++;
      else
        ac[p] = true;
    }
  }

  int seito = 0, mati = 0;
  for (int i = 0; i < n; i++) {
    seito += ac[i];
    mati += wa[i] * ac[i];
  }
  cout << seito << " " << mati << endl;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
    int x,y,temp;
    while(1){
        cin>>x>>y;
        if(x==0 && y==0){
            break;
        }
        else
        {
            if(x>y){
                temp=y;
                y=x;
                x=temp;
            }
            cout<<x<<" "<<y<<endl;
        }
    }
}


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

const int mod = 1000000007;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int dp[100020][13];
  memset(dp,0,sizeof(dp));
  if(s[0]=='?')rep(i,10)dp[0][i]=1;
  else dp[0][s[0]-'0']=1;
  for(int i=1;i<n;i++){
    if(s[i]=='?'){
      for(int j=0;j<13;j++){
        for(int l=0;l<10;l++){
          (dp[i][(j*10+l)%13]+=dp[i-1][j])%=mod;
        }
      }
    }else{
      int c = s[i]-'0';
      for(int j=0;j<13;j++){
        (dp[i][(j*10+c)%13]+=dp[i-1][j])%=mod;
      }
    }
    for(int j=0;j<13;j++)dp[i][j]%=mod;
  }
  // rep(i,n){
  //   rep(j,13){
  //     cout << dp[i][j] << ' ';
  //   }
  //   cout << endl;
  // }
  cout << dp[n-1][5] << endl;
  return 0;
}


Measured memory_bytes: 5632
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(N):
    if a[i] > x:
        cnt += a[i] - x
        a[i] = x

for i in range(1, N):
    #print(cnt)
    if a[i - 1]  + a[i] > x:
        cnt += (a[i - 1] + a[i] - x)
        a[i] -= ((a[i - 1] + a[i]) - x)
        #print(cnt)
    #print(a)
print(cnt)


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int w,h;
    while(cin>>h>>w, w|h){
        vvi g(w,vi(h));
        rep(i,h)rep(j,w) cin >> g[j][i];
        int m=0;
        rep(mask,1<<h){
            int s=0;
            rep(j,w){
                int c=0;
                rep(i,h) c += g[j][i] ^ (mask>>i & 1);
                s += max(c, h-c);
            }
            m=max( m , s );
        }
        cout << m << endl;
    }
}

Measured memory_bytes: 1860
import Data.List
import Data.Array.IO
import Control.Monad
import Control.Applicative
import Data.Int


primes = aux [2..]
  where aux (x:xs) = x : aux [y | y<-xs, y`mod`x/=0]

main = do
  n <- readLn :: IO Int
  let p = take 1000 primes
  
  arr <- newArray ((0,0),(n+1,n+1)) 1 :: IO (IOUArray (Int,Int) Int64)

  forM_ [(x,y) | x<-[1..n], y<-[1..n]] $ \(x,y) -> do
    when (even (x+y)) $ do
      writeArray arr (x,y) (p!!((x+y)`div`2-1))

  forM_ [(x,y) | x<-[1..n], y<-[1..n]] $ \(x,y) -> do
    when (odd (x+y+n)) $ do
      readArray arr (n-x+1,y) >>= \a -> writeArray arr (n-x+1,y) (a * p!!(n+(x+y)`div`2-1))

  forM_ [(x,y) | x<-[1..n], y<-[1..n]] $ \(x,y) -> do
    when (odd (x+y)) $ do
      a <- readArray arr (x-1,y)
      b <- readArray arr (x+1,y)
      c <- readArray arr (x,y-1)
      d <- readArray arr (x,y+1)
      writeArray arr (x,y) $ foldl lcm 1 [a,b,c,d] + 1

  if n == 2 then
    putStrLn "4 7\n23 10"
    else
    mapM_ putStrLn =<< (forM [1..n] $ \y -> unwords . map show <$> (forM [1..n] $ \x -> readArray arr (x,y)))



Measured memory_bytes: 31100
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(v) v.begin(),v.end()
#define mod 1000000007


int main(){
  string s;
  cin >> s;
  ll oddsize=0,evensize=0;
  oddsize=s.size()/2+s.size()%2;
  evensize=s.size()/2;
  ll odd=0,even=0;
  rep(i,oddsize){
    if(s[2*i]=='0')odd++;
  }
  rep(i,evensize){
    if(s[2*i+1]=='0')even++;
  }
  ll ans=0,res=0;
  ans=min(odd+evensize-even,even+oddsize-odd);

  cout << ans <<endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#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<ll,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int n,m;
vector<pint> v[2][101010];
ll a[2][101010],dist[2][101010];

void bfs(int x,int flag){
    priority_queue<pint,vector<pint>,greater<pint>> q;
    dist[flag][x]=0;
    q.push({0LL,x});
    while(q.size()){
        pint p=q.top();q.pop();
        ll d=p.first,now=p.second;
        if(dist[flag][now]<d)continue;
        for(auto to:v[flag][now]){
            if(dist[flag][to.second]>dist[flag][now]+to.first){
                dist[flag][to.second]=dist[flag][now]+to.first;
                q.push({dist[flag][to.second],to.second});
            }
        }
    }
}

int main(){
    cin>>n>>m;
    int s,t;
    cin>>s>>t;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        ll a,b;
        cin>>a>>b;
        x--;y--;
        v[0][x].push_back({a,y});
        v[1][x].push_back({b,y});
        v[0][y].push_back({a,x});
        v[1][y].push_back({b,x});
    }
    rep(i,n)rep(j,2)dist[j][i]=longinf;
    bfs(s-1,0);
    bfs(t-1,1);
    ll ans[n];
    rep(i,n)ans[i]=dist[0][i]+dist[1][i];
    rep(i,n-1)ans[n-i-2]=min(ans[n-i-1],ans[n-i-2]);
    rep(i,n)cout<<(ll)1e15-ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 20296
#include <cstdio>
#include <iostream>

using namespace std;

struct node {
	int parent, left, right;
};

int NIL_ALDS17B = -1;

void setDepth(int D[], node T[], int u, int depth) {
	if (u == NIL_ALDS17B) {
		return;
	}
	D[u] = depth;

	setDepth(D, T, T[u].left, depth + 1);
	setDepth(D, T, T[u].right, depth + 1);
}
int setHeight(int H[], node T[], int u) {
	int left = 0;
	int right = 0;

	if (T[u].left != NIL_ALDS17B)
		left = setHeight(H, T, T[u].left) + 1;

	if (T[u].right != NIL_ALDS17B)
		right = setHeight(H, T, T[u].right) + 1;

	return H[u] = (left > right ? left : right);
}

int getDegree(node T[], int u) {
	int cnt = 0;
	if (T[u].left != NIL_ALDS17B)
		++cnt;
	if (T[u].right != NIL_ALDS17B)
		++cnt;
	return cnt;
}

int getSibling(node T[], int u) {

	int ret = NIL_ALDS17B;

	if (T[u].parent == NIL_ALDS17B)
		return ret;


	if (T[T[u].parent].left != u && T[T[u].parent].left != NIL_ALDS17B)
		ret = T[T[u].parent].left;

	if (T[T[u].parent].right != u && T[T[u].parent].right != NIL_ALDS17B)
		ret = T[T[u].parent].right;

	return ret;

}
int main() {

	int n;
	scanf("%d", &n);

	node T[n];
	int D[n];
	int H[n];

	for (int i = 0; i < n; ++i) {
		T[i].parent = T[i].left = T[i].right = NIL_ALDS17B;
	}

	for (int i = 0; i < n; ++i) {
		int v, l, r;
		scanf("%d %d %d", &v, &l, &r);

		T[v].left = l;
		T[v].right = r;
		if (l != NIL_ALDS17B) {
			T[l].parent = v;
		}
		if (r != NIL_ALDS17B) {
			T[r].parent = v;
		}
	}
	int root;
	for (int i = 0; i < n; ++i) {
		if (T[i].parent == NIL_ALDS17B) {
			root = i;
			break;
		}
	}

	setDepth(D, T, root, 0);
	setHeight(H, T, root);

	for (int i = 0; i < n; ++i) {
		cout << "node " << i << ": parent = " << T[i].parent << ", sibling = ";
		cout << getSibling(T, i);
		cout << ", degree = ";
		cout << getDegree(T, i);
		cout << ", depth = " << D[i] << ", height = " << H[i] << ", ";
		if (T[i].parent == NIL_ALDS17B) {
			cout << "root";
		} else if (T[i].left == NIL_ALDS17B && T[i].right == NIL_ALDS17B) {
			cout << "leaf";
		} else {
			cout << "internal node";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main(){

    int n; cin >> n;
    string a, b, c; cin >> a >> b >> c;
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == b[i] && a[i] == c[i]){}
        else{
            if(a[i] != b[i] && a[i] != c[i] && b[i] != c[i]) ans += 2;
            else{
                ans++;
                
            }
            
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	string s, t;
	cin >> s >> t;

	vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1));

	for (int i = 1, s_len = (int)s.length(); i <= s_len; i++) {
		for (int j = 1, t_len = (int)t.length(); j <= t_len; j++) {

			if (s[i - 1] == t[j - 1] && dp[i][j] < dp[i - 1][j - 1] + 1) dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

		}
	}
	
	string ans;
	int x = (int)s.length(), y = (int)t.length();
	while (x > 0 && y > 0) {

		if (dp[x][y] == dp[x - 1][y]) x--;
		else if (dp[x][y] == dp[x][y - 1]) y--;
		else {
			ans.push_back(s[x - 1]);
			x--, y--;
		}
	}

	reverse(ans.begin(), ans.end());
	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
constexpr ll M = 1e9+7;
 
int n;
int dp[51][51][21][28];
string s[51];
 
int rec(int l, int r, int p, int c) {
    int& res = dp[l][r][p][c];
    if(res != -1) {
        return res;
    }
    if(l >= r) {
        return res = 1;
    }
    if(c == 27) {
        return res = 0;
    }
    if(p == s[l].size()) {
        return res = (l + 1 == r);
    }
    res = 0;
 
    char cc = 'a' - 1 + c;
    for(int i = l; i <= r; ++i) {
        (res += 1LL * rec(l, i, p + 1, 0) * rec(i, r, p, c + 1) % M) %= M;
        if(i != r && s[i][p] != '?' && s[i][p] != cc) {
            break;
        }
        if(i != r && s[i][p] == '?' && c == 0) {
            break;
        }
    }
    return res;
}
 
int main() {
    cin >> n;
    int max_len = 0;
    for(int i = 0; i < n; ++i) {
        cin >> s[i];
        max_len = max(max_len, (int)s[i].size());
    }
    for(int i = 0; i < n; ++i) {
        s[i] = s[i] + string(max_len - s[i].size(), 'a' - 1);
    }
    fill(dp[0][0][0], dp[51][0][0], -1);
    cout << rec(0, n, 0, 0) << endl;
}


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

ll dp[400][400];
ll slime[400][400];
ll v[400];

ll f(int a, int b) {
	if (b == a) return v[a];
	if (dp[a][b]) return dp[a][b];

	ll r = 1e18;
	for (int i = a; i < b; ++i) {
		f(a, i);
		f(i+1, b);
		ll x = slime[a][i] + slime[i+1][b] + dp[a][i] + dp[i+1][b];
		if (x < r) {
			slime[a][b] = slime[a][i] + slime[i+1][b];
			r = x;
		}
	}
	dp[a][b] = r;
	return r;
}

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

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) cin >> v[i];
	for (int i = 0; i < n; ++i) slime[i][i] = v[i];

	cout << f(0, n-1) << '\n';
}


Measured memory_bytes: 2816
n=int(input())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))

def b(n,k):
    return (n>>k)&1
MOD=10**9+7

dp=[[0 for j in range(1<<n)] for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    for S in range(1<<n):
        if (dp[i][S]):
            for j in range(n):
                if (b(S,j)==0 and a[i][j]==1):
                    dp[i+1][S^(1<<j)]+=(dp[i][S^(1<<j)]+dp[i][S])%MOD
                    dp[i+1][S^(1<<j)]%=MOD
print(dp[n][-1])

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e5) + 5;
const int MAX_A = int(15e6);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir = "RDLU";
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


ll factrial[MAX_N], inverse[MAX_N];  //階乗と逆元を保持

ll mod_power(ll x, ll n) {  //繰り返し二乗法
    ll res = 1;
    while (n > 0) {
        if (n & 1) {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

void init(ll n) {
    factrial[0] = 1;
    inverse[0] = 1;
    for (ll i = 1; i <= n; i++) {
        factrial[i] = (factrial[i - 1] * i) % MOD;  //階乗を求める
        inverse[i] = mod_power(factrial[i], MOD - 2) % MOD;  //オイラーの定理で逆元を求める
    }
}

ll nCk(ll n, ll k) {
    if(n < 0 || k < 0 || n < k) return 0;
    return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}


int main() {
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    init(h+w);
    ll ans = 0;
    for(ll i = h-a-1, j = b; i>=0 && j<=w; i--, j++){
        ans += nCk(i+j,j) * nCk(h+w-i-j-2,w-j-1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int h, m, s;
    cin >> s;
    h = s / 3600;
    s = s % 3600;
    m = s / 60;
    s = s % 60;
    
    printf("%d:%d:%d\n", h, m, s);

    return 0;
}



Measured memory_bytes: 3200
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

ll n;
ll a[100000], b[100000];

int main(){
  cin >> n;
  rep(i, n) cin >> a[i] >> b[i];
  ll k = 0, res = 0;
  rrep(i, n){
    ll t = (a[i] + k + b[i] - 1) / b[i] * b[i];
    res += t - (a[i] + k);
    k += t - (a[i] + k);
  }
  cout << res << endl;
}


Measured memory_bytes: 1920
# alter altar
length = int(input())
stone = input()
red = [0] * (length + 1)
white = [0] * (length + 1)
[red_num, white_num] = [0, 0]
for i in range(1, length + 1):
	if(stone[i-1] == "W"):
		white_num += 1
	if(stone[length-i] == "R"):
		red_num += 1
	white[i] = white_num
	red[length - i] = red_num
# print(white)
# print(red)
mini = 200000
for i in range(0, length+1):
	trial = max(white[i], red[i])
	mini = min(mini, trial)
print(mini)

Measured memory_bytes: 18628
#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
    char ch = getchar(); x = 0;
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 2e5 + 10;
int n, ans, res;
signed main() {
    read (n);
    for (int i = 1; i <= n; ++i) res += i * (n - i + 1);
    for (int i = 1, u, v; i < n; ++i) {
        read (u), read (v);
        if (u > v) swap (u, v);
        res -= u * (n - v + 1);
    } return printf ("%lld\n", res), 0;
}


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

vector<int> v[100001];

int main(){
    int n,m,ans = 0;
    cin >> n >> m;
    for(int i = 0;i < n;i ++){
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
    }
    priority_queue<int> pq;
    for(int i = 1;i <= m;i ++){
        for(int j = 0;j < v[i].size();j ++){
            pq.push(v[i][j]);
        }
        if(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
use proconio::input;
use std::cmp::{max, min};

const MAX_L: usize = 100_000;
const BASE_SIZE: usize = 1 << 10;

fn main() {
    input! {
        n: usize,
        vw: [(u32, u32); n],
        q: usize,
        vl: [(usize, usize); q],
    }
    let dp = make_dp(&vw);
    for vlq in vl {
        println!("{}", calc(&vw, vlq.0 - 1, vlq.1, &dp));
    }
}

fn make_dp(vw: &Vec<(u32, u32)>) -> Vec<Vec<u32>> {
    let mut dp = Vec::<Vec<u32>>::new();

    dp.push(
        (0..=MAX_L)
        .map(|i| if (i as u32) < vw[0].1 { 0 } else { vw[0].0 })
        .collect()
    );

    let n = min(vw.len(), BASE_SIZE - 1);
    for c in 1..n {
        let p = (c - 1) / 2;
        dp.push(
            (0..=MAX_L)
            .map(|i| {
                let w = vw[c].1;
                let v = if (i as u32) < w { 0 } else { dp[p][i - w as usize] + vw[c].0 };
                max(dp[p][i], v)
            })
            .collect()
        );
    }

    dp
}

fn calc(
    vw: &Vec<(u32, u32)>,
    u: usize, 
    l: usize,
    dp: &Vec<Vec<u32>>
) -> u32 {
    if u < dp.len() {
        dp[u][l]
    } else {
        let p = (u - 1) / 2;
        let w = vw[u].1;
        let pv1 = calc(vw, p, l, dp);
        let pv2 = if (l as u32) < w { 0 } else { calc(vw, p, l - w as usize, dp) + vw[u].0 };
        max(pv1, pv2)
    }
}


Measured memory_bytes: 410912
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

signed main(void) {
  int n;
  cin >> n;
  vector<int> d;
  rep(i, n) {
  	int tmp; 
  	cin >> tmp;
  	d.pb(tmp);
  }

  SORT(d);
  
  int ans = d[n/2] - d[n/2-1];
  
  cout << ans << endl;

  return 0;
}


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

int main() {
  int m, f, r;
  
  for (int i=0; i<=50; i++) {
    cin >> m >> f >> r;
    if (m==-1 && f==-1 && r==-1) break;
    else {
      if (m ==-1 || f==-1) cout << "F" << endl;
      else if (m+f >= 80) cout << "A" << endl;
      else if (65 <= m+f && m+f < 80) cout << "B" << endl;
      else if (50 <= m+f && m+f < 65) cout << "C" << endl;
      else if (30 <= m+f && m+f < 50) {
        if (r >= 50) cout << "C" << endl;
        else cout << "D" << endl;
      }
      else cout << "F" << endl;
    }
  }
  
//中間試験、期末試験のいずれかを欠席した場合成績は F。
//中間試験と期末試験の合計点数が 80 以上ならば成績は A 。
//中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。
//中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。
//中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 ただし、再試験の点数が 50 以上ならば成績は C。
//中間試験と期末試験の合計点数が 30 未満ならば成績は F。
  
  return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>

main(){
  int hw[100][100];
  int h,w,n,i,j,count=0,ans=0;
  
  scanf("%d",&h);
  scanf("%d",&w);
  
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      hw[i][j]=0;
    }
  }
  
  scanf("%d",&n);
  
  if(h<=w)  
   for(i=0;i<h;i++){
    ans=ans+1;
    for(j=0;j<w;j++){
      hw[i][j]=1;
      count++;
      if(count==n)
        break;
    }
    if(count==n)
        break;
   }
  else
    for(i=0;i<w;i++){
      ans=ans+1;
      for(j=0;j<h;j++){
       hw[j][i]=1;
       count++;
       if(count==n)
         break;
     }
     if(count==n)
        break;
    }
  printf("%d",ans);
  
  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;

namespace ABC
{
    class ABC096D
    {
        public static int N = 0;
        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());//長さ

            var ans = findAnswer();

            ans.Sort();
            Console.WriteLine(string.Join(" ", ans.ToArray()));
        }

        static List<int> findAnswer()
        {
            //解説より
            //5で割って、1余る素数列を作る
            var ans = new List<int>(N);
            for(int i = 11; i <= 55555; i += 5)//いちばん最初に候補になる素数である11から開始.次の候補まで一気に5増加すれば必ず5で割って1余る
            {
                if(isPrime(i) == true)
                {
                    ans.Add(i);
                    if(ans.Count == N)
                    {
                        return ans;
                    }
                }
            }
            //ここには多分こない
            return null;
        }
        public static bool isPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
    }
}



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector

int main(void)
{
	int n, t;
	cin >> n >> t;
	vec<int> a(n);
	rep(i, n) cin >> a[i];
	int MIN = 1000000007;
	int diffmax = - 1;
	int ans = 1;

	rep(i, n) {
		MIN = min(MIN, a[i]);
		if (diffmax < a[i] - MIN) {
			diffmax = a[i] - MIN;
			ans = 1;
		} else if (diffmax == a[i] - MIN) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;



int main() {
    int S,h,m,s;
    cin >>S;
    h=S/3600;
    m=(S%3600)/60;
    s=S%60;
   cout <<h<<":"<<m<<":"<<s<<endl;
}


Measured memory_bytes: 3108
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		PriorityQueue<Team> queue = new PriorityQueue<>();
		boolean isFirst = true;
		while (true) {
		    int n = sc.nextInt();
		    if (n == 0) {
		        break;
		    }
		    if (!isFirst) {
    		    sb.append("\n");
		    }
		    isFirst = false;
		    for (int i = 0; i < n; i++) {
		        queue.add(new Team(i, sc.next(), sc.nextInt(), sc.nextInt(), sc.nextInt()));
		    }
		    while (queue.size() > 0) {
		        sb.append(queue.poll()).append("\n");
		    }
		}
		System.out.print(sb);
	}
	
	static class Team implements Comparable<Team> {
	    int idx;
	    String name;
	    int point;
	    
	    public Team(int idx, String name, int win, int lose, int draw) {
	        this.idx = idx;
	        this.name = name;
	        this.point = win * 3 + draw;
	    }
	    
	    public int compareTo(Team another) {
	        if (point == another.point) {
	            return idx - another.idx;
	        } else {
	            return another.point - point;
	        }
	    }
	    
	    public String toString() {
	        return name + "," + point;
	    }
	}
}



Measured memory_bytes: 27384
s = input()
x = "abcdefghijklmnopqrstuvwxyz"
y,y2,z = [[-1,0] for i in range(26)],[],len(s)
for i in range(z):
	a = x.find(s[i])
	y[a][0],y[a][1] = i,max(i-y[a][0]-1,y[a][1])
for i in y:
	if i[1]!=0: y2.append(max(i[1],z-i[0]-1))
if y2==[]: print(0)
else: print(min(y2))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    switch(n % 10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
    }
    return 0;
}

Measured memory_bytes: 3632
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  string s0,s1,s2;
  cin >> s0 >> s1 >> s2;
  cout << char('A'+s0.front()-'a');
  cout << char('A'+s1.front()-'a');
  cout << char('A'+s2.front()-'a');
  cout << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair<A, B> {
	A first;
	B second;

	Pair(A first, B second) {
		this.first = first;
		this.second = second;
	}

}

class TaskB {
	int INF = (int) 1e3 + 5;
	long mod = (long) 1e9 + 7;

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int H = in.nextInt();
		int W = in.nextInt();
		long dp[][] = new long[H + 1][W + 1];
		for (int i = 0; i < W + 1; i++) {
			dp[0][i] = 0;
		}
		for (int j = 0; j < H + 1; j++) {
			dp[j][0] = 0;
		}
		dp[1][1] = 1;
		for (int i = 1; i <= H; i++) {
			String tc = in.next();
			char arr[] = tc.toCharArray();
			for (int j = 1; j <= W; j++) {
				if (arr[j - 1] != '#') {
					dp[i][j] += (dp[i][j - 1] + dp[i - 1][j]) % mod;
				}
			}
		}
//		for (int i = 0; i <= H; i++) {
//			for (int j = 0; j <= W; j++) {
//				pw.print(dp[i][j] + " ");
//			}
//			pw.println();
//		}
		pw.println(dp[H][W] % mod);
	}

	boolean FirstRow_Col(Pair<Integer, Integer> pair) {
		return pair.first == 0 || pair.second == 0;
	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

int main() {
	int N,A;
	cin >> N>>A;
	N %= 500;
	if (N<=A) {
		cout << "Yes"<<endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF 2e15
#define MOD 10e9 + 7

typedef vector <int> vint;
typedef long long    ll;



int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int    n;
    string s;
    cin >> n;
    cin >> s;
    vector <char> ans(s.size());
    rep(i, s.size()) {
        ans.at(i) = (s.at(i) + n - 65) % 26 + 65;
        // cout << ans.at(i) << endl;
    }
    rep(i, s.size()) {
        cout << ans.at(i);
    }
    cout << endl;





    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>

#define FOR(i,j,k) for((i)=(j);(i)<(k);i++)

using namespace std;

int main(void)
{
	int n=0;
	double x[20],y[20];
	double ans=0;
	while(scanf("%lf,%lf",&x[n],&y[n])!=EOF) n++;
	for(int i=1;i<=n-2;i++){
		double a=sqrt((x[0]-x[i])*(x[0]-x[i])+(y[0]-y[i])*(y[0]-y[i]));
		double b=sqrt((x[i]-x[i+1])*(x[i]-x[i+1])+(y[i]-y[i+1])*(y[i]-y[i+1]));
		double c=sqrt((x[i+1]-x[0])*(x[i+1]-x[0])+(y[i+1]-y[0])*(y[i+1]-y[0]));
		double z=(a+b+c)/2;
		double s=sqrt(z*(z-a)*(z-b)*(z-c));
		ans+=s;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
  int a; cin >> a;
  cout << a+(a*a)+(a*a*a) << endl;
  return 0;
}

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

int main(){
  int N; cin >> N;
  long double r=0;
  for(int i=0;i<N;i++){
    long double x; cin >> x;
    string u; cin >> u;
    if(u=="JPY"){
      r += x;
      
    }else{
      r += x * 380000;
    }
    
  }
  cout << r << endl;
}

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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int d[10][10] = { 0 };

	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		d[a][b] = d[b][a] = 1;
	}
	vector<int> cc;
	for (int i = 2; i <= n; i++) {
		cc.push_back(i);
	}
	long long int ans = 0;
	do {
		bool h = true;
		for (int i = 0; i+1 < cc.size(); i++) {
			if (d[cc[i]][cc[i + 1]] == 0) {
				h = false;
			}
		}
		if (d[1][cc[0]] == 0) {
			h = false;
		}
		if (h) {
			ans++;
		}
	} while (next_permutation(cc.begin(), cc.end()));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

h,w,d = inpl()
a = [inpl() for i in range(h)]
de = defaultdict(int)
for i in range(h):
    for j in range(w):
        de[a[i][j]] = (i,j)
li = dict()
for i in range(d):
    c = 0
    tmp = 0
    while True:
        if de[i+d*c] == 0:
            c += 1
            continue
        tmp = de[i+d*c]
        break
    li[i+d*c] = 0
    while True:
        c += 1
        if de[i+d*c] == 0:
            break
        now = de[i+d*c]
        kyori = abs(now[0]-tmp[0]) + abs(now[1]-tmp[1])
        li[i+d*c] = li[i+d*(c-1)] + kyori
        tmp = now
# print(li)
q = inp()
lr = [inpl() for i in range(q)]
for l,r in lr:
    print(li[r] - li[l])


Measured memory_bytes: 121824
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using ll = long long;

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

    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    Bint sum = 1;
    REP(i, n) {
        sum *= a[i];
        if (sum > 1000000000000000000) {
            sum = -1;
            break ;
        }
    }

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

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

using namespace std;

int main() {
	int K, S;
	int count = 0;

	cin >> K >> S;

	for (int x = 0;x <= K;x++) {
		for (int y = 0;y <= K;y++) {
			int z = S - x - y;
			if (0 <= z and z <= K)
				count++;
		}

	}
		

	cout << count << endl;
}

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

int main()
{
	int n, a[1000], ans=0, b=0, c=0;
	cin >> n;
	
	for (int i=1; i<=n; ++i)
		cin >> a[i];
	
	for (int i=1; i<=n; ++i)
	{
		if(a[i]%2!=0)
			b++;
		
		else
		{
			if(a[i]%3==0)
				ans++;
		
			else if(a[i]%5==0)
				ans++;
			
			else if(a[i]%3==0 && a[i]%5==0)
				{
					if(ans!=0)
						ans--;
					else 
						ans++;
				}
				
			else
				c++;
		}
	}
	
	if (ans+b==n)
		cout << "APPROVED" << endl;
	
	if (c!=0 && ans+b+c==n)
		cout << "DENIED" << endl;
	
	return 0;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n;
int s[200005];

int stk[200005], level[200005], p;

void print_stack(){
	printf("STACK: \n");
	for(int i = 1; i <= p; i++){
		printf("  i = %d: %d %d\n", i, stk[i], level[i]);
	}
}
bool ok(int alp){
//	printf("alp = %d\n", alp);
	// can form the strings with alphabet size alp?
	p = 0;
	for(int i = 1; i <= n; i++){
		bool clear_stuff = false;
		while(p > 0 && s[i] < stk[p]){
			clear_stuff = true;
			p--;
		}
		// here s[i] >= stk[p]
		if(p > 0 && s[i] == stk[p]){
			// could be a chain reaction!
			level[p]++;
		}else{
			stk[++p] = s[i];
			if(clear_stuff){
				level[p] = 2;
			}else{
				level[p] = 1;
			}
		}
		
//		print_stack();
		
		if(level[p] <= alp){
			continue;
		}
		while(level[p] > alp){
			if(p > 1 && stk[p - 1] == stk[p] - 1){
				level[p - 1]++;
				p--;
			}else{
				stk[p]--;
				if(stk[p] == 0){
					return false;
				}
				level[p] = 2;
				break;
			}
		}
		// need to add this at the end...
		stk[++p] = s[i];
		level[p] = 1;
//		printf("AFTER..");
//		print_stack();
	}
	return true;
}

int main(){
	scanf("%d", &n);
	bool can_one = true;
	for(int i = 1; i <= n; i++){
		scanf("%d", &s[i]);
		if(i > 1 && s[i] <= s[i - 1]){
			can_one = false;
		}
	}
	if(can_one){
		printf("1\n");
		return 0;
	}
	int l = 1, r = n;
	while(r - l > 1){
		int m = (l + r) >> 1;
		if(ok(m)) r = m;
		else l = m;
	}
	printf("%d\n", r);
	return 0;
}

Measured memory_bytes: 1536
n = input().split()

n = [int(n[0]), int(n[1])]
H = n[0]
W=n[1]

s = [list(map(str, input().split())) for i in range(H)]

c = True
for i in range(H):
    for j in range(W):
        if(s[i][0][j] == '#'):
            if(i == 0):
                if(j == 0):
                    if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.'):
                        c = False
                        break
                elif(j == W - 1):
                    if(s[i+1][0][j ] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
                else:
                     if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
            elif(i == H - 1):
                if(j == 0):
                    if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.'):
                        c = False
                        break
                elif(j == W - 1):
                    if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
                else:
                     if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
            else:
                if(j == 0):
                    if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.' and s[i + 1][0][j] == '.'):
                        c = False
                        break
                elif(j == W - 1):
                    if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
                        c = False
                        break
                else:
                     if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
                        c = False
                        break
                
    
if(c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3192
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d,e, H, W;
long long A[200005] = {};
long long B[201][201] = {};
long long C[200005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;

char ch[100][100];

int main() {


	cin >> N;
	

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

	b = 0;
	d = 10000000000;
	for (int i = 0; i < N; i++) {
		
		b += A[i];
		c = abs(a - 2*b);

		if (d > c) {
			d = c;
		}
		

	}

	cout << d << endl;
	
	return 0;

}


Measured memory_bytes: 4352