akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;

int y[55];
long long int c[52][51][2505];
int main() {
	int n, a;
	
	cin >> n;
	cin >> a;
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}
	c[1][0][0] = 1;
	c[1][1][y[0]] = 1;
	for (int i = 2; i < n+1; i++) {
		for (int j = 0; j < i+1; j++) {
			for (int k = 0; k <=n * 50; k++) {
				if (k >= y[i-1]) {
					if (j > 0)c[i][j][k] = c[i - 1][j][k] + c[i - 1][j - 1][k - y[i-1]];
				}
				else {
					c[i][j][k] = c[i - 1][j][k];
				}
			}
		}
	}
	long long int sum = 0;
	for (int i = 1; i < n+1; i++) {
		sum += c[n][i][i * a];
	}
	cout << sum;
}

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

int main()
{
	int N;
	cin >> N;
	for (int a = 1; a <= 9; ++a)
	{
		for (int b = a; b <= 9; ++b)
		{
			if (a * b == N)
			{
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define INF 0x7fffffff
typedef long long LL;
const int maxn = 1e5 + 10;
int n, m;

struct node {
    int val, lc, rc, dis, par;
} t[maxn];

void init(int x) {
    for (int i = 1; i <= x; i++) {
        t[i].lc = t[i].rc = t[i].dis = 0;
        t[i].par = i;
    }
}

int find(int x) {
    if (t[x].par == x) return x;
    else return t[x].par = find(t[x].par);
}

bool same(int x, int y) {
    return find(x) == find(y);
}
void swap(int& x, int& y)
{
    int t = x;
    x = y;
    y = t;
}
int unite(int x, int y) {
    if (x == 0)
        return y;
    if (y == 0)
        return x;
    if (t[x].val > t[y].val)
        swap(x, y);
    t[x].rc = unite(t[x].rc, y);
    t[t[x].rc].par = x;
    if (t[t[x].lc].dis < t[t[x].rc].dis)
        swap(t[x].lc, t[x].rc);
    if (t[x].rc == 0)
        t[x].dis = 0;
    else
        t[x].dis = t[t[x].rc].dis + 1;
    return x;
}
int pop(int x) {
    int l = t[x].lc, r = t[x].rc;
    t[x].lc = t[x].rc = t[x].dis = 0;
    t[x].par = x;
    t[l].par = l, t[r].par = r;
    return unite(l, r);
}
int add(int x,int y)
{
    if(x == 0 || y == 0)
        return INF;
    return t[x].val + t[y].val;
}
int main()
{
    cin >>n >>m;
    init(n);
    for(int i=1; i<=n; ++i)
    {
        cin>>t[i].val;
    }
    for(int i=1; i<=m ;++i)
    {
        int x,y;
        cin>>x>>y;
        int nx = find(x+1);
        int ny = find(y+1);
        unite(nx,ny);
    }
    map<int,int> ns2;
    set<pair<int,int>> s,s2;
    for(int i=1; i<=n ;++i)
    {
        int x = find(i);
        s.insert(make_pair(t[x].val,x));
        int y = pop(x);
        s2.insert(make_pair(add(x,y),x));
        ns2[x] = add(x,y);
        unite(x,y);
    }
    LL ans = 0;
    for(int tt=1; tt< n-m-1 ; ++tt)
    {
        int x = s.begin()->second;
        s.erase(s.begin());
        int y = s2.begin()->second;
        s2.erase(s2.begin());
        if(y == x)//当前最小+二轮最小刚好就是当前最小的那个，取出当前第二小的，与当前最小的进行合并
        {
            y = s.begin()->second;
            s.erase(s.begin());
            s2.erase(make_pair(ns2[y],y));//当前最小的已经在s2中已经被删掉了
        }else//否则，取出和最小的，与当前最小的合并
        {
            s.erase(make_pair(t[y].val,y));
            s2.erase(make_pair(ns2[x],x));//删掉当前最小的那个
        }
        ans += t[x].val + t[y].val;
        int nx = pop(x);
        int ny = pop(y);
        int nz = unite(nx,ny);
        if(nz == 0)
        {
            cout<<"Impossible"<<endl;
            return 0;
        }
        s.insert(make_pair(t[nz].val,nz));
        int nz_ = pop(nz);
        s2.insert(make_pair(add(nz,nz_),nz));
        ns2[nz] = add(nz,nz_);
        unite(nz,nz_);
    }
    if(n-m>1)
    {
        int x = s.begin()->second;
        s.erase(s.begin());
        int y = s.begin()->second;
        ans+= t[x].val + t[y].val;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 16256
#!/usr/bin/env python3
# coding: utf-8

def main():
    N, K = map(int, input().split())
    s = dict(zip(range(1, N + 1), [0] * N))
    for _ in range(K):
        _ = input()
        *A, = map(int, input().split())
        for a in A:
            s[a] += 1
    c = len(list(filter(lambda x: x == 0, s.values())))
    print(c)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
long double dp[1002];
long double sum[200002];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i=1;i<=1000;i++){
        long double x = 1.0/i;
        for(int j=1;j<=i;j++) dp[i] += x*j;
    }
    long double ans = 0;
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d", &x);
        sum[i] += dp[x];
        sum[i] += sum[i-1];
        if(i >= k) ans = max(ans, sum[i] - sum[i-k]);
    }
    printf("%.10Lf\n", ans);
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=510;
char s[N][N];

int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int n,m,i,j;
	scanf("%d%d",&n,&m);
	rep(i,1,n)	scanf("%s",s[i]+1);
	rep(i,1,n){
		rep(j,1,m){
			if(j==1){printf("#");continue;}
			if(j==m){printf(".");continue;}
			if(s[i][j]=='#'){printf("#");continue;}
			if(i&1){printf("#");continue;}
			printf(".");
		}
		printf("\n");
	}
	printf("\n");
	rep(i,1,n){
		rep(j,1,m){
			if(j==m){printf("#");continue;}
			if(j==1){printf(".");continue;}
			if(s[i][j]=='#'){printf("#");continue;}
			if((i&1)==0){printf("#");continue;}
			printf(".");
		}
		printf("\n");
	}
}
				

Measured memory_bytes: 896
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, input().split())
# 文字列の入力
#s = input()
#開業されたN個要素を受け付ける
list=[]
for i in range(K):
    #print(i)
    d=int(input())
    #list.append(list(map(int, input().split())))
    tmp_list = input().split()
    map(int, tmp_list)
    list.append(tmp_list)

#print(list)

ans=0

for i in range(N):
    #print(i+1)
    flg=0
    for j in range(K):
        #print(list[j])
        if str(i+1) in list[j]:
            #print("flg")
            flg = 1
    if flg == 0:
        ans=ans+1

print(ans)


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

using namespace std;

const int maxi=1e6;
int lev,rez,n,sum,x,y;
vector<int> v[maxi];
int pr[maxi];

void dfs(int x, int pred)
{
    lev++;

    sum++;

    pr[x]=pred;
    if (x==n) rez=lev;
    for (int i:v[x])
        if (i!=pred) dfs(i,x);
    lev--;
}

int main()
{
   cin>>n;

   for (int i=1;i<n;i++)
   {
       scanf("%d%d",&x,&y);
       v[x].push_back(y);
       v[y].push_back(x);
   }

   dfs(1,0);

   rez-=2;
   rez/=2;

   x=n;

   while(rez>0)
   {
       x=pr[x];
       rez--;
   }

    sum=0;
   dfs(x,pr[x]);


   if (sum<n-sum) printf("Fennec\n"); else printf("Snuke\n");

   return 0;
}


Measured memory_bytes: 33792
/**
 * Title: B - Common Raccoon vs Monster
 * Url: https://atcoder.jp/contests/abc153/tasks/abc153_b
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int h, n; cin >> h >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    if(accumulate(a.begin(), a.end(), 0)>=h) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
const double pi = 2 * acos (0.0);

int main()
{
	char s[10];
	scanf("%s",s);
	int cnta=0,cntb=0,cntc=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='a') cnta++;
		else if(s[i]=='b') cntb++;
		else if(s[i]=='c') cntc++;
	}
	if(cnta==1&&cntb==1&&cntc==1) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    while(true) {
        int w, h; cin >> w >> h;

        if(w == 0 && h == 0) break;

        vector<vi> m(h, vi(w));
        REP(i, h) REP(j, w) cin >> m[i][j];

        vector<vector<bool>> visit(h, vector<bool>(w, false));

        vi dx = {0, 1, -1}, dy = {0, 1, -1};
        auto check = [&] (int x, int y) -> bool {
            return x >= 0 && x < w && y >= 0 && y < h;
        };

        auto dfs = [&] (auto &&f, int cx, int cy) -> void {
            visit[cy][cx] = true;

            REP(i, 3) REP(j, 3) {
                int nx = cx + dx[i], ny = cy + dy[j];
                if (check(nx, ny)){
                    if(!visit[ny][nx] && m[ny][nx] == 1) {
                        f(f, nx, ny);
                    }
                }
            }
        };

        int ans = 0;
        REP(i, h) REP(j, w) {
            if (m[i][j] == 1 && !visit[i][j]) dfs(dfs, j, i), ans++;
        }

        print(ans);
    }

}


Measured memory_bytes: 3272
/**
*    created: 05.07.2020 17:25:44
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

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

    int n;
    cin >> n;
    int od = 0;
    int fo = 0;
    int tw = 0;
    rep(i,n) {
        int a;
        cin >> a;
        if (a % 2 == 1) od++;
        else if (a % 4 == 0) fo++; 
        else tw++;
    }
    if (tw > 0) {
        if (od <= fo) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else {
        if (od <= fo + 1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 3628
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();
        int N, K;
        {int[] a = r.ii(); N = a[0]; K = a[1];}
        double ans = 0;
        if(K <= N)
            ans += N-K+1;
        for(int i = 1; i <= Math.min(K-1, N); i++){
            int n = 0;
            int score = i;
            while(score < K){
                n++;
                score *= 2;
            }            
            ans += Math.pow(0.5, n);
        }
        ans /= N;
        print(ans);        
    }
    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int Int(String s){
            return Integer.parseInt(s);
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}


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

typedef long long ll;

int Q;
ll A,B;

bool judge(ll mid)
{
    if(mid < A && mid < B)return true;
    if(mid % 2)
    {
        ll mid1,mid2;
        mid1 = mid2 = (mid + 1) / 2;
        if(A <= mid1)mid1++;
        if(B <= mid2)mid2++;
        return mid1 * mid2 < A * B;
    }
    else
    {
        ll mid11,mid12,mid21,mid22;
        mid11 = mid21 = mid / 2;
        mid12 = mid22 = mid11 + 1;
        if(A <= mid11)
        {
            mid11++;
            mid12++;
        }
        else if(A <= mid12)mid12++;
        if(B <= mid21)
        {
            mid21++;
            mid22++;
        }
        else if(B <= mid22)mid22++;
        return (mid21 * mid12 < A * B) && (mid11 * mid22 < A * B);
    }
    return false;
}

int main()
{
    scanf("%d",&Q);

    while(Q--)
    {
        scanf("%lld%lld",&A,&B);
        ll l = 0,r = 2000000000;
        while(r - l > 1)
        {
            ll mid = (l + r) / 2;
            if(judge(mid))l = mid;
            else r = mid;
        }
        printf("%lld\n",l);
    }
    return 0;
}


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

int main(){
  int N, Q;
  cin >> N >> Q;
  string s; cin >> s;
  vector<pair<char, char>> spell(Q);
  for (int i=0; i<Q; i++) cin >> spell[i].first >> spell[i].second;
  int lft = -1, rgt = N;
  int check = (lft+rgt)/2;
  int leftedge, rightedge;
  int befcheck = -1;
  while (true){
    check = (lft+rgt)/2;
    if (check==befcheck) break;
    // cout << check << endl;
    int pos = check;
    for (int i=0; i<Q; i++){
      if (spell[i].first==s[pos]){
        if (spell[i].second == 'L') pos--;
        else pos++;
      }
      if (pos < 0) {
        break;
      }
    }
    if (pos < 0){
      lft = check;
    } else {
      rgt = check;
    }
    befcheck = check;
  }
  leftedge = lft;
  // cout << leftedge << endl;
  lft = -1; rgt = N;
  check = (lft+rgt)/2;
  befcheck = N;
  while (true){
    check = (lft+rgt)/2;
    if (check==befcheck) break;
    int pos = check;
    for (int i=0; i<Q; i++){
      if (spell[i].first==s[pos]){
        if (spell[i].second == 'L') pos--;
        else pos++;
      }
      if (pos >= N) {
        break;
      }
    }
    if (pos >= N){
      rgt = check;
    } else {
      lft = check;
    }
    befcheck = check;
  }
  rightedge = rgt;
  // cout << rightedge << endl;
  cout << max(0, rightedge-(leftedge+1)) << endl;
}


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

#define rep(i, a) for (ll i = 0; i < (a); i++ )
#define FOR(i, m, n) for(ll i = m; i < n; i++)
 
typedef pair<ll,ll> P;
 
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=acos(-1);


// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<ll> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<ll> sizes;

  UnionFind(ll n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  ll find(ll x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(ll x, ll y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(ll x, ll y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  ll size(ll x) {
    return sizes[find(x)];
  }
};

// 頂点a, bをつなぐコストcostの（無向）辺
struct Edge
{
  ll a, b, cost;

  // コストの大小で順序定義
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
  ll n;  // 頂点数
  vector<Edge> es;  // 辺集合

  // クラスカル法で無向最小全域木のコストの和を計算する
  // グラフが非連結のときは最小全域森のコストの和となる
  ll kruskal() {
    // コストが小さい順にソート
    sort(es.begin(), es.end());

    UnionFind uf(n);
    ll min_cost = 0;

    rep(ei, es.size()) {
      Edge& e = es[ei];
      if (!uf.same(e.a, e.b)) {
        // 辺を追加しても閉路ができないなら、その辺を採用する
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};


int main(){
    ll N;
    cin >> N;
    vector<vector<ll>> A,B;
    rep(i,N) {
        ll a,b;
        cin >> a >> b;
        A.push_back({a,b,i});
        B.push_back({b,a,i});
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    Graph g;
    g.n = N;

    rep(i,N-1) {
        Edge e1,e2;
        e1.a = A[i][2];
        e1.b = A[i+1][2];
        e1.cost = min(abs(A[i][0]-A[i+1][0]),abs(A[i][1]-A[i+1][1]));
        e2.a = B[i][2];
        e2.b = B[i+1][2];
        e2.cost = min(abs(B[i][0]-B[i+1][0]),abs(B[i][1]-B[i+1][1]));
        g.es.push_back(e1);
        g.es.push_back(e2);
        //break;
        //cout << e1.a << " " << e1.b << " " << e1.cost << endl;
    }

    cout << g.kruskal() << endl;

}

Measured memory_bytes: 20192
h, w = map(int, input().split())
word1 = '#'*(w+2)
ans = list()
ans.append(word1)
for x in range(h):
    a = list(map(str, input().split()))
    word2 = '#' + "".join(a) + '#'
    ans.append(word2)

ans.append(word1)

for x in range(h+2):
    print(ans[x])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 998244353;
ll n, s;
ll a[3005];
ll dp[3005][3005];
int main () {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> s;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= 3000; ++j) {
            dp[i][j] = dp[i-1][j] * 2 % MOD;
            if (j >= a[i]) dp[i][j] = (dp[i][j] + dp[i-1][j-a[i]] % MOD) % MOD;
        }
    }
    cout << dp[n][s] << endl;
    
}

Measured memory_bytes: 74100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int l,r,d;
    cin>>l>>r>>d;
    cout<<r/d-(l-1)/d<<endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int d;
  cin >> d;
  if(d == 22){
    cout << "Christmas Eve Eve Eve" << endl;
  }else if(d == 23){
    cout << "Christmas Eve Eve" << endl;
  }else if(d == 24){
    cout << "Christmas Eve" << endl;
  }else if(d == 25){
    cout << "Christmas" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        Set<Integer> sunukes = new HashSet<>();
        for(int i=1;i<=k;i++){
            int d =sc.nextInt();
            for(int j=1;j<=d;j++){
                int sunuke = sc.nextInt();
                sunukes.add(sunuke);
            }
        }

        System.out.println(n-sunukes.size());

    }
}


Measured memory_bytes: 37400
#include<bits/stdc++.h>
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 Would
#define you
#define please

int main() {
	//おまじない
	cin.tie(0);
	ios::sync_with_stdio(false);



	int N, X, x;
	ll a[200001] = {};
	cin >> N >> X;
	rep(i, N) {
		cin >> x;
		a[i + 1] = a[i] + x;
	}

	ll sontoku = 0;
	rep(i, N) {
		ll toku = 1ll * X * i;
		ll sonn = 0;
		if (i > N / 2) {
			int sore = N - i;
			int ookisa = N / sore;
			int kazuA = N % sore;

			sonn += 2ll * a[kazuA];
			rep1(iii, ookisa - 2) {
				sonn += 2ll * a[kazuA + sore * iii];
				if (toku - sonn < 0) break;
			}
		}

		sontoku = max(sontoku, toku - sonn);
	}

	long long kotae = a[N] * 5 + 2ll * N * X - sontoku;
	cout << kotae << "\n";
	Would you please return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N, D;
	cin >> N >> D;
	vector<vector<int>> x(N, vector<int>(D));
	for(int i=0; i<N; ++i){
	    for(int j=0; j<D; ++j){
	        cin >> x[i][j];
	    }
	}
	int ans=0;
	for(int i=0; i<N; ++i){
	    for(int j=i+1; j<N; ++j){
	        int now=0;
	        for(int k=0; k<D; ++k){
	            now += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
	        }
	        int s=1;
	        while(s*s<now){
	            ++s;
	        }
	        if(s*s==now) ++ans;
	    }
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

# 入力が文字のリスト
# S = list(input().split())

#入力が数字のリスト
# A = list(map(int, input().split()))

# 入力がリストのリスト
# S = [list(input()) for i in range(H)]


# リストliから重複を削除したリストli_uniqを作成
#li_uniq = []
#for i in li:
#    if x not in li_uniq:
#        li_uniq.append(x)

# 複数行のinput - list版
#list = [list(map(int, input().split())) for i in range(N)]
# 複数行のinput - dictionary版
# key = a, value = b
#for i in range(N):
#    a, b = map(int, input().split())
#    dict[a] = b


N = int(input())
D,X = map(int, input().split())
A = [int(input()) for i in range(N)]

for i in range(N):
    X += (math.floor((D - 1)/A[i]) + 1)

print(X)


Measured memory_bytes: 12428
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll dp[3333][3333];

int main() {
    ll N, T;
    cin >> N >> T;
    vector<pair<ll,ll>> ab;
    rep(i,N){
        ll a, b;
        cin >> a >> b;
        ab.push_back({a,b});
    }
    sort(all(ab));
    rep(i,N+5)rep(j,T+5)dp[i][j] = 0;
    rep(i,N)rep(j,T){
        ll w = ab[i].first;
        ll v = ab[i].second;
        chmax(dp[i+1][j], dp[i][j]);
        if(j + w >= T)continue;
        chmax(dp[i+1][j+w], dp[i][j] + v);
    }
    ll ans = 0;
    rep1(i,N)rep(j,T){
        chmax(ans, dp[i][j] + ab[i].second);
    }
    //printpair(ab);
    cout << ans <<endl;
}

Measured memory_bytes: 80256
R1, C1, R2, C2 = gets.split.map(&:to_i)
M = 10**9 + 7

@fct, @inv, @finv = [nil, 1], [nil, 1], [nil, 1]
(2 .. R2 + C2 + 2).each do |i|
  @fct[i] = @fct[i - 1]*i % M
  @inv[i] = M - @inv[M % i]*(M/i) % M
  @finv[i] = @finv[i - 1] * @inv[i] % M
end
f = ->(i, j){@fct[i + j] * @finv[i] * @finv[j] % M}
g = ->(x, y){f[x + 1, y + 1]}
puts (g[R2, C2] - g[R1 - 1, C2] - g[R2, C1 - 1] + g[R1 - 1, C1 - 1]) % M

Measured memory_bytes: 50664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  vector<int> A(N);
  double ave = 0;
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    ave += A.at(i);
  }
  ave /= N;
  long long P = round(ave);
  long long  ans = 0;
  for(int i = 0; i < N; i++)
    ans += (P - A.at(i)) * (P - A.at(i));
  cout << ans << endl;
  
}
  
      

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s.back() == 's') s.push_back('e');
  s.push_back('s');
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3620
n, m = map(int, input().split())
lst = []
for _ in range(m):
    s, c = map(int, input().split())
    lst.append([s-1,c])
    
ans = []
for _ in range(10**(n)):
    i = 1
    nums = list(str(_))
    while len(nums) < n:
        nums.insert(0,[])
    for s in lst:
        if nums[s[0]] != str(s[1]):  
            i = 0
            break
    if i == 1 and not [] in nums:
        ans.append(_)

if ans:
    print(min(ans))
else:
    print(-1)

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

map<ll, ll> mp;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  ll n,m;cin>>n>>m;
  for(int i=0;i<n;i++){
    ll a,b;cin>>a>>b;
    if (!mp[a]) mp[a] = 0;
    mp[a] += b;
  }

  ll res=0;

  for (auto& kv : mp) {
    auto k = kv.first;
    auto v = kv.second;
    ll qt = min(m, v);
    res += k * qt;
    m-=qt;
    if(m==0)break;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    string s;
    cin >> s;
    string t[4] = { "erase","dream","dreamer","eraser" };
    while(sz(s) > 0){
	itn f = 0;
	rep(i,0,4){
	    int id = s.rfind(t[i]) ;
	    // PS(id);
	    if(id != -1){
		if(sz(s) - id == sz(t[i])){
		    f = 1;
		    s.erase(id);
		}
	    }
	}
	if(f == 0){
	    NO;
	    ret 0;
	}
	//P(s);
    }
    YES;
    return  0;
}


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

typedef int keytype;

//quicksort(<#keytype *a#>, <#int first#>, <#int last#>)

void quicksort(keytype a[], int first, int last){
    int i, j;
    keytype x, t;
    
    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int gcd(int x, int y){
    if (y == 0) return x;
    else        return gcd(y, x % y);
}

int main() {
    long long int h,w,ans=0;
    long long int h_s=0,w_s=0,h_a=0,w_a=0,set;
    scanf("%lld %lld",&h,&w);
    h_s=h%2;
    w_s=w%2;
    h_a=(h-h_s)/2;
    w_a=(w-w_s)/2;
    
    ans=w*h_a;
    if (h_s==1) {
        ans=ans+w_s+w_a;
    }
    if (h==1||w==1) {
        ans=1;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

long long int ModPow(long long int a, long long int p, long long int M){
  long long int res = 1;
  long long int f = a;
  while(p > 0){
    if(p & 1){
      res = (res * f) % M;
    }
    f = (f*f)%M;
    p >>= 1;
  }
  return res;
}

long long int Popcount(long long int X){
  long long int cntr = 0;
  while(X > 0){
    if(X & 1)
      cntr++;
    X >>= 1;
  }
  return cntr;
};

int main(){
  int N;
  cin >> N;
  string s;
  long long int baseM = 0;
  long long int evenR = 0;
  long long int oddR = 0;
  for(int i = 0; i < N; i++){
    char c;
    cin >> c;
    s.push_back(c);
    if(c - '0')
      baseM++;
  }
  if(baseM != 1){
      for(int i = 0; i < N; i++){
        if(s[i] - '0'){
          evenR = (evenR + ModPow(2, N-i-1, baseM+1)) % (baseM+1);
          oddR = (oddR + ModPow(2, N-i-1, baseM-1)) % (baseM-1);
        }
      }
      for(int k = 0; k < N; k++){
        long long int cntr = 1;
        long long int R = 0;
        long long int M = 0;
        if(s[k] - '0'){
          M = baseM-1;
          R = (oddR - ModPow(2, N-k-1, M)) % M;
        }else{
          M = baseM+1;
          R = (evenR + ModPow(2, N-k-1, M)) % M;
        }
        if(R < 0)
          R += M;
        if(R == 0 || M == 0){
          cout << cntr << endl;
          continue;
        }
        do{
          M = Popcount(R);
          R = R % M;
          cntr++;
        }while(R > 0);
        cout << cntr << endl;
      }
    }else{
      for(int i = 0; i < N; i++){
        if(s[i] - '0'){
          evenR = (evenR + ModPow(2, N-i-1, baseM+1)) % (baseM+1);
        }
      }
      for(int k = 0; k < N; k++){
        long long int cntr = 1;
        long long int R = 0;
        long long int M = 0;
        if(s[k] - '0'){
          cout << 0 << endl;
          continue;
        }else{
          M = baseM+1;
          R = (evenR + ModPow(2, N-k-1, M)) % M;
        }
        if(R < 0)
          R += M;
        if(R == 0 || M == 0){
          cout << cntr << endl;
          continue;
        }
        do{
          M = Popcount(R);
          R = R % M;
          cntr++;
        }while(R > 0);
        cout << cntr << endl;
      }
    }
  }


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	string s; cin >> s;
	sort(all(s));
	if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main(void){
  int a, b;
  string op;
  while(1){
    cin >> a >> op >> b;
    if (op == "+")
      cout << a + b << endl;
    if (op == "-")
      cout << a - b << endl;
    if (op == "*")
      cout << a * b << endl;
    if (op == "/")
      cout << a / b << endl;
    if (op == "?")
      break;
  }
  return 0;
}


Measured memory_bytes: 3140
import java.util.Scanner;
import java.util.TreeMap;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		TreeMap<Integer, Integer> map = new TreeMap<>();

		int i;
		for(i = 0; i < n; i++) {
			map.put(scan.nextInt(), i + 1);
		}

		int cnt = 0;
		int len = map.size();
		for(int ans: map.values()) {
			cnt++;
			if(len > cnt)
				System.out.print(ans + " ");
			else
				System.out.println(ans);
		}

	}
}


Measured memory_bytes: 72280
let input = require('fs').readFileSync('/dev/stdin', 'utf8')
// let input = require('fs').readFileSync('./sample.txt', 'utf8')
.split(/\n| /)
// .map(item => parseInt(item))
.slice(0,-1)

const [N, X, time] = input.map(item => parseInt(item))


let total = 0
let total_t = 0
while(true){
    if(total >= N){
        console.log(total_t)
        return
    }
    total += X
    total_t += time
}

Measured memory_bytes: 29692
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int maxn = 2e6+5;
const LL MOD = 1e9+7;
LL inv[maxn], f[maxn], invf[maxn];

void init() {
    inv[1] = 1;
    for(int i = 2; i < maxn; ++i)
        inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
    f[0] = invf[0] = 1;
    for(int i = 1; i < maxn; ++i) {
        f[i] = f[i-1] * 1LL * i % MOD;
        invf[i] = invf[i-1] * inv[i] % MOD;
    }
}

LL comb(int a, int b) {
    if(b < 0 || b > a) return 0;
    return f[a]*invf[a-b]%MOD*invf[b]%MOD;
}

void run_case() {
    LL n, m;
    init();
    cin >> n >> m;
    if((n+m)%3) cout << "0\n";
    else {
        
        cout << (comb((n+m)/3, (2*n-m)/3) + MOD) % MOD;
    }
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 50508
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
  
using namespace std;

#define pi 3.141592653589793

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

int minprime(int m)
{
	while(!isprime(m)){
		m++;
	}
	return m;
}

long long int solve(int n)
{
	long long int pow_10_i_mod_n[2005] = {};
	pow_10_i_mod_n[0] = 1;
	pow_10_i_mod_n[1] = 10 % n;
	for(int i = 2; i < n - 1; i++){
		pow_10_i_mod_n[i] = (pow_10_i_mod_n[1] * pow_10_i_mod_n[i - 1]) % n;
	}
	long long int ans = 0;
	for(int i = 0; i < n - 1; i++){
		ans += pow_10_i_mod_n[i];
	}
	ans = ans % n;
	return ans;
}

int main()
{
	int n;
	cin >> n;
	int p_n = minprime(2 * n + 1);
	cout << solve(p_n) << endl;
	return 0;
}

Measured memory_bytes: 1180
//Bokann ga bokka--nn!!
//joi 2006yo-5
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int x[1005],y[1005],z[1005],re[1005];
int main(){
	int a,b,c;
	int n;
	while(1)
	{
		cin >> a >> b >> c;
		if(!a) return 0;
		cin >> n;
		int ok[305]={};
		//0未確定
		//1ok確定
		//2ng確定
		for(int i=0;i<n;i++)
		{
			cin >> x[i] >> y[i] >> z[i] >> re[i];
		}
		bool update=false;
		while(1)
		{
			for(int i=0;i<n;i++)
			{
				if(re[i]==1)
				{
					if(!ok[x[i]] || !ok[y[i]] || !ok[z[i]]) { ok[x[i]]=ok[y[i]]=ok[z[i]]=1; update=true;}
				}
				else
				{
					if(ok[x[i]]==1 && ok[y[i]]==1 && !ok[z[i]]) {ok[z[i]]=2; update=true;}
					if(ok[x[i]]==1 && ok[z[i]]==1 && !ok[y[i]]) {ok[y[i]]=2; update=true;}
					if(ok[z[i]]==1 && ok[y[i]]==1 && !ok[x[i]]) {ok[x[i]]=2; update=true;}
				}
			}
			if(!update) break;
			update=false;
		}
		for(int i=1;i<=a+b+c;i++)
		{
			cout << 2-ok[i] << endl;
		}
	}
}

Measured memory_bytes: 1176
N = int(input())
MOD = 10**9 + 7

def pow_mod(a, n, MOD):
    ret = 1
    for i in range(n):
        ret = a * ret % MOD
    return ret

ans = pow_mod(10, N, MOD) - 2*pow_mod(9, N, MOD) + pow_mod(8, N, MOD)
print(ans % MOD)


Measured memory_bytes: 62832
#include <stdio.h>
int main(void){
  int a,b,res=0,num=1;
  scanf("%d%d",&a,&b);
  if(b>1){
    while(num<b){
      res++;
      num+=(a-1);
    }
  }
  printf("%d\n",res);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String nl = System.getProperty("line.separator");
		StringBuilder p = new StringBuilder(1000);
		StringBuilder d = new StringBuilder(".");
		StringBuilder s = new StringBuilder("#");
		StringBuilder k = new StringBuilder(100);
		Scanner r = new Scanner(System.in);
		int h, w, ww;
		String u;
		for (w = 0; w < 4; ++w) {
			d.append(d);
			s.append(s);
		}
		ww = d.length();
		while ((h = r.nextInt()) + (w = r.nextInt()) > 0) {
			for (; w > ww; ww += ww) {
				d.append(d);
				s.append(s);
			}
			p.append(u = s.substring(0,w)).append(nl);
			k.setLength(0);
			k.append(d.substring(0, w)).append(nl)
			.replace(0, 1, "#").replace(w - 1, w, "#");
			for ( ; h > 2; --h) {
				p.append(k);
			}
			p.append(u).append(nl).append(nl);
		}
		System.out.print(p);
	}
}

Measured memory_bytes: 18380
N, M = gets.chomp.split().map(&:to_i)
items = gets.chomp.split().map(&:to_i)
items.sort!

another = [items.pop / 2]

(M-1).times do 
  if items.empty? || items.last < another.first
    another << (another.shift / 2)
  elsif items.last >= another.first
    another << (items.pop / 2)
  end
end

sum = 0
items.each { |i| sum += i } if !items.empty?
another.each { |i| sum += i }
puts sum

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

int T[3100];
char in[3100][3100];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	long long ret=0;
	for(int i=a-1;i>=0;i--){
		int tmp=0;
		for(int j=b-1;j>=0;j--){
			if(in[i][j]=='O')tmp++;
			if(in[i][j]=='I')T[j]++;
			if(in[i][j]=='J'){
				ret+=tmp*T[j];
			}
		}
	}
	cout<<ret<<endl;
}


Measured memory_bytes: 12248
#include <stdbool.h>
#include <stdint.h>

#define MEM_SIZE 500
static int64_t fib_mem[MEM_SIZE];

int64_t fibonacchi_number(int64_t n)
{
  static bool initialized = false;
  if (!initialized) {
    uint32_t i;
    for (i = 0; i < MEM_SIZE; i++) {
      fib_mem[i] = -1;
    }
    initialized = true;
  }

  if (n == 0)
    return fib_mem[n] = 1;
  else if (n == 1)
    return fib_mem[n] = 1;
  else {
    if (fib_mem[n] != -1)
      return fib_mem[n];
    else
      return fib_mem[n] = fibonacchi_number(n - 1) + fibonacchi_number(n - 2);
  }
}

#if !defined(TEST)
#include <stdio.h>
int32_t main(void)
{
  int32_t n;
  scanf("%d", &n);
  printf("%ld\n", fibonacchi_number(n));
  return 0;
}
#endif

Measured memory_bytes: 600
#!/usr/bin/env python

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    s = set()
    for a in A:
        if a in s:
            print("NO")
            exit()
        else:
            s.add(a)
    print("YES")

if __name__ == '__main__':
    main()



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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

ll N, K;

ll ans;

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

	cin >> N >> K;

	N = N%K;

	ans = min(N, abs(N-K) );
	cout << ans << "\n";
 
	return 0;		
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    vector<ll> ra(n + 1, 0);
    vector<ll> rb(m + 1, 0);
    bool madaa = true, madab = true;
    ll maxa, maxb;
    rep(i, n) {
        cin >> a.at(i);
        ra.at(i + 1) = ra.at(i) + a.at(i);
        if (madaa && ra.at(i + 1) > k) {
            maxa = i + 1;
            madaa = false;
        }
    }
    rep(i, m) {
        cin >> b.at(i);
        rb.at(i + 1) = rb.at(i) + b.at(i);
        if (madab && rb.at(i + 1) > k) {
            maxb = i;
            madab = false;
        }
    }
    if (madaa) maxa = a.size() + 1;
    if (madab) maxb = b.size();
    ll ans = 0;
    rep(i, maxa) {
        ll time = 0;
        while(rb.at(maxb) > k - ra.at(i)) {
            maxb--;
        }
        time = maxb + i;
        ans = max(time, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9528
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N;
	std::cin >> N;
	std::cout << (N*800 - N/15*200) << "\n";
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC143
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            string u = ReadLine();
            int cnt = 1;
            for(int i=0;i<s[0]-1;i++){
                if(u[i]!=u[i+1]){
                    cnt++;
                }

            }
            WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13408
#include <bits/stdc++.h>
    using namespace std;
    
        
    int main(){
        long long q , h ,s , d;
        cin >> q >> h >> s >> d;
        long long ans;
        ans = 0;
        q = 4 * q;
        h = 2 * h;
        long long o;
        o = min(q, min(h , s));
        long long n;
        cin >> n;
        if(n == 1){
            cout << o << endl;
            return 0;
        }
        long long t;
        t = min(d , o * 2);
        ans = n / 2;
        ans = ans * t;
        if(n % 2 == 1){
            ans += o;
        }
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 256
// Aizu 2217: Let's JUMPSTYLE
// 2017.9.23 bal4u@uu

#include <stdio.h>

int jump[100][100][2];  // [0]:?????£????????????r, [1]:?????£????????????c
int mark[100][100];

int main()
{
	int n, r, c, r0, c0, r1, c1;   // x, y??§????????????r,c???????????????y,x????????±???
	int new, ans;		// new: ??°???????????????, ans: ???????????????

	while (scanf("%d", &n) && n > 0) {
		for (r = 0; r < n; r++) for (c = 0; c < n; c++) {
			scanf("%d%d", &c1, &r1);
			jump[r][c][0] = r1, jump[r][c][1] = c1;
			mark[r][c] = 0;		// ?????????????????¨???????????????
		}
		ans = new = 0;
		for (r = 0; r < n; r++) for (c = 0; c < n; c++) {
			if (!mark[r][c]) {		// ??????????????????????????????
				new++;				// ??°?????????????????¨??????????????????
				mark[r][c] = new;	// ?????????
				for (r0 = r, c0 = c; ; r0 = r1, c0 = c1) {
					r1 = jump[r0][c0][0], c1 = jump[r0][c0][1];
					if (mark[r1][c1] > 0) {			// ???????????????????????\??£???
						if (mark[r1][c1] == new)	// ??°??????????????????????????????
							ans++;
						break;						// ?????????????????????????????????????????????
					}
					mark[r1][c1] = new;
				}
			}
		}
		printf("%d\n", ans);	// ????????????????????????????????????????????§????¨???????o(n^2)
	}
	return 0;
}

Measured memory_bytes: 1752
def main():
	import itertools
	
	n,d = map(int,input().split())
	# print(n,d)
	List = [list(map(int,input().split())) for i in range(n)]
	# print(len(List))
	combi = list(range(n))
	# print(combi)
	ans = 0
	for v in itertools.combinations(combi, 2):
		# print("v is {}".format(v))
		# print("v0 = {}".format(v[0]))
		# print("v1 = {}".format(v[1]))
		di = 0
		for i in range(d):
			# print("i = {}".format(i))
			# print("list v0 = {}".format(List[v[0]][i]))
			# print("list v1 = {}".format(List[v[1]][i]))
			di += (List[v[0]][i] - List[v[1]][i])**2
			# print("List[v[0]][i] =={}".format(List[v[0]][i]))
			# print("List[v[1]][i] =={}".format(List[v[1]][i]))
			# print("di = {}".format(di))
		# print(di)
		di = di**0.5
		# print(di)
		# print(isinstance(di,int))
		if di == int(di):
			ans += 1
			# print("ans = {}".format(ans))
		else:
			ans += 0
	print(ans)



	

if __name__ == "__main__":
	main()

Measured memory_bytes: 38256