akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  
  vector<int>N(n);
  for (int i = 0; i < n; i++) {
    cin >> N.at(i);
  }
  int A ;
  int B ;  
  long long C = 0 ;
  
  sort(N.begin(),N.end());
  A = N.at(0);
  B = N.at(n-1);
  
  for (int i = 0; i < n; i++) {
    C += N.at(i);
  }
    
  cout << A << ' ' << B << ' ' << C << endl;
}
  
  


Measured memory_bytes: 3188
//无锡沁园实验小学 龚欣怡
#include <bits/stdc++.h>
using namespace std;

int n, m;

int main()
{
	cin >> n >> m;
	if (m % n == 0) cout << n + m << endl;
	else cout << m - n << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
public class c
{
  public static void Main()
 {
   string b = Console.ReadLine();
   if(b=="A") Console.WriteLine("T");
    else if(b=="T")Console.WriteLine("A");
     else if(b=="G")Console.WriteLine("C");
     else if(b=="C")Console.WriteLine("G");
 }
}

Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,c,k,ans=0;
  cin >> n >> c >> k;
  int t[n]={};
  for(int i=0; i<n; i++) {
    cin >> t[i];
  }
  sort(t,t+n);
  for(int i=0; i<n;) {
    long long cnt=1,T=t[i]+k;
    i++;
    while(t[i]<=T&&cnt<c) {
      cnt++,i++;
      if(cnt==c) {
        break;
      }
    }
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    ll N,x;
    cin >> N >> x;
    vector<ll> a(N);
    rep(i,N)cin >> a[i];
    vector<ll> b(N);
    ll res = 1LL<<60;
    b=a;
    rep(k,N){
        rep(i,N){
            int idx = i-k>=0?i-k:N-(k-i);
            b[i]=min(b[i],a[idx]);
        }
        ll cost = 0;
        rep(i,N)cost+=b[i];
        res=min(cost+k*x,res);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  uli w,h;
  scanf("%lld %lld",&w,&h);
  vector<pair<uli,int> >d;
  for(int i=0;i<w;i++){
    uli x;
    scanf("%lld",&x);
    d.push_back(pair<uli,int>(x,0));
  }
  for(int i=0;i<h;i++){
    uli x;
    scanf("%lld",&x);
    d.push_back(pair<uli,int>(x,1));
  }
  sort(d.begin(),d.end());
  uli ans=0ll;
  uli x=0ll,y=0ll;
  for(pair<uli,int>e:d){
    uli inc=0;
    if(e.second==0){
      inc=e.first*(h+1);
      inc-=e.first*(x);
      y++;
    }
    else{
      inc+=e.first*(w+1);
      inc-=e.first*(y);
      x++;
    }
    ans+=inc;
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0
int sum[100005];

signed main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	sum[0] = 0, sum[1] = 0;
	for(int i=2;i<=n;i++){
		if (s[i - 2] == 'A'&&s[i - 1] == 'C') {
			sum[i] = sum[i - 1] + 1;
		}
		else {
			sum[i] = sum[i - 1];
		}
	}
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		cout << sum[r] - sum[l] << endl;
	}

	END;
}


Measured memory_bytes: 1792
n = int(input())
sd = {}

for _ in range(n):
  s=input()
  if s in sd:
    sd[s]+=1
  else:
    sd[s] =1
m=max(sd.values())
ans=[]
for i in sd:
  if sd[i]==m:
    ans.append(i)
ans.sort()
for i in ans:
  print(i)

Measured memory_bytes: 32096
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int dp[2001][2001];
int memo[2001][2001];

int main(){

	int length;
	char buf[2001],reverse[2001];
	stack<char> ANS;

	while(scanf("%s",buf) != EOF){

		for(length = 0; buf[length] != '\0'; length++);

		for(int i = 0; i < length; i++){
			reverse[i] = buf[length-1-i];
		}
		reverse[length] = '\0';

		for(int i = 0; i <= length; i++){
			for(int k = 0; k <= length; k++){
				dp[i][k] = 0;
			}
		}

		for(int i = 0; i < length; i++){
			for(int k = 0; k < length; k++){
				if(buf[i] == reverse[k]){
					dp[i+1][k+1] = dp[i][k]+1;
					memo[i+1][k+1] = 0;
				}else{
					if(dp[i][k+1] >= dp[i+1][k]){
						dp[i+1][k+1] = dp[i][k+1];
						memo[i+1][k+1] = 1;
					}else{
						dp[i+1][k+1] = dp[i+1][k];
						memo[i+1][k+1] = -1;
					}
				}
			}
		}

		for(int i = length,k = length; i > 0 && k > 0;){

			if(memo[i][k] == 1){
				i--;
			}else if(memo[i][k] == -1){
				k--;
			}else{ //memo[i][k] == 0
				ANS.push(buf[i-1]);
				i--;
				k--;
			}
		}

		while(!ANS.empty()){
			printf("%c",ANS.top());
			ANS.pop();
		}

		printf("\n");
	}

	return 0;
}

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

int main() {

    // 時刻M（12月30日）
    int m;
     
     // 整数A,Bを入力
     cin >> m;
     
     // 次の年になるまでの時間を出力
     cout << 24 - m + 24 << endl;
}  

Measured memory_bytes: 256
from operator import itemgetter, attrgetter

a = int(input())
b = []
for i in range(a):
    c = input().split()
    b.append((c[0], int(c[1]), i+1))
s = sorted(b, key=itemgetter(1), reverse=True)
#print(s)
f = sorted(s, key=itemgetter(0), reverse=False)
#print(f)

for i in f:
    print(i[-1])



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>



using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	int m = 0;

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


	bool goodIn = true;
	for (int i = n - 1; i >= 0; i--) {
		int cnt = 0;
		for (int j = 2 * (i+1) -1; j < n;  j += (i+1)) {
			cnt += b[j];
			
		}
		
		if (cnt % 2 != a[i]) {
			b[i] = 1;
			m++;
		}
		
	}

	
	if (goodIn) {
		cout << m << endl;
		for (int i = 0; i < b.size(); i++) {
			if (b[i] != 0) {
				cout << i+1 << " ";
			}
		}
	}
	else {
		cout << -1;
	}

}

Measured memory_bytes: 2432
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////
const int MOD = 998244353;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> l(k), r(k);
    for (int i = 0;i < k;i++){
        cin >> l[i] >> r[i];
    }
    vector<long long> dp(n + 1, 0);
    dp[0] = 1; dp[1] = -1;
    for (int i = 0;i < n;i++){
        dp[i] = ((dp[i] % MOD) + MOD) % MOD;
        dp[i+1] = (dp[i+1] + dp[i]) % MOD;
        for (int j = 0;j < k;j++){
            if (i + l[j] < n) dp[i + l[j]] += dp[i];
            if (i + r[j] + 1 < n) dp[i+ r[j] + 1] -= dp[i];
        }
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
  int a;
  cin >> a;
  int b = a/500;
  int c = (a%500)/5;
  cout << (b*1000)+(c*5) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
    int x=0,c=getchar(),f=0;
    for(;c>'9'||c<'0';f=c=='-',c=getchar());
    for(;c>='0'&&c<='9';c=getchar())
    x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
const int maxn = 1e3 + 10;

double h[maxn];
int main() {
    int n = read();
    double t , x;
    scanf("%lf%lf", &t, &x);

    double temp = 100000000;
    int ans = -1;
    for (int i=1; i<=n; i++){
        double y;
        scanf("%lf", &y);
        if (fabs(t-y*0.006 - x) < temp){
            temp = fabs(t-y*0.006 - x);
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
struct edge{
	int k,vis,next;
}e[205];
int n,m,K,home[55],cnt=-1;
void add(int x,int y){
	cnt++;
	e[cnt].k=y;
	e[cnt].next=home[x];
	home[x]=cnt;
}
int dfn[55],mn[55],cc,s[105],top;
bool vis[55];
ll bin[105],fac[205],inv[205],ans=1;
int gcd(int a,int b){
	int t;
	while(b){
		t=a;a=b;b=t%b;
	}
	return a;
}
ll quick_pow(ll a,ll b){
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}
ll C(int n,int m){
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
void dfs(int k){
	dfn[k]=mn[k]=++cc;
	for(int i=home[k];~i;i=e[i].next) if(!e[i].vis){
		e[i].vis=e[i^1].vis=1;
		s[++top]=i;
		if(!dfn[e[i].k]){
			dfs(e[i].k);
			mn[k]=min(mn[k],mn[e[i].k]);
			if(mn[e[i].k]>=dfn[k]){
				ll sum=0;int cir=1,len=0;
				for(int p=top;p&&s[p+1]!=i;len++,p--)
					if(vis[e[s[p]].k]) cir=0;
					else vis[e[s[p]].k]=1;
				if(cir){
					for(int p=0;p<len;p++) sum=(sum+bin[gcd(p,len)])%mod;
					sum=sum*quick_pow(len,mod-2)%mod;
				}
				else sum=C(len+K-1,K-1);
				ans=ans*sum%mod;
				for(;s[top+1]!=i;top--) vis[e[s[top]].k]=0,s[top+1]=-1;
				s[top+1]=-1;
			}
		}
		mn[k]=min(mn[k],dfn[e[i].k]);
	}
}
int main(){
	memset(s,-1,sizeof(s));
	memset(home,-1,sizeof(home));
	scanf("%d%d%d",&n,&m,&K);
	bin[0]=1;
	for(int i=1;i<=n+2;i++) bin[i]=bin[i-1]*K%mod;
	for(int i=1,x,y;i<=m;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	fac[0]=inv[0]=1;
	for(int i=1;i<=202;i++) fac[i]=fac[i-1]*i%mod,inv[i]=quick_pow(fac[i],mod-2);
	for(int i=1;i<=n;i++) if(!dfn[i]){
		memset(s,-1,sizeof(s));top=0;
		dfs(i);
	}
	printf("%lld",ans);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int diff[n];
  for (int i = 0; i < n; i++) {
    int d1, d2;
    cin >> d1 >> d2;
    diff[i] = d1 - d2;
  }

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (diff[i] == 0) {
      cnt++;
      if (cnt == 3) {
        puts("Yes");
        return 0;
      }
    } else {
      cnt = 0;
    }
  }

  puts("No");
}

Measured memory_bytes: 3628
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

/*long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}*/

ll c[10][10];

void solve()
{
    IN(n);
    ll k = 1;
    rep(i, n+1)
    {
        if (i >= k*10) k *= 10;
        ++c[i/k][i%10];
    }
    ll s = 0;
    reps(i, 1, 10)
    {
        reps(j, 1, 10)
        {
            s += c[i][j]*c[j][i];
        }
    }
    cout << s << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int n,r;
    cin>>n>>r;
    if(n>=10)cout << r << endl;
    else{
        cout << r+(100*(10-n)) << endl;
    }
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3620
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        mut sp: [(String, usize); n]
    }
    let mut new_sp = vec![];
    for (i, &(ref stri, ref pt)) in sp.iter().enumerate() {
        new_sp.push((i+1, stri, pt))
    }

    new_sp.sort_by(|a, b| {
        match a.1.cmp(&b.1) {
            Ordering::Equal => a.2.cmp(&b.2).reverse(),
            other => other,
        }});
    for (i, _, _) in new_sp {
        println!("{}", i)
    }
}


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

typedef long long ll;

int main()
{
    int n,k,ans;
    cin >> n>>k;
    n--;
    k--;
    while(n>0){
        ans++;
        n -= k;
    }
    cout << ans << endl;
    return 0;
}


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

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

  int count = 0 ;
  int judge = 0 ; //0は判定待ち、1は単調増加、2は単調減少
  for(int i = 0 ; i < n - 1 ; i++)
  {
    if(judge == 0 && data.at(i) > data.at(i + 1))
    {
      judge = 2 ;
    }
    else if(judge == 0 && data.at(i) < data.at(i + 1))
    {
      judge = 1 ;
    }
    
    if(judge == 1 && data.at(i) > data.at(i + 1))
    {
      count++;
      judge = 0 ;
    }
    else if(judge == 2 && data.at(i) < data.at(i + 1))
    {
      count++;
      judge = 0 ;
    }
  }

  cout << count + 1 << endl ;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

struct Point {
    Point() : x(0), y(0) {}
    Point(double x, double y) : x(x), y(y) {}
    double x, y;
};

vector<Point> pnt;

double calc_dist(Point a, Point b) {
    double dx = a.x - b.x;
    double dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
}

double calc_r(Point p) {
    double r = 0;
    for (auto to : pnt) r = max(r, calc_dist(p, to));
    return r;
}

double calc_y(double x) {
    double low_y = 0;
    double high_y = 1000;
    int cnt = 500;
    while(cnt--) {
        double c1 = (low_y * 2 + high_y) / 3.0;
        double c2 = (low_y + high_y * 2) / 3.0;
        if (calc_r(Point(x, c1)) < calc_r(Point(x, c2))) high_y = c2;
        else low_y = c1;
    }
    return low_y;
}

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

    pnt = vector<Point>(n);

    rep(i, n) cin >> pnt[i].x >> pnt[i].y;

    double low_x = 0;
    double high_x = 1000;
    int cnt = 500;
    while(cnt--) {
        double c1 = (low_x * 2 + high_x) / 3.0;
        double c2 = (low_x + high_x * 2) / 3.0;
        if (calc_r(Point(c1, calc_y(c1))) < calc_r(Point(c2, calc_y(c2)))) high_x = c2;
        else low_x = c1;
    }

    cout << fixed << setprecision(20) << calc_r(Point(low_x, calc_y(low_x))) << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int a[55],b[55],c[55],d[55];

int main(void){
	          int i,j;

	          int N,M;
	          cin >> N >> M;
	          for(i=1;i<=N;i++){
	        	  cin >> a[i] >> b[i];
	          }
	          for(i=1;i<=M;i++){
	        	  cin >> c[i] >> d[i];
	          }

	          for(i=1;i<=N;i++){
	        	  int mn=1e9;
	        	  int p;
		          for(j=M;j>=1;j--){
		        	  int x=abs(a[i]-c[j])+abs(b[i]-d[j]);
		        	  if(x<=mn){
		        		  mn=x;
		        		  p=j;
		        	  }
		          }

		          cout << p << endl;
	          }


	          return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>

int main(){
	int l, a, b, c, d;
	scanf("%d%d%d%d%d", &l, &a, &b, &c, &d);
	printf("%d\n", l-std::max(a%c == 0 ? a / c : a / c + 1, b%d == 0 ? b / d : b / d + 1));
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a,b,c;
    cin>>a>>b>>c;
    if((a==5&&b==5&&c==7)||(b==5&&c==5&&a==7)||(c==5&&a==5&&b==7))
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)

func main() {
    var n int
    var a string
    var b string
    var c string

    fmt.Scanln(&n)

    sc := bufio.NewScanner(os.Stdin)

    if sc.Scan() {
        a = sc.Text()
    }

    if sc.Scan() {
        b = sc.Text()
    }

    if sc.Scan() {
        c = sc.Text()
    }

    as := strings.Split(a, " ")
    bs := strings.Split(b, " ")
    cs := strings.Split(c, " ")

    var happy int
    var pre_ate int = -1
    for _, an := range as {
        ai, _ := strconv.Atoi(an)

        tmp, _ := strconv.Atoi(bs[ai-1])
        happy += tmp

        if ai-pre_ate == 1 {
            // 追加満足度
            tmp, _ := strconv.Atoi(cs[pre_ate-1])
            happy += tmp
        }
        pre_ate = ai
    }
    fmt.Println(happy)

}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	VI a(n);
	FOR(i, 0, n) cin >> a[i];
	
	int ans= INF;
	FOR(t, 1, n)
	{
		int s1 = 0, s2 = 0;
		FOR(i, 0, t) s1 += a[i];
		FOR(i, t, n) s2 += a[i];
		ans = min(ans, abs(s1 - s2));
	}
	
	cout << ans;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
n=int(input())
ans=0
l=[]
for i in range(1,n+1):
    ans+=i
    if ans>=n:
        l.append(i)
        break
    else:
        l.append(i)
s=sum(l)
if n==s:
    #print(l)
    for k in range(i):
        print(l[k])
else:
    for j in range(i):
        #print(l)
        if s-l[j]==n:
            l=l[:j]+l[j+1:]
            for k in range(i-1):
                print(l[k])
            break

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int s,w;
    Scd2(s,w);

    printf ("%ssafe\n", w>=s?"un":"" );

    return 0;
}



Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define N 200010
#define int long long 
using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,m,k,d[N],s[N],fin[N];
int now[N],cnt,rk[N],vis[N];
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
		d[i]=read();
	for(int i=2;i<=n;i++) s[i-1]=d[i]-d[i-1];
	m=read(); k=read();
	for(int i=1;i<n;i++) rk[i]=i;
	for(int i=1;i<=m;i++)
	{
		int x=read();
		swap(rk[x],rk[x-1]);
	} 
	//zhihuan
	for(int i=1;i<n;i++) if(!vis[i])
	{
		int x=rk[i]; 
		now[0]=i; 
		vis[i]=1;
		cnt=1;
		while(!vis[x])
		{
			vis[x]=1;
			now[cnt++]=x;
			x=rk[x];
		}
		for(int i=0;i<cnt;i++)
			fin[now[i]]=now[(i+k)%cnt];
	}
	
	printf("%lld\n",d[1]);
	for(int i=1;i<n;i++)
	{
		d[1]+=s[fin[i]];
		printf("%lld\n",d[1]);
	}
	return 0;
}

Measured memory_bytes: 9088
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

      
N,K=map(int,input().split())  
uf = UnionFind(N)
for i in range(K):
  a,b,c=map(int,input().split())
  uf.union(a-1,b-1)
print(uf.group_count())

Measured memory_bytes: 81728
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lint N;
    cin >> N;
    vector<lint> P(N);
    REP(i, N) cin >> P[i];
    REP(i, N) if(P[i] != -1) P[i]--;
    UnionFind uf(N);
    lint ans = 0;
    lint K = 0;
    REP(i, N) {
        if(P[i] == -1) {
            K++;
            continue;
        }
        if(uf.same(i, P[i])) continue;
        uf.unite(i, P[i]);
        ans++;
    }
    vector<lint> gsize(N);
    REP(i, N) gsize[uf.root(i)]++;
    vector<bool> minus1(N);
    REP(i, N) if(P[i] == -1) minus1[uf.root(i)] = true;
    REP(i, N) if(!minus1[i]) gsize[i] = 0;
    ans = (ans + K) * power(N-1, K, MOD) % MOD;
    vector<lint> dp(N+1);
    dp[0] = 1;
    REP(i, N) {
        if(gsize[i] == 0) continue;
        IREP(j, N) {
            dp[j+1] = (dp[j+1] + dp[j] * gsize[i] % MOD * max(j, 1) % MOD) % MOD; 
        }
    }
    dp[1] -= K;
    FOR(i, 1, N+1) {
        //cout << ans << endl;
        ans = (ans - dp[i] * power(N-1, K-i, MOD) % MOD + MOD) % MOD;
    }

    cout << ans << endl;
}


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

const int inf = (1 << 30) - 1;

int main()
{
	int N;
	int A[15], W[15];
	int minv[2];

	cin >> N;

	for ( int i = 0; i < N; i++ ) cin >> A[i];
	for ( int i = 0; i < N; i++ ) cin >> W[i];
	
	minv[0] = minv[1] = inf;

	for ( int i = 0; i < N; i++ ) {
		minv[A[i]] = min(minv[A[i]], W[i]);
	}

	if ( minv[0] == inf || minv[1] == inf ) {
		cout << 0 << endl;
	} else {
		cout << minv[0] + minv[1] << endl;
	}

	return ( 0 );
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

using namespace std;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}
 
const int mod = (int)1e9 + 7;
const int N = int(1e5) + 123;

int cnt[N], x[N], y[N];
bool ok[N];
 
int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();
	int n, m;
	cin >> n >> m;
	ok[1] = 1;
	for(int i = 1; i <= n; i++) cnt[i] = 1;
	for(int i = 1; i <= m; i++)
	{
		cin >> x[i] >> y[i];
		if(cnt[x[i]] == 1 && ok[x[i]] == 1)
		{
			ok[x[i]] = 0;
			ok[y[i]] = 1;
		}
		else if(cnt[x[i]] > 1 && ok[x[i]] == 1) ok[y[i]] = 1;
		cnt[x[i]]--;
		cnt[y[i]]++;
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) if(ok[i]) ans++;
	cout << ans;
}


Measured memory_bytes: 1536
#include <stdio.h>

int main(void){
	int N, A, B;
	int train,taxi;

	scanf("%d %d %d", &N, &A, &B);

	train = N * A;
	taxi = B;

	if(train >= taxi){
  	printf("%d",taxi);
	}else{
  	printf("%d",train);
	}
}

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

int main()
{
  int w, h;
  while(1) {
    cin >> h >> w;
    if(h == 0 && w == 0) break;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        if(i == 0 || i == h - 1 || j == 0 || j == w - 1) cout << '#';
        else cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



ll N,value;
ll dp[55][55][5005];


int main(){

	scanf("%lld %lld",&N,&value);

	//dp[i][保留数(左右同じ)][score] = 場合の数

	for(ll i = 0; i <= N; i++){
		for(ll k = 0; k <= N; k++){
			for(ll p = 0; p <= N*N; p++){

				dp[i][k][p] = 0;
			}
		}
	}

	dp[0][0][0] = 1;

	for(ll i = 0; i < N; i++){
		for(ll k = 0; k <= i; k++){
			for(ll p = 0; p <= value; p++){
				if(dp[i][k][p] == 0)continue;

				//段i同士を結ぶ
				dp[i+1][k][p+2*k] += dp[i][k][p];
				dp[i+1][k][p+2*k] %= MOD;

				//両方保留
				dp[i+1][k+1][p+2*k+2] += dp[i][k][p];
				dp[i+1][k+1][p+2*k+2] %= MOD;

				//片方結ぶ
				dp[i+1][k][p+2*k] += (2*k*dp[i][k][p])%MOD;
				dp[i+1][k][p+2*k] %= MOD;

				if(k > 0){
					//両方結ぶ
					dp[i+1][k-1][p+2*k-2] += (k*k*dp[i][k][p])%MOD;
					dp[i+1][k-1][p+2*k-2] %= MOD;
				}
			}
		}
	}

	printf("%lld\n",dp[N][0][value]);

	return 0;
}


Measured memory_bytes: 109952
# -*- coding: utf-8 -*-
import math
import datetime

# 入力
#N = int(input())
#S = str(input())
#N, A, B = map(int, input().split())
A, B = map(int, input().split())

if (A+B)%2 == 0 :
  print (int((A+B)/2))
else :
  print ("IMPOSSIBLE")

Measured memory_bytes: 3312
#include <iostream>

using namespace std;


int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int ans = 110;
    while (k > 0) {
        ans--;
        if (a % ans == 0 && b % ans == 0) {
            k--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static final Scanner in =  new Scanner(System.in);
	public static void main(String args []){
		String s =in.next();
		char a = s.charAt(2);
		char b = s.charAt(3);
		char c= s.charAt(4);
		char d = s.charAt(5);
		if(a==b && c==d){
			System.out.print("Yes");
			
		}else{
			System.out.print("No");
		}
		
	
		
	}
}


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

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int ans;

    for(int i=100; i>0; i--){
        if(a%i==0 && b%i==0) k--;
        if (k==0) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

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;
}

ll min3(ll a, ll b, ll c){
    if(a < b){
        if(b < c) return a;
        else{
            if(a < c) return a;
            else return c;
        }
    }else{
        if(b < c) return b;
        else return c;
    }
}

int main(){
    ll n,W; cin >> n >> W;
    vl w(n), v(n);
    rep(i,n) cin >> w[i] >> v[i];
    vvl dp(n+1, vl(W+1,0));
    //rep(i,n+1) dp[i][0] = 0;
    //rep(j,W+1) dp[0][j] = 0;
    for(ll i=1; i<n+1; i++){
        for(ll j=1; j<W+1; j++){
            dp[i][j] = dp[i-1][j];
            if(j - w[i-1] >= 0) chmax(dp[i][j],dp[i-1][j-w[i-1]] + v[i-1]);
        }
    }
    cout << dp[n][W] << endl;
}

Measured memory_bytes: 80256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N, L, T=0;
    cin >> N >> L;
    for (int i=0;i<N;i++) T += L+i;
    int m = 1<<30, me;
    for (int i=0;i<N;i++) {
        if (m > abs(L+i)) {
            m = abs(L+i);
            me = T-(L+i);
        }
    }
    cout << me << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define F -1
#define NF 1
int r[N],c[N],ds[2*N-1],dg[2*N-1];
bool x[N][N];
void initialize(){
  int i;
  for(i=0;i<N;i++){
    r[i]=F;
    c[i]=F;
  }
  for(i=0;i<2*N-1;i++){
    ds[i]=F;
    dg[i]=F;
  }
}
void in(){
  int i,j,k,r,c;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      x[i][j]=false;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    x[r][c]=true;
  }
}
void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(x[i][j]){
        if(r[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(r[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
void recu(int i){
  int j;
  if(i==N){
    print();
    return;
  }
  for(j=0;j<N;j++){
    if(c[j]==NF || ds[i+j]==NF || dg[i-j+N-1]==NF)continue;
    r[i]=j;
    c[j]=ds[i+j]=dg[i-j+N-1]=NF;
    recu(i+1);
    r[i]=c[j]=ds[i+j]=dg[i-j+N-1]=F;
  }
}
int main(){
  initialize();
  in();
  recu(0);
  return 0;
}



Measured memory_bytes: 2112
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
int d[11][11];
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<11;i++)
		{
			for(int j=0;j<11;j++)
			{
				d[i][j]=0;
			}
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cin >> d[i][j];
			}
		}
		int x=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				d[i][n]+=d[i][j];
				d[n][i]+=d[j][i];
				x+=d[i][j];
			}
		}
		d[n][n]=x;
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				printf("%5d",d[i][j]);
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define endl '\n'
#define ll long long
#define inf 1000000007
int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n,w;
	cin>>n>>w;
	ll dp[n+1][w+1];
	ll arr[n+1],arr1[n+1];
	for(ll i=1;i<=n;i++)
	{
		cin>>arr[i]>>arr1[i];
	}
	for(ll i=1;i<w+1;i++)
	{
		if(arr[1]>i)
			dp[1][i]=0;
		else
			dp[1][i]=arr1[1];
	}
	for(ll i=1;i<n+1;i++)
	{
		if(arr[i]>1)
			dp[i][1]=0;
		else
			dp[i][1]=arr1[i];
	}
	for(ll i=0;i<n+1;i++)
		dp[i][0]=0;
	for(ll i=2;i<n+1;i++)
	{
		for(ll j=2;j<w+1;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j-arr[i]>=0)
			{
					dp[i][j]=max(dp[i][j],arr1[i]+dp[i-1][j-arr[i]]);
			}	
		}
	}
	cout<<dp[n][w]<<endl;

	return 0;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ll = long long;
#define AC ios::sync_with_stdio(0),cin.tie(0);

int main()
{
    AC
    int h,w;
    cin>>h>>w;
    vector<vector<char>> v(h+1,vector<char>(w+1));
    vector<vector<int>> dp(h+1,vector<int>(w+1,0));
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            cin>>v[i][j];
    dp[1][1]=1;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
        {
            if(i==1&&j==1) continue;
            if(v[i][j]!='#') dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
        }
    cout<<dp[h][w]<<'\n';
}


Measured memory_bytes: 5248
package main

import (
	"fmt"
	"strconv"
)

func headLetter(a int) int {
	s := strconv.Itoa(a)
	b,_ := strconv.Atoi(s[0:1])
	return b
}

func tailLetter(a int) int {
	s := strconv.Itoa(a)
	//fmt.Println(s)
	n := len(s)
	b,_ := strconv.Atoi(s[n-1:n])
	return b
}

func printArray(a [81]int) {
	for i := 0 ; i < 9 ; i++ {
		fmt.Println(a[i*9:(i+1)*9])
	}
}

func main(){
	var n,c int
	var count [81]int
	fmt.Scan(&n)
	for i := 1 ; i <= n ; i++{
		if i%10 == 0 {
			continue
		}
		head_i := headLetter(i)
		tail_i := tailLetter(i)
		count[(head_i-1)*9+(tail_i-1)]++
	}
	//printArray(count)
	for i := 0 ; i < 9 ; i++ {
		for j := 0 ; j < 9 ; j++ {
			c += count[i*9+j]*count[j*9+i]
		}
	}
	fmt.Println(c)
}


Measured memory_bytes: 2944
#include <iostream>
using namespace std;
int a, b;
string s="Negative";
int main() {
	cin>>a>>b;
	if(a<=0 && b>=0) s="Zero";
	else if(a>0 || b<0 && (b-a)%2) s="Positive";
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();

		int sum_n = 0;
		int sum_m = 0;

		if (N > 1 ){
			for (int i = N-1; i > 0; i-- ){
				sum_n += i ;
			}
		}
		if (M > 1 ){
			for (int i = M-1; i > 0; i-- ){
				sum_m += i ;
			}
		}

		System.out.println( sum_m + sum_n );

	}
}

Measured memory_bytes: 23764
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const N = nextInt()
    const a = nextIntArray()
    let m = {}
    for (let el of a) {
        if (!m[el]) m[el] = 1
        else m[el]++
    }
    let cnt = 0
    for (let key of Object.keys(m)) {
        if (m[key] < key) {
            cnt += m[key]
        } else if (m[key] > key) {
            cnt += m[key] - Number(key)
        }
    }
    console.log(cnt)
}
Main()


Measured memory_bytes: 59456
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
LL n, x;
int main() {
#ifndef ONLINE_JUDGE
#endif
	scanf("%lld%lld", &n, &x);
	LL ans = n;
	LL a = n - x, b = x;
	while(a && b) {
		ans += (a / b) * b * 2;
		a %= b;
		if(!a) ans -= b;
		swap(a, b);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
string make(string &t){
    string res;
    int n=t.size();
    for(int i=0;i<n;i++){
        if(i!=n-1&&t[i]=='B'&&t[i+1]=='C'){
            res.push_back('D');
            i++;
        }
        else res.push_back(t[i]);
    }
    return res;
}
int main(){
    string s,t;
    cin>>t;
    s=make(t);
    int n=s.size();
    V<int> sum(n+1,0);
    for(int i=n-1;i>=0;i--){
        if(s[i]=='D')sum[i]=sum[i+1]+1;
        else if(s[i]=='A')sum[i]=sum[i+1];
        else sum[i]=0;
    }
    ll ans=0;
    for(int i=0;i<n;i++)if(s[i]=='A')ans+=sum[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu long long unsigned
int main()
{
    int t,a,b,x,y,z,n,mx,mn,tmp;
    scanf("%d %d %d",&n,&x,&y);
    for(int i=min(x,y);i<=max(x,y);i++){
        if(i%n==0){
            puts("OK");
            return 0;
        }
    }
    puts("NG");


    return 0;
}




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

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

  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 3; ++j)
      for (int k = 0; k < 3; ++k)
        if (A[j][k] == b[i])
          A[j][k] = 0;

  bool flag = false;
  for (int i = 0; i < 3; ++i)
    if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0)
      flag = true;
  for (int j = 0; j < 3; ++j)
    if (A[0][j] == 0 && A[1][j] == 0 && A[2][j] == 0)
      flag = true;
  if ((A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) ||
      (A[2][0] == 0 && A[1][1] == 0 && A[0][2] == 0))
    flag = true;

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

Measured memory_bytes: 256
#include <stdio.h>

const int INF = 1e+9 + 7;
int ans = 0;

void merge(int A[], int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1 + 1], R[n2 + 1];
    for (int i = 0; i < n1; i++)
    {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++)
    {
        R[i] = A[mid + i];
    }
    L[n1] = INF;
    R[n2] = INF;
    int i = 0, j = 0;
    for (int k = left; k < right; k++)
    {
        ans++;
        if (L[i] <= R[j])
        {
            A[k] = L[i];
            i++;
        }
        else
        {
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int A[], int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main()
{
    int n;
    scanf("%d", &n);
    int A[n];

    for (int i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }

    mergeSort(A, 0, n);

    printf("%d", A[0]);
    for (int i = 1; i < n; i++)
    {
        printf(" %d", A[i]);
    }
    printf("\n%d\n", ans);
    return 0;
}


Measured memory_bytes: 5748