akhauriyash/Code-Regression huggingface dataset:
def binarev(x):
    ans = []
    while x:
        ans.append(x%2)
        x = x//2
    return ans

def power(a, b, *c):
    if c:
        c = c[0]
        bb = binarev(b)
        n = len(bb)
        pool = [a%c] * n
        for i in range(1, n):
            pool[i] = (pool[i-1]**2)%c
        ans = 1
        for i in range(n):
            if bb[i]: ans = (pool[i]*ans)%c
        return ans
    else:
        bb = binarev(b)
        n = len(bb)
        pool = [a] * n
        for i in range(1, n):
            pool[i] = pool[i-1]**2
        ans = 1
        for i in range(n):
            if bb[i]: ans *= pool[i]
        return ans

def root(x, n):
    a = x
    left = 0
    right = x
    while left+1 < right:
        x = (left + right)//2
        if power(x, n) <= a:
            left = x
        else:
            right = x
    return left

def log(x, n):
    a = x
    left = 0
    right = x
    while left+1 < right:
        x = (left + right)//2
        if power(n, x) <= a:
            left = x
        else:
            right = x
    return left

def permod(MOD, N, R=-1):
    from functools import reduce
    if R==-1: R=N
    return reduce(lambda x,y: x*y%MOD, range(N, N-R, -1))


def combod(MOD, N, R):
    return permod(MOD, N, R) * power(permod(MOD, R), MOD-2, MOD) % MOD


n,a,b = map(int, input().split())
p = 7 + 10**9
print((power(2,n,p) - combod(p,n,a) - combod(p,n,b) - 1) % p)

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

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

    if (x == 1){
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
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; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

struct UnionFind {
  vector<int> par;
   
  UnionFind(int n) : par(n, -1) { }
  void init(int n) { par.assign(n, -1); }
   
  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
    
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
    
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y); // merge technique
    par[x] += par[y];
    par[y] = x;
    return true;
  }
    
  int size(int x) {
    return -par[root(x)];
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,q; cin >> n >> q;
  UnionFind uf(n);
  while(q--){
    int t,u,v;
    cin >> t >> u >> v;
    if(t==0) uf.merge(u,v);
    else cout << (uf.issame(u,v) ? 1 : 0) << '\n';
  }

  return 0;
}


Measured memory_bytes: 3960
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a>b)
        swap(a,b);
    if(b>c)
        swap(b,c);
    if(a>b)
        swap(a,b);

    cout << c-a << endl;

    return 0;
}


Measured memory_bytes: 256
while 1:
	n,k = map(int,raw_input().split())
	s = [0]*(n+1)
	ss = [0]*(n+1)
	if n == 0: break
	c = sorted([int(raw_input()) for i in range(k)])
	if c[0] == 0:
		for i in c[1:]:
			s[i] = s[i-1]+1
			ss[i] = ss[i-1]+1
			if s[i-1] == 0 and s[i-2] > 0:
				ss[i] = s[i] + s[i-2] + 1
		print max(ss)
	else:
		for i in c:
			s[i] = s[i-1] + 1
		print max(s)

Measured memory_bytes: 11064
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

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

	double a;
	double sum = 0.0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		sum += 1 / a;
	}
	cout << 1 / sum;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int l, r, d, cnt=0;
  cin >> l >> r >> d;
  for(int i=l; i<=r; i++){
    if(i%d==0) cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

void BubbleSort(int *, int);
int count=0;

int main()
{
    int i, N;
    int A[100];
    
    scanf("%d", &N);
    for(i=0; i < N; i++){
        scanf("%d", &A[i]);
    }
    for(i=0; i < N; i++){
        BubbleSort(A, N);
    }
    
    for(i=0; i < N; i++){
        if(i != 0)printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", count);
    return 0;
}

void BubbleSort(int A[], int N)
{
    int i, flag=1, str;
    while(flag){
        flag = 0;
        for(i=N-1; i > 0; i--){
            if(A[i] < A[i-1]){
                str = A[i-1];
                A[i-1] = A[i];
                A[i] = str;
                count++;
            }
        }
    }
}


Measured memory_bytes: 2100
N = int(input())

for h in range(1, 3501):
    for n in range(h, 3501):
        x = 4*h*n-N*n-N*h
        if x <= 0:
            continue
        else:
            if (N*h*n)%x == 0:
                print(h, n, (N*h*n)//x)
                exit()


Measured memory_bytes: 40412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
//#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll p,a[3005];
vector<ll>ans;
vector<vector<ll>>pl;
ll modpow(ll x,ll n,ll mod){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll mod;
ll dp[3005][3005];
ll x[6005];
int main(){
    
	cin >> p ; mod = p;rep(i,6005) x[i] = modpow(i-3000,p-2,p);
	rep(i,p) cin >> a[i];
	ans.resize(p,0);
	dp[0][0] = 1;
	rep(i,p){
		rep(j,p){
			if(dp[i][j] == 0) continue;
			dp[i+1][j] += dp[i][j];
			dp[i+1][j+1] += dp[i][j]*(-i)%mod;
		}
		rep(j,p+1) dp[i+1][j]%=mod;
	}
	
	rep(i,p){
		pl.clear(); ll coef = a[i]; 
		ll t[3005];
		rep(i,3005) t[i] = dp[p][i];
		repn(ii,p) {t[ii] -= t[ii-1]*(-i)%mod;t[ii]%=mod;}
			rep(j,p){
				if(i == j) continue;
				coef =  coef*x[i-j+3000]%p;
			}
		vector<ll>ret;
		rep(i,p) ret.pb(t[p-1-i]);
		rep(i,ret.size()) ret[i] = (ret[i]*coef%mod+mod)%mod;
		rep(i,p) ans[i] += ret[i];
	}
	rep(i,p) ans[i] = (ans[i]%mod+mod)%mod;
	rep(i,p) cout << ans[i] << endl;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<(n); i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
signed main(void){
    int h,w;cin>>h>>w;
    int wf[10][10];rep(i,10)rep(j,10)cin>>wf[i][j];
    rep(k,10)rep(i,10)rep(j,10){
        wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j]);
    }
    int ans=0;
    int x;
    rep(i,h*w){
        cin>>x;if(x==-1)continue;
        ans+=wf[x][1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
int px[90005],py[90005];
int d[90005];
int main(){
    int h,w,D;cin >> h >> w >> D;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int a;cin >> a;
            px[a]=i;
            py[a]=j;
        }
    }
    for(int i=D+1;i<=h*w;i++){
        d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
    }
    int q;cin >> q;
    for(int i=0;i<q;i++){
        int l,r;cin >> l >> r;
        cout << d[r]-d[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
import java.util.*;
import java.util.ArrayList;
public class Main {
    public static void main (String[] args) {
        Scanner kc = new Scanner(System.in);
    man(kc);
    }
    public static void man(Scanner sc){
    int n = sc.nextInt();
        boolean[][] field = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            int peep = sc.nextInt() - 1;
            int count = sc.nextInt();
            for (int j = 0; j < count; ++j) {
                field[peep][sc.nextInt() - 1] = true;
            }
        }
        StringBuilder ka = new StringBuilder();
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; j++) {
                if (j > 0) {
                    ka.append(" ");
                }
                if (field[i][j]) {
                    ka.append("1");
                } else {
                    ka.append("0");
                }
            }
            ka.append("\n");
        }
        System.out.print(ka);
}
}


Measured memory_bytes: 29540
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int N, tmp, midlow, midhigh;
    int X[200001] = {};
    vector<int> v;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> tmp;
        X[i] = tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    midlow = v[(N/2)-1];
    midhigh = v[N/2];
    
    for(int i = 0; i < N; i++){
        if(X[i] <= midlow) cout << midhigh << endl;
        else cout << midlow << endl;
    }

}

Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    string str1,str2;
    cin>>str1;
    str2="CODEFESTIVAL2016";
    int ans=0;
    for(int i=0;i<16;i++){
        if(str1[i]!=str2[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    int ans = -1;
    rep(i, 1001)
    {
        if (int(i * 0.08) == a && int(i * 0.10) == b)
        {
            ans = i;
            break;
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

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

	while(1){
		C -= B;
		if (C <= 0){
			cout << "Yes" << endl;
			break;
		}
		A -= D;
		if (A <= 0){
			cout << "No" << endl;
			break;
		}
	}


	return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int l,n,x,res,sum;
int main(){
   cin>>n>>x;
   for(int i=1;i<=n;i++){
    cin>>l;
    sum+=l;
    if(sum<=x) res++; 
}
   res++;
   cout<<res;
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
 
#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tolower(c) char(c+0x20)
#define toupper(c) char(c-0x20)

const ll MAX_N = 100000;
 
int main(void){
    ll a,b,c,d;
    string s,t,u;
 
    cin >> a >> b;//>> c >> d;
    //cin >> s >> t >> u;
    cout << (a + b) % 24;
    
    return 0;
}

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

int main(){
    int r;
    cin >> r;
    if (r<1200){
        cout << "ABC" << endl;
    }
    else if (r>=2800){
        cout << "AGC" << endl;
    }
    else {
        cout << "ARC" << endl;
    }

}


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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const int MAXN = 1e5+1;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	vector<int> cnt(MAXN);
	for(int i = 0; i < n; i++){
		cnt[a[i]]++;
	}

	int res = cnt[0]+cnt[1];
	int m = *max_element(all(a));
	for(int i = 1; i <= m; i++){
		int x = cnt[i-1]+cnt[i]+cnt[i+1];
		if(x > res){
			res = x;
		}
	}

	cout << res << endl;

	return 0;
}

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	int k = n%10;
	if(k == 2 ||k == 4 ||k == 5 ||k == 7 ||k == 9) cout << "hon" << endl;
	else if(k == 0 ||k == 1 ||k == 6 ||k == 8) cout << "pon" << endl;
	else cout << "bon" << endl;
	
} 

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	lli N, P;
	cin >> N >> P;
	if (N == 1) {
		cout << P << endl;
		return 0;
	}
	
	int ans = 1;
	for (lli i = 1; pow(i,N) <= P; i++) {
		if (P % (lli)pow(i, N) == 0) {
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b, c;
	while (cin >> a,a != 0)
	{	
		int d[10000] = {}, sum[10000] = {};
		for (int i = 0; i < a; i++)
		{
			cin >> d[i] >> b >> c;
			sum[i] = b + c;
			for (int j = 0; j < 2; j++)
			{
				if (sum[0] < sum[i])
				{
					swap(sum[i], sum[0]);
					swap(d[i], d[0]);
				}
			}

		}
		cout << d[0] << " " << sum[0] << endl;
	}
}

Measured memory_bytes: 1244
#include<stdio.h>
int main(void)
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    while(a>0&&c>0)
    {
        c = c - b;
        if(c<0)
        break;
        a = a - d;
    }
    if(c<=0)
    printf("Yes");
    else
    {
        printf("No");
    }
    
}

Measured memory_bytes: 1688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,s;
  string str;
  cin>>n>>str;
  s=str.size();
  for(int i=0; i<s; i++){
    str.at(i)=str.at(i)+n;
    str.at(i)=str.at(i)-'A';
    str.at(i)=str.at(i)%26;
    str.at(i)=str.at(i)+'A';
  }
  cout<<str;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};

int large = 1000000000000000000;


int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    while(t--) {
        int n;
        cin>>n;
        int x = 0;
        int ans = 1;
        int a[n];
        fori(i,n) {
            cin>>a[i];
        }
        sort(a,a+n);
        fori(i,n) {
            x = a[i];
            if(ans != -1 && ans > 0 && x > large/ ans) {
                ans = -1;
            }
            if(ans != -1){
                ans *= x; 
            }
        }
        if(ans > large) ans = -1;
        cout<<ans;

    }
    
    return 0;
}

Measured memory_bytes: 4480
fun main(args: Array<String>) {
    abc059c()
}

fun abc059c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toLong() }.toTypedArray()

    // 偶数index目までの和の符号を正、奇数までを負とするパターン
    var changeCountEvenPositiveCase: Long = 0
    var sumEvenPositiveCase: Long = 0
    val aListEvenPositiveCase = aList.clone()
    for (i in 0 until n) {
        val it = aListEvenPositiveCase[i]
        sumEvenPositiveCase += it
        if (i % 2 == 0) {
            // 偶数index目なのでここまでの和の符号が正でない場合は、1まで加算
            if (sumEvenPositiveCase <= 0) {
                val addValue = Math.abs(sumEvenPositiveCase) + 1
                aListEvenPositiveCase[i] += addValue
                sumEvenPositiveCase += addValue
                changeCountEvenPositiveCase += addValue
            }
        } else {
            // 奇数index目なのでここまでの和の符号が負でない場合は、-1まで減算
            if (sumEvenPositiveCase >= 0) {
                val minusValue = Math.abs(sumEvenPositiveCase) + 1
                aListEvenPositiveCase[i] -= minusValue
                sumEvenPositiveCase -= minusValue
                changeCountEvenPositiveCase += minusValue
            }
        }
    }

    // 偶数index目までの和の符号を負、奇数までを正とするケース
    var changeCountOddPositiveCase: Long = 0
    var sumOddPositiveCase: Long = 0
    val aListOddPositiveCase = aList.clone()
    for (i in 0 until n) {
        val it = aListOddPositiveCase[i]
        sumOddPositiveCase += it
        if (i % 2 == 0) {
            // 偶数index目なのでここまでの和の符号が負でない場合は、-1まで減算
            if (sumOddPositiveCase >= 0) {
                val minusValue = Math.abs(sumOddPositiveCase) + 1
                aListOddPositiveCase[i] -= minusValue
                sumOddPositiveCase -= minusValue
                changeCountOddPositiveCase += minusValue
            }
        } else {
            // 奇数index目なのでここまでの和の符号が正でない場合は、1まで減算
            if (sumOddPositiveCase <= 0) {
                val addValue = Math.abs(sumOddPositiveCase) + 1
                aListOddPositiveCase[i] += addValue
                sumOddPositiveCase += addValue
                changeCountOddPositiveCase += addValue
            }
        }
    }

    println(Math.min(changeCountEvenPositiveCase, changeCountOddPositiveCase))
}


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

int main()
{
	int N,T;
	cin >> N >> T;
	int index = -1;
	int c[N], t[N];
	for(int i = 0; i < N; i++){
		cin >> c[i] >> t[i];
		if(t[i] > T){
			continue;
		}else{
			if(index == -1){
				index = i;
			}else{
				if(c[index] > c[i])
					index = i;
			}
		}
	}

	if(index == -1){
		cout << "TLE\n";
	}else{
		cout << c[index] << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
# stdin = open("sample.txt")


MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr


    
def main():
    h, w, k = [int(x) for x in stdin.readline().rstrip().split()]
    board = []
    kuro = 0
    pattern_h = [[0]*h for _ in range(2 ** h)]
    pattern_w = [[0]*w for _ in range(2 ** w)]
    ans = 0
    nokori = 0
    
    for _ in range(h):
        s = stdin.readline().rstrip()
        v = [s[i] for i in range(0, len(s))]
        kuro += v.count("#")
        board.append(v)
    memo = copy.deepcopy(board)
    
    for i in range(2 ** h):
        for j in range(h):
            if (i >> j) & 1:
                pattern_h[i][j] = j + 1
    for i in range(2 ** w):
        for j in range(w):
            if (i >> j) & 1:
                pattern_w[i][j] = j + 1
                
    for i in range(2 ** w):
        for j in range(w):
            if pattern_w[i][j] != 0:
                for l in range(h):
                    memo[l][j] = "x"
        for i2 in range(2 ** h):
            for j2 in range(h):
                if pattern_h[i2][j2] == 0:
                    nokori += memo[j2].count("#")
            if k == nokori:
                ans += 1
            nokori = 0
        memo = copy.deepcopy(board)
                        
    print(ans)
                                        
main()

Measured memory_bytes: 27288
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_QUIZ_MAX		100005									// 最大問題数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1WCnt[D_QUIZ_MAX];									// WA数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i, liWork;
	char lc1Buf[1024];

	// 結果数 - 取得
	int liRCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &liWork, &liRCnt);

	// 結果 - 取得
	int liACnt = 0;
	int liWCnt = 0;
	for (i = 0; i < liRCnt; i++) {
		int liRes;
		char lc1Res[128];
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%s", &liRes, lc1Res);

		// AC済
		if (si1WCnt[liRes] < 0) {
			continue;
		}

		// 結果
		if (!strcmp(lc1Res, "AC")) {
			liACnt++;
			liWCnt += si1WCnt[liRes];
			si1WCnt[liRes] = -1;
		}
		else {
			si1WCnt[liRes]++;
		}
	}

	// 出力
	sprintf(lc1Buf, "%d %d\n", liACnt, liWCnt);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si1WCnt, 0, sizeof(si1WCnt));						// WA数

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k,l;
  int a[3520],b[32768],p;
  int ct;
  memset(b,0,sizeof(b));
  a[0]=2;
  j=1;
  b[2]=1;
  for(i=3;i<32768;i+=2){
    l=(int)sqrt(i)+1;
    for(k=3;k<l;k+=2){
      if(i%k==0)
	break;
    }
    if(k>=l){
      a[j]=i;
      j++;
      b[i]=1;
    }
  }
  a[j]=32768;
  while(cin>>p&&p){
    ct=0;
    for(i=0;a[i]*2<=p;i++){
      if(b[p-a[i]])
	ct++;
    }
    cout<<ct<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <cmath>
#include <string.h>
#define inf 0x7fffffff
using namespace std;
struct I
{
    int x,y;
};


int a,b,c,k,n,m,i,d,e[4010][4005],o[410200],l[212000],dx[20]={1,-1},dy[20]={0,0,1,-1},dz[20]={1,-1};
long long x,y,z;
//map <string,int> m;
int j[1060][20];

stack<int> s;
char r1[5500];
//deque<int> d;
struct P
{
    int x,y;
    /*bool operator<(const P &a)const
    {

        return max(x,-x)<=max(a.x,-a.x);
    }*/
};
double u;
//P u[500000];
vector <int> v[211010];
queue<int> q;
string r;

//A==65
//Z==90

//a==97

bool sdf(P a,P b)
{
    return a.x<b.x;
}



int main()
{
    scanf("%lld",&x);
    if(x==0)
    {
        printf("2\n1 1");
        return 0;
    }
    if(x==1)
    {
        printf("2\n2 0");
        return 0;
    }

    if(x<=50)
    {
        printf("%lld\n",x);
    for(long long t=x;t>=1;t--)
        printf("%lld ",t);
    return 0;
    }
    y=50+x/50;
    z=x%50;
    printf("50\n");
    for(long long t=1;t<=50;t++)
    {
        if(t<=z)
            printf("%lld ",y+50-z);
        else printf("%lld ",y-z-1);
    }
}


Measured memory_bytes: 6400
import Data.List
main = do
  input <- getLine
  let n = length input
      p = subsequences [1..n-1]
      ans = map (sum . split 0 input) p
  print $ sum ans

split :: Int -> String -> [Int] -> [Int]
split _ [] []     = []
split _ s []     = [read s]
split n s (x:xs) = (read $ take (x-n) s) : (split x (drop (x-n) s) xs)


Measured memory_bytes: 1020
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
ans = [[] for i in range(N)]
for i in range(M):
    p,s = [(x) for x in stdin.readline().rstrip().split()]
    ans[int(p)-1].append(s)

ac = 0
pe = 0
tmp = 0
flag = False
for j in range(N):
    tmp = 0
    for k in ans[j]:
        if k == "WA":
            tmp += 1
        else:
            ac += 1
            pe += tmp
            tmp = 0
            break
print(ac,pe)

Measured memory_bytes: 20344
from sys import stdin
S = (stdin.readline().rstrip())
ans1 = [0] * (len(S)+1)

cnt = 0
for j in range(len(S)):
    if S[j] == "<":
        cnt += 1
        ans1[j+1] = cnt

    else:
        cnt = 0

ans2 = [0]*(len(S)+1)
cnt = 0
for j in range(len(S)-1, -1, -1):
    if S[j] == ">":
        cnt += 1
        ans2[j] = cnt

    else:
        cnt = 0

ans = 0
for i,j in zip(ans1,ans2):
    ans += max(i,j)
print(ans)

Measured memory_bytes: 27300
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = B[A[0]-1]
for i in range(1,N):
    ans += B[A[i]-1]
    if A[i-1] + 1 == A[i]:
        ans += C[A[i-1]-1]
print(ans)

Measured memory_bytes: 38256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>


int main(){
  
  // read problem
  long long int N;
  std::string S;
  scanf("%lld", &N);
  std::cin >> S;
  
  // solve problem
  std::vector<std::vector<long long int> > dp(N);
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < N; j++){
      dp[i].push_back(0);
    }
  }
  // initialize dp table
  for(long long int i = 0; i < N; i++){
    for(long long int j = i+1; j < N; j++){
      if(S[i] == S[j]){
        dp[i][j] = 1;
      }
    }
  }
  
  // update dp table
  for(long long int l = 0; l <= 12; l++){ // log(5e3) ~ 12
    for(long long int i = 0; i < N; i++){
      for(long long int j = 0; j < N; j++){
        // if dp[i][j] can still be updated
        if(dp[i][j] == (1<<l)){
          dp[i][j] = dp[i][j] + dp[i+(1<<l)][j+(1<<l)];
          dp[i][j] = std::min(dp[i][j], j-i);
        }
      }
    }
  }
  
  // calculate answer
  long long int ans = 0;
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < N; j++){
      ans = std::max(ans, dp[i][j]);
    }
  }
  
  std::cerr << "Answer:" << std::endl;
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 218368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };


		int N = cin.nextInt();
		int[] x = new int[N];
		for (int i = 0; i < N; i++)
		{
			x[i] = cin.nextInt();
		}
		int L = cin.nextInt();
		int Q = cin.nextInt();
		int[] a = new int[Q];
		int[] b = new int[Q];
		for (int i = 0; i < Q; i++)
		{
			a[i] = cin.nextInt() - 1;
			b[i] = cin.nextInt() - 1;
			if (a[i] > b[i])
			{
				int tmp = a[i];
				a[i] = b[i];
				b[i] = tmp;
			}
		}

		int depth = 17;
		int[,] r = new int[depth, N];
		for (int i = 0; i < N - 1; i++)
		{
			if (x[N - 1] - x[i] <= L)
			{
				for (int j = i; j < N; j++)
				{
					r[0, j] = N - 1;
				}
				break;
			}
			int ok = i + 1, ng = N - 1;
			while (ng - ok > 1)
			{
				int mid = (ok + ng) / 2;
				if (x[mid] - x[i] > L)
				{
					ng = mid;
				}
				else
				{
					ok = mid;
				}
			}
			r[0, i] = ok;
			/*
			for (int j = i + 2; j < N; j++)
			{
				if (x[j] - x[i] > L)
				{
					r[0, i] = j - 1;
					break;
				}
			}
			*/
		}
		r[0, N - 2] = N - 1;
		r[0, N - 1] = N - 1;
		for (int i = 1; i < depth; i++)
		{
			for (int j = 0; j < N; j++)
			{
				r[i, j] = r[i - 1, r[i - 1, j]];
			}
		}
		for (int i = 0; i < Q; i++)
		{
			int ok = (1 << 17) - 1, ng = 0;
			while (ok - ng > 1)
			{
				int now = a[i];
				int nowdepth = 0;
				int mid = (ok + ng) / 2;
				while (mid > 0)
				{
					if ((mid & 1) == 1)
					{
						now = r[nowdepth, now];
					}
					nowdepth++;
					mid >>= 1;
				}
				if (now >= b[i])
				{
					ok = (ok + ng) / 2;
				}
				else
				{
					ng = (ok + ng) / 2;
				}
			}
			Console.WriteLine(ok);
		}
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

signed main(){
    int A,B,C;
    cin >> A >> B >> C;
    cout << (A*B*C)/(2*max(A,max(B,C))) << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        Scanner ob=new Scanner(System.in);
        int n =ob.nextInt();
        ob.nextLine();
        HashSet<String> set = new HashSet<>();
        while(n-->0)
        set.add(ob.nextLine());
        System.out.println(set.size());

    }
}

Measured memory_bytes: 79580
list = []
for i in range(5):
  list.append(int(input()))
list = list[::-1]
k = int(input())
dist = 0
j = 0
cant_connect = False
for i in range(5):
  for j in range(i+1, 5):
    dist = list[i] - list[j]
    if dist > k:
      cant_connect = True
      break
  if cant_connect:
    break
if cant_connect:
  print(":(")
else:
  print("Yay!")
  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define inf 0x3fffffff
#define LL long long  

using namespace std;
  
inline char nc(){
    /* 
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
    */return getchar();
}
  
inline void read(int &x){
  char c=nc();int b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
  
inline void read(LL &x){
  char c=nc();LL b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
inline void read(char &x){
  for (x=nc();!(x=='('||x==')');x=nc());
}

inline int read(char *s)
{
    char c=nc();int len=1;
    for(;!(c>='a'&&c<='z');c=nc()) if (c==EOF) return 0;
    for(;(c>='a'&&c<='z');s[len++]=c,c=nc());
    s[len++]='\0';
    return len-2;
}
int wt,ss[19];
inline void print(int x){
    if (x<0) x=-x,putchar('-'); 
    if (!x) putchar(48); else {
    for (wt=0;x;ss[++wt]=x%10,x/=10);
    for (;wt;putchar(ss[wt]+48),wt--);}
}
inline void print(LL x){
    if (x<0) x=-x,putchar('-');
    if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}

int T,n;
char s[200010];
map<string,bool> m; 

int main()
{
    n=read(s);
    int ans=0;
    string x="",y="";
    m.clear();m[y]=true;
    for (int i=1;i<=n;i++)
    {
        x+=s[i];
        if (m.find(x)==m.end())
        {
            m[x]=true;
            ans++;
            m.erase(y);
            y=x;
            x="";
        }
        //cout<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String T = sc.nextLine();
		if (T.substring(0, T.length()-1).equals(S)) {
		    System.out.println("Yes");
		} else {
		    System.out.println("No");
		}
    }
}


Measured memory_bytes: 35780
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ar := make([]int, 0, m)
	for i := 0; i < m; i++ {
		var a int
		fmt.Scan(&a)
		ar = append(ar, a)
	}
	sort.Ints(ar)
	br := make([]int, 0, m-1)
	for i := 1; i < m; i++ {
		v := ar[i] - ar[i-1]
		br = append(br, v)
	}
	sort.Ints(br)
	if len(br) <= n-1 {
		fmt.Println(0)
		return
	}
	br = br[:len(br)-n+1]
	sum := 0
	for _, v := range br {
		sum += v
	}
	fmt.Println(sum)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int N; string S;
	cin>>S; N=S.size();
	int ans=0;
	for(int i=0;i<(1<<N-1);i++){
		vector<int> pul(N-1,0);
		for(int j=0;j<N-1;j++){
			if(i & (1<<j))pul[j]=1;
		}
		int tmp=0;
		for(int j=0;j<N-1;j++){
			if(pul[j]==1){
				ans+=stoi(S.substr(tmp,j-tmp+1));
				tmp=j+1;
			}
		}
		ans+=stoll(S.substr(tmp,10));
	}
	cout<<ans<<endl;

}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
		
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int sum = stdIn.nextInt();
			if(sum == 0) break;
			for(int i = 0; i < 9; i++) {
				sum -= stdIn.nextInt();
			}
			System.out.println(sum);
		
		
		}
	}
}

Measured memory_bytes: 17188
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MOD(x) ((x) % (1e9 + 7))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const double EPS = 1e-10;
const double PI = acos(-1.0);

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	ll n;
	scanf("%lld", &n);
	ll result;
	ll k = n;
	for(ll i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			result = n / i + i - 2;
		}
	}
	printf("%lld\n", result);
	return 0;
}

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

#define SIZE 100

int field[SIZE][SIZE][3];

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        memset(field, 0, sizeof(field));
        for (int y = 0; y < n; y++) {
            for (int x = 0; x < n; x++) {
                cin >> field[y][x][2] >> field[y][x][1];
            }
        }
        int result = 0, num = 0;
        for (int y = 0; y < n; y++) {
            for (int x = 0; x < n; x++) {
                if (field[y][x][0] > 0) {
                    continue;
                }
                num++;
                pair<int, int> next(y, x);
                while (true) {
                    if (field[next.first][next.second][0] == 0) {
                        field[next.first][next.second][0] = num;
                        next = make_pair(field[next.first][next.second][1], field[next.first][next.second][2]);
                        continue;
                    } else if (field[next.first][next.second][0] == num) {
                        result++;
                    }
                    break;
                }
            }
        }
        cout << result << endl;
    }
}

Measured memory_bytes: 0
n,k = map(int,input().split())

list1 = []
listeven = []

for i in range(1,n+1):
    if i%k == 0: list1.append(i)
    elif i%k == k/2: listeven.append(i)

if k%2 != 0:
    print(len(list1)**3)

else:
    print(len(list1)**3 + len(listeven)**3)

Measured memory_bytes: 52080
n,k=map(int,input().split())
*a,= map(int,input().split())
*f,= map(int,input().split())
a=sorted(a)
f=sorted(f, reverse=True)

def is_ok(arg):
    cnt=0
    for i in range(n):
        cnt+=max(a[i]-arg//f[i], 0)
    return cnt<=k

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(-1, 10**12))

Measured memory_bytes: 122364
#include<iostream>
#include<string>
using namespace std;
int dp[200][200];
int main(){
	int r,c;
	cin>>r>>c;
	for(int i=0;i<=r;i++)
		dp[i][c]=0;
	for(int i=0;i<c;i++)
		dp[r][i]=0;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>dp[i][j];
			dp[i][c]+=dp[i][j];
			dp[r][j]+=dp[i][j];
			dp[r][c]+=dp[i][j];
		}
	}
	for(int i=0;i<=r;i++){
		for(int j=0;j<c;j++)
			cout<<dp[i][j]<<" ";
		cout<<dp[i][c]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
# coding: utf-8
# Your code here!
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

l=[]
for i in range(N):
    l+=(([i+1]*A[i]))

#print(*l)

for i in range(H):
    if i%2==0:
        print(*l[0:W])
        del l[:W]
    else:
        print(*l[0:W][::-1])
        del l[:W]
    

Measured memory_bytes: 3828
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &st) {
	for (const auto &e : st) os << e << " ";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
	for (const auto &e : mp) os << e << " ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T = lint>
struct Edge {
	int to;
	T cost;
	int tank;
	Edge() {}
	Edge(int to, T cost, int tank = 0) : to(to), cost(cost), tank(tank) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

int main() {

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

	int N, M, L;
	cin >> N >> M >> L;

	vector<vector<Edge<int>>> edges(N);
	for (int i = 0; i < M; i++) {
		int u, v, len;
		cin >> u >> v >> len;
		u--, v--;
		edges[u].emplace_back(v, len);
		edges[v].emplace_back(u, len);
	}

	auto bfs = [&](int st) {
		vector<pair<int, int>> dp(N, { INF, 0 });
		dp[st] = { 0, -L };
		queue<pair<int, pair<int, int>>> que;
		que.emplace(st, dp[st]);
		while (!que.empty()) {
			auto now = que.front();
			que.pop();
			for (const auto &e : edges[now.first]) {

				if (e.cost > L || now.second.first > dp[e.to].first) continue;

				auto tmp = now.second;
				if (e.cost > -tmp.second) {
					tmp.first++;
					tmp.second = -L + e.cost;
				}
				else tmp.second += e.cost;

				if (tmp < dp[e.to]) {
					dp[e.to] = tmp;
					que.emplace(e.to, tmp);
				}

			}
		}
		return dp;
	};

	vector<vector<pair<int, int>>> memo(N);
	for (int i = 0; i < N; i++) memo[i] = bfs(i);

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int s, t;
		cin >> s >> t;
		s--, t--;
		auto tmp = memo[s][t].first;
		if (tmp != INF) cout << tmp << "\n";
		else cout << -1 << "\n";
	}

	return 0;
}

Measured memory_bytes: 2944
#include<cstdio>
#include<cstdlib>
#include<iostream>

int main(){
    int n, q;
    std::cin >> n;
    int* S = new int[n + 1];
    for(int i = 0; i < n; i++){
        scanf("%d", &S[i]);
    }
    std::cin >> q;
    int* T = new int[q];
    for(int i =0; i < q; i++){
        scanf("%d", &T[i]);
    }
    int cnt = 0;

    for(int j = 0; j < q; j++){
        S[n] = T[j];
        int i = 0;
        while(S[i] != T[j]){
            i++;
        }
        if(i != n){
            cnt++;
        }
    }

    printf("%d\n", cnt);

    return 0;
}


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

const int Nmax=200010;

int main() {
	int N,A[2][100]={},S[2][101]={};
	cin >> N;
	for(int i=0;i < N;i++){
		cin >> A[0][i];
		S[0][i] = A[0][i] + S[0][i-1];
    }
	for(int i=0;i < N;i++){
		cin >> A[1][i];
		S[1][i] = A[1][i] + S[1][i-1];
	}
	int mac = 0;
	for(int i=0;i < N;i++){//Nだけ右に行く
		mac = max(mac,S[0][i] + (S[1][N-1]-S[1][i-1]));
	}
	cout << mac << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int gint(){
	char c; int f=1;
	while(c=getchar(),c<48||c>57)
		if(c=='-')f=-1;
	int x=0;
	for(;c>47&&c<58;c=getchar()){
		x=x*10+c-48;
	}
	return x*f;
}

#define max_N 200005

int n,a[max_N],b[max_N];

int main(){
	n=gint();
	for(int i=1,j=0,k=n+1;i<=n;++i){
		a[i]=gint();
		if(i&1)b[++j]=n-i+1;
		else b[--k]=n-i+1;
	}
	for(int i=1;i<=n;++i)printf("%d%c",a[b[i]],i==n?'\n':' ');
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>

using namespace std;

long long int Q, H, S, D, N,a,b;

int main() {
	cin >> Q >> H >> S >> D;
	cin >> N;
	a = min(Q * 8, min(H * 4, min(S * 2, D)));
	b = min(Q * 4, min(H * 2, S));
	if (N % 2 == 0) {
		cout << N / 2 * a << endl;
		return 0;
	}
	if (a >= b * 2) {
		cout << N*b << endl;
		return 0;
	}
	else {
		cout << (N / 2)*a + b << endl;
		return 0;
	}
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int a, b;
  string s;
  cin >> a >> b >> s;
  bool ok = true;
  for (int i = 0; i < a + b + 1; i++) {
    if (i == a) {
      ok &= (s[i] == '-');
    } else {
      ok &= (s[i] >= '0' && s[i] <= '9');
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{ 
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        /*var nk = Input.ar;var res = 0L;
        for(var i = 1; i <= nk[0]; i++)
        {
            var ct = 0;var k = i;
            while (nk[1] > k) { k *= 2;ct++; }
            if(ct!=0)
            res += ct + 1;
        }
        WriteLine(((double) / res).ToString("F10"));*/
        var s = ReadLine();
        var q = ToInt32(s.Substring(0, 2));
        var w = ToInt32(s.Substring(2));
        if (q > 12 && w > 12) WriteLine("NA");
        else if (q == 0 && w > 12) WriteLine("NA");
        else if (w == 0 && q > 12) { WriteLine("NA"); }
        else if (q == 0 && w == 0) { WriteLine("NA"); }
        else if (q < 12 && w == 0) WriteLine("MMYY");
        else if (w < 12 && q == 0) { WriteLine("YYMM"); }
        else if (q < 13 && w < 13) { WriteLine("AMBIGUOUS"); }
        else if (q > 12 ) WriteLine("YYMM");
        else  WriteLine("MMYY");
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

ll keta(ll n){
    ll ret=0;
    while(n){
        n/=10;
        ret++;
    }
    return ret;
}

int main(){
    ll n;cin>>n;
    ll ans=0;

    for(ll i=1;i<=n;i++){
        if(keta(i)%2==1) ans++;
    }

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

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

int main()
{
  double pi = acos(-1);
  double a, b, h, m, x1, x2, y1, y2, output;
  cin >> a >> b >> h >> m;

  x1 = b * cos(m * pi / 30);
  y1 = b * sin(m * pi / 30);
  x2 = a * cos(h * pi / 6 + m * pi / 360);
  y2 = a * sin(h * pi / 6 + m * pi / 360);
  output = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
  cout << fixed << setprecision(15) << output << endl;

  return 0;
}


Measured memory_bytes: 4048