akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 0 ; i < n ; i++) {
			b[i] = sc.nextInt();
		}
		for(int i = 0 ; i < n ; i++) {
			c[i] = sc.nextInt();
		}
		long ans = 0;
		Arrays.sort(a);
		Arrays.sort(c);
		for(int i  = 0 ; i < n ; i++) {
			ans += 0L + binary_search(a, b[i]) * (n - binary_search(c, b[i] + 1));
		}
		System.out.println(ans);
	}

	public static long binary_search(int[] a, int x) {
		int l = -1;
		int r = n;
		while(r - l > 1) {
			int i = (l + r) / 2;
			if(x <= a[i]) r = i;
			else l = i;
		}
		return r;
	}
}


Measured memory_bytes: 96704
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  int N;
  cin >> N;
  int x[N], y[N], h[N];
  int nonzero;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> h[i];
    if (h[i] != 0) nonzero = i;
  }

  bool foundFlag;
  int xAns;
  int yAns;
  int hAns;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      int H = abs(i - x[nonzero]) + abs(j - y[nonzero]) + h[nonzero];

      foundFlag = true;
      for (int k = 0; k < N; k++) {
        if (max(H - abs(i - x[k]) - abs(j - y[k]), 0) != h[k]) {
          foundFlag = false;
          break;
        }
      }

      if (foundFlag) {
        xAns = i;
        yAns = j;
        hAns = H;
        break;
      }
    }
    if (foundFlag) break;
  }

  cout << xAns << " " << yAns << " " << hAns << endl;

  return 0;
}

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

int main() {
int H,W;
cin>>H>>W;
vector <vector<char>>table(H,vector<char>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>table.at(i).at(j);
}
}
vector<int> wrow;
vector <int>wcolumn;
for(int i=0;i<H;i++){
bool x =true;
for(int j=0;j<W;j++){
if(table.at(i).at(j)=='#'){
x=false;
break;
}
}
if(x){
wrow.push_back(i);
}
}
for(int i=0;i<W;i++){
bool x =true;
for(int j=0;j<H;j++){
if(table.at(j).at(i)=='#'){
x=false;
break;
}
}
if(x){
wcolumn.push_back(i);
}
}

for(int i=0;i<H;i++){
bool p=true;
bool q = true;
for(int k:wrow){
if(i==k){
p=false;
break;
}}
if(p){for(int j=0;j<W;j++){
q=true;
for(int k:wcolumn){
if(j==k){
q=false;
break;}
}
if(p&&q){cout<<table.at(i).at(j);}}}
if(p){cout<<endl;}
}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N;long M;int V,P;cin>>N>>M>>V>>P;
	long A[N];
	rep(i,0,N) cin>>A[i];
	sort(A,A+N);
	long s[N]={};s[N-1]=A[N-1];
	for(int i=N-2;i>=0;i--){
		s[i]=s[i+1]+A[i];
	}
	int ans=P;long temp=M*(P-1);
	rep(i,0,N-P){
		if(A[i]+M<A[N-P]) continue;
		if(M*i+(A[i]+M)*(N-P+1-i)+s[N-P+1]-s[i]+temp<M*V) continue;
		ans++;
	}cout<<ans<<endl;
}

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

int main() {

    int n; cin >> n;
    int curr = 1;
    int ans = 0;
    for(int i = 0;i<n;i++){
        int x; cin >> x;
        if(x == curr) {
            curr ++;
        } else {
            ans ++;
        }
    }
    if(ans >= n) cout << "-1" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 
 * This code is written by Sanskar Agarwal
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

#define ll long long
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define S second
#define F first
#define PB push_back

const ll MAX=1000000000000000;
ll dp[101][100001];

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


    ll n,W;
    cin>>n>>W;
    ll i,v[n],w[n],sm=0;
    for(i=0;i<n;i++) {
        cin>>w[i]>>v[i];
        sm+=v[i];
    }
    ll ans=0;
    for(i=1;i<=sm;i++)
        dp[0][i]=MAX;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=sm;j++)
        {
            if(v[i-1]>j)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=min(dp[i-1][j-v[i-1]]+w[i-1],dp[i-1][j]);
            //cout << dp[i][j] << " ";
            if(dp[i][j]<=W)
            {
                if(j>ans)
                    ans=j;
            }
        }
        //cout << "\n";
    }
    cout << ans;
    return 0;
}


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

using namespace std;

int main(){
	int tmp0,tmp1;
	int n=0;
	int sum0=0,sum1=0;

	char unko;
	while(cin>>tmp0){
		cin>>unko;
		cin>>tmp1;
		sum0+=tmp0*tmp1;
		sum1+=tmp1;
		n++;
	}
	double ans2=sum1/(double)n;
	cout<<sum0<<endl;
	cout<<(int)(ans2+0.5)<<endl;
}

/*
Sample Input
100,20
50,10
70,35
Output for the Sample Input
4950
22

*/

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int N, M;
int ng[101010];
mint dp[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a; cin >> a;
		ng[a] = true;
	}

	dp[0] = 1;
	rep(i, 0, N) rep(d, 1, 3) if (!ng[i + d]) dp[i + d] += dp[i];
	cout << dp[N] << endl;
}







Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precise cout.precision(8); cout << fixed;
#define seed srand(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main() {

    zoom;    
    ll N, i;
    cin >> N;
    vector<string> A(N);
    vector<ll> B(N);
    for(i = 0; i < N; i += 1)
        cin >> A[i] >> B[i];
    string x;
    cin >> x;
    ll ans = 0;
    for(i = 0; i < N; i += 1) {
        if(A[i] == x) {
            i += 1;
            break;
        }
    }
    for(; i < N; i += 1)
        ans += B[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if (a < b)
    {
        printf("a < b\n");
    }
    if (a > b)
    {
        printf("a > b\n");
    }
    if (a == b)
    {
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
import java.util.*;


public class Main {
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if (A == B && B == C) {
			System.out.println("No");
		}
		else if(A != B && B != C && C != A) {
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21716
N = int(input())
S = input()
num = S[1:].count("E")
ans = num
for i in range(1, N):
    if S[i - 1] == "W":
        num += 1
    if S[i] == "E":
        num -= 1
    ans = min(num, ans)
print(ans)
    

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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.in", "r", stdin);
#endif

    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    printf("%lld\n", 1ll * z / x * y);
    return 0;
}


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

int A, B, C, D, E, F;

int main() {
   cin >> A >> B >> C >> D >> E >> F;

   // 砂糖、水をそれぞれ独立して作る
   set<int> waterSet, sugarSet;

   // 水
   for (int i = 0; i <= 33; i++) {
      for (int j = 0; j <= 33; j++) {
         int w = 100*A*i + 100*B*j;
         if (w <= F) waterSet.insert(w);
      }
   }

   // 砂糖
   for (int i = 0; i < 3010; i++) {
      for (int j = 0; j < 3010; j++) {
         int s = C*i + D*j;
         if (s <= F) sugarSet.insert(s);
      }
   }
  
   const double nLim = (double)E/(100+E); // 濃度の限界値
   double noudo = -1; // 初期値を-1にしないと一度も更新されなくなってしまう
   int ans1 = 0, ans2 = 0;
   for (int s : sugarSet) {
      for (int w : waterSet) {
         int sum = s + w; // 砂糖水
         double x = (double)s/sum; // 作った砂糖水の濃度
         if (sum <= F && x <= nLim && x > noudo) { // 条件を満たす && 濃度が最大値
            noudo = x;
            ans1 = sum, ans2 = s;
         }
      }
   }
   printf("%d %d\n", ans1, ans2);

   return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    double x[N + 1];
    double y[N + 1];
    REP(i, N){
        cin >> x[i] >> y[i];
    }

    ll Nfac = 1;
    vector<ll> order;
    REP(i, N){
        Nfac *= i;
        order.push_back(i);
    }

    double a, b;
    double ans = 0;
    do{
        a = x[order[0]];
        b = y[order[0]];
        REP(i, N - 1){
            ans += sqrt((a - x[order[i]]) * (a - x[order[i]]) + (b - y[order[i]]) * (b - y[order[i]]));
            a = x[order[i]];
            b = y[order[i]];
        }
    }while(next_permutation(order.begin(), order.end()));

    cout << std::fixed << std::setprecision(15) << ans / (double)Nfac << endl;

    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    if(x < K-x)
      sum += 2 * x;
    else
      sum += 2 * (K - x);
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
const int maxx=100010;

vector<int> A[maxx];
int pre[maxx],parent[maxx],low[maxx];
bool flag[maxx];
int v,e,now=1;

void dfs(int u){
	flag[u]=true;
	low[u]=now;
	pre[u]=now;
	now++;
	for(int i=0;i<A[u].size();i++){
		if(flag[A[u][i]]==false) {
			parent[A[u][i]]=u;
			dfs(A[u][i]);
			low[u]=min(low[u],low[A[u][i]]);
		}
		else if(parent[u]!=A[u][i]){
			low[u]=min(low[u],pre[A[u][i]]);
		}
		
	}
	return ;
}


int main (){
	int x,y;
	parent[0]=0;
	for(int i=0;i<maxx;i++){
		flag[i]=false;
	}
	cin>>v>>e;
	while(e--){
		cin>>x>>y;
		A[x].push_back(y);
		A[y].push_back(x);
	}
	dfs(0);
	
	//for(int i=0;i<v;i++) cout<<i<<"  "<<low[i]<<endl;
	
	set<int> ans;
	int cnt=0;
	for(int i=1;i<v;i++){
		int p=parent[i];
		if(p==0) cnt++;
		else if(pre[p]<=low[i]) ans.insert(p);
	}
	if(cnt>=2) ans.insert(0);
	for(set<int>::iterator it=ans.begin();it!=ans.end();it++) cout<<*it<<endl;
	return 0;
	
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N){cin >> a.at(i);}

    set<int> ans;
    // 大きい数のほうが制約が多いので，大きい方から
    rrep(i, N, 1){
        int tmp = 2;
        bool flag = true; // あまりゼロ
        while (true){
            int num = i * tmp;
            if (num > N){break;}
            if (ans.find(num) != ans.end()){flag = !flag;}
            tmp += 1;
        }
        if ((flag && a.at(i - 1) == 1) || (!flag && a.at(i - 1) == 0)){ans.insert(i);}
    }
    int M = ans.size();
    cout << M << endl;
    if (M != 0){
        for (auto v: ans){cout << v << " ";}
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main() {
    int x, init = 1, before, next;
    cin >> x;
    
    while (true) {
        before = pow(init, 2);
        next = pow(++init, 2);
        if (next > x) {
            cout << before << "\n";
            break;
        }
    }
    
    return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> c(H + 2, vector<char>(W + 2));
    rep(i, H + 2) rep(j, W + 2) {
        if (i == 0 || i == H + 1) c[i][j] == '.';
        else if (j == 0 || W == j + 1) c[i][j] == '.';
        else cin >> c[i][j];
    }
    rep(i, H + 2) rep(j, W + 2) {
        if (c[i][j] == '#') {
            if (c[i - 1][j] == '.' && c[i + 1][j] == '.' && c[i][j - 1] == '.' && c[i][j + 1] == '.') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    x, a, b = li_input()

    print("A") if abs(a - x) < abs(b - x) else print("B")


main()


Measured memory_bytes: 4628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int c = 1;
		while (x != 0) {
			System.out.println("Case " + c + ": " + x);
			c++;
			x = sc.nextInt();
		}

	}
}



Measured memory_bytes: 42504
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,M,C;
int B[20];
signed main(){
	cin>>N>>M>>C;
	rep(i,M)cin>>B[i];
	int ans=0;
	while(N--){
		int sum=0;
		rep(i,M){
			int a;cin>>a;
			sum+=a*B[i];
		}
		if(sum+C>0)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3636
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8').strip()
    red = S.count('R')
    if red>N-red:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define abs(x) ((x)>0?(x):-(x))
#define min(a,b) (a<b?a:b)
#define ll long long
//#define file
using namespace std;

int d[250001][2],f[501][501],a[501][501],n,i,j,k,l,h,t,ans,x,y;
const int fx[2][4]={{-1,0,1,0},{0,1,0,-1}};

int main()
{
	#ifdef file
	freopen("b.in","r",stdin);
	#endif
	
	scanf("%d",&n);
	fo(i,1,n) fo(j,1,n) f[i][j]=min(min(i,n-i+1),min(j,n-j+1)),a[i][j]=1;
	
	fo(i,1,n*n)
	{
		scanf("%d",&k),j=(k-1)/n+1,k=(k-1)%n+1;
		
		--f[j][k];ans+=f[j][k];a[j][k]=0;
		h=0;t=1;
		d[1][0]=j;d[1][1]=k;
		while (h<t)
		{
			++h;
			fo(l,0,3)
			{
				x=d[h][0]+fx[0][l];y=d[h][1]+fx[1][l];
				if (x>=1 && x<=n && y>=1 && y<=n && f[x][y]>f[d[h][0]][d[h][1]]+a[x][y])
				{
					f[x][y]=f[d[h][0]][d[h][1]]+a[x][y];
					++t;d[t][0]=x;d[t][1]=y;
				}
			}
		}
	}
	printf("%d\n",ans);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

Measured memory_bytes: 7508
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   :
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define rep(i,a) lp(i,0,a-1)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 7, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
string s;
int interval[N], n, k, ans;
inline bool can(int len) {
	for (int i = 1; i + len - 1 <= n; ++i) {
		if (s[i] == s[i - 1])
			continue;
		int q = interval[i + len - 1] - interval[i - 1];
		if (q <= k)
			return true;
	}
	return false;
}
int main() {
	FAST
	cin >> n >> k >> s;
	if (k>=n) f(n);
	s = "&" + s;
	lp(i,1,n)
	{
		interval[i] = interval[i - 1];
		if (s[i] != s[i - 1] && s[i] == '0')
		interval[i]++;
	}
	int l = 1,
	r = n;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (can(mid)) {
			ans = mid;
			l = mid + 1;
		} else
			r = mid - 1;
	}
	f(ans);
	return 0;
}

Measured memory_bytes: 896
def puts_ans(x, y)
  @ans << (@r ? "#{@n-x} #{@n-y}" : "#{x+1} #{y+1}")
end



@n = gets.to_i
a = gets.split.map(&:to_i)
@ans = []

sorted = a.sort
p = (sorted.first.abs > sorted.last.abs ? sorted.first : sorted.last)
idx = a.index(p)

@r = false
if p < 0
  a = a.reverse
  idx = @n-1-idx
  @r = true
end

(@n-1).times do |i|
  if (a[i] > a[i+1] && p > 0) || (a[i] < a[i+1] && p < 0)
    a[i+1] += p
    puts_ans(idx, i+1)
    if (a[i] > a[i+1] && p > 0) || (a[i] < a[i+1] && p < 0)
      a[i+1] += p
      puts_ans(idx, i+1)
    end
    if a[i+1].abs > p.abs
      p = a[i+1]
      idx = i+1
    end
  end
end

puts @ans.length, @ans




Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define lowbit(x) ((-(x)) & (x))
using namespace std;

const int MOD = 1e9 + 7;

void U(int &x) {
	if(x > MOD) x -= MOD;
}

int n, m, k, a, b, c, mt[30][30], f[1 << 20], ans;

int main() {
	scanf("%d%d%d", &n, &m, &k);
	memset(mt, 0xff, sizeof(mt));
	for(int i = 1; i <= k; i++) {
		scanf("%d%d%d", &a, &b, &c);
		mt[a][--b] = c;
	}
	f[0] = 1;
	n--;
	for(int i = 1; i <= m; i++) {
		for(int j = 0; j < n; j++) 
			for(int k = 0; k < (1 << n); k++) 
				if(!(k & (1 << j))) 
					U(f[k + (1 << j) - (lowbit(k >> j) << j)] += f[k]);
					
		for(int k = 0; k < (1 << n); k++) 
			for(int j = 0; j < n; j++) 
				if(mt[i][j] != -1 && mt[i][j] != ((k >> j) & 1))
					f[k] = 0;
	}
	for(int i = 0; i < (1 << n); i++) 
		U(ans += f[i]);
	printf("%d\n", ans);
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String str[] = br.readLine().split(" ");

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			int temp = 0;

			while (a[i] % 2 == 0) {
				temp++;
				a[i] /= 2;
			}
			count += temp;
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 25556
import sys
input = sys.stdin.readline

INF = 100100

def dijkstra(M: list, u: int = 0) -> list:
    global N
    d = [INF] * N
    d[u] = 0
    visited = [False] * N
    while True:
        mincost = INF
        for i in range(N):
            if not visited[i] and d[i] < mincost:
                mincost = d[i]
                u = i
        if mincost == INF:
            return d
        visited[u] = True
        for v in range(N):
            if not visited[v]:
                if d[u] + M[u][v] < d[v] :
                    d[v] = d[u] + M[u][v]


def main():
    global N
    N = int(input())
    M = [[INF]*N for _ in range(N)]
    for _ in range(N):
        A = list(map(int, input().split()))
        u = A[0]
        k = A[1]
        for i in range(k):
            v = A[2+2*i]
            c = A[3+2*i]
            M[u][v] = c
    d = dijkstra(M)
    for i, di in enumerate(d):
        print(i, di)

if __name__ == '__main__': main()


Measured memory_bytes: 5808
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ve vector
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())
//using namespace __gnu_pbds;
using namespace std;

// // // functions: find_by_order  & order_of_key
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

const int inf=(int)2e9;
const long long mod=1000000007; //1E9+7
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

ll powmod(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1) ans*=a;
		p/=2;a*=a; ans%=mod;a%=mod;
	}
	return ans;
}
ll mdinv(ll a){return powmod(a,mod-2); }

struct dat{
	int w,s,v;
	dat(int ww,int ss,int vv){
		w=ww;s=ss;v=vv;	
	}
};

bool cmp(dat& a,dat& b){
	return a.w+a.s < b.w+b.s;
}

signed main(){
	IOS
	int n;cin>>n;
	ve<dat> v;
	forn(i,n){
		int w,s,x;cin>>w>>s>>x;
		v.pb(dat(w,s,x));
	}
	sort(all(v),cmp);
	int mm=2e4+2;
	vi DP(20004,0),DP_new(20004,0);
	for(int i=0;i<n;i++){
		for(int lim=0;lim<=mm;lim++){
			DP_new[lim]=DP[lim];
			int nwt=min(lim-v[i].w,v[i].s);
			if(nwt>=0)
				DP_new[lim]=max(DP_new[lim],v[i].v+DP[nwt]);
		}
		swap(DP_new,DP);
	}
	cout<<*max_element(all(DP));
}


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

int main()
{
  int64_t N, ans;
  cin >> N;
  for (int h = 1; h <= 3500; h++)
  {
    for (int n = 1; n <= 3500; n++)
    {
      if ((4 * h * n) - (N * n) - (N * h) != 0 && (N * h * n) % ((4 * h * n) - (N * n) - (N * h)) == 0)
      {
        if ((N * h * n) / ((4 * h * n) - (N * n) - (N * h)) > 0)
        {
          int64_t w = (N * h * n) / ((4 * h * n) - (N * n) - (N * h));
          cout << h << ' ' << n << ' ' << w << endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>

using namespace std;

int main()
{
    int h, w;
    char s;
    while (true)
    {
        cin >> h >> w;
        if (h + w == 0)
        {
            break;
        }

        for (int i = 0; i < h; i++)
        {
            if (i % 2 == 0)
            {
                s = '#';
            }
            else
            {
                s = '.';
            }

            for (int j = 0; j < w; j++)
            {
                cout << s;
                if (s == '#')
                {
                    s = '.';
                }
                else
                {
                    s = '#';
                }
            }
            cout << endl;
        }

        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3112
N, Y = [int(elem) for elem in input().split(' ')]

if Y > 10000 * N:
    print(-1, -1, -1)
    exit(0)

for num_yukichi in range(N+1):
    for num_ichiyou in range(N - num_yukichi + 1):
        num_souseki = N - num_yukichi - num_ichiyou
        sum = 10000 * num_yukichi + 5000 * num_ichiyou + 1000 * num_souseki
        if sum == Y:
            print(num_yukichi, num_ichiyou, num_souseki)
            exit(0)
else:
    print(-1, -1, -1)


Measured memory_bytes: 40796
words = lambda t : list(map(t, input().split()))

a = int(input())
b = int(input())

if a == 1 :
    if b == 2:
        print(3)
    else:
        print(2)
elif a == 2:
    if b == 1:
        print(3)
    else:
        print(1)
else :
    if b == 1:
        print(2)
    else:
        print(1)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
ll l[211];

int main()
{
	cin >> n;
	n *= 2;

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

	sort(l, l + n);

	ll ans = 0;

	for (int i = n - 1; i > 0; i-=2) {
		ans += std::min(l[i], l[i - 1]);
	}


	cout << ans << endl;

	return 0;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 300005

int tree[4*N];
vector<int>G[N];


void update(int node,int b,int e,int idx,int val){
   if(idx<b||idx>e) return ;
   if(b==e){
     tree[node]+=val;
      return ;
   }
   int mid=(b+e)/2;
   update(2*node,b,mid,idx,val);
   update(2*node+1,mid+1,e,idx,val);
   tree[node]=max(tree[2*node],tree[2*node+1]);
}


int main ()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int h,w,m;cin>>h>>w>>m;
   for(int i=1;i<=m;i++){
      int x,y;cin>>x>>y;
      G[x].pb(y);
      update(1,1,w,y,1);
   }
   int ans=0;
   for(int i=1;i<=h;i++){
      if(G[i].size()){
         int cnt=G[i].size();
         for(int v:G[i]) update(1,1,w,v,-1);
         cnt+=tree[1];
         ans=max(cnt,ans);
         for(int v:G[i]) update(1,1,w,v,1);
      }
   }
   cout<<ans<<endl;
   return 0;
}



Measured memory_bytes: 24092
#include <stdio.h>
#include <string.h>
#include <math.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int N, i, j;
	float sum=0;
	int x[8], y[8];
	
	scanf("%d", &N);
	lop(i, N){
		scanf("%d %d", &x[i], &y[i]);
	}
	
	for(i=0; i<N; i++){
		for(j=i+1; j<N; j++){
			sum+=sqrt(pow(x[i]-x[j],2.0)+pow(y[i]-y[j],2.0));
		}
	}
	
	printf("%f", sum/N*2);
	
return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

bool used[310][310];
bool dp[310][310];
vi w;

int dp2[310][310];
template<typename T> T chmax(T& a, const T& b){return a = max(a, b);}
template<typename T> T chmin(T& a, const T& b){return a = min(a, b);}
//[l, r) de tatakeruka
bool calc(int l, int r) {
	if(r - l <= 1) return false;
	if(used[l][r]) return dp[l][r];
	used[l][r] = true;
	if(r - l == 2) {
		return dp[l][r] = (abs(w[l] - w[r-1]) <= 1);
	}
	for(int m = l + 1; m < r; m++) {
		bool f = true;
		f &= calc(l, m);
		f &= calc(m, r);
		dp[l][r] |= f;
	}
	if(abs(w[l]-w[r-1]) <= 1) dp[l][r] |= calc(l+1, r-1);
	return dp[l][r];
}

int calc2(int l, int r) {
	if(dp2[l][r] != -1) return dp2[l][r];
	if(r - l <= 1) return dp2[l][r] = 0;
	if(dp[l][r]) return dp2[l][r] = r - l;
	int ret = 0;
	for(int m = l + 1; m < r; m++) {
		chmax(ret, calc2(l, m)+calc2(m, r));
	}
	return dp2[l][r] = ret;
}

int main(){
	int n;
	while(cin >> n && n) {
		w.clear();
		w.resize(n);
		rep(i, n) cin >> w[i];
		rep(i, 310) rep(j, 310) dp[i][j] = used[i][j] = false, dp2[i][j] = -1;
		REP(r, 1, n+1) rep(l, r) calc(l, r);
		cout << calc2(0, n) << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long A,B,C,D;
	scanf("%lli %lli %lli %lli",&A,&B,&C,&D);
	if(A>=1 && B>=1 && C>=1 && D>=1 && A<=pow(10,4) && B<=pow(10,4) && C<=pow(10,4) && D<=pow(10,4))
	{
		if(A*B > C*D)
			printf("%lli",A*B);
		else
			printf("%lli",C*D);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

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


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

void chmax(int &a,int b) { a=max(a,b); }
void chmin(int &a,int b) { a=min(a,b); }

//-----------------------------------------------------------------------------

int h,w;

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

	cin>>h>>w;
	REP(i,h) {
		string s;cin>>s;
		cout<<s<<endl<<s<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
test_list = list()
i = 0
while i < 10000:
    a = input("")
    if(int(a) != 0):
        test_list.append(int(a))
    else:
        break
    i += 1

for i,l in enumerate(test_list):
    print("Case {}: {}".format(i + 1,l))



Measured memory_bytes: 5912
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<pll> p(n);
    rep(i,n){
        cin >> p[i].first;
        p[i].second = i;
    }
    sort(p.begin(),p.end(),greater<pll>());
    ll ans = 0;
    set<ll> st;
    st.insert(-1);
    st.insert(n);
    st.insert(p[0].second);
    for(int i=1;i<n;i++){
        
        auto it1 = st.lower_bound(p[i].second);
        auto it2 = it1;
        --it2;
        
        if(it2 != st.begin()){
            auto it3 = it2;
            --it3;
            ans += p[i].first * ((*it1) - (p[i].second)) * ((*it2) - (*it3)); 
        }
        ++it1;
        if(it1 != st.end()){
            auto it4 = it1;
            --it4;
            ans += p[i].first * ((*it1) - (*it4)) * ((p[i].second) - (*it2));
        }
        
        st.insert(p[i].second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

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


    int num=0;
    
    for(int i=0;i<N;++i){
        int temp=0;
        cin >> temp;

        if(i%2 ==0){
            if(temp %2 ==1){
                num++;
            }
        }
    }

    cout<<num<<endl;

}



Measured memory_bytes: 3620
#include"iostream"
#include"algorithm"

using namespace std;
typedef long long int llint;
double A, B;

int main() {
	cin >> A >> B;
	double a = A / 0.08;//答えは必ずこれ以上の値
	double b = B / 0.10;//答えは必ずこれ以上の値

	int ans = -1;
	for (int i = 0; i <= 1000; i++) {
		int xa = i * 0.08;
		int xb = i * 0.10;
		//cout << xa << " " << xb << endl;
		if (xa == (int)A && xb == (int)B) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
template<class _T>
inline void _prfe(const char *_n, _T _c, bool _p = false){
    ITER(_c) _it=_c.begin();
    if(_p){ cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{ cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

int main(){
    int n, m;
    while(cin >> n){
        if(n == 0) break;

        int t[11][11];
        FILL(t,0);
        REP(y,n) REP(x,n){
            cin >> m;
            t[y][x] = m; t[y][n] += m; t[n][x] += m; t[n][n] += m;
        }
        REP(y,n+1){
            REP(x,n+1){
                printf("%5d", t[y][x]);
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1164
import heapq


n, m = map(int, input().split())
costs = list(map(lambda c: -int(c), input().split()))
heapq.heapify(costs)

for i in range(m):
    v = heapq.heappop(costs)
    v = v / 2
    # print(v)
    heapq.heappush(costs, v)


print(sum(map(lambda c: int(-c), costs)))


Measured memory_bytes: 14252
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>
#include <limits>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  string S;
  cin >> S;
  int ans = numeric_limits<int>::max();
  rep(i, S.size() - 2) {
    char part[3] = {S[i], S[i + 1], S[i + 2]};
    int partInt = atoi(part);
    ans = min(ans, abs(753 - partInt));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
use std::collections::{BTreeMap, BTreeSet};

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let mut a: Vec<usize> = sc.vec(n);
    a.sort();

    let mut a_count = BTreeMap::new();
    for &a in a.iter() {
        a_count.entry(a).and_modify(|c| *c += 1).or_insert(1);
    }

    let mut removed = BTreeSet::new();
    let mut ans = 0;
    for &a in a.iter() {
        if !removed.contains(&a) && a_count[&a] == 1 {
            ans += 1;
        }
        if removed.contains(&a) {
            continue;
        }
        let mut cur = a;
        while cur <= 1_000_000 {
            removed.insert(cur);
            cur += a;
        }
    }

    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 29484
#include <bits/stdc++.h>
#define N 60
#define MOD 1000000007
using namespace std;
long long ans;
string s1,s2;
int main(){
	int i,j,n;
	cin>>n;
	cin>>s1>>s2;
	if(s1[0]==s2[0])
	{
		ans=3;
	}
	else
	{
		ans=6;
	}
	for(i=1;i<n;i++)
	{
		if(s1[i]==s1[i-1])
		{
			continue;
		}
		if(s1[i]!=s2[i])
		{
			if(s1[i-1]!=s2[i-1])
			{
				ans=(ans*3)%MOD;
			}
			else
			{
				ans=(ans*2)%MOD;
			}
		}
		else
		{
			if(s1[i-1]==s2[i-1])
			{
				ans=(ans*2)%MOD;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
s=input()
if int(s[:4])<2019:
    print("Heisei")
else:
    if s[5:7]=="10" or s[5:7]=="11" or s[5:7]=="12":
        print("TBD")
    elif int(s[6])<5:
        print("Heisei")
    else:
        print("TBD")

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int a = Integer.parseInt(strArr[0]);
		int b = Integer.parseInt(strArr[1]);
		int ans = 0;
		if (a > (2 * b)) {
			ans = a - (2 * b);
		}
		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
typedef  long long ll;
using namespace std;
const int maxn = 3e5 + 100;
ll a[maxn];
int main() {
	ios::sync_with_stdio(0);
	ll n, m,sum=0;
	cin >> n >> m;
	for (int i = 1, x; i <= n; i++)
		cin >> a[i], sum += a[i];
	sort(a + 1, a + 1 + n,greater<ll>());
	for (int i = 1; i <= min(n,m); i++)
		sum -= a[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include <chrono>
#include <random>
#include <ctime>
#include <algorithm>
#include <iosfwd>
#include <iostream>
#include <list>
#include <ostream>
#include <streambuf>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fori(i, n) for(ll i = 0; i < (n); ++i)
#define forI(i, n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define ff first
#define ss second

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#define pt pair<ll, ll>
#define x first
#define y second

pll operator+ (pll a, pll b){ return {a.x + b.x, a.y + b.y}; }

ll rand0m() {
    return (ull(rand()) << 15ull | ull(rand()));
}                   //[0 ... n)
ll rand0m(ll x) {
    return rand0m() % x;
}               //[0 ... n)
ll rand0m(ll minn, ll maxx) {
    return rand0m(maxx - minn + 1) + minn;
}   //[minn ... maxx]

const ll MAXN = 1e6 + 1;
const ll mod = 1e9 + 7;
const ll INF = 2e9 + 1000;

ll n, m;
ld pr[3000];
ld dp[3000][3000];

void solve(){
    cin >> n;
    forI(i, n) cin >> pr[i];
    dp[0][0] = 1;
    forI(i, n){
        fori(j, i + 1){
            dp[i][j] = dp[i - 1][j] * (1 - pr[i]);
            if(j) dp[i][j] += dp[i - 1][j - 1] * pr[i];
        }
    }
    ld c = 0;
    for(ll i = n / 2 + 1; i <= n; ++i) c += dp[n][i];
    cout.precision(10);
    cout << fixed << c;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //stress();
    solve();
}

Measured memory_bytes: 139136
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	int n, m,tmp=0,ax=0,k,s;
	string str, str2[5000];
	cin >> k >> s;
	
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (s - i - j >= 0 && s - i - j <= k) { tmp++; }
		}
	}
	cout <<tmp;
}

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

int main() {
    
    int n;
    vector<string> S;
    string ans = "";
    
    cin >> n;
    
    for ( int i = 0; i < n; i++ ) {
        string s;
        cin >> s;
        
        S.push_back( s );
    }
    
    for ( char c = 'a'; c <= 'z'; c++ ) {
        
        int n_min = INT_MAX;
        int count = 0;
        
        for ( int i = 0; i < n; i++ ) {
            count = 0;
            for ( int j = 0; j < S[i].length(); j++ ) {
                if ( c == *( S[i].substr( j , 1 ).c_str() ) ) { count++; }
            }
            n_min = min( n_min, count );
        }
        
        for ( int k = 0; k < n_min; k++ ) {
            ans += c;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256