akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


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

struct edge{ll to, cost;};
vector<edge> tree[202020];
bool visit[101010];
int top[202020];
vector<int> d;
int cnt;

void dfs(int v){
    if(visit[v]==true) return;
    visit[v]=true;
    top[v]=d[cnt];
    cnt++;
    for(auto x:tree[v]){
        dfs(x.to);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    REP(i,n-1){
        int a,b;
        cin>>a>>b;
        --a,--b;
        edge e;
        e.to = b,e.cost=0;
        tree[a].push_back(e);
        e.to = a,e.cost=0;
        tree[b].push_back(e);
    }
    
    REP(i,n){
        int tmp;cin>>tmp;
        d.push_back(tmp);
    }
    VRSORT(d);
    //top[0]=d[0];
    dfs(0);
    int ans=0;
    for(int i=1;i<n;i++) ans+=d[i];
    cout<<ans<<endl;
    REP(i,n) cout<<top[i]<<" ";
    cout<<endl;
}

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

typedef long long lli;

int main()
{
   lli k, n;
   cin>>k>>n;

   vector<lli>V;
   lli x;
   for(int i = 0; i < n; i++)
   {
       cin>>x;
       V.push_back(x);
   }

   lli mx = V[0];
   for(int i = 0; i < n-1; i++)
   {
       mx = max(mx, V[i+1] - V[i]);
   }
   mx = max(mx, k - V[n-1] + V[0]);
   cout<<k - mx<<endl;
}



Measured memory_bytes: 2420
def gcd(a,b):
	return a if b==0 else gcd(b,a%b)

n=input()
if n==2:
	a,b=map(int,raw_input().split())
	g=gcd(a,b)
else:
	a,b,c=map(int,raw_input().split())
	g=gcd(gcd(a,b),c)
for i in range(1,g+1):
		if gcd(i,g)==i:print i

Measured memory_bytes: 7100
h,w = gets.split.map(&:to_i)
a = []
n = 0
ans = []
h.times do
  a << gets.split.map(&:to_i)
end
h.times do |i|
  (w-1).times do |j|
    if a[i][j] % 2 == 1
      a[i][j+1] += 1
      n += 1
      ans << [i+1,j+1,i+1,j+2]
    end
  end
end

(h-1).times do |i|
  if a[i][w-1] % 2 == 1
    a[i+1][w-1] += 1
    n += 1
    ans << [i+1,w,i+2,w]
  end
end

p n
ans.each do |arr|
  puts arr.join(" ")
end


Measured memory_bytes: 29204
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto md = readNums!int;

  int ret;
  foreach(m; 1 .. md[0]+1){
    foreach(d; 1 .. md[1]+1){
      if(d % 10 >= 2 && d / 10 >= 2 && (d % 10) * (d / 10) == m){
        ret++;
      }
    }
  }

  writeln(ret);
}


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

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)++)

int main(){
  int n,k;
  const int max = 2*1e5;
  int h[max+1];

  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> h[i];

  long long sum = 0;
  sort(h, h+n);
  for(int i = 0; i < n - k; i++){
    // cout << h[i] << endl;
    sum += h[i];
  }
  // sum += k;

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1024
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


d = gff
num = gf
data = 0

num.each do |n|
  data += n
end

data1 = (data/d).ceil.to_i 
data2 = (data/d).floor.to_i 
ans1 = 0
ans2 = 0
num.each do |n|
  ans1 += (n.to_i-data1) ** 2
  ans2 += (n.to_i-data2) ** 2
end

puts min ans1,ans2


Measured memory_bytes: 3964
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll K, T;
    cin >> K >> T;

    priority_queue<ll > que;

    for(ll i = 0; i < T; i++){
        ll t; cin >> t;
        que.push(t);
    }

    ll top = que.top();
    for(ll i = 0; i < T; i++){
        if(i == 0){
            que.pop();
        }else{
            ll tmp = top - que.top();
            //cout << tmp << endl;
            que.pop();
            top = abs(tmp);
        }
    }

    cout << max(0LL, top - 1) << endl;

}

Measured memory_bytes: 256
def solve(left, right)
  return if left > right
  x = $preorder[$cur]
  $cur += 1
  solve(left, $inorder.index(x)-1)
  solve($inorder.index(x)+1, right)
  $postorder << x
end
n = gets.to_i
$preorder = gets.split.map(&:to_i)
$inorder = gets.split.map(&:to_i)
$postorder = []
$cur = 0
solve(0, n-1)
puts $postorder.join(" ")

Measured memory_bytes: 8680
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

size_t N, M;
vector<size_t> g[10];

auto dp = make_v(-1, 10, (1 << 9));

int64_t dfs(size_t now_node, int bit) {
    if (__builtin_popcount(bit) == N) return 1;
    if (~dp[now_node][bit]) return dp[now_node][bit];

    int ret = 0;
    for (auto &next: g[now_node]) {
        if ((bit >> next) & 1) continue;
        ret += dfs(next, bit | (1 << next));
    }

    return dp[now_node][bit] = ret;
}

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

    cin >> N >> M;

    for (size_t i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    cout << dfs(0, 1) << "\n";

    return 0;
}


Measured memory_bytes: 384
X,Y = gets.split.map &:to_i
A3 = 2*X - Y
B3 = 2*Y - X
unless A3 >= 0 && B3 >= 0 && A3 % 3 == 0 && B3 % 3 == 0
  p 0; exit
end

A = A3 / 3; B = B3 / 3;

Mod = 10**9+7

def powmod(b,r,mod)
  a = 1
  while r > 0
    if r%2 == 1
      a = a * b % mod
    end
    b = b * b % mod
    r /= 2
  end
  a
end

def invmod(f, mod)
  powmod(f, mod-2, mod)
end

def factorial(n, mod)
  fs = [1]
  (1..n).each{ |k| fs << (fs[-1] * k) % mod }
  fs
end

$fs = factorial(A+B,Mod)

def comb(n,r)
  return 0 if r < 0
  return 0 if n < r
  $fs[n] * invmod($fs[r],Mod) % Mod * invmod($fs[n-r],Mod) % Mod
end

p comb(A+B, A)

Measured memory_bytes: 8956
N=int(input())
h=list(map(int, input().split()))

def f(x):
  m=min(x)
  n=len(x)
  if n>1:
    x=[x[i]-m for i in range(n)]
    temp=devider(x)
    for t in temp:
      m+=f(t)
  return m

def devider(y):
  output=[]
  n=len(y)
  i=0
  while i<n:
    while i<n and y[i]==0:
      i+=1
      
    if i>=n:
      break
      
    j=i+1
    while j<n and y[j]!=0:
      j+=1
      
    if j-i==1:
      output.append([y[i]])
    else:
      output.append(y[i:j])
      
    i=j
    
  return output

h=devider(h)
ans=0
for htemp in h:
  ans+=f(htemp)
  
print(ans)

Measured memory_bytes: 3188
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;
#define Fill(a, b) memset(a, b, sizeof(a))
#define Debug(x) cout << #x << "=" << (x) << endl;
typedef long long LL;
const LL inf = 1LL << 61;
const LL mod = 1000000007;
#define DEBUG
#ifdef DEBUG
#endif
const int maxn = 55;


bool g[maxn][maxn], vis[maxn];
void dfs(int u)
{
	if(vis[u])return ;
	vis[u] = true;
	for(int i = 1; i < maxn; i++)
	{
		if(g[u][i])dfs(i);
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    int n, m, ans = 0, u, v;
    Fill(g, 0);
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
    	scanf("%d%d", &u, &v);
    	g[u][v] = true;
    	g[v][u] = true;
    }
    for(int i = 1; i <= n; i++)
    {
    	for(int j = i+1; j <= n; j++)
    	{
    		if(!g[i][j])continue;
    		g[i][j] = false;
    		g[j][i] = false;
    		Fill(vis, 0);
    		dfs(1);
    		for(int s = 2; s <= n; s++)
    		{
    			if(!vis[s])
    			{
    				ans++;//cout << i << " " << j << endl;
    				break;
    			}
    		}
    		g[i][j] = true;
    		g[j][i] = true;
    	}
    }
    printf("%d\n", ans);






















    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>

int main() {
    int r, c;
    std::cin >> r >> c;

    std::vector< std::vector< int > > vs(r + 1, std::vector< int >(c + 1));
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            std::cin >> vs[i][j];
        }
    }

    for (int i = 0; i <= r; ++i) {
        vs[i].back() = accumulate(vs[i].begin(), vs[i].end() - 1, 0);
        if (i == r) continue;
        for (int j = 0; j < c; ++j) {
            vs[r][j] += vs[i][j];
        }
    }

    for (int i = 0; i <= r; ++i) {
        for (int j = 0; j <= c; ++j) {
            std::cout << vs[i][j] << (j == c ? "\n" : " ");
        }
    }
}


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

int main()
{
    int x,n;
    cin >> x >> n;
    vector<int> q(102);

    for(int i = 0; i < 102; i++)
        q[i] = i;
    

    int z;
    int count = 0;
    for (int i = 0; i < n; i++) {
        cin >> z;
        for (int j = 0; j < 102; j++) {
            if (z == q[j]) {
                q.erase(q.begin()+j);
                count++;
            }
        }
    }

    int ans = 1000000;
    int y = 0;
    for (int i = 0; i < 102-count; i++) {
        if (ans > abs(x-q[i]))
            y = i;
        ans = min(abs(x-q[i]),ans);
    }

    if (ans == 0)
        cout << x << endl;
    else
        cout << q[y] << endl;
    
    
    return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

int n;

int main(){
    cin>>n;
    cout<<24-n+24<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void sort(int *a,int n)
{
        int i,j,max,index;
        for(i=0;i<n;i++){
                max=a[i];index=i;
                for(j=i;j<n;j++){
                        if(a[j]>max){
                                max=a[j];
                                index=j;
                        }
                }
                a[index]=a[i];
                a[i]=max;
        }
        return ;
}
int main(void)
{
        int n,m,i,s=0,c=0;
        scanf("%d%d",&n,&m);
        int a[n];
        for(i=0;i<n;i++){
                scanf("%d",&a[i]);
                s+=a[i];
        }

        sort(a,n);

        for(i=0;i<n;i++){
                if(a[i]>=(double)s/(4*m)) c++;
        }
        if(c>=m) printf("Yes\n");
        else printf("No\n");
        return 0;
}


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

int A, B, C, K;
int main()
{
	cin >> A >> B >> C >> K;
	if (A >= K) cout <<K<<endl;
	else if (A < K && A + B >= K) cout <<A<< endl;
	else cout << 2 * A - K + B << endl;
	return 0;
}


Measured memory_bytes: 3592
n, x, y = map(int, input().split())
x -= 1
y -= 1

dists = [0] * (n-1)

for i in range(n):
    for j in range(i+1, n):
        d = min(
            abs(j-i),
            abs(i-x) + abs(y-j) + 1,
            abs(i-y) + abs(x-j) + 1
        )

        dists[d-1] += 1

print(*dists, sep='\n')

Measured memory_bytes: 3444
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: usize = itr.next().unwrap().parse().unwrap();
    let b: usize = itr.next().unwrap().parse().unwrap();

    let c = b - a;
    if c % 2 == 0 {
        println!("{}", c / 2);
    } else {
        let d = a + (b - a - 1) / 2;
        let e = (n - b) + 1 + (b - a - 1) / 2;
        println!("{}", min(d, e));
    }
}


Measured memory_bytes: 4352
#include<iostream>

using namespace std;

int main(){
  int N,i,a,b,counter;
  int flag=0;
  int yes = 0;
  cin>>N;
  for(i=0;i<N;i++){
    cin>>a>>b;
    if(a==b){
      if(i-counter==1){
        counter = i;
        flag+=1;
        if(flag == 2){
          yes+=1;
        }
      }else{
        counter = i;
        flag = 0;
      }
    }
  }
  if(yes>0){
    cout<<"Yes"<<endl;
  }else{
  cout<<"No"<<endl;
}
  return 0;
}


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

int x,a;
bool cari;
int main(){
	x=0;
	a=0;
	cari=true;
	cin>>x;
	for(int i =0; i<2 && cari; i++){
		a=x%10;
		if(a==9){
			cout<<"Yes\n";
			cari=false;
		}
		x/=10;
	}
	if(cari){
		cout<<"No\n";
	}
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

double DP[17][(1 << 16)];

int main(){
	
	int m, n;
	cin >> m >> n;
	
	double cost[17][17];
	
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			cin >> cost[i][j];
		}
	}
	
	for(int j = 0; j < (1 << m); j++){
		for(int i = 0; i < n; i++){
			DP[i][j] = 0;
		}
		DP[n][j] = 1;
	}
	
	for(int i = n - 1; i >= 0; i--){
		for(int j = 0; j < (1 << m); j++){
			for(int k = 0; k < m; k++){
				if(j & (1 << k)){
					double P = 1;
					double S = 0;
					for(int l = i; l < n; l++){
						S += P * (1 - cost[k][l]) * DP[l][j - (1 << k)];
						P *= cost[k][l];
					}
					S += P;
					DP[i][j] = max(DP[i][j], S);
				}
			}
		}
	}
	
	printf("%.12f\n", DP[0][(1 << m) - 1]);
	
	return 0;
}



Measured memory_bytes: 11964
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c)cout<<1<<endl;
    else if(a!=b&&b!=c&&a!=c)cout<<3<<endl;
    else cout<<2<<endl;
    return 0;
}




Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int W, a, b;
	
	cin >> W >> a >> b;

	if (a >= b + W)
	{
		cout << a - b - W << endl;
	}
	else if (a + W <= b)
	{
		cout << b- a - W << endl;
	}
	else
	{
		cout << 0 << endl;
	}

	
	return 0;
}


Measured memory_bytes: 256
import collections

n = int(input())
s = list(input() for i in range(n))

col = collections.Counter(s)
col = col.most_common()

count = [0]
k = 0

for i in range(len(col)):
    if i == 0:
        count[k] = col[i][1]
        k += 1
    elif count[k-1] == col[i][1]:
        count.append(col[i][1])

ans = [0]*len(count)

for i in range(len(count)):
    ans[i] = col[i][0]
ans.sort()

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 45052
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200){
        cout << s;
    }else{
        cout << "red";
    }
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
 
mod = 10 ** 9 + 7
ans = 0
 
for i in range(k, n+2):
  ans += int(n*(n+1)/2 - (n-i)*(n - i + 1)/2 - (i-1)*i/2 + 1)
 
print(ans%mod)

Measured memory_bytes: 64080
n,m,x,y = map(int,input().split())
xlis = list(map(int,input().split()))
ylis = list(map(int,input().split()))
xlis.sort()
ylis.sort()
if xlis[-1] < ylis[0] and x < ylis[0] < y:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3060
#include<iostream>
#include<vector>

using namespace std;

int d[100001][2],visit[100001]={};
vector<vector<int>> v(100001);

int dfs(int p,int a){
  visit[p]=1;
  for(int i=0;i<v[p].size();i++)
    if(visit[v[p][i]]==0){
      d[v[p][i]][a]=d[p][a]+1;
      dfs(v[p][i],a);
    }
}

int main(){
  int n,a,b,cnt=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin >> a >>b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1,0);
  d[1][0]=0;
  for(int i=1;i<=n;i++)
    visit[i]=0;
  d[n][1]=0;
  dfs(n,1);
  for(int i=1;i<=n;i++){
    if(d[i][0]>d[i][1])
      cnt++;
    else
      cnt--;
  }
  if(cnt>=0)
    cout << "Snuke" <<endl;
  else
    cout << "Fennec" <<endl;
}

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

const int N = 1e5 + 5;

int fa[N];
int n1[N], n2[N];

vector<int> edge[N];

int Find(int v)
{
  return v == fa[v] ? v : fa[v] = Find(fa[v]);
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m = 0;
  cin >> n;
  for (int i = 0; i < n; ++ i) {
    int u, v;
    cin >> u >> v;
    m = max(m, max(u, v));
    edge[u].push_back(v);
  }
  for (int i = 1; i <= m; ++ i) {
    fa[i] = i;
    n1[i] = 0;
    n2[i] = 1;
  }
  for (int i = 1; i <= m; ++ i) {
    int len = edge[i].size();
    if (len == 0) continue;
    int pa = Find(edge[i][0]);
    n1[pa] ++;
    for (int j = 1; j < len; ++ j) {
      int v = edge[i][j];
      int pa2 = Find(v);
      if (pa != pa2) {
        fa[pa2] = pa;
        n1[pa] += n1[pa2];
        n2[pa] += n2[pa2];
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i <= m; ++ i) {
    if (fa[i] == i) {
      ans += 1ll * n1[i] * n2[i];
    }
  }
  cout << ans - 1ll * n << endl;
  return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <cmath>
#include <bitset>
#include <random>
#include <ctime>
#include <algorithm>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll mod = 1000000007;

vector<ll> dp(400010);

int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    rep(i,n) dp[i] = a[i];
    ll ans = dp[0];
    for(int i = 1;i < (n - 1);i++) {
        int num = i + n/2 + n%2 - 1;
        ans += dp[i];
        dp[num] = dp[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 8008
#include <stdio.h>
long long x;//1<=a,b<=120
main(){
    scanf("%lld",&x);
    for(long long a=-118;a<=119;++a) for(long long b=-119;b<=118;++b) if(a*a*a*a*a-b*b*b*b*b==x) return printf("%lld %lld\n",a,b),0;
}

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

int main() {
  int n; cin >> n;
  int team[110] = {};

  for(int i = 0; i < n*(n-1)/2; i++) {
    int a, b, ap, bp; cin >> a >> b >> ap >> bp;
    if(ap > bp) team[a] += 3;
    else if(ap < bp) team[b] += 3;
    else {
      team[a]++;
      team[b]++;
    }
  }

  int cnt = n;
  while(cnt) {
    int m = -1;
    for(int i = 1; i <= n; i++) {
      if(m < team[i]) {
        m = team[i];
      }
    }
    
    int same = 0;
    for(int i = 1; i <= n; i++) {
      if(m == team[i]) {
        team[i] = (n-cnt+1) * -1;
        same++;
      }
    }
    cnt -= same;
  }
  for(int i = 1; i <= n; i++) cout << team[i]*-1 << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int color[100010];
vector<vector<pair<int,int > > >G(100010);
void dfs(int v,int p,int c){
  color[v]=c;
    for(int i=0;i<G[v].size();i++){
      if(G[v][i].first!=p){
        if(G[v][i].second%2)dfs(G[v][i].first,v,1-c);
        else dfs(G[v][i].first,v,c);
      }
    }
}
int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++){
        int u,v,w;cin>>u>>v>>w;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }
    dfs(1,0,0);
    for(int i=1;i<=n;i++){
        cout<<color[i]<<endl;
    }
}

Measured memory_bytes: 9088
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
long long int a;
long long int b;
 long long int c;
int main(){
	cin>>a>>b>>c;
	if(b-a==c-b){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=200005;
int n;
char s[maxn];
ll ans;

int main(){
	scanf("%s",s);n=strlen(s);
	int last=0;
	rep(i,n+1)if(i==n||(s[i]=='B'&&(i+1>=n||s[i+1]!='C'))||(s[i]=='C'&&(i-1<0||s[i-1]!='B'))){
		int cnt=0;
		for(int j=i-1;j>=last;j--){
			if(j-1>=last&&s[j]=='C'&&s[j-1]=='B')cnt++,j--;
			else{
				assert(s[j]=='A');
				ans+=cnt;
			}
		}
		last=i+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int N, M;
    cin >> N >> M;
    
    int count, min_count=N*M;
    char flag[N][M];
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            cin >> flag[i][j];
        }
    }
    
    for(int w=1; w<=N-2; w++){
        for(int b=1; b<=N-w-1; b++){
            count=0;
            for(int i=0; i<w; i++){
                for(int j=0; j<M; j++){
                    if(flag[i][j] != 'W'){
                        count++;
                    }
                }
            }
            for(int i=w; i<w+b; i++){
                for(int j=0; j<M; j++){
                    if(flag[i][j] != 'B'){
                        count++;
                    }
                }
            }
            for(int i=w+b; i<N; i++){
                for(int j=0; j<M; j++){
                    if(flag[i][j] != 'R'){
                        count++;
                    }
                }
            }
            if(min_count>count){
                min_count=count;
            }
        }
    }
    cout << min_count << endl;
    
}



Measured memory_bytes: 3100
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
    int w,a,b;
    cin>>w>>a>>b;
    if (a+w<b)
    {
        cout<<b-w-a<<endl;
    }
    else if (b+w<a)
    {
        cout<<a-w-b<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;

namespace AtCoderSolve
{
    class Solve
    {

        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;


        static int N;
        static long[] a, b, c;
        
        //static long[] A, B;


        public static void Input()
        {
            var cin = new Scanner();
            N = int.Parse(Console.ReadLine());
            a = new long[N];
            b = new long[N];
            c = new long[N];
            for(var i = 0; i < N; i++)
            {
                var input = cin.SplitReaderL();
                a[i] = input[0];
                b[i] = input[1];
                c[i] = input[2];
            }
        }


        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            long[,] dp = new long[N + 1, 3];
            dp[0, 0] = 0;
            dp[0, 1] = 0;
            dp[0, 2] = 0;

            for(var i = 1; i <= N; i++)
            {
                dp[i, 0] = Max(dp[i - 1, 1], dp[i - 1, 2]) + a[i - 1];

                dp[i, 1] = Max(dp[i - 1, 0], dp[i - 1, 2]) + b[i - 1];

                dp[i, 2] = Max(dp[i - 1, 0], dp[i - 1, 1]) + c[i - 1];
            }

            long ans = Max(dp[N, 0], Max(dp[N, 1], dp[N, 2]));
            Console.WriteLine(ans);

            //Console.Out.Flush();
        }
    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }
}






Measured memory_bytes: 21812
#include<stdio.h>
int main(void){
  
long long a,b,k;
  scanf("%lld%lld%lld",&a,&b,&k);
  if(a-k<0)printf("0 ");
  else {printf("%lld ",a-k);
        printf("%lld",b);
        return 0;
       }
  long ans=b-(k-a);
  if(ans<0)ans=0;
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	a += 'g';
	b += 'g';
	c += 'g';
	
	char tmp = a[0];
	a.erase(a.begin());
	while(a.empty() == false && b.empty() == false && c.empty() == false)
	{
		switch(tmp)
		{
			case 'a' :
				tmp = a[0];
				a.erase(a.begin());
				break;
			case 'b' :
				tmp = b[0];
				b.erase(b.begin());
				break;
			case 'c' :
				tmp = c[0];
				c.erase(c.begin());
				break;
		}
	}
	
	if(a.empty() == true)
	{
		cout << "A" << endl;
	}
	else if(b.empty() == true)
	{
		cout << "B" << endl;
	}
	else
	{
		cout << "C" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
int power(int a,int b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}


int32_t main()
{
    IOS
    
    
        
        int n;
        cin>>n;
        
        vector<int> s[n+1];
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=n-1;++j)
                {
                    int p;
                    cin>>p;
                    
                    s[i].push_back(p);
                }

        }
        int ans=0;;
        int it[n+1];
        memset(it,0,sizeof(it));
        bool vi[n+1];
        while(1)
        {
            int check=1;
            for(int i=1;i<=n;++i)
            {
                if(it[i]!=n-1)
                {
                    check=0;
                    break;
                }
            }
            if(check)
                break;
            
            memset(vi,false,sizeof(vi));
            check=1;
            for(int i=1;i<=n;++i)
            {
                if(vi[i])
                    continue;
                if(it[i]==n-1)
                    continue;
                
                if(i==s[s[i][it[i]]][it[s[i][it[i]]]] and vi[s[i][it[i]]]==false)
                {

                    int temp=s[i][it[i]];
                    check=0;
                    vi[i]=true;
                    vi[temp]=true;
                    //out<<*s[i].begin()<<" "<<i<<endl;
                    it[i]++;
                    it[temp]++;
                }
                

            }
            if(check)
            {
                cout<<-1;
                return 0;
            }
            
            ans++;
        }
        cout<<ans;

}


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

ll mypow(ll a, ll b) {
    ll r = 1;
    while (b--) {
        r *= a;
    }
    return r;
}

int main() {
    int N; cin >> N;
    string ans;
    for (int i = 1; i < 40; i++) {
        if (N == 0) break;
        ll t = mypow(2, i);
        if ((t +N % t) % t == 0) {
            ans += '0';
        } else {
            ans += '1';
            if (i % 2 == 1) {
                N -= mypow(2, i-1);
            } else {
                N += mypow(2, i-1);
            }
        }
    }
    if (ans.length() == 0) ans = "0";
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;

#define INF (1LL << 60)
#define MOD 1000000007

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

int main()
{
    string S;
    cin >> S;

    ll N = S.length();

    bool f = true;
    REP(i,0,N/2) {
        if(S[i] != S[N-1-i]) f = false; 
    }
    REP(i,0,(N-1)/4) {
        if(S[i] != S[(N-1)/2-1-i]) f = false;
    }
    REP(i,(N+3)/2,N) {
        if(S[i] != S[N-1-i]) f = false;
    }

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

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[200000];
signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,2*n)scanf("%lld", &a[i]);
	sort(a, a+2*n);
	int ans = 0;
	rep(i,2*n){
		if(i%2 == 0)ans += min(a[i], a[i+1]);
	}
	printf("%lld\n", ans);
	return 0;
}







Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
import numpy as np

n = int(input())
cood = [tuple(map(int, input().split())) for _ in range(n)]
distances = np.zeros((n, n))
for i in range(n):
    for j in range(n):
        dx = cood[i][0] - cood[j][0]
        dy = cood[i][1] - cood[j][1]
        distances[i][j] = math.sqrt(dx*dx + dy*dy)

fact = 1
for i in range(1, n+1):
    fact *= i

dup = fact / n
total = np.sum(distances * dup)
ave = total / fact
print(ave)


Measured memory_bytes: 12408
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

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

	ll n, k, ans = 0;
	cin >> n >> k;

	ll mn = 0, mx = 0, br1, br2;
	mx = 0, mn = 0;
	for(int i=0; i<k; i++){
		mx += n-i;
		br1 = i+1;
	}
	for(int i=0; i<k; i++){
		mn += i;
		br2 = i+1;
	}
	while(k <= n+1){
		//cout << mx << ' ' << mn << endl;
		ans += mx - mn + 1;
		ans %= mod;
		mx += n-br1, br1++;
		mn += br2, br2++;
		k++;
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 3652
def gi; gets.split.map(&:to_i); end
H,W=gi

h=Hash.new(0)
$<.read.split.each do |a|
    a.each_char do |c|
        h[c] += 1
    end
end

x1 = (H.odd? && W.odd? ? 1 : 0)
x2 = 0
x2 += H/2 if W.odd?
x2 += W/2 if H.odd?
x4 = (H/2) * (W/2)

n4 = h.values.inject(0) {|n,v|n+=v/4}
if n4 < x4
    puts 'No'
    exit
end
n2 = h.values.inject(0) {|n,v|n+=v/2} - x4*2
if n2 < x2
    puts 'No'
    exit
end
n1 = h.values.inject(0) {|n,v|n+=v} - x4*4 - x2*2
if n1 < x1
    puts 'No'
    exit
end

# p [x1,x2,x4]
# p [n1,n2,n4]

puts 'Yes'

Measured memory_bytes: 14316
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	string A, B, C;
	int a, b, c;
	cin >> A >> B >> C;
	string x = A + " " + B + " "  + C;
	a = int(A.length());
	b = int(B.length());
	c = int(C. length());
	if(x[a - 1] == x[a + 1] && x[a + b] == x[a + b + 2]){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
int main() {
    int N;
    cin >> N;
    vector<i64> A(N), B(N), C(N - 1);
    for (auto &x : A) {
        cin >> x;
        x--;
    }
    for (auto &x : B) cin >> x;
    for (auto &x : C) cin >> x;
    i64 ans = 0;
    for(int i = 0; i < N; i++) {
        ans += B[A[i]];
        if(i && A[i - 1] + 1 == A[i]) {
            ans += C[A[i - 1]];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,k;
	ll ans=0LL;
	cin >>n>>k;
	Vi h(n);
	rep(i,n){
		cin>>h[i];
	}
	sort(all(h),greater<int>());
	rep(i,n){
		if(i<k){
			continue;
		}
		ans+=h[i];
	}
	cout<<ans<<endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  double a,b,x;
  cin >> a >> b >> x;

  double c = 2.0*x/a/b;
  const double PI=3.14159265358979323846;
  double ans = atan2(b*1.0, c)*180/PI;
  if(x > a*a*b/2.0){
    c = 2*(a*a*b-x)/a/a;
    ans = atan2(c, a)*180/PI;


  }


  cout << Decimal;
  cout << ans << endl;



}


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

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

    int cnt = 0;
    int mx = 0;

    for(int i=0; i<s.size(); i++){
        if(s.at(i)=='I') cnt++;
        else cnt--;

        mx = max(cnt, mx);
    }

    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    N = input()
    if len(N)==3:
        if int(N[2])==3:
            print("bon")
        elif int(N[2])==0 or int(N[2])==1 or int(N[2])==6 or int(N[2])==8:
            print("pon")
        else:
            print("hon")
    elif len(N)==2:
        if int(N[1])==3:
            print("bon")
        elif int(N[1])==0 or int(N[1])==1 or int(N[1])==6 or int(N[1])==8:
            print("pon")
        else:
            print("hon")
    else:
        if int(N[0])==3:
            print("bon")
        elif int(N[0])==0 or int(N[0])==1 or int(N[0])==6 or int(N[0])==8:
            print("pon")
        else:
            print("hon")

if __name__=="__main__":
    main()

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


int main() {
  int a,  b;
  cin>>a>>b;
  
    cout<<a/b<<endl;
   cout<<a%b<<endl;
  
  cout << fixed << setprecision(8);
   cout<<(double)a/b<<endl;
      
    
  
  
}


Measured memory_bytes: 3268
//============================================================================
// Name        : ProjG.cpp
// Author      : Yong Kiat
// Version     :
// Copyright   : By Algotae.
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>

using namespace std;

int n, a[100000][3], dp[100000][3];

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

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

    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for (int i = 1; i < n; i++) {
    	dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
    	dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
    	dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

    return 0;
}


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

int main(){
  int p,q,r;
  cin >> p >> q >> r;
  int m = max(max(p,q),r);
  bool flag=true;
  if(m==p && flag){
    cout << q+r << endl;
    flag=false;
  }
  if(m==q && flag){
    cout << p+r << endl;
    flag=false;
  }
  if(m==r && flag){
    cout << p+q << endl;
    flag=false;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
    int a,b;
    cin >> a >> b;
    int ten=1;
    int x=0,y=0;
    for(int i=0; i<b; i++){
        x+=ten*a;
        ten*=10;
        }
    ten=1;
    for(int i=0; i<a; i++){
        y+=ten*b;
        ten*=10;
    }

    string S= to_string(x);
    string T = to_string(y);
    if(S<=T){
        cout << S << endl;
    }
    else{
        cout << T << endl;
    }

}

 


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
int counter[1000000] = {};
int can_be[1000000] = {};
int main(){
	int n, m;
	cin >> n >> m;
	for (int i = 1;i <= n;++i) {
		counter[i] = 1;
	}
	can_be[1] = true;
	for (int i = 0;i < m;++i) {
		int x, y;
		cin >> x >> y;
		if (can_be[x] == 1) {
			can_be[y] = 1;
		}
		counter[x]--;
		if (counter[x] == 0) can_be[x] = 0;
		counter[y]++;
	}
	n++;
	long long ans = 0;
	REP(i, n) {
		if (can_be[i] != 0) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

		int count = 0;
		for(int i=0; i<N; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();

			if(Math.sqrt((Math.pow(x, 2) + Math.pow(y, 2))) <= D) {
				count++;
			}
		}

		System.out.println(count);
	}

}


Measured memory_bytes: 48740
K = int(input())

cnt=1
Num=7%K
while cnt<=K:
  if K%2==0:
    print('-1')
    break
  if Num%K==0:
    print(cnt)
    break
  else:
    Num = (10*Num + 7)%K
    cnt+=1
else:
  print('-1')



Measured memory_bytes: 9176
import math
import collections

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

p = primes(1000)
dic = collections.defaultdict(int)
N = int(input())
mod = 10**9 +7
for i in range(1, N+1):
    for j in p:
        while i % j == 0:
            dic[j] += 1
            i = i // j
    ans = 1
for c in dic.values():
    ans *= (c+1)
    ans %= mod
print(ans)

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

int n,a[128]={0},f,i;
char c;

int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>c;
		if(a[c]==0)
		{
			f++;
			a[c]=1;
		}	
	}
	if(f==4)
		cout <<"Four";
	else
		cout <<"Three";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				scan.close();
				break;
			}
			int sum = 0;
			int s[] = new int[n];
			for(int i = 0; i < n; i++){
				s[i] = scan.nextInt();
				sum += s[i];
			}
			double m = Double.valueOf(sum) / Double.valueOf(n);
			double sig = 0;
			for(int i = 0; i < n; i++){
				sig += Math.pow(s[i] - m, 2);
			}
			double a = Math.sqrt(sig / n);
			System.out.println(a);
		}
	}
}

Measured memory_bytes: 31828
#include<bits/stdc++.h>
#include <math.h>
#include <limits.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}

int main(void){
  long long int n,k,i,j;
  long long int a,b,c;

  cin >> a >> b >> c;
  
  YN(a==b&&b==c);

  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF (1e10)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

int N,K;
int ans[100001];
vector<vector<pair<int,ll> > > tp;

void dfs(int parent,int idx,ll distance){
  if(distance%2==0){
    ans[idx] = 0;
  }else{
    ans[idx] = 1;
  }
  REP(i,0,tp[idx].size()){
    if(tp[idx][i].first!=parent){
      dfs(idx, tp[idx][i].first, distance + tp[idx][i].second);
    }
  }
}

int main()
{
  cin>>N;
  tp.resize(N);

  REP(i,0,N-1){
    int u, v;
    ll w;
    cin >> u >> v >> w;
    u--;
    v--;
    tp[u].push_back(make_pair(v, w));
    tp[v].push_back(make_pair(u, w));
  }

  dfs(-1, 0, 0);

  REP(i,0,N){
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 9600
N, X, Y = map(int, input().split())
ans = [0] * (N+1)
for i in range(1, N+1):
  for j in range(i+1, N+1):
    anst = min(j-i, abs(X-i) + abs(Y-j) + 1)
    ans[anst] += 1
      
for i in range(N-1):
  print(ans[i+1])

Measured memory_bytes: 3444
n = gets.chomp.to_i

s = []

c_0 = 0
c_1 = 0
c_2 = 0
c_3 = 0

for num in 0...n do
 s[n]=gets.chomp
 if(s[n] == "AC")
  c_0 = c_0 + 1
 elsif(s[n] == "WA")
  c_1 = c_1 + 1
 elsif(s[n] == "TLE")
  c_2 = c_2 + 1
 else
  c_3 = c_3 + 1
 end

end

puts "AC x #{c_0}"
puts "WA x #{c_1}"
puts "TLE x #{c_2}"
puts "RE x #{c_3}"

Measured memory_bytes: 15012
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n, cnt=0;
    cin >> n;
    vector<int>p(n);
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    for(int i=0; i<n-1; i++){
        if(p[i]==i+1){
            swap(p[i],p[i+1]);
            cnt++;
        }
    }
    if(p[n-1]==n) cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3784