akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

n = int(input())
S = [input() for i in range(n)]

counter = [defaultdict(lambda: 0) for i in range(n)]
for i in range(n):
    for c in S[i]:
        counter[i][c] += 1
        
all_counter = defaultdict(lambda: 0)
for s in counter[0]:
    all_counter[s] += counter[0][s]
    
for i in range(n):
    for s in all_counter:
        all_counter[s] = min(counter[i][s], all_counter[s])

for s in sorted(all_counter, key=lambda x: x[0]):
    print(s* all_counter[s], end='')    

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

typedef long long ll;

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N), B(N);
    rep(i, N) {
        cin >> A[i];
        B[i] = -A[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    ll l = -1e18-1, h = 1e18+1, ans = -1e18-1, m;
    while (l + 1 < h) {
        m = (l + h) / 2;
        ll c = 0;
        rep(i, N) {
            if (A[i] > 0) {
                ll k;
                if (m >= 0) k = m / A[i];
                else k = (m - A[i] + 1) / A[i];
                int j = upper_bound(A.begin(), A.end(), k) - A.begin();
                c += min(i, j);
                if (j > 0 && A[i] * A[j - 1] > ans) ans = A[i] * A[j - 1];
            }
            if (A[i] < 0) {
                int j = lower_bound(A.begin(), A.end(), m / A[i]) - A.begin();
                //cout << "j=" << j << endl;
                c += max(0, i - j);
                if (j < N && A[j] * A[i] > ans) ans = A[j] * A[i];
            }
            if (A[i] == 0) {
                if (m >= 0) {
                    c += i;
                    if (0 > ans) ans = 0;
                }
            }
            //cout << "A[i]=" << A[i] << " c=" << c << " ans=" << ans << endl;
        }
        //cout << "l=" << l << " h=" << h << " m=" << m << " c=" << c << " ans=" << ans << endl; 
        if (c < K) l = m;
        else h = m;
    }
    cout << h << endl;
}

Measured memory_bytes: 3328
//RohitKaushal
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define print(x) cerr << (#x) << "is "<< x << "\n"
typedef long long ll;
const int MOD = 1e9+7;


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

   ll n,m;
   cin>>n>>m;
   ll t;
   std::multiset<ll, greater <ll>> v;
   for (int i = 0; i < n; ++i)
   {
   		cin>>t;
   		v.insert(t);
   }




   while(m){
   	ll max = *v.begin();
   	max/=2;
   	v.insert(max);
   	v.erase(v.begin());
   	m--;
   }

   ll sum=0;
 	while(v.size())
 	{
 		sum+=*v.begin();
 		v.erase(v.begin());
 	}

   cout<<sum;




   return 0;
} 


Measured memory_bytes: 4992
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e - a > k:
    print(":(")
elif e - b > k:
    print(":(")
elif e - c > k:
    print(":(")
elif e - d > k:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	string S;
	cin >> S;
	if (S.length() == 2)
	{
		cout << S;
	}
	else
	{
		for (int i = 2; i >= 0; --i)
		{
			cout << S[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);
 
$max = strlen($s);
$s .= $s[0];
$ps = [[0, 0], [0, 1], [1, 0], [1, 1]];
foreach ($ps as $p) {
	$t = $p;
	for ($i = 1; $i <= $max; $i++) {
		if ($s[$i] == 'o' && $t[$i] == 0 || $s[$i] == 'x' && $t[$i] == 1) {
			$t[$i+1] = $t[$i-1];
		} else {
			$t[$i+1] = 1 - $t[$i-1];
		}
	}
	if ($t[0] == $t[$max] && $t[1] == $t[$max+1]) {
		$x = substr(implode($t), 0, -2);
		exit(str_replace([0,1], ['S','W'], $x));
	}
}
echo '-1';

Measured memory_bytes: 10868
while True:
  n = int(input())
  if n == 0:
    break
  hr_lst = []
  for _ in range(n):
    h, r = map(int, input().split())
    hr_lst.append((h, r))
  
  m = int(input())
  for _ in range(m):
    h, r = map(int, input().split())
    hr_lst.append((h, r))
  
  hr_lst.sort(reverse=True)

  r_lst = [[] for _ in range(1001)]
  for h, r in hr_lst:
    r_lst[h].append(r)
  r_lst = [lst for lst in r_lst if lst != []]
  
  """
  dp[y] ... 最大yまでの最大入れ子数
  dp[y] = max(dp[y], dp[v - 1] + 1)
  """
  dp = [0] * 1001
  for x in range(len(r_lst)):
    vlst = r_lst[x]
    max_v = 1000
    for v in vlst:
      for y in range(max_v, v - 1, -1):
        dp[y] = max(dp[y], dp[v - 1] + 1)
  print(dp[1000])


Measured memory_bytes: 5724
#include <bits/stdc++.h>
using namespace std; 
int main() {
  int X;
  cin>>X;
  int Y=X;
  int sum = 0;
while(Y!=0){
  sum += Y% 10;
  Y/= 10;
}
if(X%sum==0){
  cout<<"Yes"<<endl;
}else{
  cout<<"No"<<endl;
}
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
std::mt19937 gen(std::chrono::system_clock::now().time_since_epoch().count());
const int maxn = 600 + 10;
const int maxm = maxn * maxn;
char s[maxn][maxn];
ll f[maxn][maxn], sf[maxn][maxn], g[maxn][maxn], sg[maxn][maxn];
ll p[maxn * maxn];
bool ans[maxn][maxn];
int n;
void solve(const ll mod)
{
	ll b = std::uniform_int_distribution<>(0.25 * mod, 0.75 * mod)(gen);
	p[0] = 1; for(int i = 1; i < maxm; ++i) p[i] = p[i - 1] * b % mod;
	for(int i = 1; i <= (n << 1); ++i)
	{
		for(int j = 1; j <= (n << 1); ++j) 
			f[i][j] = (f[i][j - 1] * b + s[i][j] - 'a') % mod;
		for(int j = 1; j <= n; ++j)
			sf[i][j] = (f[i][j + n - 1] + mod - f[i][j - 1] * p[n] % mod) % mod;
	}
	for(int j = 1; j <= n; ++j)
	{
		for(int i = 1; i <= (n << 1); ++i)
			f[i][j] = (f[i - 1][j] * p[n] + sf[i][j]) % mod;
		for(int i = 1; i <= n; ++i)
			sf[i][j] = (f[i + n - 1][j] + mod - f[i - 1][j] * p[n * n] % mod) % mod;
	}
	for(int j = 1; j <= (n << 1); ++j)
	{
		for(int i = 1; i <= (n << 1); ++i)
			g[i][j] = (g[i - 1][j] * b + s[i][j] - 'a') % mod;
		for(int i = 1; i <= n; ++i)
			sg[i][j] = (g[i + n - 1][j] + mod - g[i - 1][j] * p[n] % mod) % mod;
	}
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= (n << 1); ++j) 
			g[i][j] = (g[i][j - 1] * p[n] + sg[i][j]) % mod;
		for(int j = 1; j <= n; ++j)
			sg[i][j] = (g[i][j + n - 1] + mod - g[i][j - 1] * p[n * n] % mod) % mod;
	}
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
		{
			//cout << i << ' ' << j << ' ' << sf[i][j] << ' ' << sg[i][j] << endl;
			if(sf[i][j] != sg[i][j])
				ans[i][j] = 0;
		}
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%s", s[i] + 1);
		for(int j = 1; j <= n; ++j)
		{
			ans[i][j] = 1;
			s[i + n][j] = s[i][j + n] = s[i + n][j + n] = s[i][j];
		}
	}
	solve(1e9 + 7);
	solve(1e9 + 7);
	int ret = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			ret += ans[i][j];
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 17276
n = int(input())
a = list(map(int, input().split()))

l = len(bin(max(a))[2:])

cumsums = [[0] for _ in range(l)]
for i in range(n):
    for j in range(l):
        if a[i] & (1 << j):
            cumsums[j].append(cumsums[j][-1] + 1)
        else:
            cumsums[j].append(cumsums[j][-1])

ans = 0
left = 0
for i in range(1, n+1):
    while left < i:
        f = True
        for j in range(l):
            if cumsums[j][left] < cumsums[j][i] - 1:
                f = False

        if f:
            break
        else:
            left += 1

    ans += i - left
print(ans)


Measured memory_bytes: 142536
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}


ll cum[100010];
ll Mcum[100010];
int a[100010];
int main() {
	int N, K; cin >> N >> K;
	cum[0] = 0; Mcum[0] = 0;
	REP(i, N) {
		cin >> a[i];
		cum[i + 1] = cum[i] + a[i];
		Mcum[i + 1] = Mcum[i] + max(0, a[i]);
	}
	ll res = 0;
	ll ans = 0;
	REP(i, N - K+1) {
		res = max((ll)0, (cum[i + K] - cum[i]));
		res += Mcum[i] - Mcum[0] + Mcum[N] - Mcum[i + K];
		ans = max(ans, res);
	}
	p(ans);
}

Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {

  static void trace(int[] a, int n) {
    for (int i = 0; i < n; i++) {
      if (i > 0) System.out.print(" ");
      System.out.print(a[i]);
    }
    System.out.println();
  }
    
  static void insertionSort(int[] a, int n) {
    int t, j;
    for (int i = 1; i < n; i++) {
      t = a[i];
      j = i - 1;
      while (j >= 0 && a[j] > t) {
        a[j + 1] = a[j];
        j--;
      }
      a[j + 1] = t;
      trace(a, n);
    }
  } 

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = stdIn.nextInt();
    trace(a, n);
    insertionSort(a, n);
  }
}

Measured memory_bytes: 33996
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
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;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;
    cin>>s;
    int n=s.length();
    int ans=0;
    for(int i=0;i<n;i++){
        if(s[i]=='1')
            ans++;


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


Measured memory_bytes: 256
integer H,W
integer,allocatable,dimension(:,:)::DP
integer mo
character(1000) line

read*,H,W
allocate(DP(H,W))
mo=10**9+7
read*,line
DP=0
if(line(1:1)==".")DP(1,1)=1
do i=2,W
  if(line(i:i)==".")DP(1,i)=DP(1,i-1)
end do

do i=2,H
  read*,line
  if(line(1:1)==".")DP(i,1)=DP(i-1,1)
  do j=2,W
    if(line(J:J)==".")DP(i,j)=mod(DP(i-1,j)+DP(i,j-1),mo)
  end do
end do

print"(i0)",DP(H,W)
end

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int H, W;

int main() {
	cin >> H >> W;
	const int nul = 0;
	vector<string> S(H);
	vector<vector<int> > mass(H, vector<int> (W, H + W - 1));
	for (int i = 0; i < H; i++) {
		cin >> S[i];

		int left = -1, right = W;
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				mass[i][j] = nul;
				left = j;
			}
			else {
				mass[i][j] -= left + 1;
			}
			if (S[i][W - 1 - j] == '#') {
				right = W - 1 - j;
			}
			else {
				mass[i][W - 1 - j] -= W - right;
			}
		}

	}
	for (int j = 0; j < W; j++) {
		int up = -1, down = H;
		for (int i = 0; i < H; i++) {
			if (S[i][j] == '#') {
				mass[i][j] = nul;
				up = i;
			}
			else {
				mass[i][j] -= up + 1;
			}
			if (S[H - 1 - i][j] == '#') {
				down = H - 1 - i;
			}
			else {
				mass[H - 1 - i][j] -= H - down;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans = max(ans, mass[i][j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 20096
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

h,w=LI()
h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0})
dp=[10**6]*(h*w)
g[1],dp[1]=0,0

for j in range(h*w-h):
    r,c=j//w,j%w
    if (r in [0,h-1]) or (c in [0,w-1]):
      	if j!=1:
            continue

    dp[j+1]=min(dp[j]+1 if (g[j],g[j+1])==(0,1) else dp[j],dp[j+1])
    dp[j+w]=min(dp[j]+1 if (g[j],g[j+w])==(0,1) else dp[j],dp[j+w])

print(dp[(h-2)*w+w-2])


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n;
char a[500][501];

int cr(int i){
  int s = 0;
  rep(j, n){
    s += a[i][j] == '#';
  }
  return s;
}
int cc(int j){
  int s = 0;
  rep(i, n){
    s += a[i][j] == '#';
  }
  return s;
}

int main(){
  cin >> n;
  rep(i, n){
    cin >> a[i];
  }

  bool b = true;
  rep(i, n){
    if(cr(i)){
      b = false;
      break;
    }
  }
  if(b){
    cout << -1 << endl;
    return 0;
  }
  int p = n + 1;
  rep(i, n){
    p = min(n - cr(i) + !cc(i), p);
  }
  rep(i, n){
    p += cc(i) != n;
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	double d;
	cin>>d;
	ll x[n],y[n];
	for(int i=0;i<n;i++)cin>>x[i]>>y[i];
	int count=0;
	for(int i=0;i<n;i++){
		double val=sqrt(x[i]*x[i]+y[i]*y[i]);
		if(val<=d)
		count++;
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 6868
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n, i;
    cin >> n >> i;
    cout << n - i + 1 << endl;

}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; ++i){
        cin >> A[i];
    }
    for(int i=0; i<N; ++i){
        int v = A[i];
        int j = i-1;
        for(; v<=A[j] && j>=0; --j){
            A[j+1] = A[j];
        }
        A[j+1] = v;
        for(int k=0; k<N-1; ++k){
            cout << A[k] << " ";
        }
        cout << A[N-1] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>

int main(void)
{
	int i,k;
	char s[101], t[20];
	scanf("%d", &k);
	scanf("%s", &s);


	for (i = 0;s[i] != '\0';i++) {
	}
	i--;
	if (i < k) {
		printf("%s",s);
		return 0;
	}
	for (i = 0;i<k;i++) {
		printf("%c",s[i]);
	}
	printf("...");

	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)

int main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll res = 0;
  rep(i, n - 1) {
    ll l = a[i];
    ll r = a[i + 1];
    ll sum = max(l + r - x,0LL);
    res += sum;
    a[i+1]-= sum;
    if(a[i+1] < 0){
      a[i]+=a[i+1];
      a[i+1]=0;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1024
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);++i)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

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

	int x_group = 0;
	int y_group = 0;

	if(x==1
	|| x==3
	|| x==5
	|| x==7
	|| x==8
	|| x==10
	|| x==12
	) x_group = 1;

	if(y==1
	|| y==3
	|| y==5
	|| y==7
	|| y==8
	|| y==10
	|| y==12
	) y_group = 1;

	if(x==4
	|| x==6
	|| x==9
	|| x==11
	) x_group = 2;

	if(y==4
	|| y==6
	|| y==9
	|| y==11
	) y_group = 2;

	if(x==2
	) x_group = 3;

	if(y==2
	) y_group = 3;

	ote(x_group == y_group? "Yes":"No");

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(Q: int, H: int, S: int, D: int, N: int):
    h1 = min(2*Q, H)
    h1 = min(h1*2, S)
    d1 = D

    ans = 0
    if 2*h1 < d1:
        print(N*h1)
    else:
        if N%2 == 0:
            print((N//2)*d1)
        else:
            print((N//2)*d1 + h1)
    
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    Q = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(Q, H, S, D, N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>

using namespace std;
typedef long long ll;
int main(){
    int i,n,cnt = 0;ll d; cin >> n >> d;
    for(i=0;i<n;i++){
        ll x,y; cin >> x >> y;
        if(x*x + y*y<=d*d) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
n = int(input())
a = [int(i) for i in input().split()]

num = 0

is_swapped = True
i = 0
while is_swapped:
    is_swapped = False
    for j in range(n-1, i, -1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            is_swapped = True
            num += 1
    i += 1

print(' '.join([str(i) for i in a]))
print(num)


Measured memory_bytes: 5608
<?php
$file = new SplFileObject("php://stdin");
$file->setFlags(15);
$file->setCsvControl(' ');

$line = [];
foreach ($file as $i => $row) {
    $line[$i] = $row;
}

$column = $line[0][0];
$stairs = $line[1];
$isOperated = false;
$isError = false;
for ($i = 0; $i < $column - 1; $i++) {
    $left = $stairs[$i];
    $right = $stairs[$i + 1];

    if ($left - 1 > $right || (isset($min) && $min > $right)) {
        $isError = true;
    } elseif ($left - 1 == $right) {
        $min = $left - 1;
    }
}

$str = $isError ? 'No' : 'Yes';

echo $str . PHP_EOL;

Measured memory_bytes: 16888
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)  for(int i = n - 1; i >= 0; --i)
#define forr1(i, n) for(int i = n; i >= 1; --i)
#define form(l, r, i)   for(int i = l; i <= r; ++i)
#define forv(r, l, i)   for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
  
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 9;
  
using namespace std;

int main()
{
    barnarnar
    multiset<ll> a1;
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    forn(i, a)
    {
    	ll t;
    	cin >> t;
    	a1.insert(t);
    	if(a1.si > x)	a1.erase(a1.begin());
	}
	multiset<ll> b1;
	forn(i, b)
	{
		ll t;
		cin >> t;
		b1.insert(t);
		if(b1.si > y)	b1.erase(b1.begin());
	}
	forn(i, c)
	{
		ll t;
		cin >> t;
		ll el1 = *a1.begin(), el2 = *b1.begin();
		if(t > el1 && t - el1 >= t - el2)
		{
			a1.erase(a1.begin());
			a1.insert(t);
		}
		elif(t > el2)
		{
			b1.erase(b1.begin());
			b1.insert(t);
		}
	}
	ll ans = 0;
	for(auto i:a1)	ans += i;
	for(auto i:b1)	ans += i;
	cout << ans;
    return 0;
}

Measured memory_bytes: 8704
import java.util.Scanner;
  
public class Main {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  String line = sc.nextLine();
  String[] split = line.split(" ");
  int[] num = new int[split.length];
  
  for (int i = 0; i < split.length; i++) {
   num[i] = Integer.parseInt(split[i]);
  }
  int w = num[0];
  int h = num[1];
  int x = num[2];
  int y = num[3];
  int r = num[4];
  String str = null;
  if(r <= x && x <= (w - r) && r <= y && y <= (h - r)) {
   str = "Yes";
  } else {
   str = "No";
  }
    
  System.out.println(str);
  sc.close();
 }
}

Measured memory_bytes: 26292
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(string N){
  ll ans=0;
  REP(N.size()){
    ans+=N[i]-'0';
  }
  string n=N;
  reverse(n.begin(),n.end());
  n+='0';
  ll i=0;
  while(i<n.size()){
    dump(i);
    if(n[i]>'5'||(i<n.size()-1&&n[i]=='5'&&n[i+1]>='5')){
      ans-=(n[i]-'0')*2-10;
      n[i]='0';
      ll j=i+1;
      bool f=true;
      while(j<n.size()&&f){
        if(n[j]=='9'){
          n[j]='0';
          ans-=9;
          f=true;
        }else{
          ++n[j];
          ans+=1;
          f=false;
        }
        ++j;
      }
      i=j-2;
    }
    dump(n);
    ++i;
  }
  reverse(n.begin(),n.end());
  dump(n);
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
  string N;
  cin>>N;
    solve(N);
    return 0;
}


Measured memory_bytes: 4252
#include <bits/stdc++.h>
using namespace std;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int n;
char t[200][200];
   
int main(){
  int d,D;
  int i,j;
  scanf("%d",&d);
     
  for(D=0;D<d;D++){
    if(D>0)printf("\n");
       
    scanf("%d",&n);
       
    for(i=0;i<=n+3;i++){
      for(j=0;j<=n+3;j++){
        if(i==0||j==0||i==n+3||j==n+3)t[i][j]='#';
        else t[i][j]=' ';
      }
    }
       
    int y=n+1,x=2,dir=0,cnt=1;
    while(1){
      while(1){
        t[y][x]='#';
        if(t[y+dy[dir]*2][x+dx[dir]*2]=='#')break;
        cnt++;
        y+=dy[dir];
        x+=dx[dir];
      }
      if(cnt<=1)break;
      dir=(dir+1)%4;
      cnt=0;
    }
       
    for(i=2;i<2+n;i++){
      for(j=2;j<2+n;j++){
        printf("%c",t[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 3164
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 3e5 + 20 ;
int n , r1 , r2 ;
vector <int> g1[N] , g2[N] ;

int res[N] ;
int cnt , x[N] , y[N] , ptr[N] ;
bool vis[N] ;
vector <int> h[N] , vec ;

inline void err () {
	cout << "IMPOSSIBLE\n" ;
	exit(0) ;
}

inline void get_tree (vector <int> g[N] , int &root) {
	for (int i = 0 , p ; i < n ; i ++) {
		cin >> p ;
		if (p == -1) {
			root = i ;
			continue ;
		}
		p -- ;
		g[p].pb(i) ;
	}
}

inline void add_edge (int u , int v) {
	x[cnt] = u , y[cnt] = v ;
	h[u].pb(cnt) ;
	h[v].pb(cnt) ;
	cnt ++ ;
}

void dfs (int v) {
	bool fl = 0 ;
	for (int &j = ptr[v] ; j < _sz(h[v]) ; j ++) {
		int i = h[v][j] ;

		if (vis[i]) continue ;

		vis[i] = 1 ;
		int u = x[i] ^ y[i] ^ v ;
		
		if (x[i] == u) swap(x[i] , y[i]) ;

		dfs(u) ;
		vec.pb(i) ;
		fl = 1 ;
	}
}

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

	cin >> n ;
	get_tree(g1 , r1) ;
	get_tree(g2 , r2) ;

	for (int i = 0 ; i < n ; i ++)
		if ((_sz(g1[i]) & 1) != (_sz(g2[i]) & 1)) err() ;

	for (int i = 0 ; i < n ; i ++) {
		for (int j : g1[i]) add_edge(i , j) ;
		for (int j : g2[i]) add_edge(i + n , j + n) ;
	}
	
	add_edge(2 * n , r1) ;
	add_edge(2 * n , r2 + n) ;

	for (int i = 0 ; i < n ; i ++)
		if (!(_sz(g1[i]) & 1)) add_edge(i , i + n) ;

	dfs(0) ;

	for (int i : vec) {
		if (abs(x[i] - y[i]) == n && max(x[i] , y[i]) < 2 * n) 
			res[min(x[i] , y[i])] = (x[i] < y[i] ? 1 : -1) ;
	}

	cout << "POSSIBLE\n" ;
	for (int i = 0 ; i < n ; i ++) cout << res[i] << ' ' ;
	cout << '\n' ;
}


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

double dp[3002][3002] = {};

int main(){
    int N;
    double p;
    double logp[3002];
    double log1_p[3002];
    double ans = 0.0;

    cin >> N;
    for(int n=1;n<=N;n++){
        cin >> p;
        logp[n] = log(p);
        log1_p[n] = log(1-p);
    }

    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j] = -1.0 * 1e18;
        }
    }

    dp[0][0] = 0;
    for(int n=1;n<=N;n++){
        for(int m=0;m<=n;m++){
            dp[n][m] = dp[n-1][m] + log1_p[n];
            if(m != 0) dp[n][m] = log(exp(dp[n][m]) + exp(dp[n-1][m-1] + logp[n]));
        }
    }

    for(int n=N/2+1;n<=N;n++) ans += exp(dp[N][n]);
    cout << setprecision(10) << fixed << ans << "\n";
    return 0;
}

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

def solve():
    N, M = map(int, input().split())
    adjL = [[] for _ in range(N)]
    outdegs = [0] * N
    for _ in range(M):
        s, t = map(int, input().split())
        s, t = s-1, t-1
        adjL[s].append(t)
        outdegs[s] += 1

    dp = [0] * N
    for v in reversed(range(N-1)):
        e = 0
        for v2 in adjL[v]:
            e += dp[v2]
        dp[v] = e/outdegs[v] + 1

    ans = dp[0]
    for vNow in range(N-1):
        if outdegs[vNow] == 1: continue
        maxDP = 0
        vMax = -1
        for v2 in adjL[vNow]:
            if dp[v2] > maxDP:
                maxDP = dp[v2]
                vMax = v2
        e = 0
        for v2 in adjL[vNow]:
            if v2 == vMax: continue
            e += dp[v2]
        dp[vNow] = e/(outdegs[vNow]-1) + 1

        for v in reversed(range(vNow)):
            e = 0
            for v2 in adjL[v]:
                e += dp[v2]
            dp[v] = e/outdegs[v] + 1

        ans = min(ans, dp[0])

    print(ans)


solve()


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

int main() {
  int A, B,count=0;
  cin >> A >> B;
for(int i=A;i<=B;i++){
 if(i/10000==i%10&&i/1000%10==i%100/10) {
   count++;
 }
}
  cout << count << endl;
}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

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


    ll n;
    cin >> n;
    cout << n+n*n+n*n*n << "\n";

    return 0;
}

Measured memory_bytes: 3604
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::marker::*;
use proconio::*;

#[fastout]
fn main() {
    input! {
        n: i64,
    }
    // annotate for rust-analyzer
    let n: i64 = n;

    let mut ans = 0;
    for i in 1..=n {
        ans += if i % 3 == 0 || i % 5 == 0 { 0 } else { i };
    }

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


Measured memory_bytes: 2164
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
  	int n, a[200005] = {}, b = 0;
  	cin >> n;
  	for (int i = 1; i <= n; i++) cin >> a[i], b ^= a[i];
  	for (int i = 1; i <= n; i++) cout << (b ^ a[i]) << ' ';
}



Measured memory_bytes: 3984
#include<stdio.h>
#include<math.h>
 
int main(){
  int n;
  scanf("%d",&n);
 
  int i;
  int ans =0;
  for(i=0;i<=sqrt(n);i++){
    ans = i*i;
  }
 
 
 
  printf("%d\n",ans);
 
 
  return 0;
 }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

ll gcd(ll a, ll b){return b==0 ? a : gcd(b, a%b);}
ll lcm(ll a, ll b){return a / gcd(a,b) * b;}

int main()
{
  ll x;
  cin >> x;
  ll a = lcm(360, x);
  cout << a/x << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <utility>

using namespace std;

pair<int, int> prod(pair<int, int> &a, pair<int, int> &b) {
  return make_pair(max({a.first, b.first}), min(a.second, b.second));
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
  }
  pair<int, int> res = make_pair(L[0], R[0]);
  for (int i = 0; i < M; i++) {
    pair<int, int> p = make_pair(L[i], R[i]);
    res = prod(res, p);
  }
  if (res.first > res.second) {
    cout << 0 << endl;
  } else {
    cout << res.second - res.first + 1 << endl;
  }
  return 0;
}


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

namespace AtCoder.Contests.ABC157
{
    /// <summary>
    /// 
    /// </summary>
    static class A
    {
        static void Main(string[] args)
        {
            var n = ReadInt();

            Console.WriteLine((n + 1) / 2);
        }

        #region Console
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


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

using namespace std;

const int MaxN = 55;
const long long Mod = 1000000007;

int n;
long long k;

struct Matrix
{
    long long a[MaxN][MaxN];
    Matrix()
    {
        for (int i = 0; i <= n; i++)
        {
            for (int j = 0; j <= n; j++)
            {
                a[i][j] = 0;
            }
        }
    }
    Matrix operator*(const Matrix data) const
    {
        Matrix Ans;
        for (int t = 1; t <= n; t++)
        {
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    Ans.a[i][j] = (Ans.a[i][j] + a[i][t] * data.a[t][j]) % Mod;
                }
            }
        }
        return Ans;
    }
};

Matrix x;

Matrix Power(Matrix a, long long b)
{
    Matrix t = a;
    b--;
    Matrix k = a;
    while (b > 0)
    {
        if (b % 2 == 1)
        {
            t = t * k;
        }
        b /= 2;
        k = k * k;
    }
    return t;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            cin >> x.a[i][j];
        }
    }
    x = Power(x, k);
    long long Ans = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            Ans = (Ans + x.a[i][j]) % Mod;
        }
    }
    cout << Ans;
    return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

vector<int> g[100'000];
vector<int> dp;

int calc(int i){
    if(dp[i] != -1) return dp[i];
    if(g[i].size() == 0) return 0;
    else{
        int ma = 0;
        for(auto && j : g[i]){
            ma = max(ma, calc(j));
        }
        dp[i] = ma + 1;
        return dp[i];
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        --x; --y;
        g[x].push_back(y);
    }

    dp = vector<int>(n, -1);
    int ans = 0;
    for(int i = 0; i < n; ++i){
        ans = max(ans, calc(i));
    }

    cout << ans << "\n";
    return 0;
}

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

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

	if (a <= b && b <= c) {
		cout << a << " " << b << " " << c << "\n";
	}
	else if ( a >= c && b <= c){
		cout << b << " " << c << " " << a << "\n";
	}
	else if (a >= b && b >= c) {
		cout << c << " " << b << " " << a << "\n";

	}
	else if (a <= c && c <= b) {
		cout << a << " " << c << " " << b << "\n";
	}
	else if (b <= a && a <= c) {
		cout << b << " " << a << " " << c << "\n";
	}
	else {
		cout << c <<" " <<  a << " "<< b << "\n";
	}
	return 0;
}

Measured memory_bytes: 1168
//超都観光

#include "bits/stdc++.h"

using namespace std;

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

int main()
{
    int W, H, N;
    cin >> W >> H >> N;

    int ans = 0;

    int old_x, old_y;
    int x, y;

    cin >> x >> y;

    FOR(i, 1, N)
    {
        old_x = x;
        old_y = y;
        cin >> x >> y;
        if(x >= old_x && y >= old_y)
        {
            ans += max(x - old_x, y - old_y);
        }
        else
        {
            if(x < old_x && y < old_y)
            {
                ans += max(old_x - x, old_y - y);
            }
            else
            {
                ans += (abs(x - old_x) + abs(y - old_y));
            }
        }
    }

    cout << ans << endl;

    return 0;
}






Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

int h,l;
int vis[1005][1005];
char mapp[1005][1005];
int ans=0;

struct point{
    int h;
    int l;
    int step;
    point(int _h=0,int _l=0,int _step=0):h(_h),l(_l),step(_step){}
};

queue<point> que;

void bfs(){
    point tmp;
    while(!que.empty()){
        tmp=que.front();
        if(tmp.step>ans) ans=tmp.step;
        que.pop();
        if(mapp[tmp.h+1][tmp.l]=='.'&&vis[tmp.h+1][tmp.l]==0){
            que.push(point(tmp.h+1,tmp.l,tmp.step+1));
            vis[tmp.h+1][tmp.l]=1;
        }
        if(mapp[tmp.h-1][tmp.l]=='.'&&vis[tmp.h-1][tmp.l]==0){
            que.push(point(tmp.h-1,tmp.l,tmp.step+1));
            vis[tmp.h-1][tmp.l]=1;
        }
        if(mapp[tmp.h][tmp.l+1]=='.'&&vis[tmp.h][tmp.l+1]==0){
            que.push(point(tmp.h,tmp.l+1,tmp.step+1));
            vis[tmp.h][tmp.l+1]=1;
        }
        if(mapp[tmp.h][tmp.l-1]=='.'&&vis[tmp.h][tmp.l-1]==0){
            que.push(point(tmp.h,tmp.l-1,tmp.step+1));
            vis[tmp.h][tmp.l-1]=1;
        }
    }
    return ;
}

int main(){
    while(!que.empty()) que.pop();
    cin>>h>>l;
    memset(vis,0,sizeof(vis));
    memset(mapp,'#',sizeof(mapp));
    for(int i=1;i<=h;i++){
        for(int j=1;j<=l;j++){
            cin>>mapp[i][j];
            if(mapp[i][j]=='#'){
                que.push(point(i,j,0));
                vis[i][j]=1;
            }
        }
    }
    bfs();
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 17296
package main

import (
	"fmt"
)

func main() {

	for {
		var H, W int
		fmt.Scan(&H)
		fmt.Scan(&W)

		if H == 0 && W == 0 {
			break
		}
		for h := 0; h < H; h++ {
			for w := 0; w < W; w++ {
				fmt.Print("#")
			}
			fmt.Println("")
		}
		fmt.Println("")
	}
}



Measured memory_bytes: 1132
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    ull a;string b;cin>>a>>b;
    int c=0;
    reverse(b.begin(),b.end());
    for(int i=b.length()-1;i>=0;i--)
    {
        if(b[i]>=48 && b[i]<=57)
            c=c*10+b[i]-'0';
    }
    ull ans=a*c;
    ull x=ans/100;
    cout<<x<<nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
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; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

std::vector<int> primeFactors(int n) {
  std::vector<int> v;
  int i = 2;
  while (i * i <= n) {
    if (n % i == 0) {
      v.push_back(i);
      n /= i;
    } else {
      i++;
    }
  }
  v.push_back(n);
  return v;
}

main {
  int n;
  cin >> n;
  vi a = primeFactors(n);
  cout << n << ':';
  for (auto &x : a) cout << ' ' << x;
  cout << endl;
}

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

int main()
{
  string S;
  cin >> S;
  int64_t p = 0, g = 0, score = 0;
  for (int i = 0; i < S.size(); i++)
  {
    if (S.at(i) == 'p')
    {
      if (p + 1 <= g)
      {
        p++;
      }
      else
      {
        g++;
        score--;
      }
    }
    else
    {
      if (p + 1 <= g)
      {
        p++;
        score++;
      }
      else
      {
        g++;
      }
    }
  }
  cout << score << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

int main() {
    int n,m;
    cin >> n >> m;
    ll sum = 0;
    rep(i,m){
        ll num;
        cin >> num;
        sum += num;
    }
    if (n-sum >= 0) cout << n-sum << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3636
N,M=list(map(int,input().split()))
e_list = [[] for i in range(N)]
e_list2 = []
for i in range(M):
    a,b,d = list(map(int,input().split()))
    a=a-1
    b=b-1
    e_list[a].append([b,d])
    e_list[b].append([a,d])
    e_list2.append([a,b,d])

dist_list = []
import heapq
for i in range(N):
    vi = i
    min_d_list = [10**27 for i in range(N)]
    min_d_list[vi] = 0
    prev_list = [-1 for i in range(N)]
    q = []
    for i in range(N):
        heapq.heappush(q,[min_d_list[i],i])

    while len(q)>0:
        d,v = heapq.heappop(q)
        for e in e_list[v]:
            v1,d1=e
            if min_d_list[v1]>d+d1:
                min_d_list[v1]=d+d1
                prev_list[v1]=v
                heapq.heappush(q,[d+d1,v1])
    dist_list.append(min_d_list)
count=len(e_list2)
for e in e_list2:
    for i in range(N):
        if dist_list[i][e[0]]+e[2]==dist_list[i][e[1]]:
            count-=1
            break

print(count)

Measured memory_bytes: 3700