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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using ll = int64_t;

using namespace std;

int n,k;
int64_t v[100];

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

    cin >> n >> k;
    REP(i,n) cin >> v[i];

    int64_t ans = 0;

    for(int l = 0;l <= n;l++){
        for(int r = 0;r <= n - l;r++){
            int left = k - (l + r);
            if(left < 0)continue;

            vector<int64_t> a;
            for(int i = 0;i < l;i++){
               a.push_back(v[i]);
            }
            for(int i = 0;i < r;i++){
                a.push_back(v[n-1-i]);
            }
            sort(a.begin(),a.end());

            int64_t sum = 0;
            for(auto i : a) sum += i;

            for(int i = 0;i < min((int)a.size(),left);i++){
               if(a[i] < 0)sum -= a[i];
               else break;
            }
            ans = max(ans,sum);
        }
    }

    cout << ans << '\n';
}



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

#define endl '\n'

using namespace std;

int N;

int a[100001],b[100001],c[100001];

long long dp[100001][5];

long long ans(int i,int judge){

  if(dp[i][judge]!=-1){
    return dp[i][judge];
  }

  if(i==N){
    return 0;
  }else{

    long long ret;
    if(judge==1){
      ret=max(ans(i+1,2)+b[i],ans(i+1,3)+c[i]);
    }else if(judge==2){
      ret=max(ans(i+1,1)+a[i],ans(i+1,3)+c[i]);
    }else if(judge==3){
      ret=max(ans(i+1,1)+a[i],ans(i+1,2)+b[i]);
    }else{
      ret=max(max(ans(i+1,1)+a[i],ans(i+1,2)+b[i]),ans(i+1,3)+c[i]);
    }
    
    return dp[i][judge]=ret;
    
  }
}

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  memset(dp,-1,sizeof(dp));

  cin>>N;

  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  
  cout<<ans(0,0)<<endl;
  
  return 0;

}


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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)


int main() {
  int a;
  cin >> a ;
  cout << pow(a,3) << endl;
}

Measured memory_bytes: 3968
/*
 * 0653_Sugoroku_and_Pieces.c
 *
 *  Created on: 2019/05/19
 *      Author: nagashima
 */

#include <stdio.h>
#include <stdlib.h>

int main(void){
	int N,M;
	int *X;
	int *A;

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

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

	for(int i=0;i<M;i++)
		if((X[A[i]-1]!=2019) && (X[A[i]]!=(X[A[i]-1]+1)))
			X[A[i]-1]++;


	for(int i=0;i<N;i++)printf("%d\n",X[i]);
        free(X);
        free(A);

	return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
itn N;
bool dbg = false;
double X[100], Y[100];
double d(int i, int j) {
    double x, y;
    x = X[i] - X[j];
    y = Y[i] - Y[j];
    x = abs(x);
    y = abs(y);
    return sqrt(x * x + y * y);
}
void solve() {
    double ans = 0;
    FOR(i, 0, N) {
        FOR(j, i + 1, N) {
            ans += d(i, j);
        }
    }
    ans = ans * 2.0 / (double)N;
    std::cout << std::fixed;
    std::cout << std::setprecision(10) << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 0, N) {
        cin >> X[i] >> Y[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 2e5+5;
ll n,k;
vi f,u;

ll check(ll x)
{
	vi temp(n);
	rep(i,0,n) temp[i] = x/f[i];
	sort(temp.begin(), temp.end());

	ll ans=0;
	rep(i,0,n) ans+=max((ll)0,u[i]-temp[i]);
	return ans<=k;
}

int solve()
{	
	cin>>n>>k;
	u.assign(n,0);
	f.assign(n,0);
	rep(i,0,n) cin>>u[i];
	rep(i,0,n) cin>>f[i];

	sort(u.begin(), u.end());

	ll low=0,high=1e13;

	while(low<high)
	{
		ll mid = low+(high-low)/2;
		// whatis(mid);
		if(check(mid)) high=mid;
		else low=mid+1;
	}

	cout<<low;

	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    int n;
    cin>>n;
    vector<map<char,int>> v(n);
    rep(i,n){
        string S;
        cin>>S;
        rep(j,S.size()){
            v[i][S[j]]++;
        }
    }
    map<char,int>ansm=v[0];
    for(int i=1;i<n;i++){
        irep(j,ansm){
            j->second=min(j->second,v[i][j->first]);
        }
    }
    string anss="";
    irep(i,ansm){
        rep(j,i->second){
            cout<<i->first;
        }
    }
    cout<<endl;

}


Measured memory_bytes: 256
import bisect
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
# print(bisect.bisect(A,4))
    
ans = 0
for b in B:
    aindex = bisect.bisect_left(A,b)
    cindex = bisect.bisect_right(C,b)
    # print(b,aindex,(len(C)-cindex))
    ans += aindex*(len(C)-cindex)

print(ans)



Measured memory_bytes: 23360
<?php
list($H, $W, $D) = array_map('intval', explode(' ', trim(fgets(STDIN))));

$table = [];
$map = [];
for ($i = 0; $i < $H; $i++) {
  $table[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $H; $i++) {
  for ($j = 0; $j < $W; $j++) {
    $num = $table[$i][$j];
    $map[$num] = [$j, $i];
  }
}

// print_r($map);

$tests = [];
$Q = (int)trim(fgets(STDIN));
for ($i = 0; $i < $Q; $i++) {
  $tests[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}

$magicTable = [];
// 1 ~ D - 1までをスタート地点としたときに N まで行ったときの魔力消費量の早見表を作成
function calcTotalMagic($start) {
  global $H, $W, $D, $table, $map, $magicTable;
  list($x, $y) = $map[$start];
  $now = $start;
  // print_r($map);
  $magic = 0;
  // print_r($now);
  // echo "now = $now\n";
  while ($now <= $H * $W) {
    $magicTable[$now] = $magic;
    // echo ("x, y = ($x, $y)\n");
    if ($now + $D > $H * $W) {
        break;
    }
    list($newX, $newY) = $map[$now + $D];
    $magic += abs($x - $newX) + abs($y - $newY);
    $x = $newX;
    $y = $newY;
    $now = $table[$y][$x];
  }
}

for ($i = 1; $i <= $D; $i++) {
  calcTotalMagic($i);
}

// print_r($magicTable);

function solve($test) {
  global $magicTable;
  $L = $test[0];
  $R = $test[1];
  return $magicTable[$R] - $magicTable[$L];
}

// print_r($magicTable);
foreach ($tests as $test) {
  $magic = solve($test);
  echo "$magic\n";
}


Measured memory_bytes: 95220
/*
  A - Shiritori
  <http://abc060.contest.atcoder.jp/tasks/abc060_a>
*/

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

int main(int argc, char const *argv[]) {

  char A[11],B[11],C[11];
  int len;

  scanf("%s %s %s", A, B, C);
  len = strlen(A);
  if( B[0] == A[len-1] ){
    len = strlen(B);
    if( C[0] == B[len-1] ){
      printf("YES");
      return 0;
    }
  }
  printf("NO");

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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 ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

int main(void) {
   ll N;
   int Q;
   cin >> N >> Q;
   
   vector<ll> C(N+1, 0), R(N+1, 0);
   vector<bool> C_used(N+1, false), R_used(N+1, false);
   
   ll cl, rw, cmin, rmin;
   cl = rw = N-1;
   cmin = rmin = N;
   rep(i, 0, Q) {
     int cmd, x;
     cin >> cmd >> x;
     if(cmd==1) {
       //(1, x)
       C_used[x] = true;
       if (x>=cmin) continue;
       
       rep(j, x, cmin) C[j] = cl;
       rw = x - 1;
       cmin = x; 
       
     } else {
       //(x, 1)
       R_used[x] = true;
       if (x>=rmin) continue;
       
       rep(j, x, rmin) R[j] = rw;
       cl = x - 1;
       rmin = x;
     
     }
    
   }
   ll sum = 0;
   rep(i, 1, N) {
     if (R_used[i]) sum += R[i];
     if (C_used[i]) sum += C[i];
   }
   ans = (N-2)*(N-2)+Q-sum;
   cout << ans << endl;
    return 0;
}





Measured memory_bytes: 6404
#include <iostream>
using namespace std;
 
int main(){
    long x,y=0,z=0;
	cin >> x;
    if (x >= 500 ){
        y = x/500;
      	if (x%500 >= 5){
      		z = (x%500)/5;
    		}
    } else if (x >= 5 ){
   		z = x/5;
    }
    cout << y*1000+z*5 << endl;
    return 0;
}

Measured memory_bytes: 256
#coding:utf-8
antena = []
for i in range(5):
    antena.append(int(input()))
k = int(input())
ans = False

for i in range(5):
    for j in range(5):
        if antena[i] - antena[j] > k:
            ans = True
            break

if ans == True:
    print(':(')
else:
    print('Yay!')

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    string S;
    cin >> S;
    char c = S[0];
    int ans = 0;
    for(int i = 1; i < S.size() ; i++){
        if(c != S[i]){
            ans++;
            c = S[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args) {
		int pasta[] = new int[3];
		int juice[] = new int[2];
		Scanner sc = new Scanner(System.in);
		for(int i = 0; i < 3; i++){
			pasta[i] = sc.nextInt();
		}
		for(int i = 0; i < 2; i++){
			juice[i] = sc.nextInt();
		}
		int minp =3000;
		for(int i = 0; i < 3; i++){
			if(minp > pasta[i]){
				minp = pasta[i];
			}
		}
		int minj = 3000;
		for(int i = 0; i < 2; i++){
			if(minj > juice[i]){
				minj = juice[i];
			}
		}
		int sum = minp + minj;
		sum = sum - 50;
		System.out.println(sum);
	}

}

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

int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }

int main() {
    int n;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    double ans = 0;
    rep(i,n){
        cin >> x[i] >> u[i];
        if(u[i] == "JPY")ans += x[i];
        else ans += x[i] * 380000.0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int sum=0;
    for(int i=0;i<3;i++)sum+=sc.nextInt();
    if(sum>21)System.out.println("bust");
    else System.out.println("win");
  }
}

Measured memory_bytes: 23124
#include<stdio.h>
int main(){
  int n,p;
  scanf("%d",&n);
  switch(n%10){
  	case 0:
    case 1:
    case 6:
    case 8:
      printf("pon\n");
      break;
    case 3:
      printf("bon\n");
      break;
    default:
      printf("hon\n");
  }
  return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L


int Z_algo(string s) {
    int n = s.length();
    vector<int> z(n);
    int L = 0, R = 0;
    for (int i = 1; i < n; i++) {
        if (i > R) {
            L = R = i;
            while (R < n && s[R - L] == s[R]) R++;
            z[i] = R - L; R--;
        }
        else {
            int k = i - L;
            if (z[k] < R - i + 1) z[i] = z[k];
            else {
                L = i;
                while (R < n && s[R - L] == s[R]) R++;
                z[i] = R - L; R--;
            }
        }
    }
    int mx = 0;
    for (int i = 0; i < n; i++) mx = max(mx, min(i, z[i]));
    return mx;
}
const int mxN = 1e9 +7;

int main() {
    long long n;
    cin >> n;
    vector<vector<int>> a(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 1; j++) {
            int x; cin >> x; x--;
            a[i].push_back(x);
        }
    }
    vector<int> pos(n);
    int days = 0;
    while (true) {
        vector<bool> visited(n);
        bool ok = false;
        for (int j = 0; j < n; j++) {
            if (visited[j] || pos[j] == n - 1) continue;
            if (visited[a[j][pos[j]]]) continue;
            if (a[a[j][pos[j]]][pos[a[j][pos[j]]]] == j) {
                pos[a[j][pos[j]]]++;
                visited[j] = true;
                visited[a[j][pos[j]]] = true;
                pos[j]++;
                ok = true;
            }
        }
        if (!ok) {
            break;
        }
        days++;
    }
    bool good = true;
    for (int i = 0; i < n; i++) {
        if (pos[i] != n-1) good = false;
    }
    if (!good) {
        cout << -1;
    }
    else {
        cout << days;
    }
    return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>v[100005];
bool visi[100005];
ll sum[100005];
ll ans;

void dfs(ll u)
{
    visi[u]=true;
    for(auto i:v[u])
    {
        if(visi[i]==false)
        {
            dfs(i);
        }
        sum[u]=max(sum[i]+1,sum[u]);
    }
    ans=max(ans,sum[u]);
}

int main() {
	ll m,n,k,i,j,w;
    cin>>n>>m;
    while(m--)
    {
        cin>>i>>j;
        v[i].push_back(j);
    }
    for(i=1;i<=n;i++)sum[i]=1;
    ans=-1;
    for(i=1;i<=n;i++)
    if(!visi[i])
    dfs(i);
    cout<<ans-1;
	return 0;
}


Measured memory_bytes: 12640
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C&lang=ja
ALDS1_1_c:素数の数

*/

#include <bits/stdc++.h>
#include <math.h>


#define PI 3.14159265358979323846;

using namespace std;

void disp(int *n, int N);

int main(void){

	unsigned short int r;
	cin >> r;

	unsigned short int ratio = r*r;
	//unsigned short int menseki_r = r*r*PI;
	//unsigned short int ratio = /menseki_std
	printf("%d\n",ratio);

	


	return 0;
	
  
}

void disp(int *n, int N){
	//printf("disp: ");
	for(int i=0; i<N; i++) {
		printf("%d", n[i]);
		if( i != N-1) printf(" ");
	}
	printf("\n");
}



Measured memory_bytes: 256
import math
from operator import mul
from functools import reduce

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

x,y=map(int,input().split())
if y>2*x:
    print(0)
    exit()
if y<x/2:
    print(0)
    exit()
if (x+y)%3!=0:
    print(0)
    exit()
if (-x+2*y)/3%1!=0:
    print(0)
    exit()
if (-y+2*x)/3%1!=0:
    print(0)
    exit()

x_=int((-x+2*y)/3)
y_=int((2*x-y)/3)

print(cmb(x_+y_,x_)%(10**9+7))


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

int h,w,k;

vector<int> inttovec(int bit)
{
	vector<int> res;
	for(int i = 0;bit!=0;i++)
	{
		if(bit&1)res.push_back(i);
		bit/=2;
	}
	return res;
}

vector<int> sep(int bit)
{
	vector<int> bitzen = inttovec(bit);
	vector<int> res(h);
	for(auto i:bitzen)
	{
		for(int j = i+1;j<h;j++)
		{
			res[j]++;
		}
	}
	//for(auto i:res)cout<<i<<' ';cout<<endl;
	return res;
}


int main()
{
	cin >> h >> w >> k;
	vector<string> g(h);
	for(int i =0;i<h;i++)
	{
		cin >> g[i];
	}
	ll ans = 1e9;
	for(int bit=0;bit<1<<(h-1);bit++)
	{
		ll now = inttovec(bit).size();
		if(now==-1)now=0;
		vector<int> set = sep(bit);
		vector<int> cnt(h);
		bool isans = true;
		for(int i = 0;i<w;i++)
		{
			for(int j = 0;j<h;j++)
			{
				cnt[set[j]]+=g[j][i]-'0';
			}
			bool koe = false;
			for(int j = 0;j<h;j++)
			{
				if(cnt[j]>k)
				{
					koe = true;
				}
			}
			
			if(koe)
			{
				now ++;
				for(int j = 0 ;j<h;j++)cnt[j]=0;
				for(int j = 0;j<h;j++)
				{
					cnt[set[j]]+=g[j][i]-'0';
					if(cnt[set[j]]>k)
					{
						//cout<<i<<' '<<j<<endl;
						isans=false;
					}
				}
			}
		}
		if(isans==false)continue;
		//cout<<bit<<endl;
		ans = min(ans,0LL+now);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline int IN(void)
{
  int x=0,f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
static inline void OUT(int x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline int min(const int a,const int b){return a<b?a:b;}
int main(void)
{
  int N=IN(),a=0,across,d,down,p,q,xy,que[251501],vacant[252525],dist[252525];
  rep(i,N)
  {
    xy=(N+2)*(i+1)+1;across=min(i,N-1-i),down=3;
    rep(j,across){dist[xy++]=down++;}
    rep(j,N-2*across){dist[xy++]=across+3;}
    rep(j,across){dist[xy++]=--down;}
  }
  rep(k,N*N)
  {
    xy=IN();xy+=(xy-1)/N*2+N+2;a+=dist[xy];p=0,q=0;
    que[p++]=xy;vacant[xy]=1;
    while(p>q)
    {
      xy=que[q++],d=dist[xy]-vacant[xy]+1;
      if(dist[xy-N-2]>d){dist[xy-N-2]=d;que[p++]=xy-N-2;}
      if(dist[xy+N+2]>d){dist[xy+N+2]=d;que[p++]=xy+N+2;}
      if(dist[xy-1]>d){dist[xy-1]=d;que[p++]=xy-1;}
      if(dist[xy+1]>d){dist[xy+1]=d;que[p++]=xy+1;}
    }
  }
  OUT(a-3*N*N);return puts(""),0;
}

Measured memory_bytes: 4464
#include<iostream>
#include<bits/stdc++.h>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vpll vector<pair<ll,ll> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(i,s,n)   for(int i=s;i<=n;i++)
#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)
#define popcnt(x) __builtin_popcount(x)
#define EPS 1e-9
#define INF 1e17
using namespace std;
const int mod = 1000000007;
const int N = 1000000+5;
const double pi = acos(-1);
class cmp{
public:
	bool operator() (pair<ll, pll> &A, pair<ll, pll> &B){
		return A > B;
	}
};
template<class a,class b,class c>
class tup{
public:
	a f;
	b s;
	c t;
	tup(a f,b s,c t):f(f),s(s),t(t){}
	tup(){}
};
bool by_sec(pll &A, pll &B){
	return A.second < B.second;
}
ld dist(pll p1, pll p2){
	return (ld)sqrt((ld)(p1.first - p2.first)*(p1.first - p2.first) + (ld)(p1.second - p2.second)*(p1.second - p2.second));
}
ll fact[1000009], inv[1000009];
ll fp(ll a, ll b){
	if (b == 0)
		return 1;
	ll ans = fp(a, b / 2);
	ans = (ans * ans) % mod;
	if (b % 2 != 0)
		ans = (ans * (a % mod)) % mod;
	return ans;
}
void FacInv(ll n){
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}
ll ncr(ll n, ll r){
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}

ll dp[N];
int main()
{
	Amr_Abdelazim
		ll n;
	cin >> n;
	for (auto &i : dp)i = 1e15;
	dp[n - 1] = 0;
	vll v(n);
	rep(i, n)cin >> v[i];
	for (int i = n - 1; i >= 0; i--){
		if (i-1>=0)
		dp[i - 1] = min(dp[i - 1], abs(v[i] - v[i - 1]) + dp[i]);
		if (i - 2 >= 0)
		dp[i - 2] = min(dp[i - 2], abs(v[i] - v[i - 2]) + dp[i]);
	}
	cout << dp[0] << "\n";

	return 0;
}


Measured memory_bytes: 11944
#include<bits/stdc++.h>
using namespace std;
#define N (100010)
#define ll long long
int n,a[N],t[N];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++){
		bool f=0;
		int l=1,r=t[0],ans=0;
		while (l<=r){
			int mid=(l+r)>>1;
			if (t[mid]<a[i]) ans=mid,r=mid-1;
			else l=mid+1;
		}
		if (ans) t[ans]=a[i];
		else t[++t[0]]=a[i];
	}
	printf("%d",t[0]);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void solve(){
    ll n,k;
    cin>>n>>k;
    vll v(n);
    fr(i,0,n)
    cin>>v[i];
    sort(v.begin(),v.end());
    ll ans=0;
    if(k>=n){
    cout<<0; return ;}
    for(int i=0;i<n-k;i++)
    ans+=v[i];
    cout<<ans;
}

int main(){
    ll t=1;
//cin>>t;
    while(t--){
     solve();
     cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#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 MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n;
map<LL, PII> S;
vector<PII> ans;
LL offset;

int main()
{
	scanf("%d", &n);
	rep(i, n) {
		LL d;
		scanf("%lld", &d);
		S[d] = MP(1, i + 1);
	}
	while(S.size() >= 2) {
		pair<LL, PII> cur = *S.rbegin();
		S.erase(cur.first);
		LL nd = cur.first - n + 2 * cur.second.first;
		if(S.find(nd) == S.end()) {
			printf("-1\n");
			return 0;
		}
		S[nd].first += cur.second.first;
		offset += cur.second.first;
		ans.push_back(MP(cur.second.second, S[nd].second));
	}
	if(S.begin()->first != offset) printf("-1\n");
	else rep(i, ans.size()) printf("%d %d\n", ans[i].first, ans[i].second);
	return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int a,b; cin >> a >> b;
    vector<int> s(1000,0);
    rep1(i,1000)s[i]=s[i-1]+i;
    int c,d;
    rep(i,1000){
        if(s[i+1]-s[i] == b-a)d=s[i+1],c=s[i];
    }
    cout << d-b << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[]A = new int[N+1];
		for(var i=0;i<N+1;i++){
			A[i] = int.Parse(str[i]);
		}
		string[] str2 = Console.ReadLine().Split();
		int[]B = new int[N];
		for(var i=0;i<N;i++){
			B[i] = int.Parse(str2[i]);
		}
		long ans = 0;
		for(var i=0;i<N;i++){
          	int a1 = Math.Min(A[i],B[i]);
			ans += a1;
			A[i] -= a1;
          	B[i] -= a1;
          	int a2 = Math.Min(A[i+1],B[i]);
			ans += a2;
			A[i+1] -= a2;
          	B[i] -= a2;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 34780
#include <stdio.h>
#include<iostream>
#include<algorithm>
#include <string.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
int mp[55][26];
int fi[27];
int main()
{	
	/*freopen("input.txt","r",stdin);*/
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		/*cout<<s[0]-'a'+1<<endl;*/
		for(int j=0;j<s.length();j++)
			mp[i][s[j]-'a'+1]++;
	}
	fill(fi,fi+27,10000);
	for(int i=1;i<=26;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(mp[j][i]<fi[i])
				fi[i]=mp[j][i];
		}
	}
	for(int i=1;i<=26;i++)
	{
		if(fi[i]==0) continue;
		for(int j=1;j<=fi[i];j++)
			printf("%c",i-1+'a');
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N),indegree(N),vis(N); char st[N];
vector<int> adj[N];
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
bool comp(const pii a, const pii b)
{
    if(a.se==b.se)
    return a.fi<b.fi;
    return a.se<b.se;
}
vector<vector<int>> dp,v;
void solve()
{
    int n,k; cin>>n>>k;
    map<int,int> mp; int x;
    for(int i=0;i<k;i++)
    {
        cin>>x; int y;
        for(int j=0;j<x;j++)
        cin>>y,mp[y]++;
    }
    cout<<n-mp.size();
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 19412
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();    
        int n = r.i();
        int[] a = r.ii();
        int[] b = new int[n];
        for(int i = 0; i < n; i++){
            while(n-1-2*i >= 0){
                b[i] = a[n-1-2*i];
                i++;
            }
            int j = 2*i-n;
            int k = 0;
            while(i < n){
                b[i] = a[j+2*k];
                i++;
                k++;
            }                
        }
        for(int x : b)
            print(x+" ");
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        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;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 58888
#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-12, PI = acos(-1);
const int N = 3e3 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

vector<int> vec[N];
int played[N];
int kam[N];

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, a;
  cin >> n;
  queue<int> Q;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < n; ++j) {
      cin >> a;
      vec[i].push_back(a);
    }
//    reverse(vec[i].begin(), vec[i].end());
    Q.push(i);
  }
  int day = 1;
  int matches = (ll)(n) * (ll)(n - 1) / 2;
  while(!Q.empty()) {
    queue<int> Q2;
    int sz = Q.size();
    while(sz--) {
      int me = Q.front();
      Q.pop();
      if(kam[me] == n - 1)
        continue;
      int to = vec[me][kam[me]];
      if(kam[to] == n - 1 || to == me)
        continue;
      int toTo = vec[to][kam[to]];
      if(toTo != me) continue;
      if(played[me] < day && played[to] < day) {
        played[me] = day;
        played[to] = day;
        kam[me]++;
        kam[to]++;
        if(kam[me] != n - 1)
          Q2.push(me);
        if(kam[to] != n - 1)
          Q2.push(to);
        --matches;
      }
    }
    swap(Q, Q2);
    if(!matches)
      break;
    ++day;
  }
  if(matches)
    cout << -1;
  else
    cout << day;
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
// 返り値: a と b の最大公約数
template <typename T>
ll GCD(T a, T b) {
  if (b == 0) {
    return a;
  }
  ll d = GCD(b, a % b);
  return d;
}
int main() {
  ll N;
  cin >> N;
  vector<ll> T(N);

  REP(i, N) { cin >> T[i]; }
  ll ans = T[0];
  REP(i, N) { ans = (ans) / GCD(ans, T[i]) * T[i]; }
  cout << ans << endl;
}

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

int main(){
 int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  sort(arr, arr+n);
  cout<<arr[n/2] - arr[n/2-1]<<endl;
  return 0;
}

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

long a[100010],n,k,i,j,x,c,res;
int main()
{
  cin>>n>>k;
  for(i=0;i<n;++i)cin>>a[i];
  for(i=62;i>=0;--i){
    c=0;
    for(j=0;j<n;++j)c+=(a[j]>>i)&1;
    if(2*c<n&&(x|(1L<<i))<=k)x|=1L<<i;
  }
  res=0;
  for(i=0;i<n;++i)res+=x^a[i];
  cout<<res<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long N, long long K, std::vector<long long> H){
    sort(all(H));
    ll sum=0;
    rep(i,N-K){
        sum+=H[i];
    }
    op(sum)
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, K, std::move(H));
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int co[2]={0};
	int a,b,c;
	char d;
	while(cin>>a>>d>>b>>d>>c){
		if(hypot(a,b)==c)co[0]++;
		if(a==b)co[1]++;
	}
	rep(i,2)cout<<co[i]<<endl;
}

Measured memory_bytes: 1172
from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
for num in a:
  if num % 4 == 0:
    d[4] += 1
    continue
  if num % 2 == 0:
    d[2] += 1
    continue
print("Yes" if n//2 <= d[4] + (d[2] // 2) else "No")

Measured memory_bytes: 14636
// atcoder/abc166/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  const lli X = 1e9 + 1;
  vec<pair<lli, lli>> v;
  for (lli i = 0; ; ++i) {
    lli x = i * i * i * i * i;
    if (v.size() && X < abs(v.back().first - x)) break;
    v.push_back(make_pair(x, i));
  }
  // cout << v << endl;

  lli x;
  while (cin >> x) {
    bool f = true;
    each (y, v) {
      if (!f) break;
      each (z, v) {
        if (y.first - z.first == x) {
          cout << y.second << ' ' << z.second << endl;
          f = false;
          break;
        }
        if (y.first + z.first == x) {
          cout << y.second << ' ' << -z.second << endl;
          f = false;
          break;
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3644
M = 10**9+7
n, k = map(int, input().split())
*a, = map(int, input().split())
a = a[::-1]
b = [0]*2001
c = [0]*n
d = [0]*n
for i in range(n):
    b[a[i]] += 1
    if i > 0:
        c[i] += sum(b[:a[i]])
for i in range(n):
    f = b[:a[i]]
    if f: d[i] += sum(f)
g, h = sum(c)%M, sum(d)%M
print((k*g+k*(k-1)//2*h)%M)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define f1(n) for(int i=0;i<n;++i)
#define f2(n) for(int i=1;i<=n;++i)
#define lson(x) x<<1
#define rson(x) x<<1|1
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const int maxn = 2e5 + 5;
const int mod = 0x3f3f3f3f;
const ll Mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll Inf = (ll)1e15;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	cout << n*(n-1)/2+m*(m-1)/2 << endl;


	return 0;
}

Measured memory_bytes: 384
//答え見ました。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1000000007;

int n;

void dfs(string s,char mx){
  if(s.size()==n) printf("%s\n", s.c_str());
  else{
    for(char c='a'; c<=mx; c++){
      if(c==mx) dfs(s+c,mx+1);
      else dfs(s+c,mx);
    }
  }
}


int main() {
  cin >> n;
  dfs("",'a');
  return 0;
}

Measured memory_bytes: 1536
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int N = sc.nextInt();
			int S = sc.nextInt();
			int W = sc.nextInt();
			int Q = sc.nextInt();
			if ((N|S|W|Q) == 0) {
				break;
			}
			
			int a[] = new int[N];
			
			int g = S;
			for(int i =0; i < N;i++){
				a[i] = (g/7)%10;
				if(g%2==0){
					g = (g/2);
				}else{
					g = (g/2)^W;
				}
			}
			int ans = 0;
			
			if(Q == 2 || Q==5){
				ans = 0;
				int zeroc = 0;
				for(int i = 0; i < N ; i++){
					if(a[i] != 0){
						zeroc++;						
					}
					if(a[i]%Q == 0){
						ans += zeroc;
						
					}
				}
				
				System.out.println(ans);
				continue;
			}
			
			
			int used[] = new int[Q];
			used[0] = 1;
			
			int p = 1;
			int prev = 0;
			
			for(int i = 0; i < N ;i++){
				
				int v = (prev+p*a[N-i-1])%Q;
				
				prev = v;					
				
				if(a[N - i-1] != 0){
					ans += used[v];
				}
				used[v]++;
			
				p = (p*10)%Q;
				
			}
			System.out.println(ans);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
def is_valid(n, a)
  counter = Hash.new(0)
  a.each do |i|
    counter[i] += 1 
  end
  if counter[0] == n
    return "Yes"
  end
  if n % 3 != 0
    return "No"
  end

  flag1 = Array.new
  flag2 = Array.new
  counter.each do |key, value|
    if n / 3 == value
      flag1.push(key)
    end
    if 2 * n / 3 == value
      flag2.push(key)
    end
  end
  if flag2.length == 1 and flag1.length == 1 and flag1[0] == 0
    return "Yes"
  end
  if flag1.length == 3 and flag1.reduce(:^) == 0
    return "Yes"
  end
  return "No"
end

n = gets.to_i
a = gets.split.map(&:to_i)
puts is_valid(n, a)


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

const ll p = 1e9+7;
const int M = 2005;

ll fact[M*M], invfact[M*M], inv[M*M], dp[M][M], part[M][M], n, k;

ll comb(int x, int y) {
	if (x < 0 || y < 0 || x < y)
		return 0;
	return fact[x]*invfact[y]%p*invfact[x-y]%p;
}

int main() {
	cin >> n >> k;
	if (k == 1) {
		cout << "1\n"; return 0;
	}
	inv[1] = fact[0] = fact[1] = invfact[0] = invfact[1] = 1;
	for (int i = 2; i < M*M; ++i) {
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;
		fact[i] = i*fact[i-1]%p;
		invfact[i] = inv[i]*invfact[i-1]%p;
	}

	for (int i = 1; i <= n; ++i) {
		// casework on longest prefix of 0s
		if (i == 1)
			dp[i][1] = 1;
		else
			for (int j = 1; j <= i; ++j)
				dp[i][j] = comb(i*k-j-1, k-2)*i%p*part[i-1][j-1]%p;
		
		for (int j = i; j >= 0; --j)
			part[i][j] = (part[i][j+1]+dp[i][j])%p;
	}

	cout << part[n][0] << endl;
}


Measured memory_bytes: 139776
N = int(input())
ans = "Yes"
arr = []
for i in range(N):
    arr.append(input())
    if not i == 0:
        if arr[i-1][-1] == arr[i][0] and not arr[i] in arr[:-2]:
            pass
        else:
            ans = "No"
            break

print(ans)


Measured memory_bytes: 2940
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
use std::cmp;
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        S: chars,
    }
    let mut count0 = 0;
    let mut count1 = 0;

    for ind in 0..S.len() {
        if ind % 2 == 0 {
            match S[ind] {
                '0' => count1 += 1,
                '1' => count0 += 1,
                _ => (),
            }
        } else {
            match S[ind] {
                '0' => count0 += 1,
                '1' => count1 += 1,
                _ => (),
            }
        }
    }

    println!("{}", cmp::min(count0, count1));
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, A, B;
    cin >> K >> A >> B;
    REP(i, A, B) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <queue>
#include <stack>

int n;

std::queue<int> f;
std::stack<int> s, in;

int main() {

	std::cin >> n;

	int a;

	for (int i = 0; i < n; ++i) {
		std::cin >> a;
		in.emplace(a);
	}

	if (in.size() == 1) {
		std::cout << in.top() << std::endl;
		return 0;
	}

	while (!in.empty()) {

		f.emplace(in.top());
		in.pop();

		if (!in.empty()) {

			s.emplace(in.top());
			in.pop();
		}
	}

	while (!f.empty()) {
		std::cout << f.front() << ' ';
		f.pop();
	}

	while (s.size() > 1) {
		std::cout << s.top() << ' ';
		s.pop();
	}

	std::cout << s.top() << std::endl;

	//system("pause");

	return 0;
}

Measured memory_bytes: 3072