akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<iomanip>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long

typedef pair<lint, lint> P;

struct point { lint x, y; int num; };
struct edge { lint from, to, cost; };
vector<edge> G;
int n;


struct union_find{
    vector<int> par;
    vector<int> rank;
    union_find(int n) : par(n), rank(n){
        for(int i = 0; i < n; i++){
            par[i] = i; rank[i] = 0;
        }
    }
    int root (int x){
        if(par[x] == x) return x;
        par[x] = root(par[x]);
        return par[x];
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]){
            par[rx] = ry;
        }
        else{
            par[ry] = rx;
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

lint Kruskal(){
    sort(all(G), [](edge const& l, edge const& r)->bool{
        return l.cost < r.cost;
    });

    union_find uf(n);
    lint res = 0; int c = 0;
    for(edge& e: G){
        if(uf.same(e.to, e.from)) continue;
        uf.unite(e.to, e.from);
        res += e.cost; c++;
        if(c == n - 1) break;
    }
    return res;
}

int main(){
    cin >> n;
    vector<point> vp;
    rep(i, n){
        lint x, y; cin >> x >> y;
        vp.push_back(point{x, y, i});
    }

    sort(all(vp), [](point const& l, point const& r)->bool{
        return l.x < r.x;
    });
    rep(i, n-1){
        G.push_back(edge{vp[i].num, vp[i+1].num, vp[i+1].x - vp[i].x});
        G.push_back(edge{vp[i+1].num, vp[i].num, vp[i+1].x - vp[i].x});
    }

    sort(all(vp), [](point const& l, point const& r)->bool{
        return l.y < r.y;
    });
    rep(i, n-1){
        G.push_back(edge{vp[i].num, vp[i+1].num, vp[i+1].y - vp[i].y});
        G.push_back(edge{vp[i+1].num, vp[i].num, vp[i+1].y - vp[i].y});
    }
    lint res = Kruskal();
    cout << res << endl;
}

Measured memory_bytes: 17388
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let N = parseInt(input[0][0], 10);
    let v_L = input[1].map(e => parseInt(e, 10));
    v_L.sort((a, b) => a - b);

    let ans = 0;

    for (let i = 0; i < N - 2; i++){
        for (let j = i + 1; j < N - 1; j++){
            if (v_L[i] === v_L[j]) continue;
            for (let k = j + 1; k < N; k++){
                if (v_L[j] === v_L[k]) continue;
                if (v_L[i] + v_L[j] > v_L[k]) ans ++;
                else break;
            }
        }
    }

    console.log(ans);

}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 32368
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		double a = Double.parseDouble(str[0]);
		double b = Double.parseDouble(str[1]);
		System.out.println(a*b/3.305785);
	}

}

Measured memory_bytes: 17104
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		int len = s.length();
		int del;
		for (del = 1; del < len; del++) {
			if ((len - del) % 2 != 0) continue;
			
			String sub = s.substring(0, len - del);
			String l = sub.substring(0, sub.length() / 2);
			String r = sub.substring(sub.length() / 2);
			
			if (l.equals(r)) break;
		}
		
		System.out.println(len - del);
		
		sc.close();
	}
}




Measured memory_bytes: 27028
n = int(input())
s = input()
t = input()

ans = 1
mod = 10**9+7
bef = True
skip = -1
for i in range(n):
  if skip == i:
      continue
  if i == 0:
    if s[i] == t[i]:
      ans *= 3
    else:
      ans *= 6
  elif bef:
    ans *= 2
  else:
    if s[i] != t[i]:
      ans *= 3
  if s[i] == t[i]:
    bef = True
  else:
    bef = False
    skip = i+1
  ans %= mod
print(ans)

Measured memory_bytes: 9188
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
long long x,y;
long long ans,i;
using namespace std;
int main()
{
	cin>>x>>y;
	i=x;
	while(i<=y)
	{
		i*=2;
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
///age yekam bekeshi beham is no problem ._.
#include<bits/stdc++.h>
#define size(a) (int)a.size()
#define int long long
#define F first
#define S second
#define pb push_back
using namespace std;
void null(){return ;}
const int maxn=1e5+7,INF=3e18+9237,mod=1e9+7;
int cnt[maxn];

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;cin>>n;
	for(int i=0,x;i<n;i++){
		cin>>x;
		cnt[x]++;
		cnt[x+1]++;
		if(x-1>0)cnt[x-1]++;
	}
	int ans=0;
	for(int i=0;i<maxn;i++)ans=max(ans,cnt[i]);
	cout<<ans;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int r[n];

    rep(i,n){
        int m;
        scanf("%d",&m);
        r[i] = m;
    }

    int min_r = r[0];
    int ans = r[1] - r[0];
    for(int i = 1; i < n; i++){
        min_r = min(r[i-1], min_r);
        ans = max(ans, r[i] - min_r);
    }

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

}


Measured memory_bytes: 3512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;
int koch(double lx, double ly, double rx, double ry, int n){
  if( n == 0 ){
    printf("%.10lf %.10lf\n", lx, ly);
    return 0;
  }
  double x1 = (2*lx+rx)/3;
  double y1 = (2*ly+ry)/3;

  double x3 = (lx+2*rx)/3;
  double y3 = (ly+2*ry)/3;

  double d60 = 60* M_PI / 180.0;

  double x2 = cos(d60)*(x3-x1) - sin(d60)*(y3-y1) + x1;
  double y2 = sin(d60)*(x3-x1) + cos(d60)*(y3-y1) + y1;

  koch(lx, ly, x1, y1, n-1);
  koch(x1, y1, x2, y2, n-1);
  koch(x2, y2, x3, y3, n-1);
  koch(x3, y3, rx, ry, n-1);

  return 0;
}

int main(void) {
  int n;
  cin >> n;
  koch(0.0, 0.0, 100.0, 0.0, n);
  printf("%.10lf %.10lf\n", 100.0, 0.0);
  return 0;
}

// EOF

Measured memory_bytes: 3180
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
hav = []
res = 1000
for x in a:
    # print(res)
    for y,c in hav:
        res = max(res,y*x+c)
    yy = res//x
    cc = res - yy*x
    hav.append([yy,cc])
# print(hav)
print(res)

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

int main(){
	int n;
    ll val, soma =0 ;
  cin >> n;
  for(int i = 0;i<n;i++){
  	cin >> val;
    soma += val;
    soma--;
  }
  cout<<soma<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
   
int main(){
    string s;
    cin >> s;
    bool a=false;
    if(s=="AKIHABARA")a=true;
    else if(s=="KIHABARA")a=true;
    else if(s=="KIHBARA")a=true;
    else if(s=="KIHABRA")a=true;
    else if(s=="KIHABAR")a=true;
    else if(s=="KIHBRA")a=true;
    else if(s=="KIHBAR")a=true;
    else if(s=="KIHABR")a=true;
    else if(s=="KIHBR")a=true;
    else if(s=="AKIHBARA")a=true;
    else if(s=="AKIHBRA")a=true;
    else if(s=="AKIHBAR")a=true;
    else if(s=="AKIHBR")a=true;
    else if(s=="AKIHABRA")a=true;
    else if(s=="AKIHABAR")a=true;
    else if(s=="AKIHABAR")a=true;
    if(a)cout << "YES" << endl;
    else cout << "NO" << endl;


    
} 
    

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int find(int x);
int same(int x,int y);
void unite(int x,int y);
typedef pair<ll,ll>P;
ll d[100009],p[100009];
vector<P>vec;
vector<ll>ans;
ll now;

int main(){
  ll n,m;
  cin>>n>>m;
  now=n*(n-1)/2;
  for(int i=0;i<=n;i++){
    p[i]=i;
    d[i]=1;
  }
  for(int i=0;i<m;i++){
    ll a,b;
    cin>>a>>b;
    vec.push_back(P(a,b));
  }
  reverse(vec.begin(),vec.end());
  for(int i=0;i<m;i++){
    ans.push_back(now);
    ll a=vec[i].first;
    ll b=vec[i].second;
    if(!same(a,b)){
      unite(a,b);
    }
  }
  reverse(ans.begin(),ans.end());
  for(int i=0;i<m;i++){
    cout<<ans[i]<<endl;
  }
  return(0);
}

int find(int x){
  if(p[x]==x)return x;
  return p[x]=find(p[x]);
}

int same(int x,int y){
  if(find(x)==find(y))return 1;
  else return 0;
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  p[x]=y;
  now+=d[x]*(d[x]-1)/2;
  now+=d[y]*(d[y]-1)/2;
  d[y]+=d[x];
  now-=d[y]*(d[y]-1)/2;
}


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

int heihou(int n){
  if(n==1||n==4||n==9||n==16||n==25||n==36||n==49||n==64||n==81||n==100||n==121||n==144||n==169||n==196||n==225||n==256||n==289||n==324||n==361||n==400||n==441||n==484||n==529||n==576||n==625||n==676||n==729||n==784||n==841||n==900||n==961||n==8||n==27||n==125||n==216||n==343||n==512||n==729||n==1000||n==32||n==243||n==128){
    return 1;
  }
  else{
    return 0;
  }
}

int main(){
  int n;
  cin >> n;
  for(int i=n;;i--){
    if(heihou(i)==1){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
//2013/11/01(金) 動的計画

#include <iostream>
using namespace std;

int main()
{
	int n;
	char X[257][257];
	int count;

	while(true){	

		count=0;

		cin >> n;
		
		if(n==0)
			break;

		for(int j=1; j<=n; j++)
			for(int k=1; k<=n; k++)
				cin >> X[j][k];

		int DP[4][257][257];

		for(int i=0; i<4; i++)
			for(int j=0; j<=n+1; j++)
				for(int k=0; k<=n+1; k++)
					DP[i][j][k] = 0;

		for(int j=1; j<=n; j++){
			for(int k=1; k<=n; k++){
				if(X[j][k] == '1'){
					 DP[0][j][k] = DP[0][j-1][k]+1;
              DP[1][j][k] = DP[1][j][k-1]+1;
              DP[2][j][k] = DP[2][j-1][k-1]+1;
              DP[3][j][k] = DP[3][j-1][k+1]+1;
					
					for(int i=0; i<4; i++)
						if(count < DP[i][j][k])
							count = DP[i][j][k];
				}
			}
		}

		cout << count << endl;
	}	
	return 0;
}
 

Measured memory_bytes: 2252
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    h, w, k = map(int, input().split())
    s = [input() for i in range(h)]
    ans = [[-1 for i in range(w)] for j in range(h)]

    c = 1
    for i in range(h):
        first = True
        if "#" not in s[i]:
            continue
        for j in range(w):
            if s[i][j] == "#" and first:
                first = False
            elif s[i][j] == "#":
                c+=1
            ans[i][j] = c
        c += 1
    
    for k in range(300):
        for i in range(h):
            for j in range(w):
                if ans[i][j] == -1 and i == 0:
                    ans[i][j] = ans[i+1][j]
                elif ans[i][j] == -1 and i == h - 1:
                    ans[i][j] = ans[i - 1][j]
                elif ans[i][j] == -1:
                    if ans[i - 1][j] != -1:
                        ans[i][j] = ans[i-1][j]
                    elif ans[i + 1][j] != -1:
                        ans[i][j] = ans[i+1][j]



    

    
    for i in range(h):
        print(*ans[i])        

                    


if __name__ == '__main__':
    main()


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

#define LL long long
#define RG register

using namespace std;
template<class T> inline void read(T &x) {
	x = 0; RG char c = getchar(); bool f = 0;
	while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
	while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
	x = f ? -x : x;
	return ;
}
template<class T> inline void write(T x) {
	if (!x) {putchar(48);return ;}
	if (x < 0) x = -x, putchar('-');
	int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
	for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 1e5 + 10, Limit = 1 << 15;
int val[N], cnt[15], res[Limit], f[Limit];
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n;
	read(n);
	for (int i = 1; i < n; i++) {
		int x, y, z; read(x), read(y), read(z);
		x++; y++; val[x] ^= z; val[y] ^= z;
	}
	for (int i = 1; i <= n; i++) cnt[val[i]]++;
	int ans = 0, S = 0;
	for (int i = 1; i <= 15; i++)
		ans += cnt[i] / 2, S |= (cnt[i] & 1) << (i - 1);
	for (int i = 1, cnt; i < Limit; i++) {
		cnt = 0;
		for (int j = 1; j <= 15; j++)
			if ((i >> (j - 1)) & 1) res[i] ^= j, cnt++;
		f[i] = cnt - 1;
	}
	for (int i = 1; i < Limit; i++)
		if (!res[i])
			for (int j = i; j; j = (j - 1) & i)
				if (!res[j]) f[i] = min(f[i], f[j] + f[i ^ j]);
	printf("%d\n", ans + f[S]);
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int Mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

void f()
{
    int n,mn=INT_MAX,s1,s2;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(int i=0; i<n; i++)
    {
        s1=0,s2=0;
        for(int j=0; j<i; j++)
            s1+=a[j];
        for(int j=i; j<n; j++)
            s2+=a[j];
        mn=min(mn,abs(s1-s2));
    }
    cout<<mn<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		string s=Console.ReadLine();
		long ans=0,k=0;
		for(int i=s.Length-1;i>=0;i--){
			if(s[i]=='W'){
				k++;
			}
			else{
				ans+=k;
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const int mod = 1e9+7;
int n;
string s;

void solve(){
	ll dp[n][13];
	memset(dp,0,sizeof(dp));
	if( s[0] != '?' ){ dp[0][s[0]-'0']++; }
	else{
		for(int i=0; i<10; ++i){ dp[0][i]++; }
	}
	for(int i=1; i<n; ++i){
		if( s[i] != '?' ){
			for(int k=0; k<13; ++k){
				dp[i][(10*k+(s[i]-'0'))%13] += dp[i-1][k] % mod;
				dp[i][(10*k+(s[i]-'0'))%13] %= mod;
			}
		}else{
			for(int j=0; j<10; ++j){
				for(int k=0; k<13; ++k){
					dp[i][(10*k+j)%13] += dp[i-1][k] % mod;
					dp[i][(10*k+j)%13] %= mod;
				}
			}
		}
	}
	cout<<dp[n-1][5]<<'\n';
}




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

	cin>>s;
	n = s.size();
	solve();

	return 0;
}


Measured memory_bytes: 10604
///created: 11/Jul/2019 12:41:17

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
const int modulo = 1e9 + 7;

#ifdef LOCAL_DEBUG_NTV1612
template<class __Ty>
string to_string(__Ty a) {
	string res = "[ ";
	bool f = true;
	for (auto &p : a) { res += (f ? string("") : string(", ")) + to_string(p); f = false;	}
	return res + " ]";
}
void _debug() { fprintf(stderr, "\n"); }
template<typename __Ty_head, typename... __Ty_tail>
void _debug(__Ty_head head, __Ty_tail... tail) { fprintf(stderr, "%s ", to_string(head).c_str()); _debug(tail...); }
#define debug(...) fprintf(stderr, "DEBUG [%s]: ", #__VA_ARGS__), _debug(__VA_ARGS__)
#else
#define debug(...) 0
#endif

template<class __Ty> bool mini(__Ty& a, __Ty b) { return a > b ? ((a = b) | 1) : (0); }
template<class __Ty> bool maxi(__Ty& a, __Ty b) { return a < b ? ((a = b) | 1) : (0); }
template<class __Ty> __Ty add(__Ty a, __Ty b) { return (a + b) % (__Ty(modulo)); }
template<class __Ty> __Ty sub(__Ty a, __Ty b) { __Ty m(modulo); return ((a - b) % m + m) % m; }

const int N = 21;
struct edge {
	int v, c;
	edge(int a = 0, int b = 0) {
		v = a;
		c = b;
	}
};
vector<edge> g[N];
int n, m, x[N];
int cnt;
vector<int> rc;

int dfs(int i, int cost) {
	if (x[i] == 20) {
		printf("%4d: ", ++cnt);
		for (int z = 1; z <= i; ++z)
			printf("%2d ", x[z]);
		printf(": %d\n", cost);
		rc.push_back(cost);
	}
	else {
		for (edge e : g[x[i]]) {
			x[i + 1] = e.v;
			dfs(i + 1, cost + e.c);
		}
	}
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int L, n, c = 1;
	n = 20;
	cin >> L;
	for (int i = 1; i <= 19; ++i)
		g[i].push_back(edge(i + 1, 0));
	vector<int> f;
	while (L) {
		f.push_back(L & 1);
		L /= 2;
	}
	f.pop_back();
	reverse(f.begin(), f.end());
	int u = 2, w[21] = {0}, m = 19;
	w[1] = 0;
	for (int v : f) {
		if (v) {
			w[u] = w[u - 1] * 2 + 2;
			g[u - 1].push_back(edge(u, w[u] - w[u - 1] - 1));
			g[1].push_back(edge(u, w[u]));
			m += 2;
		}
		else {
			w[u] = w[u - 1] * 2 + 1;
			g[u - 1].push_back(edge(u, w[u] - w[u - 1]));
			m++;
		}
		++u;
	}
	cout << 20 << ' ' << m << '\n';
	for (int i = 1; i <= 20; ++i)
		for (edge e : g[i])
			cout << i << ' ' << e.v << ' ' << e.c << '\n';
	return 0;
}


Measured memory_bytes: 256
use std::io::stdin;

fn main () {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let s: Vec<isize> = s.trim().split('/').flat_map(str::parse).collect();
    let y = s[0];
    let m = s[1];
    let d = s[2];
    if y > 2019 || (y == 2019 && m >= 5) {
        println!("TBD");
    } else {
        println!("Heisei");
    }
}


Measured memory_bytes: 4352
n=int(input())
print(0)
A=[-1]*n
S=input()
if S=="Vacant":
  exit()
elif S=="Male":
  A[0]=0
else:
  A[0]=1
l=0
r=n
while r-l!=0:
  mid=(l+r)//2
  print(mid)
  S=input()
  if S=="Vacant":
    exit()
  elif S=="Male":
    A[mid]=0
  else:
    A[mid]=1
  if (mid-l)%2!=(A[l]+A[mid])%2:
    r=mid
  else:
    l=mid

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

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

  vector<pair<int, int>> ab(n);
  rep(i, n) cin >> ab[i].first >> ab[i].second;

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

  int cnt = 0;
  int i = 0;
  ll ans = 0;
  while (cnt < m) {
    int d = min(m - cnt, ab[i].second);
    ans += (ll)ab[i].first * d;
    cnt += d;
    i++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include<cstdlib>
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <string>
void call(int n);
using namespace std;
int main(){
	
	int r,c;
	cin>>r>>c;
	
	int ar[r+1][c+1];
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>ar[i][j];
		}
	}
	
	
	for(int i=0;i<r;i++){
		int sum=0;
		for(int j=0;j<c+1;j++){
			
			if(j!=c){
				sum=sum+ar[i][j];
				cout<<ar[i][j]<<' ';
			}else{
				ar[i][c]=sum;
				cout<<sum<<endl;
				
			}
		}
	}
	for(int i=0;i<c+1;i++){
		int sum=0;
		for(int j=0;j<r;j++){
			sum=sum+ar[j][i];
		}
		if(i==c){cout<<sum<<endl;

		}else{		cout<<sum<<' ';}
	}

}


Measured memory_bytes: 3132
import itertools

n, m = map(int, input().split())

path = [[False] * n for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True

ans = 0

# 頂点を並び替える順列を生成してループ
for i in itertools.permutations(range(n), n):
    # 頂点1が始点
    if i[0] == 0:
        # 生成した順列の中をさらにループ
        for j in range(n):
            # n - 1 まで続いたら条件を満たすパスが存在する
            if j == n - 1:
                ans += 1
                break
            # i[j] から i[j + 1] に行くパスがなければ終了
            if not path[i[j]][i[j + 1]]:
                break

print(ans)

Measured memory_bytes: 39920
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>

int main(){
  int N;
  std::cin >> N;
  
  int x=0;
  int y=0;
  int t = 0;
  
  for(int i=0;i<N;++i){
    int T,X,Y;
    std::cin >> T>> X >> Y;
    
    int distance = std::abs(X - x) +  std::abs(Y - y);
    int time = T - t;
    if(distance > time || ((time - distance) % 2)){
  	  std::cout << "No";
      return 0;
    }
    
    x = X;
    y = Y;
    t = T;
  }
  
  	std::cout << "Yes";
      return 0;
}

Measured memory_bytes: 256
from fractions import gcd
from functools import reduce
def gcd_list(n):
    return reduce(gcd, n)

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
dist = []
for i in range(N):
    dist.append(x[i+1] - x[i])
print(gcd_list(dist))

Measured memory_bytes: 16280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cassert>

using namespace std;
#define ll long long
#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
int N, Ans; inline ll sg(ll x, ll k){if(x<k) return 0; if(!(x%k)) return x/k; return sg(x-((x%k-1)/(x/k+1)+1)*(x/k+1),k);}
int main(){N = read(); for(rint i = 1, a, k; i <= N; a = read(), k = read(), Ans ^= sg(a,k), i++); puts(Ans?"Takahashi":"Aoki"); return 0;}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, H, best, ans;
std::vector<LL> a, b;

int main()
{
	std::cin >> N >> H;
	rep(i,N)
	{
		LL aa, bb;
		std::cin >> aa >> bb;
		a.push_back(aa);
		b.push_back(bb);
		best = std::max(best, aa);
	}

	std::sort(a.begin(), a.end(), std::greater<LL>());
	std::sort(b.begin(), b.end(), std::greater<LL>());
	rep(i,N-1)
	{
		b[i + 1] += b[i];
	}
	ans = 1145148101919931;
	rep(i,N)
	{
		LL life = H - b[i], res;
		if (life <= 0)
			res = i + 1;
		else
			res = i + 1 + life / best + (life % best != 0 ? 1 : 0);
		ans = std::min(ans, res);
	}

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


Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++) 
using namespace std;
int dp[101][10001];
int main(){
    int n,w;
    cin>>n>>w;
    int v[n+1],a[n+1];
    r(i,1,n+1)cin>>v[i]>>a[i];
    r(i,1,n+1)r(j,1,w+1){
    	if(j<a[i])dp[i][j]=dp[i-1][j];
    	else dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i]]+v[i]);
    }
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 7016
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


template<int MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0) val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator - () const noexcept {
    return val ? MOD - val : 0;
  }
  constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp& operator += (const Fp& r) noexcept {
    val += r.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  constexpr Fp& operator -= (const Fp& r) noexcept {
    val -= r.val;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr Fp& operator *= (const Fp& r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp& operator /= (const Fp& r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr bool operator == (const Fp& r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator != (const Fp& r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
    if (n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1) t = t * a;
    return t;
  }
};
using mint = Fp<MOD>;


int main() {
  ll n; cin >> n;
  vector<mint> x(n);
  rep(i, n) {
    int a; cin >> a;
    x[i] = mint(a);
  }

  mint ans = 0;
  mint invsum = 0;
  mint fac = 1;
  rep(i, n-1) {
    invsum += mint(1) / mint(1+i);
    ans += invsum * (x[i+1] - x[i]);
    fac *= mint(i+1);
  }
  ans *= fac;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline long IN(void)
{
  long x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline long Abs(const long x){return x<0?-x:x;}
int main(void)
{
  long X=IN(),K=IN(),D=IN();X=Abs(X);
  if(X/D>=K){X-=K*D;return OUT(X),0;}else K-=X/D,X-=X/D*D;
  return (K&1)?OUT(Abs(X-D)):OUT(X),0;
}

Measured memory_bytes: 1536
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, A, B = list(map(int, sys.stdin.readline().split()))
S = sys.stdin.readline().rstrip()

cnt = 0
b = 0
for c in S:
    ok = False
    if c == 'a':
        ok = cnt < A + B
    if c == 'b':
        ok = cnt < A + B and b < B
        b += ok
    cnt += ok
    if ok:
        print('Yes')
    else:
        print('No')


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

#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
	bool flag = 0;
	string s, t;
	cin>>s>>t;
		int pos = s.length()-t.length();
		while(pos>=0){
		flag  = 0;
		string ans = s.substr(pos, t.length());
		rep(i,0,ans.length()){
			if(ans[i] != '?' && ans[i] != t[i]){
				flag = 1;
				break;
			}
		}	
		if(flag == 0)break;
			pos--;
		}
		if(pos >=  0 && flag == 0){
			rep(i, pos, pos + t.length())
				s[i] = t[i-pos];
			rep(i,0,s.length())
				if(s[i] == '?')
					s[i] = 'a';
			cout<<s<<endl;
		}
		else
		cout<<"UNRESTORABLE"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        int q = s.nextInt();
        List<Integer> l = new ArrayList<>();
        List<Integer> ans = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(s.nextInt());
        }
        for (int i = 0; i < n; i++) {
            ans.add(k-q);
        }
        for (int i = 0; i < q; i++) {
            ans.set(l.get(i)-1,ans.get(l.get(i)-1)+1);
        }
        for (int answer : ans) {
            if (answer <= 0)
                System.out.println("No");
            else
                System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 78424
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	//奇数にLなく偶数にRない
	string S;
	cin >> S;
	for (int i = 0; i < S.length(); i += 2) {
		//Lなし
		if (S[i] == 'L') {
			cout << "No";
			return 0;
		}
	}
	for (int i = 1; i < S.length(); i += 2) {
		//Rなし
		if (S[i] == 'R') {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Num 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int d, g;
    vector<pair<int, int>> v;
    vector<int> lim;
    vector<int> use;
    cin >> d >> g;
    rep(i, d)
    {
        pair<int, int> hoge;
        cin >> hoge.first >> hoge.second;
        v.push_back(hoge);
    }
    int ans = INT_MAX;
    rep(i, pow(2, d))
    {
        int count = 0;
        int value = 0;
        rep(j, d)
        {
            if ((i & (1 << j)) > 0)
            {
                count += v[j].first;
                value += v[j].first * 100 * (j + 1) + v[j].second;
            }
        }
        if (g <= value)
        {
            //cout << "0Count " << count << "Value " << value << endl;
            ans = min(ans, count);
            continue;
        }
        int use = -1;
        rep(j, d)
        {
            if ((i & (1 << j)) == 0)
            {
                use = j;
            }
        }
        rep(j, v[use].first)
        {
            value += 100 * (use + 1);
            count++;
            if (value >= g)
            {
                //cout << "1Count " << count << "Value " << value << endl;
                ans = min(ans, count);
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
using ll = long long;
using vl = vector<ll>;


int main() {
    int N, K, C;
    string S;
    cin >> N >> K >> C >> S;
    vl a(N, -1), b(N, -2);
    int cnt = 0;
    rep(i,N) {
        if (S[i]=='o' and cnt < K) {
            a[i] = cnt; cnt++;
            i += C;
        }
    }
    reverse(S.begin(), S.end());
    cnt = 0;
    rep(i,N) {
        if (S[i]=='o' and cnt < K) {
            b[N-1-i] = K-1-cnt; cnt++;
            i += C;
        }
    }
    rep(i,N) {
        if (a[i] == b[i]) {
            cout << i+1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4996
#include <iostream>
using namespace std;
int main(){
string S;
  cin>>S;
  if(S=="A"){
  cout<<"T";
  }
  else if(S=="T"){
  cout<<"A";
  }
  else if(S=="C"){
  cout<<"G";
  }
  else{
  cout<<"C";
  }
}


Measured memory_bytes: 3600
:- use_module(library(apply)).
:- use_module(library(yall)).

main :-
	read_num(N),
        read_n_string_list(N, L),
        include([X]>>(X == "AC"),
                L,
                AC),
        include([X]>>(X == "WA"),
                L,
                WA),
        include([X]>>(X == "TLE"),
                L,
                TLE),
        include([X]>>(X == "RE"),
                L,
                RE),
        length(AC, NumAC),
        length(WA, NumWA),
        length(TLE, NumTLE),
        length(RE, NumRE),
	write('AC x '), write(NumAC), nl,
        write('WA x '), write(NumWA), nl,
        write('TLE x '), write(NumTLE), nl,
        write('RE x '), write(NumRE), nl,
	nl,
	halt.


read_n_string_list(N, L) :-
	read_n_string_list_aux(N, [], L),
	!.
read_n_string_list_aux(0, L, L).
read_n_string_list_aux(N, Acc, L) :-
	read_str(NewS),
	NewN is N - 1,
	read_n_string_list_aux(NewN, [NewS|Acc], L).
	

read_str(S) :-
        read_string(current_input, ' \n', '', _, S).

read_num(N) :-
	read_str(S),
	number_string(N, S).



Measured memory_bytes: 17336
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

WHITE = '.'
BLACK = '#'

num_white = 0
for x in range(H):
    for y in range(W):
        if S[x][y] == WHITE:
            num_white += 1

is_reached = False
positions = [(0, 0)]
delta_positions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
S[0][0] = 1

while positions:
    new_positions = []
    for x, y in positions:
        for dx, dy in delta_positions:
            new_x = x + dx
            new_y = y + dy
            if 0 <= new_x and new_x < H and 0 <= new_y and new_y < W:
                if S[new_x][new_y] == WHITE:
                    new_positions.append((new_x, new_y))
                    S[new_x][new_y] = S[x][y] + 1
                    if new_x == H - 1 and new_y == W - 1:
                        is_reached = True
                        break
    positions = new_positions

if is_reached:
    print(num_white - S[H-1][W-1])
else:
    print(-1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
		

}
int main(){

  
  ll X,Y,A,B,C;
 
  cin>>X>>Y>>A>>B>>C;
  
  priority_queue<ll>p;
  priority_queue<ll>q;
  priority_queue<ll,vector<ll>,greater<ll>>r;
  priority_queue<int, vector<int>, greater<int> >que;
  
  rep(i,A){
    ll a;
    cin>>a;
     p.push(a);
  }
  rep(i,B){
    ll b;
    cin>>b;
     q.push(b);
  }

    rep(i,C){
    ll c;
    cin>>c;
     r.push(c);
  }

  
  rep(i,X){
    que.push(p.top());
    p.pop();
  }
 rep(i,Y){
    que.push(q.top());
    q.pop();
  }
  while(!(r.empty())){
    if(que.top()<r.top()){
      que.pop();
      que.push(r.top());
        r.pop();
    }
                          else{
r.pop();
                          }
                         }
ll sum=0;
    
    while(!(que.empty())){
      sum+=que.top();
      que.pop();
    }
    
    cout<<sum<<endl;
  }


Measured memory_bytes: 4084
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
  //↓見なくていいよ！ここから------------------------------------------
  static public class InputIterator{
    ArrayList<String> inputLine = new ArrayList<String>(1024);
    int index = 0; int max;
    InputIterator(){
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      while(true){
        String read;
        try{
          read = br.readLine();
        }catch(IOException e){
          read = null;
        }
        if(read != null){
          inputLine.add(read);
        }else{
          break;
        }
      }
      max = inputLine.size();
    }
    public boolean hasNext(){return (index < max);}
    public String next(){
      if(hasNext()){
        String returnStr = inputLine.get(index);
        index++;
        return returnStr;
      }else{
        throw new IndexOutOfBoundsException("これ以上入力はないよ。");
      }
    }
  }
  
  static InputIterator ii = new InputIterator();//リアクティブでは使えないので諦めてScanner使うこと
  static PrintWriter out = new PrintWriter(System.out);
  static void flush(){out.flush();}
  static void myout(Object t){out.println(t);}
  static void myerr(Object t){System.err.println(t);}
  static String next(){return ii.next();}
  static int nextInt(){return Integer.parseInt(next());}
  static long nextLong(){return Long.parseLong(next());}
  static ArrayList<String> nextStrArray(){return myHanSpSplit(next());}
  static ArrayList<String> myHanSpSplit(String str){return new ArrayList<String>(Arrays.asList(str.split(" ")));}
  static ArrayList<String> nextCharArray(){return mySingleSplit(next());}
  static ArrayList<String> mySingleSplit(String str){return new ArrayList<String>(Arrays.asList(str.split("")));}
  static ArrayList<Integer> nextIntArray(){
    ArrayList<Integer> ret = new ArrayList<Integer>();
    ArrayList<String> input = nextStrArray();
    for(int i = 0; i < input.size(); i++){
      ret.add(Integer.parseInt(input.get(i)));
    }
    return ret;
  }
  static ArrayList<Long> nextLongArray(){
    ArrayList<Long> ret = new ArrayList<Long>();
    ArrayList<String> input = nextStrArray();
    for(int i = 0; i < input.size(); i++){
      ret.add(Long.parseLong(input.get(i)));
    }
    return ret;
  }
  static String kaigyoToStr(String[] list){return String.join("\n",list);}
  static String kaigyoToStr(ArrayList<String> list){return String.join("\n",list);}
  static String hanSpToStr(String[] list){return String.join(" ",list);}
  static String hanSpToStr(ArrayList<String> list){return String.join(" ",list);}
  public static void main(String[] args){
    solve();
    flush();
  }
  //↑見なくていいよ！ここまで------------------------------------------
  static public void solve(){//ここがメイン関数代わり
    ArrayList<String> tmp = nextStrArray();
    BigDecimal A = new BigDecimal(tmp.get(0));
    BigDecimal B = new BigDecimal(tmp.get(1));
    A = A.multiply(B);
    Long output = A.longValue();
    myout(output);
    
  }
  //Method addition frame start

  //Method addition frame end
}


Measured memory_bytes: 33164
#include <iostream>
#define ll long long
using namespace std;

ll N;
ll W;
ll w[120];
ll v[120];
ll  dp[120][100005];
ll solve(ll n,ll up_to);

int main(){
  cin>>N>>W;
  
  for(ll in=1;in<=N;in++){
    cin>>w[in]>>v[in];
  }
 
  for(ll i=0;i<=W;i++) dp[0][i] =0;
  for(ll j=1;j<=N;j++) dp[j][0]=0;
  
  for(ll n=1;n<=N;n++){
    for(ll up_to=1;up_to<=W;up_to++ ){
      if(up_to-w[n]>=0){
         dp[n][up_to] = max(dp[n-1][up_to],dp[n-1][up_to-w[n]]+v[n]);
      } else {
        dp[n][up_to] = dp[n-1][up_to];
      }
    }
  }
  cout<<dp[N][W]<<endl;
  
  return 0;
}




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

int bubbleSort(int a[], int n){
  int sw=0;
  bool flag=1;
  for(int i=0; flag; i++){
    flag=0;
    for(int j=n-1; j>=i+1; j--){
      if(a[j]<a[j-1]){
	swap(a[j],a[j-1]);
	flag=1;
	sw++;
      }
    }
  }
  return sw;
}

int main(){
  int a[100],n,sw;
  cin>>n;
  for(int i=0; i<n; i++) cin>>a[i];

  sw=bubbleSort(a,n);

  for(int i=0; i<n; i++){
    if(i) cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  cout<<sw<<endl;

  return 0;
}



Measured memory_bytes: 3064
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product

# input = sys.stdin.readline
ABCD = input()
for p in product((0, 1), repeat=3):
    A, B, C, D = int(ABCD[0]), int(ABCD[1]), int(ABCD[2]), int(ABCD[3])
    total = 0
    if (p[0] == 0):
        total = A + B
    else:
        total = A - B
    if (p[1] == 0):
        total += C
    else:
        total -= C
    if (p[2] == 0):
        total += D
    else:
        total -= D
    if total == 7:
        break
if p[0] == 0:
    op1 = "+"
else:
    op1 = '-'
if p[1] == 0:
    op2 = "+"
else:
    op2 = '-'
if p[2] == 0:
    op3 = "+"
else:
    op3 = '-'
print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))









Measured memory_bytes: 27016
#include <iostream>
#include <string>
#include <algorithm>
#define MAX 1e9
using namespace std;


int main()
{
int N;
cin>>N;
int A[N];
int B[N];
int min=MAX;
for(int i=0;i<N;i++){
  cin>>A[i];
  if(min>A[i])min=A[i];
};
int min1=0;
while(1){
  min1=min;
for(int i=0;i<N;i++){

  B[i]=A[i]%min;
  if(B[i]>0){if(min>B[i])min=B[i];}
  }
if(min1==min){
  cout<<min<<endl;
  break;
}
}
return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
long long n,i,b,c;
int main(){
  cin>>n;
  vector<long long> a(n,0);
  for(;i<n;i++)cin>>b,b--,a[i]=b;
  for(i=0;i<n;i++){
    if(a[a[i]]==i)c++;
  }
  cout<<c/2;
}

Measured memory_bytes: 1024
n=int(input())
H=list(map(int,input().split()))

if n==1:
  print("Yes")

for i in range(n-1):
  d=H[i+1]-H[i]
  if d<-1:
    print("No")
    break
  if d==-1:
    H[i+1]+=1
  if i==n-2 and d>-2:
    print("Yes")
    

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string str;
    cin >> str;
    if(str.at(2) == str.at(3) && str.at(4) == str.at(5)
     ){
     cout << "Yes" << endl;
     }
     else{
         cout << "No" << endl;
     }
}

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

char F(long long int N) {
  char X = 'a' + N - 1;
  if (N == 0) X = 'z';
  return X;
}

int main() {
  long long int N;
  cin >> N;
  vector<char> V;
  while (N > 0) {
    V.push_back(F(N % 26));
    if (N % 26 == 0) N -= 26;
    N /= 26;
  }
  for (int i = V.size() - 1; i >= 0; i--) {
    cout << V.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) for(int i=0; i<n; i++)

typedef long long int ll;

int main(){
  int sx,sy,tx,ty,diffx,diffy;
  scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
  diffx=tx-sx;
  diffy=ty-sy;
  REP(i,diffx) printf("R");
  REP(i,diffy) printf("U");
  REP(i,diffx) printf("L");
  REP(i,diffy+1) printf("D");
  REP(i,diffx+1) printf("R");
  REP(i,diffy+1) printf("U");
  printf("LU");
  REP(i,diffx+1) printf("L");
  REP(i,diffy+1) printf("D");
  printf("R");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+7;
typedef long long LL;
int a[N];
LL f[N], dist[N];
void init(int n)
{
    for(int i=0;i<=n;i++) f[i]=i;
    memset(dist,0,sizeof(dist));
    return ;
}
LL get(LL x)
{
    if(x!=f[x])
    {
        LL t=(f[x]);
        f[x]=get(f[x]);
        dist[x]+=dist[t];
    }
    return f[x];
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    sort(a+1,a+n+1);
    int cnt=0, sum=0;
    for(int i=n;i>=0;i--)
    {
        if(cnt==k) break;
        sum+=a[i];
        cnt++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr char sp=' ';
constexpr ll mod=1000000007;

int N,A,B;
ll res;

ll pw(ll x,int y){
	ll a=1;
	while(y){
		if(y&1)a=a*x%mod;
		x=x*x%mod;
		y/=2;
	}
	return a;
}

ll modinv(ll x){
	return pw(x,mod-2);
}

ll comb(int n,int r){
	ll a,b;
	a=b=1;
	for(ll i=1;i<=r;i++){
		a*=(n-i+1);
		b*=i;
		a%=mod;
		b%=mod;
	}
	return a*modinv(b)%mod;
}

int main(){
	cin>>N>>A>>B;
	res=pw(2,N);
	res--;
	res-=comb(N,A);
	res-=comb(N,B);
	res+=mod*10;
	res%=mod;
	cout<<res<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A[500000+1], h;

int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

void maxHeap(int i){
  int l=left(i), r=right(i);
  int largest;
  
  if(l <= h && A[l] > A[i]) largest=l;
  else largest=i;

  if(r <= h && A[r] > A[largest]) largest=r;

  if(largest != i){
    swap(A[i], A[largest]);
    maxHeap(largest);
  }
}

  


int main(void){
  int i;
  
  scanf("%d", &h);
  for(i=1; i<=h; i++) scanf("%d", &A[i]);

  for(i=h/2; i>=1; i--) maxHeap(i);  

  for(i=1; i<=h; i++) printf(" %d", A[i]);
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std;
#define float double
float dp[3000][3000];//dp[i][j] will represent that i am at coin i and have j heads



int main()
{
    int n;
    cin>>n;
    vector<float> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];//this is the probability of getting a head
    }
    
    memset(dp,0.0,sizeof(dp));

    dp[0][0]=1.0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*(1.0-v[i-1]);//at coin i getting 0 heads
        //means all tails
    }
    
    for(int i=1;i<=n;i++)//coin i starts from 1//1 based indexing
    {
        for(int j=1;j<=n;j++)
        {
            dp[i][j]=v[i-1]*dp[i-1][j-1]+(1.0-v[i-1])*dp[i-1][j];//on coin i if head then i need j-1 heads
            //if tail then j tails on the i-1 coins
        }
    }
    
    
    
    float ans=0.0;
    for(int j=0;j<=n;j++)//means heads are j
    {
        int tails=n-j;
        if(j>tails)//if heads are more than tails
        {
            ans=ans+dp[n][j];
        }
    }
    
    printf("%.9f\n",ans);
    
    return 0;
}

Measured memory_bytes: 70528
import java.util.Scanner;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final String A;
    private final String B;
    private final String C;

    public Main() {
	A = scan.next();
	B = scan.next();
	C = scan.next();

	scan.close();
    }

    public final void answer() {
	System.out.println(A.charAt(A.length()-1) == B.charAt(0) && B.charAt(B.length()-1) == C.charAt(0) ? "YES" : "NO");
    }
}


Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
    	Scanner sn = new Scanner(System.in);
        int x  = sn.nextInt();
      	if( x== 0 ) {
        	        System.out.println("1");
        } else {
                System.out.println("0");

        }
    }
}
 

Measured memory_bytes: 35788
#include <cstdio>
#define ll long long

int main() {
    ll score, tot = 0, now = 1, cnt = 0;
    scanf("%lld", &score);
    cnt += (score / 11) * 2;
    int c = score % 11;
    if(c > 6)  cnt += 2;
    else if(c <= 6 && c > 0)   cnt += 1;
    printf("%lld\n", cnt);
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];
		int point = 0;
		for(int i = 0; i < n - 1; i++) {
			point = sc.nextInt();
			num[point - 1]++;
		}
		for(int j = 0; j < n; j++) {
			System.out.println(num[j]);
		}
	}
}

Measured memory_bytes: 62124