akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main(){
	
	
	bool bot = true;
	int h, w;
	cin >> h >> w;
	string board[50];
	for (int i = 0;i < h;i++) cin >> board[i];
	const int dx[4] = {1,0,-1,0};
	const int dy[4] = { 0,-1,0,1 };
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (board[i][j] == '.') continue;
			bool can = false;
			for (int k = 0;k < 4;k++) {
				int ni = i + dx[k];
				int nj = j + dy[k];
				if (ni < 0 or h <= ni) continue;
				if (nj < 0 or w <= nj) continue;
				if (board[ni][nj] == '#') can = true;
			}
			if (can == false) {
				bot = false;
				goto loopend;
			}
		}
	}
	if(bot==true)	cout << "Yes";
loopend:
	if(bot==false)
	cout << "No";
}

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

const int maxn = 2e5 + 10;

int n;
int cnt[26];
char s[maxn];

int main() {
//    freopen("input.in", "r", stdin);
  //  freopen("output.out", "w", stdout);

    scanf("%s", s);
    n = strlen(s);
    for (int i = 0; s[i]; ++i) cnt[s[i] - 'a']++;
    long long ans = 1 + 1ll * n * (n - 1) / 2;
    for (int i = 0; i < 26; ++i)
        ans -= 1ll * cnt[i] * (cnt[i] - 1) / 2;
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 384
def fact(n, r, modp):
    """
    n ~ (n - r + 1)の積 % modpを求める
    """
    curr = n % modp
    for x in range(n - r + 1, n):
        curr *= x
        curr %= modp
    return curr


def power(x, n, modp):
    """
    modつき累乗
    return x^n % modp
    """
    if n == 0:
        return 1

    k = 1
    while n > 1:
        if n % 2:
            k *= x
            k %= modp
        x *= x
        x %= modp
        n //= 2

    return (k * x) % modp


def combination(n, r, modp):
    """
    modつき組み合わせ計算
    return n_C_r % modp
    """ 
    # フェルマーの小定理を利用
    num = fact(n, r, modp)
    den = fact(r, r, modp)

    c = num * power(den, modp - 2, modp)
    return c % modp


def submit():
    n, a, b = map(int, input().split())
    modp = 1000000007
    ans = power(2, n, modp) - combination(n, a, modp) - \
          combination(n, b, modp) - 1
    print(ans % modp)


if __name__ == "__main__":
    submit()

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

int main(){
  int a, b;
  cin >> a >> b;
  
  int u[13] = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};
  
  int res = a + b;
  if(res < 10) cout << res << endl;
  else cout << "error" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":"\n");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    vector<int> a(n);
    cin>>a;
    map<int,int> mn,cnt;
    REP(i,n) {
        if(!CONTAIN(mn,a[i])) {
            mn[a[i]]=i;
            cnt[a[i]]=1;
        } else {
            chmin(mn[a[i]],i);
            cnt[a[i]]++;
        }
    }
    mn[0]=-1;
    int sum=0;
    vector<int> ans(n,0);
    int idx=INF;
    ITR(itr,rbegin(mn),rend(mn)) {
        if(itr->first==0) break;
        auto nxitr=next(itr);
        int diff=(itr->first)-(nxitr->first);
        sum+=cnt[itr->first];
        chmin(idx,itr->second);
        ans[idx]+=diff*sum;
    }
    cout<<ans<<endl;
    return 0;
}



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

int main() {
  struct Point {double x, y; char d;};
  int N;
  cin >> N;
  vector<vector<Point>> P(4);
  for(auto i=0; i<N; ++i) {
    double x, y; char d;
    cin >> x >> y >> d;
    auto index = [](auto c) {string S="RULD"; return find(begin(S), end(S), c) - begin(S);};
    P[index(d)].push_back({x, y, d});
  }

  auto score = [&](auto t) {
    double maxx, minx, maxy, miny;
    maxx = maxy = -1e9;
    minx = miny = 1e9;
    for(const auto& v: P) for(const auto& p: v) {
      double dx = (p.d=='R') - (p.d=='L');
      double dy = (p.d=='U') - (p.d=='D');
      auto x = p.x + t * dx;
      auto y = p.y + t * dy;
      maxx = max(maxx, x);
      minx = min(minx, x);
      maxy = max(maxy, y);
      miny = min(miny, y);
    }
    return (maxx-minx) * (maxy-miny);
  };

  vector<double> time = {0, 1e9};
  auto cmpx = [](auto l, auto r) {return l.x < r.x;};
  auto cmpy = [](auto l, auto r) {return l.y < r.y;};
  vector<vector<double>> ends(4, vector<double>(2, 0));
  for(auto d=0; d<4; ++d) if(!P[d].empty()) {
    if(d&1) {
      auto p = minmax_element(begin(P[d]), end(P[d]), cmpy);
      ends[d][0] = p.first->y;
      ends[d][1] = p.second->y;
    } else {
      auto p = minmax_element(begin(P[d]), end(P[d]), cmpx);
      ends[d][0] = p.first->x;
      ends[d][1] = p.second->x;
    }
  }
  for(auto d=0; d<2; ++d) {
    auto a = ends[d];
    auto b = ends[d+1];
    for(auto i: {0, 1}) for(auto j: {0, 1}) time.emplace_back(abs(a[i]-b[j]));
  }
  sort(begin(time), end(time));

  auto ans = 1e18;
  for(auto i=1; i<time.size(); ++i) {
    auto l=time[i-1], h=time[i];
    for(auto i=0; i<100; ++i) {
      auto m1 = (2*l+h)/3.0;
      auto m2 = (l+2*h)/3.0;
      if(score(m1) < score(m2)) h = m2;
      else                      l = m1;
    }
    ans = min(ans, score(l));
    ans = min(ans, score(h));
  }
  cout << setprecision(10) << fixed << ans << endl;
}


Measured memory_bytes: 2816
s = input()
if (s == "SUN"):
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
elif s == "SAT":
    print(1)


Measured memory_bytes: 2940
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    vector<int> hoge(3);
    for(int i=0;i<3;i++) cin>>hoge.at(i);
    int k;
    cin>>k;
    sort(hoge.begin(),hoge.end());
    hoge.at(2)*=pow(2,k);
    int ans=0;
    for(int i=0;i<3;i++) ans+=hoge.at(i);
    cout<<ans<<endl;
    
    return 0;
}

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

using namespace std;
#define int long long
#define N 666666
int  arr[N],sum[N];
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>arr[i];
	sum[n]=arr[n];
	for(int i=n-1;i>=1;i--) sum[i]=min(sum[i+1],arr[i]);
	int maxn=0;
	for(int i=1;i<=n;i++){
		maxn=max(maxn,arr[i]-sum[i]);
	}
	if(maxn>1) cout<<"No";else cout<<"Yes";
	return 0;
}

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

using namespace std;

string T,P;
int tlen,plen;

bool match(int idx){
  for(int i=0;i<plen;i++){
    if(T[idx+i]!=P[i]) return false;
  }
  return true;
}

int main(){
  cin>>T>>P;
  
  tlen=T.size();
  plen=P.size();

  for(int i=0;i<=tlen-plen;i++){
    if(match(i)){
      cout<<i<<endl;
    }
  }
}

Measured memory_bytes: 3188
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [A, B, , K] = input[0].map(Number);

  return Math.min(A, K) - Math.max(K - (A + B), 0);
};

console.log(main(read()));


Measured memory_bytes: 29676
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> A;
    for (int i = 0; i < N; i++) {
        int j;
        std::cin >> j;
        A.push_back(j);
    }
    std::sort(A.begin(), A.end());

    long long int sum = 0;
    int k = 0;
    for (int i = 0; i < N - 1; i++) {
        sum += A.at(i);
        if (sum * 2 < A.at(i + 1)) {
            k = i + 1;
        }
    }
    printf("%d\n", N - k);
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,l,c,f;
	cin>>n>>k;
	ll temp;
	vc a(n+1);
	for(i=1;i<=n;i++)cin>>a[i];
	ll ans=0;
	for(i=1;i<n;i++)
	{
	    temp=a[i]+a[i+1];
	    if(temp>k)
	    {
	        if(a[i+1]>=(temp-k))
	            a[i+1]-=(temp-k);
	        else
	            a[i+1]=0;
	        ans+=temp-k;
	    }
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3964
SS = input()
T = input()
ans = "z"*(len(SS)+1)

for i in range(len(SS) - len(T) + 1):
	temp = "?"*i + T + "?"*(len(SS)-i-len(T))
	cond = True
	for i in range(len(SS)):
		if SS[i] == "?" or temp[i] == "?":
			continue
		else:
			if SS[i] != temp[i]:
				cond = False
	if cond:
		temp_2 = []
		for i in range(len(SS)):
			if SS[i] == "?" and temp[i] == "?":
				temp_2.append("a")
			elif SS[i] == "?" and temp[i] != "?":
				temp_2.append(temp[i])
			else:
				temp_2.append(SS[i])
		temp_3 = "".join(temp_2)
		if temp_3 <= ans:
			ans = temp_3

if ans == "z"*(len(SS)+1):
	print("UNRESTORABLE")
else:
	print(ans)

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

int main(){
    int n, S[10000];
    int q, T[500];
    int sw=0;
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> S[i];
    }
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> T[i];
    }
    
    for(int i=0; i<q; i++){
        for(int j=0; j<n; j++){
            if(T[i]==S[j]){
                sw++;
                break;
            }
        }
    }
    
    cout << sw << endl;
    
    return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
int main(){
	ll n;
	cin>>n;
	
	vector<ll> dp(3);
	
	for(ll day=0;day<n;day++){
		vector<ll> ndp(3,0);
		vector<ll> c(3);
		for(ll i=0;i<3;i++){
			cin>>c[i];
		}
		
		for(ll i=0;i<3;i++){
			for(ll j=0;j<3;j++){
				if(i!=j){
					ndp[i] = max(dp[j]+c[i],ndp[i]);
				}
			}
		}
		dp = ndp;
	}
	cout<<max(max(dp[0],dp[1]),max(dp[1],dp[2]))<<"\n";
}

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

using std::pair;
using std::make_pair;
typedef pair<int, int> Pair;

#define update_max(a, b) if ((a) < (b)) (a) = (b)
#define update_min(a, b) if ((a) > (b)) (a) = (b)

const int N = 100 + 10;

struct Point {
  long long x, y;

  Point(long long x = 0, long long y = 0) : x(x), y(y) {}

  void input() {
    std::cin >> x >> y;
  }
} points[N];

int n;

bool cmp(const Point& a, const Point& b) {
  return atan2(a.y, a.x) < atan2(b.y, b.x);
}

void run(int case_id = 0) {
  std::cin >> n;
  for (int i = 0; i < n; ++ i) {
    points[i].input();
  }
  std::sort(points, points + n, cmp);

  long long answer = 0;
  for (int i = 0; i < n; ++ i) {
    Point p;
    for (int length = 0; length < n; ++ length) {
      int j = (i + length) % n;
      p.x += points[j].x;
      p.y += points[j].y;
      update_max(answer, p.x * p.x + p.y * p.y);
    }
  }

  std::cout << std::setprecision(12) << std::fixed;
  std::cout << sqrt(answer * 1.0) << "\n";
}

void multi_cases_main() {
  int num_tests;
  std::cin >> num_tests;
  for (int t = 1; t <= num_tests; ++ t) {
    run(t);
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  run();
  return 0;
}


Measured memory_bytes: 256
N,M = map(int, input().split())
a=[input() for i in range(N)]
b=[input() for i in range(M)]
 
ans = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        t = [k[j:j+M] for k in a[i:i+M]]
        if t==b: ans =1
 
print("Yes" if ans else "No")

Measured memory_bytes: 3064
a, b = map(int, input().split())
N = int(input())
books = []
for i in range(N):
    books.append(list(map(int, input().split())))

is_booked = 0
for i in range(len(books)):
    if books[i][0] <= a < books[i][1]:
        is_booked = 1
    elif a < books[i][0] < b:
        is_booked = 1

print(is_booked)



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

int main() {
  int H,W;
  cin >> H>>W;
  for (int i=0;i<W+2;i++){
  cout << "#";
}
cout<<endl;
for(int i=0;i<H;i++){
  cout << "#";
  string S;
  cin >> S;
  cout << S;
  cout << "#";
  cout<<endl;
}
for (int i=0;i<W+2;i++){
cout << "#";
}
  }


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

int main()
{
    _LL k, q;
    cin >> k >> q;
    _LL *d = new _LL[k];
    _LL *td = new _LL[k];
    rep(i, k) cin >> d[i];
    rep(t, q)
    {
        _LL n, x, m;
        cin >> n >> x >> m;
        rep(i, k) td[i] = d[i] % m;
        _LL ln = (n - 1) / k;
        _LL lm = (n - 1) % k;
        _LL dsum = 0;
        _LL count = 0;
        rep(i, k)
        {
            dsum += td[i];
            if( td[i] != 0 ) count++;
        }
        dsum *= ln;
        count *= ln;
        rep(i, lm) 
        {
            dsum += td[i];
            if( td[i] != 0 ) count++;
        }
        dsum += x % m;
        cout << count - dsum / m << endl;
    }
}

Measured memory_bytes: 3704
//
//  main.cpp
//  A_Grouping
//
//  Created by user1 on 2017/05/20.
//  Copyright © 2017年 user1. All rights reserved.
//

#include <iostream>
int x, y;
int groups[3][7] = {{1,3,5,7,8,10,12},
    {4,6,9,11},
    {2}};

void solve(){
//    //initialize with 0
//    for(int ind_group = 0; ind_group<3; ind_group++){
//        for(int ind_num = 0; ind_num<7; ind_num++){
//            groups[ind_group][ind_num] = 0;
//        }
//    }
    
    std::cin>>x;
    std::cin>>y;
        //Search for x
        for(int ind_group = 0; ind_group<3; ind_group++){
            for(int ind_num = 0; ind_num<7; ind_num++){
                if(groups[ind_group][ind_num] == x){
                    //Search for y
                    for(ind_num = 0; ind_num<7; ind_num++){
                        //same group!
                        if(groups[ind_group][ind_num] == y){
                            printf("Yes\n");
                            return;
                        }
                    }
                    //not same group
                    printf("No\n");
                    return;
                    
                }
            }
        }
    
}

int main(int argc, const char * argv[]) {
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int ans = 0;
    int count = 0;
    int now = Integer.parseInt(sc.next());
    for(int i = 1; i < N; i++){
      int n = Integer.parseInt(sc.next());
      if(n <= now){
        count++;
        now = n;
      }else{
        count = 0;
        now = n;
      }
      ans = count > ans ? count : ans;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 46588
#include<iostream>
#include<cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    for(int i=max(-1000000,b-a+1);i<=min(1000000,b+a-1);i++)printf(i==b-a+1?"%d":" %d",i);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

    int i_coinNum;
    int i_inputSumMoney;

    scanf("%d%d", &i_coinNum, &i_inputSumMoney);

    if (500 * i_coinNum >= i_inputSumMoney)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
 
using namespace std;
 
int silly_sort(vector<int> v, int n){
    vector<pair<int, int> > temp(n);
    for (int i = 0; i < n; i++){
        temp[i].first = v[i];
        temp[i].second = i;
    }
    sort(temp.begin(), temp.end());
 
    int cost = 0, s = temp[0].first;
    for (int i = 0; i < n; i++){
        int j = temp[i].second;
        if (j != i && j >= 0){
            int n = 1, amin, sum;
            amin = sum = temp[i].first;
            while (j != i){
                int next = temp[j].second;
                sum += temp[j].first;
                n++;
                temp[j].second = -1;
                j = next;
            }
            cost += min(sum + (n - 2) * amin, sum + amin + (n + 1) * s);
        }
    }
    return cost;
}
int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    cout << silly_sort(v, n) << endl;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i = 0; i < n; i++)
#define for1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(int i = n-1; i >= 0; i--)
#define fore(i,a,b) for(int i = a; i <= b; i++)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
 
 
const  int MAXn= 3e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;
 
 
int main(){
	ll h, n;
	cin >> h >> n;
	vi  a(n), b(n);
	forn(i, n) { cin >> a[i] >> b[i];}
	ll dp[h + 1];
	for(int i = 0; i <= h; i++) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < n; j++) {
			ll temp = i + a[j];
			temp = min(temp, h);
			dp[temp] = min( dp[temp], dp[i] + b[j]);
		}
	}
	cout << dp[h] ;
}
			


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a==b){
        cout<<a+b<<endl;
    }else{
        cout<<max(a,b)*2-1<<endl;
    }

}



Measured memory_bytes: 3636
#include<iostream>

int main(){
int n,a,b;
 std::cin >> n >> a >> b;
 std::string s;
 std::cin >> s;
 int pass=0,bcnt=0;
 for(int i=0;i<n;i++){
   if(s[i]=='a' && pass<a+b){
     pass++;
     std::cout << "Yes" << std::endl;
   }
   else if(s[i]=='b' && pass<a+b && bcnt<b){
    pass++;
    bcnt++;
    std::cout << "Yes" << std::endl;
   }
   else
    std::cout << "No" << std::endl;
 }
 return 0;
}


Measured memory_bytes: 3744
N,T = map(int,input().split())
c = []
t = []
hoge = []

for i in range(N):
  a,b = map(int,input().split())
  c.append(a)
  t.append(b)

for i in range(N):
  if t[i] <= T:
    hoge.append(c[i])
if hoge != []:
  print(min(hoge))
else:
  print("TLE")

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

using namespace std;
using ll = long long;

int z;

int main() {

	int a, b,c;
	cin >> a >> b >> c;

	if (a == b)cout << c << endl;
	else if (b == c) cout << a << endl;
	else cout << b << endl;
	

	//cin >> z;

	return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;
 
 
public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
	int i=0;
        int [] num = new int[n];


        for(i = 0; i < n; i++){
            num[i] = sc.nextInt();
        }


        for(i = n-1; i >= 0; i--){
            if(i != 0){
                System.out.print(num[i]);
		System.out.print(" ");
                  
            }else{
                break;
            }
        }
 		System.out.println(num[i]);
    }
}


Measured memory_bytes: 26236
def main():
    islands, regular_boat = map(int, input().split())
    departure_from_island1 = []
    arrive_to_islandN = []
    for _ in range(regular_boat):
        start, final = map(int, input().split())
        if start == 1 and final == islands:
            continue
        elif start == 1:
            departure_from_island1.append(final)
        elif final == islands:
            arrive_to_islandN.append(start)
    print("POSSIBLE" if len(set(departure_from_island1) & set(arrive_to_islandN)) > 0 else "IMPOSSIBLE")


if __name__ == '__main__':
    main()



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

template<unsigned long long SIZE> class unionFind{
    protected:
        long long uni[SIZE];
        long long diff_weight[SIZE];
    public:
        unionFind(){
            for(int i=0;i<SIZE;i++){
                uni[i]=-1;
                diff_weight[i]=0;
            }
        }
        unsigned long long root(unsigned long long a){
            if(a>=SIZE) throw std::range_error("与えられたインデックスが木の範囲外です");
            if(uni[a]<0) return a;
            else{
                unsigned long long r=root(uni[a]);
                diff_weight[a]+=diff_weight[uni[a]];
                return uni[a]=r;
            }
        }
        long long weight(unsigned long long a){
            root(a);
            return diff_weight[a];
        }
        long long diff(unsigned long long a, unsigned long long b){
            if(isSame(a,b)) return weight(b)-weight(a);
            else return INT64_MAX;
        }
        unsigned long long count(unsigned long long a){
            return -uni[root(a)];
        }
        bool merge(unsigned long long a, unsigned long long b, long long w=1){
            w+=weight(a);  w-=weight(b);
            a=root(a);  b=root(b);
            if(a==b) return false;
            if(uni[a]>uni[b]){
                swap(a, b);
                w=(-w);
            }
            uni[a]+=uni[b];
            uni[b]=a;
            diff_weight[b]=w;
            return true;
        }
        bool isSame(unsigned long long a,unsigned long long b){
            return root(a)==root(b);
        }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    unionFind<100001> uf;
    int n, m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int x, y, z;
        cin >> x >> y >> z;
        uf.merge(x, y);
    }
    int64_t ans = 1;
    for(int i=2;i<=n;i++){
        if(!uf.isSame(1, i)){
            ans++;
            uf.merge(i, 1);
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

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


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		String ans = (n<1000)?"ABC":"ABD";
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll                    long long int
#define ull                   unsigned long long int
#define vll                   vector<long long int>
#define loop(i,a,b) 		  for(ll i=(ll)a;i<(ll)b;++i)
#define pb                    push_back
#define ii					  pair<int, int> 
#define vii					  vector<ii>
#define vvi					  vector<vector<int>> 
#define pi                    acos(-1.0)
#define MOD                   1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void f_io(){
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
struct Interval 
{ 
    int val, idx; 
}; 
  
// Compares two intervals according to staring times. 
bool compareInterval(Interval i1, Interval i2) 
{ 
    return (i1.val < i2.val); 
}


int main(){ 
    f_io();
        ll t,n,w,a,k,x;
 
   
     cin>>n>>x>>k;
     if(n<x){
         cout<<k;
     }
     else{
         if(n%x==0){
             cout<<(n/x)*k;
         }
         else{
              cout<<(n/x+1)*k;
         }
     }



    
       

    }



   

      



    
    
    

        




    




      







   





         
    

Measured memory_bytes: 3656
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
		String b = sc.next();

		char[] ac = a.toCharArray();
		char[] bc = b.toCharArray();

		Arrays.sort(ac);
		Arrays.sort(bc);
		for (int i = 0; i < b.length() / 2; i++) {
			char tmp = bc[i];
			bc[i] = bc[b.length() - 1 - i];
			 bc[b.length() - 1 - i] = tmp;
		}

		String aa = new String(ac);
		String bb = new String(bc);

		int al = aa.length();
		int bl = bb.length();
		if (aa.compareTo(bb) < 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23764
import math
     
A,B,H,M = map(int, input().split())
     
hourdegrees = ( H * 60 + M ) * (0.5)
mindegrees = M*(6)
      
if mindegrees < hourdegrees:
  degree = hourdegrees - mindegrees
elif mindegrees > hourdegrees:
  degree = mindegrees - hourdegrees
elif mindegrees == hourdegrees:
  degree = 0
      
distance = math.sqrt(A ** 2 + B ** 2 -2 * A * B * math.cos(math.radians(degree) ) )
print(distance)

Measured memory_bytes: 62388
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N, L := getInt(), getInt()
	a := getInts(N)

	pos := -1
	for i := 0; i < N-1; i++ {
		if a[i]+a[i+1] >= L {
			pos = i
			break
		}
	}

	if pos == -1 {
		out("Impossible")
		return
	}

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	fmt.Println("Possible")
	for i := 0; i < pos; i++ {
		fmt.Fprintln(w, i+1)
	}
	for i := N - 2; i > pos; i-- {
		fmt.Fprintln(w, i+1)
	}
	fmt.Fprintln(w, pos+1)
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main() {
	cin.sync_with_stdio(false);
	ll H, W;
	cin >> H >> W;
	if (H % 3 == 0 || W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll s1, s2, s3,s4,s5;
	ll ans=H*W;
	int x;
	rep(i, max(H, W)+1) {
		if (min(H,W)*i > H*W / 3) {
			if (min(H, W)*i - H*W / 3 <= H*W / 3 - min(H, W)*(i - 1)) {
				x = i;
			}
			else {
					x = i - 1;
				}
			break;
		}
	}
	s1 = x*min(H, W);
	rep(i, min(H, W)) {
		s2 = i*(max(H, W) - x);
		s3 = H*W - s1 - s2;
		ans = min(max(s1, max(s2, s3)) - min(s1, min(s2, s3)), ans);
	}
	rep(i, max(H, W) - x) {
		s2 = i*min(H, W);
		s3 = H*W - s1 - s2;
		ans = min(max(s1, max(s2, s3)) - min(s1, min(s2, s3)), ans);
	}

	rep(i, min(H, W) + 1) {
		if (max(H, W)*i > H*W / 3) {
			if (max(H, W)*i - H*W / 3 <= H*W / 3 - max(H, W)*(i - 1)) {
				x = i;
			}
			else {
				x = i - 1;
			}
			break;
		}
	}
	s1 = x*max(H, W);
	rep(i, max(H, W)) {
		s2 = i*(min(H, W) - x);
		s3 = H*W - s1 - s2;
		ans = min(max(s1, max(s2, s3)) - min(s1, min(s2, s3)), ans);
	}
	rep(i, min(H, W) - x) {
		s2 = i*max(H, W);
		s3 = H*W - s1 - s2;
		ans = min(max(s1, max(s2, s3)) - min(s1, min(s2, s3)), ans);
	}
	

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  ll n,m,x;
  cin >> n >> m >> x;
  vector<ll>c(n);
  vector<vector<ll>>a(n,vector<ll>(m));
  rep(i,n){
    cin >> c[i];
    rep(j,m)cin >> a[i][j];
  }
  ll sum=1E9+7;
  vector<ll>temp(m);
  for(ll bit=0;bit<(1<<n);bit++){
    ll mm=0;
    rep(i,m)temp[i]=0;
    for(ll i=0;i<n;i++){
      if(bit&(1<<i)){
	mm+=c[i];
	rep(q,m)temp[q]+=a[i][q];
      }
    }
    bool f=true;
    rep(i,m){
      if(temp[i]<x)f=false;
    }
    if(f)sum=min(sum,mm);
  }
  if(sum==1E9+7)cout << -1;
  else cout << sum;
}



Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()

void Main()
{
    vector<string> s(3);
    rep(i, 3) cin >> s[i];
    cout << "A" << s[1][0] << "C" << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    a, b, c = map(int, input().split())
    g[a-1].append((b-1, c))
    g[b-1].append((a-1, c))


def dijkstra(s,n,g):
    # g[i][j] : the cost of i→j  or g[i] = [(target, cost), ...]
    # must import heapq
    d = [10**18] * n
    d[s] = 0
    q = [(0,s)]
    while q:
        dist_u, u = heappop(q)
        if d[u] < dist_u:
            continue
        for v, c in g[u]:  # 'in g[u]' if g is an adj list.
            if d[v] > dist_u + c:
                d[v] = dist_u + c
                heappush(q, (d[v], v))
    return d




q, k = map(int, input().split())
d = dijkstra(k-1, n, g)

for _ in range(q):
    x, y = map(int, input().split())
    print(d[x-1]+d[y-1])


Measured memory_bytes: 80304
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		char a = scanner.next().charAt(0);
		char b = scanner.next().charAt(0);
		
		if ((a == 'H' && b =='H') || (a == 'D' && b =='D')) {
			System.out.println('H');
		}else {
			System.out.println('D');
		}
	}
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
struct edge {int from, to, color; };
vector<edge> G[100010];


int cnt[100010];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    map<P, int> mp;    
    edge es[N-1];

    rep(i, N-1)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge e;
        e.from=a;
        e.to=b; 
        e.color=0;
        cnt[a]++; cnt[b]++;

        es[i]=e;
        G[e.from].push_back(e);
        G[e.to].push_back(e);
    }

    queue<int> que;  //for next vertex 
    que.push(0);

    while(!que.empty())
    {
        int v = que.front();
        que.pop();
        bool used[N];
        FILL0(used);
        int cur=1; 


        rep(i, G[v].size())
        {
            if(mp[P(G[v][i].from, G[v][i].to)]!=0)
            {
                used[mp[P(G[v][i].from, G[v][i].to)]]=true;
            }
        }

        rep(i, G[v].size())
        {
            if(mp[P(G[v][i].from, G[v][i].to)]==0)
            {
                while(used[cur])
                {
                    cur++;
                }

                if(!used[cur])
                {
                    G[v][i].color=cur;
                    mp[P(G[v][i].from, G[v][i].to)]=G[v][i].color;
                }
                
                cur++;                
            }

            if(G[v][i].to!=v)
            {
                que.push(G[v][i].to);
            }
        }
    }

    int MAX_C = 0;
    rep(i, N)
    {
        if(cnt[i]>MAX_C)
        {
            MAX_C=cnt[i];
        }
    }

    cout << MAX_C << endl;

    rep(i, N-1)
    {
        cout << mp[P(es[i].from,es[i].to)] << endl;
    }


    return 0;
}
 

//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find



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

typedef long long LL;

const int N=200000,mod=998244353;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n;
char s[N+9];

void into(){
  scanf("%d%s",&n,s+1);
}

int pw[N+9];

void Get_pw(){
  pw[0]=1;
  for (int i=1;i<=n;++i) pw[i]=mul(pw[i-1],2);
}

int ans0,ans[N+9];

bool Check_ans(int p){
  for (int i=0,opt=0;i<n;i+=p,opt^=1)
	for (int j=1;j<=p;++j)
	  if (s[j]^opt^s[i+j]) return (s[j]^opt)<s[i+j];
  return 1;
}

void Get_ans(){
  for (int i=1;i<=n;++i){
	if (n%i||n/i&1^1) continue;
	for (int j=1;j<=i;++j)
	  if (s[j]=='1') sadd(ans[i],pw[i-j]);
    if (Check_ans(i)) sadd(ans[i],1);
  }
  for (int i=1;i<=n;++i){
	if (n%i||n/i&1^1) continue;
	for (int j=2;i*j<=n;++j) ssub(ans[i*j],ans[i]);
	sadd(ans0,mul(ans[i],i));
  }
}

void work(){
  Get_pw();
  Get_ans();
}

void outo(){
  printf("%d\n",mul(ans0,2));
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 5584
import sys

H, N = map(int, input().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

dp = [float('inf') for _ in range(H + max(AB)[0] + 1)]
dp[0] = 0
for h in range(H + max(AB)[0] + 1):
    for n in range(N):
        if h - AB[n][0] >= 0:
            dp[h] = min(dp[h - AB[n][0]] + AB[n][1], dp[h])

print(min(dp[H:]))


Measured memory_bytes: 42972
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
LL n;
inline LL qp(LL x,LL y)
{
	LL ans=1,y1=y,base=x;
	while(y1)
	{
		if(y1&1)
			ans=ans*base%mod;
		base=base*base%mod;
		y1>>=1;
	}
	return ans%mod;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	cout<<((qp(10ll,n)-2*qp(9ll,n)+qp(8ll,n))%mod+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 3600
n, k = gets.chomp.split.map(&:to_i)

arr = []
n.times do |i|
  arr[i] = gets.chomp.split.map(&:to_i)
end
arr.sort!
arr.each do |a, b|
  if b >= k
    p a
    exit
  else
    k -= b
  end
end


Measured memory_bytes: 10488
N, M = map(int, input().split())

penalty = 0
a = [[False, 0] for i in range(N)]
count = 0

for i in range(M):
    p, S = input().split()
    p = int(p) - 1
    if a[p][0] == False:
        if S == 'WA':
            a[p][1] += 1
        else:
            a[p][0] = True
            count += 1
    else:
        pass

print(count, sum([a[i][1] for i in range(N) if a[i][0] is True]))

Measured memory_bytes: 14168
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            var S = Console.ReadLine();
            var K = long.Parse(Console.ReadLine());

            long s1 = 0;
            long s2 = 0;

            for (var i = 0; i < S.Length; i++) {
                if (i == S.Length - 1)
                    break;
                if (S[i] == S[i + 1]) {
                    s1++;
                    i++;
                }
            }
            S += S;
            for (var i = 0;i < S.Length; i++) {
                if (i == S.Length - 1)
                    break;
                if (S[i] == S[i + 1]) {
                    s2++;
                    i++;
                }
            }
            if(S.Distinct().Count() == 1) {
                Console.Write(s1 * (K % 2) + s2 * (K / 2));
            }else{
            	Console.Write(s1 + (s2 - s1) * (K - 1));
        	}
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define REP2D(i,j,h,w) for(long long i=0;i<h;i++) for(long long j=0;j<w;j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=h;i++) for(long long j=1;j<=w;j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) (a.begin()),(a.end())
#define RANGE(a) (a),(a+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<a<<endl;
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100005
//---------------------

int n,d[MAXN];

int main(){
  	ZERO(d);
  	cin>>n;
  	REP(i,n) cin>>d[i];
  	sort(d,d+n);
  	int l=d[(n>>1)-1],r=d[(n>>1)];
  	int ret=r-l;
  	PRT(ret);
	return 0;
}

Measured memory_bytes: 768
import sys
sys.setrecursionlimit(1000000000)


def process():
    for data in get_dataset():
        H = len(data)
        W = len(data[0])
        field = create_field(H, W)
        print search(H, W, data, field)


def search(H, W, data, field):
    count = 0
    for i in xrange(H):
        for j in xrange(W):
            if field[i][j] == 0:
                continue
            _search(i, j, H, W, data[i][j], data, field)
            count += 1
    return count


def _search(i, j, H, W, cell, data, field):
    field[i][j] = 0
    for a in xrange(i-1, i+2):
        if -1 < a < H:
            pass
        else:
            continue
        for b in xrange(j-1, j+2):
            if -1 < b < W:
                pass
            else:
                continue

            if a != i and b != j:
                continue

            if field[a][b] == 0:
                continue
            if cell == data[a][b]:
                _search(a, b, H, W, cell, data, field)
    return


def create_field(H, W):
    field = []
    for i in xrange(H):
        raw = []
        for j in xrange(W):
            raw.append(1)
        field.append(raw)
    return field


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(raw_input().rstrip())
        dataset.append(data)
    return dataset

process()

Measured memory_bytes: 15884
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main() {
	int a, b;
	cin >> a >> b;
	int plus = a + b;
	int minus = a - b;
	int multi = a * b;
	int ans = max({ plus, minus, multi });
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 504
from collections import defaultdict

N, K, C = map(int, input().split())
s = list(input())
llst = []
rlst = []

index = 0
lcnt = 0
while index < N:
    if s[index] == 'o':
        llst.append(index)
        index += C + 1
        lcnt += 1
        if lcnt == K:
            break
    else:
        index += 1
index = N - 1
rcnt = 0
while index >= 0:
    if s[index] == 'o':
        rlst.append(index)
        index -= (C + 1)
        rcnt += 1
        if rcnt == K:
            break
    else:
        index -= 1

ans = []
for i in range(len(llst)):
    if i <= len(rlst):
        if llst[i] == rlst[-i - 1]:
            ans.append(llst[i] + 1)
    else:
        break

for i in ans:
    print(i)

Measured memory_bytes: 67144
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

#define ALL(a)  (a).begin(),(a).end()

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
    ll n;
    ll ans = 0;

    vector<int> l;

    cin >> n;

    for (int i = 0; i < n; i++) {
         int temp;
         cin >> temp;
         l.push_back (temp);
    }

    sort(ALL(l), greater<int>());

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] >= l[j] + l[k]) break;
                else ans++;
            }
        }
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 256
n = int(input())
csf=[]
for _ in range(n-1):
    c,s,f=map(int,input().split())
    csf.append((c,s,f))
ans=[0]*n
for i,(c,s,f) in enumerate(csf):
    for j in range(0,i+1):
        if ans[j]<=s:
            ans[j]=s+c
        else:
            ans[j]=(ans[j]+f-1)//f*f+c
for x in ans:
    print(x)

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

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)

typedef pair<int, int> P;

const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

template<class T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T>
bool chmin(T &a, const T &b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m;
	cin >> n >> m;
	int a[m], b[m], c[m];
	REP(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--, b[i]--;
	}
	
	int d[n][n];
	REP(i, n) {
		REP(j, n) {
			if (i == j) d[i][j] = 0;
			else d[i][j] = INF;
		}
	}
	
	REP(i, m) {
		chmin(d[a[i]][b[i]], c[i]);
		chmin(d[b[i]][a[i]], c[i]);
	}
	
	REP(k, n) {
		REP(i, n) {
			REP(j, n) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	
	int ans = m;
	REP(i, m) {
		bool used = false;
		REP(j, n) {
			if (d[j][a[i]] + c[i] == d[j][b[i]]) used = true;
		}
		if (used) ans--;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int W,H,x,y, s;
  scanf("%d %d %d %d", &W,&H, &x, &y);
  if(x + x == W &&  y + y == H){
    s = 1;
  } else {
    s = 0;
  };
  printf("%f %d", (double)W*H/2 ,s);

  return 0;
}

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


bool is_prime(int x){
    if(x <= 1) return false;
    for(int i=2; i*i<=x;i++){
        if(x%i == 0) return false;
    }
    return true;
}

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

    int p=x;
    while(!is_prime(p)) p++;

    cout << p << endl;
    return 0;
}

Measured memory_bytes: 256
L,R = map(int, input().split())
n = 2019
if R-L >= n:
    print(0)
else:
    L %= n
    R %= n
    if L == 0 or R == 0:
        print(0)
    elif L >= R:
        print(0)
    else:
        numbers = []
        for i in range(R-L):
            for j in range(R-L-i):
                numbers.append( ((L+i) * (L+i+j+1)) % n)
        
        print(min(numbers))

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

costs = [0] * N

for i in range(1,N):
  minimum = 99999999999
  for j in range(1, min(K, i)+1):
    minimum = min(minimum, costs[i-j] + abs(h[i] - h[i-j]))
  costs[i] = minimum

print(costs[N-1])

Measured memory_bytes: 84084
# https://atcoder.jp/contests/abc160/submissions/11310424

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    def dist(a, b):
        return min(
            abs(a - b),
            abs(a - X) + abs(b - Y) + 1,
            abs(a - Y) + abs(b - X) + 1
        )

    ctr = [0] * N
    for b in range(N):
        for a in range(b):
            d = dist(a, b)
            ctr[d] += 1

    print(*ctr[1:], sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 46428