akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
lld dp[100005][101];
lld change(lld ar[], lld br[] , lld k,lld n)
{
    if(k<=0)
    return 0;
    if(n<=0)
    return 0;
    if(dp[k][n]!=-1)
        return dp[k][n];

    lld b=0;
    if(k>=ar[0])
        b=br[0]+change(ar+1,br+1,k-ar[0],n-1);
    lld ans=max(b,change(ar+1,br+1,k,n-1));
    dp[k][n]=ans;
    return ans;

}
int main()
{

        lld k,m;
        cin>>m>>k;
        lld ar[m];
        lld br[m],i,j;
        for(i=0;i<100005;i++)
        {
            for(j=0;j<101;j++)
                dp[i][j]=-1;
        }
        for(i=0;i<m;i++)
            cin>>ar[i]>>br[i];
        cout<<change(ar,br,k,m);

}


Measured memory_bytes: 79104
"use strict";
function main(input) {
  let a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];

  let k = parseInt(input[0]);

  console.log(a[k-1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int n;
vector<pair<int,int>> e[100000];
int num;
int ans[100000];

void solve(int v,int p,int c){
    for(auto nt:e[v]){
        int u=nt.first;
        int i=nt.second;
        if(u!=p){
            ans[i]=(c+1)%num;
            solve(u,v,(c+1)%num);
            c=(c+1)%num;
        }
    }
}

int main(){
    cin>>n;
    int cnt[n]={};
    for(int i=0;i<n-1;i++){
        int s,t;
        cin>>s>>t;
        --s,--t;
        e[s].push_back({t,i});
        e[t].push_back({s,i});
        cnt[s]++;
        cnt[t]++;
    }
    for(int i=0;i<n;i++){
        num=max(num,cnt[i]);
    }
    solve(0,-1,-1);
    cout<<num<<endl;
    for(int i=0;i<n-1;i++){
        cout<<ans[i]+1<<endl;
    }
}

Measured memory_bytes: 7680
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef double db;
typedef string str;
// head

void solve(){
    str s,t;
    cin>>s>>t;
    int S=s.size();
    int T=t.size();
    int dp[1010][1010];
    range(i,S){
        range(j,T){
            if (s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }
            else{
                dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
            }
        }
    }
    cout<<dp[S][T]<<endl;
}

int main(){
    int n;
    cin>>n;
    range(i,n)
    solve();
}


Measured memory_bytes: 7124
import sys
sys.setrecursionlimit(10**5) #再帰回数を増やさないとREになる

N, M, K = map(int, input().split())
friend = [[] for _ in range(N)]
block = [[] for _ in range(N)]
for _ in range(M):
  a, b = map(int, input().split())
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
for _ in range(K):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)

sgn = [0 for _ in range(N)]
groupnum = 0

def makenetwork(n, groupnum):
  for item in friend[n]:
    if sgn[item] == 0:
      sgn[item] = groupnum
      makenetwork(item, groupnum)

for k in range(N):
  if sgn[k] == 0:
    groupnum += 1
    sgn[k] = groupnum
    makenetwork(k, groupnum)

count = [0 for _ in range(groupnum)]
for k in range(N):
  count[sgn[k]-1] += 1

ans = ''
for k in range(N):
  num = count[sgn[k]-1] -1  - len(friend[k])
  for item in block[k]:
    if sgn[item] == sgn[k]:
      num -= 1
  ans += str(num) + ' '

ans.rstrip()
print(ans)

Measured memory_bytes: 64432
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class CFennecVsMonster
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var n = long.Parse(input[0]);
            var k = long.Parse(input[1]);
            var hList = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
            hList.Sort();

            for (int i = 0; i < k; i++)
            {
                if (hList.Count == 0)
                {
                    break;
                }
                hList.RemoveAt((int)n - i - 1);
            }

            Console.WriteLine(hList.Sum());
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 37760
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int x[20], y[20], p[20];
ll ans[20], c[(1<<15)+10][18][2];

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    for (int i=0;i<n;i++) cin >> x[i] >> y[i] >> p[i];

    int cnt2 = 1, cnt3 = 1;
    for (int i=0;i<n;i++) {
        cnt2 *= 2; cnt3 *= 3;
    }

    for (int i=0;i<cnt2;i++) {
        vector<int> t;
        for (int j=0;j<n;j++) {
            if (((1<<j)&i)==0) continue;
            t.pb(j);
        }

        // y line
        for (int j=0;j<n;j++) {
            ll now = 1LL*p[j]*abs(x[j]);
            for (auto g: t) now = min(now, 1LL*p[j]*abs(x[g]-x[j]));
            c[i][j][0] = now;
        }

        // x line
        for (int j=0;j<n;j++) {
            ll now = 1LL*p[j]*abs(y[j]);
            for (auto g: t) now = min(now, 1LL*p[j]*abs(y[g]-y[j]));
            c[i][j][1] = now;
        }
    }

    for (int i=0;i<=n;i++) ans[i] = 1e18;

    for (int i=0;i<cnt3;i++) {
        string t = "";
        int v = i, cnt = 0;
        for (int j=0;j<n;j++) {
            t += (char)(v%3+'0');
            if (v%3) cnt++;
            v /= 3;
        }
        reverse(t.begin(), t.end());

        int g1 = 0, g2 = 0, p = 1;
        for (int j=0;j<n;j++) {
            if (t[j]=='1') g1 += p;
            if (t[j]=='2') g2 += p;
            p <<= 1;
        }

        ll now = 0;
        for (int j=0;j<n;j++) {
            now += min(c[g1][j][0], c[g2][j][1]);
        }
        ans[cnt] = min(ans[cnt], now);
    }

    for (int i=0;i<=n;i++) cout << ans[i] << endl;
}


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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

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

    ll n;
    cin >> n;
    vector<ll> t(n);
    for (ll i = 0;i < n;i++){
        cin >> t[i];
    }

    ll ans = t[0];

    for (ll i = 0; i < n; i++){
        ans = lcm(ans,t[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int a;
    unsigned long long int ans = 0;
    int x = 0;
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a);
        if (a == 0)
            x = 0;
        else
        {
            if (x == 1)
            {
                ans++;
                a--;
                x = 0;
            }
            ans += (unsigned long long int)a / 2;
            x = a % 2;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int func(int i,int ht[],int dp[])
{
	if(i==1)
		return 0;
	if(i<1)
		return 1e9;
	if(dp[i]!=-1)
		return dp[i];
	int pos1=abs(ht[i]-ht[i-1]) + func(i-1,ht,dp);
	int pos2=abs(ht[i]-ht[i-2]) + func(i-2,ht,dp);
	return dp[i] = min(pos1,pos2);
}
int main()
{
	int n;
	cin>>n;
	int ht[n+1]={0};
	for(int i=1;i<=n;i++)
		cin>>ht[i];
	int dp[n+1];
	memset(dp,-1,sizeof(dp));
	cout<<func(n,ht,dp);
}

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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

//2値の最大公約数(順序関係なし・0はダメ)
int gcd(int a, int b){
    return b ? gcd(b, a%b) :a;
}

//n個の最大公約数
int ngcd(vector<int>& a){
    int res;
    res = a.at(0);
    for(int i = 1; i< a.size() && res != 1; i++){
        res = gcd(a.at(i), res);
    }
    return res;
}

//2値の最小公倍数
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

//n個の最小公倍数
int nlcm(vector<int> numbers){
    int res;
    res = numbers.at(0);
    for(int i = 0; i< numbers.size();i++){
        res = lcm(res, numbers[i]);
    }
    return res;
}

//素数判定O(√N)
bool isPrime(int x){
    if(x<2) return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(int i = 3; i*i <= x; i+=2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(int n){
    int res = 0;
    while(n>0){
        res += n%10;
        n /= 10;
    }
    return res;
}

//約数全列挙
vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

//繰り返し自乗法
long long int mod_pow(long long int x, long long int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

//文字列の中で何回文字が出てきたのかを数える
int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c); //覚える
}

int main(){
    ll k; cin >> k;
    string num = "7";
    ll ans = 1;

    while(stoi(num)<k){
        num.push_back('7');
        ans++;
    }
 
    ll now = stoi(num), buf = ans;
    while(now%k != 0 && ans - buf != k){
        now = now%k*10 + 7;
        ans++;
    }
    if(ans - buf == k) cout << -1 << endl;
    else cout << ans << endl;
}

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

vector<vector<int> > a;
vector<bool> b;
map<pair<int, int>, int> m;
int ans = 0;

void dfs(int i, int c){
	int cnt = 0;
	for(unsigned j = 0; j < a[i].size(); j++){
		if(b[a[i][j]]) continue;
		++cnt; if(cnt == c) ++cnt;
		b[a[i][j]] = 1;
		m[{i, a[i][j]}] = cnt;
		dfs(a[i][j], cnt);
	}
	ans = max(ans, cnt);
}
 
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	a.resize(n + 1);
	vector<pair<int, int> > p;
	for(int i = 0; i < n - 1; i++){
		int u, v; cin >> u >> v;
		a[u].push_back(v);
		a[v].push_back(u);
		p.push_back({u, v});
	}
	b.resize(n + 1, 0); b[1] = 1;
	dfs(1, 0);
	cout << ans << '\n';
	for(auto i : p){
		int u = i.first, v = i.second;
		if(!m[{u, v}]) swap(u, v);
		cout << m[{u, v}] << '\n';
	}
	cout << '\n';
}

Measured memory_bytes: 14972
#include<stdio.h>
int main(){
  int a,b,c,d,e;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a<=b)e=e+a;
  else e=e+b;
  
  if(c<=d)e=e+c;
  else e=e+d;
  
  printf("%d",e);
  return 0;
}

Measured memory_bytes: 128
function Main(s){
  s = s.split(" ").map(a=>+a);
  var n = s[0];
  var a = g(s[1]);
  var b = g(s[2]);
  var ans = [];
  var k = n * n;
  for(var i = 0; i < 2 * n; i++)
  for(var j = 0; j < 2 * n; j++){
    if(f(a,i,j) && f(b,i,j))ans[--k] = i + " " + j;
    if(!k){console.log(ans.join("\n"));return;}
  }
}
function g(n){
  var s = 1;
  while((n & 3) === 0){
    s <<= 1;
    n >>>= 2;
  }
  return [s, n & 1];
}
function f(s,y,x){
  y = Math.floor(y / s[0]);
  if(!s[1])return !(y&1);
  x = Math.floor(x / s[0]);
  return !(x+y&1);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 19916
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(sum(a[:k]))

Measured memory_bytes: 62216
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
string s, t;
set<string> S;

void Work()
{
    int lens = s.size();
    int lent = t.size();
    for(int i = 0; i < lens; i++)
    {
        if(s[i] == '?' || s[i] == t[0])//如果字符相等
        {
            string tmp = s;              //构造判断子串之前的字符
            for(int j = 0; j < i; j++)
                if(tmp[j] == '?')
                    tmp[j] ='a';    
            bool can = false;
            for(int j = 0; j < lent; j++)    //判断是否为子串
            {

                if(tmp[i+j]!= '?' && tmp[i+j] != t[j])  //字符匹配
                    break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can)
            {
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';//处理匹配后的字符
                S.insert(tmp);  //压入容器
            }
        }
    }
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << *S.begin() << endl;
}
int main()
{
    cin >> s >> t;
    Work();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, s, n) for(int i = s; i < n; i++)
#define rRep(i, n) for(int i = n - 1; i >= 0; i--)
#define pii pair<int, int>
#define vii vector<pair<int, int>>
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define endl "\n"

const int MAXN = 2e5 + 10;
vi adj[MAXN];

int32_t main() {
	FAST
	//ofstream fout ("test.out");
    //ifstream fin ("test.in");
 	int n, k;
 	cin >> n >> k;

 	REP(i, 0, n)  {
 		int x;
 		cin >> x;
 		adj[i].pb(x - 1);
 	} 

 	vector<bool> vis(n, false);
 	vi path;
 	path.pb(0);
 	while(!vis[path[path.size() - 1]]) {
 		vis[path[path.size() - 1]] = true;
 		path.pb(adj[path[path.size() - 1]][0]);
 	}
 	int rep = path[path.size() - 1];
 	vi fin;
 	int ind = -1;
 	REP(i, 1, path.size()) {
 		fin.pb(path[i - 1]);
 		if(path[i - 1] == rep) {
 			ind = i - 1;
 		}
 	}
 	if(k <= ind) {
 		cout << fin[k] + 1 << endl;
 		return 0;
 	}
 	k -= ind;
 	k %= (fin.size() - ind);
 	cout << fin[ind + k] + 1 << endl;

}

Measured memory_bytes: 18856
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080

using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;
ll N,K;
ll ans=0;
int main(){
	cin>>N>>K;
	for(ll x=K+1;x<=N;x++){
		ll hoge=N%x;
		ans=ans+(N/x)*(x-K)+max((ll)0,hoge-K+1);
		if(K==0)ans--;
		//cout<<(N/x)*(x-K)+max((ll)0,hoge-K+1)<<endl;
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t LL;
LL com(LL m,LL j)
{
  switch(j)
  {
    case 1:return m;
    case 2:return m*(m-1)/2;
    case 3:return m*(m-1)*(m-2)/6;
    default:return 0;
  }
}
string S;
int N,K;
LL f(int i,int k,int under)
{
  if(k==0)return 1;
  if(i==N)return 0;
  if(under)return com(N-i,k)*pow(9,k);
  else
  {
    if(S.at(i)=='0')return f(i+1,k,false);
    else return f(i+1,k,true)+f(i+1,k-1,true)*(S.at(i)-'1')+f(i+1,k-1,false);
  }
}
int main()
{
  cin>>S>>K;
  N=S.size();
  cout<<f(0,K,false)<<endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    ARemainingBalls solver = new ARemainingBalls();
    solver.solve(1, in, out);
    out.close();
  }

  static class ARemainingBalls {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      String s = in.next();
      String t = in.next();
      int si = in.nextInt();
      int ti = in.nextInt();
      String u = in.next();
      out.println(s.equals(u) ? --si + " " + ti : si + " " + --ti);
    }

  }
}



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


int cnt[26];

int main(){
	int num =0;
	string s;

	while(getline(cin,s), s != ""){

	for(int i=0; i < s.length(); i++){
		if(islower(s[i])){
			num = s[i] - 'a';
			if(num>=0)
				cnt[num]++;
		}
		else{
			s[i]=tolower(s[i]);
			num = s[i] - 'a';
			if(num>=0)
				cnt[num]++;
		}
	}
}
	int j=97;
	for(int i=0; i<26; i++){
		printf("%c"" : ""%d\n", j,cnt[i]);
		j++;
	}
	return 0;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    long ans = 0;
    if(n > 1){
        ans = k*pow(k-1,n-1);
    }
    else{
        ans = k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a;
int b;
int d;
int r;
double f;
scanf("%d %d",&a,&b);
d=a/b;
r=a%b;
f=1.0*a/b;
printf("%d %d %.8lf\n",d,r,f);
return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	string s,t;
	cin>>s>>t;
	// cout<<s.length()<<endl;
	if(t.compare(0,s.length(),s)==0)
		cout<<"Yes\n";
	else cout<<"No\n";

	return 0;
}

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

ll leng[51];
ll pat[51];

ll res(ll n, ll x) {
  if (n == 0 && x == 1) return 1;
  if (n == 0 && x == 0) return 0;
  if (x <= 1) {
    return 0;
  } else if (x <= 1+leng[n-1]) {
    return res(n-1, x-1);
  } else {
    return pat[n-1] + 1 + res(n-1, x-2-leng[n-1]);
  }
}

int main() {
  cin >> N >> X;
  leng[0] = 1; pat[0] = 1;
  for (ll i = 1; i <= N; i++) {
    leng[i] = 2*leng[i-1]+3;
    pat[i] = 2*pat[i-1]+1;
  }
  cout << res(N, X) << endl;
}

Measured memory_bytes: 256
H,W,A,B = map(int,input().split())


class Combination:
    """
  O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
  n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
  使用例：
  comb = Combination(1000000)
  print(comb(5, 3))  # 10
  """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv

comb = Combination(1000000)
MOD = 10**9+7
ans = 0
for i in range(B,W):
    ans += comb(H-A-1+i,i)*comb(A-1+W-1-i,A-1)
    ans %= MOD
    #print(comb(H-A-1+i,i)*comb(A-1+W-1-i,A-1))
print(ans)




Measured memory_bytes: 121848
fun main(args: Array<String>) {
    val n:String? = readLine()
    val monstersInput:String? = readLine()
    val saversInput:String? = readLine()

    if (n == null || monstersInput == null || saversInput == null) return

    val monsters:List<String> = monstersInput.trim().split(" ")
    val savers:List<String> = saversInput.trim().split(" ")

    var count:Long = 0
    var nextAttack:Long = 0
    for (i in savers.indices) {
        var monster = monsters[i].toLong()
        val saver = savers[i].toLong()
        if (nextAttack > 0) {
            if (monster < nextAttack) {
                count += monster
                monster = 0
            } else {
                count += nextAttack
                monster -= nextAttack
            }
        }

        if (monster < saver) {
            count += monster
            nextAttack = saver - monster
        } else {
            count += saver
            nextAttack = 0
        }
    }

    if (nextAttack > 0) {
        val lastMonster = monsters.last().toLong()
        count += if (lastMonster < nextAttack) lastMonster else nextAttack
    }

    println(count)

}

Measured memory_bytes: 81848
/*
           Nothing is absolute.
     This is the only absolute truth.
*/

#include<bits/stdc++.h>

using namespace std;

using ull = unsigned long long;
using ll = long long;

#define READ freopen("in.txt", "r", stdin)
#define ROUT freopen("out.txt", "w", stdout)
#define pb push_back
#define endl '\n'

void fasterIO()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

void fileIO()
{
    READ;
    //ROUT;
}

int main()
{
    //fileIO();
    fasterIO();
    //Siv();

    int l;
    cin>>l;

    double d = (double)l;

    cout<<fixed<<setprecision(12)<<(d/3)*(d/3)*(d/3)<<endl;

    exit(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main(void){
  double x,h;
  while(cin >> x >> h,x&&h)
    printf("%.6f\n",x*x+sqrt((x*x)/4+h*h)*x*2);

  return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
//const int mod = 1000000007;
const ll mod = INF / 1000;

int main() {
    char a, b;
    cin >> a >> b;

    bool t = true;
    if (a == 'D') t = false;

    if (b == 'D') t = !t;

    cout << (t ? 'H' : 'D') << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;



#define rep(i, N) for(int i = 0;i < N;i++)
	typedef long long ll;

	using namespace std;

	const ll MOD = 1e9 + 7;

	int main(void) {
		int N; cin >> N;
		ll ans = 1;

		for (int i = 1; i <= N; i++) {
			ans = (ans * i) % MOD;
		}

		cout << ans << endl;

		return 0;
	}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    ll n;
    cin>>n;
    V<pair<ll,ll>> a(n);
    rep(i,n){
        ll aa;
        cin>>aa;
        a[i]=make_pair(aa,i);
    }
    sort(all(a));
    set<ll> pos,neg;
    ll ans=0;
    for(int i=0;i<n;i++){
        if(i==0){
            ans+=(a[i].sc+1)*(n-a[i].sc);
        }else{
            if(a[i].sc<*begin(pos)){
                ans+=a[i].ft*(*begin(pos)-a[i].sc)*(a[i].sc+1);
            }else if(a[i].sc>*rbegin(pos)){
                ans+=a[i].ft*(n-a[i].sc)*(a[i].sc-*rbegin(pos));
            }else{
                ll u=a[i].sc+*neg.ub(-a[i].sc);
                ll v=*pos.ub(a[i].sc)-a[i].sc;
                ans+=a[i].ft*(u*v);
            }
        }
        pos.insert(a[i].sc);
        neg.insert(-a[i].sc);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 22652
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	fmt.Println(answer(a, b))
}

func answer(a int, b int) int {
	apfs := PrimeFactors(a)
	bpfs := PrimeFactors(b)

	m := make(map[int]bool)

	for _, v1 := range apfs {
		if _, ok := m[v1]; !ok {
			for _, v2 := range bpfs {
				if v1 == v2 {
					m[v1] = true
					break
				}
			}
		}
	}

	return len(m)+1
}

// Get all prime factors of a given number n
func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

Measured memory_bytes: 512
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int n = s.size();
	ll cnt = 0, ans = 0;
	int prev = -1;
	RREP(i, n) {
		if (s[i] == 'A') {
			if (prev == 'B')ans += cnt;
			else {

				cnt = 0;
			}
			if (cnt == 0)	prev = -1;
		}
		else if (s[i] == 'B') {
			if (prev == 'C') {
				cnt++;
				prev = 'B';
			}
			else {
				cnt = 0;
				prev = 'B';
			}
		}
		else {
			if (prev != 'C') {
				prev = 'C';
			}
			else {
				cnt = 0;
			}
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 720
fun main(args: Array<String>) {
    val n = readInputLine().toLong()

    for (i in 1 until Int.MAX_VALUE) {
        if (i * i > n) {
            println((i - 1) * (i - 1))
            break
        }
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 33812
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
double eps=1e-8;
ll mod=1e9+7;
ll inf=1e9;
priority_queue<P,vector<P>,greater<P> > pq;

template <typename T>
int Count(const vector<T> &v, T l,T r){
  //counting [l,r]
  auto L = lower_bound(v.begin(), v.end() , l );
  auto R = upper_bound(v.begin(), v.end(), r );
  // [l,r) change upper -> lower

  return R-L;
}

int main(){
  int h,w,a[100][100];
  cin>>h>>w;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)cin>>a[i][j];
  int ans=1e9;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      int cnt=0;
      for(int m=0;m<h;m++)
	for(int n=0;n<w;n++)cnt+=min(abs(i-m),abs(j-n))*a[m][n];
      ans=min(ans,cnt);
    }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3108
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val t = (1..n).map { sc.nextInt() }
    val sumT = t.sum()

    val m = sc.nextInt()
    repeat(m) {
        val p = sc.nextInt() - 1
        val x = sc.nextInt()
        println(sumT - t[p] + x)
    }
}

Measured memory_bytes: 31392
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
int main(){
    cout << fixed << setprecision(10);
    int n,m;
    set<string> ss;
    int state = 1;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        ss.insert(s);
    }
    cin >> m;
    rep(i,m){
        string s;
        cin >> s;
        if(ss.find(s) != ss.end()){
            if(state == 1) cout << "Opened by " << s << endl;
            else cout << "Closed by " << s << endl;
            state ^= 1;
        }else cout << "Unknown " << s << endl;
    }
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int>data(n);
  for(int i=0;i<n;i++){
    cin >> data[i];
  }
  sort(data.begin(),data.end());
  vector<int>ddata;
  for(int i=0;i < min(4,n);i++){
    for(int j=0;j< min(4,n);j++){
      if(i==j) continue;
      int left=data[i],right=data[j];
      while(right!=0) right/=10,left*=10;
      ddata.push_back(left+data[j]);
    }
  }
  sort(ddata.begin(),ddata.end());
  cout << ddata[2] << endl;
}



Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll n,l,k;
vp in(n);
ll calc(ll q,ll T){
	if(q<0||q>=n)return 0;
	return (ll)(in[q].first*2+(T-1)*in[q].second)*T/2;
}
ll f(ll a,ll t,ll e){
//	cout<<a<<" "<<t<<endl;
	ll T=k-e*l-t;
	ll co=e*l;
	ll sum=0;
	ll q=a+e;
	if(t<0||t>l)return 0;
	if(T<0||T>l)return 0;
	sum+=calc(q,T);
//	cout<<a<<" "<<t<<" "<<sum<<endl;
	sum+=calc(a-1,l)-calc(a-1,l-t);
//	cout<<a<<" "<<t<<" "<<sum<<endl;
	return sum;
}
int main(){
	cin>>n>>l>>k;
	in=vp(n);
	rep(i,n)cin>>in[i].first>>in[i].second;
	vi su(n+1);
	rep(i,n){
		su[i+1]=(in[i].first*2+(l-1)*in[i].second)*l/2;
	}
	rep(i,n)su[i+1]+=su[i];
	ll out=0;
	ll e=k/l;
	rep(q,n-e+1){
//		cout<<su[q+(k-1)/l]-su[q]<<endl;
		ll sum=su[q+e]-su[q];
		ll L=0,r=k-e*l+1;
//		cout<<L<<" "<<r<<endl;
		while(r-L>10){
			ll h1=L+(r-L)/3;
			ll h2=L+(r-L)/3*2;
			ll t1=f(q,h1,e);
			ll t2=f(q,h2,e);
			if(t1>t2)r=h2;
			else L=h1;
		}
		loop(i,max(0ll,L-100),min(k-e*l+1,L+100)){
			out=max(out,sum+f(q,i,e));
		}
	}
	if(k-(k/l-1)*l<2*l){
		e=k/l-1;
		rep(q,n-e+1){
	//		cout<<su[q+(k-1)/l]-su[q]<<endl;
			ll sum=su[q+e]-su[q];
			ll L=0,r=k-e*l+1;
	//		cout<<L<<" "<<r<<endl;
			while(r-L>10){
				ll h1=L+(r-L)/3;
				ll h2=L+(r-L)/3*2;
				ll t1=f(q,h1,e);
				ll t2=f(q,h2,e);
				if(t1>t2)r=h2;
				else L=h1;
			}
			loop(i,max(0ll,L-100),min(k-e*l+1,L+100)){
				out=max(out,sum+f(q,i,e));
			}
		}
	}
	cout<<out<<endl;
}

Measured memory_bytes: 5900
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

S = input()
N = len(S)+1
L = [0]*N
R = [0]*N
for i in range(N-1):
    L[i+1] = L[i]+1 if S[i]=='<' else 0
for i in range(N-2,-1,-1):
    R[i] = R[i+1]+1 if S[i]=='>' else 0
ans = [max(l,r) for l,r in zip(L,R)]
print(sum(ans))

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

void main_()
{
    ll N;
    vector<ll> As;
    cin >> N;
    copy_n(istream_iterator<ll>(cin), N, back_inserter(As));
    vector<ll> ball_counts(2 * 100'000 + 1);
    for (auto a : As) {
        ball_counts[a]++;
    }
    auto mc2 = [](ll m) { return (m < 2) ? 0 : m * (m - 1) / 2; };
    auto total = accumulate(begin(ball_counts), end(ball_counts), 0LL,
        [mc2](auto acc, auto n) {
            return acc + mc2(n);
        });

    for (auto a : As) {
        auto count = ball_counts[a];
        auto ans = (count < 2) ? total : total - (count - 1);
        cout << ans << "\n";
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 5872
#include <stdio.h>

int main() {
    char s[5];
    scanf("%s", s);

    if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    int a[n];

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

   for(long long i=0;i<n-1;i++){

       cout << a[n-i-1] <<" ";

   }
    cout << a[0] << endl;
    return 0;

}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define RI register int

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc();
  while (ch < '0' || ch > '9') ch = gc();
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
}

int const MAXN = 2005;
int vis[MAXN], a[MAXN], In[MAXN], Dfn[MAXN], cnt;
vector <int> G[MAXN];
priority_queue <int> q;

inline int gcd(int x, int y) {
  int t;
  while (y) t = x % y, x = y, y = t;
  return x;
}

void Dfs(int now) {
  Dfn[now] = ++cnt;
  vis[now] = 1;
  vector <int> :: iterator it = G[now].begin(), en = G[now].end();
  for (; it != en; ++it) {
    if (Dfn[now] < Dfn[*it]) ++In[*it];
    if (!vis[*it]) ++In[*it], Dfs(*it);
  }
}

int main() {
 // freopen("rearranging.in", "r", stdin);
 // freopen("rearranging.out", "w", stdout);
  int n; read(n);
  for (RI i = 1; i <= n; ++i) read(a[i]);
  sort(a + 1, a + 1 + n);
  for (RI i = 1; i <= n; ++i)
    for (RI j = i + 1; j <= n; ++j)
      if (gcd(a[i], a[j]) != 1)
        G[i].push_back(j), G[j].push_back(i);
  for (RI i = 1; i <= n; ++i)
    sort(G[i].begin(), G[i].end());
  for (RI i = 1; i <= n; ++i)
    if (!vis[i]) Dfs(i);
  for (RI i = 1; i <= n; ++i) if (!In[i]) q.push(i);
  while (!q.empty()) {
    int t = q.top(); q.pop();
    printf("%d ", a[t]);
    vector <int> :: iterator it = G[t].begin(), en = G[t].end();
    for (; it != en; ++it)
      if (Dfn[t] < Dfn[*it]) {
        --In[*it];
        if (!In[*it]) q.push(*it);
      }
  }
  return 0;
}


Measured memory_bytes: 17664
//https://atcoder.jp/contests/abc134
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e6 + 5;
const double E = 1e-9;

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

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*ifstream cin("input.txt");
	ofstream cout("output.txt");*/
	int n;
	cin >> n;
	vector<int> a(n), b;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	b = a;
	sort(b.begin(), b.end(), greater<int>());
	for (int i = 0; i < n; i++)
	{
		if (a[i] == b[0])
			cout << b[1] << "\n";
		else
			cout << b[0] << "\n";
	}
	return 0;
}
//04-08-2020 09:49:23
//------------------------------------------------------------------------------

Measured memory_bytes: 4716
r, c = map(int, input().split())

mat = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
    mat[i] = list(map(int, input().split()))

for i in range(r):
    s = sum(mat[i])
    mat[i].append(s)

for j in range(c):
    s = 0
    for i in range(r):
        s += mat[i][j]
    mat[r][j] = s

mat[r][c] = (sum(mat[r]))

for i in range(r+1):
    for j in range(c+1):
        if j == c:
            print(str(mat[i][j]))
        else:
            print(str(mat[i][j]) + " ", end="")



Measured memory_bytes: 6212
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

struct DSU {
	vector<int> p, s;
	vector<bool> kek;
	DSU(int n) : p(n), s(n, 1), kek(n) { iota(p.begin(), p.end(), 0); }
	int get(int v) {
		return (v == p[v] ? v : p[v] = get(p[v]));
	}
	bool unite(int u, int v) {
		u = get(u);
		v = get(v);
		if (u != v) {
			if (kek[u] && kek[v]) {
				return false;
			}
			if (s[u] < s[v]) {
				swap(u, v);
			}
			s[u] += s[v];
			p[v] = u;
			kek[u] = kek[u] | kek[v];
			return true;
		}
		else if (!kek[u]) {
			kek[u] = true;
			return true;
		}
		return false;
	}
};

struct Edge {
	int u, v, w;
	bool operator < (const Edge& o) const {
		return (w > o.w);
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, h, w;
	cin >> n >> h >> w;
	vector<Edge> es;
	for (int i = 0; i < n; i++) {
		int r, c, w;
		cin >> r >> c >> w;
		--r; --c;
		es.push_back({ r, h + c, w });
	}
	sort(es.begin(), es.end());
	DSU dsu(h + w);
	long long ans = 0;
	for (auto& e : es) {
		if (dsu.unite(e.u, e.v)) {
			ans += e.w;
		}
	}
	cout << ans;
}


Measured memory_bytes: 3188
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()

    return '{:0.9f}'.format(n / m)



print(main())




Measured memory_bytes: 5464
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define s(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;

int main() {
	int x = 0, y = 0, z = 0;
	string str;
	cin >> str;
	rep(i, 3) {
		if (str[i] == 'a')x++;
		if (str[i] == 'b')y++;
		if (str[i] == 'c')z++;
	}
	if (x == 1 && y == 1 && z == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
def spaceinput():
    s=input()
    if len(s)==0:
        return False

    return list(map(int,s.split(" ")))


N=int(input())
a=sorted(spaceinput(),reverse=True)

k=0
count=0
N=len(a)
while True:
    #print(a)
    s=int(a[k]/N)
    a[k]-=N*s
    for j in range(N):
        if k!=j:
            a[j]+=s
    count+=s
    if max(a)<N:
        break
    k=(k+1)%N


print(count)


Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

var comb [][]int

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	a, _ := strconv.Atoi(stringLineScan())
	b, _ := strconv.Atoi(stringLineScan())
	x := a / 4 * 4
	y := b / 4 * 4
	ans := 0
	for i := x; i < a; i++ {
		ans ^= i
	}
	for i := y; i <= b; i++ {
		ans ^= i
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<stdio.h>

int linearSearch(int,int *,int);

int main()
{
  int i,j,n,q,S[10000],T[10000];

  scanf("%d",&n);
  for(i = 0;i < n;i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);
  for(i = 0;i < q;i++)
    scanf("%d",&T[i]);

  i = 0;
  
  for(j = 0;j < q;j++)
    {
      if(linearSearch(n,S,T[j]) == 1)
	i++;
    }
  printf("%d\n",i);
      
  return 0;
}

  int linearSearch(int n,int *A,int B)
{
  int i;
  
  for(i = 0;i < n;i++)
    {
      if(A[i] == B)
	{
	  return 1;
	  break;
	}
    }
  return 0;
}
      



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

ll dp[55][2];

int main() {
  ll n,k;
  cin >> n >> k;

  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<ll> cnt(50);
  for (int i = 0; i < n; i++) {
    ll x = a[i];
    for(int bit = 0; bit < 50; bit++) {
      if(1 & (x >> bit)) cnt[bit]++;
    }
  }
  memset(dp, -1 ,sizeof(dp));
  dp[50][0] = 0;
  for (int i = 49; i >= 0; i--) {
    ll p = (1LL << i);
    bool flag = false;
    if(1 & (k >> i)) flag = true;
    ll val0 = p * cnt[i]; // value when i-th bit is 0
    ll val1 = p * (n - cnt[i]);

    // 0: tight 1: loose
    // tight to tight
    if(dp[i + 1][0] != -1) {
      if(flag) dp[i][0] = max(dp[i][0] , dp[i + 1][0] + val1);
      else dp[i][0] = max(dp[i][0] , dp[i + 1][0] + val0);
    }
    // tight to loose
    if(dp[i + 1][0] != -1) {
      if(flag) dp[i][1] = max(dp[i][1] , dp[i + 1][0] + val0);
    }

    // loose to loose
    if(dp[i + 1][1] != -1) {
      dp[i][1] = max(dp[i][1], dp[i + 1][1] + val1);
      dp[i][1] = max(dp[i][1], dp[i + 1][1] + val0);
    }
  }
  cout << max(dp[0][0], dp[0][1]) << '\n';
}

Measured memory_bytes: 1024
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

ll A[100010] = {};

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

  int N, T;
  cin >> N >> T;
  REP(i, N) {
    cin >> A[i];
  }

  ll ma = A[1] - A[0];
  ll mi = A[0];
  int mac = 0;
  int c = 0;
  for (int i = 1; i < N; i++) {
    if (A[i] - mi > ma) {
      ma = A[i] - mi;
      c = 1;
    } else if (A[i] - mi == ma) {
      c++;
    }
    // cout << mi << " " << A[i] << " " << ma << " " << c << endl;
    mi = min(mi, A[i]);
    mac = max(mac, c);
  }

  cout << mac << endl;
  return 0;
}


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

int main() {
	int A;
	string op;
	int B;
	cin >> A;
	cin >> op;
	cin >> B;
	if (op == "+") {
		cout << A + B << endl;
	}
	else if (op == "-") {
		cout << A - B << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

int main()
{

    vector<pair<ll, ll> > v; 

    int n;
    cin >> n;

    ll max_sum = -1*INT64_MAX;
    ll max_diff = -1*INT64_MAX;
    ll min_sum = INT64_MAX;
    ll min_diff = INT64_MAX;
    
    pair<ll,ll> mxsm;
    pair<ll,ll> mnsm;
    pair<ll,ll> mxdf;
    pair<ll,ll> mndf;
    
    ll x,y;
    for(int i=0;i<n;i++)
    {
        cin >> x >> y;

        if(x+y > max_sum)
        {
            mxsm = mp(x,y);
            max_sum = x+y;
        }

        if(x-y > max_diff)
        {
            mxdf = mp(x,y);
            max_diff = x-y;
        }
        if(x+y < min_sum)
        {
            mnsm = mp(x,y);
            min_sum = x+y;
        }
        if(x-y < min_diff)
        {
            mndf = mp(x,y);
            min_diff = x-y;
        }

    }
    ll ans = -1*INT64_MAX;
    /*
    v.push_back(mxsm);
    v.push_back(mxdf);
    v.push_back(mnsm);
    v.push_back(mndf);

    sort(v.begin(), v.end());
    
    
    
    for(int i=0;i<4;i++)
    {
        for(int j = i+1;j<4;j++)
        {
            if(v[i].S <= v[j].S)
            {
                ans = max(ans, v[j].F + v[j].S - v[i].F - v[i].S);
            }
            else
            {
                ans = max(ans, v[j].F - v[j].S - v[i].F + v[i].S);
            }
        
        }
    }*/

    ans = max( abs(mxsm.F - mnsm.F) + abs(mxsm.S - mnsm.S) ,   abs(mxdf.F - mndf.F) + abs(mxdf.S - mndf.S)    );


    cout << ans << endl;





}

Measured memory_bytes: 3616
u, s, e, w, n, d = list(map(int, input().split()))
insts = input()
for inst in insts:
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w
print(u)

Measured memory_bytes: 7676
n = int(input())
s = [input() for i in range(n)]

countM=0
countA=0
countR=0
countC=0
countH=0

for i in range(n):
  if s[i][0]=="M":
    countM+=1
  if s[i][0]=="A":
    countA+=1
  if s[i][0]=="R":
    countR+=1
  if s[i][0]=="C":
    countC+=1
  if s[i][0]=="H":
    countH+=1
ans = countM*countA*countR + countM*countA*countC + countM*countA*countH 
ans = ans + countM*countR*countC + countM*countR*countH +countM*countC*countH
ans = ans + countA*countR*countC +countA*countR*countH + countA*countC*countH + countR*countC*countH
print(ans)

Measured memory_bytes: 9772