akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
int main(){
	int M,K;
	cin>>M>>K;
	if(K>(pow(2,M)-1) ){printf("-1\n");return 0;}
	if(M == 0){
		if(K == 0)printf("0 0\n");
		
	}else if(M == 1){
		if(K == 1){
			printf("-1\n");
		}else printf("0 0 1 1\n");
	}else{
		if(K == 0){
			int i ;
			for(i =0;i<= (pow(2,M)-1)-1;i++){
				printf("%d %d ",i,i);
			}
			printf("%d %d",i,i);
			return 0;
		}
		printf("0 %d 0 ",K);
		// vector<int> pa;
		queue<int> fq,seq;
		stack<int> sta;
		
		for(int i = 1;i<= (pow(2,M)-1);i++){
			if(i == K)continue;
			sta.push(i);
			fq.push(i);
		}
		int sz = sta.size();
		fq.push(K);
		for(int i =0;i<sz;i++){
			int no = sta.top();sta.pop();
			//cerr<<no<<endl;
			seq.push(no);
		}
		while(!fq.empty()){
			printf("%d ",fq.front()); fq.pop();
		}
		while(! seq.empty()){
		if(seq.size() == 1){ printf("%d",seq.front());seq.pop();}
		else {
			printf("%d ",seq.front());seq.pop();
		}
		}
	}
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

string res;

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

    string N;
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N.size(); i++)
    {
        sum += N[i] - '0';
    }
    if(sum%9==0){
        res = "Yes";
    }else{
        res = "No";
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3780
import math

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

def lcm(x, y):
	# 最小公倍数
    return (x * y) // math.gcd(x, y)


A,B,C,D=input2()
lenC=B//C
lenD=B//D
lenCD=B//lcm(C,D)

ans=0
ans=B-(lenC+lenD-lenCD)

A-=1
lenC=A//C
lenD=A//D
lenCD=A//lcm(C,D)

ans-=A-(lenC+lenD-lenCD)

print(ans)

Measured memory_bytes: 9056
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        tgcd = gcd(i, j)
        for k in range(1, k + 1):
            l = gcd(tgcd, k)
            ans += l

print(ans)


Measured memory_bytes: 70792
/*
___ is a raging sadist.
*/

//Destroy all WA at test 2

#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define endl "\n"
#define PI 3.14159265
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;
//const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7; 
using namespace std;

ll power(ll x, ll y) 
{ 
   ll res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  

        y = y>>1; 

        if (x<=100000000)
        x = (long long)(x*x);

        //cout<<x<<'\n'; 
    } 
    return res; 
} 

vector <pair<int,int>> adj[100005];
vector <int> dis;
vector <int> pred;

int num,m;

const int INF=1000000000;

void dijkstra(int s, vector<int> & d, vector<int> & p) {

    int n = num;
    d.assign(n, INF);
    p.assign(n, -1);

    d[s] = 0;
    set<pair<int, int>> q;
    q.insert({0, s});
    while (!q.empty()) {
        int v = q.begin()->second;
        q.erase(q.begin());

        for (auto edge : adj[v]) {
            int to = edge.first;
            int len = edge.second;

            if (d[v] + len < d[to]) {
                q.erase({d[to], to});
                d[to] = d[v] + len;
                p[to] = v;
                q.insert({d[to], to});
            }
        }
    }
}



int main()
{

#ifndef ONLINE_JUDGE    
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

fastio();


cin>>num>>m;

int x,y;

For(i,0,m){
cin>>x>>y;
adj[x-1].pb(mp((y-1),1));
adj[y-1].pb(mp((x-1),1));
}

dijkstra(0,dis,pred);

for(int i=1;i<=num-1;i++){
if (dis[i]==INF){
cout<<"No";
return 0;
}
}

cout<<"Yes"<<endl;

for(int i=1;i<=num-1;i++){
cout<<pred[i]+1<<endl;
}

return 0;
}

Measured memory_bytes: 16680
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     ll n,w;
     cin>>n>>w;
     ll aw[n+1],av[n+1];
     for(ll i=1;i<=n;i++)
     {
         cin>>aw[i]>>av[i];
     }
     ll q[n+1][w+1]={0};
       for(ll i=0;i<=n;i++)
         q[i][0]=0;
        for(ll i=0;i<=n;i++)
          q[0][i]=0;
          for(int i=0;i<=n;i++)
            for(int j=0;j<=w;j++)
            q[i][j]=0;
      for(ll i=1;i<=n;i++)
      {
         for(ll j=1;j<w+1;j++)
         {
             /*if(j-aw[i] >=0 )
             {aa=q[i-1][j-aw[i]];*/
             if(j-aw[i]>=0)
            q[i][j]=max(q[i-1][j],q[i-1][j-aw[i]]+av[i]);
             else
                q[i][j]=q[i-1][j];
           // else
                //q[i][j]=q[i-1][j];
         }
      }

  cout<<q[n][w];
}


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

using namespace std;

int main()
{
    long long a , b, c , k; cin>>a>>b>>c>>k;
    if(k <= a){
        cout<<k<<"\n";
        return 0;
    }
    if(a + b >= k){
        cout<<a<<"\n";
        return 0;
    }
    long long ans = (k - a - b);
    cout<<a - (ans)<<"\n";

   return 0;
}

Measured memory_bytes: 3580
#![allow(non_snake_case)]

use std::collections::{HashMap, HashSet, VecDeque};
use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let M: usize = read();
    let ps: Vec<usize> = (0..N).map(|_| read::<usize>() - 1).collect();
    let ms: Vec<(usize, usize)> = (0..M)
        .map(|_| (read::<usize>() - 1, read::<usize>() - 1))
        .collect();
    println!("{}", solve(ps, ms) + 1)
}

fn solve(ps: Vec<usize>, ms: Vec<(usize, usize)>) -> usize {
    // 1. msがつなぐグループを作る(i と値両方)
    let mut graph: HashMap<usize, Vec<usize>> = HashMap::new();
    for (x, y) in ms {
        let entry = graph.entry(x).or_insert_with(|| vec![]);
        entry.push(y);
        let entry = graph.entry(y).or_insert_with(|| vec![]);
        entry.push(x);
    }
    let mut visited = vec![false; ps.len()];
    let mut ans = 0;
    for i in 0..ps.len() {
        if visited[i] {
            continue;
        }
        let mut queue = VecDeque::new();
        queue.push_front(i);
        visited[i] = true;
        let mut indexes = HashSet::new();
        let mut values = HashSet::new();
        indexes.insert(i);
        values.insert(ps[i]);
        while let Some(v) = queue.pop_back() {
            match graph.get(&v) {
                None => {
                    continue;
                }
                Some(vec) => {
                    for &next in vec {
                        if visited[next] {
                            continue;
                        }
                        queue.push_front(next);
                        visited[next] = true;
                        indexes.insert(next);
                        values.insert(ps[next]);
                    }
                }
            }
        }
        for i in indexes {
            if values.contains(&i) {
                ans += 1;
            }
        }
    }
    ans - 1
}


Measured memory_bytes: 13744
import java.util.Scanner;

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

		String S = sc.next();

		String H = sc.next();
		int A = sc.nextInt();
		int B = sc.nextInt();
		String U = sc.next();


		if(U.equals(S)) {
			A--;
		}else if(U.equals(H)) {
			B--;
		}
		System.out.println(A);
		System.out.println(B);
	}
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    int arr[n] = {};
    for(int i=0; i<n;i++){
        cin >> arr[i];
    }

    
    
    int cur = 0;
    int ret = 0;
    int pos = -1;
    for(int i=n-1;i>0;i--){
        if(arr[i] <= arr[i-1]){
            ++cur;
            ret = max(cur,ret);
            
        }else{
            cur = 0;
            ret = max(cur,ret);
            
        }
    }

    cout << ret << endl;
    return 0;

}


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

#define pb push_back


long long nextll(long long n)
{
	vector<int> digis;
	long long result = 0;
	int pot = 1;
	long long temp = pow(10, pot);
	
	digis.pb(n%10);
	while(n%temp != n)
	{
		int digi = (n/temp)%10;
		digis.pb(digi);
		pot++;
		temp = pow(10,pot);
	}
	
	digis[0] = digis[0] + 1;

	int size = digis.size();
	
	int i;
	bool vaiUm = false;
	for(i = 0; i<size; i++)
	{
		int nex;
		int atu = digis[i];

		if(i+1 < size)
		{
			nex = digis[i+1];
		}
		else
		{
			if(atu==10)
			{
				digis.pb(1);
				digis[i] = 0;
			}
			break;
		}

		if(atu == nex + 2 || atu == 10) // vai um
		{
			digis[i+1] = digis[i+1] + 1;

		}
		else
		{
			break;
		}
	}

	int value = digis[i];
	for(int j = i-1; j>=0; j--)
	{
		if(value != 0)
			value--;
		digis[j] = value;
	}

	result = 0;
	size = digis.size();
	for(int i = 0; i<size; i++)
	{
		result += digis[i] * pow(10, i);
	}

	return result;
}

int main()
{

	int k;
	cin>>k;
	long long result = 0;
	for(int i =0; i<k; i++)
	{
		result = nextll(result);
	}
	cout<< result <<endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;
	string result;
	for (auto i = 0; i < S.length(); ++i)
	{
		result += S[i];
		result += T[i];
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
int ar[100005];

int mig[100005];
int m;
lint K;

int dif[100005];
lint res[100005];
bool done[100005];
int main(){
  cin>>n;
  REP(i,n) cin>>ar[i];
  cin>>m>>K;

  REP(i,n-1) mig[i]=i;

  REP(i,m){
    int a;cin>>a;
    a-=2;
    swap(mig[a],mig[a+1]);
  }
  REP(i,n-1) if(!done[i]){
    vector<int> cy;
    int cur=i;
    while(!done[cur]){
      done[cur]=1;
      cy.pb(cur);
      cur=mig[cur];
    }
    int m2=cy.size();
    REP(j,m2){
      dif[cy[j]]=cy[(j+K)%m2];
    }
  }
  res[0]=ar[0];
  REP(i,n-1){
    res[i+1]=res[i]+ar[dif[i]+1]-ar[dif[i]];
  }
  REP(i,n) printf("%lld\n",res[i]);
  return 0;
}





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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e6 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;

int main() {
    ll n;
    cin >> n;
    vll v(n);
    ll sum = 0;
    unordered_map<ll, ll> cnt;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        sum += v[i];
        cnt[v[i]]++;
    }
    int q;
    cin >> q;
    while (q--) {
        ll b, c;
        cin >> b >> c;
        cnt[c] += cnt[b];
        sum += (c - b) * cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }

}



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

int main(){
  string S, T;
  cin >> S >> T;
  int ans=0;
  if(S.at(0)==T.at(0)) ans++;
  if(S.at(1)==T.at(1)) ans++;
  if(S.at(2)==T.at(2)) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define tam 220000
#define offset 100000
#define se second
#define fi first
#define forr(i,p,n) for(ll i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<int,int> ii;
using namespace std;

int arrpa[tam],ans[tam];
map<int,int> resp;
int findpa(int num)
{
    if (arrpa[num]==num)
        return num;
    else return arrpa[num]=findpa(arrpa[num]);
}
set<int> s;
bool vis[tam];
vector<int> grafo[tam];
vector<int> elementos;
void dfs(int num)
{
    vis[num]=1;
    if (s.find(findpa(num))==s.end())
        s.insert(findpa(num));
    else
        resp[findpa(num)]++;
    elementos.pb(num);
    forr(i,0,grafo[num].size())
    {
        int hijo=grafo[num][i];
        if (vis[hijo]==false)
            dfs(hijo);
    }
}
int main()
{
    forr(i,0,tam)
    arrpa[i]=i,vis[i]=0;
    int n,k,l,iz,der;
    cin>>n>>k>>l;
    forr(i,0,k)
    {
        cin>>iz>>der;
        grafo[iz].pb(der);
        grafo[der].pb(iz);
    }
    int pa1,pa2;
    forr(i,0,l)
    {
        cin>>iz>>der;
        pa1=findpa(iz);
        pa2=findpa(der);
        if (pa1!=pa2)
        {
            arrpa[pa1]=pa2;
        }
    }
    
    forr(i,1,n+1)
    {
        if (vis[i]==false)
        {
            s.clear();
            dfs(i);
            forr(j,0,elementos.size())
            ans[elementos[j]]=resp[findpa(elementos[j])]+1;
            elementos.clear();
            resp.clear();
        }
    }
    forr(i,1,n+1)
    {
        cout<<ans[i]<<" ";
    }
    cout<<endl;

}

Measured memory_bytes: 15608
import sys

input = sys.stdin.readline


def main():
    H, W, M = map(int, input().split())
    row = [0] * (H)
    col = [0] * (W)
    bomb = set()
    for _ in range(M):
        h, w = map(int, input().split())
        bomb.add((h, w))
        row[h-1] += 1
        col[w-1] += 1
    row_max = max(row)
    row_index_list = [i for i, v in enumerate(row) if v == row_max]
    col_max = max(col)
    col_index_list = [i for i, v in enumerate(col) if v == col_max]
    ans = row_max + col_max - 1
    c = False
    for x in row_index_list:
        for y in col_index_list:
            if not (x + 1, y + 1) in bomb:
                c = True
                break
        if c:
            break
    if c:
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 string s;
 cin >> s;
 int yon = 0;
string a = "ATCG";
int now = 0;
rep(i,s.size()){
  bool k = false;
  rep(j,a.size()){
    if(s[i]==a[j]) k = true;
  }
  if(!k){
    now = 0;
  }else{
    now++;
    yon = max(yon,now);
  }
}
cout << yon << endl;
 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>  
#include<string.h>  
#include<math.h>  
#include<algorithm>  
using namespace std;  
int main()  
{  
    char s[100005];  
    scanf("%s", s);  
    int sum=0, len=strlen(s); 
	int a=0, g=0;  
    for(int i=0;i<len;i++)  
    {  
        if(s[i]=='g')  
        {  
            if(g>a)  
            {  
                sum++;  
                a++;  
            }  
            else  
                g++;  
        }  
        else  
        {  
            if(g>a)  
                a++;  
            else  
            {  
                sum--;  
                g++;  
            }  
        }  
    }  
    printf("%d\n", sum);  
    return 0;  
}   


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D, enter; vll path;
int main() {
	string S;
	cin >> S;
	N = S.length();
	vll dp(N+1, vl(2, 0));
	//0はぴったり、1は余分に
	for (i = 0; i < N+1; i++) {
		dp[i][0] = INF; dp[i][1] = INF;
	}
	dp[0][0] = 0; dp[0][1] = 1;
	for (i = 0; i < N; i++) {
		dp[i + 1][0] = min(dp[i][0] + ctoi(S[i]), dp[i][1] + (10-ctoi(S[i])));
		dp[i + 1][1] = min(dp[i][0] + ctoi(S[i])+1, dp[i][1] + (9 - ctoi(S[i])));
	}
	cout << dp[N][0];
}

Measured memory_bytes: 55940
N, K = map(int, input().split())
if K>(N-1)*(N-2)//2:
  print(-1)
else:
  M = N-1 + (N-1)*(N-2)//2-K
  print(M)
  for i in range(N-1):
    print(i+1,N)
  
  cnt = (N-1)*(N-2)//2
  flag = False
  for i in range(N-2):
    for j in range(i+1,N-1):
      if cnt == K:
        flag=True
        break
      print(i+1,j+1)
      cnt -= 1
    if flag:
      break
    

Measured memory_bytes: 42736
from bisect import bisect_left
from collections import defaultdict as dd

def main():

  s=input()
  t=input()
  n=len(s)

  dic=dd(list)
  for idx,i in enumerate(s*2):
    dic[i].append(idx)

  ans,p=0,-1
  for i in t:
    if i not in dic.keys():
      print(-1)
      exit()
    p=dic[i][bisect_left(dic[i], p+1)]
    if p>=n:
      p-=n
      ans+=n

  print(ans+p+1)

if __name__=='__main__':
  main()

Measured memory_bytes: 18292
#include <iostream>
#include <string>
#include <stack>
#include <list>

using namespace std;

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

	int len = area.size(), sum = 0;

	stack<int> st1;
	list<pair<int, int> > lst;

	for (int i = 0; i < len; i++) {
		if (area[i] == '\\') {
			st1.push(i);
		}
		else if (area[i] == '/' && !st1.empty()) {
			int j = st1.top();
			st1.pop();

			sum += (i - j);

			int temp = i - j;
			while (!lst.empty() && lst.front().second > j) {
				temp += lst.front().first;
				lst.pop_front();
			}
			lst.push_front(make_pair(temp, j));
		}
	}

	cout << sum << endl;
	int size = lst.size();
	cout << size;
	for (int i = 0; i < size; i++) {
		cout << " " << lst.back().first;
		lst.pop_back();
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1324
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

void pairsort(int n,int *a,int *b){
	pair<int,int> c[50];
	rep(i,n) c[i]=make_pair(-a[i],b[i]);
	sort(c,c+n);
	rep(i,n) a[i]=-c[i].first, b[i]=c[i].second;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		int pace[50],lap[50];
		rep(i,n) scanf("%d%d",pace+i,lap+i);

		pairsort(n,pace,lap);

		vector<int> stop[50];
		rep(i,n){
			int t=0;
			stop[i].push_back(t);
			rep(j,2*lap[i]){
				int t_next=t+pace[i];
				rep(k,i){
					int idx=lower_bound(stop[k].begin(),stop[k].end(),t)-stop[k].begin()-1;
					if(0<=idx && idx+1<stop[k].size() && idx%2==j%2){
						t_next=max(t_next,stop[k][idx+1]);
					}
				}
				t=t_next;
				stop[i].push_back(t);
			}
		}

		int ans=0;
		rep(i,n) ans=max(ans,stop[i].back());
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1156
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*


fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val k = sc.nextInt()

    val vs = Array(k) { Vertex(it) }

    for (x in 1 until k) {
        vs[x].adj.add(Edge(vs[(x * 10) % k], 0))
        vs[x].adj.add(Edge(vs[(x + 1) % k], 1))
    }

    vs[1].dist = 0

    val bfs = PriorityQueue<Vertex>()
    var count = 0

    bfs.add(vs[1])
    while (!bfs.isEmpty()) {
        val v = bfs.poll()
        //if (v.solved) continue


        v.solved = true
        for (edge in v.adj) {
            count += 1
            if (edge.to.dist == -1 || edge.to.dist > v.dist + edge.length) {
                edge.to.dist = v.dist + edge.length
                bfs.add(edge.to)
            }
        }
    }

    println(vs[0].dist + 1)

}


data class Vertex(val x: Int): Comparable<Vertex> {
    override fun compareTo(other: Vertex): Int {
        return this.dist - other.dist
    }

    var dist = -1
    var solved = false
    val adj = mutableListOf<Edge>()
}

class Edge(val to: Vertex, val length: Int)


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}




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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	ld p[n+1], dp[n+1][n+1];
	for(int i=0; i<=n; i++)for(int j=0; j<=n; j++)dp[i][j]=(ld)0;
	for(int i=1; i<=n; i++){
		cin >> p[i];
	}
	dp[0][0] = 1;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=i; j++){
			dp[i][j] += dp[i-1][j-1]*p[i];
			dp[i][j-1] += dp[i-1][j-1]*(1.0-p[i]);
		}
	}
	ld ans = 0;
	for(int j=0; j<=n; j++){
		if(j>n-j)ans += dp[n][j];
	}
	cout << fixed <<  setprecision(12) << ans << endl;
	
}	


Measured memory_bytes: 140928
N, K = map(int, input().split())
A = list(map(int, input().split()))
t = A.index(1)
ans = 10 ** 7
for i in range(K):
    pre = max(t + i, 0)
    tail = max(N - 1 - t - i, 0)
    unit = K - 1
    pre_unit = -(-pre // unit)
    tail_unit = -(-tail // unit)
    ans = min(ans, pre_unit + tail_unit)
print(ans)


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

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>> ab(2 * N);
	set<int> S;
	int a, b, ans = 0;
	for (int i = 0;i < N;i++) {
		cin >> a >> b;
		ab[a] = { b,1 };
	}
	for (int i = 0;i < N;i++) {
		cin >> a >> b;
		ab[a] = { b,0 };
	}

	for (int i = 0;i < 2 * N;i++) {
		a = ab[i].first;
		b = ab[i].second;
		if (b) {
			S.insert(a);
		}
		else{
			if (S.empty()) {
				continue;
			}
			auto c = S.upper_bound(a);
			if (c != S.begin()) {
				c--;
				S.erase(c);
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
  N = int(input())
  A = [list(map(int, input().split())) for _ in range(N)]
  dp = [0]*(1<<N)
  dp[0] = 0
  for i in range(2,N+1):
    S = (1 << i) - 1
    while S < (1 << N):
      for k in range(N):
        if S>>k & 1:
          break
      dp[S] = dp[S-(1<<k)]
      for j in range(k+1,N):
        if S>>j & 1:
          dp[S] += A[k][j]
      x = S & -S; y = S + x
      S = ((S & ~y) // x >> 1) | y
  for i in range(2,N+1):
    S = (1 << i) - 1
    while S < (1 << N):
      T = (S-1)&S
      while T>0:
        dp[S] = max(dp[S],dp[T]+dp[S-T])
        T = (T-1)&S
      x = S & -S; y = S + x
      S = ((S & ~y) // x >> 1) | y
  ans = dp[-1]
  return ans
print(solve())

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

ll y(ll x) {
  switch (x % 4) {
    case 0:
      return x;
    case 1:
      return 1;
    case 2:
      return x + 1;
    default:
      return 0;
  }
}

int main() {
  in(ll, a, b);
  out(y(b) ^ y(a - 1));
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define dd double
#define f0(i, n) for(int i = 0; i < n; i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define f1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second





int main() {


	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif


//ios_base& scientific (ios_base& str);
	int n, k;
	cin >> n >> k;

	int h[n + 1];
	vector<int>dp(n + 1, INT_MAX);

	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}

	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);

	for (int i = 3; i <= n; i++) {

		for (int j = i - 1; j >= max(1, i - k); j--) {

			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n] << endl;




	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    ll x;
    cin >> x;
    ll res = 0;
    res += x / 500 * 1000;
    x %= 500;
    res += x / 5 * 5;
    cout << res << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
int main()
{
	ll a,b,n;
	cin>>n>>a>>b;
	cout<<n/(a+b)*a+(n%(a+b)>=a?a:n%(a+b));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

ll dp[110][10];

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int W = w;
    --w;
    dp[0][0] = 1;
    rep(i, h) {
        rep(mask, 1<<w) {
            bool f = true;
            rep(j, w-1) if((mask&(1<<j))&&(mask&(1<<(j+1)))) f= false;
            if(!f) continue;
            rep(j, W) {
                if(j > 0 && (mask&(1<<(j-1)))) {
                    (dp[i+1][j-1] += dp[i][j]) %= MOD;
                }
                else if(mask&(1<<j)) {
                    (dp[i+1][j+1] += dp[i][j]) %= MOD;
                }
                else {
                    (dp[i+1][j] += dp[i][j]) %= MOD;
                }
            }
        }
    }
    cout << dp[h][k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, w int
	fmt.Scan(&n, &w)
	items := make([]Item, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&items[i].Weight, &items[i].Value)
	}
	dp := make([][]int, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]int, w + 1)
	}
	first := items[0]
	for i := 0; i < w + 1; i++ {
		if i >= first.Weight {
			dp[0][i] = first.Value
		}
	}
	for i := 1; i < n; i++ {
		item := items[i]
		for j := 0; j < w + 1; j++ {
			if j >= item.Weight {
				dp[i][j] = max(dp[i - 1][j - item.Weight] + item.Value, dp[i - 1][j])
			} else {
				dp[i][j] = dp[i - 1][j]
			}
		}
	}
	fmt.Println(dp[n - 1][w])
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

type Item struct {
	Weight int
	Value int
}


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

int main(void) {
    int R, C, input, tmpSum;
    cin >> R >> C;

    vector<int> lastLine(C+1, 0);
    for(int i=0; i < R; i++) {
        tmpSum = 0;
        for(int j=0; j < C; j++) {
            cin >> input;
            cout << input << " ";
            tmpSum += input;
            lastLine[j] += input;
        }
        cout << tmpSum << endl;
        lastLine[C] += tmpSum;
    }
    for(int i=0; i < C; i++) {
        cout << lastLine[i] << " ";
    }
    cout << lastLine[C] << endl;

    return 0;
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//a???????????????
		int a = sc.nextInt();
		//b???????????????
		int b = sc.nextInt();
		//?????¶???
		if( a < b){
			System.out.println("a < b");
		//a??????b???????????§???????????°??¨???
		}else if(b < a){
			System.out.println("a > b");
		//a??????b??????????°????????????°??¨???
		}else if(a == b){
		//a??¨b?????????????????°??¨???
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26208
n,t,s,i,j,k[999][25];
main() {
	for(;scanf("%d",&n)*n;){
		memset(k,0,99900);
		for(i=0;i<n;i++){
			scanf("%d%d",&t,&s);
			k[s][i]=t;
		}
		n=0;t=0;
		for(i=0;i<999;i++){
			for(j=25;j--;){
				t+=k[i][j];
				n|=t>i;
			}
		}
		puts(n?"No":"Yes");
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>

using namespace std;
typedef long long LL;

int main() {
    LL A, B, N;
    cin >> A >> B >> N;
    if (N <= B - 1) {
        cout << floor(A * N / B) - A * floor(N / B) << endl;
    } else {
        cout << floor(A * (B - 1) / B) - A * floor((B - 1) / B) << endl;
    }
  	return 0;
}

Measured memory_bytes: 3764
function seach(y,x){
   if(yx[y][x]=="*")return 0;
   var dy=[-1,-1,0];
   var dx=[-1,0,-1];
   var min=n;
   for(var i=0;i<3;i++){
      var yy=y+dy[i];
      var xx=x+dx[i];
      if(yy<0 || yy>=n || xx<0 || xx>=n)return 1;
      min=Math.min(min,yx[yy][xx]);
   }
   return min+1;
}
  
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var max=0;
   var yx=[];
   for(var i=0;i<n;i++){
      var str=Arr.shift();
      yx.push(str.split(""));
   }
   for(var y=0;y<n;y++){
      for(var x=0;x<n;x++){
         yx[y][x]=seach(y,x);
         max=Math.max(max,yx[y][x]);
      }
   }
   console.log(max);
}

Measured memory_bytes: 69308
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout<<s,0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[]{ -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[]{ 0, 1, 1, 1, 0, -1, -1, -1 };
void run() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}

int main() {
	run();
	int n; cin >> n;
	vector<ll> sum(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> sum[i];
		sum[i] += sum[i - 1];
	}
	ll mn = sum[n];
	for (int i = 1; i <= n; i++) {
		ll  dif = abs(sum[n] - sum[i] - sum[i]);
		mn = min(mn, dif);
	}
	cout << mn;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include<numeric>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

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

int main(){
    int n; cin >> n;
    vector<int> d;
    rep(i, n){
        int ds; cin >> ds;
        d.push_back(ds);
    }

    int rec=0;
    rep(i, n){
        rep(j, n){
            rec+=d.at(i)*d.at(j);
        }
    }
    rep(i, n){
        rec-=d[i]*d[i];
    }
    out(rec/2);

}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 2e5+1;
int n, D, A, R[N];
long psum[N + 1];
pii a[N];

int main()
{
  fastio;
  cin >> n >> D >> A;
  for (int i = 1; i <= n; i++){
    cin >> a[i].first >> a[i].second;
    a[i].second = (a[i].second + A - 1) / A;
  }
  sort(a + 1, a + 1 + n);
  int ptr = 1;
  for (int i = 1; i <= n; i++){
    while (ptr <= n && a[ptr].first - a[i].first <= 2 * D) ptr++;
    R[i] = ptr;
  }
  long res = 0;
  for (int i = 1; i <= n; i++){
    psum[i] += psum[i - 1];
    long cur = max(0ll, psum[i] + a[i].second);
    res += cur; psum[i] -= cur; psum[R[i]] += cur;
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    n--;
    ll diff = b - a;
    bool ok = false;
    for (int i = 0; i <= n; ++i) {
        ll mini = -i * d + (n - i) * c;
        ll maxi = -i * c + (n - i) * d;
        if (mini <= diff && diff <= maxi) {
            ok = true;
            break;
        }
    }
    if (ok)
        cout << "YES"
             << "\n";
    else
        cout << "NO"
             << "\n";
    return 0;
}

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	int a;
	string s;
	cin >> a;
	cin >> s;

	if (a >= 3200) cout << s << endl;
	else cout <<  "red" << endl;

	return 0;
}


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

int main(void){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  
  if(0<=b && 0<=d){
    if(a*c<b*d)cout<<b*d<<endl;
    else cout<<a*c<<endl;
  }else if(0<=a && d<=0){
    cout<<a*d<<endl; 
  }else if(b<=0 && 0<=c){
    cout<<b*c<<endl;
  }else if((b<=0 && d<=0) || (a*b<=0 && d<=0) || (c*d<=0 && b<=0)){
    cout<<a*c<<endl; 
  }
  
  return 0;
  
}

Measured memory_bytes: 3540
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <queue>

#include <cmath>
#include <cstdio>

using namespace std;


int main(int argc, char **argv){
	long N, K;
	cin >> N >> K;
	N += 1; //0にろうそくを１個立てる
	K += 1;
	vector<long> x;
	int start = N-1;
	for (int i = 0; i < N-1; ++i){
		long xi;
		cin >> xi;
		if (xi>0 && start == N-1){
			start = i;
			x.push_back(0);
		}
		x.push_back(xi);
	}
	if (start == N-1){ x.push_back(0); }

	long long cost = LLONG_MAX;
	for (long left=max(start-(K-1),0l);left<=start; ++left){
		int right = left + K - 1;
		if (right >= N){ break; }
		long labs = abs(x[left]);
		long rabs = abs(x[right]);
		cost = min(cost, 2ll * min(labs, rabs) + max(labs, rabs));
	}
	
	cout << cost << endl;

	return 0;
}


Measured memory_bytes: 1400
import java.util.*;

class Main{
	public static int mod=1000000007;

	public static long modpow(long n,long p){
		if(p==0)
			return 1;
		if(p%2==1)
			return n*modpow(n,p-1)%mod;
		long d=modpow(n,p/2);
		return d*d%mod;
	}

	public static long modpow(long n){
		return modpow(n,mod-2);
	}

	public static long nCr(long n,long r){
		if(n-r<r)
			return nCr(n,n-r);
		long res=1;
		for(long i=n-r+1;i<=n;++i){
			res*=i;
			res%=mod;
		}
		for(long i=2;i<=r;++i){
			res*=modpow(i,mod-2);
			res%=mod;
		}
		return res;
	}

	public static void main(String[] $){
		final Scanner s=new Scanner(System.in);
		final int n=s.nextInt();
		final int a=s.nextInt();
		final int b=s.nextInt();

		System.out.println((modpow(2,n)+mod*2-1-nCr(n,a)-nCr(n,b))%mod);
	}
}


Measured memory_bytes: 23124
#include <stdio.h>

/* Macro Definition */
#define MAX 200000

/* Prototype Declaration */
void merge(int *, int, int, int);
void mergeSort(int *,int, int);

/* Grobal Variable */
int S[MAX], L[(MAX/2) + 1], R[(MAX/2) + 1], n;
long long count = 0;

int main() {
  int i;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &S[i]);

  mergeSort(S, 0, n);

  printf("%lld\n", count);

  return 0;
}

void merge(int *S, int left, int mid, int right) {
  int i, j = 0, k, n1, n2;
  n1 = mid - left;
  n2 = right - mid;

  for ( i = 0; i < n1; i++ ) L[i] = S[i+left];
  for ( i = 0; i < n2; i++ ) R[i] = S[i+mid];

  L[n1] = 1000000500;
  R[n2] = 1000000500;

  i = 0;

  for ( k = left; k < right; k++ ) {
    if ( L[i] <= R[j] ) {
      S[k] = L[i];
      i++;
    }else {
      count += (n1 - i);
      S[k] = R[j];
      j++;
    }
  }


}

void mergeSort(int *S, int left, int right) {
  int mid;
  
  if( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(S, left, mid);
    mergeSort(S, mid, right);
    merge(S, left, mid, right);
  }

}

Measured memory_bytes: 2156
#include<iostream>
#include<stdio.h>

using namespace std;

int main() {
	int H,W;

	while (1) {

		cin >> H >> W;

		if (H == 0 && W == 0) {
			return 0;
		}

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {

				cout << '#';
			}
			cout << endl;
		}
		cout << endl;

	}
	return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define mz 998244353
#define pq priority_queue
using namespace std;

int h[100005];
bool life[100005];

int main()
{
    int n,m,a,b;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&h[i]);
    while(m--)
    {
        scanf("%d%d",&a,&b);
        if(h[a]>=h[b])
            life[b]=1;
        if(h[a]<=h[b])
            life[a]=1;
    }
    m=0;
    for(int i=1;i<=n;i++)
    {
        if(!life[i])
            m++;
    }
    printf("%d\n",m);
    return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    int a, b;
    cin >> a >> b;

    if(b * 2 > a)
        cout << "0";
    else
        cout << a - (b * 2);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000000

int main(){
  string S;
  cin>>S;
  if(S.size()==2){
    cout<<S<<endl;
  }else{
    reverse(S.begin(),S.end());
    cout<<S<<endl;
  }
}


Measured memory_bytes: 3596
/*
Hanit Banga
*/

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e8 + 5;

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	if (a == b and b == c)
	{
		if (a % 2)
			cout << 0;

		else
			cout << -1;

		return 0;
	}

	int ans = 0;
	for (ans = 0; ans < N; ++ans)
	{
		if (a % 2 or b % 2 or c % 2)
			break;

		int temp = a;
		a = (b + c) / 2;
		int temp2 = b;
		b = (temp + c) / 2;
		c = (temp + temp2) / 2;
	}

	if (a % 2 or b % 2 or c % 2)
		cout << ans;

	else
		cout << -1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(li i=0;i<n;i++)
#define li long long int
#define ll long long int
#define pb push_back
#define all(v) sort(v.begin(),v.end())
const int N = 40043;
const ll mod = 1e9 + 7;
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define s second
int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    return (a*b)/gcd(a,b);
}
li pow(li a,li b,li mo)
{
    if(a==0)
    return 1;
    li u=pow(a,b/2,mo);
    u=(u%mod*u%mod)%mo;
    if(b%2==1)
    u=(u%mod*a%mod)%mod;
    return u;
}
ll power(ll a,ll b)
{
    ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
 
li xx,yy,dd;
void equation(li a,li b)
{
    if(b==0)
    {
        xx=1;
        yy=0;
        dd=a;
    }
    else
    {
        equation(b,a%b);
        li temp=xx;
        xx=yy;
        yy=temp-(a/b)*yy;
    }
}
li inverse(li a,li m)
{
    equation(a,m);
    return(xx%m+m)%m;
}
bool compare(const char &i, char &j)
{
    
    return i > j;
    
}
void solve()
{
    char a;
    cin>>a;
    if(a>='a' && a<='z')
    cout<<'a';
    else
    cout<<'A';
}
int main()
{
    li t;
    t=1;
    while(t--)
    solve(),cout<<endl;
    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define inf (1<<30)
bool prime(int x){
	if(x<2)return 0;
	for(int i=2;i*i<=x;i++)if(x%i==0)return 0;
	return 1;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	cout<<s;
	if(s[s.size()-1]=='s')cout<<"es";
	else cout<<'s'; 
	return 0;
}


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

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

    vector<string> vec(N);
    for(int i=0; i<N; i++){
        cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end());

    for(int i=0; i<N; i++){
        cout << vec.at(i);
    }
}


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

int main(){
  string s;cin>>s;
  int p=0;
  map<char,int> dir;
  for(int i=0;i<s.size();i++){
    dir[s[i]]=1;
  }
  cout<<(dir['S']==dir['N'] && dir['W']==dir['E'] ? "Yes" : "No")<<endl;
  return 0;
  


}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 110000
ll MOD=1e9+7;

main(){
    int n=in(),k=in(),q=in();
    vec v(n+1);
    rep(i,q){
        v[in()]++;
    }
    rep2(i,1,n){
        if(k-q+v[i]>0)cout<<"Yes"<<endl;
        else cout<<"No\n";
    }
}

Measured memory_bytes: 1024