akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
		int n;
		scanf("%d",&n);
		int a[n],b[n],i,j,counter,counter_fore;
		for(i=0;i<n;i++)scanf("%d",&a[i]);
		if(n%2==0){
				counter=n/2;
				counter_fore=n/2-1;
		}
		else {
				counter=n/2;
				counter_fore=n/2+1;
		}
		for(i=0;i<n;i++){
				if(n%2==0){
						if(i%2==0){
								b[counter]=a[i];
								counter++;
						}else{
								b[counter_fore]=a[i];
								counter_fore--;
						}
				}else if(n%2==1){
						if(i%2==0){
								b[counter]=a[i];
								counter--;
						}else if(n%2==1){
								b[counter_fore]=a[i];
								counter_fore++;
						}
				}
		}
		for(i=0;i<n;i++)printf("%d ",b[i]);
		return 0;
}


Measured memory_bytes: 3712
n = int(input())
s = input()

# E:右　W:左
cnt = [0] * (n+1)
for i in range(1, n+1):
    cnt[i] += cnt[i-1]
    if s[i-1] == "E": cnt[i] += 1

ans = float("INF")
for i in range(1,n+1):
    a = ((i-1) - cnt[i-1]) + (cnt[-1]-cnt[i])
    if ans > a: ans = a
print(ans)

Measured memory_bytes: 21128
def abc131c_anti_division():
    import math
    a, b, c, d = map(int, input().split())
    cnt = b // c - ((a - 1) // c)
    cnt += b // d - ((a - 1) // d)
    e = (c * d) // math.gcd(c, d)
    cnt -= (b // e - ((a - 1) // e))
    print(b - a + 1 - cnt)

abc131c_anti_division()

Measured memory_bytes: 62180
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		if( a*b > c * d) {
			System.out.println(a * b);
		}else {
			System.out.println(c * d);
		}
		sc.close();
	}

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

Measured memory_bytes: 21844
unittest
{
	assert( [ "3" ].solve == 61 );
	assert( [ "4" ].solve == 230 );
	assert( [ "100" ].solve == 388130742 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	const M = 10L ^^ 9 + 7;
	const ACGT = "ACGT";
	
	// dp[ i .. i+3文字目 ][ i文字目の文字 ][ i+1文字目の文字 ][ i+2文字目の文字 ]
	auto dp = new ModWorld!M[][][][]( n - 2, 4, 4, 4 );
	foreach( ai, a; ACGT )
	{
		foreach( bi, b; ACGT )
		{
			foreach( ci, c; ACGT )
			{
				if( [ a, b, c ] == "AGC" || [ b, a, c ] == "AGC" || [ a, c, b ] == "AGC" ) continue;
				dp[ 0 ][ ai ][ bi ][ ci ] = 1;
			}
		}
	}
	foreach( i; 0L .. dp.length.signed - 1 )
	{
		foreach( ai, a; ACGT )
		{
			foreach( bi, b; ACGT )
			{
				foreach( ci, c; ACGT )
				{
					foreach( di, d; ACGT )
					{
						if( [ a, c, d ] == "AGC" || [ a, b, d ] == "AGC" || [ b, c, d ] == "AGC" || [ c, b, d ] == "AGC" || [ b, d, c ] == "AGC" ) continue;
						dp[ i + 1 ][ bi ][ ci ][ di ] += dp[ i ][ ai ][ bi ][ ci ];
					}
				}
			}
		}
	}
	auto ans = ModWorld!M( 0L );
	foreach( ai, ac; ACGT )
	{
		foreach( bi, b; ACGT )
		{
			foreach( ci, c; ACGT )
			{
				ans += dp[ $ - 1 ][ ai ][ bi ][ ci ];
			}
		}
	}
	return ans;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	
	void opAssign( long r ){ this.n = r; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}


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

int arr[21];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int N, ans = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    for (int i = 1; i < N - 1; i++) {
        int min1 = 1e9, min2 = 1e9;
        for (int j = i - 1; j <= i + 1; j++) {
            if (arr[j] < min1) {
                min2 = min1;
                min1 = arr[j];
            } else if (arr[j] < min2) {
                min2 = arr[j];
            }
        }
        if (min2 == arr[i]) {
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
using namespace std;
const int inf = 1001001000;

//最長増加部分列の長さを返す.
int LIS(vector<int> a){
	vector<int> dp(a.size(),inf);
	for (int i = 0; i< a.size(); i++){
		dp[lower_bound(dp.begin(),dp.end(),a[i]) - dp.begin()] = a[i];
	}
	for (int i = dp.size() - 1; i >= 0;i--){
		if (dp[i] != inf) return i+1;
	}
	return 0;
}

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	cout << LIS(a) << endl;
	return 0;
}




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

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int ans=0;
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    rep(i,0,a+1){
        rep(j,0,b+1){
            rep(k,0,c+1){
                if(500*(i)+100*(j)+50*(k)==x)ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    const int count_limit = 1000000000;
    int n;
    cin >> n;

    int count_min = count_limit;
    for (int i = 0; i < n; i++) {
        int num;
        cin >> num;
        int count = 0;
        while (num % 2 == 0) {
            count ++;
            num /= 2;
        }
        if (count < count_min) {
            count_min = count;
        }
    }
    cout << count_min;


}


Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');
while (line = lines.shift()) {
	const [n, max] = line.split(' ').map(Number);
	if (n === 0 && max === 0) { break; }
	const prices = lines.shift().split(' ').map(Number);
	let temp = 0;
	for (let i = 0; i <= n; i++) {
		for (let j = 0; j <= n; j++) {
			if (!prices[i] || !prices[j] || i === j) {
				continue;
			}
			const tempCalc = prices[i] + prices[j];

			if (tempCalc <= max && tempCalc > temp) {
				// console.log(`${prices[i]} + ${prices[j]} = ${tempCalc}`)
				temp = tempCalc;
			}
		}
	}
	console.log(`${temp ? temp : 'NONE'}`)
	// temp = 0;
} 



Measured memory_bytes: 18272
package main

import "fmt"

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	answer := 0
	
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			answer = i + n/i
		}
	}
	
	fmt.Println(answer - 2)
}


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

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    vector<vector<ll>> A(3, vector<ll>(3));
    ll N;
    REP(i,0,3) REP(j,0,3) cin >> A[i][j];
    cin >> N;
    vector<ll> b(N);
    REP(i,0,N) cin >> b[i];

    vector<vector<bool>> F(3, vector<bool>(3, false));

    REP(i,0,N) {
        REP(j,0,3) {
            REP(k,0,3) {
                if(A[j][k] == b[i])
                    F[j][k] = true;
            }
        }
    }

    bool f = false;
    if (F[0][0] && F[0][1] && F[0][2]) f = true;
    if (F[1][0] && F[1][1] && F[1][2]) f = true;
    if (F[2][0] && F[2][1] && F[2][2]) f = true;
    if (F[0][0] && F[1][0] && F[2][0]) f = true;
    if (F[0][1] && F[1][1] && F[2][1]) f = true;
    if (F[0][2] && F[1][2] && F[2][2]) f = true;
    if (F[0][0] && F[1][1] && F[2][2]) f = true;
    if (F[0][2] && F[1][1] && F[2][0]) f = true;

    if(f) _PR("Yes");
    else _PR("No");

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include <iostream>

int main()
{
    int n;
    std::cin >> n;

    for (int i = 0; i < n; ++i) {
        double x1, y1, x2, y2, x3, y3, x4, y4;
        std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        double abx = x2 - x1, aby = y2 - y1, cdx = x4 - x3, cdy = y4 - y3;
        if (abx * cdy - aby * cdx == 0.0) std::cout << "YES" << std::endl;
        else std::cout << "NO" << std::endl;
    }
}

Measured memory_bytes: 1224
#include<iostream>
using namespace std;
static const int N = 100;

int main() {
    int M[N][N]; // adjecent matrix
    int n, u, k, v;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) M[i][j] = 0;
    }
    
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define    ll           long long
#define    ln           endl
#define    gap          " "
#define    in           cin
#define    out          cout
#define    yes          cout<<"YES"<<endl
#define    no           cout<<"NO"<<endl
#define    new_line     out<<endl;
#define    f(i,x,n)     for(int i=x;i<n;i++)
#define    fr(i,x,n)    for(int i=x;i>n;i--)
#define    vi           vector<int>
#define    vll          vector<ll>
using namespace std;
 
void solve()
{
 
 
}
 
int main()
{
        ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
int t;
cin>>t;
(t)?cout<<'0':cout<<'1';
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
 
int N, M, Q, p[509][509];
int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; i++) { int L, R; cin >> L >> R; p[L][R]++; }
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) p[i][j] += p[i - 1][j]; }
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) p[i][j] += p[i][j - 1]; }
 
	for (int i = 1; i <= Q; i++) {
		int L, R; cin >> L >> R;
		cout << p[R][R] + p[L - 1][L - 1] - p[L - 1][R] - p[R][L - 1] << endl;
	}
	return 0;
}


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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
int n,d,a[50][50],u,cc,ans;
int main()
{
	n=read(); d=read();
	for(int i=1;i<=n;++i)
	for(int j=1;j<=d;++j)cin>>a[i][j];
	for(int i=1;i<n;++i)
	for(int j=i+1;j<=n;++j){
		u=0;
		for(int k=1;k<=d;++k)u+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
		cc=sqrt(u+0.1);if(cc*cc==u)++ans;
	}//sqrt int   //int+dou   dou
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
 
ll const INF = 1LL<<60;
 
ll N;
ll sum[200001];
ll arr[100001];
 
ll midx;

bool C(ll d, ll S[], ll base) {
  ll p1 = lower_bound(S, S+N, d+base) - S;
  ll p2 = lower_bound(S, S+N, d+S[p1]) - S;
  if(N <= p2) return false;
  if(S[N-1] - S[p2] >= d) {
    return true;
  }
  return false;
}
 
int main() {
   
  cin >> N;
  for(int i=0; i<N; i++) {
    cin >> arr[i];
  }
   
  for(int i=0; i<N; i++) {
    sum[i] = arr[i];
    if(i) sum[i] += sum[i-1];
  }
  for(int i=N; i<2*N; i++) {
    sum[i] = arr[i-N]+sum[i-1];
  }
   
  ll ans = 0;
  for(midx=0; midx<N; midx++) {
    ll lb = 0, ub = INF;
    while(ub-lb>1) {
      ll mid = (lb+ub)/2;
      ll c;
      if(midx>0) c = sum[midx-1];
      else c = 0;
 
      if(C(mid, sum+midx, c)) {
        lb = mid;
      } else {
        ub = mid;
      }
    }
    ans = max(ans, lb);
  }
   
  cout << ans << endl;
   
  return 0;
}

Measured memory_bytes: 3504
program digits_in_multiplication
  implicit none
  integer(8) :: n, m, h, l, i
  read(*,*) n
  m = int(ceiling(sqrt(real(n,8))),8)
  h = n/2_8
  l = 0_8
  do i = m, 1_8, -1_8
    if (mod(n,i).eq.0_8) then
      l = n/i
      exit
    end if
  end do
  if (l.eq.0_8) then
    write(*,'(i0)') int(log10(real(n,8))) + 1
  else
    write(*,'(i0)') int(log10(real(l,8))) + 1
  end if
end program digits_in_multiplication

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	int a[50], b[50];
	bool e[51][51] = {};
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		e[a[i]][b[i]] = e[b[i]][a[i]] = true;
	}
	int c = 0;
	for (int i = 0; i < M; i++) {
		e[a[i]][b[i]] = e[b[i]][a[i]] = false;
		int d[51] = {};
		queue<int> q;
		q.push(*a);
		while (!q.empty()) {
			int i = q.front();
			q.pop();
			if (d[i]) continue;
			d[0]++;
			d[i] = 1;
			for (int j = 1; j <= N; j++)
				if (e[i][j]) q.push(j);
		}
		c += *d < N;
		e[a[i]][b[i]] = e[b[i]][a[i]] = true;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
open Batteries

let () =
  let n = Scanf.scanf "%s " (fun a -> a) in
  let digits = String.to_list n |> List.map (fun x -> int_of_char x - 48)  in
  let sum = List.fold_left (+) 0 digits in

  Printf.printf "%d\n" (if sum = 1 then 10 else sum)



Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

std::vector<long long> split()
{
	std::vector<long long> res;
	std::string line;
	std::getline(std::cin, line, '\n');

	std::string item;

	for (long long n = 0; n < line.size(); ++n)
	{
		if (line.at(n) == ' ')
		{
			if (!item.empty())
				res.push_back(std::stoll(item));

			item.clear();
		}

		else
		{
			item += line.at(n);
		}
	}

	if (!item.empty())
		res.push_back(std::stoll(item));

	return res;
}

std::vector<std::vector<long long> > mul(const std::vector<std::vector<long long> >& A, const std::vector<std::vector<long long> >& B)
{
	std::vector<std::vector<long long> > result;

	for (long long ay = 0; ay < A.size(); ++ay)
	{
		std::vector<long long> nl;
		for (long long bx = 0; bx < B[0].size(); ++bx)
		{
			long long sum = 0;
			for (long long ax = 0; ax < A[0].size(); ++ax)
			{
				sum += A[ay][ax] * B[ax][bx];
			}

			nl.push_back(sum);
		}

		result.push_back(nl);
	}

	return result;
}

int main()
{
	auto a = split();
	int n, m, l;
	int* arr[3] = { &n, &m, &l };
	for (int x = 0; x < 3; ++x)
		*(arr[x]) = a[x];

	std::vector<std::vector<long long> > A;
	std::vector<std::vector<long long> > B;

	for (int y = 0; y < n; ++y)
	{
		A.push_back(split());
	}

	for (int y = 0; y < m; ++y)
	{
		B.push_back(split());
	}

	std::vector<std::vector<long long> > result = mul(A, B);

	for (long long ac = 0; ac < result.size(); ++ac)
	{
		for (long long bc = 0; bc < result[ac].size(); ++bc)
		{
			std::cout << result[ac][bc];

			if (bc == result[ac].size() - 1)
				std::cout << std::endl;
			else
				std::cout << " ";
		}
	}

	return 0;
}


Measured memory_bytes: 3308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int count =0;
		for (int i=0;i<4;i++) {
			if (s.charAt(i)=='2') {
				count++;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  map<int, ll> counter;
  FOR(i, 1, 182) {
    counter[i*i]++;
    FOR(j, i, 182) {
      if (i*i+j*j > 1<<15) break;
      counter[i*i+j*j]++;
      FOR(k, j, 182) {
        if (i*i+j*j+k*k > 1<<15) break;
        counter[i*i+j*j+k*k]++;
        FOR(l, k, 182) {
          if (i*i+j*j+k*k+l*l > 1<<15) break;
          counter[i*i+j*j+k*k+l*l]++;
        }
      }
    }
  }

  while (1) {
    int n; cin >> n;
    if (not n) break;
    cout << counter[n] << endl;
  }
  return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int a,b;
    cin >> a >> b;
    cout << (a+b)%24 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int n, ans=0,tmp=0;
    cin >> n;
    vi h(n);
    rep(i, n){
        cin >> h[i];
        if(i>0){
            if(h[i-1]>=h[i]){
                tmp++;
                ans = max(ans, tmp);
            }
            else{
                tmp = 0;
            }
        }
    }
    cout << ans << endl; 

}

Measured memory_bytes: 640
from itertools import combinations as cb
node = []
n,x,y = map(int, input().split())
for i in range(1, n+1):
  node.append(i)
pair = list(cb(node, 2))
dist = [0]*n
for a in pair:
  if a[1] <= x or a[0] >= y:
    dist[a[1]-a[0]] += 1
  else:
    dist[min(abs(x-a[0])+abs(y-a[1])+1,a[1]-a[0])] += 1
for i in range(1, n):
  print(dist[i])

Measured memory_bytes: 147900
s = input() + 'R'
n = len(s) - 1
cs = [0] * n
last_l = -1
last_r = None
for i in range(n):
  if s[i] == 'R' and s[i + 1] == 'L':
    last_r = i
  if s[i] == 'L' and s[i + 1] == 'R':
    cs[last_r] += (last_r - last_l + 1) // 2 + (i - last_r) // 2
    cs[last_r + 1] += i - last_l - cs[last_r]
    last_l = i

print(' '.join(map(str, cs)))

Measured memory_bytes: 10484
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
constexpr ll MOD = 1e9 + 7;



int main(){
    int h, a;
    cin >> h >> a;
    cout<< h/a+(h%a!=0) << endl;
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
#define HYPP(x) hypot(x.first,x.second)

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;



int main() {
	string Sa, Sb, Sc;
	cin >> Sa;
	cin >> Sb;
	cin >> Sc;
	int a = 0, b = 0, c = 0;
	char turn = 'a';
	while (true) {
		switch (turn)
		{
		case 'a':
			if (Sa.size() == a) {
				cout << "A" << endl;
				return 0;
			}
			turn = Sa[a];
			a++;
			break;
		case 'b':
			if (Sb.size() == b) {
				cout << "B" << endl;
				return 0;
			}
			turn = Sb[b];
			b++;
			break;
		case 'c':
			if (Sc.size() == c) {
				cout << "C" << endl;
				return 0;
			}
			turn = Sc[c];
			c++;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define OK { cout << "OK" << endl; return 0; }
#define NG { cout << "NG" << endl; return 0; }
#define sz(v) ((int)(v).size())
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void out(T a){cout << a << endl;}
template<class T>void die(T a){cout << a << endl; exit(0);}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

#define SIZE 200005
#define MOD 1000000007
 
typedef pair <int,int> P;
 
ll inv[SIZE], fac[SIZE], finv[SIZE];
void make(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<SIZE; i++)
	{
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
    return ;
}
ll comb(int a,int b){
	if(a < b) return 0;
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}



ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
    
  int a; cin >> a;
  out(a + a *a + a*a*a);
	
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    stack<char> st;
    st.push('A');
    rep(i,Size(s)){
        if(s[i]=='S')st.push('S');
        else{
            if(st.top()=='S'){
                st.pop();
            }
            else{
                st.push(s[i]);
            }
        }
    }
    Cout(Size(st)-1);
    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  
  for (int i = A; i <= B; i++){
    string I = std::to_string(i);
    
    if (I.at(0) == I.at(4)
        && I.at(1) == I.at(3)){
      count++;
    }
  }
    
  cout <<  count << endl;    
 }


Measured memory_bytes: 256
use std::fmt::Debug;
use std::str::FromStr;

#[allow(dead_code)]
#[allow(deprecated)]
fn read_line_from_stdin() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    buffer.trim_right().to_owned()
}

#[allow(dead_code)]
#[allow(deprecated)]
fn parse_line_to_single<T>() -> T
where
    T: FromStr,
    T::Err: Debug,
{
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    T::from_str(buffer.trim_right()).unwrap()
}

#[allow(dead_code)]
#[allow(deprecated)]
fn parse_line_to_multiple<T>() -> Vec<T>
where
    T: FromStr,
    T::Err: Debug,
{
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    buffer
        .trim_right()
        .split_whitespace()
        .flat_map(|s| T::from_str(s))
        .collect()
}

macro_rules! parse_line {
    [$( $x:tt : $t:ty ),+] => {
        //declare variables
        $( let $x: $t; )+
        {
            use std::str::FromStr;
            // read
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            #[allow(deprecated)]
            let mut splits = buf.trim_right().split_whitespace();
            // assign each variable
            $(
                $x = splits.next().and_then(|s| <$t>::from_str(s).ok()).unwrap();
            )+
            // all strs should be used for assignment
            assert!(splits.next().is_none());
        }
    };
}

use std::collections::HashSet;

fn main() {
    parse_line![_town_count: usize, desired_move_count: usize];

    let transporters = parse_line_to_multiple::<usize>();

    let mut current_town = 1;
    let mut move_histories = vec![];
    let mut visited_towns=HashSet::new();

    loop {
        if move_histories.len() == desired_move_count {
            println!("{}", current_town);
            break;
        }
        if visited_towns.contains(&current_town) {
            let remaining_movement = desired_move_count - move_histories.len();

            let first_loop_index = {
                let mut i = 0;
                loop {
                    if move_histories[i] == current_town {
                        break;
                    }
                    i += 1;
                }
                i
            };

            let loop_length = move_histories.len() - first_loop_index;
            let index_diff = remaining_movement % loop_length;
            let final_town = move_histories[first_loop_index + index_diff];
            println!("{}", final_town);
            break;
        }
        move_histories.push(current_town);
        visited_towns.insert(current_town);
        let town_index = current_town - 1;
        current_town = transporters[town_index];
    }
}


Measured memory_bytes: 8344
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
    string s;
    long long k;
    double sum=0;
    int r = 1;
    cin >> s;
    cin >> k;
    for(long long i=0; i<k; i++){
        if( s[i] != '1' ) { r = s[i]-'0'; break;}
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		int[] array = new int[3];

		for(int i=0;i<3;i++) {
			array[i] = sc.nextInt();
		}

		int tmp;

		for(int i=0;i<3;i++) {
			for(int j=i+1;j<3;j++) {
				if(array[j]<array[i]) {
					tmp = array[j];
					array[j] = array[i];
					array[i] = tmp;
				}
			}
		}

		for(int i=0;i<3;i++) {
			System.out.print(array[i]);
			if(i!=2) {
				System.out.print(" ");
			}
		}
		System.out.println();

		sc.close();
	}
}


Measured memory_bytes: 26144
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const int MAX = 2000 ;

int N,M;
int a[MAX];

int main()
{

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

    int sum = 0;
    int flag = 1;
    while(1)
    {
        for(int i = 1;i<=N;i++)
        {
            if(a[i]%2==0)
                a[i] = a[i]/2;
            else
            {
                flag = 0;
                break;
            }
        }
        if(flag==0)
            break;
        sum++;
    }

    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin>>n;
    int cnt=0;
    int arr[n],mex=n+2;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(mex>=arr[i]) cnt++;
        mex=min(mex,arr[i]);
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str,str1;
        int n[] = new int[26];
        char c = 'a';
        while((str = br.readLine())!=null){
            str1 = str.toLowerCase();
            for(int i=0;i<str1.length();i++){
                int a = str1.charAt(i);
                if(Character.isAlphabetic(a)){
                    n[a-c]++;
                }
            }
        }
        for(int i=0;i<n.length;i++){
            System.out.println(c++ +" : "+n[i]);
        }
    }
}

Measured memory_bytes: 24000
#include<iostream>
#include<vector>
#include<map>
#include<tuple>
#include<set>
#include<cmath>
#include<numeric>
#define ll long long
#define MOD = 1e9+7
 
using namespace std;

int main(){
  int K;
  string S;
  cin >> K >> S;
  if(S.size() > K){
    for(int i=0;i<K;i++){
      cout << S[i];
    }

    cout << "..." << endl;
  }else{
    cout << S << endl;
  }
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define ll long long
#define MAX 5000005
using namespace std;

int n;
string s;

int main()
{
    cin >> s;
    int flag = 1;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '7')flag = 0;
    }
    if(flag) puts("No");
    else puts("Yes");

    return 0;
}


Measured memory_bytes: 3596
import java.util.*;


public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] lines = line.split(" ", 0);
        long a = Long.parseLong(lines[0]);
        long b = Long.parseLong(lines[1]);
        long c = Long.parseLong(lines[2]);
        long d = Long.parseLong(lines[3]);
        
        long x1 = a * c;
        long x2 = a * d;
        long x3 = b * c;
        long x4 = b * d;

        System.out.println(Math.max(Math.max(x1, x2), Math.max(x3, x4)));
    }
}

Measured memory_bytes: 35656
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = accumulate(a.begin(), a.begin() + K, 0);
    cout << ans << '\n';
}


Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    while (cin >> n) {
        if (n == 1) {
            cout << 0 << endl;
            continue;
        }
        
        vector<bool> is_prime(n + 1, true);
        is_prime[0] = false; is_prime[1] = false;
        for (int i = 2; i <= n; i++) {
            if (is_prime[i]) {
                for (int j = 2 * i; j <= n; j += i) {
                    is_prime[j] = false;
                }
            }
        }
        
        int ans = 0;
        for (int i = 0; i <= n; i++) {
            if (is_prime[i]) ans++;
        }
        cout << ans << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3240
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

struct UnionFind{
    /// 最小構成UnionFind木
    P: Vec<usize>,
}

impl UnionFind {
    fn new(n:usize) -> UnionFind{
        UnionFind {P:(0..n).collect()}
    }
    fn get_parent(&mut self,n:usize) -> usize{
        if self.P[n] == n{ return n;}
        let p = self.P[n];
        self.P[n] = self.get_parent(p);
        self.P[n]
    }
    fn is_unite(&mut self,x:usize,y:usize) -> bool{
        self.get_parent(x)==self.get_parent(y)
    }
    fn merge(&mut self,x:usize,y:usize){
        if self.is_unite(x,y) {return;}
        let i = self.get_parent(x);
        let j = self.get_parent(y);
        self.P[j] = i;
    }
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let N:usize = iter.next().unwrap().parse().unwrap();
    let K:usize = iter.next().unwrap().parse().unwrap();
    let L:usize = iter.next().unwrap().parse().unwrap();
    let mut T1 = UnionFind::new(N);
    for _ in 0..K{
        let p:usize = iter.next().unwrap().parse::<usize>().unwrap() -1;
        let q:usize = iter.next().unwrap().parse::<usize>().unwrap() -1;
        T1.merge(p,q);
    }
    let mut T2 = UnionFind::new(N);
    for _ in 0..L{
        let p:usize = iter.next().unwrap().parse::<usize>().unwrap() -1;
        let q:usize = iter.next().unwrap().parse::<usize>().unwrap() -1;
        T2.merge(p,q);
    }
    let mut cnt = HashMap::new();
    for i in 0..N{
        let p = T1.get_parent(i);
        let q = T2.get_parent(i);
        let k = (p,q);
        let c = *(cnt.get(&k).unwrap_or(&0));
        cnt.insert(k, c+1);
    }
    for i in 0..N{
        let p = T1.get_parent(i);
        let q = T2.get_parent(i);
        let k = (p,q);
        let ans = cnt.get(&k).unwrap();
        println!("{}",ans);
    }

}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define fi first
#define se second
#define int long long
typedef pair<int,int> P;


std::vector<int> r;
std::vector<P> pp;
P find(int x){
  while(x!=pp[x].first)x=pp[x].first;
  return pp[x];
}
bool same(int x,int y){
  return find(x).first==find(y).first;
}
void unite(int x,int y){
  x=find(x).first;y=find(y).first;
  if(x==y) return;
  if(r[x]<r[y]) swap(x,y);
  r[x]+=r[y];
  int a=pp[x].second+pp[y].second;
  pp[x].second=pp[y].second=a;
  pp[y].first=x;
}


signed main(){
  int N,M;cin>>N>>M;
  std::vector<int> a(M),b(M);
  for(int i=0;i<M;i++)cin>>a[i]>>b[i];
  r.resize(N);
  for(int i=0;i<N;i++)r[i]=1;
  pp.resize(N);
  for(int i=0;i<N;i++)pp[i]=P(i,1);
  std::vector<int> ans;
  int w=N*(N-1)/2;
  for(int i=M-1;i>=0;i--){
    ans.push_back(w);
    if(find(a[i]).first==find(b[i]).first)continue;
    w-=find(a[i]).second*find(b[i]).second;
    unite(a[i],b[i]);
  }
  reverse(ans.begin(),ans.end());
  for(auto e:ans)cout<<e<<endl;
}


Measured memory_bytes: 6132
object Main extends App{
  val l1 = io.StdIn.readLine()
  val N = l1.split(" ")(0).toInt
  val L = l1.split(" ")(1).toInt

  val words = (0 until N).map((i) => {
    io.StdIn.readLine()
  })

  println(words.sorted.mkString(""))
}


Measured memory_bytes: 21572
#include<iostream>
#include<complex>

using namespace std;

typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) <EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

double cross(P a, P b) {
	  return (a.real() * b.imag() - a.imag() * b.real());
}
int is_intersected_ls(P a1, P a2, P b1, P b2) {
	  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
		           ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

int main(void){
	P A,B,C,P,O;

	while(cin>>A.real()>>A.imag()>>B.real()>>B.imag()>>C.real()>>C.imag()>>P.real()>>P.imag()){
		O.real()=(A.real()+B.real()+C.real())/3;//ツ三ツ角ツ形ツづ個陳心
		O.imag()=(A.imag()+B.imag()+C.imag())/3;
		if(is_intersected_ls(O,P,A,B)){
			cout<<"NO"<<endl;
			continue;
		}
		if(is_intersected_ls(O,P,A,C)){
			cout<<"NO"<<endl;
			continue;
		}
		if(is_intersected_ls(O,P,C,B)){
			cout<<"NO"<<endl;
			continue;
		}
		cout<<"YES"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll a,b,c;
  cin>>a>>b>>c;
  if(a==b+c||b==c+a||c==a+b){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
      
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main()
{
    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x,t;
    cin>>x;
    t=x/500*1000+((x%500)/5)*5;
    cout<<t;
}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int n;
  while(cin >> n, n) {
    int f[12][12] = {};
    rep(i, n) {
      rep(j, n) {
        cin >> f[i][j];
        f[i][n] += f[i][j];
        f[n][j] += f[i][j];
        f[n][n] += f[i][j];
      }
    }

    rep(i, n+1) {
      rep(j, n+1) {
        printf("%5d", f[i][j]);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1184
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
	static PrintWriter out = new PrintWriter(System.out);
	static FastScanner sc = new FastScanner();
	static Scanner stdIn = new Scanner(System.in);
	static int n;
	static int m;
	static int k;
	public static void main(String[] args) {
		while(true) {
			n = sc.nextInt();
			m = sc.nextInt();
			k = sc.nextInt();
			if(n == 0 && m == 0 && k == 0) break;
			long sum = dfs(0,0);
			double ans = sum;
			ans /= Math.pow(m, n);
			
			out.println(ans);
			
		}
		out.flush();
	}
	
	public static long dfs(long a, long b) {
		if(a == n) {
			if(b - k <= 0) return 1;
			else           return b-k;
		}
		else {
			long sum = 0;
			for(int i = 1; i <= m; i++) {
				sum += dfs(a+1,b+i);
			}
			return sum;
		}
		
	}
}


//-----------------Template------------------//
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	 
	public int nextInt() {
		 if (!hasNext()) throw new NoSuchElementException();
		 int n = 0;
		 boolean minus = false;
		 int b = readByte();
		 if (b == '-') {
			 minus = true;
			 b = readByte();
		 }
		 if (b < '0' || '9' < b) {
			 throw new NumberFormatException();
		 }
		 while(true){
			 if ('0' <= b && b <= '9') {
				 n *= 10;
				 n += b - '0';
			 }else if(b == -1 || !isPrintableChar(b)){
				 return minus ? -n : n;
			 }else{
				 throw new NumberFormatException();
			 }
			 b = readByte();
		 }
	}
	 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	 
 
}

Measured memory_bytes: 18816
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
void Yay(bool condition){

    if(condition){
        p("Yay!");
    }else{
        p(":(");
    }
    return;
}

//ll fact[800005],rfact[800005];
/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[500005];
char s[500005],t[500005];

bool flag,dame;




int main(){
	cin >> n >> k;
	if(k == 1){
		p(0);
	}else{
		p(n-k);
	}

	

	return 0;
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	ll ans = 0;
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		if (u > v)swap(u, v);
		ans += ((ll)i + 1) * (n - i);
		ans -= u * ((ll)n - v + 1);
	}
	ans += n;
	cout << ans << endl;
}

Measured memory_bytes: 3608
s = int(input())
a = [s]
for i in range(10000):
    if a[i] %2 == 0:
        b = a[i]//2
        if b in a:
            print(i+2)
            exit()
        a.append(b)
    else:
        b = 3*a[i]+1
        if b in a:
            print(i+2)
            exit()
        a.append(b)

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define int long long


class ATravelingBudget {
public:
	void solve(std::istream& in, std::ostream& out) {
    int a,b,c,d;
    in >> a >> b >> c >> d;
    out << min(a, b) + min(c, d) << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	ATravelingBudget solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3580
#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(void) {
    string a, b, c; 
    cin >> a >> b >> c;
    a[0] = 'A'+a[0]-'a';
    b[0] = 'A'+b[0]-'a';
    c[0] = 'A'+c[0]-'a';
    cout << a[0] << b[0] << c[0];
}


Measured memory_bytes: 256
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

		public static void main(String[] args){
			
			Scanner sc = new Scanner(System.in);

			int X = sc.nextInt();
			int Y = sc.nextInt();
			int Z = sc.nextInt();

			X = X - Z;
			int hito = Y + Z;
			int ans1 = X / hito ;
			int work = X % hito;
			if (work < X){
				System.out.println(ans1);
			}else{	
				System.out.println(ans1 + 1);
			}


		}
}


Measured memory_bytes: 22740