akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #define pb push_back
    #define mp make_pair
    #define fst first
    #define snd second
    #define all(cont) cont.begin(), cont.end()
    #define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
    #define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
    #define SZ(x) ((int)x.size())
    #define EPS 1e-9
    #define PI 3.1415926535897932384626433832795
    #define MOD 1000000007
    #define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
     
    const int N = 0;
     
    typedef long long int ll;
     
    using namespace std;
     
    int main(){
        int n;cin>>n;
        int n2 = 0;
        int n4 = 0;
        int no = 0;
        fore(i,0,n){
            int val;cin>>val;
            if(val%4 == 0){
                n4++;
            }else if(val%2 == 0){
                n2++;
            }else{
                no++;
            }
        }
        //cout<<n2<<" "<<n4<<" "<<no<<" ";
        if(n4>=no-1){
            if(n2 == 0){
                cout<<"Yes";
            }else{
                if(n4-no >= 0){
                    cout<<"Yes";
                }else{
                    cout<<"No";
                }
            }
        }else{
            cout<<"No";
        }
    }

Measured memory_bytes: 384
class SegmentTree:
    def __init__(self, initial_values, f=max, zero=0):
        self.__size = len(initial_values)
        self.__n = 1 << ((self.__size - 1).bit_length())
        self.__f = f
        self.__z = zero
        self.__dat = [zero for _ in range(2 * self.__n)]
        zi = self.__get_leaf(0)
        for i, v in enumerate(initial_values):
            self.__dat[zi + i] = v
        for i in range(zi-1, -1, -1):
            self.__dat[i] = self.__f(*self.__get_children(i))
    
    def update(self, index, value):
        i = self.__get_leaf(index)
        if self.__dat[i] == value: return
        self.__dat[i] = value
        while i > 0:
            i = self.__get_parent(i)
            self.__dat[i] = self.__f(*self.__get_children(i))
    
    def query(self, from_inclusive, to_exclusive):
        if to_exclusive <= from_inclusive: return self.__z
        a, b = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1
        ans = self.__z
        while b - a > 1:
            if self.__is_right(a): ans = self.__f(ans, self.__dat[a])
            if self.__is_left(b): ans, b = self.__f(ans, self.__dat[b]), b-1
            a, b = a//2, self.__get_parent(b)
        ans = self.__f(ans, self.__dat[a])
        if a != b: ans = self.__f(ans, self.__dat[b])
        return ans

    def __get_leaf(self, i): return self.__n + i - 1
    def __get_parent(self, i): return (i-1)//2
    def __get_children(self, i): return (self.__dat[2*i+1], self.__dat[2*i+2])
    def __is_left(self, i): return i&1 == 1
    def __is_right(self, i): return i&1 == 0

N = int(input())
S = input()
g = lambda c: 1 << (ord(c)-ord('a'))
tree = SegmentTree([g(c) for c in S], lambda x,y:x|y)
Q = int(input())
for _ in range(Q):
    t, a, b = input().split()
    if t == '1': tree.update(int(a)-1, g(b))
    else: print(bin(tree.query(int(a)-1, int(b))).count('1'))

Measured memory_bytes: 116244
package main

import "fmt"

type edge struct {
	to     int
	length int
}

type graph [][]edge

// 二部グラフ判定
var color []int // -1: 未訪問, 0: 白確定, 1: 黒確定
func dfs(g graph, v, cur int) {
	color[v] = cur
	for _, e := range g[v] {
		// 隣接頂点がすでに色確定していた場合
		if color[e.to] != -1 {
			continue
		}

		// 辺の長さが偶数の場合、同じ色に塗る
		if e.length%2 == 0 {
			dfs(g, e.to, cur)
		} else {
			dfs(g, e.to, 1-cur)
		}
	}
}

func main() {
	// 頂点数
	var n int
	fmt.Scan(&n)

	// グラフ入力受け取り
	g := make(graph, n)
	for i := 0; i < n-1; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		g[a-1] = append(g[a-1], edge{to: b - 1, length: c})
		g[b-1] = append(g[b-1], edge{to: a - 1, length: c})
	}

	// 探索
	color = make([]int, n)
	for i := range color {
		color[i] = -1
	}
	for v := 0; v < n; v++ {
		// vが探索済みだったらスルー
		if color[v] != -1 {
			continue
		}
		dfs(g, v, 0)
	}

	for _, c := range color {
		fmt.Println(c)
	}
}


Measured memory_bytes: 23936
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string S, T, U;
int main() {
	while (true) {
		cin >> T; if (T == "-")break; cin >> S >> U; string V = ""; int c = 0;
		reverse(S.begin(), S.end()); reverse(T.begin(), T.end()); T += S[S.size() - 1];

		while (S.size() + T.size() >= 1) {
			if (c < U.size() && U[c] == S[S.size() - 1]) {
				T = T.substr(0, T.size() - 1);
				if (T.size() >= 1)S[S.size() - 1] = T[T.size() - 1];
				if (T.size() == 0)S = "";
				c++;
			}
			else {
				V += S[S.size() - 1]; S = S.substr(0, S.size() - 1);
				if (S.size() >= 1)T[T.size() - 1] = S[S.size() - 1];
				if (S.size() == 0)T = "";
			}
		}
		cout << V << endl;
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> data(n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }

    vector<int> temp = data;
    sort(temp.begin(), temp.end());
    int BLeft = temp.at(n / 2 - 1);
    int BRight = temp.at(n / 2);

    for (int i = 0; i < n; i++){
        if (data.at(i) <= BLeft){
            cout << BRight << endl;
        }
        else{
            cout << BLeft << endl;
        }
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM(f:updMaxMin)
// --> f:updMaxMin
// ---- inserted function updMaxMin from util.cc
template<typename T>
bool updMax(T& tmax, const T& x) {
  if (x > tmax) { tmax = x; return true;  }
  else          {           return false; }
}
template<typename T>
bool updMin(T& tmin, const T& x) {
  if (x < tmin) { tmin = x; return true;  }
  else          {           return false; }
}
// ---- end updMaxMin
// @@ !! LIM  -- end mark --

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  vector<ll> c(45);
  for (ll i = 44; i >= 0; i--) {
    for (ll j = 0; j < N; j++) {
      if ((A[j] >> i) & 1) c[i]++;
    }
  }
  ll p = 0;
  ll q = -1;
  for (ll i = 44; i >= 0; i--) {
    ll p0 = p;
    ll q0 = q;
    ll t = (1LL << i);
    if (q >= 0) {
      q = q0 + t * c[i];
      updMax(q, q0 + t * (N - c[i]));
    }
    if ((K >> i) & 1) {
      updMax(q, p0 + t * c[i]);
      p = p0 + t * (N - c[i]);
    }else {
      p = p0 + t * c[i];
    }
  }
  cout << max(p, q) << endl;

  return 0;
}



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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;

ll solve(ll n)
{
	if(n<0) return 0;
	
	ll ans=0;
	if(n&1) {
		ans=((n+1)/2)&1;
	}
	else {
		ans=(n/2)&1;
		ans^=n;
	}
	return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	ll a, b;
	cin>>a>>b;
	ll ans=solve(b)^solve(a-1);
	cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 256
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():

    start = time.time()

    n, q = get_int_multi()

    a = [[] for _ in range(n+1)]
    for _ in range(n-1):
        s, e = get_int_multi()
        a[s].append(e)
        a[e].append(s)

    point = [0] * (n+1)
    for _ in range(q):
        p, x = get_int_multi()
        point[p] += x

    def tasu(now, prev):
        for next in a[now]:
            if next == prev:
                continue
            point[next] += point[now]
            tasu(next, now)

    sys.setrecursionlimit(10 ** 6)
    tasu(1, -1)
    point = point[1:] #１つ目は0なので除去（inputは1始まりなので、0は使わない）
    print(*point) # * は引数展開　listの中身を引数にする。例えばprint(*[1,2,3])はprint(1,2,3)になり 1 2 3 が出力される


if __name__ == '__main__':
    main()




Measured memory_bytes: 284940
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;

int main() {
	int n; cin >> n;
	int y; cin >> y;
	y /= 1000;
	bool x = false;
	int ans_x, ans_y, ans_z;
	srand(1145141919);
	while (clock()<1995000) {
		int a = rand() % (n + 1);
		int b = rand() % (n - a + 1);
		int c = n - (b + a);
		if (a + b * 5 + c * 10 == y) {
			x = true;
			ans_x = c;
			ans_y = b;
			ans_z = a;
			break;
		}
	}

	if (x) {
		cout << ans_x << " " << ans_y << " " << ans_z << endl;
	}
	else {
		cout << "-1 -1 -1" << endl;
	}

	return 0;
}

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

int main(){
    int x , n;
    cin >> x >> n;
    vector<int> a(200,0);
    if(n == 0){
        cout << x << endl; 
        return 0;
    } 
    for(int i = 1; i <= n; ++i){
        int p;
        cin >> p;
        a[p + 100] = 1;
    }

    if(a[x + 100] != 1){
         cout << x << endl;
         return 0;
    }

    for(int i = 1; i <= 100; ++i){
        int l = x + 100 - i;
        int r = x + 100 + i;
        if(a[l] != 1){
            cout << l - 100 << endl;
            return 0;
        }
        if(a[r] != 1){
            cout << r - 100 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
struct UnionFind{
    vector<int> par;
    UnionFind(int N){
        par.resize(N);
        for(int i=0;i<N;i++){
            par[i] = i;
        }
    }
    void Union(int x,int y){
        par[Get(x)] = Get(y); 
    }
    bool Same(int x,int y){
        return Get(x) == Get(y);
    }
    int Get(int x){
        if(x != par[x]){
            par[x] = Get(par[x]);
        }
        return par[x];
    }
};
long Cost[200010];
long CostE[200010];
pair<long,pair<int,int>> edge[100000];
int par[100000];
pair<int,int> G[200010];
void Calc(){
	int N = rei();
	int M = rei();
	for(int i=0;i<N;i++){
		par[i] = i;
		Cost[i] = rel();
	}
	for(int i=0;i<M;i++){
		int a = rei()-1;
		int b = rei()-1;
		long c = rel();
		edge[i] = {c,{a,b}};
	}
	sort(edge,edge+M);
	UnionFind U(N);
	int p = N;
	for(int i=0;i<M;i++){
		int f = edge[i].second.first;
		int t = edge[i].second.second;
		if(!U.Same(f,t)){
			int fp = U.Get(f);
			int tp = U.Get(t);
			Cost[p] = Cost[par[fp]] + Cost[par[tp]];
			CostE[p] = edge[i].first;
			G[p] = {par[fp],par[tp]};
			U.Union(f,t);
			par[U.Get(f)] = p;
			p++;
		}
	}
	stack<pair<int,long>> sp;
	sp.push({p-1,Cost[p-1]});
	while(!sp.empty()){
		int v = sp.top().first;
		long c = sp.top().second;
		sp.pop();
		Cost[v] = max(Cost[v],c);
		if(v >= N){
			if(CostE[v] > Cost[v]){
				sp.push({G[v].first,0});
				sp.push({G[v].second,0});
			}
			else{
				sp.push({G[v].first,Cost[v]});
				sp.push({G[v].second,Cost[v]});
			}
		}
	}
	int ans = 0;
	for(int i=0;i<M;i++){
		long ec = edge[i].first;
		long vc = Cost[edge[i].second.first];
		if(ec > vc){
			ans++;
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
int n,K,m;
ll f[305][305],c[605][605],s[305][305];
int main(){
	scanf("%d%d%d",&n,&K,&m);
	n++;
	const int mod=m;
	for(int i=0;i<=602;i++){
		c[i][0]=1;
		for(int p=1;p<=i;p++) c[i][p]=(c[i-1][p]+c[i-1][p-1])%mod;
	}
	for(int i=0;i<=K;i++) s[1][i]=K-i+1,f[1][i]=1;
	for(int i=2;i<=n;i++){
		for(int p=0;p<=K;p++){
			for(int j=1;j<i;j++) f[i][p]=(f[i][p]+s[j][p+1]*c[i-2][j-1]%mod*f[i-j][p])%mod;
		}
		for(int p=K;~p;p--) s[i][p]=(s[i][p+1]+f[i][p])%mod;
	}
	printf("%lld",f[n][0]);
	return 0;
}

Measured memory_bytes: 4480
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<time.h>
#include<sstream>
#define MINN -1e8 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF=0x3f3f3f3f3f3f;
const int P=1e9+7;
const int MAXN=32000;
const double pi=3.1415926;
const ll mod=1000000007;
int a[505][505],n;
void f(int l,int r,int tmp)
{
	if(l==r)return;
	int mid=(r+l)/2;
	for(int i=l;i<=mid;i++)
	{
		for(int j=mid+1;j<=r;j++)
		{
			a[i][j]=tmp;
		}
	}
	if(r!=l+1)
	{
		f(l,mid,tmp+1);
		f(mid+1,r,tmp+1);
	}
}
int main()
{
	cin>>n;
	f(1,n,1);
	for(int i=1;i<=n-1;i++)
	{
		cout<<a[i][i+1];
		for(int j=i+2;j<=n;j++)
		{
			cout<<" "<<a[i][j];
		}
		cout<<'\n';
	}
	return 0;
}

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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    ll H, W;  cin >> H >> W;
  	if(W == 1 || H == 1){  cout << 1 << endl;  return 0;  }
    if(H % 2 != 0){
      if(W % 2 != 0){  cout << (H-1)*W/2 + W/2 + 1 << endl;  }
      else          {  cout << (H-1)*W/2 + W/2 << endl;  }
    }else{
      cout << H*W/2 << endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int x[3000], y[3000], z,i=0,j=0;
	while (1)
	{
		scanf("%d %d", &x[i], &y[i]);
		if (x[i] > y[i])
		{
			z = x[i];
			x[i] = y[i];
			y[i] = z;
		}
		if (x[i] == 0 && y[i] == 0)
		{
			break;
		}
		i++;
		j++;
	}
	i = 0;
	while (i<j)
	{
		printf("%d %d\n", x[i], y[i]);
		i++;
	}
	return 0;
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
#define f(b) ((s[b]=='0'&&s[b+1]>'0')||(s[b]=='1'&&s[b+1]<'3'))
int main(){
  string s;
  cin>>s;
  if(f(0)&&f(2))cout<<"AMBIGUOUS\n";
  else if(f(0))cout<<"MMYY\n";
  else if(f(2))cout<<"YYMM\n";
  else cout<<"NA\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include <vector>
#define re(i,n) for(int i = 0; i < n; i++)
const int MOD = 1000000007;

long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

int main() {
    long long a, b, c;
    int n;
    cin >> n;
    a = 1;
    b = 1;
    c = 1;
    re(i, n) {
        a *= 10;
        b *= 9;
        c *= 8;
        a = a % 1000000007;
        b = b % 1000000007;
        c = c % 1000000007;
    }
    b = (2 * b) % 1000000007;
    a = (a + c) % 1000000007;
    cout << mod((a%MOD) - (b%MOD),MOD) << endl;

    
    return 0;
}

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

using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;

    unordered_map<int,int> mp[2];
    int tmp;
    for(int i=0;i<n;i++){
        cin>>tmp;
        mp[i%2][tmp]++;
    }
    pair<int,int> maxi[2];
    maxi[0]={0,0};
    maxi[1]={0,0};
    for(auto it:mp[0]){
        if(maxi[0].second<=it.second){
            maxi[0]=it;
        }
    }

    for(auto it:mp[1]){
        if(maxi[1].second<=it.second){
            maxi[1]=it;
        }
    }


    if(maxi[0].first==maxi[1].first){
        // cout<<"true";
        int max2[2]= {0,0};
        for(auto it:mp[0]){
                if(max2[0]<=it.second && maxi[0].first!=it.first){
                    max2[0]=it.second;
                }
        }

        for(auto it:mp[1]){
            if(max2[1]<=it.second && maxi[1].first!=it.first){
                max2[1]=it.second;
            }
        }


        cout<<min(n-maxi[0].second - max2[1],n-max2[0] - maxi[1].second);
        return 0;
    }

    cout<<n-maxi[0].second-maxi[1].second;
    return 0;

    // int ans=0;
    // char ansc;
    // for(auto it: mp[0]){
    //     if(ans<=it.second){
    //         ansc=it.first;
    //         ans=it.second;
    //     }
    // }   
    // // cout<<ans<<endl;
    // int ans2=0;
    // char ansc2;
    // for(auto it: mp[1]){
    //     if(ans2<=it.second){
    //         ansc2=it.first;
    //         ans2=it.second;
    //     }
    // } 
    // // cout<<ans2<<endl;
    // if(ansc==ansc2){
    //     int sans=0;
    //     // char sansc;
    //     for(auto it: mp[0]){
    //         if(sans<=it.second && ansc!=it.first){
    //             // sansc=it.first;
    //             sans=it.second;
    //         }
    //     } 
    //     int sans2=0;
    //     // char sansc2;
    //     for(auto it: mp[1]){
    //         if(sans2<=it.second && ansc2!=it.first){
    //             // sansc2=it.first;
    //             sans2=it.second;
    //         }
    //     } 

    //     cout<<min(n-sans-ans2,n-ans-sans2);

    //     return 0;
    // }
    // cout<<n-ans-ans2;
    // return 0;
}


Measured memory_bytes: 7208
#include <iostream>

using namespace std;
typedef long long ll;
int n;
ll ns[100000+9], a=0;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&ns[i]);
        ns[i]=ns[i]*2;
        if((i&1)==0) a+=ns[i];
        else a-=ns[i];
    }
    a/=2;
    ll cur=a;
    printf("%lld ", a);
    for(int i=0;i<n-1;i++){
        printf("%lld ", ns[i]-cur);
        cur=ns[i]-cur;
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int k; cin>>k;
	ll ans = 0;
	for(int a = 1; a <= k; a++){
		for(int b = 1; b <= k; b++){
			int x = __gcd(a, b);
			for(int c = 1; c <= k; c++){
				ans += __gcd(x, c);
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  if(A >= K) {
    cout << K << endl;
    return 0;
  }
  int tmp = K - A;
  if(B >= tmp){
    cout << A << endl;
    return 0;
  }
  tmp -= B;
  cout << A - tmp << endl;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
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<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
int d[1<<18];
map<int,pair<int,int>>m;
int H,W,D;
int a;
int q;
int l,r;
inline void solve(void){
  in(H,W,D);
  rep(i,H){
    rep(j,W){
      in(a);
      m[a]={i,j};
    }
  }
  up(i,1,H*W)d[i+D]=d[i]+abs(m[i].ft-m[i+D].ft)+abs(m[i].sd-m[i+D].sd);
  in(q);
  while(q--){
    in(l,r);
    out(d[r]-d[l]);
  }
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 12032
#include<stdio.h>
#define N 8
#define FREE 0
#define NOT_FREE 1

void putQueen(int );
void printBoard(void);

int row[N],col[N],dpos[N*2-1],dneg[N*2-1];
int Q[N][N];

int main(){
  int i,j,k,r,c;
  
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
    
  }
  for(i=0;i<N*2-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      Q[i][j]=FREE;
    }
  }
  
  scanf("%d",&k);
  
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    Q[r][c]=NOT_FREE;
  }
  putQueen(0);

  return 0;
  
}

void putQueen(int i){
  int j;
  
  if(i==N){
    printBoard();
    return ;
  }

  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1] == NOT_FREE){
      continue;
    }
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    
    putQueen(i+1);

    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}
    
      
void printBoard(void){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(Q[i][j]==NOT_FREE && row[i]!=j) return;
    }
  }
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    
    printf("\n");
  }
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
using Int = long long;
using namespace std;
int main()
{
    int x; cin >> x;
    if (x < 1200) cout << "ABC" << endl;
    else cout << "ARC" << 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);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i <= Math.max(x, y); i++) {
			int temp = c * 2 * i + a * Math.max(x - i, 0) + b * Math.max(y - i, 0);
			if (temp < ans) {
				ans = temp;
			}
		}
		System.out.println(ans);
	}
}

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

int main() {
    long long n, m;
    cin >> n >> m;
    vector<long long> cost(m), item(m);
    for(long long i = 0; i < m; i++) {
        long long b;
        cin >> cost[i] >> b;
        item[i] = 0;
        while(b--) {
            long long x;
            cin >> x;
            x--;
            item[i] |= ((1ll)<<x);
        }
    }
    vector<long long> dp((1ll)<<n, 1000000);
    dp[0] = 0;
    for(long long i = 0; i < m; i++) {
        for(long long j = 0; j < ((1ll)<<n); j++) {
            dp[j | item[i]] = min(dp[j | item[i]], dp[j] + cost[i]);
        }
    }
    if(dp[((1ll)<<n) - 1] == 1000000)
        dp[((1ll)<< n) - 1] = -1;
    cout << dp[((1ll)<< n) - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
BASE, N = map(int, input().split())
NGs = input().split()

def solve():
    def is_valid(num):
        s_num = str(num)
        for ng in NGs:
            if s_num.count(ng):
                return False
        return True

    # print(BASE, N)
    # print(NGs)

    num = BASE

    while not is_valid(num):
        num += 1

    return num

res = solve()
print(res)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, k, nowcolor;
vector<int>color[maxn];
vector<int>G[maxn];
bool vis[maxn];
map<vector<int>, int>Map;
void dfs(int u)
{
    vis[u] = 1;color[u].push_back(nowcolor);
    for(auto v : G[u])if(!vis[v])dfs(v);
}
int main()
{
    k = 2;int a[3];
    scanf("%d%d%d", &n, &a[1], &a[2]);
    for(int i = 1; i <= k; i++)
    {
        for(int j = 1; j <= n; j++)G[j].clear(), vis[j] = 0;
        int m, u, v;
        m = a[i];
        while(m--)
        {
            scanf("%d%d", &u, &v);
            G[u].push_back(v);
            G[v].push_back(u);
        }
        nowcolor = 0;
        for(int j = 1; j <= n; j++)
            if(!vis[j])nowcolor++, dfs(j);
    }
    for(int i = 1; i <= n; i++)Map[color[i]]++;
    for(int i = 1; i <= n; i++)printf("%d ", Map[color[i]]);
    return 0;
}


Measured memory_bytes: 39552
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,pair<int,int>>
#define F first
#define S second
using namespace std;
#define mod 1000000007

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n; cin>>n;
    vector<char> arr(n+1);
    int r=0; int w=0;
    for(int i=1;i<=n;i++){
        cin>> arr[i];
        if(arr[i]=='R') r++;
        else w++;
    }
    int cr=0;
    for(int i=1;i<=r;i++){
        if(arr[i]=='R') cr++;
    }
    int cw=0;
    for(int i=n;i>n-w;i--){
        if(arr[i]=='W') cw++;
    }
    cout<<min(r-cr,w-cw)<<endl;


}


Measured memory_bytes: 3640
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = readline().strip()

    fN = sum(map(int, N))
    N = int(N)

    if N % fN == 0:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()


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

int n[10];

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a==0 || b==0 || c==0 || d == 0) cout << "NO" << endl;
    else if(a+b+c+d == 21) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
    
}

Measured memory_bytes: 256
N=int(input())
p=list(map(float,input().split()))
import numpy as np
d=np.zeros(N+2)
d[1]=1
for i in range(N):
    d[1:i+3]=(d[:i+2]*p[i]+d[1:i+3]*(1-p[i]))
print(sum(d[N//2+2:]))

Measured memory_bytes: 14436
use proconio::{fastout, input};
use std::cmp::min;

#[fastout]
fn main() {
    input! {
        n: u64,
    }
    let mut i = 1;
    let mut ans = n - 1;
    while i * i <= n {
        if n % i == 0 {
            let j: u64 = n / i;
            ans = min(ans, i + j - 2);
        }
        i += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2200
#include<bits/stdc++.h>
#include <cmath>
#define ll long long  
#define PI 3.14159265358979323846
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb emplace_back
#define watch5(a,b,c,d,e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d << " | "<<#e<<": "<<e<<endl;
#define watch4(a,b,c,d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define watch3(a,b,c) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<endl;
#define watch2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
#define watch(a) cerr <<#a<<": "<<a<<endl;
#define F first
#define S second
#define mod 1073741824
using namespace std;

int min(int a, int b){
  return a<b?a:b;
}

int32_t main(){
	IOS;
  float d, t, s;
  cin >> d>> t >> s;
  float tt = d / s;
  if(tt <= t){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}																				  

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

int main(){
	
	int n;
	cin>>n;
	string arr[n];
	map<string , int> m;
	
	int ma = INT_MIN;
	
	for(int i = 0 ; i < n ; i++){
		cin>>arr[i];
		m[arr[i]] += 1;
		ma = max(ma, m[ arr[i] ]);
	}
	
	map<string, int> :: iterator it;
	for(it = m.begin(); it != m.end(); it++) {
		if(it->second == ma)
			cout<<it->first<<endl;
	}
	
}

//7
//beat
//vet
//beet
//bed
//vet
//bet
//beet
// beat => 1,  beet => 2, bed => 1, bet => 1, vet => 2,


Measured memory_bytes: 26752
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

void solve(){
  ll A,B,C,D;
  cin>>A>>B>>C>>D;

  if(A<B||D<B||C<A%B){
    cout<<"No"<<endl;
    return;
  }else if(C>=B){
    cout<<"Yes"<<endl;
    return;
  }

  ll g=gcd(B,D);
  ll x=(C-A%B)/g+1;
  ll val=A%B+g*x;

  if(val>=B) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

int main(){
  int T;
  cin>>T;
  rep(i,T) solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
int main(){
	int A,B;
	cin>>A>>B;
	cout<<(B-1+A-2)/(A-1)<<endl;
}


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

#define LSOne(S) ((S) & (-S))
#define sswap(x, y) { x+=y; y = x-y; x -= y;}

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int n, e, qm, m;
	vi a;
	cin >> n;
	cin >> m >> qm;
	a.pb(m);
	a.pb(qm);
	if (qm > m) sswap(qm, m); 
	while (cin >> e) {
		a.pb(e);
		if (e > m) {
			qm = m;
			m = e;
		}
		else if (e == m)
			qm = e;
		else if (e > qm)
			qm = e;
	}
	for (auto x : a) {
		if (x == m) cout << qm << ende;
		else cout << m << ende;
	}
  return 0;
}


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

struct Node {
	int key;
    Node *left;
	Node *right;
	Node *parent;
};

Node *root,*NIL;
void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
   z=new Node;
    
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while (x != NIL) {
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y==NIL){
        root = z;
    }else{
        if(z->key < y->key){
            y->left=z;
        }else {
            y->right = z;
        }
    }
}

void Preparse(Node *T) {
	if (T == NIL) return;
	cout << " " << T->key;
	Preparse(T->left);
	Preparse(T->right);
}
bool find(Node *T,int num) {
    int k=num;
	if (T == NIL) return false;
    else if(T->key ==num) return true;
    if(k < T->key)return find(T->left,k);
    else return find(T->right,k);


}
void Inparse(Node *T) {
	if (T == NIL) return;
	Inparse(T->left);
	cout << " " <<T->key;
	Inparse(T->right);
}
int main() {
	int n; cin >> n;
	int num;
  string str;
	for (int i = 0; i < n; i++) {
    cin>>str;
    if(str=="insert"){
      cin>>num;
        insert(num);
      }
    else if(str=="print"){
              Inparse(root);
      cout << endl;
      Preparse(root);
      cout << endl;
    }
    else if(str=="find"){
              cin>>num;
        if(find(root,num)) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
  }

	return 0;
}




Measured memory_bytes: 21908
A, B = map(int, input().split())
A_under = (A * 25 + 1) // 2
A_top = ((A + 1) * 25 + 1) // 2 - 1
B_under = B * 10
B_top = B * 10 + 9

ans = -1

for p in range(A_under, A_top + 1):
    if B_under <= p <= B_top:
        ans = p
        break

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision
const int MAX = 10000000;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll X,Y;
    cin >> X >> Y;
    ll A=(-1*X+2*Y)/3;
    ll B=(2*X-Y)/3;
    if((-1*X+2*Y)%3!=0 || (2*X-Y)%3!=0){
        cout << 0 << endl;
        return 0;
    }
    cout << COM(A+B,A) << endl;
}

Measured memory_bytes: 234624
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
l gcd(l a,l b){
   return b==0?a:gcd(b,a%b);
}
l findlcm(l arr[], l n) 
{ 
    
    l ans = arr[0]; 
    for (l i = 1; i < n; i++) 
        ans =(l) (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 

  
    return (l)ans; 
}
int main()
{
    l n;
    cin>>n;
    l arr[n];
    for(l i=0;i<n;i++) cin>>arr[i];
    //cout<<findlcm(arr,n);
    l a;
    l b=0;
    a = findlcm(arr,n);
    for(l i=0;i<n;i++)
    {
        b+=(a/arr[i]);
    }
    double result; 
    result = (double(a)/double(b));
    cout<<setprecision(15)<<result;
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<vector>
using namespace std;
int main()
{
	while(1)
	{
		int N;
		cin >> N;
		if(N == 0)
		{
			return 0;
		}

		vector<vector<int>> map;

		//??????????????????
		for(int i = 0; i < N+1; i++)
		{
			vector<int> column;
			for(int j = 0; j < N + 1; j++)
			{
				if(i == N)
				{
					column.push_back(0);
				}
				else if(j != N)
				{
					int value;
					cin >> value;
					column.push_back(value);
				}
				else
				{
					column.push_back(0);
				}

			}  
			map.push_back(column);
		}
		//?????????????¨????
		int totalSum = 0;
		//????????????????¨????
		for(int i = 0; i < N; i++)
		{
			int sum = 0;
			for(int j = 0; j < N; j++)
			{
				sum += map[i][j];
			}
			map[i][N] = sum;
		}
		//????????????????¨????
		for(int i = 0; i < N; i++)
		{
			int sum = 0;
			for(int j = 0; j < N; j++)
			{
				sum += map[j][i];
			}
			map[N][i] = sum;
			totalSum += sum;
		}
		//????????????????¨???????????????£??\
		map[N][N] = totalSum;

		for(int i = 0; i < N + 1; i++)
		{
			for(int j = 0; j < N + 1; j++)
			{
				cout << setw(5) << right << map[i][j];
			}
			cout << endl;
		}
	}

}

Measured memory_bytes: 3148
#include<iostream>
#include<cmath>
using namespace std;
string s[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
double r[]={0,0,0,0,255,255,255,255},g[]={0,0,255,255,0,0,255,255},b[]={0,255,0,255,0,255,0,255};
int f(char c)
{
	if(c<='9')return c-'0';
	else return c-'a'+10;
}
main()
{
	string t;
	while(cin>>t,t!="0")
	{
		double R,G,B;
		int i;
		double M=1e9;
		R=f(t[1])*16+f(t[2]);
		G=f(t[3])*16+f(t[4]);
		B=f(t[5])*16+f(t[6]);
		for(int j=0;j<8;j++)
		{
			double now=hypot(r[j]-R,hypot(g[j]-G,b[j]-B));
			if(now<M)
			{
				M=now;
				i=j;
			}
		}
		cout<<s[i]<<endl;
	}
}



Measured memory_bytes: 3260
def factorial(n)
  i = 2
  while i <= Math.sqrt(n)
    if n % i == 0
      return [i, n / i]
    end
    i = i + 1
  end
  return [n, 1]
end

n = gets.to_i
print "#{n}: "
while n > 1
  f, n = factorial(n)
  if n == 1
    print "#{f}\n"
    break
  else
    print "#{f} "
  end
end


Measured memory_bytes: 8900
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next;
}E[MAXN * 2];
int N,M,head[MAXN],sumE;
int que[MAXN * 2],ql,qr;
bool vis[MAXN];
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void Solve() {
    read(N);read(M);
    int a,b;
    for(int i = 1 ; i <= M ; ++i) {
	read(a);read(b);
	add(a,b);add(b,a);
    }
    ql = N,qr = N - 1;
    que[++qr] = 1;vis[1] = 1;
    while(1) {
	int u = que[qr];
	bool flag = 1;
	for(int i = head[u] ; i ; i = E[i].next) {
	    int v = E[i].to;
	    if(!vis[v]) {
		que[++qr] = v;
		vis[v] = 1;
		flag = 0;break;
	    }
	}
	if(flag) break;
    }
    while(1) {
	int u = que[ql];
	bool flag = 1;
	for(int i = head[u] ; i ; i = E[i].next) {
	    int v = E[i].to;
	    if(!vis[v]) {
		que[--ql] = v;
		vis[v] = 1;
		flag = 0;break;
	    }
	}
	if(flag) break;
    }
    out(qr - ql + 1);enter;
    for(int i = ql ; i <= qr ; ++i) {
	out(que[i]);space;
    }
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 3200
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Program{
    public static void Main(){
        double ans = 0;
        string[] S = ReadLine().Split(' ');
        int N = int.Parse(S[0]);
        int K = int.Parse(S[1]);

        ans = (double)(N-1)/(K-1);
        WriteLine(Ceiling(ans));
    } 
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>

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

typedef long long ll;

using namespace std;

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

  int c = ceil(N/1.08);
  int f = floor(c * 1.08);
  if(f==N) cout << c << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli arr[MaxN];
	void solve(){
		lli N,K,i,j,p,q,res=0;
		cin>>N>>K;
		for(i=0;i<N;i++){
			cin>>arr[i];
		}
		sort(arr,arr+N);
		for(i=N-K-1;i>=0;i--){
			res+=arr[i];
		}
		cout<<res;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String []arg){
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		List<String[]> list = new ArrayList<String[]>();
		for(int i=0; i<str.length(); i++){
			String tmp[] = new String[2];
			int cnt = 1;
			if(str.charAt(i)=='I'){
				tmp[0] = "I";
			}
			else if(str.charAt(i)=='O'){
				tmp[0] = "O";
			}
			else if(str.charAt(i)=='J'){
				tmp[0] = "J";
			}
			if(i<str.length()-1){
				while(str.charAt(i)==str.charAt(i+1)){
					cnt++;
					i++;
					if(i==str.length()-1){
						break;
					}
				}
			}
			tmp[1] = String.valueOf(cnt);
			list.add(tmp);
		}
		
		int answer = 0;
		for(int i=1; i<list.size()-1; i++){
			String[] tmpJ=list.get(i-1);
			String[] tmpO=list.get(i);
			String[] tmpI=list.get(i+1);
			if(tmpO[0].equals("O")){
				if(tmpI[0].equals("I") && tmpJ[0].equals("J")){
					if(Integer.parseInt(tmpI[1])>=Integer.parseInt(tmpO[1]) && Integer.parseInt(tmpJ[1])>=Integer.parseInt(tmpO[1])){
						if(answer<Integer.parseInt(tmpO[1])){
							answer = Integer.parseInt(tmpO[1]);
						}
					}
				}
			}
		}
		System.out.println(answer);
	}

}



Measured memory_bytes: 112376
#include <bits/stdc++.h>
using namespace std;
typedef long long lol;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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 (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    lol n; cin >> n;
    lol go100 = n/500;
    lol amari = n%500;
    lol go = amari/5;
    result = go100*1000 + go*5;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3628