akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

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

  if (a < b && b < c) {
    cout << "Yes" << "\n";
  } else {
    cout << "No" << "\n";
  }
}


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

	int h[100000];

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, C;
  cin >> N >> C;
  vector<vector<ll> > D(C, vector<ll>(C));
  rep(i, 0, C){
    rep(j, 0, C){
      cin >> D[i][j];
    }
  }
  vector<vector<ll> > C_(3, vector<ll>(C));
  rep(i, 0, N){
    rep(j, 0, N){
      ll tmp;
      cin >> tmp;
      C_[(i+j)%3][tmp-1]++;
    }
  }

  ll ans = INT_MAX;
  for(int c1=0; c1<C; ++c1){
    for(int c2=0; c2<C; ++c2){
      if(c1 == c2) continue;
      for(int c3=0; c3<C; ++c3){
        if(c1 == c3) continue;
        if(c2 == c3) continue;
        ll tmp1 = 0;
        ll tmp2 = 0;
        ll tmp3 = 0;
        for(int c4=0; c4<C; ++c4){
          tmp1 += C_[0][c4]*D[c4][c1];
          tmp2 += C_[1][c4]*D[c4][c2];
          tmp3 += C_[2][c4]*D[c4][c3];
        }
        ans = min(ans, tmp1+tmp2+tmp3);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	string s, t;
	int s_size, t_size, N;

	cin >> s >> t;

	sort(s.begin(), s.end());
	sort(t.rbegin(), t.rend());

	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
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;}


ll cntN[100005];// 最悪全ての数字が同じ


void cal(ll N){
    ll cnt = 0;
    rep(i, N){
        cnt += i;
        cntN[i+1] = cnt;
    }
}


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

    ll N,  M ;

    cin >> N >> M;

    cal(100001);


    vector<ll> A;
    vector<ll> sumA;
    rep(i,N){
        ll inp;
        cin >> inp;
        A.pb(inp);
    }

    ll s = 0;
    map<ll,ll> cnt;
    sumA.pb(0);
    cnt[0] ++;
    rep(i,N){
        s += A[i];
        sumA.pb(s % M);
        cnt[s%M] ++;
    }

    rmsame(sumA);

    ll ans = 0 ;
    rep(i, sumA.size()){
        ans += cntN[cnt[sumA[i]]];
    }
    cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

using i64 = long long;

const int N = 20005;

int n;

int a[N], b[N], p[N];

int main() {
#ifdef HOME
	freopen("agc7b.in", "r", stdin);
	freopen("agc7b.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 ct, sum(0);

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

	ct = n * (n + 1);
	for (int i = 1; i <= n; ++i) {
		a[i] = ct + (i - 1) * n;
		b[i] = ct - (i - 1) * n; }
	for (int i = 1; i <= n; ++i)
		a[p[i]]+= i;

	for (int i = 1; i <= n; ++i)
		cout << a[i] << " \n"[i == n];
	for (int i = 1; i <= n; ++i)
		cout << b[i] << " \n"[i == n];

	return 0; }


Measured memory_bytes: 896
#pragma GCC optimize(3)
#include<cstdio>
#include<cstring>
#define gc() getchar()
using namespace std;
const int maxn=200010,maxm=400010;
int n,m,cnt,head[maxn];
struct edge{
    int from,to,next;
}edges[maxm];
char c[maxn];
bool sz[maxn];
inline bool check(int p){
    char hd;
    if(head[p]<0) return false;
    register int j;
    for(j=head[p];sz[edges[j].to];j=edges[j].next);
    if(j>=0) hd=c[edges[j].to];
    for(;j>=0;j=edges[j].next) if(!sz[edges[j].to]){
        if(c[edges[j].to]!=hd) return true;
    }
    return false;
}
inline void dfs(int p){
    sz[p]=true;
    for(register int j=head[p];j>=0;j=edges[j].next) if((!sz[edges[j].to])&&(!check(edges[j].to))) dfs(edges[j].to);
}
inline void gi (int &x){
    char c;
    for(c=gc();c<'0'||c>'9';c=gc());
    for(x=0;c<='9'&&c>='0';c=gc()) x=x*10+(c&15);
}
int main(){
    scanf("%d%d",&n,&m);getchar();
    scanf("%s",c+1);int xx,yy;memset(head,-1,sizeof(head));
    for(register int i=1;i<=m;i++){
        gi(xx);gi(yy);
        edges[cnt]=(edge){xx,yy,head[xx]};
        head[xx]=cnt++;
        edges[cnt]=(edge){yy,xx,head[yy]};
        head[yy]=cnt++;
    }
    bool flag;//memset(sz,1,sizeof(sz));
    while(true){
        flag=true;
        for(register int i=1;i<=n;i++) if((!sz[i])&&(!check(i))){
            flag=false;dfs(i);
        }
        if(flag) break;
    }
    for(register int i=1;i<=n;i++) if(!sz[i]){
        printf("Yes\n");return 0;
    }
    printf("No\n");
    return 0;
}

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

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

    int res;
  
  if(N >= 10){
   res = R;
  }
  else{
    res = R + 100*(10-N);
  }
  

      
  cout << res << endl;
}







Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c[31]={0},d=0;
  scanf("%d %d",&a,&b);
  for(int i=0; i<a; i++){
    int e;
    scanf("%d",&e);
    for(int j=0; j<e; j++){
      int f;
      scanf("%d",&f);
      c[f]++;
    }
  }
  for(int i=1; i<=b; i++){
    if(c[i]==a){d++;}
  }
  printf("%d",d);
  return 0;}

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

int main(){
	int n, x, i, j, k, s;
	
	while(1){
		cin >> n >> x;
		
		if(n == 0 && x == 0){
			break;
		}
		
		s = 0;
		for(i = 1; i <= n - 2; i++){
			for(j = i + 1; j <= n; j++){
				for(k = j + 1; k <= n; k++){
					if(i + j + k == x){
						s++;
					}
				}
			}
		}
		cout << s << endl;
	}
	
	return 0;	
}

Measured memory_bytes: 3092
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	a := nextInt()
	puts(a + a*a + a*a*a)
}


Measured memory_bytes: 1784
n=int(input())
n3=n//3
s3=(n3*3)*(n3+1)//2
n5=n//5
s5=((n5)*5)*(n5+1)//2
n15=n//15
s15=((n15)*15)*(n15+1)//2
 
s=n*(n+1)//2
s=s-s3-s5+s15
print(s)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 210000
ll P[N], pos[N];
signed main () {
	memset(pos, -1, sizeof(pos));
	ll n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)  {
		cin >> P[i];
	}
	ll pt = 1;
	vector<ll> v;
	while(pos[pt] == -1) {
		pos[pt] = v.size();
		v.push_back(pt);
		pt = P[pt];
	}
	int c = v.size() - pos[pt];
	int l = pos[pt];
	if(k < l) {
		cout << v[k] << endl;//未进环 
	}
	else {
		k -= l;k %= c;
		cout << v[l + k] << endl;
	}
	
	return 0;
} 

Measured memory_bytes: 8456
import sys
import os
import math
import string
import collections

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

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


def f(N):
    return sum(map(int, str(N)))


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    q = f(N)
    print('No' if N%q else 'Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3832
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    ss = set(s)
    if len(ss) == 26:
        print('None')
    else:
        for i in range(26):
            if chr(ord('a')+i) not in ss:
                print(chr(ord('a')+i))
                return

solve()


Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    cout << min(b*c*(a%2), min(c*a*(b%2), a*b*(c%2))) << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int switchCount = sc.nextInt();
		int lampCount = sc.nextInt();
		List<int[]> switchInfo = new ArrayList<int[]>();
		for(int i =0;i < lampCount;i++) {
			int connectSwitch = sc.nextInt();
			int[] connectSwitchInfo = new int[connectSwitch];
			for(int j =0; j < connectSwitch; j++) {
				connectSwitchInfo[j] = sc.nextInt();
			}
			switchInfo.add(connectSwitchInfo);
		}
		int[] onOffInfo = new int[lampCount];
		for(int i =0;i < lampCount; i++) {
			onOffInfo[i] = sc.nextInt();
		}
		int answer = 0;
		for(int i =0;i < 1 <<switchCount;i++) {
			for(int j =0; j < lampCount;j++) {
				int switchOnCount = 0;
				for(int k =0; k < switchInfo.get(j).length;k++) {
					if((1 & (i >> (switchInfo.get(j)[k] -1))) == 1 ) {
						switchOnCount++;
					}
				}
				if(switchOnCount % 2 != onOffInfo[j]) {
					break;
				}
				if(j ==lampCount-1) {
					answer++;
				}
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 36012
#coding:utf-8
N,K = map(int,input().split())
oldK = K
K = min(N,K)
V = list(map(int,input().split()))
mx = 0
for k in range(1,K+1):
    for i in range(k+1):
        late = V[-(k-i):]
        if len(late)==N:
            late = []
        #print (k,V[:i],late)
        a = V[:i]+late
        a += [0]
        #print (a)
        a.sort()
        idx = min(a.index(0),oldK-k)
        sm = sum(a[idx:])
        #print (a,sm)
        mx = max(sm,mx)
        #print (mx)
print (mx)


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

using namespace std;
typedef long long ll;
int main() {
  int N; cin>>N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) cin>>a[i];
  ll ans = 0;
  int left = 0, right = 0;
  int sum_x = a[0], sum_a = a[0];
  for(left = 0; left < N; left++) {
    while(true) {
      //      cout << left << "," << right << "," << sum_a << "," << sum_x << endl;
      if(sum_x != sum_a) {
	sum_a -= a[right];
	sum_x ^= a[right];
	break;
      }
      right++;
      if(right >= N) break;
      sum_x ^= a[right];
      sum_a += a[right];
    }
    right--;
    ans += (ll)(right - left + 1);
    //    cout << "Answer"<<ans << ":" << left << "," << right << "," << sum_a << "," << sum_x << endl;
    sum_a -= a[left];
    sum_x ^= a[left];
	
  }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    for (auto &i : s) {
        if (i == '7') {
            cout << "Yes\n";
            rr;
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 3640
#include<iostream>
#include<complex>
#include<cmath>
#include<cstdio>
using namespace std;

complex<double> w[100];
int r[100];
complex<double> t,s;

bool inter(int a,double  x,double y){
  return sqrt( (w[a].real()-x)*(w[a].real()-x) + (w[a].imag()-y)*(w[a].imag()-y) ) <= r[a] + 1e-10;
}

double dot(complex<double> a,complex<double> b){
  return a.real()*b.real() + a.imag()*b.imag();
}

double cross(complex<double> a,complex<double> b){
  return a.real() * b.imag() - a.imag() * b.real();
}

double dis_s_p(complex<double> a,complex<double> b,complex<double> c){
  if( dot(b-a,c-a) < 1e-10 ) return abs(c-a);
  if( dot(a-b,c-b) < 1e-10 ) return abs(c-b);
  return abs( cross(b-a,c-a) ) / abs(b-a);
}

int main(){
  int n,m;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++)cin >> w[i].real() >> w[i].imag() >> r[i];

    cin >> m;
    for(int i=0;i<m;i++){
      cin >> t.real() >> t.imag() >> s.real() >> s.imag();

      bool f = true;
      for(int j=0;j<n;j++){
	bool a = inter(j,t.real(),t.imag()),b = inter(j,s.real(),s.imag());
	if(a != b)f = false;
	else if(!a && !b){
	  if(dis_s_p(t,s,w[j]) <= r[j] + 1e-10)f = false;
	}
	if(!f)break;
      }

      if(f)cout << "Danger\n";
      else cout << "Safe\n";
    }
  }
}

Measured memory_bytes: 0
#include <cstdio>

int k,f=0,step=1;
int a[5];
void dfs(int step);
int check();
int main(){
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	scanf("%d",&k);
	if(check()) f=1;
	else dfs(step);
	if(f) printf("Yes\n");
	else printf("No\n");
	return 0;
}
int check(){
	if(a[1]>a[0] && a[2]>a[1]) return 1;
	else return 0;
}
void dfs(int s){
	if(f==1) return;
	else if(s>k){
		step--;
		return;
	}
	for(int i=0;i<3;i++){
		a[i] *= 2;
		if(check()){
			f = 1;
			return;
		}
		dfs(++step);
		a[i] /= 2;
	}
	step--;
	return;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<ll>
#define pi pair<ll,ll>
#define vp vector<pi>
#define mp map<ll,ll>
#define pb push_back
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int32_t main(){
    fast;
    
     ll n,k;
     cin>>n>>k;
     
     vi v(n);
     for(ll i=0;i<n;i++)
     cin>>v[i];
     ll INF=1e+18;
     vi dp(n,INF);
     dp[0]=0;
     dp[1]=abs(v[1]-v[0]);
     
     for(ll i=2;i<n;i++)
     {
     for(ll j=i-1;j>=(i-k) && j>=0;j--)
       dp[i]=min(dp[i],dp[j]+abs(v[j]-v[i]));
     }
     
     cout<<dp[n-1];
     
    
    return 0;
    
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))

bs = []
b = True
for i in range(n-1):
    if b and a[i] < a[i+1]:
        bs.append(i)
        b = False
    elif not b and a[i] > a[i+1]:
        bs.append(i)
        b = True

if not b:
    bs.append(n-1)

m = 1000
for i in range(0, len(bs), 2):
    s = m // a[bs[i]]
    m += s * (a[bs[i+1]]-a[bs[i]])

print(m)


Measured memory_bytes: 9208
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int i=0;
    char *t,*dpdmax;
    t=(char *)malloc(sizeof(char)*200001);
    dpdmax=(char *)malloc(sizeof(char)*200001);
    if(t==NULL||dpdmax==NULL)
        return EXIT_FAILURE;
    scanf("%s",t);
    while(t[i]!='\0'){
        if(t[i]=='?'){
            if(t[i+1]=='D')
                if(i!=0&&t[i-1]=='P')
                    dpdmax[i]='D';
                else
                    dpdmax[i]='P';
            else
                dpdmax[i]='D';
        }else
            dpdmax[i]=t[i];
        i++;
    }
    dpdmax[i]='\0';
    printf("%s\n",dpdmax);
    free(t);
    free(dpdmax);
    return 0;
}


Measured memory_bytes: 1732
#include <stdio.h>
int gcd(int a,int b);

int main(int argc, const char * argv[]) {
  int a,b;
  scanf("%d %d",&a,&b);
  printf("%d\n",gcd(a,b));
}

int gcd(int a,int b){
  int r;
  while((r = a % b) != 0){
    a = b;
    b = r;
  }
  return b;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int  k = scanner.nextInt();
		int  s=scanner.nextInt();


		int result=0;

		for(int x=0;x<=k;x++) {

			for(int y=0;y<=k;y++) {

				boolean isMacth= k>=s-(x+y) && s-(x+y)>=0;

				if(isMacth) {
					result++;
				}

			}

		}

		System.out.println(result);


		scanner.close();

	}




}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  cout << (n + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int n, p;
ll dp[51][2];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> n >> p) {
        MEM(dp, 0);
        dp[0][0] = 1;
        rep(i, n) {
            int a;
            cin >> a;
            rep(j, 2) {
                int nj = (j + a) % 2;
                dp[i + 1][nj] += dp[i][j];
                dp[i + 1][j] += dp[i][j];
            }
        }
        cout << dp[n][p] << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
//#define ll long long int
int main()
{
    double n;
    cin >> n;
    double ans  = ceil(n/1000);
    //cout << ans << endl;
    double s =(ans*1000) - n;
    if(s == 0)
        cout << 0 << endl;
    else cout << s << endl;
    return 0;

}


Measured memory_bytes: 3748
#!/usr/bin/env python3

ABC = "abcdefghijklmnopqrstuvwxyz"

def add_next(s):    
    for c in ABC:
        if c not in s:
            return s + c
    raise Exception

def change_next(s):
    for i in reversed(range(n)):
        flag = False
        for j in range(i + 1, n):
            if ord(s[i]) < ord(s[j]):
                flag = True
                break
        if flag:
            for k in range(1, n):
                if chr(ord(s[i]) + k) not in s[:i]:
                    return s[:i] + chr(ord(s[i]) + k)
            raise Exception
    raise Exception

s = input()
n = len(s)

if n < 26:
    res = add_next(s)
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        res = "-1"
    else:
        res = change_next(s)

print(res)


Measured memory_bytes: 3064
import sys
input=sys.stdin.readline
import math
x=int(input())
i=x
while True:
  flag="ok"
  for j in range(2,i):
    if i % j == 0:
      flag="ng"
      break
  if flag=="ok":
    print(i)
    break
  i+=1

  # int(math.sqrt(i)) + 1)

Measured memory_bytes: 38512
#include <iostream>

using namespace std;

int main(){
  int r,g,b,n,ans = 0;
  cin >> r >> g >> b >> n;
  for(int i = 0; i <= n/r;i++){
    for(int j = 0; j <= (n-r*i)/g;j++){
      if( n-r*i-g*j == 0) {
        //cout << i << ' ' << j << ' ' << (n -r*i - g*j) / b << endl;
        ans++;
      }
      if(n -r*i - g*j > 0 && (n -r*i - g*j) % b == 0){
        ans++;
        //cout << i << ' ' << j << ' ' << (n -r*i - g*j) / b << endl;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b);
#define chmin(a, b) a = min(a, b);
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<int> h(n), a(n);
    rep(i, n) cin >> h[i];
    rep(i, n) cin >> a[i];
    map<int, ll> dp;
    dp[0] = 0;
    rep(i, n) {
        auto it = dp.lower_bound(h[i]);
        it--;
        ll t = it->second + a[i];
        dp[h[i]] = t;
        while(1) {
            auto it = dp.upper_bound(h[i]);
            if (it != dp.end() && it->second <= t) {
                dp.erase(it);
            } else break;
        }
    }
    cout << dp.rbegin()->second << endl;
}


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

main()
{
int a,b;
   while(1){
   	scanf("%d %d",&a,&b);
   	if((a|b)==0)break;
   	if(b<a)std::swap(a,b);
   	printf("%d %d\n",a,b);
    }
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define infy 2e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
const int N = 3004;
int dp[3004][3004];
string s1,s2;
int n;
int f(int i,int j)
{
       if(i>=n || j >= n){return 0;}
       if(dp[i][j] != -1){return dp[i][j];}
       if(s1[i] == s2[j]){
              return dp[i][j] = 1+f(i+1,j+1);
       }
       return dp[i][j] = max(f(i+1,j),f(i,j+1));
}
int main()
{
       cin>>s1>>s2;
       if(s1.size()<s2.size()){
              swap(s1,s2);
       }
       fri(i,0,s1.size()-s2.size()){
              s2 += 'Z';
       }
       memset(dp,-1,sizeof dp);
        n = s1.size();
       string fin;
       int i = 0;
       int j = 0;
       bool vis[n];
       //cout<<f(0,0)<<endl;
       memset(vis,false,sizeof vis);
       while(i<n && j<n){
              if(s1[i]==s2[j]){
                     vis[i] = true;
                     i++;
                     j++;
                     continue;
              }
              if(f(i+1,j)>=f(i,j+1)){
                     i++;
              }
              else{
                     j++;
              }
       }
       fri(i,0,s1.size()){
              if(vis[i]){
                     fin.pb(s1[i]);
              }
       }
       cout<<fin<<endl;
}


Measured memory_bytes: 35840
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

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

    int n;
    cin >> n;

    vector<int> x(n);
    rep(i, n){
        cin >> x[i];
    }

    int l;
    cin >> l;

    vector< vector<int> > v(18, vector<int>(n, 0));
    rep(i, n){
        v[0][i] = upper_bound(x.begin(), x.end(), x[i] + l) - x.begin() - 1;
    }

    rep(i, 17){
        rep(j, n){
            v[i + 1][j] = v[i][v[i][j]];
        }
    }

    int q;
    cin >> q;
    while(q--){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        if(a > b){
            swap(a, b);
        }

        int ans = 0, now = a;
        while(now < b){
            rrep(i, 18){
                if(v[i][now] < b || i == 0){
                    now = v[i][now];
                    ans += (1 << i);
                    break;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 8312
#include<bits/stdc++.h>
using namespace std;
int n,x,ans,MAX,a[100010];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x>n)
		{
			ans++;
			continue;
		} 
		MAX=max(MAX,x);
		a[x]++;
	}
	for(int i=1;i<=MAX;i++)
	{
		if(a[i]==0) continue;
		if(a[i]<i)
		{
			ans+=a[i];
			continue;
		} 
		ans+=a[i]-i;
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int m, k; cin >> m >> k;
  if (m < 3) {
    V<> a;
    for (int i = 0; i < 1 << m; ++i) {
      a.push_back(i);
      a.push_back(i);
    }
    int n = a.size();
    do {
      V<> c(n + 1);
      for (int i = 0; i < n; ++i) c[i + 1] = c[i] ^ a[i];
      bool ok = true;
      for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (a[i] == a[j]) {
        if ((c[j + 1] ^ c[i]) != k) ok = false;
      }
      if (ok) {
        for (int i = 0; i < n; ++i) cout << a[i] << " \n"[!(n + ~i)];
        return 0;
      }
    } while (next_permutation(begin(a), end(a)));
    cout << -1 << '\n';
  } else {
    if (k >= 1 << m) return cout << -1 << '\n', 0;
    V<> a;
    a.push_back(k);
    for (int i = 0; i < 1 << m; ++i) if (i != k) a.push_back(i);
    a.push_back(k);
    for (int i = (1 << m) - 1; i >= 0; --i) if (i != k) a.push_back(i);
    int n = a.size();
    for (int i = 0; i < n; ++i) cout << a[i] << " \n"[!(n + ~i)];
  }
}


Measured memory_bytes: 4292
#[warn(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        l: usize,
    }

    let n = l as f64 / 3f64;

    let ans = n * n * n;

    // let ans = (l * l * l) as f64 / 27 as f64;

    // let mut ans = 0f64;
    // let l = l * 10;

    // for x in 0..l+1 {
    //     for y in 0..l-x+1 {
    //         let z = (l - x - y) as f64 / 10.0;
    //         let x = x as f64 / 10.0;
    //         let y = y as f64 / 10.0;
    //         ans = ans.max(x * y * z);
    //     }
    // }

    println!("{}", ans);
}


Measured memory_bytes: 2156
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int r;
  cin>>r;
  if(r<1200) cout<<"ABC"<<'\n';
  else if(r<2800) cout<<"ARC"<<'\n';
  else cout<<"AGC"<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <list>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define ll long long int
#define repeat(n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define llcast static_cast<long long int>

#define PRIME (998244353)
#define MAX_SIZE (3001)

int dp[MAX_SIZE][MAX_SIZE];

int main() {
    int n, s;
    cin >> n >> s;

    vector<int> v;

    repeat(n) {
        int x;
        cin >> x;
        v.push_back(x);
    }

    dp[0][0] = 1;

    repeat(n) {
        for (int j = 0; j <= s; ++j) {
            dp[i + 1][j] = (2ll * dp[i][j] + dp[i + 1][j]) % PRIME;
            int y = v[i] + j;
            if (y <= s) {
                dp[i + 1][y] = (llcast(dp[i + 1][y]) + dp[i][j]) % PRIME;
            }
        }
    }

    cout << dp[n][s];

    return 0;
}

Measured memory_bytes: 38368
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

bool win(int a, int b)
{
  return ((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1));     
}
int main()
{
  while (true) {
    int a[5];
    for (int i = 0; i < 5; i++) {
      scanf("%d ", a + i);
      //printf("%d\n", a[i]);
    }
    if (a[0] == 0) {break;}
  
  
    bool f[] = {false, false, false};
    bool flag = true;
    f[a[0] - 1] = true;
    for (int i = 1; i < 5; i++) {
      if (a[i] != a[i - 1]) {
	flag = false;
      }
      f[a[i] - 1] = true;
    }
    bool aiko = false;
    if (flag) {
      aiko = true;
    } 
    for (int i = 0; i < 3; i++) {
      if (!f[i]) {goto next;}
    }
    aiko = true;
  next:;
    /*for (int i = 0; i < 5; i++) {
      printf("%d\n", a[i]);
      }*/
    for (int i = 0; i < 5; i++) {
      if (aiko) {printf("3\n");}
      else {
	for (int j = 0; j < 5; j++) {
	  if (i == j) {continue;}
	  if (a[i] == a[j]) {continue;}
	  if (win(a[i], a[j])) {
	    printf("1\n");
	    break;
	  } else if (win(a[j], a[i])) {
	    printf("2\n");
	    break;
	  }
	}
      }
    }
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    set<int> st;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    cout << st.size() << endl;
	return 0;
}



Measured memory_bytes: 256
def dist(p, q)
  Math.sqrt((0..2).reduce(0){ |s, i| s + (p[i] - q[i]) ** 2 })
end

gets.to_i.times do
  real = gets.split.map(&:to_f)
  m = gets.to_i
  ps = m.times.map{ gets.split.map(&:to_f) }
  tbl = ps.map{ |p| ps.map{ |q| dist(p, q) } }
  (0...m).to_a.permutation(3) do |i, j, k|
    imag = [tbl[j][k], tbl[k][i], tbl[i][j]]
    if imag.zip(real).map{ |i, r| i / r }.combination(2).map{ |x, y| x / y }.all?{ |v| (1 - v).abs < 0.001 }
      puts [i + 1, j + 1, k + 1].join(' ')
      break
    end
  end
end

Measured memory_bytes: 8896
S =input()
ls_S = list(S)
ans = "YES"

while len(ls_S) != 0:
  if "".join(ls_S[len(ls_S)-5:]) == "dream":
    ls_S = ls_S[:len(ls_S)-5]
  elif "".join(ls_S[len(ls_S)-5:]) == "erase":
    ls_S = ls_S[:len(ls_S)-5]
  elif "".join(ls_S[len(ls_S)-7:]) == "dreamer":
    ls_S = ls_S[:len(ls_S)-7] 
  elif "".join(ls_S[len(ls_S)-6:]) == "eraser":
    ls_S = ls_S[:len(ls_S)-6]
  else:
    ans = "NO"
    break
print(ans)

Measured memory_bytes: 10560
#include <iostream>

using namespace std;

int main()
{
    int A ,B ,C ;
    cin >> A>>B>>C ;
    if (A+B>=C&&1<=A<=500&&1<=B<=500&&1<=C<=1000)
    {
        cout << "Yes" ;

    }else if (C>A+B&&1<=A<=500&&1<=B<=500&&1<=C<=1000)
        cout << "No" ;

    }




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

int main() {
  int h, w;
  while (cin >> h >> w, h | w) {
    string a(w, '#');
    string b = '#' + string(w - 2, '.') + '#';
    cout << a << endl;
    for (int i = 0; i < h-2; i++) {
      cout << b << endl;
    }
    cout << a << endl;
    cout << endl;
  }
}


Measured memory_bytes: 3120
#include <iostream>
#include <queue>
#include <utility>
#include <stdio.h>


using namespace std;

int main()
{
  int n, q;
  scanf("%d %d", &n, &q);
  queue< pair<string, int> > Q;

  string name;
  int time;
  for (int i = 0; i < n; ++i) {
    cin >> name >> time;
    Q.push(make_pair(name, time));
  }

  int time_stamp = 0;
  pair<string, int> candidate;

  while (!Q.empty()) {
    candidate = Q.front();
    if (candidate.second <= q) {
      time_stamp += candidate.second;
      cout << candidate.first << " " << time_stamp  << endl; //output
      Q.pop();
    } else {
      time_stamp += q;
      candidate.second -= q;
      Q.pop();
      Q.push(candidate);
    }
  }
  return 0;
}

Measured memory_bytes: 4456
N, X = map(int, input().split())

max_layer = 50
all_layer = [0]*(max_layer+1)
pate = [0]*(max_layer+1)
all_layer[0] = 1
pate[0] = 1

for i in range(1,max_layer+1):
    all_layer[i] = 2*all_layer[i-1] + 3
    pate[i] = 2*pate[i-1] + 1

def dfs(level, remain):
    ans = 0
    if level == 0:
        return 1

    if remain > 0:
        remain -= 1
    if remain > 0:
        if all_layer[level-1] <= remain:
            remain -= all_layer[level-1]
            ans += pate[level-1]
        else:
            ans += dfs(level-1, remain)
            return ans
    if remain > 0:
        remain -= 1
        ans += 1
    if remain > 0:
        if all_layer[level-1] <= remain:
            remain -= all_layer[level-1]
            ans += pate[level-1]
        else:
            ans += dfs(level-1, remain)
            return ans
    return ans
print(dfs(N, X))

Measured memory_bytes: 38256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

template<class T>
vector<T> make_v(size_t size, const T &init) {
    return vector<T>(size, init);
}
template<class... Ts>
auto make_v(size_t size, Ts... rest) {
    return vector<decltype(make_v(rest...))>(size, make_v(rest...));
}

int main() {
    string s; cin >> s;
    int n = s.size();
    auto dp = make_v(n + 1, 2, 6, 0LL);
    dp[0][0][0] = 1;
    rep(i, n) rep(less, 2) rep(state, 6) rep(d, 10) {
        if (!less && s[i] - '0' < d) break;
        int nless = less | (d < s[i] - '0');
        int nstate = d == 5;
        if (state == 1 && d == 1) nstate = 2;
        if (state == 2) nstate = (d == 5 ? 3 : 4);
        if (state == 3 && d == 1) nstate = 2;
        if (state == 3 && d == 3) nstate = 5;
        if (state == 4 && d == 3) nstate = 5;
        if (state == 5) nstate = 5;
        dp[i + 1][nless][nstate] += dp[i][less][state];
    }
    cout << dp[n][0][5] + dp[n][1][5] << endl;
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


vector<ll> enum_div(ll n){//yakusu
  vector<ll> ret;
  for(ll i=1 ; i*i<=n ; ++i){
      if(n%i == 0){
        ret.push_back(i);
        if(i*i!=n)ret.push_back(n/i);
      }
  }
  return ret;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  vector<ll> A(N);
  FOR(i,0,N) cin >> A[i];

  SORT(A);
  if(A[0] == 1 && N>1 && A[1] == 1){
    cout << 0 << endl;
    return 0;
  }
  if(A[0]==1 && N==1){
    cout << 1 << endl;
    return 0;
  }
  if(A[0] == 1 && N>1 && A[1] > 1){
    cout << 1 << endl;
    return 0;
  }

  vector<ll> se(1000007,0);

  ll ans = 0;
  FOR(i,0,N){
    bool ok = true;
    if(i!=(N-1) && A[i]==A[i+1])ok = false;
    for(auto x:enum_div(A[i])){
      if(se[x])ok = false;
    }
    ans += ok;
    se[A[i]]=1;
  } 
  cout << ans << endl;
}



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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int64_t n = in(), a = in(), b = in(), c = in(), d = in();

  b = abs(b - a);
  for (int64_t l = -(n - 1) * d, r = -(n - 1) * c; l != n * c + d; l += d + c, r += d + c) {
    if (l <= b && b <= r) {
      cout << "YES" << endl;
      return 0;
    }
    // cout << "[" << l << ", " << r << "]" << endl;
  }

  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>
using namespace std;
const long long int mod=1000000009;
const long long int INF=1000000000;
const long long int MAX=1000000000;
int main()
{
	long long int n,a,b;
	vector<long long int> h;
	cin>>n>>a>>b;
	h.resize(n);
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
 
	long long int up=MAX,low=0;
	long long int mid=0;
 
	while(up-low>1)
	{
		mid=(up+low)/2;
		long long int t=0;
		for(int i=0;i<n;i++)
		{
			long long int x=h[i];
			x-=b*mid;
			if (x>0)
			{
				t+=ceil((double)x/(a-b));
			}
		}
        if(t<=mid)
		{
			up=mid;
		}else
		{
			low=mid;
		}
	}
	cout<<up<<endl;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define name(x) #x
using namespace std;


const int INF = INT_MAX;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

const int MAX_SIZE = 22;
int memo[MAX_SIZE][1<<22];
int visited[1<<22];
int N;
VV(int) a;


int main() {

    cin >> N;
    a.resize(N+1);
    for(auto i = 1; i<=N; i++){
        a[i].resize(N+1);
    }
    
    for(auto i = 1; i<=N; i++){
        for(auto j = 1; j<=N; j++){
            cin >> a[i][j];
        }
    }
    
    // dp[i+1][mask] = SUM(dp[i][x] s.t. (mask & x) == x)
    
    queue<int> x;
    
    
    for(auto i = 0; i<N; i++){
        auto mask = 1<<i;
        
        if (a[1][i+1] == 0) continue;
        memo[1][mask] = 1;
        x.push(1<<i);
        visited[1<<i] = 1;
        
    }
    x.push(-1);
    
    for(auto i = 2; i<=N; i++){
        
        while(x.front() !=-1){
            
            auto from = x.front();
            x.pop();
            
            for(auto j = 0; j<N; j++){
                
                if (a[i][j+1] == 0) continue;
                auto temp = (1<<j) + from;
                if ((from >> j)%2 == 1) continue;
                memo[i][temp] += memo[i-1][from];
                memo[i][temp] %=MOD;
                if (visited[temp] == 0) x.push(temp);
                visited[temp] = 1;
            }
        }
        
        
        x.pop();
        x.push(-1);
        
    }
    cout << memo[N][(1<<N)-1] << endl;
    
    
    
    return 0;
}




Measured memory_bytes: 192256