akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
main(){
  long a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  long ans=min(a*x+b*y,2*c*max(x,y));
  if(x>y){
    ans=min(ans,a*(x-y)+2*c*y);
  }
  else if(y>x){
    ans=min(ans,b*(y-x)+2*c*x);
  }
  cout<<ans<<endl;
}    


Measured memory_bytes: 256
import math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = (x[0]-x[3])**2 + (x[1]-x[4])**2
	d = math.sqrt(d)
	d = math.fabs(d)
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if d > s:
		answers.append(0)
	elif d == s:
		answers.append(1)
	elif d < s:
		if d < r:
			if x[2] > x[5]:
				answers.append(2)
			else:
				answers.append(-2)
		elif d >= r:
			answers.append(1)
for val in answers:
	print val

Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000100
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int h[100100];
int dp[100100];
int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> h[i];
	for(int i=0;i<N;i++)dp[i]=INF;
	dp[0]=0;
	for(int i=1;i<N;i++){
		dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
		if(i>1)dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout << dp[N-1] << endl;
	return 0;
}

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

struct PAIR{int first, second; };
PAIR ans[100005];

int main(){
	int n;	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);

	int left=0;
	int ansNum=0;
	int sum=0;

	if(n>2){
		for(int i=1;i<=n;i++){
			if(a[i-1]<0)left=i;
			else{
				left--;
				break;
			}
		}



		if(left==n-1){		// 全部マイナス
			for(int i=0;i<n-1;i++){
				ans[ansNum].first=a[n-1];
				ans[ansNum].second=a[i];
				a[n-1]-=a[i];

				++ansNum;
			}
			sum=a[n-1];

		}else if(left>=0){		// 一部マイナス
			for(int i=1;i<n-1;i++){
				if(i<=left){
					ans[ansNum].first=a[n-1];
					ans[ansNum].second=a[i];
					a[n-1]-=a[i];
				}else{
					ans[ansNum].first=a[0];
					ans[ansNum].second=a[i];
					a[0]-=a[i];
				}
				++ansNum;
			}
			ans[ansNum].first=a[n-1];
			ans[ansNum].second=a[0];
			sum=a[n-1]-a[0];
		}else{				// マイナスなし
			for(int i=1;i<n-1;i++){
				ans[ansNum].first=a[0];
				ans[ansNum].second=a[i];
				a[0]-=a[i];

				++ansNum;
			}
			ans[ansNum].first=a[n-1];
			ans[ansNum].second=a[0];
			sum=a[n-1]-a[0];
		}

	}else{
		ans[0].first=a[1];
		ans[0].second=a[0];
		sum=a[1]-a[0];
	}

	cout<<sum<<endl;
	for(int i=0;i<n-1;i++){
		cout<<ans[i].first<<" "<<ans[i].second<<endl;
	}





	return 0;
}


Measured memory_bytes: 3072
def wczytaj_liste():
    ciag = input()
    rozdzielona_lista = ciag.split()
    odp = []
    for wyraz in rozdzielona_lista:
        liczba = int(wyraz)
        odp.append(liczba)
    return odp

def Raccon_vs_Monster():
    H, N = wczytaj_liste()
    ruchy = wczytaj_liste()
    suma_obrazen = sum(ruchy)
    if suma_obrazen >= H:
        print('Yes')
    else:
        print('No')

Raccon_vs_Monster()


Measured memory_bytes: 52292
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const double EPS = 1e-8;
typedef complex<double> P;
typedef pair<P,P> L;
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
bool cmp(P a,P b) {return atan2(a.imag(),a.real())<atan2(b.imag(),b.real());}
double toRad(double agl) {return agl*M_PI/180.0;}
double D(P a, P b) {
  return sqrt((a.real()-b.real())*(a.real()-b.real())+(a.imag()-b.imag())*(a.imag()-b.imag()));
}
P kaiten(P a, double r) {
  return P(a.real()*cos(r)-a.imag()*sin(r),a.real()*sin(r)+a.imag()*cos(r));
}

P crosspoint(const L &l, const L &m) {
  double A = cross(l.S - l.F, m.S-m.F);
  double B = cross(l.S - l.F, l.S - m.F);
  if(fabs(A)<EPS&&fabs(B)<EPS) return m.F;
  return m.F+B/A*(m.S-m.F);
}
double area(vector<P> p) {
  double a=0;
  for(int i=0; i<(int)p.size(); i++) a+=cross(p[i],p[(i+1)%p.size()]);
  return fabs(a)/2;
}

int main() {
  int n;int c=1;
  while(scanf("%d",&n)==1 && n) {
    vector<P> v;
    for(int i=0; i<n; i++) {
      P p[3];
      p[0]=P(1,0);
      p[1]=kaiten(p[0],toRad(120));
      p[2]=kaiten(p[1],toRad(120));
      for(int j=0; j<3; j++) p[j]=kaiten(p[j],toRad(360.0/n*i));
      if(i) {
        bool f=0;
        for(int j=0; j<3; j++) {
          if(D(v[0],p[j])<EPS) f=1;
        }
        if(f) break;
      }
      v.push_back(p[0]);
      v.push_back(p[1]);
      v.push_back(p[2]);
    }
    sort(v.begin(),v.end(),cmp);
    int m=v.size();
    P p=crosspoint(L(v[0],v[m/3]),L(v[1],v[m/3*2+1]));
    for(int i=0; i<m; i++) {
      v.push_back(p);
      p=kaiten(p,toRad(360.0/m));
    }
    sort(v.begin(),v.end(),cmp);
    printf("%.10f\n",area(v)/3);
  }
  return 0;
}


Measured memory_bytes: 1444
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;

const int mod = 1e9 + 7;

ll fast(ll b, ll e) {
	ll ans = 1;
	for(; e; b = b * b % mod, e /= 2) 
		if(e&1) ans = ans * b % mod;
	return ans;
}

ll add(ll x,ll  y) {
	return (x + y) % mod;
}

ll sub(ll x, ll y){ 
	return (x - y + mod) % mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll n, ans = 1, zeros = 0;
	cin >> n;
	map<pair<ll, ll>, pair<int, int> > m;
	for(int i = 0; i < n; ++ i) {
		ll a, b;
		cin >> a >> b;
		if(a == 0 && b == 0) zeros ++;
		else {
			ll g = __gcd(a, b);
			a /= g, b /= g;
			if(b < 0) a = -a, b = -b;
			if(a > 0) m[{a, b}].first++;
			else m[{b, -a}].second++;
		}
	}
	for(auto e:m) {
		int x, y;
		tie(x, y) = e.second;
		ans = ans * sub(add(fast(2, x), fast(2, y)), 1) % mod;
	}
	cout << sub(add(ans, zeros), 1) << '\n';
}


Measured memory_bytes: 15996
#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);
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  vector<int> C(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> C.at(i);
  }
  
  int k;
  int j = 1;
  int sum = B.at(0);
  while (j < N) {
    k = A.at(j);
    sum += B.at(j);
    if (k == A.at(j - 1) + 1) {
      sum += C.at(k - 2);
    }
    j++;
  }
  cout << sum << endl;


}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1&&b==2)cout<<"3";
    else if(a==1&&b==3)cout<<"2"<<endl;
        else if(a==2&&b==3)cout<<"1"<<endl;
            else if(a==2&&b==1)cout<<"3"<<endl;
                else if(a==3&&b==1)cout<<"2"<<endl;
                    else if(a==3&&b==2)cout<<"1"<<endl;
}

Measured memory_bytes: 3544
#include <stdio.h>

typedef long long ll;

int main(void) {
  ll H,W,a;

  scanf("%lld %lld", &H, &W);
  if (H == 1 || W == 1) {
    printf("1\n");
    return (0);
  }

  a = H * W;
  printf("%lld\n", (a + 1)/2);
  return (0);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[114514];
signed main(){
    int n,c,b;
    cin>>n>>c>>b;
    int sum=0;
    for(int j=0;j<n;j++){
        cin>>a[j];
    }
    for(int i=0;i<n-1;i++){
        sum+=min((a[i+1]-a[i])*c,b);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
import itertools

N = int(input())
lst = [int(input()) for i in range(N)]
sum_lst = sum(lst)
ans = 0
if (sum_lst % 10 != 0):
  ans = sum_lst
else:
  for i in lst:
    if ((sum_lst - i) % 10 != 0):
      ans = max(ans,sum_lst - i)
print(ans)



Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define nl '\n'

using namespace std;

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

void solve()
{
	int n;
	cin>>n;
	n = n%1000;
	if(n > 0) n -= 1000;
	cout<<-n<<nl;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	//cin>>t;
	t = 1;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
int main(){
	int n;
	while(~scanf("%d",&n))
	{
		int ti[200]={0};
		int sum=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&ti[i]);
			sum+=ti[i];
		}
		int m=0;
		scanf("%d",&m);
		int a,b;
		while(m--)
		{
			int sum2=sum;
			scanf("%d %d",&a,&b);
			sum2-=ti[a];
			sum2+=b;
			printf("%d\n",sum2);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
 int main() {
  int a, b;
  std::cin >> a >> b; 
  std::cout << a/b <<std::endl;
  std::cout << a%b <<std::endl;
  double f;
  f = 1.0 * a/b;
  std::cout << std::fixed;
  std::cout << f <<std::endl;




 return 0;


}


Measured memory_bytes: 3256
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

const int N = 1e5 + 10;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	for (int i = 0; i <= n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];

	LL ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		ans += min(b[i], a[i + 1]);
		b[i] -= min(b[i], a[i + 1]);
		ans += min(b[i], a[i]);
		a[i] -= min(b[i], a[i]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		solve(s);
		s.close();
	}

	public static void solve(Scanner s) {
		int W = s.nextInt();
		int H = s.nextInt();
		int N = s.nextInt();
		boolean[][] rect = new boolean[W][H];
		for (boolean[] array : rect) {
			Arrays.fill(array, true);
		}

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

			paint(rect, x, y, a);
		}

		int count = 0;
		for (int i = 0; i < rect.length; i++) {
			for (int j = 0; j < rect[i].length; j++) {
				if (rect[i][j]) {
					count++;
				}
			}
		}

		System.out.println(count);
	}

	public static void paint(boolean[][] rect, int x, int y, int a) {
		switch (a) {
		case 1:
			for (int i = 0; i < rect.length; i++) {
				for (int j = 0; j < rect[i].length; j++) {
					if (i < x) {
						rect[i][j] = false;
					}
				}
			}
			break;
		case 2:
			for (int i = 0; i < rect.length; i++) {
				for (int j = 0; j < rect[i].length; j++) {
					if (i >= x) {
						rect[i][j] = false;
					}
				}
			}
			break;
		case 3:
			for (int i = 0; i < rect.length; i++) {
				for (int j = 0; j < rect[i].length; j++) {
					if (j < y) {
						rect[i][j] = false;
					}
				}
			}
			break;
		case 4:
			for (int i = 0; i < rect.length; i++) {
				for (int j = 0; j < rect[i].length; j++) {
					if (j >= y) {
						rect[i][j] = false;
					}
				}
			}
			break;
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  int x[n], y[n];
  for ( int i = 0; i < n; i++ ) {
    cin >> x[i] >> y[i];
  }

  if ( n <= 2 ) { cout << 1; return 0; }

  int k = 0;
  vector<int> p, q;
  for ( int i = 0; i < n; i++ ) {
    for ( int j = i+1; j < n; j++ ) {
      p.push_back(x[i] - x[j]);
      q.push_back(y[i] - y[j]);
      k++;
    }
  }

  int max = 1, pm = 0, qm = 0;
  for ( int i = 0; i < k; i++ ) {
    if ( (p[i] == pm && q[i] == qm) || (p[i] == -1*pm && q[i] == -1*qm) ) { continue; }
    int len = 1;
    for ( int j = i+1; j < k; j++  ) {
      if ( (p[i] == p[j] && q[i] == q[j]) || (p[i] == -1*p[j] && q[i] == -1*q[j]) ) { len++; }
    }
    if ( len > max ) {
      max = len;
      pm = p[i];
      qm = q[i];
    }
  }

  cout << n-max << endl;
  return 0;
}

Measured memory_bytes: 256
// D - Card Eater

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	map<int, int> counter;

	for (int i=0; i<N; i++) {
		int A;
		cin >> A;
		counter[A]++;
	}

	int num_even = 0;
	for (auto itr=counter.begin(); itr!=counter.end(); itr++) {
		if (itr->second % 2 == 0) {
			num_even++;
		}
	}

	int ans;

	if (num_even % 2 == 0) ans = counter.size();
	else ans = counter.size() - 1;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
import numpy as np
N, M, X, Y = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
num = X+1
result = False
while num <= Y:
    resultA = np.array([num for _ in range(N)])
    resultB = np.array([num for _ in range(M)])
    if np.all(resultA > A) and np.all(resultB <= B):
        result = True
        break
    num += 1

if result:
    print('No War')
else:
    print('War')


Measured memory_bytes: 20160
// 2020/4/20

#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<long long>>;

vector<long long> color;
// -1: 未探査, ０: 白, 1: 黒

bool dfs(Graph &G, long long v, int cur = 0) {
    color[v] = cur;

    for (auto next_v : G[v]) {
        // 既に探索済みの場合
        if (color[next_v] != -1) {
            // 色が同じ場合 → 二部グラフではない
            if (color[next_v] == cur) return false;

            // 色が違う場合 → 二部グラフの可能性を残してcontinue。trueは最後に返す。
            continue; 
        }

        // 1回でもふfalseが帰ってきたらfalse。
        if(!dfs(G, next_v, 1 - cur)) return false;
    }

    // 何もなければ最後にTrue！
    return true;
}

int main() {
    long long N, M;
    cin >> N >> M;

    Graph G(N);

    for (long long i = 0; i < M; i++) {
        long long a, b;
        cin >> a >> b;

        a--; b--;

        G[a].push_back(b);
        G[b].push_back(a);
    }

    color.assign(N, -1);

    bool is_bipartile = true;
    for (long long v = 0; v < N; v++) {
        if (color[v] != -1) continue;  // v が探索済みだったらスルー
        if (!dfs(G, v)) is_bipartile = false;
    }

    long long B = 0, W = 0;  // 黒の数、白の数

    for (long long i = 0; i < N; i++) {
        if (color[i] == 0) W++;
        else B++;
    }

    if (is_bipartile) cout << B * W - M << endl;
    else cout << N * (N - 1) / 2 - M << endl;
}


Measured memory_bytes: 7424
n = int(input())

temp = n
p = 2
res = 0
while p * p <= n:
    if temp % p == 0:
        cnt = 1
        while temp % (p ** (cnt + 1)) == 0:
            cnt += 1
        res += int((-1 + (1 + 8 * cnt) ** 0.5) // 2)
        temp //= p ** cnt
    p += 1

print(res + (temp != 1))


Measured memory_bytes: 9448
#N = int(input())
#A = [int(x) for x in input().split()]
#a, b, c = map(int, input().split())
#name1 = str(input())
#alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
a, b, c = map(str, input().split())
if b == "+":
    print(int(a) + int(c))
else:
    print(int(a) - int(c))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
using namespace	std;
int main(){

  long long n,a[100000],x1=0,x2=0,i;

  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  for(i=n-1;i>=1;i--){
    if(a[i]==a[i-1]){
      x1=a[i];
      i-=2;
      break;
    }
  }
  for(;i>=1;i--){
    if(a[i]==a[i-1]){
      x2=a[i];
      break;
    }
  }

  cout<<x1*x2<<endl;
  return 0;
}




Measured memory_bytes: 1024
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()


N = i_i()
S = i_s()

ans = 0
for i in range(1000):
    s = str(i).zfill(3)
    
    i = S.find(s[0])
    if i == -1:
        continue

    i = S.find(s[1], i+1)
    if i == -1:
        continue

    i = S.find(s[2], i+1)
    if i == -1:
        continue

    ans += 1

print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(!(n%7) || !(n%4)) cout<<"Yes";
	else {
		while(n-=4){
			if(!(n%7)){
				cout<<"Yes";
				return 0;
			}
			if(n<0){
				cout<<"No";
				return 0;
			}
		}
		cout<<"No";
	}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

class LCA():

    def __init__(self,G,root = 0): #O(NlogN)
        self.n = len(G)
        self.G = G
        self.root = root
        self.K = 1 #2 ** K > nとなる最小のK
        while (1<<self.K) <= self.n:
            self.K += 1
        self.parents = [[-1] * self.n for _ in range(self.K)]
        self.dist = [0] * self.n
        
        self._dfs(root,0,-1)
        for k in range(self.K - 1):
            for v in range(self.n):
                if self.parents[k][v] >= 0:
                    self.parents[k + 1][v] = self.parents[k][self.parents[k][v]]
    
    def _dfs(self,i,d,p):
        self.parents[0][i] = p
        self.dist[i] = d
        for e in self.G[i]:
            if e != p:
                self._dfs(e,d + 1,i)
    
    def qry(self,u,v): #O(logN)
        if self.dist[u] < self.dist[v]:
            u,v = v,u
        
        dif = self.dist[u] - self.dist[v]
        for k in range(self.K):
            if dif >> k & 1:
                u = self.parents[k][u]
        
        if u == v:
            return u
        
        for k in range(self.K - 1,-1,-1):
            if self.parents[k][u] != self.parents[k][v]:
                u = self.parents[k][u]
                v = self.parents[k][v]
        
        return self.parents[0][u]

def main():
    n = int(input())
    G = [[] for _ in range(n)]
    for i in range(n):
        a = list(map(int,input().split()))
        k = a[0]
        for e in a[1:]:
            G[e].append(i)
            G[i].append(e)

    lca = LCA(G)
    q = int(input())
    for _ in range(q):
        u,v = map(int,input().split())
        print(lca.qry(u,v))

if __name__ == '__main__':
    main()



Measured memory_bytes: 143832
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A.sort()
    # (1) N = 2n + 1
    #     (1-1): p1 >= p2 <= p3 >= ... <= pN
    #         各pの隣同士の差の和における係数について考えると
    #         2: n-1個（両端以外の山）、1: 2個（両端）、-2: n個（谷）。
    #     (1-2): p1 <= p2 >= p3 <= ... >= pN
    #         各pの隣同士の差の和における係数について考えると
    #         2: n個（山）、-1: 2個（両端）、-2: n-1個（両端以外の谷）。
    if N % 2 == 1:
        n = N // 2
        ans_1 = 0
        for i, a in enumerate(A):
            coef = 2
            if i < n:  # 小さい順で1～n番目は係数-2
                coef = -2
            elif i < n + 2:  # 小さい順でn+1～n+2番目は係数1
                coef = 1
            ans_1 += coef * a
        ans_2 = 0
        for i, a in enumerate(A):
            coef = 2
            if i < n - 1:  # 小さい順で1～n-1番目は係数-2
                coef = -2
            elif i < n + 1:  # 小さい順でn～n+1番目は係数1
                coef = -1
            ans_2 += coef * a
        print(max(ans_1, ans_2))
    # (2) N = 2n
    #     p1 >= p2 <= p3 >= ... >= pN
    #     各pの隣同士の差の和における係数について考えると
    #     2: n-1個（左端以外の山）、1: 1個（左端）、-1: 1個（右端）、-2: n-1個（谷）。
    else:
        n = N // 2
        ans = 0
        for i, a in enumerate(A):
            coef = 2
            if i < n - 1:  # 小さい順で1～n-1番目は係数-2
                coef = -2
            elif i < n:  # 小さい順でn番目は係数-1
                coef = -1
            elif i < n + 1:  # 小さい順でn+1番目は係数1
                coef = 1
            ans += coef * a
        print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 13380
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define SZ(x) ((int)(x).size())
#define lson rt<<1
#define rson rt<<1|1
#define pb push_back
#define fi first
#define se second
#define what_is(x) cerr<<#x<<" "<<x<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
template <typename T>
inline void _read(T& x){
    cin>>x;
}
void R(){}
template <typename T,typename... U>
void R(T&head,U&... tail){
    _read(head);
    R(tail...);
}

template <typename T>
inline void _write(const T& x){
    cout<<x<<' ';
}
void W(){cout<<endl;}
template <typename T,typename... U>
void W(const T&head,const U&... tail){
    _write(head);
    W(tail...);
}

void go();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    go();
    return 0;
}
/****************ackun*********************/

void go(){
    int n,k;
    string s;
    R(n,k,s);
    s[k-1]=s[k-1]-'A'+'a';
    W(s);
}


Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, s, e) for(int i=s; i<e; i++)
#define REF(i, s, e) for(int i=s; i>e; i--)
typedef long long ll;
static const string MinusINF = "-";


static const vector<int> vecMatch({ 2,5,5,4,5,6,3,7,6 });
int n_match, n_num;

int match(int num) {
	return vecMatch[num - 1];
}

void chmax(string& a, string b) {
	
	if (a == MinusINF) a = b;
	else if (a.size() < b.size()) a = b;
	else if (a.size() == b.size()) {
		if (a < b) a = b;
	}
	
}

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


	cin >> n_match >> n_num;

	vector<int> nums(n_num);
	FOR(i, 0, n_num) cin >> nums[i];

	string dp[10010];
	FOR(i, 0, n_match) dp[i] = MinusINF;
	dp[0] = "";

	FOR(i, 0, n_match) {
		if (dp[i] == MinusINF) continue;
		for (int num : nums) chmax(dp[i + match(num)], dp[i] + (char)('0' + num));
	}

	//cout << "dp:" << endl;
	//FOR(i, 0, n_match+1) cout << dp[i] << endl;
	cout << dp[n_match] << endl;
}

Measured memory_bytes: 43648
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
        s: String,
    }
    let v: Vec<&str> = s.split('-').collect();
    if v.len() != 2 {
        println!("No");
        return;
    }
    if v[0].len() == a && v[1].len() == b {
        println!("Yes");
        return;
    }
    println!("No");
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

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

const int INF = 100000002;

ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main(){
	int n; cin >> n;
	vl t(n); rep(i, n) cin >> t[i];
	ll ans = t[n-1];
	rep(i, n-1){
		ll tmp = gcd(ans, t[i]);
		ans *= t[i]/tmp;
	}
	cout << ans << endl;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  int A, B; cin >> A >> B;

  //main
  
  
  // output
  int ans = 0;
  if(A >= 13){
    ans = B; 
  }else if(A >= 6){
    ans = B/2; 
  }else{
    ans = 0; 
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
S = list(input())
N = len(S)-1
ans = 0
for i in range(1 << N):
    a = S[0]
    for j in range(N):
        if(i >> j) & 1 == 0:
            a += S[j+1]
        else:
            x = int(a)
            ans += x
            a = S[j+1]
    x = int(a)
    ans += x
print(ans)


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,M = IL()

d = ILL(N)

d.sort(reverse=True)
cost = 0
while M:
  a,b = d.pop()
  if M>=b:
    M -= b
    cost += a*b
  else:
    cost += a*M
    M = 0
P(cost)

Measured memory_bytes: 56668
lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int,s)
intLine(s::Array{SubString{String},1})=map(intSub,s)
function main()
  a,b=intLine(split(input()))
  println(ifelse(a>12,b,ifelse(a>5,floor(Int,b/2),0)))
end
main()

Measured memory_bytes: 110848
#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;

const int MAX = 510000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll n;
vector<ll> a;

int main() {
  COMinit();

  cin >> n;
  a.resize(n + 1);

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

  unordered_set<ll> appeared;
  int fst_idx, snd_idx;
  for (int i = 0; i < a.size(); i++) {
    if (appeared.find(a[i]) != appeared.end()) {
      snd_idx = i;
      for (int j = 0; i < a.size(); j++) {
        if (a[i] == a[j]) {
          fst_idx = j;
          break;
        }
      }
      break;
    }
    appeared.insert(a[i]);
  }

  for (int k = 1; k <= n + 1; k++) {
    cout << (COM(n + 1, k) - COM(fst_idx + n - snd_idx, k - 1) + MOD) % MOD
         << endl;
  }
}


Measured memory_bytes: 20032
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
struct mint {
    long long x; // typedef long long long long;
    mint(long long _x=0):x((_x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint modpow(long long t) const {
        if (!t) return 1;
        mint a = modpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return modpow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
int H,W,K;
//dp[i][j]: 横移動i回で縦棒jにいける場合の数
mint dp[110][10];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    //横移動がH回まで
    cin>>H>>W>>K;
    K--;
    dp[0][0] = 1;
    //i: [0, H]
    //j: [0, W)
    rep(i,H)rep(j,W){
        //i行目のあみだくじの状態をbit全探索
        for(int k = 0; k < bit(W-1);k++){
            bool ok = true;
            //隣り合っているかの確認
            for(int l = 0; l < W - 2;l++){
                if((k & bit(l)) && (k & bit(l+1)))ok = false;
            }
            if(!ok)continue;
            int nj = j;
            if(k & bit(j))nj = j+1;
            else if(j > 0 && (k & bit(j - 1)))nj = j-1;
            dp[i + 1][nj] += dp[i][j];
        }
    }
    cout<<dp[H][K].x<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner Ent = new Scanner(System.in);
        int t = Ent.nextInt();
        String p = Ent.next();
        if(p.substring(0,t/2).equals(p.substring(t/2,t))){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23508
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#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;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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; }

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  double sum = 0;
  vector<pair<double, double>> Q;
  Q.reserve(n);
  int head = 0;
  // deque<pair<double, double>> Q;
  for (int i = 0; i < n; ++i) {
    double T, V;
    scanf("%lf%lf", &T, &V);
    if (i > 0) {
      double rem = V;
      while (rem > 0) {
        if (Q[head].first > rem) {
          Q[head].first -= rem;
          sum -= rem * Q[head].second;
          break;
        } else {
          rem -= Q[head].first;
          sum -= Q[head].first * Q[head].second;
          ++head;
        }
      }
    }
    // trace(i);
    // for (auto& it : Q) {
    //   trace(it.first, it.second);
    // }
    while (head < Q.size() && Q.back().second > T) {
      double V2 = Q.back().first, T2 = Q.back().second;
      Q.pop_back();
      sum -= V2 * T2;
      T = (V2 * T2 + V * T) / (V2 + V);
      V += V2;
    }
    Q.push_back({V, T});
    sum += V * T;
    printf("%.10f\n", sum / m);
  }
  return 0;
}


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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for(T &x : vec)
        is >> x;
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vi p(n);
    cin >> p;

    int ans = 0;
    FOR(i, 1, n - 1) {
        if(p[i - 1] < p[i] or p[i + 1] < p[i]) {
            if(p[i] > p[i - 1] and p[i] > p[i + 1]) {
                continue;
            } else {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())


ans = 0
if C * 2 <= A + B:
    ans = C * min(X, Y) * 2
else:
    ans = A * min(X, Y) + B * min(X, Y)

if Y < X and C * 2 < A:
    ans = ans + (X - Y) * C * 2
elif Y < X:
    ans = ans + (X - Y) * A
elif X < Y and C * 2 < B:
    ans = ans + (Y - X) * C * 2
elif X < Y:
    ans = ans + (Y - X) * B
else:
    pass
print(ans)

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

using namespace std;
const int MOD = 1e9 + 7;

int rec(int x, int y, int h, int w, vector<string>& arr, vector<vector<int>>& dp){
    if(x>=h || y>=w)
        return 0;
    if(arr[x][y]=='#')
        return 0;
    if(dp[x][y]!=-1)
        return dp[x][y];
    if(x==h-1 && y==w-1)
        return 1;
    return dp[x][y] = (rec(x+1,y,h,w,arr,dp)+rec(x,y+1,h,w,arr,dp))%MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int h,w;
    cin>>h>>w;
    vector<string> arr(h);
    for(int i=0;i<h;i++){
        cin>>arr[i];
    }
    
    vector<vector<int>> dp(h+1, vector<int>(w+1, - 1));
    int ans = rec(0,0,h,w,arr,dp);
    cout<<ans<<"\n";
}

Measured memory_bytes: 8432
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
int f(int k){
  int l = 0;
  while(k>0){
    l += k%10;
    k /= 10;
  }
  return l;
}

int main() {
  int n;
  cin >> n;
  string ans = "No";
  if(n % f(n) == 0) ans = "Yes";
  cout << ans << endl;
}

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

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

    int n;
    cin >> n;
    int p[static_cast<int>(2 * 1e5 + 1)] = {};
    int tmp;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        p[tmp] = p[tmp - 1] + 1;
        p[tmp - 1] = 0;
    }
    int max_seq = 0;
    for (int i = 1; i <= n; ++i) {
        max_seq = max(max_seq, p[i]);
    }
    // sort(p + 1, p + n + 1);

    // cout << n - p[n] << '\n';
    cout << n - max_seq << '\n';

    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr ll INF = 1'000'000'000'000'000'100;
ll N, K;
std::vector<ll> vn, vp;
ll zn;

ll f(ll x){
    ll n = 0;

    {
        ll y = -std::min<ll>(x, -1);

        for(ll b : vn){
            n += vp.end() - std::lower_bound(vp.begin(), vp.end(), (y + b - 1) / b);
        }
    }

    if(x >= 0){
        n += 1ll * zn * (N - zn);
        n += 1ll * zn * (zn - 1) / 2;
    }

    if(x > 0){
        for(int i=0;i<vn.size();++i){
            ll b = vn[i];
            
            n += std::lower_bound(vn.begin(), vn.begin() + i, x / b + 1) - vn.begin();
        }
        for(int i=0;i<vp.size();++i){
            ll b = vp[i];
            
            n += std::lower_bound(vp.begin(), vp.begin() + i, x / b + 1) - vp.begin();
        }
    }

    return n;
}

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

    std::cin >> N >> K;

    for(int i=0;i<N;++i){
        ll A;
        std::cin >> A;
     
        if(A < 0){
            vn.emplace_back(-A);
        }else if(A == 0){
            zn += 1;
        }else{
            vp.emplace_back(A);
        }
    }

    std::sort(vn.begin(), vn.end());
    std::sort(vp.begin(), vp.end());

    ll lb = -INF, ub = INF;
    while(ub - lb > 1){
        ll m = (lb + ub) / 2;

        if(f(m) >= K){
            ub = m;
        }else{
            lb = m;
        }
    }

    std::cout << ub << std::endl;
}


Measured memory_bytes: 2420
#include<stdio.h>

int main()
{
	int A,B,C,Mx,m,mn,K,i;
	scanf("%d %d %d",&A,&B,&C);
	scanf("%d",&K);
	if(A>=B && A>=C){
		Mx=A;
		m=B;
		mn=C;
	}
	if(B>A && B>C){
		Mx=B;
		m=A;
		mn=C;
	}
	if(C>A && C>B){
		Mx=C;
		m=A;
		mn=B;
	}
	for(i=0; i<K; i++){
		Mx=Mx*2;
	}
	printf("%d\n",Mx+m+mn);
	
	return 0;
}
		

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n % 2)res = res * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return res;
}
void solve() {
	int n; cin >> n;
	vector<int> cnt(n+1);
	vector<int> d(n);
	rep(i, n) {
		cin >> d[i];
	}
	if (d[0] != 0) {
		cout << 0 << endl; return;
	}
	int ma = 0;
	rep1(i, n - 1) {
		if (d[i] == 0) {
			cout << 0 << endl; return;
		}
		cnt[d[i]]++;
		ma = max(ma, d[i]);
	}
	ll ans = 1;
	cnt[0] = 1;
	rep1(i, ma) {
		ans = ans * mod_pow(cnt[i-1], cnt[i])%mod;
	}
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
		return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n;
		double[] p1= {0,0};
		double[] p2= {100,0};
		n=scan.nextInt();
		koch(n,p1,p2);
		System.out.printf("%f %f\n",p2[0],p2[1]);
		scan.close();
	}
	public static void koch(int n,double[] p1,double[] p2) {
		if(n==0) {
			show(p1);
		}
		else {
			double[] s=new double[2];
			double[] u=new double[2];
			double[] t=new double[2];
			s[0]=(p1[0]*2+p2[0])/3;
			s[1]=(p1[1]*2+p2[1])/3;
			t[0]=(p1[0]+p2[0]*2)/3;
			t[1]=(p1[1]+p2[1]*2)/3;
			u[0]=(t[0]-s[0])*Math.cos(Math.toRadians(60))-(t[1]-s[1])*Math.sin(Math.toRadians(60))+s[0];
			u[1]=(t[0]-s[0])*Math.sin(Math.toRadians(60))+(t[1]-s[1])*Math.cos(Math.toRadians(60))+s[1];
			n--;
			koch(n,p1,s);
			koch(n,s,u);
			koch(n,u,t);
			koch(n,t,p2);
		}
	}
	public static void show(double[] d) {
		System.out.printf("%f %f\n",d[0],d[1]);
	}
}


Measured memory_bytes: 42252
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

void main()
{
    auto nmd = readln.split.to!(long[]);
    auto n = nmd[0];
    auto m = nmd[1];
    auto d = nmd[2];

    writefln("%0.10f", (n - d) * 2 * (m - 1) / (n ^^ 2).to!double / (d == 0 ? 2 : 1));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

/********************Template********************/

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, l;
	string s[100];
	cin >> n >> l;
	REP(i, n) cin >> s[i];
	sort(s, s+n);
	REP(i, n) cout << s[i];
	cout << endl;
	rtn 0;
}

Measured memory_bytes: 256
i=list(map(int,input().split()))
a=i[0]
b=i[1]
def max(x,y,z):
  if x>y:
    m=x
  else:
    m=y
  if z>m:
    m=z
  return m
ans=max(a+b,a-b,a*b)
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    int A,B,X,ans;
    scanf("%d %d %d",&A,&B,&X);
    if(X%500!=0){
        X+=500-X%500;
    }
    int a=0,b=0;
    if(A<B){
        if(X%1000>0){
            a=X/1000+1;
        }else{
            a=X/1000;
        }
    }else if(A>2*B){
        b=X/500;
    }else{
        a=X/1000;
        X%=1000;
        b=X/500;
    }
    ans=A*a+B*b;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2088
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    B.reverse()
    idx = []
    x = -1
    for i in range(N):
        if A[i] == B[i]:
            idx.append(i)
            x = A[i]
    if len(idx) == 0:
        print("Yes")
        print(*B)
    else:
        l = 0
        r = N-1
        for i in idx:
            if A[l] != x and B[l] != x:
                B[l], B[i] = B[i], B[l]
                l += 1
            else:
                if A[r] != x and B[r] != x:
                    B[r], B[i] = B[i], B[r]
                    r -= 1
                else:
                    print("No")
                    exit()
        print("Yes")
        print(*B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 116064
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 100000000;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n){
        cin >> p[i];
    }
    int count = 0;
    REP(i, n-2){
        int a = max(p[i], max(p[i+1], p[i+2]));
        int b = min(p[i], min(p[i+1], p[i+2]));
        if(p[i+1]!=a && p[i+1]!=b){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h> 
#include <iostream>
#include <map>
#include <cmath>
#include<set>
#include <vector>
#include<bitset>
#include <string>
#include<queue>
#include <algorithm>
#include<set>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define vl vector<long long >;
//#define rep(i,a,b) for(int i=a;i<b;++i)
//typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,int>ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long ll;
const int N=105;const int NN=100005;
int A[N];int B[N];
#define INF 10000
ll dp[N][NN];
//int dp[N][N][N]={0};
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

/*void show(vi v,int valeur){
    int count=0;
    
    rep(i,0,(int)v.size()){
        ++count;
        cout<<v[i]<<" " ;
        if(count==valeur){cout<<"\n";count=0;}
    }
}*/
 int main() {
        ios_base::sync_with_stdio(false); cin.tie(NULL);int n,c;
  
  cin>>n>>c;
  rep(i,1,n+1){
      cin>>A[i]>>B[i];
  }
  rep(i,1,n+1){
      rep(j,0,(c+1)){
         if(A[i]<=j&&i==1) dp[i][j]=B[i];
         if(i>1){
             if(A[i]<=j)dp[i][j]=max(B[i]+dp[i-1][j-A[i]],dp[i-1][j]);
             if(A[i]>j)dp[i][j]=dp[i-1][j];
         }
      }
  }
  cout<<dp[n][c];
   return 0;
 }



Measured memory_bytes: 81596