akhauriyash/Code-Regression huggingface dataset:
import java.util.*;



public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int ans=0;
    for(int i=0;i<s.length()-2;i++){
      if(s.substring(i,i+3).equals("ABC")){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n;
    cin >> n;
    int p = 1;
    int ans = 2;
    while(1) {
        if(ans > n) break;
        ans = pow(2, p);
        p++;
    }
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> paii;
typedef complex<double> P;

double ccw(P& p1, P& p2, P& p3)
{
	return ((p2.real() - p1.real())*(p3.imag() - p1.imag()) 
				- (p2.imag() - p1.imag())*(p3.real() - p1.real())) > 0;
}// ccw>0 ...ccw, ccw=0 ...colinear, ccw<0 ...cw

int main()
{
	double x, y;
	P p1, p2, p3, px;
	
	while(cin >> x, !cin.eof())
	{
		cin >> y;
		p1 = P(x, y);
		cin >> x >> y;
		p2 = P(x, y);
		cin >> x >> y;
		p3 = P(x, y);
		cin >> x >> y;
		px = P(x, y);
		
		if(( ccw(p1, p2, px) > 0 && ccw(p2, p3, px) > 0 && ccw(p3, p1, px) > 0)
			||( ccw(p1, p3, px) > 0 && ccw(p3, p2, px) > 0 && ccw(p2, p1, px) > 0))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
#define INFTY 1000000000
#define N 500000
void mergeSort(int *A,int left,int right);
void merge(int *A,int left,int mid,int right);
int cnt=0,n;

int main(){
  int i,A[N];

  scanf("%d",&n);
  if(n <= 0 || n > 500001)
    printf("Error\n");

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    if(i == (n-1)) printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
  printf("%d\n",cnt);
  return 0;
}

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

void merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,k;
  int L[N],R[N];
  
  n1 = mid - left;
  n2 = right - mid;
  for(i=0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFTY; 
  R[n2] = INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i] <= R[j]){
      cnt++;
      A[k] = L[i];
      i++;
    }
    else{
      cnt++;
      A[k] = R[j];
      j++;
    }
  }
  
  
}



Measured memory_bytes: 5596
N=int(input())

statements=[]
honests=[0]
for i in range(N):
  statement=[]
  A=int(input())
  for j in range(A):
    x,y=map(int,input().split(' '))
    statement.append([x-1,y]) 
  statements.append(statement)

#print(statements)
ans=0

for honest in range(1<<N):
  flag=True
  for j in range(N):
    statement=statements[j]
    for x,y in statement:
      if (honest&(1<<j))>>j ==1:
        flag*=((honest&(1<<x))>>x ==y)


    #print(flag)
  if flag==True:
    honests.append(honest)

n_honests=[]
for honest in honests:
  n_honest=0
  for i in range(N):
    n_honest+=(honest&(1<<i))>>i
  n_honests.append(n_honest)

print(max(n_honests))


Measured memory_bytes: 10616
fun main() {
    val X = readLine()!!.toInt()

    val answer = when(X) {
        in 400..599 -> 8
        in 600..799 -> 7
        in 800..999 -> 6
        in 1000..1199 -> 5
        in 1200..1399 -> 4
        in 1400..1599 -> 3
        in 1600..1799 -> 2
        in 1800..1999 -> 1
        else -> 0
    }

    print(answer)
}


Measured memory_bytes: 34568
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

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

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
using namespace std;
long long dp[110][110];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j) dp[i][j]=0;
			else dp[i][j]=100861008610086;
		}
	}
	for(int i=0;i<m;i++){
		long long a,b,c;
		cin>>a>>b>>c;
		dp[a][b]=c;
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(dp[i][k]!=100861008610086&&dp[k][j]!=100861008610086) dp[i][j]=min(dp[i][k]+dp[k][j],dp[i][j]);
			}
		}
	}
	for(int i=0;i<n;i++){
		if(dp[i][i]<0){
			cout<<"NEGATIVE CYCLE\n";
			return 0;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(dp[i][j]>=100861008610086) cout<<"INF";
			else cout<<dp[i][j];
			if(j<n-1) cout<<" ";
		}
		cout<<"\n";
	}
	return 0;
}

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

ll divisors(ll N)
{
    ll ans = INT_MAX;
    for (ll i = 1; i <= sqrt(N); i++) {
        if (N % i == 0) {
            ll x = i;
            ll y = N / i;

            x = floor(log10(x)) + 1;
            y = floor(log10(y)) + 1;

            ll val = max(x, y);
            ans = min(ans, val);
        }
    }
    return ans;
}

int main()
{
    ll N;
    cin >> N;

    ll ans = divisors(N);
    cout << ans << "\n";
}


Measured memory_bytes: 384
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
i = 0

for x in range(H):
    c = []
    for y in range(W):
        c.append(i + 1)
        a[i] -= 1
        if a[i] == 0:
            i += 1
            
    if x % 2 == 0:
        print(*c)
    else:
        print(*c[::-1])

Measured memory_bytes: 9304
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100000],x;
	int i,j,t;
	scanf("%s",a);
	i=strlen(a);
	x=a[(i-1)/2];
	for(j=i/2-1;j>=0;j--)if(a[j]!=x||a[i-1-j]!=x)break;
	t=i-j-1;
	printf("%d\n",t);
	return 0;
}


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

int main(){
  int t, d;
  cin>>t>>d;
  int count=0;
  while (t--){
    double x, y;
    cin>>x>>y;
    if (sqrt(x*x + y*y)<=d) count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3800
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<functional>
using namespace std;

#define BLACK 2LL
#define GRAY 1LL
#define WHITE 0LL
#define TEISU 1000000LL
#define INF 1145141919LL

vector<long long>x[4000];
long long n,m,a,b,c,k,G;
long long s[4000],d[4000],color[4000];
long long X[4000];
double maxn;long long res;

priority_queue<long long,vector<long long>,greater<long long>>Q;

void dijkstra(){
	while(!Q.empty()){
		int A=Q.top()/TEISU;
		int B=Q.top()%TEISU;
		Q.pop();
		color[B]=BLACK;

		if(d[B]<A*(-1))continue;

		for(int v=0;v<x[B].size();v++){
			int w=x[B][v]/TEISU;

			if(color[w]==BLACK)continue;

			if(d[w]>d[B]+x[B][v]%TEISU){

				d[w]=d[B]+x[B][v]%TEISU;
				Q.push(d[w]*TEISU+w);
				color[w]=GRAY;

			}
		}
	}
}

int main(){
	memset(X,63,sizeof(X));
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		cin>>a>>b>>c;
		x[a].push_back(b*TEISU+c);
		x[b].push_back(a*TEISU+c);
	}
	for(int i=0;i<k;i++){
		cin>>a;
		s[a]=1;
	}
	for(int i=1;i<=n;i++){
		if(s[i]==1){
			Q.push(i);
			for(int v=1;v<=n;v++){
				color[v]=WHITE;
				d[v]=INF;
			}
			d[i]=0;
			dijkstra();
			for(int j=1;j<=n;j++){
				X[j]=min(X[j],d[j]);
			}
		}
	}
	for(int i=1;i<=n;i++){
		maxn=max((long long)maxn,X[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<x[i].size();j++){
			if(abs(X[i]-X[x[i][j]/TEISU])<x[i][j]%TEISU){
				a=x[i][j]%TEISU-abs(X[i]-X[x[i][j]/TEISU]);
				maxn=max(maxn,(double)(max(X[i],X[(int)(x[i][j]/TEISU)])+1.0*a/2.0));
			}
		}
	}
	res=(1.0*maxn+0.99999999);
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 6112
#include <cstdio>
#include <vector>
#include <map>
#define N 200005
using namespace std;
int n, k, l, num, u[N], v[N];
vector<int> a[N], b[N];
map<pair<int,int>,int> mp;

void f(int p, int q) {
	if(u[p]) return;
	u[p] = q;
	for(int i=0; i<a[p].size(); i++) {
		f(a[p][i], q);
	}
}

void g(int p, int q) {
	if(v[p]) return;
	v[p] = q;
	for(int i=0; i<b[p].size(); i++) {
		g(b[p][i], q);
	}
}

int main() {
	int i, x, y;
	scanf("%d%d%d", &n, &k, &l);
	while(k--) {
		scanf("%d%d", &x, &y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	while(l--) {
		scanf("%d%d", &x, &y);
		b[x].push_back(y);
		b[y].push_back(x);
	}
	for(i=1, num=0; i<=n; i++) if(!u[i]) f(i, ++num);
	for(i=1, num=0; i<=n; i++) if(!v[i]) g(i, ++num);
	for(i=1; i<=n; i++) mp[{u[i],v[i]}]++;
	for(i=1; i<=n; i++) {
		if(!u[i] || !v[i]) printf("1 ");
		else printf("%d ",  mp[{u[i],v[i]}]);
	}
	return 0;
}

Measured memory_bytes: 27904
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()

A.sort()
m=A[-1]

d=defaultdict(int)
d2=defaultdict(int)

for i in A:
    d2[i]+=1

ans=0
for a in A:
    if d[a]==0:
        if d2[a]<=1:
            ans+=1
        i=a
        while i<=m:
            d[i]=1
            i+=a
print(ans)

Measured memory_bytes: 109904
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
    int64_t v;
    Mint() { v = 0; }
    Mint(int64_t x) { v = x % MOD; if(v < 0)  v += MOD; }

    Mint operator-() { return Mint{-v}; };
    Mint operator+(Mint x) { return Mint(v + x.v); };
    Mint operator-(Mint x) { return Mint(v - x.v); };
    Mint operator*(Mint x) { return Mint(v * x.v); };
    Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

    Mint& operator+=(Mint x) { return *this = (*this + x); };
    Mint& operator-=(Mint x) { return *this = (*this - x); };
    Mint& operator*=(Mint x) { return *this = (*this * x); };
    Mint& operator/=(Mint x) { return *this = (*this / x); };

    static Mint pow(Mint base, int64_t exp) {
        if(exp == 0)  return Mint(1);
        return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
    }

    friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

template<class T> struct Counting {
    Counting(int64_t n) {
        _fact.assign(n+1, 1);
        for(int64_t i = 1; i <= n; i++)  _fact[i] = T(i) * _fact[i-1];
    }

    T fact(int64_t n) {
        assert(0 <= n && n < (int)_fact.size());
        return _fact[n];
    }

    T perm(int64_t n, int64_t k) {
        if(n < k)  return 0;
        return fact(n) / fact(n-k);
    }

    T comb(int64_t n, int64_t k) {
        if(n < k)  return 0;
        return fact(n) / (fact(k) * fact(n-k));
    }

    private:
        vector<T> _fact;
};

int main() {
    Counting<mint> cnt(1e6);

    lint n, k;
    cin >> n >> k;

    vector<lint> a(n);
    for(auto& elem : a)  cin >> elem;

    sort(begin(a), end(a));

    mint sumx = 0, sumn = 0;
    for(lint i=0; i<n; i++) {
        // maxとして選ばれる
        sumx += cnt.comb(i, k-1) * a[i];
        // minとして選ばれる
        sumn += cnt.comb(n-i-1, k-1) * a[i];
    }

    cout << sumx - sumn << endl;
}

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

#define long long long

using namespace std  ;

const int MOD = (int)1e9 + 7;
int main()
{
    ios_base :: sync_with_stdio(false) ;
    cin.tie(nullptr) ;
    long fact [(int)1e5 + 1] ;
    fact[1] = 1 ;
    for(int i = 2 ; i <= 1e5 ; i++)
        fact[i] = fact[i - 1] * i % MOD ;
    int N , M ;
    cin >> N >> M ;
    if(abs(N - M) > 1)
        cout << 0 ;
    else
        cout << (abs(N - M) == 1 ? 1 : 2) * fact[N] * fact[M] % MOD ;

    return 0 ;
}

Measured memory_bytes: 1024
N = int(input())
S = input()
ss = set(S)
ans = 0
for i in range(1000):
    cur_index = 0
    for p in "{:03d}".format(i):
        if p not in ss:
            break
        try:
            idx = S[cur_index:].index(p)
        except:
            break
        else:
            cur_index += idx + 1
    else:
        ans += 1
print(ans)


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

using namespace std;

int n,k,tt,A[600010],st; char sd[200010];
int main()
{
	scanf("%d%d",&n,&k); scanf("%s",sd+1);
	for(int i=1;i<=n;i++) A[i]=sd[i]=='A';
	st=1; for(int i=1;i<=min(n*2,k);i++)
	{
		if(A[st]^tt) A[st]^=1;
		else tt^=1,st++,A[st+n-1]=A[st-1];
	}
	if(k<=n*2)
	{
		for(int i=1;i<=n;i++) 
			printf("%c",A[i+st-1]^tt? 'A':'B');
	}
	else 
	{
		int ty=(k-n*2)&1;
		if(ty&&n&1) A[st]^=1;
		for(int i=1;i<=n;i++) 
			printf("%c",A[i+st-1]^tt? 'A':'B');
	}
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>

using namespace std;

const int MAX = 3000;

int n;

int main(){
    int ans=0;
    int a;
    cin >> n;
    for(int i=0; i < n; i++){
        cin >> a;
        ans += a;
    }

    ans -= n;

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
/**
  * @file pa.cpp
  * @brief atcoder

  *

  * @author yao
  * @date 2018-09-29
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#define N 1048576
#define INF ((int)1e9)
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#endif //DBG

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

char s[N];

int main()
{
    strtok(fgets(s,N,stdin)," \r\t\n");
    for(char *p=s;*p;++p)*p^='1'^'9';
    puts(s);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  using P = pair<Int, Int>;
  vector<P> vp;
  for(Int i=0;i<n;i++){
    Int a,b;
    cin>>a>>b;
    vp.emplace_back(a,b);    
  }
  sort(vp.begin(),vp.end());
  Int ans=0;
  for(auto p:vp){
    Int cnt=min(m,p.second);
    ans+=p.first*cnt;
    m-=cnt;
  }
  cout<<ans<<endl;
  return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    int st = 0;
    rep(i, N){
        //cout << "aho" << endl;
        string S; cin >> S;
        if(S[0] == 'A') st++;
        else{
            st--;
            if(st < 0){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    if(st) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 3168
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int c=0;
    rep(i,n-1)if(s[i]==s[i+1])c++;
    cout<<min(n-1,c+k*2)<<endl;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int main()
{
    int l;
    cin >> l;

    double ans = l*l*l/27.0;
    printf("%lf", ans);

    return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
pair<int, int> to_grid[100000];
long long dp[100000][30] = {};
long long next_itr[100000][30] = {};
int main() {
#define int long long
	int h, w,d;
	cin >> h >> w >> d;
	for (int i = 0; i < h; ++i) {
		for (int q = 0; q < w; ++q) {
			int hoge = 0;
			cin >> hoge;
			to_grid[hoge-1] = make_pair(i,q);
		}
	}
	int grid_size = h * w;
	for (int i = 0; i < grid_size; ++i) {
		int nexting = i + d;
		nexting %= grid_size;
		dp[i][0] = abs(to_grid[i].first - to_grid[nexting].first) + abs(to_grid[i].second - to_grid[nexting].second);
		next_itr[i][0] = nexting;
	}
	for (int i = 1; i < 30; ++i) {
		for (int q = 0; q < grid_size; ++q) {
			dp[q][i] = dp[q][i - 1] + dp[next_itr[q][i - 1]][i - 1];
			next_itr[q][i] = next_itr[next_itr[q][i - 1]][i-1];
		}
	}
	int query;
	cin >> query;
	REP(test_case, query) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		int ans = 0;
		int now_go = a;
		int cnter = (b - a) / d;
		for (int i = 0; i < 30; ++i) {
			if (cnter % 2 == 1) {
				ans += dp[now_go][i];
				now_go = next_itr[now_go][i];
			}
			cnter /= 2;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 48640
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define mod 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  string s; cin>>s;
  if(s=="ABC") cout<<"ARC";
  else cout<<"ABC";
  
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
const int MAXN=3e3+7;
struct PRE {int x,y;} pre[MAXN][MAXN];
string s,t,ans;
int len,f[MAXN][MAXN];
void Getans(int x,int y)
{
	while(f[x][y]&&len)
	{
		int px=pre[x][y].x;
		int py=pre[x][y].y;
		if(f[px][py]!=f[x][y]) ans=ans+s[x-1],len--;
		x=px,y=py;
	}
	for(int i=(int)ans.size()-1;i>=0;i--) cout<<ans[i];
	cout<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0);
	cin>>s>>t;
	for(int i=1;i<=(int)s.size();i++)
		for(int j=1;j<=(int)t.size();j++)
		{
			if(s[i-1]==t[j-1])
			{
				f[i][j]=f[i-1][j-1]+1;
				pre[i][j].x=i-1,pre[i][j].y=j-1;
			}
			else
			{
				if(f[i-1][j]>f[i][j-1])
				{
					f[i][j]=f[i-1][j];
					pre[i][j].x=i-1,pre[i][j].y=j;
				}
				else
				{
					f[i][j]=f[i][j-1];
					pre[i][j].x=i,pre[i][j].y=j-1;
				}
			}
			len=max(len,f[i][j]);
		}
	for(int i=1;i<=(int)s.size();i++)
		for(int j=1;j<=(int)t.size();j++)
			if(f[i][j]==len) {Getans(i,j); return 0;}
}

Measured memory_bytes: 109432
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main (void){
    string s;
    cin >> s;
    int c1 = 0;
    int c2 = 0;
    for(int i = 0; i < s.length(); ++i){
        if(s[i] == '0') ++c1;
        else ++c2;
    }
    int ans = 2 * min(c1,c2);
    cout << ans;
}

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

int main(){
  int N, K;
  cin >> N>> K;
  vector<int>h(N);
  for(int i=0;i<N;i++)
    cin>> h[i];
    int ans=0;
  for(int i=0;i<N;i++){
    if(h[i]>=K)
        ans++;
  }
  cout<< ans<< endl;
}

Measured memory_bytes: 640
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();
		}
		for (int d = n - 1; d > 0; d--) {
			System.out.printf("%d ", a[d]);
		}
		System.out.printf("%d", a[0]);
		System.out.println("");
		sc.close();
	}
}


Measured memory_bytes: 26652
#include<bits/stdc++.h>
using namespace   std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define extreme   inline
#define ppi       pair<ll,pair<ll,ll>>
#define pb        push_back
#define mp        make_pair
#define str       string
#define pi        2*acos(0.0)
#define pr(a,x,n) for(int i=x;i<n;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define test      cout<<"THIS_AND_THIS"<<endl;
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n,m;
	cin>>n>>m;
	if(max(n,m)>=10){cout<<-1;}
	else{cout<<n*m;}
}
int32_t main(){
	kehsihba();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3648
#include <iostream>
#include <math.h>
using namespace std;


float c1x, c1y, c1r, c2x, c2y, c2r;

int judge(){
	float x = max(c1x,c2x) - min(c1x,c2x);
	float y = max(c1y,c2y) - min(c1y,c2y);
	float r = hypot(x,y);
	if(r > c1r + c2r){
		return 4;
	}
	else if(r == c1r + c2r){
		return 3;
	}
	else if(r == max(c1r,c2r) - min(c1r,c2r)){
		return 1;
	}
	else if(r < max(c1r,c2r) - min(c1r,c2r)){
		return 0;
	}
	else{
		return 2;
	}
}


int main(){
	cin >> c1x >> c1y >> c1r;
	cin >> c2x >> c2y >> c2r;
	cout << judge() << endl;
	return 0;
}


Measured memory_bytes: 3280
#include <iostream>

using namespace std;

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

	int ans = 0;
	if (a + b < c) {
		ans = a + 2 * b + 1;
	} else {
		ans = b + c;
	}
	cout << ans << endl;
}


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

int main(){ 
    int a, b;
    cin >> a >> b;
    
    for(int i = 0; i < 10000; i++){
        if(i * 8 / 100 == a && i * 10 / 100 == b){
            
            cout << i << endl;
            return 0;
        }
    }
    
    cout << -1 << endl;
    
}
        


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

typedef long long ll;
typedef unsigned long long llu;

bool compare_pair(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second > b.second;
}

int main(int argc, char *argv[]) {
  ll N;
  cin >> N;

  vector<pair<ll, ll>> A(N);
  ll tmp;
  for (ll i = 0; i < N; ++i) {
    cin >> tmp;
    A[i] = pair<ll, ll>(i, tmp);
  }
  sort(A.begin(), A.end(), compare_pair);

  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    if (A[0].first == i) {
      ans = A[1].second;
    } else {
      ans = A[0].second;
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4736
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;

int H, W;
vector<string> field;
vector<int> sum;

int main() {
    
 
   cin >> H >> W;
  
   field.resize(H);
   sum.resize(H);
  
    for (int h = 0; h < H; ++h) cin >> field[h];

   for (int h = 0; h < H; ++h) {
     
        for (int w = 0; w < W; ++w) {
          
           if(field[h][w]=='#'){
             
             continue;
           }
          
           // cout << field[h][w];
          
           int ans = 0;
           for (int dh = -1; dh <= 1; ++dh) {
            
             for (int dw = -1; dw <= 1; ++dw) {
          
                int nh = h + dh, nw = w + dw;

             // 場外アウトしたり、0 だったりはスルー
               if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
               if (field[nh][nw] == 0) continue;
               
                if(field[nh][nw]=='#'){
             
                   ans++;
                }
               
             }
            
            
            
          }
          
             string foo = to_string(ans);
              
            // char* cstr = foo.c_str();
          
             field[h][w] = foo[0];
          
        }
    }
  
  


    for (int h = 0; h < H; ++h) {
     
       
          
          cout << field[h] <<endl;
          
        
      
    }
   
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    int n;
    cin >> n;
    vi p(n);

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

    int cnt = 0;
    for (int i = 1; i < n - 1; ++i) {
        if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || ((p[i + 1] < p[i] && p[i] < p[i - 1]))) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest20191106
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] v = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int sum = 0;

            for(int i = 0; i < n; i++)
            {
                if(v[i] > c[i])
                {
                    sum += v[i] - c[i];
                }
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13268
class ModCombination():
    def __init__(self, n, mod=998244353):
        self.mod = mod
        self.N = n
        fact = [1, 1] # 元テーブル
        ifact = [1, 1] #逆元テーブル
        inverse = [0, 1] #逆元テーブル計算用テーブル

        for i in range( 2, n + 1 ):
            fact.append( ( fact[-1] * i ) % mod )
            inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
            ifact.append( (ifact[-1] * inverse[-1]) % mod )
        
        self.fact = fact
        self.ifact = ifact
        self.inverse = inverse

    def nCr(self, n, r):
        if r < 0 or r > n:
            return 0
        return self.fact[n] * self.ifact[r] * self.ifact[n-r] % self.mod

    def nPr(self, n, r):
        if r < 0 or r > n:
            return 0
        return self.fact[n] * self.ifact[n-r] % self.mod

def main():
    K = int(input())
    S = input()
    MOD = 10 ** 9 + 7
    N = len(S)
    mc = ModCombination(N+K-1, MOD)

    # 方針
    # SがN文字のとき、
    # S+K文字の文字列からSの文字をどこに配置するか決め、配置を決めたら何パターンあるか計算し、その和をとる
    # 例: S = 'abc', K = 10 のとき, 配置を以下のようにしたとする
    # ***a**b*c****
    # aの前の***にはaを入れない、bの前の**にはbを入れない、cの前の*にはcを入れないようにする
    # 例えば、***ab*b*c**** のように、bの前の**にbを入れてしまうと、
    # ***ab***c**** でパターン数を数えるとき、***ab*b*c****もOKなパターンになるので、最終的に数え上げが重複してしまうため。
    
    # ***a**b*c****
    # この配置のときのパターン数は、
    # [a以外の25文字]^3 x [b以外の25文字]^2 x [c以外の25文字]^1 x [26文字]^4
    # = 26^[最後の文字(c)の後ろの*の数]  x 25^[最後の文字(c)より前にある*の数] 
    # となる。

    # このことから、Sの最後の文字の位置を決めて、それごとにパターン数を数え上げればいいとわかる。

    # Sの最後の文字の後ろの*の数をLとすると、最後の文字より前にある*の数はK-L個
    # 最後の文字以外のN-1文字とK-L個の*の配置パターンは、
    # (N-1+K-L)_C_(N-1) (n_C_r = 組み合わせ)
    # この配置パターンそれぞれに、26^L x 25^(K-L) のパターンがある

    ans = 0
    # Sの最後の文字の後ろの*の数
    for L in range(K+1):
        index_pattern = mc.nCr(N-1+K-L, N-1)
        char_pattern = pow(26, L, MOD) * pow(25, K-L, MOD) % MOD
        ans = (ans + index_pattern * char_pattern) % MOD

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 226784
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll tot = 0;
  rep(i,n) {
    cin >> a[i];
    tot ^= a[i];
  }

  for (ll i = 0; i < n; i++) {
    ll tmp = tot ^ a[i];
    cout << tmp << " ";
  }
  cout << endl;
}


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


public class Main {


//	final int MOD = 1000000007;

	public static long ans = 0;

	public static void main(String[] args) {

//		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

//		long a = sc.nextLong();

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

		Arrays.sort(a);


		//-------------------------------------------------------------------------------------
		int tmp = 0;
		ans += a[n - 1];
		for(int i = n - 2; i > tmp; i--) {
			ans += a[i];
			tmp++;
			if(i > tmp) {
				ans += a[i];
			}
		}

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

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 61280
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()
ans = 0
for b in B:
    num_a = bisect.bisect_left(A, b)
    num_c = N - bisect.bisect_right(C, b)

    ans += num_a * num_c
print(ans)

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

const int maxn = 100100;
vector<int> g[maxn];

int dfs(int u, int prev = -1) {
  if ((int) g[u].size() > 2) {
    return u;
  }
  for (int v : g[u]) {
    if (v == prev) {
      continue;
    }
    return dfs(v, u);
  }
  return -1;
}

signed main() {
#ifdef LOCAL
  assert(freopen("e.in", "r", stdin));
#endif
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  set<int> ss;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    if ((int) g[i].size() == 1) {
      int u = dfs(i);
      if (u == -1) {
        // Path
        cout << 1 << '\n';
        return 0;
      }
      ss.insert(u);
      ++res;
    }
  }
  cout << res - (int) ss.size() << '\n';
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
//#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
/*ll ncr(ll n,ll r)
{
	if(n==1 || r==0)
	return 1;
	if(r>n/2)
	r=n-r;
	ll ans=1;
	for(ll i=1;i<=r;i++)
	{
		ans=((ans * n )/i);
		n--;
	}
	return ans;
}*/
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow(ll a,ll b,ll m)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)
			ans=(ans*a)%m;
		b=b/2;
		a=(a*a)%m;
	}
	return ans;
}
 
ll modinv(ll k)
{
	return pow(k,MOD-2,MOD);
}

ll ncr(ll n,ll c)
{
    ll t=1;
    c=min(c,n-c);
    for(ll i=1;i<=c;i++)
    {
     	t=(t*(n-i+1))%MOD;
        t=(t*modinv(i))%MOD;
	}
    return t;
}
int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll k=n/(a+b);
	ll h=n%(a+b);
	n=n-k*(a+b);
	ll ans=k*a;
	n=min(a,n);
	ans=ans+n;
	cout<<ans;
}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function unionFind(n){this.a=Array(n+1).fill(-1);}
unionFind.prototype={
  root:function(i){return this.a[i]<0?i:this.a[i]=this.root(this.a[i]);},
  same:function(x,y){return this.root(x)===this.root(y);},
  unite:function(x,y){x=this.root(x);y=this.root(y);if(x===y)return 1;if(this.a[y]<=this.a[x])this.a[y]+=this.a[x],this.a[x]=y;else this.a[x]+=this.a[y],this.a[y]=x;},
  size:function(i){return -this.a[this.root(i)];},
}

console.log(main());
function main(){
  var n = o.a();
  var uf = new unionFind(2e5);
  for(var i = 0; i < n; i++){
    var t = o.l();
    uf.unite(t[0],1e5+t[1]);
  }
  var a = xArray("[]",2e5+1);
  for(var i = 1; i <= 2e5; i++){
    a[uf.root(i)].push(i);
  }
  var ans = -n;
  for(var i = 1; i <= 2e5; i++){
    var h = 0, w = 0;
    for(var j of a[i]){
      if(j <= 1e5)h++;else w++;
    }
    ans += h*w;
  }
  return ans;
}

Measured memory_bytes: 95976
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cassert>
#include<map>

using namespace std;

#define fi first
#define se second
#define rep(i,s,t) for(int i=(s),_t=(t);i<_t;++i)
#define per(i,s,t) for(int i=(t)-1,_s=(s);i>=_s;--i)
#define debug(x) cerr<<#x<<" == "<<(x)<<endl
#define bug(x) cerr<<#x<<" == "<<(x)<<" "

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

template<class T>inline void rd(T &x){
	static char c,f;
	x=0;f=1;
	while(c=getchar(),c<48)if(c=='-')f=-1;
	do x=x*10+(c&15);
	while(c=getchar(),c>47);
	x*=f;
}

template<class T>void pf(T x){
	if(x<0)putchar('-'),x=-x;
	else if(!x){putchar('0');return ;}
	static int stk[100],tp;
	for(tp=0;x;x/=10)stk[tp++]=x%10;
	while(tp)putchar(stk[--tp]^48);
}

template<class T>void ptn(T x){pf(x),putchar('\n');}
template<class T>void ptk(T x){pf(x),putchar(' ');}
template<class T>void Min(T &A,T B){if(A>B)A=B;}
template<class T>void Max(T &A,T B){if(A<B)A=B;}

int n,A,B,C,D;
int main(){
	rd(n),rd(A),rd(B),rd(C),rd(D);
	n-=1;
	rep(i,0,n+1){
		ll a=A+(ll)i*C,b=A+(ll)i*D;
		//[a,b]
		int j=n-i;
		a-=(ll)j*D,b-=(ll)j*C;
		if(a<=B&&B<=b){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;
ll modPow(ll a, ll x, ll p) {
    ll res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

ll modInverse(ll a, ll p) {
    return modPow(a, p-2, p);
}
ll nck(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; 
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    return ( numerator* modInverse(denominator,p) ) % p;
}
signed main()
{
    fast;
   
    ll  n,a,b;
    cin>>n>>a>>b;
    ll ans = modPow(2LL,n,mod) - 1LL;
    ans = (ans - nck(n,a,mod) + mod)%mod;
    ans = (ans - nck(n,b,mod) + mod)%mod;
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef pair<ll,ll> P;
#define se second
#define fi first
struct PP{ll fi;ll se;ll th;};
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n;cin>>n;
    string s;cin>>s;
    vvi v(10);
    rep(i,n)v[s[i]-'0'].pb(i);
    ll ans=0;
    rep(i,10){
        rep(j,10){
            rep(k,10){
                if(v[i].size()==0||v[j].size()==0||v[k].size()==0)continue;
                int wi=v[i][0];
                auto wj=lower_bound(all(v[j]),v[i][0]+1);
                if(wj==v[j].end())continue;
                auto wk=lower_bound(all(v[k]),*wj+1);
                if(wk==v[k].end())continue;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

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

int main(){
    int n, x;
    cin >> n >> x;
    vl a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0LL;
    rep(i, n-1) {
        ll d = (a[i]+a[i+1]) - x;
        if(d < 0) continue;
        ans += d;
        a[i+1] = max(0LL, a[i+1]- d);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
<?php
$input = file_get_contents('php://stdin');
$busStop = str_split($input);

$one = $busStop[0];
$two = $busStop[1];
$three = $busStop[2];

if($one==$two and $one==$three){
    echo "No";
}
else{
    echo "Yes";
}

?>

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    int n,k;cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)cin>>h[i];
    sort(h,h+n);
    int ans=(int)MOD*MOD;
    for(int i=0;i+k<=n;i++){
        int ma=h[i+k-1],mi=h[i];
        //printf("%lld番目:  max:%lld min:%lld SA:%lld\n",i,ma,mi,ma-mi);
        ans=min(ans,ma-mi);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll a,p;
  cin >> a >> p;
  cout << (3*a+p)/2 << endl;
}

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

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int a[110];
map<int,int> num;
map<pair<PII,int>,int> res;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        num[a[i]]++;
    }
    LL ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        for(int k=j+1;k<=n;k++)
        {
            if(a[i]==a[j]||a[j]==a[k]||a[i]==a[k]) continue;
            int m[3]={a[i],a[j],a[k]};
            sort(m,m+3);
            int x=m[0],y=m[1],z=m[2];
            if(x+y>z&&x+z>y&&y+z>x)
            {
                if(res[{{x,y},z}]) continue;
                res[{{x,y},z}]++;
                ans+=num[x]*num[y]*num[z];
            }
        }
    cout<<ans<<endl;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    char c;
    int q, qt, f;
    cin >> s;
    cin >> q;
    bool rev = false;
    deque<char> dq;
    for (int i = 0; i < sz(s); i++) dq.push_back(s[i]);
    while (q--) {
        cin >> qt;
        if (qt == 1) {
            rev = !rev;
        } else {
            cin >> f >> c;
            if (f == 1) {
                if (rev) {
                    dq.push_back(c);
                } else {
                    dq.push_front(c);
                }

            } else {
                if (rev) {
                    dq.push_front(c);
                } else {
                    dq.push_back(c);
                }
            }
        }
    }
    string res = "";
    while (!dq.empty()) {
        res += dq.back();
        dq.pop_back();
    }
    if (!rev) {
        reverse(all(res));
    }
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 1368
N, M, X = map(int,input().split())
A = list(map(int,input().split()))
left, right = X, X
left_cost, right_cost = 0, 0
for i in range(N+1):
  left -= 1
  right += 1
  if(left in A):
    left_cost += 1
  if(right in A):
    right_cost += 1
print(min(left_cost, right_cost))

Measured memory_bytes: 3060