akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int a[100];
long long int b[100];
long long int c[100];
long long int f(long long int i,long long int amount)
{
	if(i>=n-1)
	return amount;
	if(c[i])
	{
		return f(i+1,amount%a[i] + (amount/a[i])*(a[i+1]));
	}
	else
	return f(i+1,amount);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	cin>>n;
	long long int i;
	for(i=0;i<n;i++)
	cin>>a[i];
	memset(b,-1,sizeof(b));
	b[n-1]=n;
	memset(c,0,sizeof(c));
	for(i=n-2;i>=0;i--)
	{
		b[i]=i+1;
		if(a[i+1]>=a[i])
		{
		  c[i]=c[i+1]+(a[i+1]-a[i]);
		  b[i]=b[i+1];
		}
		 //cout<<i<<" "<<b[i]<<" "<<c[i]<<endl;
	}
	cout<<f(0,1000)<<endl;
	return 0;
}



Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(void)
{
  int N;
  long long int luca[87]={2,1};

  cin >> N;
  
  for(int i=2;i<=N;i++)
    luca[i]=luca[i-1]+luca[i-2];

  cout << luca[N] << endl;

  return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vec{
    double x, y;
};
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;
}
template<class T>
T min(T a, T b)
{
    if (a < b) return a;
    return b;
}
template<class T>
T max(T a, T b)
{
    if (a > b) return a;
    return b;
}
using namespace std;
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);

    int N;
    ll ans = 0;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.rbegin(), A.rend());
    rep(i, N/ 2) {
        if (N - 1 >= 2*i + 1) ans += A[i];
        if (N - 1 >= 2*i + 2) ans += A[i+1];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4780
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append([b,c])

A = sorted(A)
BC = sorted(BC, key=lambda x:x[1], reverse=True)

a_itr = 0
bc_itr = 0
bc = BC[0]
while a_itr < N:
    if bc[0] == 0:
        bc_itr += 1
        if bc_itr < M:
            bc = BC[bc_itr]
        else:
            break
    else:
        if A[a_itr] < bc[1]:
            A[a_itr] = bc[1]
            a_itr += 1
            bc[0] -= 1
        else:
            break

print(sum(A))



Measured memory_bytes: 101120
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int main() {
	int a, b;
	cin >> a >> b;
	int n = b;
	int keta = 1;
	while (n >= 10) {
		n /= 10;
		keta++;
	}
	a = a*pow(10, keta) + b;
	for (int i = 0; i < 1000; i++) {
		if (i*i == a) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

using namespace std;

int main() {
  long long n;
  cin >> n;
  int res = 0;
  for (long long i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      ++cnt;
    }
    res += ((long long)sqrt(1 + (cnt << 3)) - 1) >> 1;
  }
  res += (n > 1);
  cout << res << '\n';
  return 0;
}


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

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}





fn main() {
    input! {
        xs: chars,
    }

    let n = xs.iter().filter(|&c| *c == 'x').count();
    let ans = if n < 8 {
        "YES"
    } else {
        "NO"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	set<int> water;
	for (int x = 0; x <= F; x += 100*A) {
		for (int y = x; y <= F; y += 100*B) {
			water.insert(y);
		}
	}
	set<int> suger;
	for (int x = 0; x <= F; x += C) {
		for (int y = x; y <= F; y += D) {
			suger.insert(y);
		}
	}
	long long r1 = 100*A, r2 = 0;
	for (int x : water) {
		int limit = min(F-x, x/100*E);
		auto it = suger.upper_bound(limit);
		-- it;
		long long rr1 = x + *it;
		long long rr2 = *it;
		//rr2 / rr1 > r2 / r1
		if (r1 * rr2 > rr1 * r2) {
			r1 = rr1;
			r2 = rr2;
		}
	}
	cout << r1 << " " << r2 << endl;
}


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

int main(){
    int n;
    char str[102];

    scanf("%d", &n);
    scanf("%s", str);
    
    if (strlen(str) <= n){
        printf("%s", str);
    }
    else{
        for (int i=0; i<n; i++){
            printf("%c", str[i]);
        }
        printf("...");
    }

    return 0;
}


Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  vector<ll> idx(n);
  rep(i,n) idx.at(A[i]-1)=i;

  ll ans=0;
  multiset<ll> s{-1,-1,n,n};
  rep(k,n,0,-1){
    ll i=idx[k-1];
    auto itl=s.insert(i);
    auto itr=itl;
    vector<ll> l(2,-1),r(2,n);
    rep(i,2){
      l[i]=*(--itl);
      r[i]=*(++itr);
    }
    ans+=k*((i-l[0])*(r[1]-r[0])+(l[0]-l[1])*(r[0]-i));
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 6528
const val MOD = 1000000007
fun main(args: Array<String>) {
    val sc = MyScanner()
    val s = sc.nextLine()
    val c = s[0]
    var flag = false
    for (i in 1 until s.length) {
        if (c != s[i]) {
            flag = true
        }
    }
    if (flag) {
        println("Yes")
    } else {
        println("No")
    }
}

class MyScanner {
    operator fun next(): String {
        return sc.next()
    }

    fun nextLine(): String {
        return sc.nextLine()
    }

    fun nextInt(): Int {
        return sc.next().toInt()
    }

    fun nextDouble(): Double {
        return next().toDouble()
    }

    fun nextLong(): Long {
        return next().toLong()
    }

    fun nextIntArray(n: Int): IntArray {
        val array = IntArray(n)
        for (i in 0 until n) {
            array[i] = nextInt()
        }
        return array
    }

    fun nextDoubleArray(n: Int): DoubleArray {
        val array = DoubleArray(n)
        for (i in 0 until n) {
            array[i] = nextDouble()
        }
        return array
    }

    fun nextLongArray(n: Int): LongArray {
        val array = LongArray(n)
        for (i in 0 until n) {
            array[i] = nextLong()
        }
        return array
    }

    fun nextLineArray(n: Int): Array<String?> {
        val array = arrayOfNulls<String>(n)
        for (i in 0 until n) {
            array[i] = nextLine()
        }
        return array
    }

    fun nextIntMatrix(n: Int, m: Int): Array<IntArray> {
        val matrix = Array(n) { IntArray(m) }
        for (i in 0 until n) {
            for (j in 0 until m) {
                matrix[i][j] = nextInt()
            }
        }
        return matrix
    }

    fun nextDoubleMatrix(n: Int, m: Int): Array<DoubleArray> {
        val matrix = Array(n) { DoubleArray(m) }
        for (i in 0 until n) {
            for (j in 0 until m) {
                matrix[i][j] = nextDouble()
            }
        }
        return matrix
    }

    fun nextLongMatrix(n: Int, m: Int): Array<LongArray> {
        val matrix = Array(n) { LongArray(m) }
        for (i in 0 until n) {
            for (j in 0 until m) {
                matrix[i][j] = nextLong()
            }
        }
        return matrix
    }

    companion object {
        var sc: java.util.Scanner = java.util.Scanner(java.lang.System.`in`)
    }
}


Measured memory_bytes: 29476
INF = float("inf")

N, M, *ABC = map(int, open(0).read().split())

D = [INF, 0] + [INF] * (N - 1)
E = tuple(zip(*[iter(ABC)] * 3))

for a, b, c in E:
    D[b] = min(D[b], D[a] - c)

ans = D[-1]

for a, b, c in E:
    D[b] = min(D[b], D[a] - c)

print("inf" if ans != D[-1] else -ans)


Measured memory_bytes: 3572
#include<iostream>
#define size(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a > b){
      if(a > c){
        cout << b + c;
      }else{
        cout << b + a;
      }
    }else{
      if(b > c){
        cout << a + c;
      }else{
        cout << a + b;
      }
    }
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

temp = 10**5
ans = 0
for i in range(N):
    t = T - H[i] * 0.006
    if abs(t - A) < temp:
        temp = abs(t - A)
        ans = i + 1
print(ans)


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

int main()
{
  string a, b;
  cin >> a >> b;
  b += a;
  cout << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

/*
struct edge {
    int from, to, cost;
    edge(int from, int to, int cost): from(from), to(to), cost(cost) {}
    edge(int to, int cost) {
        edge(0, to, cost);
    }
    edge() {
        edge(0,0,0);
    }
};
*/

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    int n,m;
    string s;
    cin >> n >> m >> s;
    VI pr(n+1);
    pr[n] = n;
    RREP(i,0,n) {
        if (s[i] == '1') pr[i] = pr[i+1];
        else pr[i] = i;
    }
    int index = n;
    VI path;
    while (index != 0) {
        int c = max(0, index - m);
        int next = pr[c];
        if (next == index) {
            cout << -1 << endl;
            return;
        }
        path.push_back(index - next);
        index = next;
    }
    reverse(all(path));
    for (auto p: path) cout << p << " ";
    cout << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}


bool ok(int N,vector<int>& D){
  while(N){
    rep(i,sz(D)){
      if(N%10==D[i]) return false;
    }
    N/=10;
  }
  return true;
}

void solve(){
  int N, K; cin >> N >> K;
  vector<int> D(K); rep(i,K) cin >> D[i];
  while(1){
    if(ok(N,D)) {
      cout << N << endl;
      break;
    }
    else N++;
  }
}

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


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int a, b; cin >> a >> b;
    cout << (a+b)%24 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int cards;   //持ってるカード枚数
	int flag[4][14] = { 0 };
	flag[0][0] = 1;   //トランプのランクに0はないから
	int d = 0;   //カードのランク
	int i, j;   //くり返し用
	char pattern;   //トランプの絵柄

	scanf("%d", &cards);
	for (i = 0; i < cards; i++)
	{
		scanf(" %c %d", &pattern, &d);
		if (pattern == 'S')
		{
			flag[0][d] = 1;
		}
		else if (pattern == 'H')
		{
			flag[1][d] = 1;
		}
		else if (pattern == 'C')
		{
			flag[2][d] = 1;
		}
		else if (pattern == 'D')
		{
			flag[3][d] = 1;
		}
	}
	/*flagに1が入ってなければそれは持っていないカード*/
	for (i = 0; i < 4; i++)
	{
		for (j = 1; j <= 13; j++)
		{
			if (flag[i][j] == 0)
			{
				if (i == 0)
					printf("S %d\n", j);
				if (i == 1)
					printf("H %d\n", j);
				if (i == 2)
					printf("C %d\n", j);
				if (i == 3)
					printf("D %d\n", j);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
struct edge { int to,nxt; } e[N<<1];
int tot=1,h[N];
void adde(int u,int v) {
    e[++tot]=(edge){v,h[u]};h[u]=tot;
    e[++tot]=(edge){u,h[v]};h[v]=tot;
}
int n,a[N],du[N],w[N];
bool dfs(int u,int fa) {
    if(du[u]==1) return w[u]=a[u],1;
    w[u]=2*a[u];
    for(int i=h[u];i;i=e[i].nxt) {
        int v=e[i].to; if(v==fa) continue;
        if(!dfs(v,u)) return 0;
        w[u]-=w[v];
    }
    return w[u]>=0;
}
bool dfs2(int u,int fa) {
    if(du[u]==1) return 1;
    for(int i=h[u];i;i=e[i].nxt) if(e[i].to!=fa&&!dfs2(e[i].to,u)) return 0;
    if(w[u]>a[u]) return 0;
    int t=a[u]-w[u],sum=0;
    for(int i=h[u];i;i=e[i].nxt) if(e[i].to!=fa) sum+=max(0,w[e[i].to]-t);
    return sum<=w[u];
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi();
    for(int i=1,u,v;i<n;i++) u=gi(),v=gi(),adde(u,v),du[u]++,du[v]++;
    if(n==2) return puts(a[1]==a[2]?"YES":"NO"),0;
    int rt=0;
    for(int i=1;i<=n;i++) if(du[i]>1) rt=i;
    if(!dfs(rt,0)||w[rt]) return puts("NO"),0;
    puts(dfs2(rt,0)?"YES":"NO");
    return 0;
}


Measured memory_bytes: 7680
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut d: Vec<usize> = read_vec();
    let l = d.len();

    d.sort();

    let M = d[l/2];
    let lb = d[l/2-1];

    println!("{}", M - lb);

}


Measured memory_bytes: 6396
#include <iostream>

using namespace std;


int sum(int N){
    return N * (N+1) / 2;
}
// return sum of [s..t]
int sum_up(int s,int t){
    return sum(t) - sum(s-1);
}

int solve(int N){
    int s = 1;
    int t = 2;
    int ret = 0;

    while(s != N){
        if(sum_up(s,t) >= N){
            if(sum_up(s,t) == N){
                ret++;
            }
            s++;
        }else{
            t++;
        }
    }
    return ret;
}

int main(int argc,char** argv){
    while(true){
        int n;cin >> n;
        if(n == 0) break;
        cout << solve(n) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=200005,INF=1<<30;

typedef vector<vector<int>> mat;
mat Gauss(mat &A){
    int R=A.size(),C=A[0].size();
    int end=0;//endより上はみた(rank?)
    
    for(int j=0;j<C;j++){
        for(int i=end;i<R;i++){
            if(A[i][j]==1){
                swap(A[end],A[i]);
                for(int k=0;k<R;k++){
                    if(k==end||A[k][j]==0) continue;
                    for(int l=0;l<C;l++){
                        A[k][l]^=A[end][l];
                    }
                }
                end++;
                break;
            }
        }
    }
    
    return A;
}

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    mat A(N,vector<int>(M));
    
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin>>A[i][j];
        }
    }
    
    A=Gauss(A);
    
    int cnt=0;
    for(int i=0;i<N;i++){
        bool ok=false;
        for(int j=0;j<M;j++){
            if(A[i][j]) ok=true;
        }
        if(ok) cnt++;
    }
    
    cout<<(mod+rui(2,N+M-1)-rui(2,N-1+M-cnt))%mod<<endl;
    
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, n)cin >> v[i];

    ll ans = 0;
    rep(left, min(n+1, k+1))rep(right, min(n+1-left, k+1-left)){
        priority_queue<ll, vector<ll>, greater<ll>> que;
        rep(i, left)que.push(v[i]);
        rep(i, right)que.push(v[n-1-i]);

        rep(i, min(k-left-right, left+right)){
            if(que.top() >= 0)break;
            que.pop();
        }
 
        ll res = 0;
        while(!que.empty()){
            res += que.top();
            que.pop();
        }

        ans = max(ans, res);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3612
from sys import exit
Y, N = map(int, input().split())
N /= 1000
N -= Y
if N == 0:
  print(0, 0, Y)
elif N < 0 or N - 9 * Y > 0:
  print(-1, -1, -1)
else:
  for n in range(Y + 1):
    if N - 9 * n < 0:
      print(-1, -1, -1)
      exit()
    if N - 9 * n == 0:
      print(n, 0, Y - n)
      exit()
    for m in range(0, Y - n + 1):
      if N - 9 * n - 4 * m == 0:
        print(n, m, Y - n - m)
        exit()
      if N - 9 * n - 4 * m < 0:
        break
  print(-1, -1, -1)


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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())

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code
int main(int argc, char const* argv[])
{
	int h,w;
	cin >> h >> w;
	vector<vector<char>> a(h,vector<char>(w));
	VVL b(h,VL(w,0));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < h; i++) {
		bool allw = true;
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				allw = false;
			}
		}
		if (allw) {
			for (int j = 0; j < w; j++) {
				b[i][j] = 1;
			}
		}
	}

	for (int i = 0; i < w; i++) {
		bool allw = true;
		for (int j = 0; j < h; j++) {
			if (a[j][i] == '#') {
				allw = false;
			}
		}
		if (allw) {
			for (int j = 0; j < h; j++) {
				b[j][i] = 1;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		bool allw = true;
		for (int j = 0; j < w; j++) {
			if (b[i][j] == 0) {
				cout << a[i][j];
				allw = false;
			}
		}
		if (!allw) {
			cout << endl;
		}
	}
	return 0;
}



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

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

        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int ans = EuclideanAlgorithm(a[0], a[1]);
        for (int i = 2; i < n; i++) {
            ans = EuclideanAlgorithm(ans, a[i]);
        }

        System.out.println(ans);
    }

    public static int EuclideanAlgorithm(int a, int b) {
        int max = Math.max(a, b);
        int min = Math.min(a, b);

        int re = max % min;
        if (re == 0)
            return min;
        return EuclideanAlgorithm(min, re);
    }
}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n;
    cin >> n;
    for (int i = 1; i <= 10; i++) {
        if (1000 * i - n >= 0) {
            print(1000 * i - n);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=300000+5,mod=1e9+7;

int main(){
    GO();

    int T;
   // cin>>T;
   T=1;
    while(T--){

        int d,t,s;
        cin>>d>>t>>s;

        int ne=(d/s)+(d%s!=0);
        if(ne<=t){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }

    }

}





































































Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll cnt[26];

void solve() {
	cin >> N;
	string S;
	cin >> S;
	rep(i, 0, N) {
		cnt[S[i] - 'a']++;
	}
	ll ans = 1;
	rep(i, 0, 26) {
		MUL(ans, cnt[i] + 1);
	}
	cout << (ans + mod - 1) % mod << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 15
#define M 5010
using namespace std;
ll n,m,cga[N],cgb[N];
string s[N],sts[N];

void dfs1(ll x,ll mr);

void dfs(ll x,ll mr)
{
	ll i;
	if(x>=n)
	{
		if(m%2==0)
		{
			dfs1(0,0);
		}
		else
		{
			dfs1(0,1);
		}
	}
	else if(cga[x]>=0)//已有匹配
	{
		dfs(x+1,mr);
	}
	else
	{
		for(i=x+1;i<n;i++)
		{
			if(cga[i]>=0||sts[i]!=sts[x])//已有匹配或不能匹配
			{
				continue;
			}
			cga[i]=x;
			cga[x]=i;
			dfs(x+1,mr);
			cga[i]=-1;
			cga[x]=-1;
		}
		if(mr==1)//单独匹配 
		{
			cga[x]=x;
			dfs(x+1,0);
			cga[x]=-1;
		}
	}
	return;
}
void dfs1(ll x,ll mr)
{
	ll i,j;
	if(x>=m)
	{
		puts("YES");
		exit(0);
	}
	else if(cgb[x]>=0)//已有匹配
	{
		dfs1(x+1,mr);
	}
	else
	{
		for(i=x+1;i<m;i++)
		{
			if(cgb[i]>=0)//已有匹配
			{
				continue;
			}
			for(j=0;j<n;j++)
			{
				if(s[j][i]!=s[cga[j]][x])//不可匹配(考虑行的可行性) 
				{
					j=-1;
					break;
				}
			}
			if(j==-1)
			{
				continue;
			}
			cgb[i]=x;
			cgb[x]=i;
			dfs1(x+1,mr);
			cgb[i]=-1;
			cgb[x]=-1;
		}
		if(mr==1)//单独匹配 
		{
			for(j=0;j<n;j++)
			{
				if(s[j][x]!=s[cga[j]][x])//不可匹配(考虑行的可行性) 
				{
					j=-1;
					break;
				}
			}
			if(j!=-1)
			{
				cgb[x]=x;
				dfs1(x+1,0);
				cgb[x]=-1;
			}
		}
	}
	return;
}
int main(){
	ll i;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>sts[i];
		s[i]=sts[i];
		sort(sts[i].begin(),sts[i].end());
	}
	memset(cga,-1,sizeof(cga));
	memset(cgb,-1,sizeof(cgb));
	if(n%2==0)
	{
		dfs(0,0);
	}
	else
	{
		dfs(0,1);
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N; cin>>N;
    vector<pair<int,int>> v;
    for(int i=0;i<N;i++){
        int a; cin>>a;
        v.push_back({a,i+1});
    }
    sort(v.begin(),v.end());
    for(pair<int,int> p:v) cout<<p.second<<' '; cout<<endl;
    return 0;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

void solve() {
    ll n, k, q;
    cin >> n >> k >> q;
    vec<ll> a(n);
    REP(i, n) cin >> a[i];
    vec<ll> b = a;
    sort(all(b));
    ll ans = b[q - 1] - b[0];
    //cout << b[q - 1] << " " << b[0] << en;

    REP(i,n) {
        vvec<ll> aa(1);
        vec<ll> ret;
        int pos = 0;
        REP(j,n){
            if(b[i]<a[j]){
                aa[pos].push_back(a[j]);
            }else{
                if(aa[pos].size()){
                    sort(all(aa[pos]));
                    pos++;
                    aa.push_back(vec<ll>());
                }
            }
        }
        sort(all(aa[pos]));

        auto check = [&](ll x) {
            ll con = 0;
            REP(j,aa.size()){
                if(aa[j].size() < k)
                    continue;
                auto it = upper_bound(all(aa[j]), b[x]);
                con += min((ll)aa[j].size() - k + 1, (ll)(it - aa[j].begin()));
            }
            return con >= q;
        };

        ll l = i;
        ll r = n;
        while(l+1<r){
            ll m = l + r >> 1;
            if(check(m)) r = m;
            else l = m;
        }
        if(r == n) continue;
        chmin(ans, b[r] - b[i + 1]);
        //cout << b[r] << " " << b[i + 1] << en;

    }
    cout << ans << en;
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // abs()
#include <string.h>         // memset()
#include <stdbool.h>

#define MAX_N 15
#define MAX_S (1 << MAX_N)

const double INF = 1e10;

int n;
int s[MAX_N], l[MAX_N], v[MAX_N];
double dp[MAX_N][MAX_S];
int w[MAX_N][MAX_S];
short prev[MAX_N][MAX_S][2];
int ord[MAX_N];

int
main(int argc, char **argv)
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d%d%d", &s[i], &l[i], &v[i]);

	memset(prev, -1, sizeof(prev));
	int S = 1;
	for (int i = 0; i < n; i++, S <<= 1)
		w[i][S] = v[i];

	int e = 1 << n;
	for (int k = 0; k < e; ++k)
	{
		S = 1;
		for (int i = 0; i < n; ++i, S <<= 1)
		{
			if (k & S)
				continue;

			int t = k | S;
			for (int j = 0; j < n; ++j)
			{
				if (i == j || w[j][k] == 0)
					continue;

				int d = abs(l[i] - l[j]);
				double x = dp[j][k] + (d * (7 + 2 * w[j][k])) / 200.0;
				if (dp[i][t] == 0 || x < dp[i][t])
				{
					dp[i][t] = x;
					w[i][t] = w[j][k] + v[i];
					prev[i][t][0] = j;
					prev[i][t][1] = k;
				}
			}
		}
	}

	double min = INF;
	int u = 0;
	for (int i = 0; i < n; ++i)
	{
		double y = dp[i][e - 1];
		if (y == 0)
			continue;

		if (y < min)
		{
			min = y;
			u = i;
		}
	}

	ord[0] = u;
	int v = e - 1;
	for (int k = 1; k < n; ++k)
	{
		ord[k] = prev[u][v][0];
		v = prev[u][v][1];
		u = ord[k];
	}

	for (int i = n - 1; i >= 0; --i)
		printf("%d%c", s[ord[i]], (i != 0) ? ' ' : '\n');

	return 0;
}

Measured memory_bytes: 8688
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}


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

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

  Yes(abs(a-c)<=d||abs(a-b)<=d&&abs(b-c)<=d);


}

Measured memory_bytes: 256
# frozen_string_literal: true

n, x, m = gets.split.map(&:to_i)

a = x

h = Hash.new { false }
l = -1
b = []
n.times do
  if h[a]
    l = a
    break
  end
  h[a] = true
  b.push a
  a = (a * a) % m
end

b1, b2 = b.slice_before(l).to_a
b1 = [] if b1.nil?
b2 = [] if b2.nil?
remain = n - b.size
if l == b[0]
  b2 = b1
  b1 = []
end
d = 0
dd = 0
if remain.positive?
  unless b2.empty?
    d = remain / b2.size
    dd = remain % b2.size
  end
end

sum1 = b1.sum
sum2 = b2.sum * (d + 1)
sum = sum1 + sum2 + b2.take(dd).sum
puts sum


Measured memory_bytes: 17024
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define rep(i, n) for (int i=0; i<(n); i++)
#define rep2(i, x, n) for (int i=x; i<(n); i++)
using namespace std;
int main(){
     
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int n;
    cin >> n;
     
    rep(i,n){
         
        int a, b, c;
        cin >> a >> b >> c;
         
        if(a>b&&a>c){
            cout << ( (a == b) == c ? "NO" : b*b + c*c == a*a ? "YES" : "NO" ) << endl;
        }else if(b>a&&b>c){
            cout << ( (a == b) == c ? "NO" : a*a + c*c == b*b ? "YES" : "NO" ) << endl;
        }else{
            cout << ( (a == b) == c ? "NO" : a*a + b*b == c*c ? "YES" : "NO" ) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3064
def gcd(a: int, b: int)->int:
    a, b = abs(a), abs(b)
    if a < b:
        a, b = b, a
    return gcd(b, a % b) if b else a


def sum_seq1(l: int, r: int)->int:
    if r < l:
        return 0
    return r*(r+1) // 2 - l*(l-1) // 2


def sum_difference(N: int, X: int, D: int)->int:
    if D == 0:
        if X == 0:
            return 1
        return N+1

    # D != 0
    g = gcd(X, D)
    a, b = D // g, -X // g

    if a < 0:
        a *= -1
        b *= -1
    i_range = [(float('inf'), -float('inf'))] * (N+1)

    ans = 0
    for k in range(N+1):
        kl, kr = i_range[k]
        nl = sum_seq1(0, k-1)
        nr = sum_seq1(N-k, N-1)
        # print('k: ({}, {}), n: ({}, {})'.format(kl, kr, nl, nr))

        if k+a <= N:
            i_range[k+a] = (b+min(kl, nl), b+max(kr, nr))

        if kr == -float('inf'):
            ans += nr - nl + 1
        elif kr < nl or nr < kl:
            ans += nr - nl + 1
        elif nl <= kl and kr <= nr:
            ans += (nr-nl+1) - (kr-kl+1)
        elif kl <= nl:
            ans += max(0, nr-kr)
        else:
            ans += kl-nl

    return ans


if __name__ == "__main__":
    N, X, D = map(int, input().split())
    ans = sum_difference(N, X, D)
    print(ans)


Measured memory_bytes: 32756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int a,b,c,d;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b>>c>>d;
    if( ((abs(a-b)<=d)&&(abs(b-c)<=d)) || (abs(a-c)<=d) )cout<<"Yes\n";
    else cout<<"No\n";
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	ll a,b;
	while(cin >> a >> b){
		ll gcd = __gcd((int)a,(int)b);
		ll lcm = a/gcd*b;

		cout << gcd << " " << lcm << endl;
	}
	return 0;
}



Measured memory_bytes: 3164
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.nextLine();
    String b = sc.nextLine();
    int idx = 0;

    if(a.length() > b.length()){
      System.out.println("GREATER");
      System.exit(0);
    }else if(a.length() < b.length()){
      System.out.println("LESS");
      System.exit(0);
    }

//charAt(-1)はout of boundsになるのでifで防ぐ
    while(a.charAt(idx) == b.charAt(idx) && idx < a.length()){
      idx++;
      if(idx == a.length()) break;
    }

    if(idx == a.length()){
      System.out.println("EQUAL");
      System.exit(0);
    }

    if(a.charAt(idx) > b.charAt(idx)){
      System.out.println("GREATER");
    }else{
      System.out.println("LESS");
    }

  }
}

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

int main() {
  //int型ではオーバーフローする。int64_t型でやる必要がある。
  int64_t N, blue, red, num, blue_red, nokori;
  cin >> N >> blue >> red;
  blue_red = blue + red;
  nokori = (N % ( blue_red));
  num = N / ( blue_red ) * blue + min( blue, nokori);
  cout << num << endl;
}

Measured memory_bytes: 256
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> n;

	set<int> st;
	int ans = 0;

	int i = 2;

	while( i*i <= n)
	{
		if( n%i == 0)
		{
			st.insert( i );
			st.insert( n/i );
		}
		i++;
	}
	st.insert(n);

	for( auto j : st)
	{
		int nn = n;
		while( nn%j == 0 ) nn /= j;
		if( nn%j ==  1 ) ans++;
	}

	st.clear();

	i = 2;
	int nn = n - 1;
	while( i*i <= nn)
	{
		if( nn%i ==0 ) st.insert( i ) , st.insert( nn/i );
		i++;
	}
	if( nn > 1 ) st.insert(nn);

	ans += (int)st.size();

	cout << ans << endl;
}

int32_t main()
{
	//INP(); 
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}

 

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

int main() {
  char mozi;
  cin >> mozi;
  
  if (mozi == 'a' || mozi == 'i' || mozi == 'u' || mozi == 'e' || mozi == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

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

int main(void){
  int i,j,k,n,s;
  char ca[201],can[201];

  while(1){
    scanf("%s\n%d", ca, &n);
    if(!strcmp(ca, "-")) break;
   
    for(i=0;i<n;i++){
      scanf("%d", &s);
      for(j=s;ca[j]!='\0';j++)
        can[j-s] = ca[j];
      for(k=0;k<s;k++)
        can[j-s+k] = ca[k];
     
      for(j=0;ca[j]!='\0';j++)
        ca[j] = can[j];
    }

    printf("%s\n", ca);
  }

  return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
using namespace std;
#define maxi 2000001
int n;
void counting(int a[],int b[],int k){
int i,j,c[10001];
	for(i=0;i<=k;i++)
	c[i]=0;
	for(j=1;j<=n;j++)
	c[a[j]]++;
	for(i=1;i<=k;i++)
	c[i]=c[i]+c[i-1];
	for(j=n;j>0;j--){
	b[c[a[j]]]=a[j];
		c[a[j]]--;
	}
}

main(){
	int i,a[maxi],b[maxi],ma;
	ma=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
	scanf("%d",&a[i]);
		ma=max(ma,a[i]);
	}
	counting(a,b,ma);
	for(i=1;i<=n;i++){
		if(i==n)
		printf("%d\n",b[i]);
		else
		printf("%d ",b[i]);
	}
	return 0;
}



Measured memory_bytes: 18848