akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        const int Mod = 1000000007;
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var odd = n % 2 == 1 ? true : false;

            if (!Check(A, odd))
            {
                Console.WriteLine(0);
                return;
            }

            var ans = 1L;
            foreach (var i in Enumerable.Range(1, n / 2))
            {
                ans *= 2;
                ans %= Mod;
            }

            Console.WriteLine(ans);
        }

        static bool Check(int[] A, bool odd)
        {
            Array.Sort(A);

            if (odd)
            {
                if (A[0] == 0)
                {
                    for (var i = 2; i < A.Length; i+=2)
                        if (A[i] != A[i - 1]) return false;

                    return true;
                }
                else return false;
            }
            else
            {
                for (var i = 1; i < A.Length; i += 2)
                    if (A[i] != A[i - 1]) return false;

                return true;
            }
        }
    }
}


Measured memory_bytes: 18016
S = raw_input()
N = len(S)

ans = 0
for i in xrange(N):
    for keta in xrange(1, N-i+1):
        if keta == N:
            ans += int(S)
        elif i == 0 or i+keta==N:
            ans += int(S[i:i+keta]) * 2**(N-keta-1)
        else:
            ans += int(S[i:i+keta]) * 2**(N-keta-2)
print ans


Measured memory_bytes: 2568
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());scan.nextLine();
		int[] a = new int [n];
		for (int i = 0;i < n;++i){
			a[i] = Integer.parseInt(scan.next());
		}

		int count = 0;
		long ans = 0;
		Arrays.sort(a);
		for (int i =n-1;i>0; --i){
			if (count==2)break;
			if (a[i]==a[i-1]){
				++count;
				if (ans==0)ans=1;
				ans*=a[i];
				--i;
			}
		}
		if (count == 2){
			System.out.print(ans);
		}else{
			System.out.print(0);
		}


	}
}
//end


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

int main() {
  int n, d;
  cin >> n >> d;
  vector<int> data(201);
  for(int i = 0; i < d; i++)
  {
    int num;
    cin >> num;
    data[num] = 1;
  }
  int ans = 0;
  for(int i = 0; i < 201; i++)
  {
    if(data[i] == 0)
    {
      if(abs(ans-n)>abs(i - n))
      {
        ans = i;
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main() {
	long long int x, k, d;

	cin >> x >> k >> d;

	if (x == 0) {
		if (k % 2) {
			cout << d << "\n";
		} else {
			cout << 0 << "\n";
		}
		return 0;
	}

	if (x > 0) {
		long long int l = x / d;
		x = x - (min(k, l)*d);
		k = k - min(k, l);
	} else {
		long long int r = abs(x) / d;
		x = x + (min(k, r)*d);
		k = k - min(k, r);
	}

	long long int ans = 1e18L;

	if (!k) {
		ans = abs(x);
	} else {
		if (k % 2 == 0) {
			ans = abs(x);
		} else if (x > 0) {
			ans = abs(x-d);
		} else {
			ans = abs(x+d);
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
int n,a,b;
signed main(){
    cin>>n>>a>>b;
    if((b-a)%2==0)cout<<(b-a)/2<<endl;
    else{
        int t=a+b-1;
        int d=(n-a)+(n-b+1);
        int x=min(t/2,d/2);
        cout<<x<<endl;
    }
    return 0;
}




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

int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x-=1;
    y-=1;
    int dist[n][n];
    vector<int> cnt(n+1, 0);

    rep(i, n){
        dist[i][i] = 0;
        for(int j=i+1; j<n; j++){
            dist[i][j] = min(abs(i-j), min(abs(x-i)+abs(j-y)+1, abs(y-1)+abs(j-x)+1));
            cnt.at(dist[i][j])+=1;
        }
    }
    for(int i=1; i<n; i++){
        cout << cnt.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 15872
a, b, c, x, y = map(int, input().split())

M = max(x, y)

def f(z):
    x2 = max(0, x - z)
    y2 = max(0, y - z)
    return 2*z*c + a*x2 + b*y2

print(min(f(i) for i in range(0, M+1)))

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 int n,m,q;
  cin >> n >> m >> q;
  VI a(q);
  VI b(q);
  VI c(q);
  VI d(q);
  rep(i,q) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  VI num(10);
  ll pnt=0;
  for(int i=1;i<=m;i++){
    num.at(0)=i;
   for(int j=i;j<=m;j++){
     num.at(1)=j;
    for(int k=j;k<=m;k++){
      num.at(2)=k;
     for(int l=k;l<=m;l++){
       num.at(3)=l;
      for(int o=l;o<=m;o++){
        num.at(4)=o;
       for(int p=o;p<=m;p++){
         num.at(5)=p;
        for(int r=p;r<=m;r++){
          num.at(6)=r;
          for(int s=r;s<=m;s++){
    		num.at(7)=s;
           for(int t=s;t<=m;t++){
             num.at(8)=t;
             for(int u=t;u<=m;u++){
               num.at(9)=u;
               ll sum=0;
                 rep(v,q){
                   if(num.at(b.at(v)-1)-num.at(a.at(v)-1)==c.at(v)){
                     sum+=d.at(v);
                   }
                 }
               pnt=max(pnt,sum);
               }
           }
          }
        }
       }
      }
     }
    }
   }
  }
               
 cout << pnt << endl;                    
 
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int i,n,dig[100000];

int main(){
	while(scanf("%d",&n)*n>=0){
		if(n==0){printf("0\n");continue;}
		for(i=0;n>0;i++){
			dig[i]=n%4;
			n=n/4;
		}
		for(;i>0;i--)printf("%d",dig[i-1]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;


struct UnionFind {
	VI par;
	UnionFind(int N) :par(N) {
		REP(i, N)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

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

	int A, B, C; cin >> A >> B >> C;
	int i = 1;
	while (i < 100000000) {
		if (A*i%B == C) {
			cout << "YES" << endl;
			return 0;
		}
		i++;
	}
	cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 256
import sys


input = sys.stdin.readline
n, q = map(int, input().split())
s = input()
flag = 0 
check_list = []
cnt = 0
for i in range(n):
    if flag == 1:
        if s[i] == 'A':
            flag = 1
        elif s[i] == 'C':
            cnt += 1
            flag = 0
        else:
            flag = 0
    else:
        if s[i] == 'A':
            flag = 1
        else:
            flag = 0
    check_list.append(cnt)
for _ in range(q):
    l, r = map(int, input().split())
    print(check_list[r-1]-check_list[l-1])


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

const int MAX = 110;
const int MAX2 = 1e5+10;
const int INF = 1e9+10;
int n, m;
pair<int, int> p[MAX];
long long memo[MAX][MAX2];

long long pd (int i, int k) {
    //cout<<"i = "<<i<<" k = "<<k<<endl;
    if(k > m) return -INF;
    if(i >= n) return 0;
    if(memo[i][k] != -1) return memo[i][k];
    return memo[i][k] = max(pd(i+1, k), p[i].second + pd(i+1, k+p[i].first));
}

int main() {
    memset(memo, -1, sizeof memo);
    cin>>n>>m;
    for(int i = 0; i < n; ++i) {
        cin>>p[i].first>>p[i].second;
    }
    long long ans = pd(0, 0);
    cout<<ans<<"\n";
}


Measured memory_bytes: 86144
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    string S,T;
    cin >> S >>T;
    ll i,j;
    bool flag;
    for(i=S.size()-1;i>=T.size()-1;i--){
        flag=1;
        for(j=0;j<T.size();j++){
            if(S[i-j]!='?'&&S[i-j]!=T[T.size()-1-j])flag=0;
        }
        if(flag){
            for(j=0;j<T.size();j++){
                S[i-j]=T[T.size()-1-j];
            }
            break;
        }
    }
    if(flag){
        for(i=0;i<S.size();i++){
            if(S[i]=='?')S[i]='a';
        }
        cout << S;
    }else cout <<"UNRESTORABLE" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;

#define SIZE 90
int m, n;
int field[SIZE][SIZE];

int max(int a, int b){
	return (a > b)? a : b;
}

int dfs(int i, int j, int step){
	int res = step;
	
	//up
	if(i > 0 && field[i - 1][j] == 1){
		field[i - 1][j] = 0;
		res = max(res, dfs(i - 1, j, step + 1));
		field[i - 1][j] = 1;
	}
	//down
	if(i + 1 < n && field[i + 1][j] == 1){
		field[i + 1][j] = 0;
		res = max(res, dfs(i + 1, j, step + 1));
		field[i + 1][j] = 1;
	}
	//left
	if(j > 0 && field[i][j - 1] == 1){
		field[i][j - 1] = 0;
		res = max(res, dfs(i, j - 1, step + 1));
		field[i][j - 1] = 1;
	}
	//right
	if(j + 1 < m && field[i][j + 1] == 1){
		field[i][j + 1] = 0;
		res = max(res, dfs(i, j + 1, step + 1));
		field[i][j + 1] = 1;
	}
	
	return res;
}

int main(){
	int res;
	
	while(true){
		scanf("%d", &m);
		scanf("%d", &n);
		if(m == 0 && n == 0) break;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				scanf("%d\n", &field[i][j]);
			}
		}
		
		res = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				if(field[i][j] == 0) continue;
				
				field[i][j] = 0;
				res = max(res, dfs(i, j, 1));
				field[i][j] = 1;
			}
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 1064
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N = 0;
    cin >> N ;

    vll P(N),Q(N);
    REP(i,N) cin >> P[i];
    REP(i,N) cin >> Q[i];
  
    //本文
  vector<int> v(N);
  //1刻みで格納できる関数、便利
  iota(v.begin(), v.end(), 1);
  ll cnt = 0,a=0,b=0;
  do{
    cnt ++;
    bool equal1 = v.size() == P.size() && std::equal(v.cbegin(), v.cend(), P.cbegin());
    bool equal2 = v.size() == Q.size() && std::equal(v.cbegin(), v.cend(), Q.cbegin());
    if(equal1) a = cnt;
    if(equal2) b = cnt;

  }while(next_permutation(v.begin(),v.end()));
    //出力
    cout << abs(a-b) << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;

#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

/*
任意の場所にどのマスの子供が集まるか
*/

int main()
{
  string S;cin>>S;
  ll n = S.size();
  
  vector<ll> a(n+1);
  ll i = 0;
  ll count=0;
  ll num = 0;//何個に別れるか
  while (i<n)
  {
    count=0;
    while (S[i]==S[i+1])
    {
      i++; 
      count++;
    }
    a[num]=count+1;
    i++;
    num++;
  }
  //for (int i=0;i<num;i++)
   // cout<<a[i]<<" ";
  
  vector<ll> ans(n+1,0);//答えを格納する配列
  
  ll now=0;
  for (int i=0;i<num;i+=2)
  { 
    if (a[i]%2!=a[i+1]%2)
    { 
      if (max(a[i],a[i+1])%2==0)
      {
        ans[now+a[i]+1]=(a[i]+a[i+1])/2+1;
        ans[now+a[i]]=(a[i]+a[i+1])/2;
        if (a[i]<a[i+1]) swap(ans[now+a[i]+1],ans[now+a[i]]);
      }
      else{
       ans[now+a[i]+1]=(a[i]+a[i+1])/2;
       ans[now+a[i]]=(a[i]+a[i+1])/2+1;
       if (a[i]<a[i+1]) swap(ans[now+a[i]+1],ans[now+a[i]]);
      }
    }
    else
    {
      ans[now+a[i]]=(a[i]+a[i+1])/2;
      ans[now+a[i]+1]=(a[i]+a[i+1])/2;
    }
    now += a[i]+a[i+1];
  }
  
  for (int i=1;i<=n;i++)
    cout<<ans[i]<<" ";
}

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

const int MAXN = 3e2 + 5;

int N, M;
int a[MAXN][MAXN];

void load() {
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= M; j++)
			scanf("%d", a[i] + j);
}

int solve() {
	int sol = N;
	vector <bool> active(M + 1, true);
	for (int k = 0; k < M; k++) {
		vector <int> occ(M + 1, 0);
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= M; j++)
				if (active[a[i][j]]) {
					occ[a[i][j]]++;
					break;
				}
		int maks = max_element(occ.begin(), occ.end()) - occ.begin();
		sol = min(sol, occ[maks]);
		active[maks] = false;
	}
	
	return sol;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

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

int main(){
	int n;	

	while(true){
		cin >> n;

		if(n==0)break;

		unsigned int c1[100000];
		unsigned int m1[100000];
		unsigned int s1[100000];
		unsigned int m2[100000];
		unsigned int s2[100000];
		unsigned int m3[100000];
		unsigned int s3[100000];
		unsigned int m4[100000];
		unsigned int s4[100000];

		for(int i=0;i<n;i++){
			cin >> c1[i] >> m1[i] >> s1[i] >> m2[i] >> s2[i] >> m3[i] >> s3[i] >> m4[i] >> s4[i];
			}

		unsigned int sum[100000];

		for(int i=0;i<n;i++){
			sum[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+(s1[i]+s2[i]+s3[i]+s4[i]);
			}

		unsigned int copy[100000];

		for(int i=0;i<n;i++){
			copy[i] = sum[i];
			}

		sort(sum,sum+n);

		for(int i=0;i<2;i++){
			int j=0;
			while(true){
				if(sum[i]==copy[j]){
					cout << c1[j] << endl;
					break;
					}
				else{
					j++;
					}
				}
			}

		int cnt=0;
		while(true){
			if(sum[n-2]==copy[cnt]){
					cout << c1[cnt] << endl;
					break;
					}
			else{
				cnt++;
				}
			}

		}

	return 0;
	}

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

int main(void)
{
  int q;
  double x;

  while (scanf("%d", &q), q != -1){
    x = q / 2.0;
    for (; fabs(x * x * x - q) >= 1e-5 * q; x = x - (x * x * x - q) / (3.0 * x * x)){}
    printf("%f\n", x);
  }

  return (0);
}

Measured memory_bytes: 632
n = int(input())
p = [[0, 0] for _ in range(n)]
for i in range(n):
  p[i] = list(map(int, input().split()))
p.sort()

st = dict()
for i in range(n-1):
  for j in range(i+1, n):
    st[(p[j][0]-p[i][0], p[j][1]-p[i][1])] = st.get((p[j][0]-p[i][0], p[j][1]-p[i][1]), 0) + 1
  
mx = 0
for key in st:
  mx = max(mx, st[key])
  
print(n-mx)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define st first
#define nd second
using namespace std;

constexpr int nax = 1e5;

int n, m, pre[nax + 1], val[nax + 1];
bool vis[nax + 1];
vector< int > gr[nax + 1];
vector< pair< int, int > > ans;

void panic()
{
    cout << -1 << '\n';
    //for (auto p : ans)
        //cerr << p.st << ' ' << p.nd << '\n';
    exit(0);
}


void dfs(const int v)
{
    static int t = 1;

    pre[v] = t++;

    for (int s : gr[v])
    {
        if (not pre[s])
            dfs(s);
        else if (pre[s] >= pre[v])
            val[s] = 1 - val[s], ans.push_back({s, v});
    }
}

void dfs2(const int v)
{
    vis[v] = true;
    for (int s : gr[v])
        if (pre[s] > pre[v] and not vis[s])
        {
            dfs2(s);
            if (val[s]) ans.push_back({s, v}), val[s] = 1 - val[s];
            else ans.push_back({v, s}), val[v] = 1 - val[v];
        }
}

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

    cin >> n >> m;

    for (int i = 0; i < m; ++i)
    {
        int p, q; cin >> p >> q;
        gr[p].push_back(q);
        gr[q].push_back(p);
    }

    for (int i = 1; i <= n; ++i)
        if (not pre[i]) dfs(i);

    for (int i = 1; i <= n; ++i)
        if (not vis[i])
        {
            dfs2(i);
            if (val[i]) panic();
        }

    for (int i = 0; i < ans.size(); ++i)
        cout << ans[i].st << ' ' << ans[i].nd << '\n';
}

Measured memory_bytes: 16500
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var s = Console.ReadLine();
		var h = s.Length / 2;
		Console.WriteLine(string.Join("", s.Reverse()) == s && s.Substring(0, h) == s.Substring(h + 1) ? "Yes" : "No");
	}
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll nCrmod(ll n,ll r){ll x=1,y=1; rep(i,r){x=x*(n-i)%mod; y=y*(i+1)%mod;} return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	string s;
	cin >> s;
	reverse(all(s));
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 2976
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


/*
int N;
Graph G;

int main() {
  cin >>N;
  rep(i, N-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
}
*/

int main() {
  string s; cin >>s;
  bool c = false;
  bool f = false;
  rep(i, s.size()){
    if (s[i] == 'C') c = true;
    if (c && s[i] == 'F') f = true;
  }
  cout <<(f ? "Yes" : "No") <<endl;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)

print(x3, y3, x4, y4)


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

int main() {
    int N;
    cin >> N;
    vector<vector<ll>> A(N, vector<ll>(N));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> A[i][j];
        }
    }
    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (A[i][k] + A[k][j] < A[i][j]) {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    ll ans = 0;
    bool found = false;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            found = false;
            for (int k = 0; k < N; ++k) {
                if (k == i || k == j) continue;
                if (A[i][k] + A[k][j] == A[i][j]) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                ans += A[i][j];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const double eps = 1e-10;
class Info{
public:
  int s,e,c,time;
  double consume;
  Info(){};
  Info(int ts,int te,int tc):s(ts),e(te),c(tc){
    consume=e-s;
    consume*=(double)c;
    time=e-s;
  };
};

//double can_water(vector<Info >&in,double L,double p,double ini){
double can_water(vector<Info >in,double L,double p,double ini){
  double vol=ini;
  int lasttime=0;//last time that scheduled
  rep(i,in.size()){
    vol=min(L,vol+(double)(in[i].s-lasttime)*p);
    vol=vol+in[i].time*p-in[i].consume;
    if ( vol<=eps)return -1;
    vol=min(vol,L);
    lasttime=in[i].e;
  }

  vol=vol+(86400-lasttime)*p;
  vol=min(vol,L);
  return vol;
}

double solve(vector<Info > &in,double L){
  double mini=0,maxi=100000000,ret=0,mid;
  while(mini+eps<maxi){
    double mid = (mini+maxi)/2;
    double day1=can_water(in,L,mid,L);
    if ( day1<=0){mini=mid+eps;continue;}
    
    double day2 = can_water(in,L,mid,day1);
    //printf("%.6lf %.6lf %.6lf\n",mid,day1,day2);
    if (day2>0 && day2-day1>=0)maxi=mid-eps,ret=mid;
    else mini=mid+eps;
  }

  return ret;
}

main(){
  int n,L;
  while(cin>>n>>L&&n){
    vector<Info> in;
    int s,t,c;
    rep(i,n){
      cin>>s>>t>>c;
      in.push_back(Info(s,t,c));
    }
    printf("%.8lf\n",solve(in,L));
  }
}

Measured memory_bytes: 5132
package main

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

type id int

type node struct {
	id id
	parent *node
	left *node
	right *node
}

func (node node) showParent() int {
	if node.parent != nil {
		return int(node.parent.id)
	} else {
		return -1
	}
}

func (node node) showSibling() int {
	if node.parent == nil {
		return -1
	}
	parent := node.parent
	if parent.left == nil || parent.right == nil {
		return -1
	}
	if parent.left.id == node.id {
		return int(parent.right.id)
	} else {
		return int(parent.left.id)
	}
}

func (node node) showDegree() int {
	var degree int
	if node.left != nil {
		degree++
	}
	if node.right != nil {
		degree++
	}
	return degree
}

func (nd node) showDepth() int {
	var depth int
	above := nd.parent
	for above != nil {
		depth++
		above = above.parent
	}
	return depth
}

func (nd node) showHeight() int {
	if nd.left == nil && nd.right == nil {
		return 0
	}

	var leftH, rightH int
	if nd.left != nil {
		leftH = nd.left.showHeight() + 1
	}
	if nd.right != nil {
		rightH = nd.right.showHeight() + 1
	}

	if leftH < rightH {
		return rightH
	} else {
		return leftH
	}
}

func (node node) showTyp() string {
	if node.parent == nil {
		return "root"
	}
	if node.left == nil && node.right == nil {
		return "leaf"
	}
	return "internal node"
}

type nodeData struct {
	id int
	left int
	right int
}

func newNodes(n int) []node {
	return make([]node, n)
}

func processNodeData(nd nodeData, nodes []node) {
	nodes[nd.id].id = id(nd.id)
	if nd.left != -1 {
		nodes[nd.left].parent = &nodes[nd.id]
		nodes[nd.id].left = &nodes[nd.left]
	}
	if nd.right != -1 {
		nodes[nd.right].parent = &nodes[nd.id]
		nodes[nd.id].right = &nodes[nd.right]
	}
}

func (node node) stringify() string {
	parent := node.showParent()
	sibling := node.showSibling()
	degree := node.showDegree()
	depth := node.showDepth()
	height :=node.showHeight()
	typ := node.showTyp()
	return fmt.Sprintf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s",
		node.id, parent, sibling, degree, depth, height, typ)
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	nodes := newNodes(n)
	for i := 0; i < n; i++ {
		nodeId, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		leftId, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		rightId, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		nodeData := nodeData{id: nodeId, left: leftId, right: rightId}
		processNodeData(nodeData, nodes)
	}
	for i := 0; i < n; i++ {
		fmt.Println(nodes[i].stringify())
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}


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

using namespace std;

int n;
long long int k;
const int MOD = 1e9 + 7;

int mul(int a, int b){
    return (long long int)(a % MOD) * (b % MOD) % MOD;
}

struct M{
    vector<vector<int>> vals;
    
    M (int size = n){
        vals = vector<vector<int>>(n, vector<int>(n));
    }

    M operator * (const M &b){
        M ans;
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                int &answer = ans.vals[i][j];
                answer = 0;
                
                for(int k = 0; k < n; ++k){
                    answer += mul(vals[i][k], b.vals[k][j]); 
                    if(answer >= MOD){
                        answer -= MOD;       
                    }
                }
            }
        }
        return ans;
    }
    
    void print(){
        cout << "MATRIX\n";
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                cout << vals[i][j] << "\t";
            }
            cout << "\n";
        }
    }
    
    int sum(){
        long long int total = 0;
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                total += vals[i][j];
                if(total >= MOD)
                    total -= MOD;
            }
        }
        return total;
    }
    
    M power(long long int k){
        M ans;
        for(int i = 0; i < n; ++i){
            ans.vals[i][i] = 1;
        }
        
        M temp;
        temp.vals = vals;
        
        while(k){
            if(k % 2){
                ans = ans * temp;
            }
            temp = temp * temp;
            k /= 2;
        }
        return ans;
    }
};

int main(){
    cin >> n >> k;
    
    M transition;
    for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
            cin >> transition.vals[i][j];
        }
    }
    
    auto ans = transition.power(k);
    // ans.print();
    cout << ans.sum() << "\n";
}

Measured memory_bytes: 3592
n = int(input())
T,A = map(int,input().split())
h = list(map(int,input().split()))
#print(h)
l =[]
for i in range(n):
  a = T - h[i]*0.006
 # print(a)
  b = abs(a-A)
  l.append(b)
  #print(l)
c = l.index(min(l))
print(c+1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
    ll n,i,s=0,q;map<ll,ll>mp;
    cin>>n;
    ll ara[n+1];
    for(i=1;i<=n;i++)cin>>ara[i];
    for(i=1;i<=n;i++)
    {
        s+=ara[i];
        mp[ara[i]]++;
    }
    cin>>q;
    for(i=1;i<=q;i++)
    {
        ll x,y;
        scanf("%lld %lld",&x,&y);
        s=s+(y-x)*mp[x];
        mp[y]+=mp[x];mp[x]=0;
        printf("%lld\n",s);
    }
}


Measured memory_bytes: 10380
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int S, W;
  std::cin >> S >> W;
  std::cout << std::string(W >= S ? "un" : "") + "safe" << '\n'; 
  return 0;
}


Measured memory_bytes: 3636
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    S = [list(map(int,input().split())) for i in range(N)]
    ret = 0
    for i in range(N-1,-1,-1):
        A, B = S[i]
        x = (A+ret)%B
        if x!=0:
            ret += B - (A+ret)%B
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 27380
# 最高で進んでもtを超えることはできない
# 1ターンにつき1進むので偶奇をみる

n = int(input())
pre = [0, 0, 0]  # time, x, y
for i in range(n):
    t, x, y = map(int, input().split())
    t -= pre[0]
    x -= pre[1]
    y -= pre[2]
    if t < abs(x) + abs(y) or (abs(x) + abs(y)) % 2 != t % 2:
        print("No")
        exit()
    pre = [t, x, y]
print("Yes")

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;
const int mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

void add(ll& a, ll b) { (a += b) %= mod; }

int main() {
    int N, S; cin >> N >> S;
    vl A(N);
    rep(i,N) cin >> A[i];
    vvl dp(3030, vl(3, 0));
    dp[0][0] = 1;
    rep(i,N) {
        vvl ndp(3030, vl(3, 0));
        rep(j,S+1) {
            add(ndp[j][0], dp[j][0]);
            add(ndp[j][1], dp[j][0]+dp[j][1]);
            add(ndp[j][2], dp[j][0]+dp[j][1]+dp[j][2]);
            if(j+A[i] > S) continue;
            add(ndp[j+A[i]][1], dp[j][0]+dp[j][1]);
            add(ndp[j+A[i]][2], dp[j][0]+dp[j][1]);
        }
        dp = ndp;
    }
    cout << dp[S][2] << endl;
    return 0;
}


Measured memory_bytes: 656
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    long long num;
    cin >> num;
    for(int i=-300;i<=300;i++){
        for(int j=i;j>=-300;j--){
            if(i*i*i*i*i-j*j*j*j*j==num){
                cout << i << " "<< j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3196
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
struct Extended_Euclid {
	static pair<long long int,long long int> solve(long long int l, long long int r) {
		const long long int agcd = gcd(l, r);
		l /= agcd;
		r /= agcd;
		bool flag = false;
		if (l < r) {
			flag = true;
			swap(l, r);
		}
		int x1 = 1, y1 = 0, z1 = l;
		int x2 = 0, y2 = 1, z2 = r;
		while (z2 != 1) {
			int q = (z1 - (z1%z2)) / z2;
			int px = x1;
			int py = y1;
			int pz = z1;
			x1 = x2;
			y1 = y2;
			z1 = z2;
			x2 =px-q*x2;
			y2 = py-q*y2;
			z2 = pz-q*z2;
		}
		if (flag)swap(x2, y2);
		return make_pair(x2, y2);
	}
}exeu;

int main() {
	int a, b; cin >> a >> b;
	auto ans(exeu.solve(a,b));
	int sum1 = ans.first + ans.second;
	if (ans.first < 0) {
		auto ans2 = make_pair(ans.first + b, ans.second - a);
		int sum2 = abs(ans2.first) + abs(ans2.second);
		if (sum1 > sum2)ans = ans2;
		else if (sum1 == sum2&&ans2.first <= ans2.second)ans = ans2;
	}
	else {
		auto ans2 = make_pair(ans.first - b, ans.second + a);
		int sum2 = abs(ans2.first) + abs(ans2.second);
		if (sum1 > sum2)ans = ans2;
		else if (sum1 == sum2&&ans2.first <= ans2.second)ans = ans2;
	}
	cout << ans.first << " " << ans.second << endl;
	return 0;
}

Measured memory_bytes: 3092
/* Search I */
#include<stdio.h>
int main(){
  int n,q; /* n: S, q: T */
  int S[10001],T[501]; /* n<=10000, q<=500 */
  int i,j,counter=0;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%d", &T[i]);
  }
  
  /* Linear Search */
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(T[i]==S[j]){
	counter++;
	break;
      }
    }
  }
  
  printf("%d\n",counter);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 1;

int main() {
  int y, m, d, h = 0;
  char tmp;
  cin >> y >> tmp >> m >> tmp >> d;
  if (m <= 4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100000

int parent(int i) {return i / 2;}
int left(int i) {return 2 * i;}
int right(int i) {return 2 * i + 1;}

int main(){
	int H, i, A[MAX + 1];
	
	scanf("%d", &H);
	for(i = 1; i <= H; i++){
		scanf("%d", &A[i]);
	}
	
	for(i = 1; i <= H; i++){
		printf("node %d: key = %d, ", i, A[i]);
		if(parent(i) >= 1) {printf("parent key = %d, ", A[parent(i)]);}
		if(left(i) <= H) {printf("left key = %d, ",A[left(i)]);}
		if(right(i) <= H) {printf("right key = %d, ",A[right(i)]);}
		printf("\n");
	}
	
	return 0;
}



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

int main() {
  int n; cin >> n;
  if(n <= 1000){
    cout << 1000-n << endl;
    return 0;
  }
  if(n <= 2000){
    cout << 2000-n << endl;
    return 0;
  }
  if(n <= 3000){
    cout << 3000-n << endl;
    return 0;
  }
  if(n <= 4000){
    cout << 4000 - n << endl;
    return 0;
  }
  if(n <= 5000){
    cout << 5000-n << endl;
    return 0;
  }
  if(n <= 6000){
    cout << 6000-n << endl;
    return 0;
  }
  if(n <= 7000){
    cout << 7000-n << endl;
    return 0;
  }
  if(n <= 8000){
    cout << 8000-n << endl;
    return 0;
  }
  if(n <= 9000){
    cout << 9000-n << endl;
    return 0;
  }
  else {
    cout << 10000-n << endl;
    return 0;
  }
  
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
	int h;
	while(cin >> h,h){
		int i,m[10001]={};
		long long ka=0,t=0;
		for(i=0;i<h;i++){
			cin >> m[i];
		}
		sort(m,m+h);
		for(i=0;i<h;i++){
			ka += t;
			t += m[i];
		}
		cout << ka << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    int N = sc.nextInt();
    int K = sc.nextInt();

    int[] h = new int[N];
    for (int i=0; i<N; i++) {
      h[i] = sc.nextInt();
    }

    Arrays.sort(h);

    int dif = Integer.MAX_VALUE;
    for (int i=K-1; i<N; i++) {
      dif = Math.min(dif, h[i] - h[i-K+1]);
    }

    System.out.println(dif);

  }
}

Measured memory_bytes: 49472
import java.util.*;
class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        for(int i = 1; ; i++) {
            int x = sc.nextInt();
            if(x == 0) break;
            System.out.println("Case " + i + ": " + x);
        }
    }
}

Measured memory_bytes: 32980
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=3e5+5;

ll dp[N][21];

int main()
{ 

IOS;


ll n,k;cin>>n>>k;

ll sum=0;

vl a(n+1);

FOR(i,n){
  cin>>a[i+1];
  sum+=a[i+1];
}

vl d;

for(int i=1;i*i<=sum;i++){
  if(sum%i==0){
    d.pb(i);
    d.pb(sum/i);
  }
}

sort(all(d),greater<>());


for(int i=0;i<d.size();i++){
  ll x=d[i];
  bool allowed=0;
  vl temp(n+1);
  for(int j=1;j<=n;j++){
     temp[j]=a[j]%x;
  }
  sort(all(temp));

/*if(x==7){
  for(auto p:temp)cout<<p<<" ";
cout<<endl;
}
*/
  for(int j=1;j<=n;j++){
    temp[j]+=temp[j-1];
    }

    for(int j=0;j<=n;j++){
      ll left=temp[j];
      if(left>k)break;
      ll right=x*(n-j) -(temp[n]-temp[j]);
      if(left==right){
        allowed=1;
        break;
      }
    }

if(allowed){
  cout<<x<<endl;
  return 0;
}
}


cout<<1<<endl;







return 0;
 
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
const int maxn = 1e3 + 5;
using namespace std;

int w,h,n;
int a,x,y;
int wl,wr,hx,hs;

int main(){
	scanf("%d %d %d", &w, &h, &n);
	wr = w;
	hs = h;
	for(int i = 1; i <= n; i++){
		scanf("%d %d %d", &x, &y, &a);
		if(a == 1)	wl = max(x,wl);
		if(a == 2)	wr = min(wr,x);
		if(a == 3) hx = max(y,hx);
		if(a == 4) hs = min(y, hs);
	}
	printf("%d\n", max((wr - wl),0) * max((hs - hx),0));
	return 0;
}

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

int main(){
  int n, h, w;
  cin >> n >> h >> w;
  cout << (n-h+1)*(n-w+1) << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io::Read;


struct State {
    n: usize,
    m: i64,
    q: usize,
    a: Vec<usize>,
    b: Vec<usize>,
    c: Vec<i64>,
    d: Vec<i64>,
}

impl State {
    fn dfs(&self, cur: &mut Vec<i64>, i: usize) -> i64 {
        if i == self.n {
            let mut ans = 0;
            for j in 0..self.q {
                if cur[self.b[j]] - cur[self.a[j]] == self.c[j] {
                    ans += self.d[j];
                }
            }
            return ans;
        }
        let minimum = if i == 0 { 1 } else { cur[i - 1] };
        let maximum = self.m;
        let mut ans = 0;
        for v in minimum..=maximum {
            cur[i] = v;
            ans = std::cmp::max(ans, self.dfs(cur, i + 1));
        }
        ans
    }

    fn solve(&self) -> i64{
        let mut cur = vec![0; self.n];
        self.dfs(&mut cur, 0)
    }
}

fn main() {
    let mut line = String::new();
    std::io::stdin().read_to_string(&mut line);
    let mut iter = line.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: i64 = iter.next().unwrap().parse().unwrap();
    let q: usize = iter.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = vec![];
    let mut b: Vec<usize> = vec![];
    let mut c: Vec<i64> = vec![];
    let mut d: Vec<i64> = vec![];
    for _ in 0..q {
        a.push(iter.next().unwrap().parse::<usize>().unwrap() - 1);
        b.push(iter.next().unwrap().parse::<usize>().unwrap() - 1);
        c.push(iter.next().unwrap().parse().unwrap());
        d.push(iter.next().unwrap().parse().unwrap());
    }
    let mut solver = State {
        n,
        m,
        q,
        a,
        b,
        c,
        d,
    };
    println!("{}", solver.solve());
}


Measured memory_bytes: 2100
// AOJ 0120: Patisserie
// 2017.8.21 bal4u@uu
// 201711.20

#include <stdio.h>
#include <string.h>
#include <math.h>

#define R 100000
int r[13];
int d[13][13];					// ???????????±???????????????????°´????????¢
int dp[13][4100];				// ?°´????????¢, ??´?????????????????±??????????±\??´?????????
char buf[50], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int w, n, i, ii, j, k;
	int lim, x;

	for (i = 3; i <= 10; i++) for (ii = i*i, j = i; j <= 10; j++, ii+=i)
		d[i][j] = d[j][i] = (int)(2*R * sqrt(ii));

	while (fgets(p=buf, 50, stdin) != NULL) {
		w = getint(); p++;
		n = 0, j = 0;
		while (*p >= ' ') {	i = getint(), p++, r[n++] = i, j += i; }
		if (2 * j <= w) { puts("OK"); continue; }
		w *= R;

		memset(dp, 0x55, sizeof(dp));
		for (ii = 1, i = 0; i < n; i++, ii <<= 1) dp[i][ii] = r[i]*R;

		lim = (1 << n) - 1;
		for (k = 0; k <= lim; k++) {
			for (ii = 1, i = 0; i < n; i++, ii <<= 1) {
				if (k & ii) continue;
				for (j = 0; j < n; j++) {
					x = dp[j][k] + d[r[i]][r[j]];
					if (x < dp[i][k|ii]) dp[i][k|ii] = x;
				}
			}
		}

		for (x = 240*R, i = 0; i < n; i++) {
			dp[i][lim] += r[i]*R;
			if (dp[i][lim] < x) x = dp[i][lim];
		}
		puts(x <= w ? "OK" : "NA");
	}
	return 0;
}

Measured memory_bytes: 1780
from bisect import bisect_left, bisect_right
N = int(input())
x = list(map(int, input().split()))
L = int(input())
n = N.bit_length()+1
next_hotel = [[0]*n for _ in range(N)]
for i in range(N):
    index = bisect_right(x, x[i]+L)-1
    if index == i:
        next_hotel[i][0] = N
    else:
        next_hotel[i][0] = index
for i in range(1, n):
    for j in range(N):
        if next_hotel[j][i-1]<N:
            index = next_hotel[next_hotel[j][i-1]][i-1]
            if index == j:
                next_hotel[j][i] = N
            else:
                next_hotel[j][i] = index
        else:
            next_hotel[j][i] = N
def count(a, b):
    if a>b:
        a, b = b, a
    res = 0
    for i in range(n):
        if a >= b:
            return  res
        c = max(0, bisect_left(next_hotel[a], b)-1)
        a = next_hotel[a][c]
        res+=2**c
Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    print(count(a-1, b-1))

Measured memory_bytes: 100120
S = gets.to_s

ng = 0
if S[0] != 'A'
	ng += 1
end

count = 0
for i in 1..S.length - 3 do 
	ng += 1 if i == 1 &&  S[i] == S[i].upcase
	count += 1 if i >=2 && S[i] == 'C'

	if S[i] != 'A' && S[i] != 'C' 
		if S[i] == S[i].upcase
			ng += 5
		end
	end
end

if count != 1
	ng += 1
end

len = S.length - 2

if S[len] == S[len].upcase
	ng += 3
end

if 	ng > 0
	print('WA')
else
	print('AC')
end


Measured memory_bytes: 1788
/*
CODED BY               
**************
DARSHAN JAIN
darshanjain31
**************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define M 1000000007

int main() 
{
	
		ll n,m;
		cin>>n>>m;
		ll a[n];
		ll sum=0;
		for (int i = 0; i < n; ++i)
		{
			cin>>a[i];
			sum+=a[i];
		}
		sort(a,a+n);
		
		ll count=0;
		for (int i = 0; i < n; ++i)
		{
			if(a[i]*4*m>=sum)
				count++;
		}
		if(count>=m)
			cout<<"Yes"<<endl;
		else 
			cout<<"No"<<endl;
	
}

Measured memory_bytes: 256