akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)

int main()
{
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n,m; cin >> n >> m;
  vector<int> d(n+1, -1);
  d[0]=1;
  d[1]=1;
  rep(i,m){
    int temp; cin >> temp;
    d[temp]=0;
  }
  rep(i,n-1){
    if(d[i+2]!=0) d[i+2]=(d[i+1]+d[i])%mod;
  }
  rep(i,n+1){
    // debug(d[i]);
  }
  cout << d[n] << endl;
  return 0;
}


Measured memory_bytes: 640
#include <map>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int N, W, H, Q, x, y, c[109], xa[109][109], ya[109][109], xb[109][109], yb[109][109]; string s[109], t[109][109], tp;
int main() {
	while (cin >> N, N) {
		cin >> W >> H;
		for (int i = 0; i < N; i++) {
			cin >> s[i] >> c[i];
			for (int j = 0; j < c[i]; j++) {
				cin >> xa[i][j] >> ya[i][j] >> xb[i][j] >> yb[i][j] >> t[i][j];
			}
		}
		cin >> Q;
		vector<int> res; res.push_back(0);
		int pos = 0;
		for (int i = 0; i < Q; i++) {
			cin >> tp;
			if (tp == "click") {
				cin >> x >> y;
				for (int j = 0; j < c[res[pos]]; j++) {
					if (xa[res[pos]][j] <= x && x <= xb[res[pos]][j] && ya[res[pos]][j] <= y && y <= yb[res[pos]][j]) {
						int ptr = -1;
						for (int k = 0; k < N; k++) {
							if (s[k] == t[res[pos]][j]) ptr = k;
						}
						res.resize(pos + 2);
						res[++pos] = ptr;
						break;
					}
				}
			}
			if (tp == "show") cout << s[res[pos]] << endl;
			if (tp == "forward" && pos + 1 != res.size()) pos++;
			if (tp == "back" && pos != 0) pos--;
		}
	}
	return 0;
}

Measured memory_bytes: 3264
import sys

def main():
  input = sys.stdin.readline
  S = [int(c) for c in input().strip()]
  n1 = 0
  n0 = 0
  for i in S:
    if i == 0:
      n0 += 1
    else:
      n1 += 1
  print(min(n1, n0) * 2)


if __name__ == '__main__':
  main()

Measured memory_bytes: 3956
from math import factorial
from itertools import permutations
n=int(input())
a=[]
ansp="a"
ansq="a"
p=[int(x) for x in input().split()]
q=[int(x) for x in input().split()]
for v in permutations(p, n):
    a.append(list(v))
a.sort()
for i in range(len(a)):
    if a[i]==p:
        ansp=i
    if a[i]==q:
        ansq=i
    if ansq!="a" and ansp!="a":
        break
print(max(ansp,ansq)-min(ansp,ansq))

Measured memory_bytes: 10484
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

int64_t mod = 998244353 ;

vector<int> getprime(int n){
    vector<int> p(0) ;
    vector<bool> table(n+1,0) ;
    for (int i = 2; i <= n; i++)
    {
        if (table.at(i) == 0)
        {
            p.push_back(i) ;
            for (size_t j = 2; j < n/i ; j++)
            {
                table.at(i*j) = 1 ;
            }
            
        }
        
    }
    return p ;
}

int main(){
    int64_t n ;
    cin >> n ;
    string c ;
    cin >> c ;
    int r = 0 ;
    for (int i = 0; i < n; i++)
    {
        if (c.at(i) == 'R')
        {
            r ++ ;
        }
        
    }
    int ans = 0 ;
    for (int i = 0; i < r; i++)
    {
        if (c.at(i) == 'W')
        {
            ans ++ ;
        }
        
    }
    cout << ans << endl ;
}

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

int ans;

int main() {
    ios::sync_with_stdio(false);

    int a, b, c, x;
    cin >> a >> b >> c >> x;

    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                    if (i*500 + j*100 + k * 50 == x)
                        ans++;
            }
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll 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');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,a[202020],b[1010101];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout); 
	cin>>n;
	fo(i,0,n){
		cin>>a[i];
		b[a[i]]++;
	}
	int ans=0;
	fo(i,0,n) {
		if(a[i]==1&&b[1]==1)ans++;
		if(b[a[i]]==1&&b[1]==0){
			int h=1;
			for(int j=2;j*j<=a[i];j++) if(a[i]%j==0&&(b[j]||b[a[i]/j])){h=0;break;}
			ans+=h;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8328
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int m=sc.nextInt();
        int k=sc.nextInt();
        int a[]=sc.nextIntArray(n);
        int b[]=sc.nextIntArray(m);
        long d[]=new long[m+1];
        d[1]=b[0];
        for (int i = 2; i < d.length; i++) {
			d[i]=d[i-1]+b[i-1];
		}
        long r=0,res,ret=0;
//        db(d);
        for (int i = 0; i <= a.length; i++) {
			if(i>=1)r+=a[i-1];
			res=k-r;
			if(res<0)break;
			int l=0,h=m+1,md=0;
			for (int j = 0; j < 50; j++) {
				md=(l+h)/2;
				if(res>=d[md]) {
					ret=max(i+md,ret);
					l=md;
				}else {
					h=md;
				}
			}
//			db(i,res,ret,d);
		}
        
        out.println(ret);
     	out.flush();
    }
        
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x,y,c;
	P(int  x, int y, int c) {
	  this.x=x;
	  this.y=y;
	  this.c=c;
	}
}

//
//class P implements Comparable<P>{
//	int x,c;long s;
//	P(int  x, int c, long s) {
//	  this.x=x;
//	  this.c=c;
//	  this.s=s;
//	}
//
//    public int compareTo(P p){
//        return Long.signum(s-p.s);
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

#define CO const
#define IN inline
typedef long long LL;
typedef long double LD;

template<class T> T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

int mod;
IN int add(int a,int b){
	return (a+=b)>=mod?a-mod:a;
}
IN int mul(int a,int b){
	return (LL)a*b%mod;
}
IN int fpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=mul(a,a))
		if(b&1) ans=mul(ans,a);
	return ans;
}

CO int N=3000+10;
int C[N][N],S[N][N],B[N];

int main(){
	int n=read<int>();read(mod);
	for(int i=0;i<=n;++i){
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;++j) C[i][j]=add(C[i-1][j-1],C[i-1][j]);
	}
	S[0][0]=1;
	for(int i=1;i<=n+1;++i)for(int j=1;j<=i;++j)
		S[i][j]=add(S[i-1][j-1],mul(j,S[i-1][j]));
	B[0]=1;
	for(int i=1;i<=n;++i){
		B[i]=B[i-1]<<1;
		if(B[i]>=mod-1) B[i]-=mod-1;
	}
	int ans=0;
	for(int i=0;i<=n;++i){
		int sum=0;
		for(int j=0;j<=i;++j) sum=add(sum,mul(S[i+1][j+1],fpow(2,(n-i)*j)));
		sum=mul(sum,mul(C[n][i],fpow(2,B[n-i])));
		ans=add(ans,i&1?mod-sum:sum);
	}
	printf("%d\n",ans);
	return 0;
}


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

int A, B;
int main(){
  cin >> A >> B;
  int mod = (A + B) % 3;
  if(mod == 0){
    cout << 3 << endl;
  }else if(mod == 1){
    cout << 2 << endl;
  }else{
    cout << 1 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    bool prime[10001];
    int n,ans;
    for(int i=3;i<10001;i+=2){
        prime[i]=true;
        prime[i+1]=false;
    }
    prime[0]=prime[1]=false;
    prime[2]=true;
    for(int i=3;i*i<10001;i+=2){
        while(!prime[i])i+=2;
        for(int j=i*i;j<10001;j+=i){
            prime[j]=false;
        }
    }
    while(scanf("%d",&n)!=EOF){
        ans=0;
        for(int i=1;i<=n;i++){
            if(prime[i]&&prime[n+1-i])ans++;
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 2632
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), K = sc.nextInt();
		for(int i = 0; i < N; i++) {
			int A = sc.nextInt();
		}
		System.out.println((N + K - 3) / (K - 1));
	}
}


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

int main(){
 int n;
 cin >> n;
 vector<tuple<string, int,int>> t(n);
 rep(i,n){
   string s;
   int point;
   cin >> s >> point;
   t[i]=make_tuple(s,-point,i+1);
 }
 sort(t.begin(),t.end());
 
 rep(i,n){
   string s;
   int point;
   int a;
   tie(s,point,a)=t[i];
   cout << a << endl;
 }
}

Measured memory_bytes: 3608
N = int(input())
S = input()

stoi = {'R':0, 'G':1, 'B':2}
itos = {1:'R', 2:'G', 3:'B'}
li = [[0] * N for _ in range(3)]
ans = 0

for ind, s in enumerate(S):
    if(ind == 0):
        li[stoi[s]][ind] = 1
    else:
        for i in range(3):
            li[i][ind] = li[i][ind - 1]
        li[stoi[s]][ind] += 1

for i in range(N):
    for j in range(i + 1, N):
        if(S[i] == S[j]):
            continue
        k = 2 * j - i
        kc = 6 - (stoi[S[i]] + stoi[S[j]] + 2)
        res = li[kc-1][-1] - li[kc-1][j]
        if(k < N and kc == stoi[S[k]] + 1):
            res -= 1
        ans += res

print(ans)

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

int main()
{
  long long int N, M;
  cin >> N >> M;
  unsigned long long int ans = 0;
  if (N == 1 && M == 1)
    ans = 1;
  else if (N == 1)
    ans = N * M - 2;
  else if (M == 1)
    ans = N * M - 2;
  else
    ans = N * M - (N * 2 + M * 2 - 4);
  cout << ans << endl;
}


Measured memory_bytes: 256
# coding:utf-8

import sys

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


q, h, s, d = LI()
n = I()

min_1 = min(4 * q, h * 2, s)
min_2 = min(2 * min_1, d)

print(n // 2 * min_2 + (n % 2) * min_1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

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()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL n;
  cin >> n;
  VVI pair(n, VI());
  REP(i, n) REP(j, n)
  {
    int a;
    cin >> a;
    if (a) pair[i].emplace_back(1<<j);
  }
  VLL dp(1<<n, 0);
  dp[0] = 1;
  bit_search(bit, n)
  {
    if (bit == (1<<n)-1) break;
    int ct = 0;
    REP(i, n) if (bit_check(bit, i)) ct++;
    REPx(x, pair[ct])
    {
      LL tmp = bit | x;
      if (tmp != bit)
      {
        dp[tmp] += dp[bit];
        dp[tmp] %= MOD;
      }
    }
  }
  cout << dp.back() << endl;

  return 0;
}

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

int main(void){
  int a,b;cin >> a >> b;
  int tou[1001];
  tou[0] = 1;
  for(int i=1;i<1000;++i)tou[i] = tou[i-1] + (i+1);
  for(int i=0;i<999;++i){
    if(tou[i+1]-b == tou[i]-a)cout << tou[i]-a << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<double> p(n);
    for(auto&& i : p){
        int a;
        cin >> a;
        i = 1. * a * (a + 1) / 2 / a;
    }
    vector<double> s(n + 1);
    partial_sum(begin(p), end(p), begin(s) + 1);
    double ans = 0;
    for(int i = 0; i + k <= n; i++){
        ans = max(ans, s[i + k] - s[i]);
    }
    cout << fixed << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 3328
// C - Green Bin
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;

int compare(const void* s1, const void* s2){
    return *(char*)s1 - *(char*)s2;
}

int scmp(const void* s1, const void* s2){
    return strcmp((char*)s1, (char*)s2);
}

int main(void){
    int n;
    ll ans=0, cnt=1;
    char s[100001][11];
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%s", s[i]);
        qsort(s[i], 10, sizeof(char), compare);
    }
    qsort(s, n, sizeof(s[0]), scmp);
    
    for(int i=0; i<n-1; i++){
        if(!strcmp(s[i], s[i+1]))cnt++;
        else{
            ans+=cnt*(cnt-1)/2;
            cnt=1;
        }
    }
    ans+=cnt*(cnt-1)/2;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2300
_ = gets
arr = gets.chomp.split(' ').map(&:to_i)
plus = 0
sum = 0
arr.each_with_index do |a, i|
  sum += a
  if i % 2 == 0
    if sum == 0
      sum += 1
      plus += 1
    elsif sum < 0
      tmp = sum.abs + 1
      sum += tmp
      plus += tmp
    end
  else
    if sum == 0
      sum -= 1
      plus += 1
    elsif sum > 0
      tmp = sum.abs + 1
      sum -= tmp
      plus += tmp
    end
  end
end

minus = 0
sum = 0
arr.each_with_index do |a, i|
  sum += a
  if i % 2 != 0
    if sum == 0
      sum += 1
      minus += 1
    elsif sum < 0
      tmp = sum.abs + 1
      sum += tmp
      minus += tmp
    end
  else
    if sum == 0
      sum -= 1
      minus += 1
    elsif sum > 0
      tmp = sum.abs + 1
      sum -= tmp
      minus += tmp
    end
  end
end

puts [plus, minus].min

Measured memory_bytes: 9612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll a[n+2];
    for(int i=0;i<n;i++)cin>>a[i];
    ll cnt[n+2]={0};
    cnt[0]=a[0];
    for(int i=1;i<n;i++)cnt[i]=cnt[i-1]+a[i];
    ll sum=0;
    ll res=cnt[n-1];
    for(int i=0;i<n-1;i++){
        if(i==0)sum+=(cnt[i]*((res-cnt[i])%mod))%mod;
        else sum+=(((cnt[i]-cnt[i-1])%mod)*((res-cnt[i])%mod))%mod;
    }
    cout<<sum%mod<<endl;
}


Measured memory_bytes: 6704
#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
using namespace std;
typedef long long ll;
const int maxn = 210000;
int main()
{
	int n, m;
	cin >> n >> m;
	m = m * 2 + 1;
	n% m ? n = n / m + 1 : n = n / m;
	cout << n;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
ll MOD=1e9+7;

struct seg{
    ll l,r;
};
bool comp1(seg p,seg q){
    if(p.l==q.l) return p.r<q.r;
    return p.l<q.l;
}
bool comp2(seg p,seg q){
    if(p.r==q.r) return p.l<q.l;
    return p.r<q.r;
}
int main(){
    int n;cin>>n;
    vector<seg> s(n);
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        s[i]=seg{a,b};
    }
    if(n%2==1){
        sort(s.begin(),s.end(),comp1);
        int ml=s[n/2].l;
        sort(s.begin(),s.end(),comp2);
        int mr=s[n/2].r;
        cout<<max(mr-ml+1,0)<<endl;
        return 0;
    }else{
        sort(s.begin(),s.end(),comp1);
        int ml=s[n/2-1].l+s[n/2].l;
        sort(s.begin(),s.end(),comp2);
        int mr=s[n/2-1].r+s[n/2].r;
        cout<<max(mr-ml+1,0)<<endl;
        return 0;
    }
}

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

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;

public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF 1000000000
#define int ll
#define PI (acos(-1))
const ll mod = 1000000007;

string l;
modint<mod> dp[100010][2];

signed main() {
    cin >> l;

    // 初期条件
    dp[0][1] = 1;

    for (int i = 0; i < l.size(); i++) {
        int n = l[i] - '0';
        if (n == 0) {
            dp[i + 1][0] += dp[i][0] * 3;
            dp[i + 1][1] += dp[i][1];
        } else {
            dp[i + 1][0] += dp[i][0] * 3;
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][1] += dp[i][1] * 2;
        }
    }

    modint<mod> ans = dp[l.size()][0] + dp[l.size()][1];

    cout << ans.a << endl;
}

// dp[i][is_smaller] = i文字目まで見たときの場合の数
// 求めるもの: dp[n][0] + dp[n][1]
// 遷移(a+b = a xor bを満たすように)
// if n==0
// is_smaller → is_smaller      0-1 dp[i+1][0] += dp[i][0]*3
// !is_smaller → is_smaller     なし
// !is_smaller → !is_smaller    n dp[i+1][1] += dp[i][1]
// else if n==1
// is_smaller → is_smaller      0-1 dp[i+1][0] += dp[i][0]*3
// !is_smaller → is_smaller     0 dp[i+1][0] += dp[i][1]
// !is_smaller → !is_smaller    n dp[i+1][1] += dp[i][1]*2
// 桁DP

Measured memory_bytes: 2048
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 10000000
#define MAX_V 1001
#define MAX_E 2001


struct edge{
	long from,to,cost;
};
edge es[MAX_E];
long d[MAX_V];
int V,E;

int belman(int s){
	fill(d,d+V,INF);
	d[s]=0;
	int cnt=0;
	while(1){
		bool update=false;
		REP(i,E){
			edge e=es[i];
			if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
		}
		if(!update)break;
		if(cnt==V-1)return 1;
		cnt++;
	}
	return 0;
}

int main(){
	int r;
	cin>>V>>E>>r;
	REP(i,E)cin>>es[i].from>>es[i].to>>es[i].cost;
	
	if(belman(r)){
		cout<<"NEGATIVE CYCLE"<<endl;
		return 0;
	}
	REP(i,V){
		if(d[i]<INF)cout<<d[i]<<endl;
		else cout<<"INF"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    int a=0;
    rep(i,n) a^=p[i];
    rep(i,n){
        int ans=a^p[i];
        cout<<ans<<" ";
    }
    cout<<endl;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

int n;
bool check(int x){
    if(x*(x+1)>=2*n) return true;
    else return false;
}

signed main(){start();
    cin>>n;

    int low=0,high=10000000;
    while(high-low>1){
        int mid=(low+high)/2;
        if(check(mid)) high=mid;
        else low=mid;
    }
    REP(i,1,high+1) if(i!=high*(high+1)/2-n) cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())

P = list(map(int, input().split()))

dice = [0] * 1001
for i in range(1,1001):
    dice[i] = dice[i-1] + i

ans = 0
tmp = 0
for i in range(N):
    if i < K-1:
        tmp += dice[P[i]] / P[i]
        #print(i, tmp)
    elif i == K-1:
        tmp += dice[P[i]] / P[i]
        #print(i, tmp)
        ans = max(ans, tmp)
    else:
        tmp += dice[P[i]] / P[i]
        tmp -= dice[P[i-K]] / P[i-K]
        #print(i, tmp)
        ans = max(ans, tmp)
        
        

print(ans)


Measured memory_bytes: 25604
k = gets.to_i
 
dp = Array.new(k,46)
dp[1] = 1
deq = [1]
 
v = 0
loop  do
  
  break if deq[0] == 0 
  
  v = deq[0]
  
  deq.shift
  u = ( v * 10 ) % k
  if dp[u] > dp[v] then
    dp[u] = dp[v]
    deq.unshift(u)
  end
  
  u = ( v + 1 ) % k
  if dp[u] > dp[v] + 1 then
    dp[u] = dp[v] + 1
    deq.push(u)
  end
end
 
puts dp[0]

Measured memory_bytes: 3144
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
// clang-format on

int A[3][3];
bool checked[3][3];
bool c() {
  REP(i, 3) {
    bool f = true;
    REP(j, 3) {
      if (!checked[i][j]) {
        f = false;
        break;
      }
    }
    if (f) return true;
  }
  REP(i, 3) {
    bool f = true;
    REP(j, 3) {
      if (!checked[j][i]) {
        f = false;
        break;
      }
    }
    if (f) return true;
  }
  bool f = true;
  REP(i, 3) f &= checked[i][i];
  if (f) return true;
  if (checked[0][2] && checked[1][1] && checked[2][0]) return true;
  return false;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  REP(i, 3) REP(j, 3) cin >> A[i][j];

  int N;
  cin >> N;
  vector<int> b(N);

  REP(i, 3) REP(j, 3) checked[i][j] = false;

  REP(i, N) {
    cin >> b[i];
    REP(j, 3) REP(k, 3) {
      if (A[j][k] == b[i]) checked[j][k] = true;
    }
  }

  cout << (c() ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
import math
N,num = map(int, input().split())
list = [int(i) for i in input().split()]
if N >= num:
    print(0)
else:
    
    list.sort()
    list2 = []
    for i in range(0,num-1):
        list2.append(abs(list[i+1] - list[i]))
    list2.sort()
    print(sum(list2[:num-N]))


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

#define REP(i, N) for(int i = 0; i < N; i++) 

const int N = 1000 * 1000;
int isPrime[1000 * 1000];

int main() {
  REP(i, N) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  
  for(int i = 0; i < N; i++)
    if( isPrime[i] ) {
      for(int j = i + i; j < N; j += i)
        isPrime[j] = false;
    }

  int n;
  while( cin >> n) {
    int cnt = 0;
    for(int i = 0; i <= n; i++) if( isPrime[i] ) cnt++;
    cout << cnt << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>

typedef long long ll;

using namespace std;

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

	bool flag = false;

	flag = false;
	for (int i = 0; i < 4; ++i)
	{
		if (a[i] == 1)
		{
			flag = true;
		}
	}
	if (!flag)
	{
		cout << "NO" << endl;
		return 0;
	}

	flag = false;
	for (int i = 0; i < 4; ++i)
	{
		if (a[i] == 9)
		{
			flag = true;
		}
	}
	if (!flag)
	{
		cout << "NO" << endl;
		return 0;
	}

	flag = false;
	for (int i = 0; i < 4; ++i)
	{
		if (a[i] == 7)
		{
			flag = true;
		}
	}
	if (!flag)
	{
		cout << "NO" << endl;
		return 0;
	}

	flag = false;
	for (int i = 0; i < 4; ++i)
	{
		if (a[i] == 4)
		{
			flag = true;
		}
	}
	if (!flag)
	{
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;
	return 0;

}

Measured memory_bytes: 256
S = input()
T = input()
Q = int(input())
ABCD = [list(map(int,input().split())) for _ in [0]*Q]

Si = [0]*(len(S)+1)
for i,s in enumerate(S,1):
    if s=="A": Si[i] = Si[i-1] + 1
    else: Si[i] = Si[i-1] + 2
    Si[i] %= 3
Ti = [0]*(len(T)+1)
for i,t in enumerate(T,1):
    if t=="A": Ti[i] = Ti[i-1] + 1
    else: Ti[i] = Ti[i-1] + 2
    Ti[i] %= 3
for a,b,c,d in ABCD:
    print("YES" if ((Si[b]-Si[a-1])%3 == (Ti[d]-Ti[c-1])%3) else "NO" )

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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

string s, t;
vector<int> a(26);
vector<int> b(26);
vector<int> A(26);
vector<int> B(26);
void init()
{
	cin >> s >> t;
	int cnt = 1;
	A.resize(s.length());
	B.resize(t.length());
	rep(i, s.length()) {
		int tt = s[i] - 'a';
		if (a[tt] == 0) {
			a[tt] = cnt++;
		}
		A[i] = a[tt];
	}
	cnt = 1;
	rep(i, t.length()) {
		int tt = t[i] - 'a';
		if (b[tt] == 0) {
			b[tt] = cnt++;
		}
		B[i] = b[tt];
	}
}

void solve()
{
	rep(i, s.length()) {
		if (A[i] != B[i]) {
			PRINT(0);
			return;
		}
	}
	PRINT(1);
}


Measured memory_bytes: 2312
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string s ;
    cin >> s ;
    size_t n = s.length();
    string t="\0";
    int count = 0 ;
    for(int i = 0 ; i < n  ; i++ ){
      if(s[i] == '0'){
         t += '0' ;
         count ++ ;
         
      }else if(s[i] == '1'){
         t += '1' ;
         count ++ ;
      }else{
          if(count != 0){
         t.erase(count-1 ,1) ;
         count -- ;
          }
        
      }
    }

    cout << t << endl;
    return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int d;
  int num;
  unordered_map<int,int> m;
  rep(i,n) m[i+1]=0;
  rep(i,k){
    cin >> d;
    rep(j,d){
      cin >> num;
      m[num]++;
    }
  }
  
  int res = 0;
  rep(i,n){
    if(m[i+1]==0) res++;
  }
  
  cout << res;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll a[252521];
ll s[252521];

int main(){
  scanf("%d", &n);
  REP(i,n)scanf("%lld",a+i);
  s[0] = 0;
  REP(i,n)s[i+1] = s[i] + a[i];
  ll ans = 1ll<<60;
  FOR(i,2,n-1){
    ll asum = s[i];
    ll bsum = s[n] - s[i];
    int aid = upper_bound(s,s+n,asum/2ll)-s-1;
    int bid = upper_bound(s,s+n,asum+bsum/2ll)-s-1;
    vector<pll> av, bv;
    if(aid>0 && i-aid>0)av.push_back(pll(s[aid]-s[0],s[i]-s[aid]));
    aid++;
    if(aid>0 && i-aid>0)av.push_back(pll(s[aid]-s[0],s[i]-s[aid]));
    aid++;
    if(aid>0 && i-aid>0)av.push_back(pll(s[aid]-s[0],s[i]-s[aid]));
    if(bid-i>0 && n-bid>0)bv.push_back(pll(s[bid]-s[i],s[n]-s[bid]));
    bid++;
    if(bid-i>0 && n-bid>0)bv.push_back(pll(s[bid]-s[i],s[n]-s[bid]));
    bid++;
    if(bid-i>0 && n-bid>0)bv.push_back(pll(s[bid]-s[i],s[n]-s[bid]));
    for(pll p : av)for(pll q : bv){
      ll mx = max({p.first, p.second, q.first, q.second});
      ll mn = min({p.first, p.second, q.first, q.second});
      CHMIN(ans, mx-mn);
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3328
def gen_d_prim(n):
    D = [0,0] + [-1] * (n-1)
    for i in range(2, n+1):
        if D[i] > 0: continue
        for j in range(i, n+1, i): D[j] = i
    return D

def is_pairwise(A):
    D = gen_d_prim(10**6)
    past = set()
    for a in A:
        now = set()
        while a != 1:
            # 素数 D[a]: 今回は未済 & 過去で済
            if not D[a] in now and D[a] in past: return False
            now.add(D[a])
            past.add(D[a])
            a //= D[a]
    return True

def gcd_all(A):
    from math import gcd
    g = 0
    for a in A: g = gcd(g, a)
    return g

def solve():
    if is_pairwise(A): return 0
    if gcd_all(A) == 1: return 1
    return 2

n = int(input())
A = [*map(int, input().split())]
print(['pairwise','setwise','not'][solve()], 'coprime')


Measured memory_bytes: 126868
#include<iostream>
#include<algorithm>
#include<climits>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const double RATE=380000.;
int n;
double x[11];
string u[11];
int main(){
  cin>>n;
  rep(i,n){
    cin>>x[i]>>u[i];
  }
  double res=0;
  rep(i,n){
    if(u[i]=="JPY"){
      res+=x[i];
    }
    else{
      res+=RATE*x[i];
    }
  }
  prin(res);

  

  return 0;
}


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

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

    bool ok = true;
    while(ok){
        ok = false;
        for(int j=n-1;j>0;j--){
            if(a[j] < a[j-1]){
                swap(a[j], a[j-1]);
                cnt++;
                ok = true;
            }
        }
    }

    for(int i=0;i<n;i++){
        cout << a[i];
        if(i != n-1)cout << " ";
        else cout << endl;
    }
    cout << cnt << endl;

    return 0;
}


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

int main()
{
	ios::sync_with_stdio(false);

	ll n, a, b, c , d;
	cin >> n >> a >> b >> c >> d;
	for (int i=0; i<=n-1; i++)
	{
		ll mn = a - d * i;
		ll mx = a - c * i;
		ll MN = b - d * (n - 1 - i);
		ll MX = b - c * (n - 1 - i);
		if (!(mx < MN || MX < mn))
		{
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define abs(x) ((x) < 0 ? (-(x)) : (x))
#define rep(i,a,m) for((i) = (a) ; (i) < (m) ; ++(i))
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
#define PI 3.14159265

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t,T;
    int K;
	cin >> T;	
    cin >> K;
    vl vec(T);
    vl A(T,1e9);
	for(t = 1; t <= T; ++ t){
        cin >> vec[t-1];
	}
    A[0] = 0LL;
    ll x;
    ll y;
    for(int i = 1; i < T; ++ i) {
        y = 1e9;
        for(int j = i - 1; j >= 0 && j >= i - K; -- j) {
            x = A[j] + abs(vec[i] - vec[j]);
            y = min(x,y);
        }
        A[i] = y;
    }
    cout << A[T-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <bitset>

#define Z class
#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
using pll = pair<long long, long long>;

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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int A, P; cin >> A >> P;
    rep (i, A) {
        P += 3;
    }
    cout << P / 2 << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  string s = "",t = "";
  string a,b;
  cin >> a >> b;
  REP(i,stoi(b)) s += a;

  REP(i,stoi(a)) t += b;
  
  string ans = "w";
  REP(i, stoi(a) > stoi(b) ? stoi(b) : stoi(a)){
    if(s[i] < t[i]) {
      ans = s;
      break;
    }
    else if(s[i] > t[i]){
      ans = t;
      break;
    }
  }
  if(ans == "w"){
    if(s.length() > t.length()) ans = t;
    else ans = s;
  }
  cout << ans << endl;
  return 0;
}

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


void solver() {
  long long n, a, b;
  cin >> n >> a >> b;

  if (a == 0 && b == 0) {
    cout << 0 << "\n";
    return;
  }

  long long n_pair = (long long)(n / (a + b));
  long long rest = (long long)(n % (a + b));

  long long ans = n_pair * a;
  if (rest >= a) {
    ans = ans + a;
  } else {
    ans = ans + rest;
  }

  cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}//continue break
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<pii> vpii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
  
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        ll n;cin>>n;
        ll k;cin>>k;
        ll a[n];rep(i,n)cin>>a[i];
        ll lo=1,hi=1e9;
        ll ans=1;
        while(lo<=hi){
            ll m=(lo+hi)/2;
            ll f=0;ll cnt=0;
            rep(i,n){
                ll u=(a[i]+m-1)/m;u--;
                if(u<0)u=0;
                cnt+=u;
            }
            if(cnt<=k)f=1;
            if(f){
                hi=m-1;ans=m;
            }
            else{
                lo=m+1;
            }
        }
        cout<<ans<<endl;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  ll x,k,d;
  cin>>x>>k>>d;
  if(abs(x)/d>k){
    ll p=abs(x)-d*k;
    out(p);
  }else{
    ll p=abs(x)%d,q=d-abs(x)%d;
    if(((abs(x)-p)/d-k)%2==0) out(p);
    else out(q);
  }
}

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


Measured memory_bytes: 3584
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
main(){
    int N,a[100],mini = 10000000;
    cin >> N;
    for(int i = 0;i < N;i++)cin >> a[i];
    for(int i = -100;i <= 100;i++){
        int sum = 0;
        for(int j = 0;j < N;j++){
            sum += (a[j] - i)*(a[j] - i);
        }
        mini = min(mini,sum);
    }
    cout << mini << endl;
}   

Measured memory_bytes: 256