akhauriyash/Code-Regression huggingface dataset:
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>

using namespace std;

typedef struct datum_name {
	int x;
	int y;
	int whosay;
	bool operator==(const datum_name& data) const
	{
		return (x == data.x && y == data.y);
	}
} datum;


bool cmp_who(const datum& left, const datum& right) {
	return left.whosay < right.whosay;
}

typedef vector<vector<int>> Graph;
vector<bool> seen;
vector<int> depth;

void dfs(const Graph& G, int v, int depth_num) {
	seen[v] = true;
	depth[v] = depth_num;

	for (auto next_v : G[v]) {
		if (seen[next_v]) continue;
		dfs(G, next_v, depth_num+1); //再帰探索
	}
}

vector<bool> seen2;
vector<int> depth2;
void dfs2(const Graph& G, int v, int depth_num) {
	seen2[v] = true;
	depth2[v] = depth_num;

	for (auto next_v : G[v]) {
		if (seen2[next_v]) continue;
		dfs2(G, next_v, depth_num+1); //再帰探索
	}
}

int main()
{
	int N, u, v;
	cin >> N >> u >> v;

	Graph graph;
	graph.resize(N);
	for (int i = 0; i < N - 1; i++) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		graph[tmp1-1].push_back(tmp2-1);
		graph[tmp2-1].push_back(tmp1-1);
	}
	seen.resize(N);
	depth.resize(N);
	seen2.resize(N);
	depth2.resize(N);

	dfs(graph, u-1, 0);
	dfs2(graph, v-1, 0);

	int max_depth = 0;
	for (int i = 0; i < N; i++) {
		if (depth[i] < depth2[i]) {
			max_depth = max(max_depth, depth2[i]);
		}
	}

	cout << max_depth-1 << endl;

	return 0;

}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 10368
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let v:Vec<i32> = procon_read();
	let a = v[0];
	println!("{}", n*n-a);
}

Measured memory_bytes: 4352
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cassert>
using namespace std;

char s[5000];
int len;

int length(int const k, int const l, int const r){
    int cur = 0, res = 0, p = l;
    while(s[p] && p < r){
        if(isalpha(s[p])){
            while(isalpha(s[p])){
                if(cur == k) throw s[p];
                res++;
                p++;
                cur++;
            }
        } else if(isdigit(s[p])){
            int mul = 0;
            while(isdigit(s[p])){
                mul = mul * 10 + s[p] - '0';
                p++;
            }
            int d = 0, i = p++;
            while(1){
                if(s[i] == '(') d++;
                else if(s[i] == ')') d--;
                if(d == 0) break;
                i++;
            }
            int memo = -1;
            for(int j = 0; j < mul; j++){
                if(memo != -1 && cur + memo < k){
                    res += memo;
                    cur += memo;
                } else {
                    int x = length(k - cur, p, i);
                    res += x;
                    cur += x;
                    memo = x;
                }
            }
            p = i + 1;
        }
    }
    return res;
}

int main(){
    static char t[5000];
    int k;
    while(scanf("%s%d",t,&k), t[0] != '0'){
        int tlen = strlen(t);
        len = 0;
        for(int i = 0; i < tlen; i++){
            if(i > 0 && isdigit(t[i - 1]) && isalpha(t[i])){
                s[len++] = '(';
                s[len++] = t[i];
                s[len++] = ')';
            } else {
                s[len++] = t[i];
            }
        }
        s[len] = 0;
        try{
            length(k, 0, len);
            putchar('0');putchar('\n');
        } catch (char e) {
            putchar(e);putchar('\n');
        }
    }
}

Measured memory_bytes: 1088
#include <bits/stdc++.h>
#define INF 2e9+7
using namespace std;
using pii=pair<int,int>;
using ll=long long int;

int n; string s;
ll ans;
vector<int> pos[3];

int mid(int a,int b,int c) {
    int aa[3]; aa[0]=a; aa[1]=b; aa[2]=c;
    sort(aa,aa+3);
    return aa[1];
}

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>s;
    /*for(int i=0;i<n-3;i++) {
        for(int j=i+1;j<n-1;j++) {
            for(int k=j+1;k<n;k++) {
                if(k-j==j-i) continue;
                if(s[i]==s[j] or s[j]==s[k] or s[i]==s[k]) continue;
                ans++;
            }
        }
    }
    cout<<ans<<endl;*/
    for(int i=0;i<n;i++) {
        if(s[i]=='R') pos[0].push_back(i);
        else if(s[i]=='G') pos[1].push_back(i);
        else pos[2].push_back(i);
    }
    int a,b;
    for(auto e1:pos[0]) {
        for(auto e2:pos[1]) {
            if(e1>e2) {
                a=e1; b=e2;
            }
            else {
                a=e2; b=e1;
            }
            int cur=a+a-b;
            if(binary_search(pos[2].begin(),pos[2].end(),cur)) ans+=pos[2].size()-1;
            else ans+=pos[2].size();

            if((a-b)%2==0 and binary_search(pos[2].begin(),pos[2].end(),a-(a-b)/2)) ans--;
            if(binary_search(pos[2].begin(),pos[2].end(),b-(a-b))) ans--;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100005;
struct Card
{
	char suit;
	int value;
	friend bool operator<(const Card& a, const Card& b)
	{
		return a.value < b.value;
	}
} card[N], t[N];
int partition(Card arr[], int p, int r)	//[p, r)????????????,????????????pivot??????
{
	int pivot = arr[r - 1].value;
	int i = p;
	for (int j = p; j < r - 1; ++j)
	{
		if (arr[j].value <= pivot)
		{
			swap(arr[i++], arr[j]);
		}
	}
	swap(arr[i], arr[r - 1]);
	return i;
}

void q_sort(Card arr[], int l, int r)
{
	if (l + 1 < r)
	{
		int t = partition(arr, l, r);
		q_sort(arr, l, t);
		q_sort(arr, t, r);
	}
}

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> card[i].suit >> card[i].value;
	memcpy(t, card, sizeof(Card) * n);
	q_sort(card, 0, n);
	stable_sort(t, t + n);
	bool flag = true;
	for (int i = 0; i < n; ++i)
	{
		if (card[i].suit != t[i].suit)
		{
			flag = false;
			break;
		}
	}
	if (flag)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;

	for (int i = 0; i < n; ++i)
		cout << card[i].suit << ' ' << card[i].value << endl;

	return 0;
}

Measured memory_bytes: 4712
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n;

signed main() {
	cin >> n;
	cout << (n/2) * ((n+1)/2) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
#define rep(x,y) for(x=0;x<(y);++x)
void in();
void solve();
int bod[14];
int main()
{
	int t;
	cin>>t;
	int ti;
	rep(ti,t)
	{
		in();
		solve();
	} 
	return 0;
}
void in()
{
	int i;
	rep(i,10)
	{
		cin>>bod[i];
	}
}
void solve()
{
	int l=0,r=0,u;
	int le[11],ri[11];
	for(u=0;u<10;++u)
	{
		if(0==l)
		{
			le[0]=bod[u];
			++l;
		}
		else if(bod[u]>le[l-1])
		{
			if(0==r||le[l-1]>ri[r-1])
			{
				le[l]=bod[u];
				++l;
			}
			else if(bod[u]>ri[r-1])
			{
				ri[r]=bod[u];
				++r;
			}
		}
		else if(0==r||bod[u]>ri[r-1])
		{
			ri[r]=bod[u];
			++r;
		}
		else
		{
			cout<<"NO\n";
			return;
		}
	}
	cout<<"YES\n";
}

Measured memory_bytes: 1120
#include<cstdio>
#include<string>
main(){
        using namespace std;
        string lv[8] = {"AAA","AA","A","B","C","D","E","NA"};
        double ind1,ind2,lvd5[7] = {35.5,37.5,40.0,43.0,50.0,55.0,70.0};
        int i,j,lvd1[7] = {71,77,83,89,105,116,148};
        while(~scanf("%lf %lf",&ind1,&ind2)){
                i = j = -1;
                while(++i<7)if(ind1 < lvd5[i])break;
                while(++j<7)if(ind2 < lvd1[j])break;
                printf("%s\n", i <= j ? lv[j].c_str() : lv[i].c_str());
        }
        return 0;
}

Measured memory_bytes: 1068
//解説AC
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll kai[200001], inv[200001];
int n, k;
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
void init() {
  kai[0] = 1LL;
  for (ll i = 1LL; i <= 200000; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }
  inv[200000] = mod_pow(kai[200000], MOD - 2LL, MOD);
  for (ll i = 199999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
    inv[i] %= MOD;
  }
}

ll comb(ll r, ll c) {
  ll res;
  res = kai[r];
  res *= inv[c];
  res %= MOD;
  res *= inv[r - c];
  res %= MOD;
  return res;
}

pair<ll, ll> dp[200001];
ll ans[200001];
vector<int> g[200001];

void dfs(int x, int y) {
  ll size = 1LL;
  dp[x] = {1LL, 1LL};
  for (int i = 0; i < g[x].size(); i++) {
    if (g[x][i] != y) {
      dfs(g[x][i], x);
      dp[x].second += dp[g[x][i]].second;
      dp[x].first *= dp[g[x][i]].first;
      dp[x].first %= MOD;
      dp[x].first *= inv[dp[g[x][i]].second];
      dp[x].first %= MOD;
    }
  }
  dp[x].first *= kai[dp[x].second - 1];
  dp[x].first %= MOD;
}

void dfs2(int x, int y) {
  if (y != -1) {
    ans[x] = ans[y] * kai[n - dp[x].second - 1];
    ans[x] %= MOD;
    ans[x] *= kai[dp[x].second];
    ans[x] %= MOD;
    ans[x] *= inv[dp[x].second - 1];
    ans[x] %= MOD;
    ans[x] *= inv[n - dp[x].second];
    ans[x] %= MOD;
  }
  for (int i = 0; i < g[x].size(); i++) {
    if (g[x][i] != y) {
      dfs2(g[x][i], x);
    }
  }
}

int main() {
  int a, b;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  init();
  dfs(1, -1);
  ans[1] = dp[1].first;
  dfs2(1, -1);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 21748
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> p(n);
    rep(i,n) cin >> p[i].first >> p[i].second;
    double ans = 0;
    rep(i,n) {
        rep(j,n) {
            if(i == j) continue;
            double dx, dy;
            dx = p[i].first - p[j].first;
            dy = p[i].second - p[j].second;
            ans += sqrt(dx*dx + dy*dy);
        }
    }
    ans /= n;
    cout << fixed << setprecision(10);
    cout << ans << endl;

    return 0;
}


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

int main(){
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  
  if (a1+a2+a3 >= 22)
    cout << "bust" << endl;
  else
    cout << "win" << endl;
}

Measured memory_bytes: 3588
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 1) Console.WriteLine("Hello World");
            else if (n == 2)
            {
                int a = int.Parse(Console.ReadLine());
                int b = int.Parse(Console.ReadLine());
                Console.WriteLine(a + b);
            }
        }
    }
}


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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int main(){
    int n, m;
    cin >> n >> m;
    //vector<int> a;
    int sum = 0;
    rep(i, m){
        int day;
        cin >> day;
        //a.push_back(day);
        sum += day;
    }
    if(n>=sum){
        cout << n - sum << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n)   for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define ALL(x)     begin (x), end (x)
using namespace std;
constexpr int64_t MOD = 1000000007;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t n;
  int64_t k;
  cin >> n >> k;

  vector <int> a (n);
  rep (i, n) cin >> a [i];

  int64_t cnt = 0;
  rep (j, n) rep (i, j)
  {
    if (a [i] > a [j]) ++ cnt;
  }

  int64_t cnt2 = 0;
  rep (i, n) rep (j, n)
  {
    if (a [i] > a [j]) ++ cnt2;
  }
  auto k2 = (k * (k - 1) / 2) % MOD;
  auto ans = cnt * k % MOD;
  ans += cnt2 * k2 % MOD;
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    int n;
    string s;
    cin >> n >> s;

    bool flag = true;
    if(n%2!=0){
        flag = false;
    }else{
        for(int i=0; i< n/2; i++){
            if(s[i] != s[i+n/2]){
                flag = false;
                break;
            }
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
void main() {
    int[] tmp = readln.split.to!(int[]);
    int x1 = tmp[0], y1 = tmp[1], x2 = tmp[2], y2 = tmp[3];
    int xdiff = x2 - x1, ydiff = y2 - y1;
    int x3 = x2 - ydiff, y3 = y2 + xdiff;
    int x4 = x1 - ydiff, y4 = y1 + xdiff;
    writeln(x3, " ", y3, " ", x4, " ", y4);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  long long a;
  long double b;
  cin >> a >> b;
  long long ans = a*b*100;
  cout << ans/100 << endl;
  return 0;
}

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

int main() {
  int S, W;
  cin >> S >> W;
  if (S <= W) {
    cout << "unsafe" << endl;
    return 0;
  }

  cout << "safe" << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < a; i++) {
		if (!(s[i] >= '0' && s[i] <= '9')) {
			cout << "No" << endl;
			return 0;
		}
	}
		if (s[a] != '-') {
			cout << "No" << endl;
			return 0;
		}
		for (int i = a + 1; i < a + b; i++) {
			if (!(s[i] >= '0' && s[i] <= '9')) {
				cout << "No" << endl;
				return 0;
			}
		}
		
			cout << "Yes" << endl;

	return 0;
}

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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  int n,m;
  n = abs(x-a);
  m = abs(x-b);
  if(n < m) puts("A");
  else puts("B");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,k; cin >> n >> k;
    vint l,r;
    rep(i,n){
        int t;cin>>t;
        if(t>=0) r.pb(t);
        else l.pb(t*-1);
    }
    sort(all(l));
    int x=r.size(); int y=l.size();

    int res=INF;

    if(x==0){
        cout<<l[k-1]<<endl;
        return 0;
    }
    for(int i=min(x,k); i>=0; i--){
        int tmp=0;
        int right;
        if(i!=0) right=r[i-1];
        
        int rest=k-i;
        if(rest>y)continue;
        if(rest<=0){
            tmp=right;
            chmin(res,tmp);
            continue;
        }
        //cout<<rest<<' '<<r[i]<<' '<<l[rest]<<endl;
        int left=l[rest-1];
        //tmp+=l[rest-1]+r[i];
        tmp=min(right,left)*2+max(right,left);
        chmin(res,tmp);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4492
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
int cnt1[MAXN],cnt2[MAXN];
vector<P> v1,v2;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]); 
    for(int i=1;i<=n;i+=2) cnt1[a[i]]++;
    for(int i=2;i<=n;i+=2) cnt2[a[i]]++;
    for(int i=1;i<=100000;i++) v1.push_back(P(cnt1[i],i));
    for(int i=1;i<=100000;i++) v2.push_back(P(cnt2[i],i));
    sort(v1.begin(),v1.end(),greater<>());
    sort(v2.begin(),v2.end(),greater<>());
    int ans=v1[0].F+v2[0].F;
    if(v1[0].S==v2[0].S) ans=max(v1[0].F+v2[1].F,v1[1].F+v2[0].F);
    printf("%d\n",n-ans);
    return 0;
}



Measured memory_bytes: 3700
import numpy as np
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

count = np.zeros(10**5+1) 
for i in range(N):
  idx = A[i]
  count[idx] += 1

total = sum(A)
for i in range(Q):
  B, C = map(int, input().split())
  count_B = count[B]	# Bの個数
  count[B] = 0
  count[C] += count_B	# 数値を置き換えた時の、その数値の数
  total = total - int(count_B*B) + int(count_B*C)
  print(total)

Measured memory_bytes: 38848
#define ioFix ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

long long madd(long long x, long long y, long long modulo) {
  return (x + y) % modulo;
}

long long mmult(long long x, long long y, long long modulo) {
  return (x * y) % modulo;
}

long long mpow(long long base, long long exponent, long long modulo) {
  long long res = 1;
  for(int i = 0; i < exponent; i++)
    res = (res * base) % modulo;
  return res;
}

long long mfac(long long n, long long modulo) {
  long long res = 1;
  for(int i = 2; i <= n; i++)
    res = (res * i) % modulo;
  return res;
}

long long mcomb(long long n, long long k, long long modulo) {
  return mfac(n, modulo) / mmult(mfac(k, modulo), mfac(n-k, modulo), modulo);
}


#define PI (2.0 * acos(0.0))
#define INF (int)1e9
#define LINF (long long)1e18
#define EPS 1e-9

#define ll long long
#define ull unsigned long long

#define pii pair<int, int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define pcc pair<char, char>
#define pbb pair<bool, bool>

#define vi vector<int>
#define vvi vector<vector<int>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vvs vector<vector<string>>

#define REP(n) for(int xix = 0; xix < (n); xix++)
#define FOR(i, from, to) for(int (i) = from; (i) < (to); (i)++)
#define RANGE(i, from, to) for(int (i) = from; (i) <= (to); (i)++)
#define ALL(x) x.begin(),x.end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

#define fillArray(arr, val) std::fill(std::begin(arr), std::end(arr), (val))

#define pow2(x) ((x)*(x))
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

#define watch(x) cout << (#x) << " is " << (x) << endl
#define watchVector(v) { for(int xvx = 0; xvx < (v).size(); xvx++) { cout << (v)[xvx] << " "; } cout << endl; }
#define watchArray(arr, n) { for(int xax = 0; xax < (n); xax++) { cout << (arr)[xax] << " "; } cout << endl; }
#define watchMatrix(x, rows, cols) for(int r = 0; r < (rows); r++) { for(int c = 0; c < (cols); c++) { cout << (x)[r][c] << " "; } cout << endl; }



#include <bits/stdc++.h>
using namespace std;


int main() {
  ioFix;
  int N;
  cin >> N;
  int counter = 0;
  REP(4) {
    if(N % 10 == 2) counter++;
    N -= N % 10;
    N /= 10;
  }
  cout << counter << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n;

int main(){
  ll ans=0;
  cin >> n;
  vi a(n),b(200000,0),c(200000,0);
  REP(i,n){
    cin>>a[i];
    a[i]--;
    b[a[i]]++;
  }




  REP(i,200000){
    c[i]=b[i]*(b[i]-1)/2;
    ans+=c[i];
  }

  ll aans=0;
  REP(i,n){
    ll ii=a[i];
    aans=ans-c[ii]+(b[ii]-1)*(b[ii]-2)/2;
    
    cout<<aans<<endl;
  }

  


  return 0;
}

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int N;//人数
            int S;//必要な個数
            int i;
           //人数Nを入力
         N = int.Parse(Console.ReadLine());
         //必要な個数Sを求める
        //（合計を求めるアルゴリズム）
       S = 0;
       for (i=0;i<=N;i++)
 　　　{ S = S + i; }//SをI増やす　S+=Iでもよい
            //Sを出力（表示）
            Console.WriteLine(S);
                //入力待ちに
             Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n, ans[N];
vector<pair<int,int>> adj[N];

void dfs(int u, int par, int col) {
	int now = 1;
	for(auto v : adj[u]) {
		if(v.first == par) continue;
		if(now == col) now++;
		ans[v.second] = now;
		dfs(v.first, u, now);
		now++;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;	
	for(int i=0;i<n-1;i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].push_back(make_pair(v, i));
		adj[v].push_back(make_pair(u, i));
	}
	dfs(0, 0, -1);
	int mx = 0;
	for(int i=0;i<n-1;i++) mx=max(mx, ans[i]);
	cout << mx << endl;
	for(int i=0;i<n-1;i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 9344
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

string s;
int dpR[N];
int dpL[N];
int cnt[N];

int main(){
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'L')
            continue;
        dpR[i] += s[i] == 'R';
        dpR[i] += dpR[i - 1];
    }
    for(int i = s.size() - 1; i >= 0; i--){
        if(s[i] == 'R')
            continue;
        dpL[i] += s[i] == 'L';
        dpL[i] += dpL[i + 1];
    }
    for(int i = 0; i < s.size()-1; i++){
        if(s[i] == 'R' && s[i + 1] == 'L'){
            cnt[i] = cnt[i + 1] = 1;
            int R = dpL[i + 2];
            int L = dpR[i - 1];
            bool swp = 0;
            int stp = max(R , L);
            if(stp % 2 == 0)
                swp = 1;
            while(R || L){
                if(R){
                    cnt[i+1]++;
                    R--;
                }
                if(L){
                    cnt[i]++;
                    L--;
                }
                swap(cnt[i] , cnt[i + 1]);
            }
            if(swp){
                swap(cnt[i] , cnt[i + 1]);
            }
        }
    }
    for(int i = 0; i < s.size(); i++){
        cout << cnt[i] << " ";
    }
}
// it will be WA if he put RRRRRRRRR.....L


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
#include <set>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
const int MAX_N = 300;
ll A[MAX_N], B[MAX_N], C[MAX_N], D[MAX_N];

ll gcd (ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main(){
  cin >> N;
  REP(i, N) cin >> A[i] >> B[i] >> C[i] >> D[i];
  REP(i, N) {
    if(A[i] < B[i] || D[i] < B[i] || A[i] % B[i] > C[i]) {
      cout << "No" << endl;
      continue;
    }
    if(B[i] <= C[i]) {
      cout << "Yes" << endl;
      continue;
    }
    ll g = gcd(B[i], D[i]);
    ll x = A[i] % B[i];
    if(B[i] - g + x % g <= C[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;

}



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

string prime(int n){
  int i,j;
  string p = "001";
  while((int)p.size()<=n)p+="10";
  i = 3;
  while(i*i<n){
    for(j=3*i;j<n;j+=2*i)p[j] = '0';
    do{i+=2;}while(p[i]-'1');
  }
  return p;
}

int main(){
  int n,c;
  string p;

  p = prime(246912);

  while(1){
    cin >> n;
    if(!n)break;

    c = 0;
    for(int i=n+1;i<=2*n;i++){
      if(p[i] == '1')c++;
    }
    
    cout << c << endl;
  }
}

Measured memory_bytes: 0
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 1e5 + 10;
int a[maxn];
int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  return 1;
}

void solve() {
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
  }

  long long want = (long long) n * (n + 1) / 2;
  if (sum % want) {
    printf("NO\n");
    return;
  }

  long long k = sum / want;

  a[n] = a[0];

  long long whole = 0;
  for (int i = 0; i < n; ++i) {
    long long now = a[i + 1] - a[i] - k;
    now = -now;
    if (now < 0 || now % n) {
      printf("NO\n");
      return;
    }
    whole += now / n;
  }
  if (whole != k) {
    printf("NO\n");
    return;
  }
  printf("YES\n");
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<char>> field(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> field[i][j];
    }
  }
  int cnt = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == '#')
        cnt++;
    }
  }
  if (cnt == H + W - 1)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}


Measured memory_bytes: 256
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

R, G, B, N = gets_i_list

max_r = (N.to_f / R).ceil
max_g = (N.to_f / G).ceil

count = 0
0.upto(max_r).each do |r|
  0.upto(max_g).each do |g|
    remain = N - R * r - G * g
    if remain >= 0 && remain % B == 0
      count += 1
    end
  end
end

puts count


Measured memory_bytes: 2556
A=[list(map(int,input().split())) for i in range(3)]
n=int(input())

for i in range(n):
  o=int(input())
  for x in range(3):
    for y in range(3):
      if o == A[y][x]:
        A[y][x]=-1

for x in range(3):
  f=True
  for y in range(3):
    if A[y][x]!=-1:
      f=False
  if f:
    print('Yes')
    exit()

for y in range(3):
  f=True
  for x in range(3):
    if A[y][x]!=-1:
      f=False
  if f:
    print('Yes')
    exit()


f=True
for i in range(3):
  if A[i][i]!=-1:
    f=False
if f:
  print('Yes')
  exit()
f=True


for i in range(3):
  if A[i][2-i]!=-1:
    f=False
if f:
  print('Yes')
  exit()

print('No')


Measured memory_bytes: 3188
import math
from itertools import permutations
n=int(input())
p=[]
for i in range(n):
    x,y=map(int,input().split())
    p.append([x,y])
s=list(permutations(p))
a=[]
for c in s:
    l=[]
    for d in range(n-1):
        xi=c[d][0]
        xj=c[d+1][0]
        yi=c[d][1]
        yj=c[d+1][1]
        t1=(xi-xj)**2
        t2=(yi-yj)**2
        l.append(math.sqrt(t1+t2))
    a.append(sum(l))
print(sum(a)/len(a))

Measured memory_bytes: 9332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    ll N = sz(s);

    ll ans = 0;
    ll tmp = 0;

    rep(i,N){
        if(s[i] == 'g'){
            if(tmp > 0){
                ans++;
                tmp--;
            }else{
                tmp++;
            }
        }else{
            if(tmp > 0){
                tmp--;
            }else{
                tmp++;
                ans--;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
def resolve():
  n = int(input())
  h = list(map(int, input().split()))
  h[0] -= 1
  for i in range(1, n):
    if h[i] -1 >= h[i-1]:
      h[i] -= 1
    if h[i-1] > h[i]:
      print('No')
      return
  print('Yes')

  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

vector<int> gph[100005];

int dfs(int x){
	int ret = 0;
	vector<int> v;
	for(auto &i : gph[x]){
		v.push_back(dfs(i));
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for(int i=0; i<v.size(); i++){
		ret = max(ret, v[i] + i + 1);
	}
	return ret;
}

int n;
int main(){
	cin >> n;
	for(int i=2; i<=n; i++){
		int p;
		scanf("%d",&p);
		gph[p].push_back(i);
	}
	cout << dfs(1) << endl;
}


Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n, d, x;
	cin >> n >> d >> x;

	vector<vector<int> > p(d, vector<int>(n));
	rep(i, d) {
		rep(j, n) cin >> p[i][j];
	}

	int dp[100005];
	memset(dp, 0, sizeof(dp));
	rep(i, d - 1) {
		rep(j, x + 1) {
			dp[j] = j;
		}

		int res = x;
		rep(j, n) {
			rep(k, x + 1) {
				if(k < p[i][j]) continue;
				dp[k] = max(dp[k], dp[k-p[i][j]] + p[i+1][j]);
				res = max(res, dp[k]);
			}
		}

		x = res;
	}
	
	cout << x << endl;

	return 0;
}

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

using namespace std;

const int INF = 1e9 + 9;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int N;
  cin >> N;
  vector < int > a(N), dp(N, INF);
  for (auto &x : a)
    cin >> x;
  dp[0] = 0;
  for (int i = 0; i < N; ++i)
    for (int j : {i + 1, i + 2})
      if (j < N)
        dp[j] = min (dp[j], dp[i] + abs (a[i] - a[j]));
  cout << dp[N - 1];
}


Measured memory_bytes: 3876
#include<bits/stdc++.h>
// #include"testlib.h"

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e6 + 10;
// const int mod = (int)1e9 + 7;


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

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

    int n, x;
    cin >> n >> x;

    int a[n];
    int sum = 0;
    int res = 1;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        sum += a[i];
        if(sum <= x) res++;
    }

    cout << res << endl;

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;

  for (int i = 0; i < s.size(); i++){
    if(s[i] != s[s.size() - i - 1]){ 
      s[s.size() - i - 1] = s[i];
      ans++;
    }
  }

  cout << ans;
}
  



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N, W;
  cin >> N >> W;
  vector<int> v(N), w(N);
  rep(i, N) cin >> v[i] >> w[i];
  vector<vector<int>> dp(N+1, vector<int>(W+1));
  for(int i=1; i<=N; i++) {
    rep(j, W+1) {
      chmax(dp[i][j], dp[i-1][j]);
      if(j-w[i-1] >= 0)
        chmax(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1]);
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 6836
#include <stdio.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n)  FOR(i,0,n)
int main(){
	int N, C, s, t, c;
	short using[30][100001] = {};
	scanf("%d%d", &N,&C);
	REP(i,30) REP(j,100001) using[i][j] = 0;
	REP(i,N) {
		scanf("%d%d%d",&s,&t,&c);
		FOR(j,s-1,t) using[c-1][j] = 1;
	}

	int dup, max = 0;
	FOR(i,0,100001) {
		dup = 0;
		FOR(j,0,C) if(using[j][i]) dup++;
		if(max < dup) max = dup;
	}
	printf("%d",max);
	return 0;
}

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

int main() {
  int n, m, l;
  unsigned long A[100][100];
  unsigned long B [100][100];
  cin >> n >> m >> l;
  for (int i =0 ; i < n ; i ++ ) {
  for (int j =0 ; j < m ; j ++ ) {
    cin >> A[i][j];
  }
  }

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

  for(int i = 0; i < n ; i ++) {
  for(int j = 0; j < l ; j ++ ) {
    unsigned long res = 0;
    for(int k = 0; k < m; k ++) {
      res += A[i][k] * B[k][j];
    }
    cout << res;
    if ( j != l-1 ) {
      cout << " " ;
  }
  }
  cout <<  endl;
  }


}

Measured memory_bytes: 3216
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		long n = nl();
		long m = nl();

		Map<Long, Long> ab = new TreeMap<>();

		for (int i = 0; i < n; i++) {
			long a = nl();
			long b = nl();

			if (ab.containsKey(a)) {
				ab.put(a, b + ab.get(a));
			} else {
				ab.put(a, b);
			}
		}

		long ans = 0;

		for (long a : ab.keySet()) {
			long honsuu = ab.get(a);
			if (honsuu < m) {
				m -= honsuu;
				ans += a * honsuu;
			} else {
				ans += a * (m);
				break;
			}
		}
		out(ans);

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int w;
	int d;

	XY(int h, int w, int d) {
		this.h = h;
		this.w = w;
		this.d = d;
	}
}


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

int max_k(int N){
  for (int n=1;n<=N;n++){
    if (n*(n+1) >= 2*N) return n;
  }
  return 0;
};

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

  int n=0;
  //vector<int> sol;
  while (N>0) {
    n = max_k(N);
    //sol.push_back(n);
    cout << n << endl;
    N -= n;
  }

  
}

 

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define int long long
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
const double EPS = 1e-6 ; 
signed main(){
    fastio
    int n ; 
    cin >> n ;
    for(int i = 62; i >= 0; i--){
        if ( (1LL << i) & n ){
            debug() << imie(i) ;
            i++;
            cout << (1LL << i) - 1 << endl;
            return 0 ;
        }
    }
    return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX (5000)

int main(void)
{
	int data[MAX];
	int tmp, max;
	int no;
	int i;
	
	while (1){
		scanf("%d", &no);
		if (no == 0) break;
		
		max = -100000;
		
		for (i = tmp = 0; i < no; i++){
			scanf("%d", &data[i]);
			tmp += data[i];
			if (max < tmp) max = tmp;
			if (tmp < 0) tmp = 0;
		}
		
		printf("%d\n", max);
	}
	
	return (0);
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - On the Way
            var line = ReadLine();
            int a = line[0];
            int b = line[1];
            int c = line[2];

            if (IsOnTheWay(a, b, c))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }            
        }

        static bool IsOnTheWay(int a, int b, int c)
        {
            if (a < b && c < b && a < c)
            {
                return true;
            }
            else if (b < a && b < c && c < a)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int d;
	cin>>d;
	if(d==25)
		cout<<"Christmas"<<endl;
	else
		if(d==24)
			cout<<"Christmas Eve"<<endl;
		else
			if(d==23)
			cout<<"Christmas Eve Eve"<<endl;
			else
				cout<<"Christmas Eve Eve Eve"<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main(){map<char,int>cnt;string w;cin>>w;int n=w.size();rep(i,0,n)cnt[w[i]]++;bool ans=true;for(auto v:cnt)if(v.second%2)ans=false;if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
}



Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    char s[100005];
    scanf("%s", s);
    int i;
    for (i = 0; i < n; i++)
    {
        if (s[i] == 'a')
        {
            if (a + b > 0)
            {
                printf("Yes\n");
                a--;
            }
            else
                printf("No\n");
        }
        else if (s[i] == 'b')
        {
            if (a + b > 0 && b > 0)
            {
                printf("Yes\n");
                b--;
            }
            else
                printf("No\n");
        }
        else
            printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 640