akhauriyash/Code-Regression huggingface dataset:
def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    b = [None] * N
    i = 0
    j = N - 1
    n = 1
    for k in range(N-1, -1, -1):
        if n & 1:
            b[i] = A[k]
            i += 1
        else:
            b[j] = A[k]
            j -= 1
        n += 1

    print(*b, sep=' ')

main()


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

using ll = long long;

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

    ll x,y;
    cin>>x>>y;

    ll cnt=1;

    while(x*2<=y)
    {
        cnt++;
        x*=2;
    }

    cout<<cnt<<"\n";

    return 0;
}


Measured memory_bytes: 3616
#include<iostream>

using namespace std;

int main(){
  string in;
  getline(cin,in);
  in += "\n";
  string out = "";
  int status = 0;
  for(int i = 0; i < in.length(); i++){
    if(in[i] == ' ' || in[i] == '.' || in[i] == ',' || in[i] == '\n'){
      if(out.length() >= 3 && out.length() <= 6){
	if(status) cout << " ";
	cout << out;
	status = 1;
      }
      out = "";
    }else out += in[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 0
import math
Q = int(input())
for i in range(Q):
    a = list(map(int,input().split()))
    a.sort()
    A = a[0]
    B = a[1]
    n = 0
    if A==B:
        n = 2*A-2
    elif B == A+1:
        n = 2*A-2
    else:
        C = math.ceil(math.sqrt(A*B)-1)
        if C*(C+1)>=A*B:
            n = 2*C-2
        else:
            n = 2*C-1
    print(n)

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

int ans[2000], tot;

int main() {
    long long n;
    scanf("%lld", &n);
    while (n) {
        ans[++tot] = (n-1)%26; n = (n-1)/26;
    }
    for (int i = tot; i >= 1; i--)
        putchar('a'+ans[i]);
    return 0;
}


Measured memory_bytes: 3760
import java.awt.geom.Point2D;
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ2151();
	}
	class AOJ2151{
		int N,M,L;
		final int INF=1<<28;
		AOJ2151(){
			while(true){
				N=sc.nextInt(); M=sc.nextInt(); L=sc.nextInt();
				if(N==0)	break;
				solve();
			}
		}
		void solve(){
			ArrayList<ArrayList<Edge>> map=new ArrayList<ArrayList<Edge>>(N);
			for(int i=0; i<N; ++i)	map.add(new ArrayList<Edge>());
			for(int i=0; i<M; ++i){
				int a=sc.nextInt(),b=sc.nextInt(),d=sc.nextInt(),e=sc.nextInt();
				--a; --b;
				map.get(a).add(new Edge(b,d,e));
				map.get(b).add(new Edge(a,d,e));
			}
			
			PriorityQueue<State> open=new PriorityQueue<State>();
			open.add(new State(0,L,0));
			int[][] closed=new int[N][L+1];
			for(int i=0; i<N; ++i)for(int j=0; j<=L; ++j)	closed[i][j]=INF;
			closed[0][L]=0;
			int ans=-1;
			while(!open.isEmpty()){
				State now=open.poll();
				if(now.p==N-1){
					ans=now.e;
					break;
				}
				for(Edge to: map.get(now.p)){
					if(now.m>=to.d && closed[to.p][now.m-to.d]>now.e){
						open.add(new State(to.p, now.m-to.d, now.e));
						closed[to.p][now.m-to.d]=now.e;
					}
					if(closed[to.p][now.m]>now.e+to.e){
						open.add(new State(to.p, now.m, now.e+to.e));
						closed[to.p][now.m]=now.e+to.e;
					}
				}
			}
			System.out.println(ans);
		}
		class Edge{
			int p,d,e;
			Edge(int p,int d,int e){
				this.p=p;	this.d=d;	this.e=e;
			}
		}
		class State implements Comparable<State>{
			int p,m,e;
			State(int p,int m,int e){
				this.p=p;	this.m=m;	this.e=e;
			}
			@Override public int compareTo(State o){
				return this.e-o.e;
			}
		}
	}
}

Measured memory_bytes: 61988
s = input()
mid = len(s)//2
ans = 0
s_ = []
for i in range(len(s)-1,mid-1,-1):
    s_ += s[i]
s_ = ''.join(map(str,s_))
for i in range(mid):
    if s_[i] != s[i]:
        ans += 1
print(ans)

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

public class Main {

	public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
        String s = r.readLine();
        int n = Integer.parseInt(s);
        s = r.readLine();
        String[] sl = s.split("[\\s]+");
        int a[] = new int[1000];
        for(int i = 0; i < n; i++)
        {
        	a[i] = Integer.parseInt(sl[i]);
        }
        
        int c = 99999999;
        for(int i = -100; i <= 100; i++)
        {
        	int v = 0;
        	for(int j = 0; j < n; j++)
        	{
        		v += (i - a[j]) * (i - a[j]);
        	}
        	c = Math.min(c, v);
        }
        
        System.out.println(c);
	}

}


Measured memory_bytes: 22868
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*int r;
	cin >> r;
	cout << r * r;*/


	int n;
	string s;
	cin >> n >> s;
	if (n % 2 == 1) {
		puts("No");
		return 0;
	}
	if (s.substr(0, n / 2) == s.substr(n / 2, n / 2)) {
		puts("Yes");
		return 0;
	}
	else {
		puts("No");
	}
	return 0;
}

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

/*
真上から見て
l : 左, r : 右
f : 前, b : 後ろ
d : 下, u : 上
*/

struct Dice
{
    int l, r, f, b, d, u;

    void RollN()
    {
        int buff = d;
        d = f, f = u, u = b, b = buff;
    }
    void RollS()
    {
        int buff = d;
        d = b, b = u, u = f, f = buff;
    }
    void RollW()
    {
        int buff = d;
        d = l, l = u, u = r, r = buff;
    }
    void RollE()
    {
        int buff = d;
        d = r, r = u, u = l, l = buff;
    }
    void RollR()
    {
        int buff = f;
        f = r, r = b, b = l, l = buff;
    }
    void RollL()
    {
        int buff = f;
        f = l, l = b, b = r, r = buff;
    }
};

/*
0 -> 上, 1-> 後ろ
2 -> 右, 3-> 左
4 -> 前, 5-> 下
*/

Dice meke_dice(int a[6])
{
    Dice dice;
    dice.u = a[0], dice.b = a[1], dice.r = a[2], dice.l = a[3], dice.f = a[4], dice.d = a[5];
    return dice;
}

//p : 上面,　q : 後面
void set_dice(Dice &dice, int p, int q)
{
    for (int i = 0; i < 7; i++)
    {
        if (i < 4)
            dice.RollE();
        else
            dice.RollN();
        if (p == dice.u)
            break;
    }
    for (int i = 0; i < 4; i++)
    {
        dice.RollR();
        if (q == dice.b)
            break;
    }
}
int main()
{
    int a[6], q;
    for (int i = 0; i < 6; i++)
        cin >> a[i];
    Dice dice = meke_dice(a);
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int s, t;
        cin >> s >> t;
        set_dice(dice, s, t);
        cout << dice.r << endl;
    }
}


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

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

// Graph
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<ll> a(N);
  for (auto &it : a)
    cin >> it;
  ll xorsum = a[0];
  for (int i = 1; i < N; i++)
    xorsum ^= a[i];
  vector<ll> ans(N);
  for (int i = 0; i < N; i++)
  {
    ans[i] = xorsum ^ a[i];
  }
  for (auto it : ans)
    cout << it << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 6380
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)



void solve() {
	long n;
  cin >> n;
  if(n%1000)
  cout<<(1000-n%1000)<<endl;
  else
    cout<<0<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tc=1;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

bool isSq(int n){
    int k = sqrt(n);
    return Sq(k) == n || Sq(k-1) == n || Sq(k+1) == n;
}

int main(void){
    Cin(int, n, d);
    vc<vc<int>> x(n, vc<int>(d, 0));
    For(i, n) For(j, d) cin >> x[i][j];
    
    int ans = 0;
    For(i, n){
        for(int j = i+1; j < n; j ++){
            int a = 0;
            For(k, d) a += Sq(x[i][k] - x[j][k]);
            if(isSq(a)) ans ++;
        }
    }
    Cout(ans);
}




Measured memory_bytes: 256
from heapq import heappush, heappop


N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort()

if N >= M:
    print(0)
    exit()

q1 = []

for i in range(M - 1):
    sec = X[i + 1] - X[i]
    heappush(q1, (-sec, i + 1))

q2 = []
for n in range(N - 1):
    sec, idx = heappop(q1)
    heappush(q2, idx)

heappush(q2, M)
cur = 0
ans = 0
for n in range(N):
    idx = heappop(q2)
    ans += X[idx - 1] - X[cur]
    cur = idx

print(ans)


Measured memory_bytes: 18000
#include<stdio.h>

int main(){

  int i,j,n,s,count=0,a[101];


  //load N
  scanf("%d",&n);
  //load number
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }

  //Algorithm
  for(i=1;i<=n;i++){
    for(j=n;j>=i+1;j--){
      //swap
      if(a[j]<a[j-1]){
	s=a[j];
	a[j]=a[j-1];
	a[j-1]=s;
	count++;
      }
    }
  }


  //primt number
    for(i=1;i<=n;i++){
      printf("%d",a[i]);
      if(i!=n){
	printf(" ");
      }
    }

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

  return 0;

}

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

int a[200200];
int main() {
  int n;
  cin >> n;
  for(int i=0; i<n; i++) {
    int x,y;
    cin >> x >> y;
    a[x+y]++;
  }
  for(int i=0; i<200100; i++) {
    a[i+1]+=a[i]/2;
    a[i]%=2;
    if(a[i]) cout << i << " " << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 3868
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int sum = 0;
		StringBuilder out = new StringBuilder();

		// 標準入力
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			String words = sc.next();

			if (words.equals("0"))
				break;

			char ch[] = words.toCharArray();

			//
			sum = 0;
			for (int i = 0; i < ch.length; i++) {
				//
				String str = String.valueOf(ch[i]);
				int num = Integer.parseInt(str);
				sum += num;
			}
			out = new StringBuilder(out + (sum + "\n"));
		}

		// 結果出力
		System.out.print(out);

	}

}

Measured memory_bytes: 18484
#include <stdio.h>

int main(void)
{
	int a, b;
	int flag = 0;
	int i;
	i = 0;
	while (1){
		flag = 0;
		scanf("%d %d", &a, &b);
			if (a + b == 0){
				break;
			}
			else {
				if (i != 0) {
					printf("\n");
				}
			}
			i++;
			
			while (a <= b){
				if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0){
					printf("%d\n", a);
					flag = 1;
				}
				a++;
			}
			if (flag == 0){
				printf("NA\n");
			}
	
	}
	
	return (0);
}

Measured memory_bytes: 616
count = gets.to_i
cards = gets.chomp.split(' ').map(&:to_i)
sorted_cards = cards.sort.reverse
alice_sum = 0
bob_sum = 0
sorted_cards.each.with_index(1) do |card, i|
  alice_sum += card if i % 2 != 0
  bob_sum += card if i % 2 == 0
end
p alice_sum - bob_sum


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;cin>>h>>w;
    ll hw=h*w;
    ll mini=h*w;
    for(int i=1;i<h;i++){
        ll s[3];
        s[0]=w*i;
        s[1]=(h-i)/2*w;
        s[2]=hw-s[0]-s[1];
        sort(s,s+3);
        mini=min(mini,s[2]-s[0]);
        s[0]=w*i;
        s[1]=w/2*(h-i);
        s[2]=hw-s[0]-s[1];
        sort(s,s+3);
        mini=min(mini,s[2]-s[0]);
    }
    for(int i=1;i<w;i++){
        ll s[3];
        s[0]=h*i;
        s[1]=(w-i)/2*h;
        s[2]=hw-s[0]-s[1];
        sort(s,s+3);
        mini=min(mini,s[2]-s[0]);
        s[0]=h*i;
        s[1]=h/2*(w-i);
        s[2]=hw-s[0]-s[1];
        sort(s,s+3);
        mini=min(mini,s[2]-s[0]);
    }
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=5010;
const int mod=1e9+7;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int qpow(int a,int b) {
	int ret=1;
	while(b) {
		if(b&1) ret=1ll*ret*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}
	return ret;
}

int f[N],p[N],fa[N],siz[N],new_f[N],fac[N],n;
bool cyc[N];

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

void merge(int x,int y) {
	x=getf(x);y=getf(y);
	if(x!=y) fa[x]=y,siz[y]+=siz[x]; else cyc[x]=1;
}

int main() {
	cin>>n;
	fac[0]=1;
	for(int i=1;i<=n;i++) fa[i]=i,siz[i]=1,fac[i]=1ll*fac[i-1]*i%mod;
	int cnt=0;
	for(int i=1;i<=n;i++) {
		p[i]=gi();
		if(p[i]!=-1) merge(i,p[i]);
		else ++cnt;
	}
	int ans=0;
	//for(int i=1;i<=n;i++)
	//if(getf(i)==i) cerr<<siz[i]<<' '<<cyc[i]<<'\n';
	for(int i=1;i<=n;i++)
		if(getf(i)==i) {
			if(cyc[i]) ans=(ans+qpow(n-1,cnt))%mod;
			else ans=(ans+1ll*qpow(n-1,cnt-1)*(siz[i]-1))%mod;
		}
	f[0]=1;
	for(int i=1;i<=n;i++)
		if(getf(i)==i&&!cyc[i]) {
			memset(new_f,0,sizeof(new_f));
			for(int j=0;j<=n;j++) {
				new_f[j]=(new_f[j]+f[j])%mod;
				new_f[j+1]=(new_f[j+1]+1ll*f[j]*siz[i])%mod;
			}
			memcpy(f,new_f,sizeof(f));
		}
	for(int i=2;i<=cnt;i++) ans=(ans+1ll*fac[i-1]*f[i]%mod*qpow(n-1,cnt-i))%mod;
	ans=(1ll*qpow(n-1,cnt)*n-ans+mod)%mod;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3728
import io.StdIn.readLine

object Main extends App {
  val Array(h, w) = readLine.split(" ").map(_.toInt)
  val pict = Seq.fill(h)(readLine).map("#" ++ _ ++ "#")

  println(("#" * (w + 2) +: pict :+ "#" * (w + 2)).mkString("\n"))
}


Measured memory_bytes: 27316
h,w=map(int,input().split())
r=1e9
f=lambda x:max(x)-min(x)
for _ in 'aa':
    for i in range(1,h):
        p=[j if j else -1e9for j in[i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]]
        q=[j if j else -1e9for j in[i*w,(h-i)*(w//2),(h-i)*(w-w//2)]]
        r=min(min(r,f(p)),f(q))
    h,w=w,h
print(r)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main(){
  int n,l;
    cin >> n >> l;
  vector<string> s(n);
  string ans;

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

  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      if(s[i] < s[j]){
        s[i].swap(s[j]);
      }
    }
  }
  for(int i = 0 ; i < n ; i++){
    ans = ans +s[i];
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
// 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 all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
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; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int W, H;
  while (cin >> W >> H, W) {
    vs v(H);
    rep(i, H) cin >> v[i];
    vvi dp(H, vi(W));
    int b = 0, w = 0;
    rep(i, H) rep(j, W) {
      dp[i][j] = 2 * (v[i][j] == 'B') + (v[i][j] == 'W');
      b -= v[i][j] == 'B';
      w -= v[i][j] == 'W';
    }
    rep(_, W * H) rep(i, H) rep(j, W) {
      if (v[i][j] != '.') continue;
      if (i > 0) dp[i][j] |= dp[i - 1][j];
      if (j > 0) dp[i][j] |= dp[i][j - 1];
      if (i < H - 1) dp[i][j] |= dp[i + 1][j];
      if (j < W - 1) dp[i][j] |= dp[i][j + 1];
    }
    rep(i, H) rep(j, W) {
      b += dp[i][j] == 2;
      w += dp[i][j] == 1;
    }
    cout << b << ' ' << w << endl;
  }
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int cnt,n;
char p[70],s[137];
int sum[70],id[137];
string solve(int l,int r){
	if(l==r){
		string s;
		for(int i=1;i<=sum[l];++i) s+=p[l];
		return s;
	}
	const int mid=l+r>>1;
	string a=solve(l,mid),b=solve(mid+1,r);
	if(a.empty()||b.empty()) return a+b;
	for(int i=0,j=0,x;i<b.size();++i,++j){
		while(j<a.size()){
			a.insert(a.begin()+j,b[i]);
			cout<<"? "<<a<<endl;
			scanf("%d",&x); a.erase(a.begin()+j);
			if(x+a.size()+1==n) break; ++j;
		}
		a.insert(a.begin()+j,b[i]);
	}
	return a;
}
int main(){
	for(int i='a';i<='z';++i) p[++cnt]=i,id[i]=cnt;
	for(int i='A';i<='Z';++i) p[++cnt]=i,id[i]=cnt;
	for(int i='0';i<='9';++i) p[++cnt]=i,id[i]=cnt;
	for(int i=1;i<=cnt;++i){
		for(int j=1;j<=128;++j) s[j]=p[i];
		cout<<"? "<<s+1<<endl;
		scanf("%d",&sum[i]); sum[i]=128-sum[i]; n+=sum[i];
	}
	string s=solve(1,cnt);
	cout<<"! "<<s<<endl;
	return 0;
}

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

typedef long double ld;
#define int long long   
#define PB push_back 
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int> 
#define vpi vector< pair<int,int> >
#define F first
#define S second 
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())

ld pi= 3.14159265358979;
//const int mod=998244353; 
const int mod = 1e9+7;
const int maxn=2e5+5;

void solve()
{
    int n; cin>>n;
    map <int, string> m;
    m[2] = "hon"; m[4] = m[2];m[7] = m[2];m[5] = m[2];m[9] = m[2];
    m[0] = "pon"; m[1] = m[0];m[6] = m[0];m[8] = m[0];
    m[3] = "bon";
	cout<<m[n%10];
} 

signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cout<<setprecision(14);
    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 
 
int main() 
{
    FAST;
    ll n,k;
    ll ans;
    cin>>n>>k;
    ve<ll> a(n);
    ans=LLONG_MIN;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ans=max(ans,a[i]);
    }
    ll l=1,r=1000000000;
    while(l<=r)
    {
        ll mid=(l+r)/2,co=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]%mid!=0)
                co+=(a[i]/mid);
            else
                co+=(a[i]/mid)-1;
        }
        if(co>k)
            l=mid+1;
        else
        {
            r=mid-1;
            ans=min(ans,mid);
        }
    }
    cout<<ans;
    subt;
    return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    int ans=0;
    string s;
    cin>>s;
    for(int i=0;i<4;i++){
        if(s[i]=='+')ans++;
        if(s[i]=='-')ans--;
    }

    cout<<ans;
 
    return 0;
}

Measured memory_bytes: 256
/*    特徴    */

/*    教訓    */

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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){

  ll X = il();

  ll sanroku = 360;
  REP(k, 1, 10000){ 
    if (k * X % 360 == 0){
      cout << k << endl;
      return 0;
    }
  }

  
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int j,k;long long l,r,ans=0;
int main()
{
	cin>>l>>r;
	if(l==r) return puts("1"),0;
	for(j=60;~j;--j) 
	{
		if((l&(1LL<<j))!=(r&(1LL<<j))) break; 
		else l=min(l,l^(1LL<<j)),r=min(r,r^(1LL<<j));
	}
	ans+=(1LL<<j)-l;
	for(k=j-1;~k;--k) if(r&(1LL<<k)) break;
	ans+=(1LL<<k+1)+(1LL<<j)-l-max(0LL,(1LL<<k+1)-l);
	cout<<ans<<endl;return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u) {
  for (int v = nt[u]; v < n; v ++) {
    nt[u] = v + 1;
    if (M[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int r) {
  for (int i = 0; i < n; i ++) nt[i] = 0;

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while (!S.empty()) {
    int u = S.top();
    int v = next(u);
    if (v != -1) {
      if (color[v] == WHITE) {
        color[v] = GRAY;
        d[v] = ++tt;
        S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs() {
  for (int i = 0; i < n; i ++) {
    color[i] = WHITE;
    nt[i] = 0;
  }
  tt = 0;

  for (int u = 0; u < n; u ++) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  for (int i = 0; i < n; i ++) {
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

int main() {
  int 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;
    }
  }

  dfs();

  return 0;
}



Measured memory_bytes: 3084
using System;
using System.Collections;
using System.IO;
using System.Linq;

namespace CompetitiveProgramming
{
  class PriorityQueue<T> where T : IComparable
  {
    const int MAX_SIZE = 2000001;
    private T[] heap;
    public int Size { get; protected set; }

    public PriorityQueue()
    {
      heap = new T[MAX_SIZE];
    }

    public void Push(T x)
    {
      int i = Size++;
      
      while (i > 0)
      {
        int p = (i - 1) / 2;
        if (heap[p].CompareTo(x) >= 0)
        {
          break;
        }
        heap[i] = heap[p];
        i = p;
      }
      heap[i] = x;
    }

    public T Top()
    {
      return heap[0];
    }

    public void Pop()
    {
      T x = heap[--Size];

      int i = 0;
      while (i * 2 + 1 < Size)
      {
        int a = i * 2 + 1, b = i * 2 + 2;
        if (b < Size && heap[b].CompareTo(heap[a]) > 0)
        {
          a = b;
        }

        if (heap[a].CompareTo(x) <= 0)
        {
          break;
        }
        heap[i] = heap[a];
        i = a;
      }

      heap[i] = x;
    }

  }

  class Solve
  {
    const int INF = (int)(1e9) + 10;

    private void Main()
    {
      PriorityQueue<ulong> pq = new PriorityQueue<ulong>();

      while (true)
      {
        string[] input = Console.ReadLine().Split();
        if (input[0] == "insert")
        {
          ulong num = ulong.Parse(input[1]);
          pq.Push(num);
        }
        else if (input[0] == "extract")
        {
          Console.WriteLine(pq.Top());
          pq.Pop();
        }
        else
        {
          return;
        }
      }
      
    }

    public Solve()
    {
      Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
      Main();
      Console.Out.Flush();
    }
  }

  class Program
  {
    static void Main(string[] args)
    {
      new Solve();
    }
  }
}

Measured memory_bytes: 37736
N, M, X, Y = map(int, raw_input().split(' '))
Xs = sorted(map(int, raw_input().split(' ')))
Ys = sorted(map(int, raw_input().split(' ')))

if max(Xs) < min(Ys) and max(Xs) < Y and X < min(Ys):
    print 'No War'
else:
    print 'War'




Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define se second
//ll string_inp() {cin.get(); for(int i =0;i<n;i++){ getline(cin,s[i]);}}

ll power(ll x, ll y, ll mod = 2e18) {ll ans = 1;x %= mod;while(y){if(y&1) ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}

ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m,a = t; t = y; y = x - q * y; x = t; } if(x < 0) x += m0;return x;}

int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;}

ll binsearch(std::vector<ll>& nums, ll target) {ll n = nums.size();ll l = 0;ll r = n-1;while(l<=r){ll mid = l+ (r-l)/2;if(nums[mid]==target)return mid;else if(nums[mid]>target)r = mid-1;else l = mid+1;}return -1;}


using namespace std;

int main()
{
   fastio
   int t;
   cin>>t;

       string s;
       cin>>s;
       if(s.size()<=t)
       {


   for(int i =0;i<s.size();i++)
   {
       cout<<s[i];
   }
       }
        else if(s.size()>t)
        {
             for(int i =0;i<t;i++)

       cout<<s[i];

            cout<<"...";
        }

}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N,M;
	cin >> N >> M;
	int ans = 0;
	if( N >= 2 ) ans += N*(N-1)/2;
	if(M >=2 ) ans += M*(M-1)/2;
	cout << ans;


}


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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  
  int maxNum = max(A, max(B,C));
  int sum = A+B+C-maxNum;
  int x = maxNum;
  for (int i=0;i<K;i++) {
    x *=2;
  }
  sum += x;
  
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <stack>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

#define echo(A) cout << A << endl;

typedef long long llong;

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

	int dont_eat = 0;
	int min = INT32_MAX;
	int all_eat = 0;
	for (int i = 0; i < N; ++i) {
		all_eat += (L+i);
	}


	for (int i = 0; i < N; ++i) {
		int sum = 0;
		for (int j = 0; j < N; ++j) {
			if(i == j) continue;
			sum += (L+j);
		}
		if(abs(sum - all_eat) < min){
			min = abs(sum - all_eat);
			dont_eat = sum;
		}
	}
	echo(dont_eat);

	return 0;
}



Measured memory_bytes: 256
def main():
    n,m = map(int, input().split())
    
    ac = [0]*n
    wa = [0]*n
    tmp = [0]*n
    for i in range(m):
        p,s = input().split()
        if ac[int(p)-1] == 1:
            continue
        if s == 'WA':
            tmp[int(p)-1] += 1
        if s == 'AC':
            ac[int(p)-1] = 1
            wa[int(p)-1] = tmp[int(p)-1]
    print(sum(ac),sum(wa))

if __name__ == '__main__':
    main()



Measured memory_bytes: 47704
a,b,c = map(int, input().split())
if a == b == c:
    if a % 2 == 1:
        print(0)
    else:
        print(-1)
else:
    ans = 0
    while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        next_a = b//2 + c//2
        next_b = a//2 + c//2
        next_c = a//2 + b//2
        a = next_a
        b = next_b
        c = next_c
        ans += 1
    print(ans)
    

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();    
    return 0;   
}
 
const int MOD = 1e9 + 7, MAXN = 5e5 + 10, INF = 1e18 + 10, BASE = 37; 

void solve() {
    int h, w, k, ans = 0;
    cin >> h >> w >> k;
    vec<vec<int>> a(h, vec<int>(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            if (c == '.') {
                a[i][j] = 1; // белые 
            }
        }
    }

    for (int mask1 = 0; mask1 < (1ll << h); ++mask1) { 
        for (int mask2 = 0; mask2 < (1ll << w); ++mask2) {
            vec<vec<int>> b = a;
            for (int i = 0; i < h; ++i) {
                if ((mask1 >> i) & 1) {
                    for (int j = 0; j < w; ++j) {
                        b[i][j] = 1;
                    }
                }
            }
            for (int j = 0; j < w; ++j) {
                if ((mask2 >> j) & 1) {
                    for (int i = 0; i < h; ++i) {
                        b[i][j] = 1;
                    }
                }
            }
            int cnt = 0;
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    if (b[i][j] == 0) {
                        cnt++;
                    }
                }
            }
            if (cnt == k) ans++;
        }
    }

    cout << ans << endl;
}

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

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc081/tasks/abc081_b
    class QuestionABC_081_B
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            //string s = Console.ReadLine();

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long counter = 0;
            while(true)
            {
                bool isLast = false;
                for (int i = 0; i < inputLongArray.Length; i++)
                {
                    if (inputLongArray[i] % 2 == 0)
                        inputLongArray[i] /= 2;
                    else
                        break;

                    if (i == inputLongArray.Length - 1)
                        isLast = true;
                }

                if (isLast)
                    counter++;
                else
                    break;
            }


            //string result = "";

            Console.WriteLine(counter);

            Console.Out.Flush();
        }
    }
}


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

using namespace std;

int main() {

	long n,m;
	cin >> n >> m;

	vector<long> ac(m+n + 1,0);
	vector<long> wa(m+n + 1,0);

	long p;
	string s;
	for (long i = 0; i < m; i++) {
		cin >> p >> s;
		if (s == "AC") {
			ac[p] = 1;
		}
		if (s == "WA") {
			if (ac[p] == 0) {
				wa[p]++;
			}
		}
	}
	for (long i = 0; i <= n; i++) {
		if (ac[i] == 0) { wa[i] = 0; }
	}
	cout << accumulate(ac.begin(), ac.end(), 0) << " " << accumulate(wa.begin(), wa.end(), 0) << endl;

	return 0;
}

Measured memory_bytes: 3328
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = input()

for i in range(1, int(N)+1):
	if int(Decimal(str(i))*Decimal("1.08")) == int(N):
		print(i)
		exit()
else:
	print(":(")

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

using namespace std;

int main() {
	int n, p[110], id[110], cnt, q[110];
	string s[110], t[110];
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s[i] >> p[i];
		t[i] = s[i];
	}
	sort(t + 1, t + n + 1);
	for (int i = 1; i <= n; i++) {
		while ((i < n) && (t[i + 1] == t[i]))
			i++;
		cnt = 0;
		for (int j = 1; j <= n; j++)
			if (s[j] == t[i]) {
				q[cnt++] = -p[j];
				id[p[j]] = j;
			}
		sort(q, q + cnt);
		for (int k = 0; k < cnt; k++)
			cout << id[-q[k]] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int [][]a = new int[n + 1][n + 1];
			int sum = 0;
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					a[i][j] = sc.nextInt();
					sum += a[i][j];
				}
			}
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					a[i][n] += a[i][j];
					a[n][j] += a[i][j];
				}
			}
			a[n][n] = sum;
			for(int i = 0; i <= n; i++) {
				for(int j = 0; j <= n; j++) {
					System.out.printf("%5d", a[i][j]);
				}
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 31612
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;

// 入力
int n, W;
int weight[110], value[110];

// DPテーブル
int dp[110][10010];

int main()
{
    cin >> n >> W;
    for (int i = 0; i < n; ++i)
        cin >> value[i] >> weight[i];

    // DP初期条件: dp[0][w] = 0
    for (int w = 0; w <= W; ++w)
        dp[0][w] = 0;

    // DPループ
    for (int i = 0; i < n; ++i)
    {
        for (int w = 0; w <= W; ++w)
        {
            if (w >= weight[i]) //i番目の荷物の重さがw以下の場合
                dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w]);
            else //i番目の荷物の重さがwより大きい場合
                dp[i + 1][w] = dp[i][w];
        }
    }

    cout << dp[n][W] << endl;
}


Measured memory_bytes: 6996
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n)  for(ll i=0;i<n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int,int> pii;
int main()
{
	IOS;
	//ll T; cin>>T;
	//ll M=pow(10,9)+7;
	int T=1;
	while(T)
	{
		ll n,d; cin>>n>>d;
		ll a[n],b[n];
		ll count=0;
		f(i,n)
		{
			cin>>a[i]>>b[i];
			ll temp = a[i]*a[i]+b[i]*b[i];
			if(temp<=d*d) count++;
		}
		cout<<count<<"\n";
		T--;
	}
	return 0;
}

Measured memory_bytes: 6764
n = int(input())
d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
mx = max(d.values())
ans = ['']
for k, v in d.items():
    if v == mx:
        ans.append(k)
ans.sort()
print(*ans, sep='\n')


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

int main() {
  // ここにプログラムを追記
  int N;
  cin >> N;
  int p[N];
  for(int i=1;i<=N;i++){
    cin >> p[i];
  }

  int flag = 0;
  for(int i=1;i<=N;i++){
    if(p[i] != i){
      flag++;
    }
  }
  if(flag==0){
    cout << "YES";
  }
  else if(flag==2){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
}

Measured memory_bytes: 256
import math
n=int(input())
problem = [list(map(int, input().split())) for _ in range(n)]
a=1
for i in range(n):
    a=a*(i+1)
wa=0
for i in range(n):
    for j in range(n):
        k=(problem[i][0]-problem[j][0])*(problem[i][0]-problem[j][0])+(problem[i][1]-problem[j][1])*(problem[i][1]-problem[j][1])
        wa=wa+math.sqrt(k)/n
        k=0
print(wa)

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

//積みきれないPの最大値が知りたい!!
int n, k, x;
vector<int> w;
bool check(int p){
        int cap = 0, count = 1;
        for(int i = 0; i < n; i++){
                if(cap + w[i] <= p){
                        cap += w[i];
                }
                else if(w[i] > p) return false;
                else{
                        count++;
                        cap = w[i];
                }
                //cout << p << " " << cap << endl;
        }
        if(count <= k) return true;
        else return false;
}
int main(){
        cin >> n >> k;
        int left = 0, right = INT_MAX;
        for(int i = 0; i < n; i++){
                cin >> x;
                w.push_back(x);
        }
        while(left + 1 < right){
                int med = (left + right) / 2;
                if(check(med)) right = med;//次は[left, med)
                else left = med;//次は[med, right)
        }
        cout << right << endl;
        return 0;
}



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

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

  if(a>b) swap(a,b);
  if(b>c) swap(b,c);
  if(a>b) swap(a,b);

  cout<<a<<" "<<b<<" "<<c<<endl;

 return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  map<int, int> mp;
  for(int i = 0, temp; i < n; ++i){
    cin >> temp;
    mp[temp]++;
  }
  int ans = 0;
  for(auto a: mp){
    if(a.first > a.second) ans += a.second;
    else if(a.first < a.second) ans += (a.second - a.first);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4736
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> takos(n);
    for(int i=0;i<n;i++) cin>>takos.at(i);
    
    int count =0;
    for(int i=0;i<n;i++){
        for(int k=0;k<n;k++){
            if(i==k)continue;
            count+=takos.at(i)*takos.at(k);
        }
    }
    cout<<count/2;
}

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

int main(){
  int N, K;
  int sum = 0;
  
  
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    
    if(x > K - x){
      sum += (K - x) * 2;
    } 
    else{
     sum += x * 2;
    }
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int l = scanner.nextInt();
        final int r = scanner.nextInt();
        final int d = scanner.nextInt();
        final long answer = IntStream.rangeClosed(l, r)
            .filter(i -> i % d == 0)
            .count();
        System.out.println(answer);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
    

Measured memory_bytes: 34092
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

template<typename T>
struct BIT{
    private:
        vector<T> array;
        const int n;
    public:
        BIT(int _n) : array(_n + 1, 0), n(_n) {}
        T sum(int i){
            T s = 0;
            while(i > 0){
                s += array[i];
                i -= i & -i;
            }
            return s;
        }
        T sum(int i, int j){
            T ret_i = sum(i-1);
            T ret_j = sum(j);
            return ret_j - ret_i;
        }
        void add(int i, T x){
            while(i <= n){
                array[i] += x;
                i += i & -i;
            }
        }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    BIT<int> bit0(n), bit1(n);
	int k, s, t, x;
    rep(i,q){
		cin >> k;
        if(k == 0){
            cin >> s >> t >> x;
            bit0.add(s, -x * (s - 1));
            bit1.add(s, x);
            bit0.add(t+1, x * t);
            bit1.add(t+1, -x);
        }
        else{
			cin >> s;
			t = s;
            int ans = 0;
            ans += bit0.sum(t) + bit1.sum(t) * t;
            ans -= bit0.sum(s - 1) + bit1.sum(s - 1) * (s - 1);
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 3620