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

int main(){
	int n,d,x;
	cin >> n >> d >> x;
	int a[n];
	for(int i=0;i<n;++i)cin >> a[i];
	
	x+=n;
	--d;
	
	for(int i=0;i<n;++i){
		x+=d/a[i];
	}
	
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp;
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::ops::*;
use std::process::exit;
use std::str::FromStr;

#[macro_export]
macro_rules! minimum {
    ($($e:expr),+) => {
        {
            let mut res = Vec::new();
            $(
                res.push($e);
            )+
            res.into_iter().min().unwrap()
        }
    };
}

pub const MOD: usize = 1000000007;

fn main() {
    let (h, w): (usize, usize) = input_two();
    let b: Vec<Vec<String>> = input_matrix(h);

    for (x, l) in b.iter().enumerate() {
        for (y, s) in l.into_iter().enumerate() {
            if &s[..] == "snuke" {
                println!("{}{}", ('A' as u8 + y as u8) as char, x + 1);
            }
        }
    }
}

pub fn input<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

pub fn input_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>()
}

pub fn input_lines<T: FromStr>(l: usize) -> Vec<T> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input());
    }
    res
}

pub fn input_lines_two<T: FromStr, U: FromStr>(l: usize) -> Vec<(T, U)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_two());
    }
    res
}

pub fn input_lines_three<T: FromStr, U: FromStr, V: FromStr>(l: usize) -> Vec<(T, U, V)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_three());
    }
    res
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}

pub fn input_matrix<T: FromStr + Clone>(h: usize) -> Vec<Vec<T>> {
    let mut res = vec![Vec::new(); h];
    for i in 0..h {
        res[i] = input_vec();
    }
    res
}


Measured memory_bytes: 4352
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;
for(int i=0;i<n;i++)if(a[i]==0) zero++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}

Measured memory_bytes: 2436
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    res = 0
    for i in range(1, n + 1):
        if i % 3 and i % 5:
            res += i
    print(res)
resolve()

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

def parent(i):
    i += 1
    return int(i/2) -1

def left(i):
    i += 1
    return 2*i -1

def right(i):
    i += 1
    return 2*i + 1 -1

A = [int(i) for i in input().split()]

print('node {}: key = {}, left key = {}, right key = {}, '.format(1, A[0], A[left(0)], A[right(0)]))

for i in range(1, len(A)):
    output = 'node {}: key = {}, parent key = {}, '.format(i+1, A[i], A[parent(i)])
    left_i = left(i)
    if(left_i < len(A)):
        output += 'left key = {}, '.format(A[left_i])
    right_i = right(i)
    if(right(i) < len(A)):
        output += 'right key = {}, '.format(A[right_i])
        
    print(output)
    


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n,m,x,y;
    bool war[300] = {};

    Scd2(n,m);
    Scd2(x,y);
    x += 100;
    y += 100;

    Rep(j,x+1){
        war[j] = true;
    }
    int u;
    Rep(i,n){
        Scd(u);
        u+= 100;
        Rep(j,u+1){
            war[j] = true;
        }
    }

    bool ans = false;
    Rep(i,m){
        Scd(u);
        u+= 100;
        if( war[u]) ans = true;
    }
    if( war[y] ) ans = true;

    ans ? printf ("War\n") : printf ("No War\n");

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000000007
using namespace std;
vector <int> tab;
vector <int> val;
int main (){
    int n,a;
    cin >> n;
    tab.push_back(0);
    val.push_back(0);
    for ( int i = 1 ; i <= n ; i++){
    cin >> a;
    tab.push_back(tab[i-1]+abs(val[i-1]-a));
    val.push_back(a);
    }
    tab.push_back(tab[n]+abs(val[n]));
    val.push_back(0);
    for( int i = 1 ; i <= n ; i ++){
    cout << tab[i-1]+tab[n+1]-tab[i+1]+abs(val[i-1]-val[i+1]) << endl;
    }
return 0;
}


Measured memory_bytes: 2164
/*
    oj d https://atcoder.jp/contests/abc178/tasks/abc178_a
    g++ A.cpp
    oj t
    oj s https://atcoder.jp/contests/abc178/tasks/abc178_a A.cpp
*/
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int x;
    cin >> x;

    if(x == 0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }

}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main() {
  int arr[3];
  cin >> arr[0] >> arr[1] >> arr[2];

  for (int j = 2; j != 0; j--) {
    for (int i = 0; i < j; ++i) {
      if (arr[i] > arr[i + 1]) {
        int tmp = arr[i + 1];
        arr[i + 1] = arr[i];
        arr[i] = tmp;
      }
    }
  }
  cout << arr[0] << ' ' << arr[1] << ' ' << arr[2] << endl;

  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A[1010101];
int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>N;
	ll ret=0;
	for(i=1;i<=N;i++) {
		for(j=i;j<=N;j+=i) ret+=j;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cstdio>
#include <climits>
#include <vector>
using namespace std;

long long gcd(long long x, long long y) {
    while(y) {
        long long t=x%y;x=y;y=t;
    }
    return x;
}

int rs[100],bs[100];
long long ps[100],qs[100], memo[100];
bool changed;

long long calc(int i) {
    if(i==-1) return 1;
    if(memo[i]>=0) return memo[i];
    changed = true;
    long long r = calc(rs[i]);
    long long b = calc(bs[i]);
    long long p = ps[i];
    long long q = qs[i];
    long long left_factor = r*p; // b*left_factor
    long long right_factor = b*q; // r*right_factor
    long long fgcd = gcd(left_factor, right_factor);
    left_factor /= fgcd;
    right_factor /= fgcd;
    memo[i] = b*left_factor + r*right_factor;
    return memo[i];
}

int main() {
    while(true) {
        int n; scanf("%d", &n);
        if(n==0) break;
        fill(memo, memo+n, -1);
        for(int i = 0; i < n; i++) {
            scanf("%lld%lld%d%d", ps+i, qs+i, rs+i, bs+i);
            rs[i]--; bs[i]--;
        }
        long long max_val = 0;
        for(int i = 0; i < n; i++) {
            changed = false;
            long long val = calc(i);
            if(changed) max_val = val;
        }
        printf("%lld\n", max_val);
    }
    return 0;
}

Measured memory_bytes: 0
/*
 *Author : zsenshi
 testing 
 */
#include <bits/stdc++.h> //Only for gcc compilers
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define dg(x) cout << #x << ":"<<x<<endl
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl
#define rep(i,begin,end) for(__typeof(end) i = (begin)-((begin) > (end)); i != (end) - ((begin) > (end)); i += 1-2*((begin) > (end)))
using namespace std;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vector<pii>> vvpi;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int h[n];
  int total = INT_MIN;
  int curr = 0 ;
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  for(int i = 0; i < n; i++){
    if(i+1 < n){
      if(h[i+1] <= h[i]){
        curr++;
      }
      else{
        total = max(total,curr);
        curr = 0;
      }
    }
    total = max(total,curr);
  }
  cout << total << '\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int a[55], n, k, ans=0;
int main() {
   cin >> n >> k;
   for (int i=0; i<n; i++) cin >> a[i];
   sort(a, a+n);
   k++;
   while (k--) ans+=a[n-k];
   cout << ans;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int frog(vector<int> A)
{
  int n=A.size();
  if(n<=1)
    return 0;
  if(n==2)
    return abs(A[0]-A[1]);
  int dp[n];
  dp[n-1]=0;
  dp[n-2]=abs(A[n-2]-A[n-1]);
  for(int i=n-3;i>=0;i--)
  {
    dp[i]=min(abs(A[i]-A[i+1])+dp[i+1],abs(A[i]-A[i+2])+dp[i+2]);
  }
   return dp[0];
}
int main()
{
  int N;
  cin>>N;
  vector<int> v(N);
  for(int i=0;i<N;i++)
    cin>>v[i];
  cout<<frog(v);
  return 0;
}

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





int main() {
  int g;
cin>>g;
  int s=0;
  vector<int>zi(g);
  for(int i=0;i<g;i++)
  {
  int a;
    cin>>a;
    zi.at(i)=a;
  }
vector<int>mann(g);
for(int i=0;i<g;i++)
  {
  int a;
    cin>>a;
    mann.at(i)=a;
s=s+a;  
} 
  vector<int>extra(g-1);
for(int i=0;i<g-1;i++)
  {
  int a;
    cin>>a;
    extra.at(i)=a;
  }
  for(int i=0;i<g-1;i++)
  {
  if(zi.at(i)+1==zi.at(i+1)) s=s+extra.at(zi.at(i)-1);
 
  }
 cout<<s<<endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>
#include <complex>

using namespace std;

#define mod 1000000007

int gcd(int m, int n)
{
	if(n == 0) return m;
	return gcd(n, m % n);
}

int main()
{
	int n;
	cin >> n;
	int a[100001];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int gcd_l[100001], gcd_r[100001];
	gcd_l[0] = a[0];
	for(int i = 1; i < n; i++){
		gcd_l[i] = gcd(gcd_l[i - 1], a[i]);
	}
	gcd_r[n - 1] = a[n - 1];
	for(int i = n - 2; i >= 0; i--){
		gcd_r[i] = gcd(gcd_r[i + 1], a[i]);
	}
	int ans = max(gcd_r[1], gcd_l[n - 2]);
	for(int i = 1; i < n - 1; i++){
		ans = max(ans, gcd(gcd_l[i - 1], gcd_r[i + 1]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
<?php
list($n) = ints();
$l[0] = 2;
$l[1] = 1;
for ($i = 2; $i <= $n; ++$i) $l[$i] = $l[$i - 2] + $l[$i - 1];
echo $l[$n];

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4604
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = Integer.parseInt(sc.next());

		int n1 = S/100;
		int n2 = S-n1*100;

		if(n1>12||n1==0) {
			if(n2>12||n2==0) {
				System.out.println("NA");
			}else {
				System.out.println("YYMM");
			}

		}else{
			if(n2>12||n2==0) {
				System.out.println("MMYY");
			}else {
				System.out.println("AMBIGUOUS");
			}
		}
	}
}

Measured memory_bytes: 21204
/* ex 7_1
series2 */
#include <stdio.h>

typedef struct point {
    int x_elem;
    int y_elem;
} point;

point shift_point(point point, struct point shift) {
    struct point result;
    result.x_elem = point.x_elem + shift.x_elem;
    result.y_elem = point.y_elem + shift.y_elem;
    return result;
}

int main(void) {
    // input and set variable
    point first;
    point second;
    point shift;
    point third;
    point fourth;
    scanf("%d", &(first.x_elem));
    scanf("%d", &(first.y_elem));
    scanf("%d", &(second.x_elem));
    scanf("%d", &(second.y_elem));

    // calculate vector
    shift.x_elem = first.y_elem - second.y_elem;
    shift.y_elem = second.x_elem - first.x_elem;

    third = shift_point(second, shift);
    fourth = shift_point(first, shift);

    printf("%d %d %d %d\n", third.x_elem, third.y_elem, fourth.x_elem,
           fourth.y_elem);
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
using namespace std;
int main(){
		int a;
		int b;
		int c;
		cin >> a >> b >> c;
		int s=0;
			for (int i = a; i <= b; i++){
			if (c%i == 0){
				s++;
			}
		}
		cout << s << endl;
	return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n, m;
    ll k;
    cin >> n;
    VL x(n);
    REP(i,n) scanf("%lld", &x[i]);
    cin >> m >> k;
    VL y(n-1);
    REP(i,n-1) y[i] = x[i+1] - x[i];
    VI s(n-1), a(n-1);
    REP(i,n-1) a[i] = s[i] = i;
    REP(i,m){
        int d;
        scanf("%d", &d);
        d--;
        swap(s[d-1], s[d]);
    }
 
    VI so(s);
    REP(i,n-1) s[so[i]] = i;
 
    while (k){
        if (k & 1LL){
            REP(i,n-1) a[i] = s[a[i]];
        }
        VI so(s);
        REP(i,n-1) s[i] = so[s[i]];
        k /= 2;
    }
 
    VI ao(a);
    REP(i,n-1) a[ao[i]] = i;
 
    ll ans = x[0];
    cout << ans << endl;
    REP(i,n-1){
        ans += y[a[i]];
        printf("%lld\n",ans);
    }
 

    return 0;
}

Measured memory_bytes: 4344
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
using namespace std;

struct pp{
	char name[11];
	int T;
};

int main(){
	int n,q;
	cin>>n>>q;
	
	pp array[100000];
	queue<int> a;
	
	for(int i=0 ; i<n ; i++){
		cin>>array[i].name>>array[i].T;
		a.push(i);
	}
	
	int tsum = 0;
	
	while(!a.empty()){
		int i = a.front();
		a.pop();
		int tmp = array[i].T-q;

		tsum += min(array[i].T, q);

		if(tmp > 0){
			array[i].T -= q;
			a.push(i);
		}else{
			printf("%s %d\n",array[i].name,tsum);
		}
	}
	
	return 0;
}

Measured memory_bytes: 2156
#include<bits/stdc++.h>
#define ll long long int

using namespace std;


int main()

{

    #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
    #endif
    ll x;
    cin>>x;
    for(ll a=-118;a<=119;a++)
    {
    	for(ll b=-119;b<=118;b++)
    	{
    		ll r=pow(a,5);
    		ll l=pow(b,5);
    		if(r-l==x)
    		{
    			cout<<a<<" "<<b<<endl;
    			return 0;
			}
		}
	}
	

}



Measured memory_bytes: 4088
import java.io.PrintWriter;
import java.util.Scanner;
class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		while(sc.hasNext()){
			String str = sc.nextLine();
			str=str.replaceAll("apple","-");
			str=str.replaceAll("peach", "apple");
			str=str.replaceAll("-","peach");
			System.out.println(str);
		}
	}	
}

Measured memory_bytes: 26024
#include<iostream>

using namespace std;

int main()
{
	int n;
	int M,N;
	int i,j;
	int ans;
	
	for(;cin >> n;)
	{
		if(n==0)
			break;
			
		ans=0;
		
		for(i=0;i<12;i++)
		{
			cin >> M >> N ;
			n-=M-N;
			if(ans==0 && n<=0)
				ans=i+1;
		}
		
		if(ans!=0)
			cout << ans <<endl;
		else
			cout << "NA" << endl;
	}
}

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

int main(){
    int a, b , c;
    cin >> a >> b >> c;
    int sum = a + b + c;
    if(sum % 2 == 1){
        cout << "No" << endl;
    }
    else if(sum / 2 == a + b || sum / 2 == b + c || sum / 2 == a + c){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a>0 && a<=9 && b>0 && b<=9) System.out.println(a*b);
		else System.out.println("-1");
	}

}


Measured memory_bytes: 26936
#!/usr/bin/env python3
def main():
    from bisect import bisect_left, bisect_right

    N, K = map(int, input().split())
    A = sorted([int(x) for x in input().split()])

    negative_end = bisect_left(A, 0)
    postive_start = bisect_right(A, 0)

    postive_cnt = N - postive_start
    negative_cnt = negative_end
    zero_cnt = N - postive_cnt - negative_cnt

    negative_pairs_cnt = postive_cnt * negative_cnt
    zero_pairs_cnt = (zero_cnt * (postive_cnt + negative_cnt)
                      + (zero_cnt * (zero_cnt - 1) // 2))
    
    # 答えが負の場合
    if K <= negative_pairs_cnt:
        # 二分探索：mid以下になるペアがK個以上あるか？
        ok, ng = 0, -10 ** 19
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            or_higher_cnt, right = 0, postive_start
            for left in range(negative_end):
                while right < N and A[left] * A[right] > mid:
                    right += 1
                or_higher_cnt += postive_cnt - (right - postive_start)
            if or_higher_cnt >= K:
                ok = mid
            else:
                ng = mid
        print(ok)
    # 答えが0の場合
    elif K <= negative_pairs_cnt + zero_pairs_cnt:
        print(0)
    # 答えが正の場合
    else:
        # 二分探索：mid以下になるペアがK個以上あるか？
        K -= negative_pairs_cnt + zero_pairs_cnt
        ok, ng = 10 ** 19, 0
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            # 正*正の場合
            or_higher_cnt, right = 0, N - 1
            for left in range(postive_start, N):
                while right < N and A[left] * A[right] > mid and left < right:
                    right -= 1
                or_higher_cnt += max(0, right - left)
            # 負*負の場合
            left = 0
            for right in range(negative_end - 1, -1, -1):
                while left < N and A[left] * A[right] > mid and left < right:
                    left += 1
                or_higher_cnt += max(0, right - left)

            if or_higher_cnt >= K:
                ok = mid
            else:
                ng = mid
        print(ok)


if __name__ == '__main__':
    main()


Measured memory_bytes: 104176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int w,a,b;cin>>w>>a>>b;
  int a2=a+w;
  int b2=b+w;
  if(b2-a<0)cout<<abs(b2-a)<<endl;
  else if(b-a2>0)cout<<abs(b-a2)<<endl;
  else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var h, w int 
  fmt.Scan(&h, &w)
  for i := 0; i < h; i++ {
    var s string 
    fmt.Scan(&s)
    for j := 0; j < 2; j++ {
      fmt.Println(s)
    }
  }
}

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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef complex<double> com;

#define endl '\n'
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;

void test()
{
	int n,m;
	double c=0,sum=0;
	cin>>n>>m;

	double a[n];

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

	for(int i=0;i<n;i++)
	{
		if(a[i] >= sum / (4*m) )
			c++;
	}

	if(c >= m)
	{
		cout<<"Yes";
	}
	else
		cout<<"No";


}

int main()
{   
fast_io();
cout << fixed << setprecision(15);
int t = 1;

//cin>>t;

for(int i = 0; i < t; i++)
{
	test();
}
return 0;
}

Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


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


ll DP[1000005], ps[1000005];


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

    int n;
    cin>>n;

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

    DP[n+1] = 1;
    DP[n] = n;
    DP[n-1] = 1LL*n*n;
    for(int i=n+1;i>=n-1;i--)
        ps[i] = (ps[i+1] + DP[i]) % MOD;

    for(int i=n-2;i>=1;i--){
        DP[i] = (DP[i+1] + ps[i+3] + (n-(n-i))) % MOD;
        ll z = 1LL*(n-1)*(n-1);
        z %= MOD;
        // z = (z * pwr(2, MOD-2)) % MOD;
        DP[i] += z;
        DP[i] %= MOD;
        ps[i] = (ps[i+1] + DP[i]) % MOD;
    }
// if(n <= 10){

// cout<<"DP: ";for(int i=1;i<=n+1;i++)    cout<<DP[i]<<" ";cout<<endl;   
// }

    DP[1] %= MOD;
    DP[1] += MOD;
    DP[1] %= MOD;
    cout<<DP[1];
    return 0;
}
 









Measured memory_bytes: 15872
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        static int maxdex = -1;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            while (true) {
                if (max2(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int max2(int[] a) {
            int M = Integer.MIN_VALUE;
            for (int i = 0; i < a.length; i++) {
                if (M < a[i]) {
                    M = a[i];
                    maxdex = i;
                }
            }
            return M;
        }

    }
}



Measured memory_bytes: 23892
n = int(input())
a_array = [int(x) for x in input().split()]
sum_a = sum(a_array)
if sum_a % n == 0:
    sum_a = int(sum_a/len(a_array))
    ans = 0
    for a in a_array:
        ans += abs(sum_a-a)**2
    print(int(ans))
else:
    sum_a1 = int(sum_a/len(a_array))
    sum_a2 = int(sum_a/len(a_array))+1
    ans1 = 0
    ans2 = 0
    for a in a_array:
        ans1 += abs(sum_a1-a)**2
        ans2 += abs(sum_a2-a)**2
    print(int(min(ans1, ans2)))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>

struct island{
	int a;
	int b;
};

int main(){
	int n,m;
	int ans=1;
	std::vector<island> iList;
	std::cin>>n>>m;

	iList.resize(m);
	
	for(int i=0; i<m; i++)
		std::cin>>iList[i].a>>iList[i].b;

	std::stable_sort(iList.begin(), iList.end(), [](const island& x, const island& y){return x.b> y.b;});
	std::stable_sort(iList.begin(), iList.end(), [](const island& x, const island& y){return x.a< y.a;});

	int curHead=0;
	int curTail=n;

	for(int i=0; i<m; i++){
		curHead=iList[i].a;
		curTail=std::min(curTail ,iList[i].b);

		if(curHead>=curTail){
			ans++;
			curTail= iList[i].b;
		}
	}

	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int fun(int high, int low, int n, int re);

int main()
{
    int h, w, n, re;
    cin >> h >> w >> n;
    if(h>w)
    {
        re=fun(h,w,n,1);
    }
    else
    {
        re=fun(w,h,n,1);
    }
    cout << re;
    return 0;
}

int fun(int high, int low, int n, int re)
{
    if(high*re>=n)
        return re;
    else
        return fun(high,low,n,re+1);
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

Int gcm(Int a,Int b){
	if(b==0)return a;
	else return gcm(b,a%b);
}

Int lcm(Int a,Int b){
	return a*b/gcm(a,b);
}

int main() {
	int a[3],m[3];
	while(cin>>a[0]>>m[0]>>a[1]>>m[1]>>a[2]>>m[2],a[0]){
		int x[3];
		x[0]=a[0];x[1]=a[1];x[2]=a[2];
		int res[3]={1,1,1};
		int i;
		for(i=0;i<3;i++){
			while(x[i]!=1){
				x[i]=a[i]*x[i]%m[i];
				res[i]++;
			}
		}
		cout<<lcm(lcm(res[0],res[1]),res[2])<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N; cin >> N;

    FOR(h, 1, 3501){
        FOR(n, 1, 3501){
            int a1 = N * h * n;
            int a2 = 4 * h * n - n * N - h * N;
            if(a2 > 0 && a1 % a2 == 0){
                int w = a1 / a2;
                cout << h << " " << n << " " << w;
                return 0;
            }
        }
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int[] a = nextInts();

		long alis = 0;
		long bob = 0;
		Arrays.sort(a);
		for(int i=N-1;i>=0;i-=2){
			alis+=a[i];
		}
		for(int i=N-2;i>=0;i-=2){
			bob+=a[i];
		}

		System.out.println(alis-bob);

	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

int main() {
	int N, K; cin >> N >> K;
	vector<int> a(N);
	for(int i=0; i<N; ++i) cin >> a[i];
	vector<vector<vector<long>>> dp(N+1, vector<vector<long>>(256, vector<long>(N+1, 0)));
	long mod=1000000007;
	dp[0][0][0]=1;
	for(int i=0; i<N; ++i){
	    for(int j=0; j<256; ++j){
	        for(int k=0; k<=i; ++k){
	            dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%mod;
	            dp[i+1][j^a[i]][k+1]=(dp[i+1][j^a[i]][k+1]+dp[i][j][k])%mod;
	        }
	    }
	}
	vector<long> frc(N+1, 1);
	for(int i=1; i<=N; ++i) frc[i]=(frc[i-1]*i)%mod;
	long ans=0;
	for(int i=1; i<=N; ++i) ans=(ans+(dp[N][K][i]*frc[i])%mod)%mod;;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 21632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

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

  int ans = s.size();

  while (ans > 0) {
    ans -= 2;
    string a = s.substr(0, ans / 2);
    string b = s.substr(ans / 2, ans / 2);
    if (a == b) {
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define INF (1 << 28)

using namespace std;

int main(void) {
	int N,T;
	cin >> N >> T;
	int res = INF;
	for (int i = 0; i < N; ++i) {
		int c,t;
		cin >> c >> t;
		if (t <= T) {
			res = min(c,res);
		}
	}
	if (res < INF) {
		cout << res << endl;
	}
	else {
		cout << "TLE" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int comb(int N, int S, int num);

int n, s;
int num[10];
int memo[10][200][20];

int main(void)
{
	int i, j;
	
	while (1){
		
		
		memset(memo, -1, sizeof(memo));
		
		
		scanf("%d %d", &n, &s);
		if (!n && !s)return 0;
		
		printf("%d\n", comb(n, 0, 0));
		
		
	}
	
}

int comb(int N, int S, int num)
{
	int i, j;
	
	if (s == S && !N)return 1;
	
	if (num == 10 || !N)return 0;
	
	if (memo[N][S][num] != -1)return memo[N][S][num];
	
	
	return memo[N][S][num] = comb(N - 1, S + num, num + 1) + comb(N, S, num + 1);
	
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin, n, k;
    vector<ll> a(n);
    REP(i, 0, n) {
        cin, a[i];
    }
    auto b = a;
    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    ll ans = 0;
    ll inf = (2e+18) + 10000010;
    ll l = -inf, r = inf;
    while(l <= r) {
        ll mid = (l + r) / 2;
        ll cnt = 0;
        REP (i, 0, n) {
            auto &c = (a[i] < 0 ? b : a);
            if (a[i] * a[i] <= mid) {
                cnt--;
            }
            auto check = [&mid, &a, &i](ll t) {
                return t * a[i] <= mid;
            };
            ll it = partition_point(c.begin(), c.end(), check) - c.begin();
            cnt += it;
        }
        cnt /= 2;
        if (cnt < k) {
            l = mid + 1;
        } else {
            ans = mid;
            r = mid - 1;
        }
    }
    print(ans);

    return 0;
}


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

typedef long long int ll;


int main()
{
    double n;
    int x = -1;
    cin >> n;
    for(ll i = 0;i <= n;i++){
        ll t = i * 1.08;
        if(t == n){
            x = i;
        }
    }

    if(x != -1){
        cout << x;
    }
    else{
        cout << ":(";
    }
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector< pair<int, int> > freq1((int) 1e5 + 1);
  vector< pair<int, int> > freq2((int) 1e5 + 1);
  for (int i = 1; i <= (int) 1e5; i++) {
    freq1[i].second = i;
    freq1[i].first = freq2[i].first = 0;
    freq2[i].second = i;
  }
  int mx1 = 0, mx2 = 0;
  for (int i = 0; i < n; i += 2) {
    freq1[a[i]].first++;
    mx1 = max(mx1, freq1[a[i]].first);
  }
  for (int i = 1; i < n; i += 2) {
    freq2[a[i]].first++;
    mx2 = max(mx2, freq2[a[i]].first);
  }
  sort(freq1.rbegin(), freq1.rend());
  sort(freq2.rbegin(), freq2.rend());
  if (freq1[0].second == freq2[0].second) {
    if (freq1[1].first > freq2[1].first) {
      cout << n - freq1[1].first - freq2[0].first << '\n';
    } else {
      cout << n - freq2[1].first - freq1[0].first << '\n';
    }
  } else {  
    cout << n - mx1 - mx2;
  }
  return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int main()
{
	int a=0,b=0,c=0,d,e;
	while(scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)!=EOF)
	{
	    if((c+e)>b||(c-e)<0||(d+e)>b||(d-e)<0)
			  printf("No\n"); 
        else 
        	 printf("Yes\n");
	}
	return 0; 
}

Measured memory_bytes: 1012
fn main() {
    let mut s = read_line();
    s = s.trim().to_string();
    let mut cnt_1 = 0;
    for (i, c) in s.chars().enumerate() {
        if i % 2 == 0 && c == '0' {
            cnt_1 += 1;
        }
        if i % 2 == 1 && c == '1' {
            cnt_1 += 1;
        }
    }
    let mut cnt_2 = 0;
    for (i, c) in s.chars().enumerate() {
        if i % 2 == 0 && c == '1' {
            cnt_2 += 1;
        }
        if i % 2 == 1 && c == '0' {
            cnt_2 += 1;
        }
    }
    if cnt_1 > cnt_2 {
        println!("{}", cnt_2);
        return
    }
    println!("{}", cnt_1);
}

fn read_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define MAXN	300005
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, m, top, q[MAXN];
long long sum[MAXN], value[MAXN], A[MAXN];
long long pre[MAXN], suf[MAXN];
long long ansp[MAXN], anss[MAXN];
long long f[MAXN];
void solve(int l, int r, int delta, long long *ans) {
	if (l == r) {
		ans[l] = 1 - value[l] + pre[l - 1] + suf[l + 1];
		return;
	}
	int mid = (l + r - delta) / 2;
	solve(l, mid, delta, ans);
	solve(mid + 1, r, delta, ans);
	long long tmp = l - 1;
	top = 1; q[1] = tmp; f[tmp] = pre[tmp];
	A[tmp] = f[tmp] + sum[tmp] + tmp * (tmp - 1ll) / 2;
	for (long long i = l; i <= mid; i++) {
		while (top >= 2 && i * (q[top] - q[top - 1]) >= A[q[top]] - A[q[top - 1]]) top--;
		f[i] = pre[i];
		A[i] = f[i] + sum[i] + i * (i - 1ll) / 2;
		while (top >= 2 && (A[i] - A[q[top]]) * (q[top] - q[top - 1]) >= (A[q[top]] - A[q[top - 1]]) * (i - q[top])) top--;
		q[++top] = i;
	}
	for (long long i = mid + 1; i <= r; i++) {
		while (top >= 2 && i * (q[top] - q[top - 1]) >= A[q[top]] - A[q[top - 1]]) top--;
		f[i] = A[q[top]] - i * q[top] - sum[i] + i * (i + 1) / 2;
	}
	f[r] += suf[r + 1];
	for (long long i = r - 1; i >= mid + 1; i--) {
		f[i] += suf[i + 1];
		f[i] = max(f[i], f[i + 1]);
	}
	for (long long i = mid + 1; i <= r; i++)
		ans[i] = max(ans[i], f[i]);
}
void DP(long long *f) {
	top = 1; q[1] = 0; A[0] = f[0] = 0;
	for (long long i = 1; i <= n; i++) {
		while (top >= 2 && i * (q[top] - q[top - 1]) >= A[q[top]] - A[q[top - 1]]) top--;
		f[i] = max(f[i - 1], A[q[top]] - i * q[top] - sum[i] + i * (i + 1) / 2);
		A[i] = f[i] + sum[i] + i * (i - 1ll) / 2;
		while (top >= 2 && (A[i] - A[q[top]]) * (q[top] - q[top - 1]) >= (A[q[top]] - A[q[top - 1]]) * (i - q[top])) top--;
		q[++top] = i;
	}
}
int main() {
	read(n);
	for (long long i = 1; i <= n; i++) {
		read(value[i]);
		sum[i] = sum[i - 1] + value[i];
	}
	DP(pre);
	reverse(value + 1, value + n + 1);
	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + value[i];
	DP(suf);
	reverse(value + 1, value + n + 1);
	reverse(suf + 1, suf + n + 1);
	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + value[i];
	solve(1, n, 1, ansp);
	reverse(value + 1, value + n + 1);
	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + value[i];
	reverse(pre + 1, pre + n + 1);
	reverse(suf + 1, suf + n + 1);
	swap(pre, suf);
	solve(1, n, 0, anss);
	reverse(value + 1, value + n + 1);
	reverse(pre + 1, pre + n + 1);
	reverse(suf + 1, suf + n + 1);
	swap(pre, suf);
	reverse(anss + 1, anss + n + 1);
	read(m);
	while (m--) {
		int x, y;
		read(x), read(y);
		printf("%lld\n", max(pre[x - 1] + suf[x + 1], max(ansp[x], anss[x]) + value[x] - y));
	}
	return 0;
}

Measured memory_bytes: 21376
n,W=map(int,raw_input().split())
w=[]
val=[]
for i in range(n):
    p=map(int,raw_input().split())
    w.append(p[0])
    val.append(p[1])
to = sum(val)    
dp = [float("inf")]*(to+1)
dp[0]=0
for i in range(n):
    for j in range(to,val[i]-1,-1):
        dp[j]=min(dp[j],dp[j-val[i]]+w[i])
for i in range(to,-1,-1):
    if(dp[i]<=W):
        print i
        exit()

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    cout<<(n+m)*(n+m-1)/2-n*m<<endl;
    return 0;
}


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

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

int gcd(int a, int b){
	if(a > b) swap(a,b);
	while(b % a != 0){
		int na,nb;
		na = max(a,b)-min(a,b);
		nb = min(a,b);
		a = na;
		b = nb;
	}
	return min(a,b);
}

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

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

	cout << gcd(a,b) << endl;

	return 0;

}



Measured memory_bytes: 3164
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {
	ll n, y;
	cin >> n >> y;
	ll sum_10000, sum_5000, sum_1000;
	ll sum = 0;
	rep(i, n+1) {
		rep(j, n+1) {
			int k = n - j - i;
			if (k < 0) continue;
			if (y == i * 10000 + j * 5000 + k * 1000 && n == i + j + k){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <iomanip>
#include <queue>

#define PI 3.14159265358979
#define MOD 1000000007

//fixed << setprecision(15) <<

using namespace std;

int main(void) {
	long long int a, b, l, m, n;
	int x[100000], y[100000];
	string s, t;
	char u;
	int i, j, k;
	bool flag = true;
	cin >> s >> t;
	for (i = 0; i < s.size(); i++) {
		if (s[i] != t[i])flag = false;
		}
		if(flag)cout << "Yes" << endl;
			else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<bits/stdc++.h>
#define pq priority_queue
#define Pi acos(-1.0)
using namespace std;
#define INFF 10000000007
#define MOD 1000000007
char s[100005];
int len;
bool life[100005],flag=0;
bool ok(bool x,bool y)
{
    life[0]=x;
    life[1]=y;
    for(int i=1;i<len;i++)
    {
        if(s[i]=='o')
        {
            if(life[i])
                life[i+1]=!life[i-1];
            else
                life[i+1]=life[i-1];
        }
        else
        {
            if(life[i]==0)
                life[i+1]=!life[i-1];
            else
                life[i+1]=life[i-1];
        }
    }
    if((s[0]=='o' && !life[0]) || (s[0]!='o' && life[0]))
    {
        if(life[1]==life[len])
        {
            if((s[len]=='o' && !life[len]) || (s[len]!='o' && life[len]))
                return life[0]==life[len-1];
            else
                return life[0]!=life[len-1];
        }
        else
            return 0;
    }
    else
    {
        if(life[1]!=life[len])
        {
            if((s[len]=='o' && !life[len]) || (s[len]!='o' && life[len]))
                return life[0]==life[len-1];
            else
                return life[0]!=life[len-1];
        }
        else
            return 0;
    }
}
int main()
{
    cin>>len;
    len--;
    scanf("%s",s);
    if(ok(0,0))
        flag=1;
    else
    {
        if(ok(0,1))
            flag=1;
        else
        {
            if(ok(1,0))
                flag=1;
            else
                flag=ok(1,1);
        }
    }
    if(!flag)
        printf("-1\n");
    else
    {
        for(int i=0;i<=len;i++)
        {
            if(life[i])
                printf("W");
            else
                printf("S");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

void run() {
	int n,want,nodd=0,neven=0; scanf("%d%d",&n,&want); REP(i,n) { int x; scanf("%d",&x); if(x%2==0) ++neven; else ++nodd; }
	ll ret;
	if(want==0) {
		if(nodd==0) ret=1LL<<n; else ret=1LL<<(n-1);
	} else {
		if(nodd==0) ret=0; else ret=1LL<<(n-1);
	}
	printf("%lld\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
N=int(input())
ls=list(map(int,input().split()))
ls.sort()

#定数倍のやつに＋１する
M=max(ls)
A=[0]*(M+1)
for i in range(N):
  a=M//ls[i]
  for j in range(1,a+1):
    if A[ls[i]]>=2:
      break
    else:
      A[j*ls[i]]+=1
  continue  
ans=0     
for i in range(len(ls)):
  if A[ls[i]]==1:
    ans+=1
print(ans)

Measured memory_bytes: 92848