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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto &i: a) cin >> i;
    vector<int> asc(n);
    asc = a;
    sort(asc.begin(), asc.end());
    int med1, med2;
    med1 = asc[n/2-1];
    med2 = asc[n/2];
    for (auto i: a) {
        if (i < med2) cout << med2 << endl;
        else cout << med1 << endl;
    }
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int n,m,i,j,k;
int a[100005];

void fail()
{
	printf("No\n");
	exit(0);
}

int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	if(!(a[1]==a[n]||a[1]+1==a[n]))fail();
	if(a[1]==a[n])
	{
		if(a[1]*2>n&&a[1]!=n-1)fail();
	}
	else
	{
		for(i=1;i<=n;++i)if(a[i]==a[1])++k;
		if(k>=a[n])fail();
		if(k+(a[n]-k)*2>n)fail();
	}
	printf("Yes\n");
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i ++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  if (n % 2 == 0) {
    for (int i = 1; i < n; i += 2) {
      if (a.at(i) != i || a.at(i - 1) != i) {
        cout << 0 << endl;
        return 0;
      }
    }
  } else if (n % 2 == 1 && a.at(0) == 0) {
    for (int i = 2; i < n; i += 2) {
      if (a.at(i) != i || a.at(i - 1) != i) {
        cout << 0 << endl;
        return 0;
      }
    }
  } else {
    cout << 0 << endl;
    return 0;
  }

  int ans = 1;
  for (int i = 1; i <= n / 2; i ++) {
    ans *= 2;
    ans %= 1000000007;
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        if(a<b && b<c) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 25908
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n,i = inp
p n-i+1

Measured memory_bytes: 1788
#include <stdio.h>

int main(void) {

	int a = 0, b = 0, n = 0, i = 0;
	int sum = 0, result = 0;
	int tmp = 0;

	scanf("%d %d %d", &n, &a, &b);

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

		tmp = i;
		sum = 0;

		while (tmp != 0) {
			sum = sum + (tmp % 10);
			tmp = tmp / 10;
		}

		if ((sum >= a) && (sum <= b)) {
			result = result + i;
		}

	}

	printf("%d\n", result);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long int dp[51][51][2501];

int main() {
	long long int N,A;
	cin >> N >> A;
	int x[N];
	for(int i = 0;i < N;i++) {
		cin >> x[i];
	}
	long long ans = 0;
	dp[0][0][0] = 1;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < N;j++) {
			for (int k = 0;k < 2501;k++) {
				if (k<x[i]) {dp[i+1][j][k] = dp[i][j][k];}
				else {
					dp[i+1][j+1][k] = dp[i][j+1][k] + dp[i][j][k-x[i]];
				}
			}
		}
	}
	for (int i = 1;i < N+1;i++) {
		ans+=dp[N][i][i*A];
	}
	cout << ans << endl;
}

Measured memory_bytes: 50048
n=int(input())
a=list(map(int,input().split()))

money=1000
kabu=0

for i in range(n-1):
    if a[i]>a[i+1]:
        money+=kabu*a[i]
        kabu=0
    elif a[i]<a[i+1]:
        money+=kabu*a[i]
        kabu=money//a[i]
        money=money%a[i]
    #print(money,kabu)

money+=kabu*a[n-1]

print(money)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }



int main() {
	int n, q;
	scanf("%d%d", &n, &q);
	n -= 2;
	int H = n, W = n;
	vector<int> height(n, n);
	vector<int> width(n, n);
	long long answer = 0;
	while(q--) {
		int type, x;
		scanf("%d%d", &type, &x);
		x -= 2;
		assert(0 <= x && x <= n - 1);
		if(type == 1) {
			if(x < W) {
				answer += min(H, height[x]);
				height[x] = -1; // will not use this again
				// debug() << imie(x) imie(height[x]);
				for(int i = x + 1; i < W; ++i) {
					height[i] = H;
				}
				W = x;
			}
			else {
				answer += height[x];
				height[x] = -1;
			}
		}
		else {
			swap(H, W);
			height.swap(width);
			// swap(height, width);
			if(x < W) {
				answer += min(H, height[x]);
				height[x] = -1; // will not use this again
				for(int i = x + 1; i < W; ++i) {
					height[i] = H;
				}
				W = x;
			}
			else {
				answer += height[x];
				height[x] = -1;
			}
			swap(H, W);
			height.swap(width);
			// swap(height, width);
		}
		debug() << imie(answer) imie(H) imie(W) imie(height) imie(width);
	}
	printf("%lld\n", (long long) n * n - answer);
}


Measured memory_bytes: 4768
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
 string a;
  cin>>a;
  bool b=0,c=0;
  rep(i,a.size()){
  if(a[i]=='C')
    b=1;
  if(b&&a[i]=='F')
    c=1;
  }
  YesNo(c);
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;

#define INF 1e10
#define EPS (1e-10)    //誤差
#define PI 3.1415926535897932384626433832795028841971

signed main(){
    
    while(1){
        double n, rr; cin >> rr >> n;
        if(n == 0 && rr == 0) break;
        vector<double> l(n);
        vector<double> r(n);
        vector<double> h(n);
        for(int i = 0; i < n; i++) cin >> l[i] >> r[i] >> h[i];

        vector<double> a(200, 0);
        for(int i = 0; i < n; i++){
            for(int j = l[i]; j < r[i]; j++){
                int x = j + 100;
                a[x] = max(a[x], h[i]);
            }
        }

        double lb = 0;
        double ub = 100100.0;

        for(int itr = 0; itr <= 1000; itr++){
            double t = (lb + ub) / 2.0;
            double y = t - rr;
            bool flag = true;
            for(int i = 0; i < 200; i++){
                
                double yy = a[i];
                double xx1 = i - 100;
                double xx2 = i - 100 + 1;
                if(abs(xx1) < rr){
                    if(sqrt(rr * rr - xx1 * xx1) + y > yy) flag = false;
                }

                if(abs(xx2) < rr){
                    if(sqrt(rr * rr - xx2 * xx2) + y > yy) flag = false;
                }

                if(!flag) break;

            }

            if(flag) lb = t;
            else ub = t;
        }

        printf("%.10f\n", lb);
    }
    return 0;
}



Measured memory_bytes: 3200
#include <iostream>

using namespace std;
long int gcd(long int a, long int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

int main(int argc, const char *argv[]) {
  long int A, B;
  cin >> A >> B;

  cout << lcm(A, B) << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)

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

    int N, M;
    cin >> N >> M;

    map<int, int> num;
    REP(i, M)
    {
        int s, c;
        cin >> s >> c;

        if(num.count(s))
        {
        // キーが有る
            // 桁が矛盾
            if(num.at(s) != c)
            {
                cout << -1 << endl;
                return 0;
            }
        }
        else
        {
        // キーがない
            num.emplace(s, c);
        }
        
    }

    // 縛りなし
    if(M == 0)
    {
        switch(N)
        {
            case 1:
                cout << 0 << endl;
                return 0;

            case 2:
                cout << 10 << endl;
                return 0;

            case 3:
                cout << 100 << endl;
                return 0;
        }
        return 0;
    }

    // 1桁じゃないのに最上位桁の値が0
    if(N > 1 && num.count(1) && num.at(1) == 0)
    {
        cout << -1 << endl;
        return 0;
    }

    string S(N, '0');

    if(N>0)
    {
        S.at(0) = num.count(1) ? num.at(1) + '0' : '1';
    }

    if(N>1)
    {
        S.at(1) = num.count(2) ? num.at(2) + '0' : '0';
    }

    if(N>2)
    {
        S.at(2) = num.count(3) ? num.at(3) + '0' : '0';
    }
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left as bl,bisect_right as br
n=int(input())
l=list(map(int,input().split()))
l.sort()
pre=10**9
mm=l[-1];p=0
for i in range(max(0,bl(l,l[-1]//2)-2),min(n,l[-1]//2+3)):
    if abs(mm/2-l[i])<pre:pre=abs(mm/2-l[i]);p=i
print(mm,l[p])


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

signed main(){
	int n,t;cin>>n>>t;
	vector<int> a(n),mx(n),mn(n);

	for(auto&& w:a)cin>>w;
	copy(begin(a),end(a),begin(mn));
	copy(begin(a),end(a),begin(mx));

	for(int i=0;i<n-1;i++){
		mn[i+1]=min(mn[i+1],mn[i]);
	}
	for(int i=n-1;i>=1;i--){
		mx[i-1]=max(mx[i-1],mx[i]);
	}
	int maxval=0ll,cnt=0ll,minval=-1ll;
	for(int i=0;i<n;i++){
		maxval=max(maxval,mx[i]-mn[i]);
	}
	for(int i=0;i<n;i++){
		if(maxval!=mx[i]-mn[i])continue;
		if(minval!=mn[i]){
		cnt++;minval=mn[i];	
		}
	}
	if(t<2)cout<<0<<endl;
	else cout<<cnt<<endl;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

//bool flag = __builtin_add_overflow(a , b , &tmp);
//bool flag = __builtin_mul_overflow(a , b , &tmp);
//bool flag3= __builtin_sub_overflow(a , b , &tmp);

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-12;
const long long inf = 2e12 + 12;
const int MAXN = 2000006, MAXM = 102, Mod = 1000000007 , MAXLog = 20;


int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    int k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i < x + k; ++i) {
        cout << i << ' ';
    }
    cout << '\n';

    return 0;
}

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

using namespace std;
using LLONG = long long;

const bool IsAllOne(const int x)
{
    if (x == 1)
    {
        return true;
    }
    if (x % 2 == 0)
    {
        return false;
    }
    return IsAllOne(x / 2);
}

const vector<int> GetExistingValues(const vector<int> &hats)
{
    set<int> values;
    for (const int hat : hats)
    {
        values.insert(hat);
    }
    vector<int> ret;
    for (const auto value : values)
    {
        ret.push_back(value);
    }
    return ret;
}

int main()
{
    int N;
    cin >> N;
    vector<int> hats(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> hats[i];
    }
    map<int, int> valueCounts;
    for (const int hat : hats)
    {
        ++valueCounts[hat];
    }
    sort(hats.begin(), hats.end());
    // ４種類以上の数字がある場合は必ずNo
    if (valueCounts.size() >= 4)
    {
        cout << "No" << endl;
        return 0;
    }
    // １種類の数字で許されるのは全て０のときだけ
    if (valueCounts.size() == 1)
    {
        if (valueCounts.find(0) != valueCounts.end())
        {
            cout << "Yes" << endl;
            return 0;
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
    }
    // ２種類の数字で許されるのは一方が0のときだけ
    else if (valueCounts.size() == 2)
    {
        if (valueCounts.find(0) == valueCounts.end())
        {
            cout << "No" << endl;
            return 0;
        }
        if (N % 3 != 0 || valueCounts[0] != N / 3)
        {
            cout << "No" << endl;
            return 0;
        }
        else
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    // ３種類の文字の場合
    else if (valueCounts.size() == 3)
    {
        if (N % 3 != 0)
        {
            cout << "No" << endl;
            return 0;
        }
        vector<int> values = GetExistingValues(hats);
        for (const int value : values)
        {
            if (valueCounts[value] != N / 3)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        for (int i = 0; i < 3; ++i)
        {
            const int a = values[i];
            const int b = values[(i + 1) % 3];
            const int c = values[(i + 2) % 3];
            if ((a ^ c) != b)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i,n) cin >> v[i];
    //小さい順に並び替えて順番に処理する
    sort(all(v));
    double ans=0;
    for(int i=0; i<n-1; i++){
        ans = (v[i]+v[i+1])/2;
        v[i+1] = ans;
    }
    cout  << setprecision(10) << ans << endl;


}

Measured memory_bytes: 3808
#include <iostream>
using namespace std;
const int MAX = 301;

int main(){
  int n,dp[MAX];

  fill(dp,dp+MAX-1,0);
  dp[0] = 1;
  for(int i = 1 ; i <= 17 ; i++){
    for(int j = 0 ; j < MAX-i*i ; j++){
      dp[i*i+j] += dp[j];
    }
  }

  while(cin >> n,n){
    cout << dp[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main{
    public static void main(String[] args){
    	Scanner scn = new Scanner(System.in);
    	int n;
    	int[] id = new int[4000];
    	long[] score = new long[4000];
    	
    	for(n=scn.nextInt(); n!=0; n=scn.nextInt()){
    		boolean flag1 = true;
    		int num=0;
    		
    		for(int i=0; i<n; i++){
    			boolean flag2 = true;
    			int tmp;
    			long sales;
    			
    			tmp = scn.nextInt();
    			sales = scn.nextLong()*scn.nextLong();

    			for(int j=0; j<num; j++)
    				if(id[j] == tmp){
    					score[j] += sales;
    					flag2 = false;
    				}
    			
    			if(flag2){
    				id[num] = tmp;
    				score[num++] = sales;
    			}
    		}
    		
    		for(int i=0; i<num; i++)
    			if(score[i] >= 1000000){
    				flag1 = false;
    				System.out.println(id[i]);
    			}
    		
    		if(flag1)
    			System.out.println("NA");
    		
    		
    	}
    }
}

Measured memory_bytes: 13000
N,K=map(int,input().split())
A=list(map(int,input().split()))

from collections import Counter
cnt=0

a=Counter(A)
b=list(a.values())
b.sort()
leng=len(b)

for item in b:
  if leng>K:
    cnt+=item
    leng-=1
    
print(cnt)

Measured memory_bytes: 32440
h, w = [int(i) for i in input().split()]
a = []
answer = []

for i in range(h):
    a.append([int(i) for i in input().split()])
  
for i in range(h):  
    for j in range(w):  
        if a[i][j] % 2 != 0:
          try:
#              if a[i][j+1] % 2 != 0:
                  a[i][j] -= 1
                  a[i][j+1] += 1            
                  answer.append([i+1, j+1, i+1, j+2])
          except:
              try:
#                  if a[i+1][j] % 2 != 0:
                      a[i][j] -= 1
                      a[i+1][j] += 1  
                      answer.append([i+1, j+1, i+2, j+1])
              except:
                  pass
    
print(len(answer))
for i in range(len(answer)):
    print(" ".join(map(str, answer[i])))


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

    
    int main() {
        int a, b, x; cin >> a >> b >> x;
        string ans;
        if (x < a) {
            ans = "NO";
        } else if (x > a + b) {
            ans = "NO";
        } else {
            ans = "YES";
        }
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
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;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;


void solve(long long A, long long B, long long C, long long D){
    ll ret =0;
    if (B <= C || D <= A)
    {
        ret = 0;
    } else if (A <= C && C < B && B <= D)
    {
        ret = B - C;
    } else if (C <= A && A < D && D <= B)
    {
        ret = D - A;
    } else if (A <= C && D <= B)
    {
        ret = D - C;
    } else if (C <= A && B <= D)
    {
        ret = B -A;
    }
    cout << ret << "\n";
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<double> a(n);
	rep(i,n) cin>>a[i];
	double sum = 0;
	rep(i,n) sum += 1.0/a[i];
	printf("%.12f\n",1.0/sum);
	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 elements = sc.nextInt();
        int[] value = new int[elements];
        for (int i = 0; i < elements; i++) {
            value[i] = sc.nextInt();
        }
        solve(value);
    }

    public static void solve(int[] ingredients){
        ingredients = insertionSort(ingredients);
        double result = 0;
        for(int i=0; i<ingredients.length-1; i++){
            result += ingredients[i]/Math.pow(2,i+1);
        }
        result += ingredients[ingredients.length-1]/Math.pow(2,ingredients.length-1);
        System.out.println(result);
    }

    public static int[] insertionSort(int[] a){
        int temp, ins, cmp; //temporary, insert, compare
        for(ins=1; ins<a.length; ins++){
            temp = a[ins];
            for(cmp = ins-1; cmp>=0; cmp--){
                if(temp < a[cmp]){
                    break;
                }
                a[cmp+1] = a[cmp];
            }
            a[cmp+1] = temp;
        }
        return a;
    }
}

Measured memory_bytes: 25044
import java.util.*;
import java.io.*;
import static java.util.Comparator.*;
 
class Main{
    public static void main(String[] args){
       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       in.lines().map(Integer::parseInt).sorted(reverseOrder()).limit(3).forEach(System.out::println);
    }
}

Measured memory_bytes: 31148
n = int(input())
s = input()
t = input()

sl = list(s)
tl = list(t)

ans = s + t
for i in range(n):

    if s[i:] == t[:n-i]:     
        sp = s[:i]
        common = s[i:]
        tp = t[n-i:]
        ans = sp + common + tp
        
        break

        
print(len(ans))
        

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, q = map(int, input().split())
pairs = [0] * q
for i in range(q):
    pairs[i] = list(map(int, input().split()))

from collections import deque

def dfs(min_val, length):
    if length == 0:
        return list([deque()])
    if min_val == m:
        return list([deque([m]) * length])
    ans = list()
    for i in range(min_val, m+1):
        remain = dfs(i, length-1)
        for j in remain:
            j.appendleft(i)
        ans.extend(remain)
    return ans

ans = 0
for i in dfs(1, n):
    tmp = 0
    for a, b, c, d in pairs:
        if (i[b-1] - i[a-1]) == c:
            tmp += d
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 68212
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

struct data{
    long a;
    long b;
    long c; 
    long d;
    data(long a2, long b2, long c2, long d2){
        a=a2;
        b=b2;
        c=c2;
        d=d2;
    }
    bool operator<( const data& another ) const {
        return d<another.d;
    }
};

int main()
{
    long N,M,Q;
    std::cin >> N >> M >> Q;
    std::vector<data> abcd;
    long a,b,c,d;
    for(long i=0; i<Q; i++){
        std::cin >> a >> b >> c >> d;
        abcd.push_back(data(a,b,c,d));
    }

    long score=0;
    long result=0;
    std::vector<long> A(10);
    for(long i=0; i<M; i++){
        for(long i1=i; i1<20; i1++){
            for(long i2=i1; i2<20; i2++){
                for(long i3=i2; i3<20; i3++){
                    for(long i4=i3; i4<20; i4++){
                        for(long i5=i4; i5<20; i5++){
                            for(long i6=i5; i6<20; i6++){
                                for(long i7=i6; i7<20; i7++){
                                    for(long i8=i7; i8<20; i8++){
                                        for(long i9=i8; i9<20; i9++)
                                        if(i1<M && i2<M && i3<M && i4<M && i5<M && i6<M && i7<M && i8<M && i9<M){
                                            A[0]=i+1;
                                            A[1]=i1+1;
                                            A[2]=i2+1;
                                            A[3]=i3+1;
                                            A[4]=i4+1;
                                            A[5]=i5+1;
                                            A[6]=i6+1;
                                            A[7]=i7+1;
                                            A[8]=i8+1;
                                            A[9]=i9+1;
                                            score=0;
                                            for(long j=0; j<Q; j++){
                                                if(A[abcd[j].b-1]-A[abcd[j].a-1]==abcd[j].c){
                                                    score+=abcd[j].d;
                                                }
                                            }
                                            if(score>=result){
                                                result=score;
                                            }
                                        }else{
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 3644
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

void add(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (a[i] > a[j]) {
        if (i < j) {
          add(ret, 1LL * m * (m + 1) / 2 % MOD);
        } else {
          add(ret, 1LL * m * (m - 1) / 2 % MOD);
        }
      }
    }
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
MOD = 10**9+7
MAXN = 5*(10**5)+5
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def nPr(n, r, mod=MOD):
    return f[n] * pow(f[n-r], mod-2, mod) % mod

n, m = map(int, input().split())
ans = 0
for k in range(n+1):
    tmp = nPr(m-k, n-k)
    tmp *= tmp
    tmp %= MOD
    tmp *= nPr(m, k)
    tmp %= MOD
    tmp *= nCr(n,k)
    tmp %= MOD
    if k%2:
        ans -= tmp
    else:
        ans += tmp
ans += MOD
ans %= MOD
print(ans)

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int  long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define pie 3.14159265358
#define mod2 998244353

 // lcm+min(a,b)
void solve(){   
    int n,m;cin>>n>>m;
    vi h(n);
    vi ans(n,1);
    rep(i,0,n)cin>>h[i];
    rep(i,0,m){
        int a,b;cin>>a>>b;a--;b--;
        if(h[a]>h[b])ans[b]=0;
        if(h[b]>h[a])ans[a]=0;
        if(h[a]==h[b]){ans[a]=0;ans[b]=0;}

    }
    int a=0;
    rep(i,0,n)a=a+ans[i];
    cout<<a;
} 

signed main(){
    IOS;
    int n=1; 
     // cin>>n; 
    rep(i,0,n)solve();
    
    return 0;
}

Measured memory_bytes: 4780
def finish(t):
    print(t)
    exit()

n = int(input())
a = list(map(int, input().split()))

if 0 in a:
    finish(0)

mod = pow(10, 18)
s = 1
for i in range(n):
    s *= a[i]
    if s > mod:
        finish(-1)
else:
    finish(s)

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


 int c[10][10]; 
int s,t,a[210][210],res; 

int main() { 
  
  scanf("%d%d",&s,&t); 
  
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++)
        scanf("%d",&c[i][j]);
    }
  
  for(int i=0;i<s;i++){
    for(int j=0;j<t;j++)
     scanf("%d", &a[i][j]);
    
  }
  
 for(int k=0;k<10;k++){
   for(int i=0;i<10;i++){
     for(int j=0;j<10;j++){

    if(c[i][j]>c[i][k]+c[k][j]) c[i][j]=c[i][k]+c[k][j];
     }
   }
 }
  for(int i=0;i<s;i++){
    for(int j=0;j<t;j++){   
    
    if(a[i][j]>=0){
      res +=c[a[i][j]][1]; 
      
    }
      
  }
  }
  
  printf("%d\n",res);
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>
using namespace std;
int main(int argc, char const *argv[]) {
  queue<int> q{};
  int i{};
  do {
    cin >> i;
    if (i == 0) {
      break;
    }
    q.push(i);
  } while (true);
  for (int i = 1; !q.empty(); ++i) {
    cout << "Case " << i << ": " << q.front() << endl;
    q.pop();
  }
  return 0;
}


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

int main(void){
  int x,y,b,p;
  int n;
  cin>>n;
  while(n--){
    cin>>x>>y>>b>>p;
    int sum = x * b + y * p;
    int sum1 = sum;
    if(b >= 5 && p >= 2) sum1 *= 0.8;
    else if(b >= 5) sum1 = (x * b + y * 2) * 0.8;
    else if(p >= 2) sum1 = (x * 5 + y * p) * 0.8;
    cout << (sum > sum1 ? sum1 : sum) << endl; 
  }


}

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

int main() {
  int N,K,min=1;
  cin >> N>>K;
  int i=1;
  
  for(i;i<=N;i++){
    if(min*2>min+K){
      min+=K;
    }else{
      min*=2;
    }
  }
    cout<<min<<endl;
}


Measured memory_bytes: 256
n,m,q=map(int,input().split())
a=[0]*q
b=[0]*q
c=[0]*q
d=[0]*q
A=[]
for i in range(q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
def score(A):
  sum=0
  for (ai,bi,ci,di) in zip(a,b,c,d):
    if A[bi-1]-A[ai-1]==ci:
      sum+=di
  return sum
def fbs(A):
  if len(A)==n:
    return score(A)
  if len(A)>0:
    pre_last=A[-1]
  else:
    pre_last=0
  res=0
  for v in range(pre_last,m):
    A.append(v)
    res=max(res,fbs(A))
    A.pop()
  return res

print(fbs(A))

Measured memory_bytes: 9256
#include<cstdio>
#include<iostream>
#include<string.h>
using namespace std;

int main()
{
	//black 1
	//white 2
	int board[7][7][7];
	int height[7][7];
	int N, M, P;
	while (cin >> N >> M >> P && N != 0 || M != 0 || P != 0)
	{
		memset(board, -1, sizeof(board));
		memset(height, 0, sizeof(height));
		int ansColor = -1;
		int ansP = -1;
		int a = 0;
		bool flag = false;
		for ( a = 0; a < P; a++)
		{
			int X, Y;
			cin >> X >> Y;
			X--; Y--;
			if (a % 2 == 0)
			{
				board[Y][X][height[Y][X]] = 1;
			}
			else
			{
				board[Y][X][height[Y][X]] = 2;
			}

			int color = board[Y][X][height[Y][X]];
			for (int dx = -1; dx <= 1; dx++)
			{
				for (int dy = -1; dy <= 1; dy++)
				{
					for (int dz = -1; dz <= 1; dz++)
					{
						if (dx == 0 && dy == 0 && dz == 0)continue;
						int nx = X + dx;
						int ny = Y + dy;
						int nz = height[Y][X] + dz;
						int cnt = 1;

						while (nx >= 0 && nx < N && ny >= 0 && ny < N && nz >= 0 && nz < N)
						{
							if (board[ny][nx][nz] != color)break;
							cnt++;
							nx += dx;
							ny += dy;
							nz += dz;
						}

						nx = X - dx;
						ny = Y - dy;
						nz = height[Y][X] - dz;
						while (nx >= 0 && nx < N && ny >= 0 && ny < N && nz >= 0 && nz < N)
						{
							if (board[ny][nx][nz] != color)break;
							cnt++;
							nx -= dx;
							ny -= dy;
							nz -= dz;
						}

						if (cnt >= M && !flag)
						{
							ansP = a + 1;
							ansColor = color;
							flag = true;
							break;
						}
					}
					if (flag)break;
				}
				if (flag)break;
			}
			if (flag)break;
			height[Y][X]++;
		}
		int X, Y;
		for (int b = a + 1; b < P; b++)cin >> X >> Y;
		if (ansColor == 1)
		{
			cout << "Black " << ansP << endl;
		}
		else if (ansColor == 2)
		{
			cout << "White " << ansP <<endl;
		}
		else
		{
			cout << "Draw" << endl;
		}

	}
}

Measured memory_bytes: 1168
//参照: IH19980412
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define pb push_back
using namespace std;
typedef long long ll;

int n;
ll a[55];
int k;
int main(){
	cin>>n>>k;
	rep(i,n) cin>>a[i];
	ll ans = -1e18;
	for(int i=-1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			if(i+1+n-j > k) continue; //(i+1) + (n-j) で現在の操作回数
			int zan = k - (i+1+n-j); //残りの操作回数
			vector<ll>vec;
			for(int x=0;x<=i;x++) vec.pb(a[x]);
			for(int x=j;x<n;x++) vec.pb(a[x]);
			SORT(vec);
			ll sum = 0;
			rep(i,vec.size()) sum += vec[i];
			for(int i=0;i<vec.size();i++){
				if(zan == 0 || vec[i] > 0) continue;
				sum -= vec[i];
				zan--;
			}
			ans = max(ans,sum);
		}}
	cout<<ans<<endl;
}



Measured memory_bytes: 256
from itertools import product
from copy import deepcopy
def solve():
    H,W,K = map(int,input().split())
    c = []
    for _ in range(H):
        c.append(list(input()))
    
    h_combs = list(product([0,1], repeat=H))
    w_combs = list(product([0,1], repeat=W))

    ans = 0
    for h_comb in h_combs:
        for w_comb in w_combs:
            mod_c = deepcopy(c)
            for i in range(H):
                if not h_comb[i]:
                    continue
                for j in range(W):
                    mod_c[i][j] = '.'

            for i in range(W):
                if not w_comb[i]:
                    continue
                for j in range(H):
                    mod_c[j][i] = '.'
            
            cnt = 0
            for h in range(H):
                for w in range(W):
                    if mod_c[h][w] == '#':
                        cnt += 1
            
            if cnt == K:
                ans += 1
    print(ans)

if __name__ == '__main__':
    solve()


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

using namespace std;

#define frei(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define fred(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define fri(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define frd(i,n) for (int i = (n) - 1; i >= 0; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )

#define uint64 unsigned long long
#define int64 long long
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
#define pr pair

#define BIT(n) (1<<(n))
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a) | (b))
#define XOR(a,b) ((a) ^ (b))
#define sqr(x) ((x) * (x))

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define PI 3.1415926535897932385
#define INF 1000111222
#define eps 1e-7
#define maxN 5005

void add_slef(int &a, int b, int mod = 0) {
    a += b;
    if(mod > 0 && a >= mod) a -= mod;
}

void sub_slef(int &a, int b, int mod = 0) {
    a -= b;
    if(mod > 0 && a < 0) a += mod;
}

vector<string> split(string s, string del) {
        vector<string> ans;
        if(s.size() == 0) {
            return ans;
        }
        size_t pos = 0;
        while((pos = s.find(del)) != string::npos) {
            string str = s.substr(0, pos);
            ans.push_back(str);
            s.erase(0, pos + del.size());
        }
        return ans;
}

const int mod = 1e9 + 7;
int dp[1 << 22];
int solve(int index, int mask, int n, vector<vector<int>> can) {
    if(index == n || mask == (1 << n)) {
        return 1;
    }
    if(dp[mask] != 0) {
        return dp[mask];
    }
    int ans = 0;
    for(int i = 0; i < can.size(); i++) {
        if(can[index][i] && !(mask & (1 << i))) {
            //cout << index << "  " << i << " " << mask << endl;
            add_slef(ans, solve(index + 1, mask ^ (1 << i), n, can), mod);
        }
    }
    dp[mask] = ans;
    return ans;
}

int main(int argc, char const *argv[])
{
    /* code */
    int n;
    cin >> n;
    vector<vector<int>> can(n, vector<int>(n));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) cin >> can[i][j];
    }
    vector<int> dp(1 << n);
    dp[0] = 1;
    for(int mask = 0; mask < (1 << n)-1; mask++) {
        int men = __builtin_popcount(mask);
        for(int i = 0; i < n; i++) {
            if(can[men][i] && !(mask & (1 << i))) {
                int m2 = mask ^(1 << i);
                add_slef(dp[m2], dp[mask], mod);
            }
        }
    }
    cout << dp[(1 << n)-1] << endl;
    //cout << solve(0, 0, n, can) << endl;
    return 0;
}


Measured memory_bytes: 8448
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N,M;
ll A[59],B[59],C[59],D[59];

ll dist(int x,int y){
    return abs(A[x]-C[y])+abs(B[x]-D[y]);
}

void fanc(int i){
    ll mn=5*LLINF;
    int best;
    rep(j,M){
        ll d=dist(i,j);
        if(mn>d){
            mn=d;
            best=j;
        }
    }
    cout1(best+1)
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M;
    rep(i,N) cin>>A[i]>>B[i];
    rep(i,M) cin>>C[i]>>D[i];
    
    rep(i,N) fanc(i);
}

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

class Program
{

    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var M = int.Parse(inputs[1]);
        var X = new int[M];
        inputs = Console.ReadLine().Split(' ');
        for (int i = 0; i < M; i++)
        {
            X[i] = int.Parse(inputs[i]);
        }

        X = X.OrderBy(x => x).ToArray();
        var diff = new int[M - 1];
        var sum = 0;
        for (int i = 0; i < diff.Length; i++)
        {
            diff[i] = X[i + 1] - X[i];
            sum += diff[i];
        }

        diff = diff.OrderByDescending(d => d).ToArray();
        foreach (var d in diff.Take(N - 1))
        {
            sum -= d;
        }

        Console.WriteLine(sum);
    }


}



Measured memory_bytes: 23392
#include<iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a;
    cin >> b;
    if (a < b)
    	cout << "a < b\n";
    else if (a > b)
    	cout << "a > b\n";
    else if (a == b)
    	cout << "a == b\n";
    return 0;
}


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

#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define clr(x) memset((x), 0, sizeof((x)));
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long i64;
typedef unsigned long long ull;

template<class T>
bool remin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool remax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

ll gcd(ll a, ll b) {
    a = abs(a);
    b = abs(b);
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

typedef ld ptdata;

struct pt {
    ptdata x, y;

    pt() {}

    pt(ptdata x, ptdata y) : x(x), y(y) {}

    inline pt operator-(const pt &r) const {
        return pt(x - r.x, y - r.y);
    }

    inline pt operator+(const pt &r) const {
        return pt(x + r.x, y + r.y);
    }

    inline pt operator*(const ptdata &r) const {
        return pt(x * r, y * r);
    }

    inline ptdata sqlen() const {
        return abs(x * x + y * y);
    }

    inline ld len() const {
        return sqrt(sqlen());
    }

    inline bool operator<(const pt &r) const {
        if (x != r.x) return x < r.x;
        return y < r.y;
    }

    inline bool operator==(const pt &r) const {
        return x == r.x && y == r.y;
    }
};

ostream &operator<<(ostream &os, const pt &p) {
    return os << "(" << p.x << "," << p.y << ")";
}

inline ptdata cross(const pt &l, const pt &r) {
    return l.x * r.y - l.y * r.x;
}

inline ptdata dot(const pt &l, const pt &r) {
    return l.x * r.x + l.y * r.y;
}


ll pwmod(ll a, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}

template<typename T>
inline T sqr(T x) {
    return x * x;
}


inline void solve() {
    string s;
    cin >> s;
    set<char> ss;
    for (char c : s) {
        ss.insert(c);
    }
    if (ss.count('S') + ss.count('N') == 1) {
        cout << "No\n";
        return;
    }
    if (ss.count('E') + ss.count('W') == 1) {
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
}

void prepare() {

}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);


    prepare();

    int t = 1;
    //cin >> t;
    //t = nxt();
    forn(i, t) {
        solve();
    }

    cerr << "Time " << clock() / (double) CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 256
a=input().split(' ')
b=int(a[0])
c=int(a[1])
data=input().split(' ')
data_1=0
data_2=0
for i in range(b):
	data_1=int(data[i])
	if data_1 >= c:
		data_2=data_2+1
	else:
		pass
print(data_2)

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
	int a;
	cin >> a;
	cout<<a*a*a<<endl;
}

Measured memory_bytes: 256
import heapq as h
n,m = map(int,input().split())
ans = 0
l = [0]*m
d = {i:[] for i in range(1,m+1)}
for _ in range(n):
  a,b = map(int,input().split())
  if a>m:
    continue
  d[a].append(b)
for i in range(1,m+1):
  if i in d:
    for x in d[i]:
      h.heappush(l,-x)
  ans -= h.heappop(l)
print(ans)

Measured memory_bytes: 27624
### 提出 #10098255

##頭良すぎて草

##x | y    x と y のビット単位 論理和
##x ^ y    x と y のビット単位 排他的論理和
##x & y    x と y のビット単位 論理積
##x << n   x の n ビット左シフト
##x >> n   x の n ビット右シフト
##~x       x のビット反転

n,m=map(int,input().split())
p=2**n
inf=10**9
dp=[inf]*p
dp[0]=0
for i in range(m):
    a,b=map(int,input().split())
    c=sum([2**(j-1) for j in list(map(int,input().split()))])
    for k in range(p):
        if dp[k|c]>dp[k]+a:
            dp[k|c]=dp[k]+a
print(dp[-1] if dp[-1]!=inf else -1)


Measured memory_bytes: 47832
n = gets.to_i
a = gets.split.map(&:to_i)

ans = []
while a.size > 0
  (a.size - 1).downto(0) do |i|
    if a[i] == i + 1
      ans.unshift(a.delete_at(i))
      break
    end
    if i == 0
      puts -1
      exit
    end
  end
end

puts ans

Measured memory_bytes: 1788