akhauriyash/Code-Regression huggingface dataset:
def main():
    n=int(input()) 
    p = input().split()
    for i in range(n):
        p[i]=float(p[i])    
    dp=[[0 for _ in range(n+1)] for _ in range(n+1)]
    dp[0][0]=1
    for i in range(1,n+1):
        for j in range(n+1):
            dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1])
        
    ans=0
    for i in range((n+1)//2):
        ans+=dp[n][-i-1]
    print(ans)

if __name__ == "__main__":
    main()

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int solve(string ss, int p, int q, int r) {
  if (ss[0] == '-') {
    int j = 0;
    while(ss[j] == '-') j++;
    int tmp = solve(ss.substr(j, ss.length() - j), p, q, r);
    if (j % 2 == 1 && tmp != 1) {
      if (tmp == 2) tmp = 0;
      else tmp = 2;
    }
    return tmp;
  } else if (ss[0] == '(') {
    int j = 1, f = 0, op = 0, k = 0;

    while(j < ss.length() - 1) {
      if (ss[j] == '(') f++;
      else if (ss[j] == ')') f--;
      else if (f == 0 && ss[j] == '*') op = 1, k = j;
      else if (f == 0 && ss[j] == '+') op = 0, k = j;
      j++;
    }
    int a = solve(ss.substr(1, k - 1), p, q, r);
    int b = solve(ss.substr(k + 1, ss.length() - 2 - k), p, q, r);

    if (op) {
      return min(a, b);
    } else {
      return max(a, b);
    }
  } else if (ss[0] == 'P') {
    return p;
  } else if (ss[0] == 'Q') {
    return q;
  } else if (ss[0] == 'R') {
    return r;
  } else {
    return ss[0] - '0';
  }
}

int main(){
  cin.sync_with_stdio(false);
  string s;
  while(cin >> s, s[0]!='.') {
    int ans = 0;
    rep(i, 27) {
      int p = i % 3, q = (i / 3) % 3, r = (i / 9) % 3;
      int tmp = solve(s, p, q, r);
      if (tmp == 2) ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int A,B,C,X,tmp=0;
  cin>>A>>B>>C>>X;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        int total=500*i+100*j+50*k;
        if(total==X){
          tmp++;
        }
      }
    }
  }
  cout<<tmp;

}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String[] tairu = S.split("");
        int not01 = 0;
        int not10 = 0;
        for(int i=0; i<tairu.length; i++) {
            if(i % 2 == 0) {
                if(tairu[i].equals("0")) {
                    not10++;
                }else {
                    not01++;
                }
            }else {
                if(tairu[i].equals("1")) {
                    not10++;
                }else {
                    not01++;
                }
            }
        }
        
        if(not10 >= not01) {
            System.out.println(not01);
        }else {
            System.out.println(not10);
        }
    }
}

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

#define ull unsigned long long
#define ll long long
#define imei(...)   "[ "<< #__VA_ARGS__ <<" = "<< __VA_ARGS__ <<" ] "

using namespace std;

void solve(int t) {
    int n;
    cin >> n;
}

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

    if (c >= 30)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#define N 100

int main()
{
   int M[N][N];
   int i, j, n, u, k, v;

   scanf("%d", &n);

   for (i=0; i<n; i++){
      for (j=0; j<n; j++)
         M[i][j] = 0;
   }

   for (i=0; i<n; i++){
      scanf("%d %d", &u, &k);
      u--;
      for (j=0; j<k; j++){
         scanf("%d", &v);
         v--;
         M[u][v] = 1;
      }
   }

   for (i=0; i<n; i++){
      for (j=0; j<n; j++){
      if (j)
         printf(" ");
      printf("%d", M[i][j]);
      }
      printf("\n");
   }

   return 0;
}

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

int main() {
	int64_t n, k;
	cin >> n >> k;

	// 選ぶ個数の最大値は n+1
	// 選ぶ個数の最小値は k
	int64_t a, b;
	// 全数選んだパターンをカウントしておく
	int64_t sum=1;
	// 全数未満のパターンについて
	for (int64_t i = k; i <= n; i++) {
		// 最小k個選ぶ時の最小値は 0...(k-1)までの和
		a = (0 + i-1) * i/2;
		// 最小k個選ぶ時の最大値は (n-k+1)...(n)までの和
		b = (n-i+1 + n) * i/2;
		// 間の数はいくらでも作れる
		sum += (b-a)+1;
		// 多くなったら削る
		if (sum > 1000000007LL) {
			sum = sum % 1000000007LL;
		}
	}
	cout << sum << '\n';
}


Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)

const int INF = 1e9 + 1000;
const li INF64 = 1e15 + 1000;
const int M = 100 + 10;
const int N = 100 * 1000 + 100;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = 3.14159265359;

li gcd(li a, li b) {
    return a == 0 ? b : gcd(b % a, a);
}

li dp[M][N];

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<int> w(n), v(n);
    forn(i, n) {
        cin >> w[i] >> v[i];
    }

    forn(i, M) {
        fore(j, 1, N) {
            dp[i][j] = INF64;
        }
    }

    int ans = 0;
    fore(i, 1, n + 1) {
        fore(j, 1, N) {
            dp[i][j] = dp[i - 1][j];
            if (j - v[i - 1] >= 0) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
            }
            if (dp[i][j] <= m) {
                ans = max(ans, j);
            }
        }
    }

    cout << ans << '\n';
    
    
}

Measured memory_bytes: 86272
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main()
{
    long long A, B, C, X, Y;
    long long M, sum, tmp;

    scanf("%lld %lld %lld %lld %lld", &A, &B, &C, &X, &Y);

    C *= 2;

    M = min(X, Y);

    sum = min(M*A+M*B, M*C);

    M = abs(X-Y);

    if(X > Y)
        tmp = M*A;
    else if(X < Y)
        tmp = M*B;

    if(tmp > M*C)
        tmp = M*C;

    printf("%lld", sum+tmp);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

int n, k, fruits[1001], ans;

int main() {
    cin >> n >> k;

    for (int i = 0; i < n; ++i)
        cin >> fruits[i];

    sort (fruits, fruits+n);

    for (int i = 0; i < k; ++i)
        ans += fruits[i];

    cout << ans;
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  ll N;
  cin >> N;
  ll d[N];
  rep(i, N) cin >> d[i];
  sort(d, d+N);

  cout << (d[N/2] - d[N/2-1]) << endl;
  return 0;
}


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

long insertionSort(int a[], int n, int g)
{
    long cnt = 0;

    for (int i = g; i < n; i++) {
        int v = a[i];
        int j = i - g;
        while (j >= 0 && a[j] > v) {
            a[j + g] = a[j];
            j -= g;
            cnt++;
        }
        a[j + g] = v;
    }

    return cnt;
}

void shellSort(int a[], int n)
{
    vector<int> G;

    int g = 1;
    while (g <= n) {
        G.push_back(g);
        g = 3 * g + 1;
    }

    sort(G.begin(), G.end(), greater<int>());

    long cnt = 0;
    for (auto i : G) {
        cnt += insertionSort(a, n, i);
    }

    cout << G.size() << endl;

    for (int i = 0; i < G.size(); i++) {
        if (i) {
            cout << " ";
        }
        cout << G[i];
    }
    cout << endl;

    cout << cnt << endl;
}

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

    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];

    shellSort(a, n);

    for (int i = 0; i < n; i++) cout << a[i] << endl;

    return 0;
}



Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,b;cin>>n>>a>>b;
	puta(n/(a+b)*a + min((n%(a+b)),a));
	return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
#define MAX 210
char c[MAX][MAX];
int p[MAX][MAX], s[MAX][MAX];
int H, W;
bool inrange(int i, int j) {
	return 0 <= i&&i < H && 0 <= j&&j < W;
}
int di[] = { 1,0,-1,0 };
int dj[] = { 0,1,0,-1 };
int bfsp(int si, int sj) {
	queue<pair<int, int>> Q, NQ;
	NQ.emplace(si, sj);
	int cnt = 0;
	while (NQ.size()) {
		swap(Q, NQ);
		while (Q.size()) {
			auto a = Q.front(); Q.pop();
			int i = a.first, j = a.second;
			if (!inrange(i, j))continue;
			if (c[i][j] == '#')continue;
			if (p[i][j] <= cnt)continue;
			p[i][j] = cnt;
			if (c[i][j] == '%')return cnt;
			rep(h, 0, 4) {
				NQ.emplace(i + di[h], j + dj[h]);
			}
		}
		cnt++;
	}
	return INF;
}
int bfss(int si, int sj) {
	queue<pair<int, int>> Q, NQ;
	NQ.emplace(si, sj);
	int cnt = 0;
	while (NQ.size()) {
		swap(Q, NQ);
		while (Q.size()) {
			auto a = Q.front(); Q.pop();
			int i = a.first, j = a.second;
			if (!inrange(i, j))continue;
			if (c[i][j] == '#')continue;
			if (s[i][j] <= cnt)continue;
			s[i][j] = cnt;
			if (c[i][j] == '$')return cnt;
			rep(h, 0, 4) {
				NQ.emplace(i + di[h], j + dj[h]);
			}
		}
		cnt++;
	}
	return INF;
}

signed main() {
	cin >> H >> W;
	int si = -1, sj;
	memset(p, 0x3f, sizeof(p));
	memset(s, 0x3f, sizeof(s));
	rep(i, 0, H)rep(j, 0, W) {
		cin >> c[i][j];
	}
	int a = INF;
	rep(i, 0, H)rep(j, 0, W) {
		if (c[i][j] == '@')a = bfsp(i, j);
	}
	int b = INF;
	rep(i, 0, H)rep(j, 0, W) {
		if (c[i][j] == '%')chmin(b, bfss(i, j));
	}

	if (a >= b)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> table = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  int a,b;
  cin >> a >> b;
  if (table.at(a) == table.at(b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl

int main() {
  int n, a;
  cin >> n >> a;
  if (n % 500 <= a) {
    coYes;
  }
  else {
    coNo;
  }
}


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

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let abc: Vec<usize> = read_vec();
  let uniq: HashSet<usize> = abc.into_iter().collect();

  let ans = if uniq.len() == 2 {
    "Yes"
  } else {
    "No"
  };

  println!("{}", ans);

}

Measured memory_bytes: 4352
#include <iostream>
#include<algorithm>
#include<set>
#include<iterator>
#include<map>
#include<unordered_map>
#include<vector>
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define pb push_back
#define F first
#define S second

int32_t main() {
   
    string a,b;
    cin>>a>>b;
    
    sort(a.begin(),a.end());
    sort(b.begin(),b.end(),greater<char>());
   
     int n = min(a.size(),b.size());
    
    /*for(int i=0;i<n;++i)
    {
        if(a[i]<b[i])
        {
            cout<<"Yes";
            return 0;
    
    }
    if(a.size()>=b.size())
        cout<<"No";
    else
        cout<<"Yes";
    */
    if(a<b)
        cout<<"Yes";
    else
        cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	string s;
	cin >> s;
	if (N >= 3200)cout << s << endl;
	else cout << "red" << endl;
}

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

#define M 1046527/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return /* your task */key%M; }
int h2(int key){ return /* your task */1+(key%(M-1)); }

int find(char str[]){

    /* your task */
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}

int insert(char str[]){

    /* your task */
 long long key,i,h;
 key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
     if(strcmp(H[h],str)==0)return 1;
     else if(strlen(H[h])==0){
       strcpy(H[h],str);
       return 0;
     }
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    int J[1000000],count=0;
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
	      J[count++]=1;
	    } else {
		J[count++]=0;
	    }
	}
    }
    for(i=0;i<count;i++){
      if(J[i]==1)printf("yes\n");
      else printf("no\n");
    }
    return 0;
}



Measured memory_bytes: 17660
from bisect import bisect_left
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))
i = 0
if N == 0:
  print(X)
else:
  while True:
    x = X-i
    idx = bisect_left(P, x)
    if idx < 0 or idx >= N or P[idx] != x:
      print(x)
      break
    else:
      x = X+i
      idx = bisect_left(P, x)
      if idx < 0 or idx >= N or P[idx] != x:
        print(x)
        break
    i += 1

Measured memory_bytes: 62008
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

signed main() {
    int N;
    cin >> N;
    vector<int>ans(N);
    for(int i = 1; i < N; i++) {
        int A;
        cin >> A;
        A--;
        ans[A]++;
    }
    for(int i = 0; i < N;  i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 4764
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  
  string n;
  cin >> n;
  string ans = "";
  for(int i=0;i<3;i++){
    if(n[i]=='9') ans += '1';
    if(n[i]=='1') ans += '9';
  }
  cout << ans <<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	cout<<max({a+a-1,a+b,b+b-1})<<endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	string n; cin >> n;
	rep(i, n.size()) {
		if (n[i] == '1') n[i] = '9';
		else n[i] = '1';
	}
	cout << n << endl;
}


Measured memory_bytes: 256
import numpy as np
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

s = input()
p = g = ans = 0
for i in s:
    if i=='p':
        if p < g: p += 1
        else: ans -= 1; g += 1
    if i=='g':
        if p < g: ans += 1; p += 1
        else: g += 1
print(ans)

Measured memory_bytes: 12684
h,w = map(int, input().split())
grid = [[0]*(w+2) for _ in range(h+2)]
original = [0]*h
for i in range(h):
  original[i] = input()
for i in range(h):
  for j in range(w):
    if original[i][j]=='#':
      grid[i][j] += 1
      grid[i+1][j] += 1
      grid[i+2][j] += 1
      grid[i][j+1] += 1
      grid[i][j+2] += 1
      grid[i+1][j+1] += 1
      grid[i+1][j+2] += 1
      grid[i+2][j+1] += 1
      grid[i+2][j+2] += 1

for i in range(h):
  output=''
  for j in range(w):
    if original[i][j]=='.':
      output+= str(grid[i+1][j+1])
    else:
      output += '#'
  print(output)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,q;
int type[40005],f[40005],t[40005];
int B=200;
set<int> G[40005];
multiset<int> G2[405];
multiset<int> bridge[405];
set<int> tgt;
int cmp[40005];
bool used[405];

void dfs(int v,int c){
	cmp[v]=c;
	for(set<int>::iterator it=G[v].begin();it!=G[v].end();it++){
		if(cmp[*it]==-1){ 
			if(tgt.find(v)==tgt.end() || tgt.find(*it)==tgt.end()){
				dfs(*it,c);
			}else{
				bridge[c].insert(*it);
			}
		}
	}
}

void dfs2(int v){
	used[v]=true;
	for(multiset<int>::iterator it=G2[v].begin();it!=G2[v].end();it++){
		if(!used[*it]){
			dfs2(*it);
		}
	}
}

int main(void){
	scanf("%d%d",&n,&q);
	for(int i=0;i<q;i++){
		scanf("%d%d%d",&type[i],&f[i],&t[i]);
	}
	for(int i=0;i<q;i++){
		if(i%B==0){
			memset(cmp,-1,sizeof(cmp));
			tgt.clear();
			for(int j=0;j<B*2;j++){
				G2[j].clear();
				bridge[j].clear();
			}
			for(int j=0;(j<B && i+j<q);j++){
				tgt.insert(f[i+j]);
				tgt.insert(t[i+j]);
			}
			int k=0;
			for(set<int>::iterator it=tgt.begin();it!=tgt.end();it++){
				if(cmp[*it]==-1){
					dfs(*it,k++);
				}
			}
			for(int j=0;j<k;j++){
				for(multiset<int>::iterator it=bridge[j].begin();it!=bridge[j].end();it++){
					int nv=cmp[*it];
					G2[j].insert(nv);
					G2[nv].insert(j);
				}
			}
		}
		if(type[i]==1){
			G[f[i]].insert(t[i]);
			G[t[i]].insert(f[i]);
			G2[cmp[f[i]]].insert(cmp[t[i]]);
			G2[cmp[t[i]]].insert(cmp[f[i]]);
		}
		if(type[i]==2){
			G[f[i]].erase(t[i]);
			G[t[i]].erase(f[i]);
			multiset<int>::iterator it=G2[cmp[f[i]]].lower_bound(cmp[t[i]]);
			if(it!=G2[cmp[f[i]]].end() && *it==cmp[t[i]]){
				G2[cmp[f[i]]].erase(it);
			}
			it=G2[cmp[t[i]]].lower_bound(cmp[f[i]]);
			if(it!=G2[cmp[t[i]]].end() && *it==cmp[f[i]]){
				G2[cmp[t[i]]].erase(it);
			}
			
		}
		if(type[i]==3){
			memset(used,false,sizeof(used));
			dfs2(cmp[f[i]]);
			printf("%s\n",used[cmp[t[i]]]?"YES":"NO");
		}
	}
	return 0;
} 


Measured memory_bytes: 9392
# -*- coding: utf-8 -*-
H, W=map(int,input().split())
s=[[0]*(W+2) for i in range(H+2)]
for ii in range(1,H+1):
    A=list(input())
    for jj in range(1,W+1):
        if A[jj-1]=='#':
            s[ii][jj]=1
can=1
for ii in range(1,H+1):
    for jj in range(1,W+1):
        if s[ii][jj]==1:
            if s[ii-1][jj]+s[ii+1][jj]+s[ii][jj-1]+s[ii][jj+1]==0:
                can=0
                break
    if can==0:
        break

if can==1:
    print('Yes')
else:
    print('No')
            


Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  cin>>N;
  vector<int> s(N);
  int max=0;
  int tmp=0;
  for (size_t i = 0; i < N; i++) {
    cin>>s[i];
  }
  sort(s.begin(),s.end());
  for (size_t i = 0; i < N; i++) {
    max+=s[i];
  }
  for (size_t i = 0; i < N; i++) {
    if(max%10!=0){
      printf("%d\n", max);
      return 0;
    }
    if(s[i]%10!=0){
    max-=s[i];
    }
  }

  printf("0\n",max);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  char a, b;
  cin >> a >> b;
  if (a == 'H')
    cout << b << endl;
  else	{
    if (b == 'H') cout << 'D' << endl;
    else cout << 'H' << endl;
  }
  return 0;
}

Measured memory_bytes: 3608
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w,a,b = map(int, input().split())
ans = [None for _ in range(h)]
for i in range(h):
    if i<b:
        ans[i] = [0]*a + [1]*(w-a)
    else:
        ans[i] = [1]*a + [0]*(w-a)
write("\n".join("".join(map(str, item)) for item in ans))

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

using namespace std;
int a,d,n;
bool num[1000000 + 1];
vector<int> prime;
void serchPrime(){

  for(long i = 2; i < 1000000 ; i++){
    if(!num[i]){
      prime.push_back(i);
      for(long k = 1; i * k < 1000000 ; k++){
        num[i * k] = true;
      }
    }
  }
}

void solve(){

  int counta = 0;
  int primeCounta = 0;
  while(true){
    if(prime[primeCounta] < a){
      primeCounta++;
    }else if(prime[primeCounta] == a){
      counta ++;
      primeCounta++;
      break;
    }else{
      break;
    }
  }

  if(counta != n){
    for(int i = a; i < 1000000 ; ){
      i += d;
      while(true){
        // cout << "i = "<< i << endl;
        // cout << "Pcounta ="<<primeCounta << endl;
        if(prime[primeCounta] < i){
          primeCounta++;
        }else if(prime[primeCounta] == i){
          counta ++;
          primeCounta++;
          break;
        }else{
          break;
        }
      }
        if(counta == n) break;
    }
  }
  cout << prime[primeCounta - 1] << endl;

}

int main(){
  serchPrime();
  while(true){
    cin >> a >> d >> n;
    if(n == 0 && d == 0 && n == 0 )break;
    solve();
  }

  return 0;
}



Measured memory_bytes: 4332
#include <bits/stdc++.h>
#define reps(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define rep(i, n) reps(i, 0, n - 1)
#define sper(i, s, n) for (int i = (s); i >= (int)(n); i--)
#define per(i, n) sper(i, n - 1, 0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b(n);
    rep(i, n) b[i] = a[i] - (i + 1);
    sort(b.begin(), b.end());
    int center = b[n / 2];
    ll ans = 0;
    rep(i, n) ans += abs(b[i] - center);
    cout << ans << endl;
}

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

Measured memory_bytes: 4836
module Main where
import Data.Char
import Data.List
int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = tail . map int . words
printer = unlines . (:[]) . show

solver as = alice - bob
  where
    sorted = zip [1..] (reverse $ sort as)
    alice = sum $ map snd $ filter (odd . fst) sorted
    bob = sum $ map snd $ filter (even . fst) sorted

Measured memory_bytes: 892
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cctype>
#include <ctime>
#include <algorithm>

int nextch(void)
{
    static char bufdatum[BUFSIZ];
    static char *buf = bufdatum, *endbuf = bufdatum;
    if (endbuf == buf)
    {
        endbuf = (buf = bufdatum) + fread(bufdatum, 1, BUFSIZ, stdin);
        if (endbuf == buf)
            return EOF;
    }
    return *buf++;
}

void legit(void) {}

template<typename Car, typename ...Cdr>
void legit(Car &var, Cdr &...Rest)
{
    int peek;
    while (!isdigit(peek = nextch())
#ifdef LEGIT_NEGI
        && peek != '-'
#endif  // LEGIT_NEGI
        )
        ;
#ifdef LEGIT_NEGI
    bool negi;
    if (peek == '-')
        negi = true;
    else
        negi = false;
#endif  // LEGIT_NEGI
    var = 0;
    do
        var = (((var << 2) + var) << 1) + (peek ^ '0');
    while (isdigit(peek = nextch()));
#ifdef LEGIT_NEGI
    if (negi)
        var = -var;
#endif  // LEGIT_NEGI
    legit(Rest...);
}

void solve(void);

int main(void)
{
#ifdef redirect
    freopen("check/data.in", "r", stdin);
    freopen("check/prog.out", "w", stdout);
    freopen("check/log.out", "w", stderr);
#endif  // redirect
#ifdef chrono
    auto begtm = clock();
#endif  // chrono
    solve();
#ifdef chrono
    auto endtm = clock();
    printf("%f\n", static_cast<float>(endtm - begtm) / CLOCKS_PER_SEC);
#endif  // chrono
    return 0;
}

typedef long long laolin;

const size_t MaxN = 100 + 7;

size_t n;

void solve(void)
{
    // Init
    legit(n);
    laolin big = 0, small = static_cast<laolin>(1e9 + 7);
    for (size_t i = 0; i < n; ++i)
    {
        laolin now;
        legit(now);
        small = std::min(small, now);
        big = std::max(big, now);
    }
    printf("%lld\n", big - small);
}



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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
//#define TEST

int main(int argc, char** argv) {
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\stdout", "w", stdout);
    }

    int Q;
    ll sumb = 0, suma1 = 0, suma2 = 0;
    priority_queue<int, vector<int>, less<int>> S1;
    priority_queue<int, vector<int>, greater<int>> S2;

    cin >> Q;
    FOR(i, Q){
        int type;
        cin >> type;
        if (type == 1){
            int a, b;
            cin >> a >> b;
            sumb += b;
            if (S1.empty() || a <= S1.top()){
                S1.push(a);
                suma1 += a;
            }
            else {
                S2.push(a);
                suma2 += a;
            }
            if (S2.size() > S1.size()){
                int x = S2.top();
                S2.pop(); suma2 -= x;
                S1.push(x); suma1 += x;
            }
            if (S1.size() > S2.size()+1){
                int x = S1.top();
                S1.pop(); suma1 -= x;
                S2.push(x); suma2 += x;
            }
        } else{
            ll median = S1.top();
            cout << median << ' ' << sumb + (ll)S1.size() * median - (ll)S2.size() * median - suma1 + suma2 << '\n';
        }
    }

    //if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


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

using namespace std;

int main(){
        int x=0, N;
        cin>>N;
        string str;
        cin>>str;
        int res=0;
        for(int i=0;i<N;i++){
                if(str[i]=='I'){
                        x++;
                }
                else{
                        x--;
                }
                res=max(res, x);
        }
        cout<<res<<endl;
        return 0;
}


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

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

    if (N >= 10)
    {
        cout << R << endl;
    }
    else
    {
        int ans = R + (100 * (10 - N));
        cout << ans << endl;
    }
}


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

int main(){
  int  a[nmax]={},n,max1=-1,max2=-1,x;
   cin>>n;
   for(int i=1;i<=n;i++){
       cin>>x;
       a[i]=x;
       if(x>max1){
           max2=max1;
           max1=x;
       }
       else{
           if(max1==x){
               max2=x;
           }
           else{
               if(x>max2){
                   max2=x;
               }
           }
       }
   }

   for(int i=1;i<=n;i++){
       if(a[i]!=max1){
           cout<<max1<<endl;
       }
       else{
           cout<<max2<<endl;
       }
   }

  return 0;
}


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

int		main(void)
{
	ll n;
	cin >> n;
	if (n / 100 == 7) {
		cout << "Yes" << endl;
	} else if (n / 10 % 10 == 7) {
		cout << "Yes" << endl;
	} else if (n % 10 == 7) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return (0);
}


Measured memory_bytes: 3612
[M,D]=list(map(int,input().split()))
count=0
for MM in range(1,1+M):
    for DD in range(1,1+D):
        d10=DD//10
        d1=DD%10
        if d1>=2 and d10 >= 2 and d1*d10==MM:
            count+=1
print(count)


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

int main(){
	int n;
	while(true){
		string ss;
		cin >> n;
		if(n==0){
			break;
		}

		int top = 1;//上
		int bot = 6;//下
		int s[4] = {2,3,5,4};
		int ans=1;

		for(int i=0;i<n;i++){
			cin >> ss;
			if(ss == "North"){
				int buf = top;
				top = s[0];
				s[0] = bot;
				bot = s[2];
				s[2] = buf;
				ans += top;
			}
			if(ss == "East"){
				int buf = top;
				top = s[3];
				s[3] = bot;
				bot = s[1];
				s[1] = buf;
				ans += top;
			}
			if(ss == "West"){
				int buf = top;
				top = s[1];
				s[1] = bot;
				bot = s[3];
				s[3] = buf;
				ans += top;
			}
			if(ss == "South"){
				int buf = top;
				top = s[2];
				s[2] = bot;
				bot = s[0];
				s[0] = buf;
				ans += top;
			}
			if(ss == "Right"){
				int buf = s[0];
				s[0] = s[1];
				s[1] = s[2];
				s[2] = s[3];
				s[3] = buf;
				ans += top;
			}
			if(ss == "Left"){
				int buf = s[3];
				s[3] = s[2];
				s[2] = s[1];
				s[1] = s[0];
				s[0] = buf;
				ans += top;
			}
		}
		cout << ans << endl;
	}
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  int n;
  cin >> n;
  int count4 = 0;
  int count2 = 0;
  int count1 = 0;
  int all = 0;
  int a;
  REP(i, n) {
    cin >> a;
    all++;
    if(a % 4 == 0) {
      count4++;
    }
    else if(a % 2 == 0) {
      count2++;
    }
    else {
      count1++;
    }
  }

  if(count2 > 0) {
    count1++;
  }
  string ans = "No";
  if(count4+1 >= count1) {
    ans = "Yes";
  }
  cout << ans << endl;
  
  /*
  eprintf("c4,all,c2:%d,%d,%d\n", count4, all, count2);
  eprintf("(all-c2-1)/2:%d\n", (all-count2-1)/2);
  int left = all - (count2 - -1);
  if(count4 >= (all - (count2 -1)) / 2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  */

  return 0;
}


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

int main(){
    string s[3];
    cin >> s[0] >> s[1] >> s[2];

    int turn = 0;
    int next = 0;
    
    while(1){
        if(s[turn].length()==0) break;
        next = s[turn][0]-'a';
        s[turn] = s[turn].substr(1);
        turn = next;
    }

    cout << (char)('A'+turn) << endl;
    return 0;
}

Measured memory_bytes: 256
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = 1004, Mod = (int)1e9 + 7;
vector <string> mat;
ll dp[N][N];
int n, m;

inline ll add (ll x, ll y) { return ((x%Mod) + (y%Mod))%Mod; }

void solve() {
   for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j)
      dp[i][j] = 0;

   for (int i = 1; i <= n && mat[i][1] == '.'; ++i) dp[i][1] = 1;
   for (int j = 1; j <= m && mat[1][j] == '.' ; ++j) dp[1][j] = 1;

   for (int i = 2; i <= n; ++i) for (int j = 2; j <= m; ++j)
   {
      if (mat[i][j] != '.') continue;
      dp[i][j] = add(dp[i-1][j], dp[i][j-1]);
   }
   cout << dp[n][m] << '\n';
}

void read() {
   cin >> n >> m;
   mat.push_back(" ");
   for (int i = 1; i <= n; ++i){
      string st; cin >> st;
      st = " " + st;
      mat.push_back(st);
   }
}

signed main() {
   IOS; PREC;
   read(), solve();

   return EXIT_SUCCESS;
}


Measured memory_bytes: 9088
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	lint n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	lint di=a-b;
	rep(i,n){
		lint x=i,y=n-1-i;
		if(x*d-y*c>=di && di>=x*c-y*d){
			cout<<"YES"<<endl;return 0;
		}
	}
	cout<<"NO"<<endl;
}


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

ans = 0
for i in range(1, N - 1):
    p1, p2, p3 = P[i - 1], P[i], P[i + 1]
    if (p1 < p2 < p3) or (p3 < p2 < p1):
        ans += 1

print(ans)


Measured memory_bytes: 2940
from itertools import  combinations as c
n=int(input())
l=[0]*5
for i in range(n):
  s=input()
  s=s[0]
  if s in "MARCH":
    l["MARCH".index(s)]+=1
ans=0
for x,c,v in c(range(5),3):
  ans+=l[x]*l[c]*l[v]
print(ans)

Measured memory_bytes: 3064
icase=0
if icase==0:
    w,h,n=map(int,input().split())
    xy=[[1]*w for i in range(h)]
    for i in range(n):
        xi,yi,ai=map(int,input().split())
        if ai==1:
            for x  in range(xi):
                for y in range(h):
                    xy[y][x]=0
        elif ai==2:
            for x  in range(xi,w):
                for y in range(h):
                    xy[y][x]=0
        elif ai==3:
            for x  in range(w):
                for y in range(yi):
                    xy[y][x]=0
        elif ai==4:
            for x  in range(w):
                for y in range(yi,h):
                    xy[y][x]=0
#        print(xy) 
    s=0
    for x in range(w):
        for y in range(h):
            s=s+xy[y][x]
    print(s)

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

int main (void){

    int s;
    char S[1003];
    char c;

    for(s=0;s<1000;s++){
        scanf("%c",&S[s]);

        if(S[s]=='\n'){
            break;
        }
    }

    if(S[s-1]=='s'){
        S[s+2]=S[s];
        S[s]='e';
        S[s+1]='s';

        for(int i=0;i<s+2;i++){
            printf("%c",S[i]);
        }
    }else{
        S[s+1]=S[s];
        S[s]='s';

        for(int i=0;i<s+1;i++){
            printf("%c",S[i]);
        }

    }






    return 0;
}

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

int main() {
  int n, x, fx;
  cin >> n;
  x = n;
  fx = 0;
  while (n >= 1){
    fx += n % 10;
    n /= 10;
  }
  if (fx == 0) fx = 1;
  if (x % fx == 0 && x > 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
#define le(x) (int) x.length()
#define rsz resize

using namespace std;
typedef vector <int> vi;
typedef vector <vector <int> > vii;
typedef pair <int, int> pii;
typedef queue <int> qi;
typedef double db;
typedef long long ll;
typedef long double ld;
 
const long double PI=3.141592653589793238462643383279502884;
const long long PRIME1=1e9+787;
 
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll minll(ll a,ll b) {return a<=b?a:b;}
ll maxll(ll a,ll b) {return a>=b?a:b;}

int main () {
    fast;
    int n;
    cin>>n;
    vector <ll> a(n);
    for (int i=0; i<n; i++) {
        cin>>a[i];
    }
    ll ans=1000;
    ll st=0;
    if (a[0]<a[1]) {
        st=ans/a[0];
        ans-=a[0]*st;
    }

    for (int i=1; i<n; i++) {
        if (a[i-1]>=a[i]) {
            ans+=st*a[i-1];
            st=ans/a[i];
            ans-=a[i]*st;
        }
    }
    ans+=st*a[n-1];
    cout<<ans;
    return 0;
}
 
 


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<pair<pair<int, int>, int>> v;
    vector<int> used(2 * n, 0);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        
        v.push_back({{x, y}, 1});
    }
    
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        
        v.push_back({{x, y}, 2});
    }

    sort(v.begin(), v.end());
    int ans = 0;
    for (int f = 0; f < 2 * n; ++f) {
        for (int i = 0; i < 2 * n; ++i) {
            if (v[i].first.second == f && v[i].second == 2) {
                for (int j = i - 1; j >= 0; --j) {
                    if (v[j].first.second < f && v[j].second == 1 && used[j] == 0) {
                        used[j] = 1;
                        ans++;
                        break;
                    }
                }
                break;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
int const MAXN=100, MAXK=100100, mod=1e9+7;
int n, k, v[MAXN], dp[MAXK][2], pre[MAXK][2];
inline int pref(int l, int r, int i){
	l=max(l,0);
	if(l==0)
		return pre[r][i];
	return (pre[r][i]-pre[l-1][i]+mod)%mod;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>v[i];
	dp[0][n&1]=1;
	for(int j=0;j<=k;j++)
		pre[j][n&1]=1;
	for(int i=n-1;i>=0;i--){
		dp[0][i&1]=1;
		pre[0][i&1]=1;
		for(int j=1;j<=k;j++){
			dp[j][i&1]=pref(j-v[i],j,(i+1)&1);
			pre[j][i&1]=(pre[j-1][i&1]+dp[j][i&1])%mod;
		}
	}
	cout<<dp[k][0];
}


Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int A = in.Int();
            int B = in.Int();
            int H = in.Int();
            int M = in.Int();

            double hp = H * 30 + M * 0.5;
            double mp = M * 6;
            double rad = Math.toRadians(hp - mp);
            double ans = Math.sqrt(Math.pow(A, 2) + Math.pow(B, 2) - 2L * A * B * Math.cos(rad));
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 33296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;
const ll MOD = 1000000007;

int main(){
  int n, i;
  cin >> n >> i;
  cout << n - i + 1 <<endl;
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ansp=p[:x]
ansq=q[:y]
ans=sum(ansp)+sum(ansq)
ep=x-1
eq=y-1
for i in range(c):
    if ep<0 and eq<0:
        break
    if (ep>=0 and eq<0) or (ep>=0 and eq>=0 and ansp[ep]<ansq[eq]):
        if ansp[ep]<r[i]:
            ans=ans-ansp[ep]+r[i]
            ep-=1 
        else:
            break
    elif (eq>=0 and ep<0) or (ep>=0 and eq>=0 and ansq[eq]<=ansp[ep]):
        if ansq[eq]<r[i]:
            ans=ans-ansq[eq]+r[i]
            eq-=1
        else:
          break
print(ans)

Measured memory_bytes: 29448