akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int n;cin>>n;
    vector<ll> v(100);
    v[0]=2; v[1]=1;
    for(int i=2;i<100;i++) v[i]=v[i-1]+v[i-2];
    cout<<v[n]<<endl;
}


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


int main() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N, -1);

  for(int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;

    if(num[s] == -1 || num[s] == c) num[s] = c;
    else {
      cout << -1;
      return 0;
    }
  }
  if(N == 1 && num[0] != -1) cout << num[0];
  else if(N == 1 && num[0] == -1) cout << 0;
  else if(num[0] != 0) {
    if(num[0] == -1) num[0] = 1;
    for(int& x : num) if(x== -1) x = 0;
    for(int x: num) printf("%1d", x);
  } else cout << -1;
}




Measured memory_bytes: 256
import Control.Applicative

main :: IO ()
main = do
  { [x] <- readLineInputs :: IO [Int]
  ; print $ case divMod x 11 of
              (q, r) | r == 0 -> q * 2
                     | r <= 6 -> q * 2 + 1
                     | otherwise -> q * 2 + 2
  }


readLineInputs :: Read a => IO [a]
readLineInputs = map read . words <$> getLine


Measured memory_bytes: 508
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	int a;
	cin >> a;
	int b, c;
	if (a % 2 == 1) {
		b = a / 2;
		c = a / 2 + 1;
	}
	else {
		b = a / 2;
		c = a / 2;
	}
	cout << b * c;
	ed;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 10 21:13:02 2020

@author: masat
"""
import math

N = int(input())
P_list = list(map(int, input().split()))
Q_list = list(map(int, input().split()))

def jishojun(a_list):
    dist = 0
    for i in range(N):
        sorted_slice = sorted(a_list[i:])
        dist += math.factorial(N-i-1) * sorted_slice.index(a_list[i])
    return dist

answer = abs(jishojun(P_list) - jishojun(Q_list))
print(answer)


Measured memory_bytes: 3064
//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


namespace {
    // printElems(&a[0], &a[n]);　みたいな感じで使う。
    void printElems(const int* begin, const int* end)
    {
        for (const int* p = begin; p != end; ++p) {
            std::cout << *p << ' ';
        }
        std::cout << std::endl;
    }
}

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 1LL<<60;



D zahyou[10][2];

int main(){
	int n;
	cin >> n;
	rep(i,n) cin >> zahyou[i][0] >> zahyou[i][1];

	vi v;
	rep(i,n) v.push_back(i);

	D ans = 0.0;
	int cnt = 0;

	do {
		cnt++;
		D anstmp = 0;
		rep1(i,n-1){
			anstmp+=sqrt(pow(zahyou[v[i]][0]-zahyou[v[i-1]][0],2)+pow(zahyou[v[i]][1]-zahyou[v[i-1]][1],2));
		}
		ans += anstmp;
	} while (std::next_permutation(v.begin(), v.end()));

	printd(ans/cnt);


	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int f[100005],t[100005],n,x,i;vector<int>e[100005];
void dfs(int x)
{
	for(int i=0;i<e[x].size();i++) dfs(e[x][i]);
	for(int i=0;i<e[x].size();i++) t[i]=f[e[x][i]];
	sort(t,t+(int)e[x].size());
	for(int i=1;i<e[x].size();i++) if(t[i]<=t[i-1]) t[i]=t[i-1]+1;
	if(e[x].size()) f[x]=t[(int)e[x].size()-1]+1;
}
int main(){for(scanf("%d",&n),i=2;i<=n;i++) scanf("%d",&x),e[x].push_back(i);dfs(1);printf("%d\n",f[1]);}

Measured memory_bytes: 10880
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

double xs[MAX_N], ys[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) cin >> xs[i];
  for (int i = 0; i < n; i++) cin >> ys[i];

  double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0, maxd = 0.0;

  for (int i = 0; i < n; i++) {
    double d = abs(xs[i] - ys[i]);
    sum1 += d;
    sum2 += d * d;
    sum3 += d * d * d;
    if (maxd < d) maxd = d;
  }

  printf("%.6lf\n", sum1);
  printf("%.6lf\n", sqrt(sum2));
  printf("%.6lf\n", pow(sum3, 1.0 / 3));
  printf("%.6lf\n", maxd);

  return 0;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b, int mod)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

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

#define N 100010
#define MOD 1000000007

struct comp {
    bool operator() (const pair<int, int> a, const pair<int, int> b) const
    {
        return a.ss > b.ss;
    }
};

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n;
    cin >> n;
    int a[n][3];

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

    int dp[2][3] = {};
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    for (int i = 1; i < n; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            dp[i % 2][j] = a[i][j] + max(dp[(i - 1) % 2][(j + 1) % 3], dp[(i - 1) % 2][(j + 2) % 3] );
        }
    }

    cout << *max_element(dp[(n - 1) % 2], dp[(n - 1) % 2] + 3);
    return 0;
}

Measured memory_bytes: 5972
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
maxi = 0
for k,v in c.items():
  if k-1 in c:
    v += c[k-1]
  if k+1 in c:
    v += c[k+1]
  maxi = max(maxi,v)
print(maxi)

Measured memory_bytes: 14564
cookie = list(map(int,input().split()))

if len(set(cookie)) == 1 and all([i % 2 == 0 for i in cookie]):
  print(-1)
else:
  con = 0
  while all([i % 2 == 0 for i in cookie]):
    a = cookie[0] // 2
    b = cookie[1] // 2
    c = cookie[2] // 2
    cookie[0] = b + c
    cookie[1] = c + a
    cookie[2] = a + b
    con += 1
  print(con)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y;

int main()
{
    cin >> W >> A >> B;
    if (A + W < B) cout << abs(B-(A+W)) << endl;
    else if (B + W < A) cout << abs(A-(B+W)) << endl;
    else cout << 0 << endl; 

    return 0;
}

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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

bool IsPrime(int);

/***** MAIN *****/
signed main() {
  int price, hyaku, ju;
  cin >> price;
  if(price < 100) {
    cout << 0 << endl;
    return 0;
  }
  hyaku = floor(price / 100);
  ju = price - (hyaku * 100);
  if(ju <= hyaku * 5) {
    cout << 1;
  } else {
    cout << 0;
  }

  cout << "\n";
  return 0;
}
/***** MAIN *****/

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

Measured memory_bytes: 384
n,m,x,y = gets.chomp.split(" ").map!{|i| i.to_i}
xi = gets.chomp.split(" ").map!{|k| k.to_i}
yi = gets.chomp.split(" ").map!{|l| l.to_i}
xi.sort!
yi.sort!

frag = "War"
if x < y and xi[-1] < yi[0] and x < yi[0] and xi[-1] < y
  frag = "No War"
end
puts frag 


Measured memory_bytes: 3836
#include<iostream>
using namespace std;
int main()
{
    int n,a,b,c,d,e,f,g,h,temp=0;
    cin>>n;
    if(1<=n && n<=9) cout<<"Yes"<<endl;
    else if(10<=n && n<=99)
    {
        temp=n;
        a=n/10;
        n%=10;
        if(temp%(a+n)==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(100<=n && n<=999)
    {
        temp=n;
        a=n/100;
        n%=100;
        b=n/10;
        n%=10;
        if(temp%(a+b+n)==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(1000<=n && n<=9999)
    {
        temp=n;
        a=n/1000;
        n%=1000;
        b=n/100;
        n%=100;
        c=n/10;
        n%=10;
        if(temp%(a+b+c+n)==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(10000<=n && n<=99999)
    {
        temp=n;
        a=n/10000;
        n%=10000;
        b=n/1000;
        n%=1000;
        c=n/100;
        n%=100;
        d=n/10;
        n%=10;
        if(temp%(a+b+c+d+n)==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(100000<=n && n<=999999)
    {
        a=n/100000;
        n%=100000;
        b=n/10000;
        n%=10000;
        c=n/1000;
        n%=1000;
        d=n/100;
        n%=100;
        e=n/10;
        n%=10;
        if(temp%(a+b+c+d+e+n)==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(1000000<=n && n<=9999999)
    {
        temp=n;
        a=n/1000000;
        n%=1000000;
        b=n/100000;
        n%=100000;
        c=n/10000;
        n%=10000;
        d=n/1000;
        n%=1000;
        e=n/100;
        n%=100;
        f=n/10;
        n%=10;
        if(temp%(a+b+c+d+e+f+n)==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(10000000<=n && n<=99999999)
    {
        temp=n;
        a=n/10000000;
        n%=10000000;
        b=n/1000000;
        n%=1000000;
        c=n/100000;
        n%=100000;
        d=n/10000;
        n%=10000;
        e=n/1000;
        n%=1000;
        f=n/100;
        n%=100;
        g=n/10;
        n%=10;
        if(temp%(a+b+c+d+e+f+g+n)==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(100000000<=n && n<=999999999)
    {
        temp=n;
        a=n/100000000;
        n%=100000000;
        b=n/10000000;
        n%=10000000;
        c=n/1000000;
        n%=1000000;
        d=n/100000;
        n%=100000;
        e=n/10000;
        n%=10000;
        f=n/1000;
        n%=1000;
        g=n/100;
        n%=100;
        h=n/10;
        n%=10;
        if(temp%(a+b+c+d+e+f+g+h+n)==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(n==1000000000) cout<<"Yes"<<endl;

    return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> x(N);
  for(int i=0;i<N;i++){
    cin>>x[i];
  }
  
  long long ans=10000000;
  for(int i=0;i<100;i++){
    long long d=0;
    for(int j:x){
      d=d+pow(j-i,2);
    }
    ans=min(ans,d);
  }
  
  cout<<ans;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
PY = [[] for i in range(m)]
for i in range(m):
  PY[i] = list(map(int, input().split()))
  PY[i].append(i)
  
PY.sort(key = lambda x:x[1])

l = [0]*(n)
for i in range(m):
  l[PY[i][0]-1]+=1
  PY[i].append(l[PY[i][0]-1])

  
PY.sort(key = lambda x:x[2])
for i in range(m):
  print('{:0=6}'.format(PY[i][0])+'{:0=6}'.format(PY[i][3]))

Measured memory_bytes: 73504
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    X, Y = MI()
    for i in range(X + 1):
        if i * 4 + (X - i) * 2 == Y:
            print("Yes")
            sys.exit()
    print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 78068
#include <bits/stdc++.h>
#define MAX_N 100000
#define mid ((l+r)>>1)
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, a[MAX_N+5], b[MAX_N+5];
int s[MAX_N+5], tr[MAX_N*2+5];
void inc(int p) {for (; p <= n*2+1; p += (p&-p)) tr[p]++;}
int sum(int p) {int ret = 0; for (; p; p -= (p&-p)) ret += tr[p]; return ret;}
bool chk(int x) {
	lnt tot = 0; memset(tr, 0, sizeof tr);
	for (int i = 1; i <= n; i++)
		s[i] = s[i-1]+(a[i] >= x ? 1 : -1);
	for (int i = 0; i <= n; i++)
		tot += sum(s[i]+n+1), inc(s[i]+n+1);
	return tot >= 1LL*n*(n+1)/4;
}
int bi_solve(int l, int r) {
	int ret = 0;
	while (l <= r)
		if (!chk(b[mid])) r = mid-1;
		else ret = mid, l = mid+1;
	return ret;
}
int main() {
	read(n); for (int i = 1; i <= n; i++) read(a[i]), b[i] = a[i];
	return sort(b+1, b+n+1), printf("%d\n", b[bi_solve(1, n)]), 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int count[10002] {0};
    int a[10002], b[10002];
    ll c[10002];
    vector<int> v[10002];
    for(int i = 0; i < n - 1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
        count[a[i]]++;
        count[b[i]]++;
    }
    ll sum = 0;
    ll lar = 0;
    for(int i = 0; i < n; i++){
        cin >> c[i];
        sum += c[i];
        lar = max(lar, c[i]);
    }
    sum -= lar;
    sort(c, c + n);
    int val[10002];
    int nextc = 0;
    queue<int> que;
    for(int i = 0; i < n; i++){
        if(count[i] == 1){
            que.push(i);
        }
    }
    while(que.size()){
        int nowv = que.front();
        que.pop();
        val[nowv] = nextc;
        nextc++;
        int nextv = v[nowv][0];
        count[nextv]--;
        auto itr = find(v[nextv].begin(), v[nextv].end(), nowv);
        v[nextv].erase(itr);
        if(count[nextv] == 1) que.push(nextv);
    }
    cout << sum << endl;
    for(int i = 0; i < n; i++){
        cout << c[val[i]] << " ";
    }
    cout << endl;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

set<ll> st;

int main() {
    ll n, m;
    cin >> n;
    m = n;
    st.insert(n);
    for (ll i = 2; i * i <= m; ++i) {
        if (m % i == 0) {
            ll t = n;
            while (t % i == 0)
                t /= i;
            if(t % i == 1)
                st.insert(i);
            t = n;
            while (t % (m / i) == 0)
                t /= (m / i);
            if (t % (m / i) == 1)
                st.insert(m / i);
        }
    }
    m = n - 1;
    if (n % m != 0)
        st.insert(m);
    for (ll i = 2; i * i <= m; ++i) {
        if (m % i == 0) {
            if (n % i != 0) {
                st.insert(i);
            }
            if (n % (m / i) != 0) {
                st.insert(m / i);
            }
        }
    }
    
    cout << st.size() << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
p = list(map(float, input().split()))

dp = np.zeros(len(p)+1)
dp[0] = 1 - p[0]
dp[1] = p[0]

for i in range(1, len(p)):
    ura = dp * (1 - p[i])
    omote = np.append(np.zeros(1), dp[:-1] * p[i])
    dp = ura + omote

print(np.sum(dp[len(p)//2+1:]))

Measured memory_bytes: 12504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	int n = sca.nextInt();
	int ans = 0;
	if(n % 2 == 0) {
		ans = n / 2;
	}
	else {
		ans = n / 2 + 1;
	}

	System.out.println(ans);
	// 後始末
	sca.close();
	}
}

Measured memory_bytes: 23764
import numpy as np
from fractions import gcd
def main():
    n, X = map(int, input().split())
    x = list(map(int, input().split()))
    x.append(X)
    x.sort()
    x = np.array(x)
    dif = np.diff(x)
    ans = 0
    for v in dif:
        ans = gcd(ans, int(v))
    print(ans)

if __name__ == "__main__":
    main()


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

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

Measured memory_bytes: 256
/*input
100
1
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4+5,N2 = 101,mod=1e9+7;
int dp[2][N2][N];
int D;

int fun(int pos,int f,int sum,string &s) //f==0 prefix equal
{
	if(pos==(int)s.size()) return (sum==0);
	if(dp[f][sum][pos]!=-1) return dp[f][sum][pos];

	int L = 9;
	if(!f) L = s[pos]-'0';

	int ans=0;
	for(int d=0;d<=L;d++)
	{
		int nd = 1;
		if(f==0 && d==L) nd=0;

		int nsum = (sum+d)%D;
		ans+=fun(pos+1,nd,nsum,s);
		ans%=mod; 
	}

	return dp[f][sum][pos]=ans;

}	

int main()
{
	memset(dp,-1,sizeof dp);
	string s;cin>>s;
	cin>>D;
	int ans = fun(0,0,0,s)-1;
	ans%=mod;
	if(ans<0) ans+=mod; 
	cout<<ans<<"\n";

	return 0;
}


Measured memory_bytes: 12220
#include "bits/stdc++.h"
#define ll long long
#define inf 1000000007 //10^9+7
#define sort(vec) sort((vec).begin(),(vec).end());
#define rever(vec) reverse((vec).begin(),(vec).end());
#define unsort(vec) sort((vec)); rever((vec));
#define gcd __gcd
using namespace std;

int main() {
  string s;
  cin>>s;
  ll e=s.size();
  ll W=0;
  ll B=0;
  ll ans=0;
  ll f=0;
  for(ll i=0;i<e;i++) {
    if(s.at(i)=='B') {
      B++;
    }
  }
  W=e-B;
  vector<ll>vec(e);
  for(ll i=0;i<e;i++) {
    if(s.at(i)=='B') {
      vec.at(i)=(W+f-i);
      f++;
    }
  }
  for(ll i=0;i<e;i++) {
    ans+=vec.at(i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2180
a,b,c,x,y= map(int, input().split())

if x==y:
    ans=min(c*2*x,(a+b)*x)

else:
    if x>y:
        ans=min(x*c*2,a*x+b*y,y*c*2+(x-y)*a)
    else:
        ans=min(y*c*2,a*x+b*y,x*c*2+(y-x)*b)

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
#define ll long long 
const int N=2e5+100;
int n,m;
int l,r,d;
vector<pair<int,int> >map[N];
bool flag,vis[N];
int dis[N];
inline void dfs(int x){
	for(int i=0;i<map[x].size();i++){
		pair<int,int>a;
		a=map[x][i];	
		if(vis[a.first]){
			if(dis[x]+a.second!=dis[a.first]){
				flag=true;
				return;
			}else continue;	
		}
		vis[a.first]=true;
		dis[a.first]=dis[x]+a.second;
		dfs(a.first);
		if(flag)return;
	}	
} 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&l,&r,&d);
		map[l].push_back(make_pair(r,d));
		map[r].push_back(make_pair(l,-d));
	}
	for(int i=0;i<n;i++){
		if(!vis[i]){
			dfs(i);
			if(flag)break;
		}	
	}
	if(!flag)printf("Yes\n");
	else printf("No\n");
	return 0;
} 

Measured memory_bytes: 13568
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		x: isize,
	}

	println!("{}", 1-x);
}


Measured memory_bytes: 2168
#include <stdio.h>
int main(){
	int n,i,g[6]={0},x,y;
	float f;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%f",&f);
		if(f<165.0)g[0]++;
		else if(f>=165.0 && f<170.0)g[1]++;
		else if(f>=170.0 && f<175.0)g[2]++;
		else if(f>=175.0 && f<180.0)g[3]++;
		else if(f>=180.0 && f<185.0)g[4]++;
		else if(f>=185.0 && f<190.0)g[5]++;
	}
	for(x=0;x<6;x++)
	{
		printf("%d:",x+1);
		for(y=0;y<g[x];y++)
		printf("*");
		puts("");
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int,input().split()))
if N == 0:
    print(1 if A[0] == 1 else -1)
    exit()

nodeS = [0 for i in range(N+1)]
nodeS[0] = 1

nodeM = nodeS[0]-A[0]

laS = [0 for i in range(N+1)]

laS[-1] = A[-1]
for i in range(N):
    laS[-2-i] = A[-2-i] + laS[-1-i]


for i in range(N):
    nodeS[i+1] = nodeM*2
    nodeM = nodeS[i+1] - A[i+1]
    if nodeS[i] >= laS[i]:
        j = i
        break
    if i == N-1:
        if nodeS[i+1] >= laS[i+1]:
            j = i+1
        else:
            print(-1)
            exit()

for i in nodeS:
    if i < 0:
        print(-1)
        exit()

ans = sum(nodeS[:j]) + sum(laS[j:])
print(ans)




Measured memory_bytes: 671860
#include <stdio.h>
#include <math.h>
int main()
{
  int a,b;
  char c;
  scanf("%d",&a);
  scanf(" %c",&c);
  scanf("%d",&b);
  while (!((c=='?'))){
    if (c=='+'){
      printf("%d\n",a+b);
    }else if(c=='-'){
      printf("%d\n",a-b);
    }else if(c=='*'){
      printf("%d\n",a*b);
    }else if(c=='/'){
      printf("%d\n",a/b);
    }
    scanf("%d",&a);
    scanf(" %c",&c);
    scanf("%d",&b);
  }
 
 
 
  return 0;
}
 

 

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> xy(m);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    xy.at(i) = make_pair(x, y);
  }
  vector<int> cnt(n, 1);
  vector<bool> possible(n, false);
  possible.at(0) = true;
  rep(i, m) {
    int x = xy.at(i).first;
    int y = xy.at(i).second;
    cnt.at(x)--;
    cnt.at(y)++;
    if (possible.at(x)) {
      possible.at(y) = true;
    }
    if (cnt.at(x) == 0) {
      possible.at(x) = false;
    }
  }
  int res = 0;
  rep(i, n) {
    if (possible.at(i) && cnt.at(i) > 0) {
      res++;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4472
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const P: char = '+';
const M: char = '-';

fn main() {
    let s: Vec<i32> = read::<String>()
        .chars()
        .map(|c| c.to_digit(10).unwrap() as i32)
        .collect();

    let op: [[i32; 3]; 8] = [
        [0, 0, 0],
        [0, 0, 1],
        [0, 1, 0],
        [0, 1, 1],
        [1, 0, 0],
        [1, 0, 1],
        [1, 1, 0],
        [1, 1, 1],
    ];

    for i in 0..8 {
        let mut ans = s[0];
        if op[i][0] == 0 { ans += s[1]; } else { ans -= s[1]; }
        if op[i][1] == 0 { ans += s[2]; } else { ans -= s[2]; }
        if op[i][2] == 0 { ans += s[3]; } else { ans -= s[3]; }
        if ans == 7 {
            println!("{}{}{}{}{}{}{}=7",
                     s[0],
                     if op[i][0] == 0 { P } else { M },
                     s[1],
                     if op[i][1] == 0 { P } else { M },
                     s[2],
                     if op[i][2] == 0 { P } else { M },
                     s[3]);
            break;
        }
    }

}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T & ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T & ref, const T value) {
    if (ref < value) ref = value;
}

constexpr ll mod = 1000000007;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    if (x == 0) {
        if (k % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
        else {
            cout << d << endl;
            return 0;
        }
    }
    if (x > 0) {
        ll div = x / d;
        ll restD = x - min(k, div) * d;
        ll restK = k - min(k, div);
        if (restK % 2 == 0) {
            cout << restD << endl;
            return 0;
        }
        else {
            cout << abs(restD - d) << endl;
        }
    }
    else {
        ll div = abs(x) / d;
        ll restD = x + min(k, div) * d;
        ll restK = k - min(k, div);
        if (restK % 2 == 0) {
            cout << abs(restD) << endl;
            return 0;
        }
        else {
            cout << abs(restD + d) << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define PI 3.14159265358979323846
int main(){
	long long a; cin >> a;
	long long res = 0;
	for (long long i = 1; i * i <= a; i++){
		if (a % i == 0){
			res = i + a / i - 2;
		}
	}
	cout << res;
	//getchar();
	//getchar();
	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,x;
    set <int> s;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        s.insert(x);
    }
    if(s.size() == n)
        cout << "YES";
    else
        cout << "NO";
}


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

#define rep1(i, a, n) for (int i = a; i < n; i++)
#define rep2(i, a, n) for (int i = n; i >= a; i--)
#define asc(v) sort(v.begin(), v.end())
#define desc(v) sort(v.begin(), v.end(), greater<int>())

using namespace std;

int main() {
  string s;
  cin >> s;
  int zeros = 0, ones = 0;
  rep1(i, 0, s.size()) if (s[i] == '0') zeros++;
  ones = s.size() - zeros;
  cout << 2 * min(ones, zeros) << endl;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
 
int main(){
    int money = 100000;
    int n;
 
    cin >> n;
    for(int i = 0; i< n; i++){
        money *= 1.05;
        if(money % 1000 != 0){
            money += 1000 - (money % 1000);
        }
    }
    cout << money << endl;
} 

Measured memory_bytes: 1156
N, W = map(int, input().split())
mX = [tuple(map(int, input().split()))
      for _ in range(N)]

# dp[i][w] := max v
dp = [[0,] * (W+1),]

for w,v in mX:
    nDp = [max(dp[-1][t], dp[-1][t-w]+v)
           if t-w >= 0 else dp[-1][t]
           for t in range(W+1)]
    dp.append(nDp)

print(dp[-1][-1])


Measured memory_bytes: 169500
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#define MAX 110000
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
vector<ll> G[MAX],col(MAX,0);
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
ll dp[300000][12]={};
void solve(ll v,ll d,ll c){
  bool ch=false;
  for(int i=d;i>=0;i--){
    if(dp[v][i] == 0){
      dp[v][i] = c;
      ch = true;
    }
  }
  if(!ch) return;
  if(d==0) return;
  for(auto nv:G[v]){
    solve(nv,d-1,c);
  }
}
signed main(){
  init_io();
  ll n,m,q,a,b;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cin >> q;
  vector<ll> v(q),d(q),c(q);
  for(int i=q-1;i>=0;i--){
    cin >> v[i] >> d[i] >> c[i];
    v[i]--;
  }
  for(int i=0;i<q;i++){
    solve(v[i],d[i],c[i]);
  }
  for(int i=0;i<n;i++){
    cout << dp[i][0]<<endl;
  }
}


Measured memory_bytes: 22132
#include <stdio.h>
int main(void){

int up[101] = {};
int down[101] = {};
int N = 0;
int i, j = 0;
int sum = 0;
int sumsum = 0;
int a = 0;

scanf("%d", &N);

for(i = 0; i < N; i++){
  scanf("%d", &a);
  up[i] = a;
}
for(i = 0; i < N; i++){
  scanf("%d", &a);
  down[i] = a;
}
for(i = 0; i < N; i++){
    for(j = 0; j < i+1; j++){
        sum = sum + up[j];
    }
    for(j = i; j < N; j++){
        sum = sum + down[j];
    }
    if(sum > sumsum){
      sumsum = sum;
    }
    sum = 0;
}

printf("%d", sumsum);

return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	char a[1200];
	int i;
	for (i = 0; a[i - 1] != '\n'; i++) {
		scanf("%c", &a[i]);
		if (65 <= a[i] && 90 >= a[i]) {
			a[i] += 32;
		}
		else {
			if (97 <= i[a] && 122 >= a[i]) {
				a[i] -= 32;
			}
		}
	}
	a[i - 1] = 0;
	printf("%s\n", a);
	return 0;
}


Measured memory_bytes: 2072
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	a := nextInt()
	b := nextInt()
	s := nextStr()

	acnt := 0
	bcnt := 0
	for i := 0; i < n; i++ {
		if s[i] == 'c' {
			fmt.Println("No")
			continue
		}
		if s[i] == 'a' {
			if acnt+bcnt < a+b {
				fmt.Println("Yes")
				acnt++
			} else {
				fmt.Println("No")
			}
			continue
		}
		if s[i] == 'b' {
			if (acnt+bcnt < a+b) && (bcnt < b) {
				fmt.Println("Yes")
				bcnt++
			} else {
				fmt.Println("No")
			}
			continue
		}
	}

}

// ---- readfunc
func scanInit() {
	const cap = 100 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2056
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
   
public class Main {
     
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
     
    public void exec() throws IOException {
        SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        out.println(
        	outC(
        		in.readIntArray(new int[in.readInt()]),
        		in.readIntArray(new int[in.readInt()])
        	)
        );
        out.flush();
    }
    
    private int outC(int[] S, int[] T) {
    	int C = 0;
    	HashSet<Integer> setS = new HashSet<>();
    	for(int s : S) {
    		setS.add(s);
    	}
    	for(int t : T) {
    		if(setS.contains(t)) {
    			C++;
    		}
    	}
    	return C;
    }
}
 
class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
    public int readInt() throws NumberFormatException, IOException{
        return Integer.parseInt(br.readLine());
    }
     
    public int[] readIntArray(int[] a) throws NumberFormatException, IOException{
        int i=0;
        while(i<a.length) {
            for(String s: br.readLine().split(" ")){
                if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
                }
            }
        }
        return a;
    }
 
     
}

Measured memory_bytes: 27652
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
MOD = 10**9 + 7
x = k*(k+1)/2
y = k*(k-1)/2
ans = 0
n.times do |i|
  n.times do |j|
    next if i==j
    if a[i] > a[j]
      if i < j
        ans += x
      else
        ans += y
      end
    end
    ans %= MOD
  end
end
p ans

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

int main() {
  int N;
  cin >> N;

  // ここにプログラムを追記
  
  for (int i = 0; i < N; i++) {
  	string S;
    cin >> S;
    
    if (S == "Y") {
    	cout << "Four";
      	break;
    }
    else if (i == N-1){
    	cout << "Three";
    }
  }
}




Measured memory_bytes: 3536
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 7 + 10**9
    if N == K:
        r = 1
        for i in A:
            r *= i
            r %= mod
        return r % mod
    if max(A) <= 0 and K % 2 == 1:
        A.sort(reverse=True)
        r = 1
        for i in range(K):
            r *= A[i]
            r %= mod
        return r % mod
    a = []
    for i in A:
        a.append((abs(i), i))
    a.sort(reverse=True)
    cm = 0
    lp = None
    lm = None
    for i in range(K):
        if a[i][1] >= 0:
            lp = i
        else:
            lm = i
            cm += 1
    if cm % 2 == 0:
        r = 1
        for i in range(K):
            r *= a[i][1]
            r %= mod
        return r
    if not lp:
        r = 1
        for i in range(K-1):
            r *= a[i][1]
            r %= mod
        r *= max(A)
        return r % mod
    np = None
    nm = None
    for i in range(K, N):
        if a[i][1] >= 0 and not np:
            np = i
        if a[i][1] < 0 and not nm:
            nm = i
        if np and nm:
            break
    if not np:
        r = 1
        for i in range(K):
            if i != lp:
                r *= a[i][1]
                r %= mod
        r *= a[nm][1]
        return r % mod
    if not nm:
        r = 1
        for i in range(K):
            if i != lm:
                r *= a[i][1]
                r %= mod
        r *= a[np][1]
        return r % mod
    r = 1
    for i in range(K):
        if i not in (lp, lm):
            r *= a[i][1]
            r %= mod
    r *= max(a[np][1] * a[lp][1], a[lm][1] * a[nm][1])
    return r % mod
print(main())


Measured memory_bytes: 38052
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy > 0:
        out = str(X_dumy % n) + out
        X_dumy = int(X_dumy / n)
    return out

n, k = map(int, input().split())
print(len(str(Base_10_to_n(n, k))))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N, A, B, C;
	cin >> N >> A >> B >> C;
	string S[N];
	rep(i,N){
		cin >> S[i];
	}
	string T[N];
	rep(i,N){
		if(S[i] == "AB"){
			if(A == 0 && B == 0){
				if(i != 0){
					if(S[i-1] == "AC"){
						if(C >= 2){
							T[i-1] = "A";
							C -= 2;
							A++;
							B++;
							T[i] = "B";
						}
						else{
							cout << "No" << endl;
							return 0;
						}
					}
					else if(S[i-1] == "BC"){
						if(C >= 2){
							T[i-1] = "B";
							C -= 2;
							A++;
							B++;
							T[i] = "A";
						}
						else{
							cout << "No" << endl;
							return 0;
						}
					}
				}
				else{
					cout << "No" << endl;
					return 0;
				}
			}
			else{
				if(A >= B){
					T[i] = "B";
					B++;
					A--;
				}
				else{
					T[i] = "A";
					B--;
					A++;
				}
			}
		}
		if(S[i] == "BC"){
			if(C == 0 && B == 0){
				if(i != 0){
					if(S[i-1] == "AB"){
						if(A >= 2){
							T[i-1] = "B";
							A -= 2;
							B++;
							C++;
							T[i] = "C";
						}
						else{
							cout << "No" << endl;
							return 0;
						}
					}
					else if(S[i-1] == "AC"){
						if(A >= 2){
							T[i-1] = "C";
							A -= 2;
							B++;
							C++;
							T[i] = "B";
						}
						else{
							cout << "No" << endl;
							return 0;
						}
					}
				}
				else{
					cout << "No" << endl;
					return 0;
				}
			}
			else{
				if(C >= B){
					T[i] = "B";
					B++;
					C--;
				}
				else{
					T[i] = "C";
					B--;
					C++;
				}
			}
		}
		if(S[i] == "AC"){
			if(C == 0 && A == 0){
				if(i != 0){
					if(S[i-1] == "AB"){
						if(B >= 2){
							T[i-1] = "A";
							B -= 2;
							A++;
							C++;
							T[i] = "C";
						}
						else{
							cout << "No" << endl;
							return 0;
						}
					}
					else if(S[i-1] == "BC"){
						if(B >= 2){
							T[i-1] = "C";
							B -= 2;
							A++;
							C++;
							T[i] = "A";
						}
						else{
							cout << "No" << endl;
							return 0;
						}
					}
				}
				else{
					cout << "No" << endl;
					return 0;
				}
			}
			else{
				if(A >= C){
					T[i] = "C";
					C++;
					A--;
				}
				else{
					T[i] = "A";
					C--;
					A++;
				}
			}
		}
	}
	cout << "Yes" << endl;
	rep(i,N){
		cout << T[i] << endl;
	}
}

Measured memory_bytes: 9908
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 1e5 + 9, M = 1e2 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

ll mem[(1 << 16)], arr[16][16], val[(1 << 16)];
int n;

ll solve(int mask) {
  if(__builtin_popcount(mask) == 0)
    return 0;
  ll& ret = mem[mask];
  if(~ret)
    return ret;
  ret = -inf;
  for (int sub = mask; sub != 0; sub = (sub - 1) & mask) {
    ret = max(solve(mask & (~sub)) + val[sub], ret);
  }
  return ret;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  cin >> n;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      cin >> arr[i][j];
  for (int mask = 0; mask < (1<<n); ++mask) {
    mem[mask] = -1;
    for (int j = 0; j < n; ++j) {
      if(mask & (1 << j)) {
        for (int k = j + 1; k < n; ++k) {
          if(mask & (1 << k))
            val[mask] += arr[j][k];
        }
      }
    }
  }
  cout << solve((1 << n) - 1);
  return 0;
}


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

int H, W, K;
vector<vector<char>> s;
int strayberry_number = 1;
vector<vector<int>> ans;


int numStrayberry(int h_start, int h_end, int w_start, int w_end) {

    int strayberry = 0;
    for (int i = h_start; i <= h_end; ++i)
    {
        for (int j = w_start; j <= w_end; ++j)
        {
            if(s[i][j] == '#') {
                strayberry++;
            }
        }
    }

    return strayberry;
}

void print() {
    for (int i = 0; i < ans.size(); ++i)
    {
        for (int j = 0; j < ans[i].size(); ++j)
        {
            printf("%d ", ans[i][j]);
        }
        cout << endl;
    }
    cout << endl;
}


void paint(int h_start, int h_end, int w_start, int w_end) {
    for (int i = h_start; i <= h_end; ++i)
    {
        for (int j = w_start; j <= w_end; ++j)
        {
            ans[i][j] = strayberry_number;
        }
    }
    // printf("---- print ----\n");
    // print();

    strayberry_number++;
}

void cut(int h_start, int h_end, int w_start, int w_end) {
    // printf("--- rec start ---\n");
    // printf("w_start : %d\n", w_start);
    // printf("w_end   : %d\n", w_end);
    // printf("h_start : %d\n", h_start);
    // printf("h_end   : %d\n", h_end);

    //矩形内のいちごの個数が1個になったら分割終了
    if(numStrayberry(h_start, h_end, w_start, w_end) == 1) { 
        paint(h_start, h_end, w_start, w_end); //矩形を番号で塗り潰す
        return;
    }

    //最初に見つかるいちごの位置
    int strayberry_h = 0;
    int strayberry_w = 0;
    for (int i = h_start; i <= h_end; ++i) {
        for (int j = w_start; j <= w_end; ++j) {
            if(s[i][j] == '#') {
                strayberry_h = i;
                strayberry_w = j;
                goto LABEL_EXIT;
            }
        }
    }

    LABEL_EXIT:
    //切る範囲をできるだけ下の方へ伸ばす
    int cut_h = strayberry_h;
    int cut_w = strayberry_w;
    for (int i = strayberry_h + 1; i <= h_end; ++i)
    {
        for (int j = 0; j <= strayberry_w; ++j) //幅は最初にいちごが見つかったところまで
        {
            if(s[i][j] == '#') {
                cut_h = max(cut_h, i-1);
                goto LABEL_EXIT2;
            }
        }

        //最後まで到達したら、縦に切ることになる
        if(i == h_end) {
            cut_h = h_end;
        }
    }


    LABEL_EXIT2:
    //分割して再帰
    // printf(" ==> cut : %d, %d\n", cut_h, cut_w);
    if(cut_h < h_end) { //横に切る
        cut(h_start  , cut_h, w_start, w_end);
        cut(cut_h + 1, h_end, w_start, w_end);
    } else if(cut_w < w_end){ //縦に切る
        cut(h_start, h_end, w_start  , cut_w);
        cut(h_start, h_end, cut_w + 1, w_end);
    }

    return;
}




int main() {
    cin >> H >> W >> K;

    for (int h = 0; h < H; ++h){
        vector<char> tmp;
        vector<int> ans_tmp;

        for (int w = 0; w < W; ++w)
        {
            char c;
            cin >> c;
            tmp.push_back(c); //ケーキ

            ans_tmp.push_back(0); //答えの初期化

        }
        s.push_back(tmp); //ケーキ

        ans.push_back(ans_tmp); //答えの初期化
    }

    // printf("---- paint ----\n");
    // paint(0, W-1, 0, H-1);

    cut(0, H-1, 0, W-1);
    // printf("---- print ----\n");
    print();

    

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

using Graph = vector<vector<int>>;

int main() {
    int n;
    cin >> n;
    Graph G(1000*n+n);
    vector<int> h(1000*n+n, 0);
    vector<vector<int>> a(n, vector<int>(n-1));
    rep(i, n){
        rep(j, n-1){
            cin >> a[i][j]; 
            a[i][j]--;
            if(j){
                int mi1 = min(a[i][j-1], i);
                int ma1 = max(a[i][j-1], i);
                int mi2 = min(a[i][j], i);
                int ma2 = max(a[i][j], i);
                G[1000*mi1+ma1].push_back(1000*mi2+ma2);
                h[1000*mi2+ma2]++;
            }
        }
    }
    map<ll, ll> mp;
    stack<int> st;
    rep(i, n){
        rep(j, n-1){
            int mi = min(a[i][j], i);
            int ma = max(a[i][j], i);
            if(h[1000*mi+ma] == 0 && !mp[1000*mi+ma]){
                st.push(1000*mi+ma);
                mp[1000*mi+ma]++;
            }
        }
    }
    vector<int> ans;
    while(st.size()){
        int i = st.top(); st.pop();
        ans.push_back(i);
        for(auto& j : G[i]){
            h[j]--;
            if(h[j] == 0)st.push(j);
        }
    }
    if(ans.size() != n*(n-1)/2)cout << -1 << endl;
    else{
        vector<int> ok(1000*n+n, 1);
        rep(i, ans.size()){
            for(auto& j : G[ans[i]]){
                chmax(ok[j], ok[ans[i]]+1);
            }
        }
        cout << *max_element(all(ok)) << endl;
    }
}


Measured memory_bytes: 53236
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

N = int(input())

if N % 10 in [0, 1, 6, 8]:
    print('pon')
elif N % 10 == 3:
    print('bon')
else:
    print('hon')


Measured memory_bytes: 72664
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 18 10:42:00 2017

@author: syaga
"""

import math

def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i-g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return cnt
         
def shellSort(A, n):
    cnt = 0
    G = [1]
    if n != 1:
        for i in range(99):
            G.append(G[i]*3+1)
        G = [x for x in G if x < n]
        G.reverse()
    m = len(G)
    print(m)
    print(" ".join(map(str, G)))
    for i in range(0, m):
        cnt = insertionSort(A, n, G[i], cnt)
    print(cnt)

if __name__ == "__main__":
    n = int(input())
    A = []
    for i in range(n):
        A.append(int(input()))
    shellSort(A, n)
    for i in A:
        print(i)

Measured memory_bytes: 47612
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int n;
    cin >> n;
    int nums[9] = { 0 };
    FOR(i, 0, n) {
        int a;
        cin >> a;
        nums[min(8, a / 400)]++;
    }
    int minx = 0, maxx = 0;
    FOR(i, 0, 8) {
        if (nums[i])
            minx++, maxx++;
    }
    minx = max(1, minx);
    maxx += nums[8];
    printf("%d %d\n", minx, maxx);
    return 0;

}

Measured memory_bytes: 256
n = gets.to_i
as = [0]
as += gets.split.map &:to_i
as << 0

total = as[0..-2].map.with_index{ |x, i| (x-as[i+1]).abs }.inject(:+)

as[1..-2].each.with_index(1){ |x, i|
	puts total - (x-as[i-1]).abs - (x-as[i+1]).abs + (as[i-1] - as[i+1]).abs
}

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

using namespace std;
int N, K;
long long int H[200005];

vector<long long int >V;
int main(void) {
	cin >> N >> K;
	long long int sum = 0;
	for (int i = 1; i <= N; i++) {
		cin >> H[i];
		V.push_back(H[i]);
		sum += H[i];
	}

	sort(V.rbegin(), V.rend());

	long long int SUM = 0;

	for (int i = 0; i <= min(K - 1,(int) V.size()-1); i++) {
		SUM += V[i];
	}

	long long int ans = max(sum - SUM, 0LL);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3444