akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[5001][5001];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    ll countneg=0;
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=abs(a[i]);
        if(a[i]<0)
        {
            countneg++;
        }
        a[i]=abs(a[i]);
    }
    //cout<<countneg<<endl;
    sort(a,a+n);
    if(countneg%2==0)
    {
        cout<<sum;    
    }
    else
    {
        cout<<sum-2*a[0];
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<ll> a(n);
	vector<ll> b(n);
	vector<ll> many;
	ll ausf = 0;
	int ans = 0;
	ll suma = 0;
	ll sumb = 0;
	for( auto &i : a ) cin >> i;
	for( auto &i : b ) cin >> i;
	for( int i = 0; i < n; ++i ){
		suma += a[i];
		sumb += b[i];
		ll dif = a[i] - b[i];
		if( dif > 0 ){
			many.push_back(dif);
		}  else if( dif < 0 ){
			ausf += (-dif);
			++ans;
		}
	}
	if( ausf == 0 ){
		cout << "0" << endl;
		return 0;
	}
	if( suma < sumb ){
		cout << "-1" << endl;
		return 0;
	}
	sort( many.begin(), many.end(), greater<ll>() );
	int bound = many.l_ength();
	ll presum = 0;
	for( int i = 0; i < bound; ++i ){
		presum += many[i];
		if( presum >= ausf ){
			cout << ans + i + 1 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2428
/**
 *    author:  [itmo] enot.1.10
 *    created: 04.09.2016 15:04:22       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 2010;

int a[N];
int b[N];

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int n, x;
    scanf("%d%d", &n, &x);
    forn(i, n) scanf("%d", a + i);
    ll res = 1e18;
    forn(i, n) b[i] = 1e9;
    forn(k, n)
    {
        ll val = k * (ll)x;
        forn(i, n)
        {
            b[i] = min(b[i], a[(i + k) % n]);
            val += b[i];
        }
        res = min(res, val);
    }
    printf("%lld\n", res);


    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N(222222);
typedef long long LL;
LL s[N];
int a[N], b[N], le[N], ri[N];
int n, k;
LL inf(1ll << 60);
inline bool inRange(int x, int le, int ri) {
	if(le < ri) {
		return le < x && x < ri;
	}else {
		return le < x || x < ri;
	}
}
inline int getDis(int x, int ri) {
	if(x < ri) {
		return ri - x;
	}else {
		return k - x + ri;
	}
}
void print(map<int, LL> & mp) {
	for(auto i : mp) {
		printf("%d %lld\n", i.first, i.second);
	}
	printf("END\n");
}
int main() {
	scanf("%d%d", &n, &k);
	map<int, LL> mp;
	LL ans(0);
	for(int i(1); i <= n; i++) { 
		scanf("%d%d", &a[i], &b[i]);
		ans += a[i] * 2;
		s[i] = s[i - 1] + a[i];
		if(b[i] == 1 && a[i] * 2 > k) {
			printf("-1\n");
			return 0;
		}
		le[i] = (-2 * s[i] % k + k) % k;
		ri[i] = (-2 * s[i - 1] % k + k) % k;
	//	cout << le[i] << ' ' << ri[i] << endl;
		if(b[1] == 2 || !inRange(le[i], le[1], ri[1])) {
			mp[le[i]] = 0;
		}
		if(b[1] == 2 || !inRange(ri[i], le[1], ri[1])) {
			mp[ri[i]] = 0;
		}
	}
	//print(mp);
	for(int i(2); i <= n; i++) {
		if(b[i] == 2)
			continue;
		LL tmp(inf);
		for(;;) {
			auto itr(mp.lower_bound(le[i] + 1));
			if(itr != mp.end() && inRange(itr->first, le[i], ri[i])) {
				tmp = min(tmp, itr->second + getDis(itr->first, ri[i]));
				mp.erase(itr);
			}else {
				break;
			}
		}
		for(;;) {
			auto itr(mp.lower_bound(ri[i]));
			if(itr != mp.begin()) {
				itr--;
				if(inRange(itr->first, le[i], ri[i])) {
					tmp = min(tmp, itr->second + getDis(itr->first, ri[i]));
					mp.erase(itr);
				}else {
					break;
				}
			}else {
				break;
			}
		}
		if(tmp != inf) {
			if(!mp.count(ri[i]))
				mp[ri[i]] = inf;
			mp[ri[i]] = min(mp[ri[i]], tmp);
		}
		//print(mp);
	}
	LL ans1(inf);
	for(auto i : mp)
		ans1 = min(ans1, i.second);
	cout << ans + ans1 << endl;

}


Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int A, B, X;
  
  cin >> A >> B;
  
  if((B - 1) % (A - 1) == 0){
    X  = (B - 1) / (A - 1);
  }
  else{
    X = (B - 1) / (A - 1) + 1;
  }
  cout << X << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;


struct UnionFind {
    vector<int> root;
    
    UnionFind(int n) {
        root.assign(n,-1);
    }
    
    int find(int n){
        if(root[n] < 0) return n;
        else return root[n] = find(root[n]);
    }
    
    void connect(int a,int b){
        int ar = find(a);
        int br = find(b);
        if(ar == br) return;
        
        if(-root[ar] < -root[br]){
            root[br] += root[ar];
            root[ar] = br;
        }else{
            root[ar] += root[br];
            root[br] = ar;
        }
    }
};


int main()
{
    int N,M;
    cin >> N >> M;
    UnionFind U(M);
    set<int> s;
    
    rep(i,N){
        int K;
        cin >> K;
        int l,r;
        rep(j,K){
            cin >> l;
            l--;
            s.insert(l);
            if(j == 0) r = l;
            else U.connect(r,l);
        }
    }
    set<int> bb;
    rep(i,M) bb.insert(U.find(i));
    
    if(bb.size()-(M-s.size()) == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    
    

    return 0;
}



Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<long> A(N);
  rep(i, 0, N) cin >> A[i];

  int two = 0;
  int four = 0;
  int odd = 0;
  rep(i, 0, N) {
    if (A[i] % 4 == 0) {
      ++four;
    } else if (A[i] % 2) {
      ++odd;
    } else {
      ++two;
    }
  }
  if (four == 0 && odd > 0) {
    cout << "No" << endl;
  } else if (four - odd < -1) {
    cout << "No" << endl;
  } else if (odd - four == 1 && two > 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <iomanip>
#include <unordered_map>
#include <string>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int N = 100010;
int h[N],e[2*N], ne[2*N], height[N], idx;
int n, m;
int a, b, cnt;
void add(int u, int v) {
    e[idx] = v;
    ne[idx] = h[u];
    h[u] = idx ++;
}

bool check(int u) {
    for(int i = h[u]; i != -1; i = ne[i]) {
        int j = e[i];
        if(height[j] >= height[u]) return false;
    }
    return true;
}
int main() {
    memset(h, -1, sizeof h);
    cin >> n >> m;
    for(int i = 1; i <=n ; i ++) {
        cin >> height[i];
    }
    for(int i = 1; i <= m; i ++) {
        cin >> a >> b;
        add(a, b);
        add(b, a);
    }
    for(int i = 1; i <= n; i ++) {
        if(check(i)) cnt ++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 5976
#include <stdio.h>

int gcd(int,int);
int main(void){
  int a,b;

    while(scanf("%d%d",&a,&b) != EOF){
      printf("%d %d\n",gcd(a,b),a / gcd(a,b) * b );
    }

  return 0;
}

int gcd(int x,int y){
  int t;
  if(x < y) {t=x;x=y;y=t;}

  if(y == 0) return x;
  else return gcd(y, x % y);
}

Measured memory_bytes: 0
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int r = stdIn.nextInt();
    int d = stdIn.nextInt();
    int x2000 = stdIn.nextInt();
    int[] x = new int[11];
    x[0] = x2000;
    for(int i = 1;i<x.length;i++) {
      x[i] = x[i-1]*r-d;
      System.out.println(x[i]);
    }
  }
}


Measured memory_bytes: 22612
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long

bool adj[101][101]={};
int n;

int main() {
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int v;
			cin>>v;
			adj[u][v]=true;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<n;j++){
			cout<<adj[i][j]<<" ";
		}
		cout<<adj[i][n]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3112
#include <cstdio>
#include <cstring>

//2のx_乗の計算。
template<class T>T pow2(T x_)
{
	if (x_ == 0)return 1;
	T ans = pow2(x_ / 2);
	return ans * ans * ((x_ % 2) ? 2 : 1);
}

using ll = long long;

ll ans = 0;

int strnum;
int a[10];

int main()
{
	char str[11];
	scanf("%s",str);
	strnum = strlen(str);
	
	for (int i = 0; i < strnum; ++i)a[i] = str[i] - '0';
	int maxbit = pow2(strnum - 1);
	for (int bit = 0; bit < maxbit; ++bit)
	{
		ll plus = 0;
		ll hold = a[0];
		for (int dig = 0; dig < strnum - 1; ++dig)
		{
			if (bit & (1 << dig))
			{
				hold *= 10;
				hold += a[dig + 1];
			}
			else
			{
				plus += hold;
				hold = a[dig + 1];
			}
		}
		plus += hold;
		ans += plus;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main() 
{
	ll n , d ;
	cin >> n >> d;
	ll a[n][d];
	for(int i=0;i<n;i++)
		for(int j=0;j<d;j++)
			cin >> a[i][j];
	
	int count = 0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
		{
			ll ans = 0 ;
			for(int k = 0 ; k < d ; k++)
				ans+= (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			ll rt = sqrt(ans);
			if(rt*rt==ans)
				count++;
		}
		cout << count ;
}

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


//defines...
#define ll long long
#define tata return;
#define pb push_back
#define mp make_pair
#define in insert
#define run ios_base::sync_with_stdio(false);cin.tie(NULL);
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define vec vector<ll>
#define setl set<ll>
#define mapl map<ll,ll>
#define shunno cout<<0<<endl;
#define pi 2*acos(0.0)1
#define hobena cout<<-1<<endl;




void oka()
{
   ll n,m;
   cin>>n>>m;
   if(n==m)
    yes
    else
    no


}






int main()
{
   //string g="abcd";
    //g.erase(g.begin()+3);
    //cout<<g<<endl;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    run
    ll i,t;
    t=1;
   //cin>>t;


    for(i=1;i<=t;i++)
    {


    oka();
    }






}


Measured memory_bytes: 3604
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)

	min := a + b
	if a+c < min {
		min = a + c
	}
	if b+c < min {
		min = b + c
	}
	fmt.Println(min)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    lli d,t,s;
    cin>>d>>t>>s;
    double z=((1.0*d)/(1.0*s));
    // cout<<z<<endl;
    if(t>=z)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
return 0;
}

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

int main() {
    int N; cin >> N;
    ll K; cin >> K;
    vector<ll> A(N), F(N);
    ll atotal = 0;
    rep(i, N){
        cin >> A[i];
        atotal += A[i];
    }
    rep(i, N){
        cin >> F[i];
    }
    sort(A.begin(), A.end());
    sort(F.begin(), F.end());
    reverse(F.begin(), F.end());

    if(atotal <= K){
        cout << 0 << endl;
    } else {
        ll left = 0;
        ll right = 1e12;
        while(right - left > 1){
            ll mid = (left+right) / 2;
            ll cnt = 0;
            rep(i, N){
                if(A[i] * F[i] > mid){
                    ll m = mid / F[i];
                    cnt += A[i] - m;
                }
            }
            if(cnt <= K){
                right = mid;
            } else {
                left = mid;
            }
        }
        cout << right << endl;
    }

    return 0;
}

Measured memory_bytes: 6420
#include<stdio.h>
#include<math.h>

int check(long s);

long p[80000],pc=0;

int main(void){
	long n,i,ans;
	
	
	while(scanf("%ld",&n)!=EOF){
		ans=0;
		
		for(i=2;i<=n;i+=2){
			if(check(i)==0)ans++;
			if(i==2)i-=1;
		}
		
		printf("%d\n",ans);
		
	}
	return 0;
}


int check(long s){
	long i;
	//struct cell *y;
	
	if(s%2==0 && s!=2)return -1;
	
	i=sqrt(s);
	if(i*i==s)return -1;
	
	for(i=0;i<pc;i++){
		if(p[i]>sqrt(s))break;
		if(s%p[i]==0)return -1;
	}
	
	
	if(s>p[pc-1] || pc==0){
		p[pc]=s;
		pc++;
	}
	
	
	return 0;
}

Measured memory_bytes: 716
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {

    int d,t,s; cin >> d >> t >> s;

    if(d <= t*s) cout << "Yes";
    else cout << "No";

}


Measured memory_bytes: 3632
n = gets.to_i
a_array = gets.strip.split.map(&:to_i)
sum = 1
if a_array.include?(0)
  puts 0
  exit
end
a_array.each do |a|
  sum *= a
  if sum > 10 ** 18
    puts -1
    exit
  end
end
puts sum

Measured memory_bytes: 23452
H,N=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
dp=[0]*10001+[10**9]*H
for i in range(1,H+10001):
    for a,b in AB:
        if i>=a:
            dp[i]=min(dp[i],dp[i-a]+b)
print(dp[-1])

Measured memory_bytes: 42348
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
lli dp[1 << 20] = {};
void solve(long long N, std::vector<std::vector<long long>> a)
{
  // dp[mask] := maskを使ったときのoptimalな分け方
  // dp[mask] := max(maskは全部一緒, dp[a] + dp[b] {a, bは少なくとも分ける}){a, b}
  dp[0] = 0;
  rep(i, 1 << N)
  {
    if (!i)
      continue;
    dp[i] = -1e18;

    lli tmp = 0;
    rep(j, N) rep(k, j)
    {
      if (((i >> j) & (i >> k)) & 1)
      {
        tmp += a[j][k];
      }
    }
    dp[i] = tmp;
    for (lli T = i; T; T = (T - 1) & i)
    {
      if (T == 0)
        break;
      chmax(dp[i], (dp[T] + dp[i ^ T]));
    }
  }

  cout << dp[(1 << N) - 1] << endl;
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<std::vector<long long>> a(N, std::vector<long long>(N));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      scanf("%lld", &a[i][j]);
    }
  }
  solve(N, std::move(a));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<stdlib.h>
#include<cstring>
using namespace std;

int main(){
  int n,i,j,k;
  int bad=0;
  char w[100][11];
    
  cin>>n;
  for(i=0;i<n;i++){
    cin>>w[i];
    for(j=0;j<i;j++){
      if(strcmp(w[i],w[j])==0){
        bad++;}
    }
  }
  
 for(i=0;i<n-1;i++){
    for(j=0;j<11;j++){
      if(w[i][j]=='\0')
        break;
    }
   
     if(w[i][j-1]!=w[i+1][0])
       bad++;
  }
  
cout<<(bad==0?"Yes":"No")<<endl;
  
  
  return 0;
  
  
}

Measured memory_bytes: 256
import math
data = list(map(int,input().split()))
a = data[0]
b = data[1]
x = data[2]

c = a*a*b/2
d = a*a*b-x
if d==0:
  print(0)
else:
  if x>c:
    e = ((d/a)*2)/a
    t = a/e
    print(90-math.degrees(math.atan(t)))
  else:
    f = ((x/a)*2)/b
    t = f/b
    print(90-math.degrees(math.atan(t)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
   string s;
   int n;
   cin>>n>>s;
   if(n%2!=0){
       cout<<"No"<<endl;
   }

   else
   {
       string s1=s.substr(0,n/2);
       string s2=s.substr(n/2,n/2);

       if(s1==s2){
           cout<<"Yes"<<endl;

       }
       else
       {
           cout<<"No"<<endl;
       }
       
   }
   
   
   }


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll a, b, x;
  scanf("%lld%lld%lld", &x, &a, &b);
  printf("%s", b - a <= 0 ? "delicious" : (b - a <= x ? "safe" : "dangerous"));
  return 0;
}

Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // double
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ios::sync_with_stdio(false);
  while(1) {
      int a,b;
      cin >> a >> b;
      if(a == 0 && b == 0) break;
      vector<vector<string>> data(a,vector<string>(b,"#"));
      rep(i,a) {
          rep(j,b) {
              if(0 < i && i < a - 1 && 0 < j && j < b - 1) data[i][j] = ".";
          }
      }
      rep(i,a) {
          rep(j,b) cout << data[i][j];
          cout << "\n";
      }
      cout << "\n";
  }
}


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

const int SIZE = 8;

int row[SIZE];
bool column[SIZE];
bool forwardDown[SIZE * 2 - 1], backDown[SIZE * 2 - 1];

bool map[SIZE][SIZE];

void Initialize() {

	for (int i = 0; i < SIZE; ++i) {
		row[i] = -1;
		column[i] = false;
		for (int j = 0; j < SIZE; ++j)
			map[i][j] = false;
	}

	for (int i = 0; i < SIZE * 2 - 1; ++i) {
		forwardDown[i] = false;
		backDown[i] = false;
	}

}

void print() {

	for (int i = 0; i < SIZE; ++i)
		for (int j = 0; j < SIZE; ++j)
			if (map[i][j] == true && row[i] != j)
				return;

	for (int i = 0; i < SIZE; ++i) {
		for (int j = 0; j < SIZE; ++j) {

			if (row[i] == j)
				cout << "Q";
			else
				cout << ".";

		}
		cout << endl;
	}


}

void SetQueen(int index) {

	// 成功
	if (index == SIZE) {
		print();
	}

	for (int i = 0; i < SIZE; ++i) {

		if (column[i] == true || forwardDown[index - i + SIZE - 1] == true ||
			backDown[index + i] == true)
			continue;

		row[index] = i;
		column[i] = true;
		forwardDown[index - i + SIZE - 1] = true;
		backDown[index + i] = true;

		SetQueen(index + 1);

		row[index] = -1;
		column[i] = false;
		forwardDown[index - i + SIZE - 1] = false;
		backDown[index + i] = false;

	}


}

int main() {

	Initialize();

	int n;
	
	cin >> n;

	for (int i = 0; i < n; ++i) {
		int r, c;
		cin >> r >> c;
		map[r][c] = true;

	}

	SetQueen(0);

	return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>
    void main()
    {
    char s[4],p=0;
      scanf("%s",s);
      for(int i=0;i<=3;i++)
      {
      if(s[i+1]-s[i] == 0) {p=2;}
      
      }
      (p==2)?(printf("Bad")):(printf("Good"));
    }

Measured memory_bytes: 128
# 累積計算

if __name__ == "__main__":
    n = int(input())
    # print(n)

    y = 100000  # 10万　100,000
    y2 = y / 1000
    for i in range(0, n):

        y4 = y2 * 1.05
        # y3 = round(y2 * 1.05 -0.5, 0)
        y3 = float(int(y2 * 1.05))
        #print("  {} {}".format(y4, y3))
        if y4 - y3 > 0:
            y4 += 1
        y2 = int(y4)
        #print("{} {}".format(i, y2 * 1000))

    print(y2 * 1000)

    # 0 105,000
    # 1 110,250 -> 111,000
    # 2 116,550 -> 117,000
    # 3 122,850 -> 123,000
    #4 129,150 -> 130,000

Measured memory_bytes: 6752
import math

N=int(input())
C,S,F = [],[],[]

for i in range(N-1):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N-1):
    ans = C[i]+S[i]
    for j in range(1,N-1)[i:]:
        ans = max(math.ceil(ans/F[j])*F[j],S[j])+C[j]
    print(ans)
    
print(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  int a, b, c, d;
  d = n%10; n /= 10;
  c = n%10; n /= 10;
  b = n%10; n /= 10;
  a = n%10;
  if (a+b+c+d == 7) cout << a << "+" << b << "+" << c << "+" << d;
  else if (a+b+c-d == 7) cout << a << "+" << b << "+" << c << "-" << d;
  else if (a+b-c+d == 7) cout << a << "+" << b << "-" << c << "+" << d;
  else if (a+b-c-d == 7) cout << a << "+" << b << "-" << c << "-" << d;
  else if (a-b+c+d == 7) cout << a << "-" << b << "+" << c << "+" << d;
  else if (a-b+c-d == 7) cout << a << "-" << b << "+" << c << "-" << d;
  else if (a-b-c+d == 7) cout << a << "-" << b << "-" << c << "+" << d;
  else if (a-b-c-d == 7) cout << a << "-" << b << "-" << c << "-" << d;
  dump("=7");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int n,s=0;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			for(int k=j+1;k<=n;k++){
				if(a[i]+a[j]>a[k]){
					s++;
				}
				else{
					break;
				}
			}
		}
	}
	cout<<s;
}


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 <bits/stdc++.h>
#define int long long
using namespace std;

int dp[100][55][55];
int ans[55][55];
int mod=1e9+7;
int n,k;

void multiply(int x)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                dp[x][i][j]=(dp[x][i][j]+dp[x-1][i][k]*dp[x-1][k][j])%mod;
            }
        }
    }
}

void find(int x)
{
    int zz[55][55]={};
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            {
                for(int k=1;k<=n;k++)
                {
                    zz[i][j]=(zz[i][j]+ans[i][k]*dp[x][k][j])%mod;
                }
            }

    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            ans[i][j]=zz[i][j];
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
// #ifndef ONLINE_JUDGE
//    freopen ("INPUT.txt" , "r" , stdin);
//    freopen ("OUTPUT.txt" , "w" , stdout);
// #endif

    clock_t clk;
	clk = clock();

// --------------Code starts here---------------------------------------------------------------------

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

    for(int i=1;i<=99;i++)
    {
        multiply(i);
    }
    vector<int>temp;
    while (k!=0)
    {
        temp.push_back(k%2);
        k/=2;
    }
    for(int i=1;i<=n;i++)
    {
        ans[i][i]=1;
    }
    for(int i=0;i<temp.size();i++)
    {
        if(temp[i])
            find(i);
    }

    int res=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            res=(res+ans[i][j])%mod;
        }
    }

    cout<<res<<"\n";
// -------------------------------------Code ends here------------------------------------------------------

    clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}


Measured memory_bytes: 2688
open System
open System
open System

type Point(coordinates: int array) =
    member this.coordiantes: int list =
        coordinates |> List.ofArray
    
    static member (-) (fst: Point, snd: Point): float =
        List.zip fst.coordiantes snd.coordiantes
        |> List.map (fun (a, b) -> a - b)
        |> List.map (fun d -> pown d 2)
        |> List.sum
        |> float
        |> sqrt
        
let isSquareNum (n: float) : bool =
    n = (int n |> float)

let combinations (l: 'a list) : ('a * 'a) list =
    let comb hd tl =
        List.map (fun x -> (hd, x)) tl
    let rec f = function
    | [] -> []
    | hd::tl ->
        (comb hd tl) @ (f tl)
    f l
        
    

[<EntryPoint>]
let main _ =
    let inputPoint _ =
        let splitted = Console.ReadLine().Split(' ')
        let coordinates = splitted |> Array.map Int32.Parse
        Point(coordinates)
    
    let [|n; _|] =
        let splitted = Console.ReadLine().Split(' ')
        splitted |> Array.map Int32.Parse
    
    let points = List.map inputPoint [1..n]
    let pairs = combinations points
    List.map Point.( - ) pairs
    |> List.filter isSquareNum
    |> List.length
    |> printf "%d"
    
    0 // return an integer exit code


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

#define MOD 1000000007

int n, m;
int memo[310][310][310];

long long dp(int i, int ma, int all){
    if(i == m) return ma == n ? 1 : 0;
    if(memo[i][ma][all] != -1) return memo[i][ma][all];

    return memo[i][ma][all] = (dp(i+1, all, all)*ma%MOD + dp(i+1, ma, all)*(all-ma)%MOD + dp(i+1, ma, all+1)*(n-all)%MOD) % MOD;
}

signed main(){
    cin >> n >> m;
    memset(memo, -1, sizeof(memo));
    cout << dp(0, 1, 1) << endl;
    return 0;
}

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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n,i;
  cin>>n;
  vector<long long int> num(n);
  long long int dp[n];
  for(i=0;i<n;i++){
    cin>>num[i];
  }
  dp[n-1] = 0;
  dp[n-2] = abs(num[n-1]-num[n-2]);
  for(i=n-3;i>=0;i--){
    dp[i] = min(abs(num[i]-num[i+2])+dp[i+2],dp[i+1]+abs(num[i]-num[i+1]));
  }
  cout<<dp[0]<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
    int S,h,m,s;
    scanf("%d",&S);
    h = S/(60*60);
    m = S%(60*60)/60;
    s = S%(60*60)%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

Measured memory_bytes: 2760
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll inv(ll a) {
    ll b = mod - 2, c = 1;
    while (b) {
        if (b % 2) c = c * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return c;
}

int main() {
    ios::sync_with_stdio(false);
    int n, a[10004] = {}, b[1000006] = {};
    ll z = 1, y = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
        int j = a[i];
        for (int k = 2; k * k <= a[i]; k++) if (j % k == 0) {
            int c = 0;
            while (j % k == 0) j /= k, c++;
            b[k] = max(b[k], c);
        }
        if (j > 1) b[j] = max(b[j], 1);
    }
    for (int i = 1; i <= 1000000; i++) for (int j = 0; j < b[i]; j++) z = z * i % mod;
    for (int i = 1; i <= n; i++) y = (y + z * inv(a[i])) % mod;
    cout << y;
}


Measured memory_bytes: 7620
#include <cstdio>
int k, n, z, d, a[300005];
int main() {
	int i;
	scanf("%d%d", &k, &n);
	if(k%2) {
		for(i=0; i<n; i++) a[i] = (k+1)/2;
		z = n-1;
		d = n/2;
		while(d--) {
			a[z]--;
			if(a[z]) z = n-1;
			else a[z]=k, z--;
		}
		for(i=0; i<=z; i++) printf("%d ", a[i]);
	} else {
		printf("%d ", k/2);
		while(--n) printf("%d ", k);
	}
	return 0;
}

Measured memory_bytes: 3328
N = int(input())
S, T = map(str, input().split())
res = ""
for i in range(2 * N):
  if i % 2 == 0:
    idx = int(i / 2)
    res += S[idx]
  else:
    idx = int((i - 1) / 2)
    res += T[idx]
print(res)

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

vvi g;
vector<int> d;

void bfs(int s){ // sを根としてbfs
  stack<int> st;
  d[s] = 0;
  st.push(s);
  
  while(!st.empty()){
    int next = st.top();
    st.pop();
    
    rep(i, g[next].size()){
      int c = g[next][i];
      
      if(d[c] == -1){
	d[c] = d[next] + 1;
	st.push(c);
      }
    }
  }
}

signed main(){
  int n, m; cin >> n >> m;
  g.resize(n);
  d.resize(n,-1);
  rep(i,m){
    int x, y, z; cin >> x >> y >> z; x--; y--;
    g[x].pb(y);
    g[y].pb(x);
  }
  int c = 0;
  rep(i,n){
    if(d[i] == -1){
      bfs(i);
      c++;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 8052
import sys
input = sys.stdin.readline

def solve(N, M, adjL, outdegs):
    dp = [0] * N
    for v in reversed(range(N-1)):
        dp[v] = sum([dp[v2] for v2 in adjL[v]]) / outdegs[v] + 1

    ans = dp[0]
    for vRem in range(N-1):
        if outdegs[vRem] == 1: continue
        sumDP, maxDP = 0, -1
        for v2 in adjL[vRem]:
            sumDP += dp[v2]
            if dp[v2] > maxDP:
                maxDP = dp[v2]
        dp[vRem] = (sumDP-maxDP) / (outdegs[vRem]-1) + 1
        for v in reversed(range(vRem)):
            dp[v] = sum([dp[v2] for v2 in adjL[v]]) / outdegs[v] + 1
        ans = min(ans, dp[0])

    print(ans)


N, M = map(int, input().split())
adjL = [[] for _ in range(N)]
outdegs = [0] * N
for _ in range(M):
    s, t = map(int, input().split())
    s, t = s-1, t-1
    adjL[s].append(t)
    outdegs[s] += 1

solve(N, M, adjL, outdegs)


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

long long int arr[1005][1005];
long long int h, w;
long long int a[1005][1005];

long long find_path(long long int row, long long int col)
{
    if(row>h||col>w){
        return 0;
    }
    else if(arr[row][col]!=-1)
        return arr[row][col]%1000000007;
    else if((row==h&&col<w&&a[row][col+1]==1)||(col==w&&row<h&&a[row+1][col]==1))
    {
        arr[row][col]=0;
    }
    else if(row==h&&col==w){
        return 1;
    }
    else if(row<h&&col<w&&a[row+1][col]==0&&a[row][col+1]==0){
        arr[row][col] = find_path(row+1, col)%1000000007+find_path(row, col+1)%1000000007;
    }
    else if(row<h&&a[row+1][col]==0){
        arr[row][col] = find_path(row+1, col)%1000000007;
    }
    else if(col<w&&a[row][col+1]==0){
        arr[row][col] = find_path(row, col+1)%1000000007;
    }
    else{
        arr[row][col]=0;
    }
    return arr[row][col]%1000000007;
}

int main() {
    long long int i, j;
    char input;
    cin>>h>>w;
    for(i=1;i<=h;i++){
        for(j=1;j<=w;j++){
            cin>>input;
            if(input=='.')
                a[i][j]=0;
            else
                a[i][j]=1;
            arr[i][j]=-1;
        }
    }

    cout<<find_path(1, 1)%1000000007<<endl;

}


Measured memory_bytes: 16128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int n, m;
	std::cin >> n >> m;
	std::vector<int> p(m), y(m);
	std::vector<std::vector<int>> py(n, std::vector<int>());
	rep(i, m) {
		std::cin >> p[i] >> y[i];
		py[p[i] - 1].push_back(y[i]);
	}

	rep(i, n) std::sort(allof(py[i]));

	rep(i, m) {
		printf("%06d%06d\n", p[i], lower_bound(allof(py[p[i] - 1]), y[i])
			- py[p[i] - 1].begin() + 1);
	}

	return 0;
}

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

int main()
{
    int n,a,b;
    cin >>n >>a >>b;
    int p1 = 0, p2 = 0, p3 = 0;
    for(int i = 0; i < n; i++){
        int p; cin>>p;
        if(p <= a) p1++;
        else if(p <= b) p2++;
        else p3++;
    }
    cout << min(p1, min(p2, p3)) <<endl;
    return 0;
}



Measured memory_bytes: 256
n, k= [0] * 2
p = []

def format_input(filename = None):
	global n, k
	global p
	if filename == None:
		n, k = list(map(int, input().split()))
		p = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(1, 2 * 10**5)
		k = rng(1, n)
		p = [rng(1, 10**3) for i in range(n)]

def get_answer():
	e = []
	e.append(sum(p[0:k]))
	for i in range(n - k):
		e.append(e[i]-p[i]+p[i+k])
	e.sort()
	answer = float(e.pop() + k) / 2.0
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 25604
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L M(L f){return f?B[f]+M(f^f&-f):0;}
L S(L a,L i){for(a=M(i++G i);i<2e5;i+=i&-i)B[i]+=a;}
L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)
    d=I->first,d-P[f]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}
L K(L f){a=X[f];n=X[b];return a-n?M(O[Z[a]>Z[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(n=0);Z[a=H[P[n]]-n?n:0];*Z=++n)for(;!O[a];S(a=H[a],O[a]=++b))X[a]=n;
       for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

Measured memory_bytes: 38012
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;
signed main()
{
    fast;
   
    ll i,n;
    cin>>n;
    ll a[n+2] , b[n+2];
    for(i=0;i<n;i++)
    {
    	cin>>a[i]>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n,greater<ll>());
    if(n&1)
    {
    	cout<<b[n/2] - a[n/2] + 1;
    }
    else
    {
    	cout<<b[n/2] + b[n/2-1] - (a[n/2] + a[n/2 -1]) + 1;
    }
    



}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    ll x, y;
    cin >> x >> y;

    if(x+y <= 1){
        cout << "Brown" << endl;
        return 0;
    } else if(abs(x-y) > 1){
        cout << "Alice" << endl;
        return 0;
    } else{
        cout << "Brown" << endl;
    }
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
A = list(map(int,input().split()))
A.reverse()

left = True
ans = deque()
while A:
    if left: ans.appendleft(A.pop())
    else: ans.append(A.pop())
    left = not left
if n % 2 == 0: ans.reverse()
print(' '.join(str(a) for a in ans))

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

  int h, w, k;
  cin >> h >> w >> k;
  vector<string> rows(h);
  for (int y = 0; y < h; y++) {
    cin >> rows[y];
  }

  auto is_empty_row = [](const string& row) -> bool {
    for (char c : row) {
      if (c == '#') return false;
    }
    return true;
  };

  auto output = Make2DVector(h, w, 0);
  vector<int> row_filled(h);
  int c = 1;
  for (int y = 0; y < h; y++) {
    if (is_empty_row(rows[y])) continue;
    int s_count = 0;
    for (int x = 0; x < w; x++) {
      if (rows[y][x] == '#') {
        s_count++;
        if (s_count >= 2) c++;
      }
      output[y][x] = c;
    }
    c++;
    row_filled[y] = true;
  }

  for (int y = 0; y + 1 < h; y++) {
    if (row_filled[y] && !row_filled[y + 1]) {
      output[y + 1] = output[y];
      row_filled[y + 1] = true;
    }
  }

  for (int y = h - 1; y - 1 >= 0; y--) {
    if (row_filled[y] && !row_filled[y - 1]) {
      output[y - 1] = output[y];
      row_filled[y - 1] = true;
    }
  }

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cout << output[y][x] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

    static long mod = 998244353;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int s = Integer.parseInt(scan.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(scan.next());
        }
        scan.close();

        long[][] dp = new long[n][s + 1];
        dp[0][0] = 2;
        if (a[0] <= s) {
            dp[0][a[0]] = 1;
        }

        for (int i = 1; i < n; i++) {
            for (int j = 0; j <= s; j++) {
                dp[i][j] += dp[i - 1][j] * 2;
                dp[i][j] %= mod;

                if (j - a[i] >= 0) {
                    dp[i][j] += dp[i - 1][j - a[i]];
                    dp[i][j] %= mod;
                }
            }
        }

        System.out.println(dp[n - 1][s]);
    }

}


Measured memory_bytes: 108736
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X, N,ans;
  bool flag = true;
  cin >> X >> N;
  if(N==0){
    cout << X << endl;
    return 0;
  }
  vector<int> p(N);
  for(int i=0;i<N;i++) cin >> p.at(i);
  //sort(p.begin(),p.end());
  for(int i=0;i<101;i++){
    flag = true;
    for(int j=0;j<N;j++) if(p.at(j) == X - i) flag = false;
    if(flag){
      cout << X - i << endl;
      return 0;
    }
    flag = true;
    for(int j=0;j<N;j++) if(p.at(j) == X + i) flag = false;
    if(flag){
      cout << X + i << endl;
      return 0;
    }
  }
}
     

Measured memory_bytes: 3624
import collections

A, B = map(int,input().split(' '))

# 素因数分解する
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
ac = collections.Counter(prime_factorize(A))
#print(prime_factorize(A))
bc = collections.Counter(prime_factorize(B))
keylist = set(ac.keys()) | set(ac.keys())
#keylist.add(set(bc.keys()) )
#print(keylist)
#print(ac,bc)
tmp=0

#print(ac[3])
dlist=[]
for key in keylist:
    if ac[key] > 0 and bc[key] > 0:
        dlist.append([key,min(ac[key],bc[key])])
    #tmp+= max(ac[key],bc[key] )

#print(dlist)
cnt=0
print(len(dlist)+1)
#for i in range(len(dlist)):
#    cnt+=pow(2,dlist[i][1])

#print(cnt-1)


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


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

    int b = 0;
    for (int i = 0; i < sz(s); i++) {
        b |= (1 << (s[i] - 'a'));
    }

    for (int i = 0; i < 26; i++) {
        if(~b&(1<<i)){
            cout << (char)('a' + i) << endl;
            return 0;
        }
    }
    puts("None");

    return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int main(){
	int n;	
	while(~scanf("%d",&n)){	
		if(n==0) break;
		priority_queue<P> que;
		for(int i=0;i<n;i++){
			int p,d1,d2;
			scanf("%d %d %d",&p,&d1,&d2);
			que.push(P(d1+d2,p));
		}

		printf("%d %d\n",que.top().second,que.top().first);
	}
}

Measured memory_bytes: 1120
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define PB push_back
#define ll long long
using  namespace std;
template <class T>
inline void read(T &x)
{
   x=0; char c=getchar(); int f=1;
   while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
   while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
vector<int> G[N];
int ans[N],sub[N],p[N],son[N],head[N],sz[N],ecnt,n;
int fa[N],mx[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
struct ed{int to,next;}e[N<<1];
void ad(int x,int y)
{
	e[++ecnt]=(ed){y,head[x]}; head[x]=ecnt;
	e[++ecnt]=(ed){x,head[y]}; head[y]=ecnt;
}
void dfs1(int u,int last)
{
	p[u]=last,mx[u]=max(mx[last],last);
	//if(mx[u]) G[mx[u]].PB(u);
	for(int k=head[u];k;k=e[k].next)
	{
		int v=e[k].to; if(v==last) continue;
		dfs1(v,u);
	}
}
void dfs2(int u)
{
	if(u!=1) ans[u]+=ans[mx[u]]-sub[son[mx[u]]];
	for(int k=head[u];k;k=e[k].next)
	{
		int v=e[k].to; if(v==p[u]) continue;
		son[u]=v,dfs2(v);
	}
}
void un(int x,int y)
{
	int fx=find(x),fy=find(y);
	if(sz[fx]>sz[fy]) swap(fx,fy);
	fa[fx]=fy,sz[fy]+=sz[fx];
}
int main()
{
	int x,y; read(n);
	for(int i=1;i<n;i++) read(x),read(y),ad(x,y);
	dfs1(1,0);
	for(int i=1;i<=n;i++) fa[i]=i,sz[i]=i!=1;
	for(int i=2;i<=n;i++) G[mx[i]].PB(i);
	for(int i=1;i<=n;i++)
	{
		int tot=G[i].size();
		for(int j=0;j<tot;j++)
		{
			int u=G[i][j]; ans[u]=1;
			if(u<i) ans[u]+=sz[find(u)]-1;
			else
			{
				for(int k=head[u];k;k=e[k].next)
				{
					int v=e[k].to;
					if(v<i)
					{
						if(v!=p[u]) sub[v]=sz[find(v)];
						ans[u]+=sz[find(v)];
					}
				}
			}
		}
		for(int k=head[i];k;k=e[k].next)
		{
			int v=e[k].to;
			if(v<i) un(v,i);
		}
	}
	dfs2(1);
	for(int i=2;i<=n;i++) printf("%d ",ans[i]); puts("");
	return 0;
}

Measured memory_bytes: 22772
#include<bits/stdc++.h>
#define rep(i,l,r) for (ll i=l;i<=r;i++)
using namespace std;
typedef long long ll;
ll a,b,c,ansx[300007],ansy[300007],N,M,T,t,K,X,Y,px,py;
int main(){
	scanf("%lld%lld%lld",&K,&X,&Y);
	if (K%2==0&&(X+Y)%2) printf("-1\n");
	else{
		while (abs(px-X)+abs(py-Y)>K*2){
			if (abs(px-X)>K){
				if (px>X) px-=K,ansx[++t]=px,ansy[t]=py;
				else px+=K,ansx[++t]=px,ansy[t]=py;
			}
			else{
				if (py>Y) py-=K,ansx[++t]=px,ansy[t]=py;
				else py+=K,ansx[++t]=px,ansy[t]=py;
			}
		}
		if (abs(px-X)+abs(py-Y)!=K){
			if (K%2&&(X+Y+px+py)%2){
				if (abs(py-Y)<=K){
					if (px<X) px+=K-abs(py-Y);
						else px-=K-abs(py-Y);
					py=Y;
				}
				else{
					if (py<Y) py+=K-abs(px-X);
						else py-=K-abs(px-X);
					px=X;
				}
				ansx[++t]=px; ansy[t]=py;
			}
			ll a=(K*2-abs(px-X)-abs(py-Y))/2;
			if (abs(px-X)<abs(py-Y)){
				if (px<=X){
					ansx[++t]=X+a;
					if (py<Y) ansy[t]=py+K-(X+a-px); else ansy[t]=py-(K-(X+a-px));
				}
				else{
					ansx[++t]=X-a;
					if (py<Y) ansy[t]=py+K-(px-X+a); else ansy[t]=py-(K-(px-X+a));
				}
			}
			else{
				if (py<=Y){
					ansy[++t]=Y+a;
					if (px<X) ansx[t]=px+K-(Y+a-py); else ansx[t]=px-(K-(Y+a-py));
				}
				else{
					ansy[++t]=Y-a;
					if (px<X) ansx[t]=px+K-(py-Y+a); else ansx[t]=px-(K-(py-Y+a));
				}
			}
		}
		ansx[++t]=X,ansy[t]=Y;
		printf("%lld\n",t);
		rep(i,1,t) printf("%lld %lld\n",ansx[i],ansy[i]);
	}
	return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	int n;
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		int count[10];
		
		for(int i = 0; i < 10; i++){
			count[i] = 0;
		}
		
		for(int i = 0; i < n; i++){
			int hoge;
			cin >> hoge;
			count[hoge]++;
		}
		
		for(int i = 0; i < 10; i++){
			if(count[i] == 0){
				cout << "-" << endl;
			}else{
				for(int j = 0; j < count[i]; j++){
					cout << "*";
				}
				cout << endl;
			}
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 2984