akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp

int n;
int A[100005];

static int partition(int p, int r) {
    int i = p - 1;
    int x = A[r];

    for (int j = 0; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

int main() {
    cin >> n;
    REP(i, n) cin >> A[i];
    int q = partition(0, n-1);
    REP(i, n) {
        if (i) cout << " ";
        if (i == q) cout << "[";
        cout << A[i];
        if (i == q) cout << "]";
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 3468
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
int main() {
  int x,a,b,joy;
  cin >> x;
  a = x/500;
  b = x%500/5;
  joy = 1000*a + 5*b;
  dunk(joy);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

constexpr int MAX = 20;
constexpr int NOT_FOUND = 11;

int w, h, ans;
int grid[MAX][MAX];

void dfs(int y, int x, int count) {
    int nx, ny;
    if(count >= ans) return;

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

    for (int i = 0; i < 4; i++) {
        nx = x + dx[i]; 
        ny = y + dy[i];

        if (grid[ny][nx] == 1) continue;

        while (0 <= ny && ny < h && 0 <= nx && nx < w && grid[ny][nx] != 1 ) {
            if(grid[ny][nx] == 3){
                ans = count;
                return;
            }else {
                ny += dy[i];
                nx += dx[i];
            }
        }

        if (grid[ny][nx] == 1 && 0 <= ny && ny < h && 0 <= nx && nx < w) {
            grid[ny][nx] = 0;
            dfs(ny - dy[i], nx - dx[i], count+1);
            grid[ny][nx] = 1;
        }
    }
}

int main(int argc, char const *argv[]) {
    while (cin>>w>>h, w || h) {
        ans = NOT_FOUND;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin>>grid[i][j]; 
            }
        }

        int count = 1;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (grid[i][j] == 2) {
                    dfs(i, j, count);
                }
            }
        }

        if (ans == NOT_FOUND) cout<<"-1"<<endl;
        else cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3036
#include <iostream>
using namespace std;
int main(){
  int x1,y1,x2,y2,x3,y3,x4,y4;
  cin >> x1 >> y1 >> x2 >> y2;
  x3 = x2+y1-y2;
  y3 = y2+x2-x1;
  x4 = x1+y1-y2;
  y4 = y1+x2-x1;
  printf("%d %d %d %d\n",x3,y3,x4,y4);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    vector<int> a;
    cin>>n;
    for(int i=0;i<n;i++){
        int j;
        cin>>j;
        a.push_back(j);
    }
    sort(a.begin(),a.end(),greater<int>());
    int ali=0,bob=0;
    for(int i=0;i<n;i++){
        if(i%2==0)ali+=a[i];
        else bob+=a[i];
    }
    cout<<ali-bob<<endl;
}


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

ll mod = 1e9+7;
ll n, m, k;
ll fat[200005], inv[200005], dp[3005];

ll modpow(ll b, ll e){
    if(e == 0) return 1;
    if(e == 1) return (b%mod);
    ll res = modpow(b, e/2);
    res = (res*res)%mod;
    if(e%2 == 1) res = (res*(b%mod))%mod;
    return res;
}

ll get_comb(ll x, ll y){
    x--; y--;
    if(x < y) swap(x,y);
    return ( fat[x+y] * ((inv[y] * inv[x])%mod) )%mod;
}

int main(){
    
    fat[0] = 1;
    inv[0] = 1;
    for(ll i = 1; i <= 2e5; i++)
        fat[i] = (fat[i-1]*i)%mod;
    for(ll i = 1; i <= 2e5; i++)
        inv[i] = modpow(fat[i], mod-2);
    
    cin >> n >> m >> k;
    vector<ii> vec;
    for(ll i = 0; i < k; i++){
        ll x, y; cin >> x >> y;
        vec.push_back({x, y});
    }
    sort(vec.begin(), vec.end());
    vec.push_back({n, m});
    for(ll i = 0; i < vec.size(); i++){
        ll x = vec[i].first, y = vec[i].second;
        dp[i] = (dp[i] + get_comb(x,y))%mod;
        for(ll j = i+1; j < vec.size(); j++){
            ll xx = vec[j].first, yy = vec[j].second;
            if(y <= yy)
                dp[j] = (dp[j]-(dp[i]*get_comb(xx-x+1, yy-y+1))%mod + mod)%mod;
        }
        //cout << x << " " << y << " " << dp[i] << endl;
    }
    cout << dp[k] << endl;
    return 0;
}

Measured memory_bytes: 3456
user = {}
kind = ["a", "b", "c"]
for i in range(3):
    user[kind[i]] = input()
flag = 0
p = user["a"][0]
while flag == 0:
    if len(user[p]) == 0:
        flag = 1
        ans = p.upper()
        break
    temp = user[p][0]
    user[p] = user[p][1:len(user[p])]
    p = temp
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,VI(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n, m, k, x, y , z = 0, h, ans=0, w, sum = 0, Max = -1, Min = 1e9+1;
  string u= "";
  bool ok=true;
  cin >> n;
  VI a(n),b(n); rep(i,n) cin >> a[i];
  x = 0; y = n-1;
  for(int i=n-1; i>=0; i--){
    if(ok){
      b[x] = a[i];
      x++; ok=false;
    }
    else{
      b[y] = a[i];
      y--; ok=true;
    }
  }
  rep(i,n) cout << b[i] << " ";
  return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s1,s2;
    cin>>s1>>s2;
    int n,m;
    cin>>n>>m;
    string str;
    cin>>str;
    if(str==s1)n--;
    if(str==s2)m--;
    cout<<n<<" "<<m;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

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

ll nck(ll n, ll k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  if(k == 0 || k == n) return 1;
  ll nume = 1, deno = 1;
  for(int i=0; i<k; i++){
    nume *= (n-i);
    deno *= (i+1);
    ll g = gcd(nume, deno);
    nume /= g;
    deno /= g;
  }
  return (ll)(nume/deno);
}


int main(){
    ll n, p;
    cin >> n >> p;
    ll odd = 0, even = 0;
    rep(i, 0, n){
        ll a;
        cin >> a;
        if(a % 2 == 0) even++;
        else odd++;
    }
    
    if(p == 0){
        ll d = 0;
        ll srt;
        if(odd % 2 == 1) srt = 1;
        else srt = 0;
        for(ll i = srt; i <= odd; i += 2){
            d += nck(odd, i);
        }
        ll ans = pow(2LL, even) * d;
        cout << ans << endl;
    }else{
        ll d = 0;
        ll srt;
        if(odd % 2 == 1) srt = 0;
        else srt = 1;
        for(ll i = srt; i <= odd; i += 2){
            d += nck(odd, i);
        }
        ll ans = pow(2LL, even) * d; 
        cout << ans << endl;
    }
    return 0;
}

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

#define int long long

struct Combination {
  int mod;
  vector<int> fact;
  vector<int> invf;
  vector<vector<int> > part;  

  /*
    constructor : O(sz+log(mod))    
  */
  Combination(int sz, int mod) : fact(sz+1), invf(sz+1), mod(mod) {
    fact[0] = 1;
    for ( int i = 1; i < (int)fact.size(); i++ ) {
      fact[i] = fact[i-1]*i % mod;
    }
    invf[sz] = inv(fact[sz]);
    for ( int i = sz-1; i >= 0; i-- ) {
      invf[i] = invf[i+1]*(i+1) % mod;
    }
  }

  int pow(int x, int n) const {
    int ret = 1;
    while ( n > 0 ) {
      if ( n & 1 ) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int inv(int x) const {
    return (pow(x, mod - 2));
  }

  /*
    permutation
  */
  int P(int n, int r) const {
    if ( r < 0 || n < r ) return (0);
    return (fact[n]*invf[n-r] % mod);    
  }

  /*
    combination
  */
  int C(int n, int r) const {
    if ( r < 0 || n < r ) return (0);    
    return (fact[n]*invf[r]%mod * invf[n-r] % mod);    
  }  

  /*
    combination with repetition
  */
  int H(int n, int r) const {
    if ( n < 0 || r < 0 ) return 0;
    if ( n == 0 && r == 0 ) return 1;
    return C(n+r-1, n);    
  }

  /*
    stirling number
  */
  int S(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      int add = C(r, i)*pow(i, n)%mod;      
      if ( (r-i)&1 ) ret += mod-add;
      else ret += add;
      ret %= mod;      
    }
    (ret *= invf[r]) %= mod;
    return ret;
  }

  /*
    bell number
  */
  int B(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      (ret += S(n, i)) %= mod;      
    }
    return ret;
  }

  /*
    calc partition number
    return partition number table
  */
  vector<vector<int> > built_part(int n, int r) {
    part = vector<vector<int> >(n+1, vector<int>(r+1, 0));
    part[0][0] = 1;
    for ( int i = 0; i <= n; i++ ) {
      for ( int j = 1; j <= r; j++ ) {
	if ( i-j >= 0 ) {
	  (part[i][j] = part[i][j-1]+part[i-j][j]) %= mod;	  
	} else {
	  part[i][j] = part[i][j-1];
	}
      }
    }
    return part;    
  }  
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, k;
  cin >> n >> k;

  if ( n < k ) {
    cout << 0 << endl;
    return 0;    
  }

  Combination c(n-k, 1e9+7);  
  c.built_part(n-k, k);
  cout << c.part[n-k][k] << endl;  
  
  return 0;
}



Measured memory_bytes: 6232
use std::io::Read;
use std::collections::HashMap;

const MOD: u64 = 998244353;

fn solve(s: u128, n: usize, mem: &mut HashMap<(u128, usize), u64>) -> u64 {
    if n == 0 { return 1 }
    if n == 1 { return (s%2 + 1) as u64 }
    if let Some(&r) = mem.get(&(s, n)) { return r }
    let mut res = (s%2 + 1) as u64 * solve(s/2, n-1, mem) % MOD;
    for l in 1..n {
        if 2*l > n { break }
        let mut ns = s & (s >> l);
        for r in 2..=n/l {
            if l*r > n { break; }
            res = (res + solve(ns, l, mem) * solve(s >> r*l, n-r*l, mem)) % MOD;
            ns &= s >> r*l;
        }
    }
    mem.insert((s, n), res);
    res
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let s = buf.trim().as_bytes();
    let n = s.len();
    let mut v : u128 = 0;
    for i in 0..n {
        if s[i] == b'1' { v |= 1 << i }
    }
    let mut mem = HashMap::new();
    let res = solve(v, n, &mut mem);
    println!("{}", res);
}


Measured memory_bytes: 52940
#include <stdio.h>

int main(void){

    int a,b,c;

    scanf("%d %d %d", &a, &b, &c);
    if(a<0 || 100<a || b<0 || 100<b || c<0 || 100<c){
        printf("Integer a & b & c should be no less than 0 and no more than 100\n");
        return 0;
    }

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

    return 0;
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S;
  cin >> S;
    if ( S.at(0) == S.at(1) ) {
      cout << "Bad" << endl;
    }
    else if ( S.at(1) == S.at(2) ) {
      cout << "Bad" << endl;
    }
    else if ( S.at(2) == S.at(3) ) {
      cout << "Bad" << endl;
    }
    else {
      cout << "Good" << endl;
    }
  }


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> r(A), g(B), n(C);
    rep(i, A) { cin >> r[i]; }

    rep(i, B) { cin >> g[i]; }

    rep(i, C) { cin >> n[i]; }

    sort(all(r), greater<ll>());
    sort(all(g), greater<ll>());
    sort(all(n), greater<ll>());
    priority_queue<ll> que;
    rep(i, X) { que.push(r[i]); }

    rep(i, Y) { que.push(g[i]); }

    rep(i, X + Y) {
        if (i < n.size()) {
            que.push(n[i]);
        }
    }

    ll res = 0;
    rep(i, X + Y) {
        res += que.top();
        que.pop();
    }

    cout << res << endl;
}

Measured memory_bytes: 8816
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;  
#define mod 998244353
#define fi first
#define sec second
int main()
{
	ll n,k;
	cin>>n>>k;
	ll x,y;
	pair<ll,ll> p[k];
	for(ll i=0;i<k;i++)
	{
		cin>>p[i].fi>>p[i].sec;
	}
	ll dp[n+1]={0};
	ll suf[n+1]={0};
	dp[n]=1;
	suf[n]=1;
	for(ll i=n-1;i>=1;i--)
	{
		for(ll j=0;j<k;j++)
		{
			if(i+p[j].fi<=n)
			{
				if(i+p[j].sec<=n)
				{
					dp[i]=(dp[i]%mod+suf[i+p[j].fi]%mod-suf[i+p[j].sec]%mod+dp[i+p[j].sec]%mod+mod)%mod;
				}
				else
				{	
					dp[i]=(dp[i]%mod+suf[i+p[j].fi]%mod-suf[n]%mod+dp[n]%mod+mod)%mod;
				}
			}
		}
		suf[i]=(suf[i]%mod+suf[i+1]%mod+dp[i]%mod)%mod;
	}
	cout<<dp[1]%mod;
}

Measured memory_bytes: 6760
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;
 
template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
 
    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};
 
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
template <class T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
 
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
//}}}

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int x;
    cin >> x;

    if(x == 0){
        cout << 1 << '\n';
    }else{
        cout << 0 << '\n';
    }

    return 0;
}

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

using namespace std;

int count_ab(const string& str) {
    int ret = 0;
    for(int i=0;i<str.length()-1;i++) {
        if(str[i] == 'A' && str[i+1] == 'B') {
            ret++;
        }
    }
    return ret;
}

int main() {
    int N; cin >> N;
    int has_AB = 0;
    int has_A  = 0;
    int has_B  = 0;
    int count = 0;
    string S;
    for(int i=0;i<N;i++) {
        cin >> S;
        count += count_ab(S);

        if(S.back() == 'A' && S.front() == 'B') {
            has_AB++;
        } else if(S.back() == 'A' && S.front() != 'B') {
            has_A++;
        } else if(S.back() != 'A' && S.front() == 'B') {
            has_B++;
        }
    }

    if(has_A + has_B == 0) {
        cout << count + max(0, has_AB - 1) << endl;
    } else {
        cout << count + has_AB + min(has_A, has_B) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    "sort"
)

func main(){
    var n int
    fmt.Scan(&n)
    aArray := make([]int, n)
    for i := range aArray {
        fmt.Scan(&aArray[i])
    }
    sort.Ints(aArray)
    
    for i := 0; i < n - 1; i += 2 {
        if aArray[i] + aArray[i+1] < 0 {
            aArray[i], aArray[i+1] = -aArray[i], -aArray[i+1]
        }
    }
    ans := 0
    for _, a := range aArray {
        ans += a
    }
    fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define int long long int
using namespace std;

#define int long long int
#define REP(i, n) for (int i(0); i < n; ++i)
#define REQ(i, a, b) for (int i(a); i <= b; ++i)


bool prime(int x){
	if(x==2){
		return true;
	}
	for(int i(2);i*i<=x;++i){
		if(x%i==0){
			return false;
		}
	}
	return true;
}

signed main(){
	int x; cin >> x;
	while(!prime(x)){
		x++;
	}
	cout << x;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,i,x,t;
	char a[105];
	while(~scanf("%d",&n))
	{
		for(i=0;i<=n;i++)
		{
			scanf("%c",&a[i]);
		}
		t=0;
		x=0;
		for(i=0;i<=n;i++)
		{
			if(a[i]=='R')
			{
				t++;
			}
			else if(a[i]=='B')
			{
				x++;
			}
		}
		if(t>x)
		{
			printf("Yes\n");
		}
		else 
		{
			printf("No\n");
		}
	}
}

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

using namespace std;

#define MAX 100005

typedef pair<int, pair<int, int>> pip;
typedef pair<pair<int, int>, pip> ppp;
typedef long long ll;

vector<pip> adj[MAX];
vector<ppp> queries;
vector<ll> dst(MAX, 0);
map<int, int> mct[MAX], mcdt[MAX];
vector<int> req[MAX], ct(MAX, 0), cdt(MAX, 0), intime(MAX), outime(MAX);
vector<vector<int>> dp(MAX, vector<int>(20, 0));
int tmm = 0;

void get(int v, int p){
    dp[v][0] = p;
    intime[v] = tmm++;
    for(auto u : adj[v])
        if( u.first != p )
            get(u.first, v);
    outime[v] = tmm++;
}

bool isAncestor(int u, int v){
    return intime[u] < intime[v] && outime[u] > outime[v];
}

int lca(int u, int v){
    if( isAncestor(u, v) )
        return u;
    if( isAncestor(v, u) )
        return v;
    for(int i = 19; i >= 0; i--)
        if( ! isAncestor(dp[u][i], v) )
            u = dp[u][i];
    return dp[u][0];
}

void dfs(int v, int p){
    for(auto u : adj[v]){
        if( u.first != p ){
            dst[u.first] = dst[v] + u.second.second;
            ct[u.second.first]++;
            cdt[u.second.first] += u.second.second;
            for(auto e : req[u.first]){
                mct[u.first][e] = ct[e];
                mcdt[u.first][e] = cdt[e];
            }
            dfs(u.first, v);
            ct[u.second.first]--;
            cdt[u.second.first] -= u.second.second;
        }
    }
}

int main(){

    int n, q;
    cin >> n >> q;
    int a, b, c, d;
    for(int i = 0; i < n-1; i++){
        cin >> a >> b >> c >> d;
        a--, b--;
        adj[a].push_back(make_pair(b, make_pair(c, d)));
        adj[b].push_back(make_pair(a, make_pair(c, d)));
    }

    get(0, 0);
    for(int i = 1; i < 20; i++)
        for(int j = 0; j < n; j++)
            dp[j][i] = dp[dp[j][i-1]][i-1];

    int x, y, u, v, lc;
    for(int i = 0; i < q; i++){
        cin >> x >> y >> u >> v;
        u--, v--;
        lc = lca(u, v);
        req[u].push_back(x);
        req[v].push_back(x);
        req[lc].push_back(x);
        queries.push_back(make_pair(make_pair(x, y), make_pair(lc, make_pair(u, v))));
    }

    dfs(0, 0);

    for(auto q : queries){
        u = q.second.second.first, v = q.second.second.second, lc = q.second.first;
        x = q.first.first, y = q.first.second;
        ll dd = dst[u] + dst[v] - 2*dst[lc];
        ll cld = mcdt[u][x] + mcdt[v][x] - 2*mcdt[lc][x];
        ll ccn = mct[u][x] + mct[v][x] - 2*mct[lc][x];
        cout << ( dd - cld + y*ccn) << endl;
    }
    return 0;
}

Measured memory_bytes: 67120
/* ex3_2
   tamayama */

#include<stdio.h>

int main(void){
    int N;
    scanf("%d",&N);

    if((N-2)%10 == 0 || (N-4)%10 == 0 || (N-5)%10 == 0 || (N-7)%10 == 0 || (N-9)%10 == 0){
        printf("hon");
    }else if(N%10 == 0 || (N-1)%10 == 0 || (N-6)%10 == 0 || (N-8)%10 == 0){
        printf("pon");
    }else{
        printf("bon");
    }
    return 0;
}

Measured memory_bytes: 1732
import sys
import bisect
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    X = list(readnums())
    xs = sorted(X)
    for i in X:
        d = bisect.bisect_left(xs, i)
        if d >= N // 2:
            print(xs[N // 2 - 1])
        else:
            print(xs[N // 2])


if __name__ == "__main__":
    main()


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

int n;
long long ans=0;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>n;
	for(int i=1; i<=n;i++){
		if(i%3!=0 and i%5!=0){
			ans+=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[][] a = new int[n][m];
		int[] b = new int[m];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				a[i][j] = scan.nextInt();
			}
		}
		for(int i = 0; i < m; i++) {
			b[i] = scan.nextInt();
		}
		
		int[] ans = new int[n];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				ans[i] += a[i][j] * b[j]; 
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.println(ans[i]);
		}
	}

}



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

int n, k;
bool c[10];

bool ok(int x) {
	while(x) {
		int d = x % 10; if (c[d]) return false;
		x /= 10;
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;
	while(k--) {
		int d; cin >> d;
		c[d] = 1;
	}
	while(true) {
		if (ok(n)) return printf("%d\n", n), 0;
		else ++n; 
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f
#define PB push_back
#define F first
#define S second
#define FOR(i,k) for(int i=0; i<k; i++)
#define RFOR(i,k) for(int i=k; i>=0; i--)
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x.begin())
#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
#define DEBUGV(x) cout<<#x<<": "; for(auto &d:x) cout<<d<<" "; cout<<endl
#define DEBUGM(x) for(auto &p:x) cout<<p.F<<":"<<p.S<<" "; cout<<endl;
#define OUT(x) cout<<(x)<<endl

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
typedef map<char,int> MC;
typedef map<int,int> MI;
typedef map<string,int> MS;

template<typename T, typename U> void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> void amax(T &x, U y) { if(x < y) x = y; }
VPII neighbors = {{0,1}, {1,0}, {0,-1}, {-1,0}};
PII operator+(PII &l, PII &r) { return {l.F+r.F, l.S+r.S}; }
bool IsValid(PII p, int Y, int X) { 
  return p.F >=0 && p.F < Y && p.S >=0 && p.S < X; }
bool IsPrime(int n) {
  if (n <= 1)  return false;
  if (n <= 3)  return true;
  if (n%2 == 0 || n%3 == 0) return false;
  for (int i=5; i*i<=n; i=i+6)
    if (n%i == 0 || n%(i+2) == 0)
      return false;
  return true;
}

int main() {
  int a,b,k;
  cin>>a>>b>>k;
  MI m;
  for(int i=a; i< min(b,a+k); i++)
    m[i]++;
  for(int i=max(a,b-k+1); i<=b; i++)
    m[i]++;
  for(auto x : m)
    OUT(x.first);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;


int main(){

	int n,d,array[1005],count;

	while(scanf("%d %d",&n,&d)!=EOF){

		array[0] = 2;
		array[1] = 3;

		for(int i=2; i < n; i++){
			array[i] = (array[i-1] + array[i-2])%1001;
		}

		std::sort(array,array+n);

		count = 1;

		for(int i=1; i < n; i++){
			if(abs(array[i]-array[i-1]) >= d)count++;
		}
		printf("%d\n",count);

	}

	return 0;
}

Measured memory_bytes: 2568
from collections import defaultdict

N = int(input())
X = input()[::-1]


def popcount(n):
    p = 0
    while n > 0:
        p += n & 1
        n >>= 1
    return p


f = defaultdict(int)
for i in range(1, N + 1):
    f[i] = f[i % popcount(i)] + 1

P = X.count('1')
base = dict()
R = defaultdict(int)
for r in [P - 1, P + 1]:
    if r == 0:
        continue
    base[r] = [1] * N
    for i in range(1, N):
        base[r][i] = base[r][i - 1] * 2 % r
    R[r] = sum(base[r][i] * int(X[i]) for i in range(N)) % r

ans = [0] * N
for i in range(N):
    if X[i] == '1' and P == 1:
        ans[i] = 0
        continue
    if X[i] == '0':
        r = P + 1
        res = R[r] + base[r][i]
    else:
        r = P - 1
        res = R[r] - base[r][i]
    ans[i] = f[res % r] + 1

for i in range(N):
    print(ans[N - i - 1])


Measured memory_bytes: 43680
#include <iostream>
#include <vector>
#include <map>

using namespace std;

const long long int MOD=1e9+7;

long long int modinv(long long int a, long long int m) {
    long long int b = m, u = 1, v = 0;
    while (b) {
        long long int t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

    vector<long long int> A(N);
    vector<map<long long int, long long int> > mp(N);
    map<long long int, long long int> lcm;
    map<long long int, vector<long long int> > pow;
    for(int n=0; n<N; n++) {
        cin >> A[n];
        long long int a=A[n];
        for(int i=2; i*i<=A[n]; i++) {
            while(a%i==0) {
                mp[n][i]++;
                a/=i;
                if(mp[n][i]+1<=pow[i].size()) continue;
                if(pow[i].size()==0) {
                    pow[i].push_back(1);
                    pow[i].push_back(i);
                } else {
                    long long int tmp=pow[i][pow[i].size()-1]*i;
                    pow[i].push_back(tmp);
                }
            }
            // cout << a << ", " << i << ", " << mp[n][i] << endl;
            if(a==1) {
                break;
            }
        }
        if(a!=1) {
            mp[n][a]++;
            if(mp[n][a]+1>pow[a].size()) {
                if(pow[a].size()==0) {
                    pow[a].push_back(1);
                    pow[a].push_back(a);
                } else {
                    long long int tmp=pow[a][pow[a].size()-1]*a;
                    pow[a].push_back(tmp);
                }
            }
        }
        
        for(auto itr=mp[n].begin(); itr!=mp[n].end(); itr++) {
            if(lcm[itr->first]<itr->second) {
                lcm[itr->first]=itr->second;
            }
        }
    }
    
    long long int lll=1;
    for(auto itr=lcm.begin(); itr!=lcm.end(); itr++) {
        lll *= pow[itr->first][itr->second];
        lll %= MOD;
    }
    
    long long int ans=0;
    for(int n=0; n<N; n++) {
        ans += lll*modinv(A[n], MOD);
        ans %= MOD;
    }
    
    cout << ans%MOD << endl;


    return 0;
    
}

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

int main(){
	int b[101],a[101],n;
	for(int i=0;i<101;i++){
		a[i] = 0;
		b[i] = a[i];
	}
	while(cin >> n && n){
		a[n] = a[n] + 1;
		b[n] = a[n];
	}
	sort(b,b+101);
	for(int i=1;i<101;i++){
		if(a[i] == b[100]) cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

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

int main() {
    ll N;
    cin >> N;
    map<ll,ll> mp;
    ll out = 0;
    ll A;
    rep(i,N){
        cin >> A;
        mp[A]++;
        out += A;
    }
    ll Q;
    cin >> Q;
    rep(i,Q){
        ll B,C;
        cin >> B >> C;
        if(mp.count(B)){
            mp[C] += mp[B];
            out += (C-B)*mp[B];
            mp.erase(B);
        }
        cout << out << endl;
    }
    return 0;
}



Measured memory_bytes: 7536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <complex>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int n, k;
    cin >> n >> k;
    for(int i = 1; ; ++i){
        if(n / k == 0){
            cout << i << endl;
            return 0;
        }
        else n /= k;
    }
}


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

int main(){
    int N;
    long long K;
    int ans;
    unordered_map <int, int> map;

    cin >> N >> K;
    int A[N+1];
    for(int i=1; i<=N; i++){
        cin >> A[i];
    }

    int count=0;
    int ii=1;

    int lstart, lscount, lecount;

    while( count<=N ){
        ii=A[ii];
        count++;
        map[ii]++;
        //cout << "count ii A[ii] map[A[ii]] " << count << " " << ii << " " << A[ii] << " " << map[A[ii]] << endl;
        if(map[A[ii]]>0){
            lstart=A[ii];
            lecount = count;
            break;
        }
    }

    count=0;
    ii=1;
    while(count <= N+1){
            if(ii==lstart){
                lscount=count;
                break;
            }
            count++;
            ii=A[ii];

    }

    lecount = lecount-lscount;

    //cout << "lscount lecount lstart " << lscount << " " << lecount << " " << lstart << endl;




    int kpcount;

    if( K <= (long long) lscount ){
        count=0;
        ii=1;
        while(count < K){
            count++;
            ii=A[ii];
        }
        ans = ii;
        
    }else{

        long long Kp = K- (long long) lscount;
        kpcount = (int) ( Kp%( (long long) (lecount+1) ) );
        count=0;
        ii=lstart;
        while(count < kpcount){
            count++;
            ii=A[ii];
        }
        ans = ii;        

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12064
n = int(input())

ans = [0]*60001

for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            a = i**2+j**2+k**2+i*j+i*k+j*k
            ans[a]+=1
for i in range(1,n+1):
    print(ans[i])


Measured memory_bytes: 9464
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    A.insert(0, 0)
    A.append(0)
    sumA = 0
    for i in range(n+1):
        sumA += abs(A[i+1] - A[i])

    for i in range(n):
        ansA = sumA - abs(A[i+1] - A[i]) - \
            abs(A[i + 2] - A[i + 1]) + abs(A[i + 2] - A[i])
        print(ansA)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20648
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long v = sc.nextLong();
        long b = sc.nextLong();
        long w = sc.nextLong();
        long t = sc.nextLong();

        if((v-w)*t >= Math.abs(a-b)){
           System.out.println("YES"); 
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 35816
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll k,a,b;
    cin >> k >> a >> b;
    rep(i,a,b){
        if(i%k==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3676
local s = io.read()
local n = #s
local cycle_end_pos = {}
local box = {}
for i = 1, 26 do
  box[i] = false
end
local t = {}
for i = 1, n do
  t[i] = s:sub(i, i):byte() - 96
end
local boxcnt = 0
for i = 1, n do
  local v = t[i]
  if not box[v] then
    box[v] = true
    boxcnt = boxcnt + 1
    if boxcnt == 26 then
      table.insert(cycle_end_pos, i)
      boxcnt = 0
      for j = 1, 26 do box[j] = false end
    end
  end
end
-- node = (#cycles + 1) * 26
local edge = {}
local invedge = {}
local canuse = {}

for i = 1, (#cycle_end_pos + 1) * 26 do
  edge[i] = {}
  invedge[i] = {}
  canuse[i] = false
end

local first_pos = {}
local last_pos = {}
for ic = 1, #cycle_end_pos do
  local spos = ic == 1 and 1 or cycle_end_pos[ic - 1] + 1
  local epos = cycle_end_pos[ic]
  for i = 1, 26 do
    box[i] = false
    first_pos[i] = 0
    last_pos[i] = 0
  end
  boxcnt = 0
  for i = spos, epos do
    local v = t[i]
    if first_pos[v] == 0 then
      first_pos[v] = i
    end
    last_pos[v] = i
  end
  for i = 1, 26 do
    local src = (ic - 1) * 26 + i
    for j = 1, 26 do
      if last_pos[j] <= first_pos[i] then
        local dst = ic * 26 + j
        table.insert(edge[src], dst)
        table.insert(invedge[dst], src)
      end
    end
  end
end
for i = 1, 26 do
  local idx = #cycle_end_pos * 26 + i
  canuse[idx] = true
end
if #cycle_end_pos == 0 then
  for i = 1, n do
    local v = t[i]
    local idx = #cycle_end_pos * 26 + v
    canuse[idx] = false
  end
else
  for i = cycle_end_pos[#cycle_end_pos] + 1, n do
    local v = t[i]
    local idx = #cycle_end_pos * 26 + v
    canuse[idx] = false
  end
end
local tasks = {}
for i = 1, 26 do
  local idx = #cycle_end_pos * 26 + i
  if canuse[idx] then
    table.insert(tasks, idx)
  end
end
local done = 0
while done < #tasks do
  done = done + 1
  local invsrc = tasks[done]
  for i = 1, #invedge[invsrc] do
    local invdst = invedge[invsrc][i]
    if not canuse[invdst] then
      canuse[invdst] = true
      table.insert(tasks, invdst)
    end
  end
end
local ret = {}
local curpos = 0
for i = 1, 26 do
  if canuse[i] then
    curpos = i
    table.insert(ret, string.char(96 + i))
    break
  end
end
for ic = 1, #cycle_end_pos do
  for i = 1, #edge[curpos] do
    local dst = edge[curpos][i]
    if canuse[dst] then
      curpos = dst
      table.insert(ret, string.char(96 + dst - 26 * ic))
      break
    end
  end
end
print(table.concat(ret))


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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    vector<int> h(n);
    for (auto &&x : h) cin >> x;

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i + 1 < n; ++i) {
        if (i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        if (i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

    cout << dp[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define foi(a,n) for(int i = a; i < (int)n; i++)
#define foj(a,n) for(int j = a; j < (int)n; j++)
#define pb(a) push_back(a)
#define ln '\n'
#define fastio 	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define cases int tests; cin >> tests; while(tests--)
using namespace std;

int main(){
	fastio;
	ll n, m, p;
	//~ cases
	{	
		int c = 0;
		cin >> n >> m;
		double x[n] , y[n];
		foi(0, n){
			cin >> x[i] >> y[i];
			if((x[i]*x[i] + y[i]*y[i]) <= m*m)c++;
		}
		cout << c;
		
	}
}


Measured memory_bytes: 6912
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int count=0,ans=INF;
    for(int i=1;i<N;i++) if(S[i]=='E') count++;
    ans=min(ans,count);
    for(int i=1;i<N;i++){
        if(S[i]=='E') count--;
        if(S[i-1]=='W') count++;
        ans=min(ans,count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
import java.io.*;

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String num1 = br.readLine();
        String[] num2 = num1.split(" ");

        int a = Integer.parseInt(num2[0]);
        int b = Integer.parseInt(num2[1]);

        if(a < b){
            System.out.println("a < b");
        }else if(a > b){
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
        }
    }
}

Measured memory_bytes: 24464
#include<iostream>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    
    int n, a;
    cin >> n;
    int odd = 0, m4 = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        if (a % 2 != 0) odd++;
        if (a % 4 == 0) m4++;
    }

    bool ok = false;
    if (m4 - odd >= 0) ok = true;
    else {
        if (m4 + odd == n && m4 + 1 == odd) ok = true;
    }

    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3144
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A, B, C, D, E, F = map(int, input().split())

dp = [-1] * (F + 1)
dp[0] = 0

cnt = 1
for i in range(F + 1):
    if dp[i] >= 0 and i + A * 100 <= F:
        dp[i + A * 100] = max(dp[i + A * 100], dp[i])
    if dp[i] >= 0 and i + B * 100 <= F:
        dp[i + B * 100] = max(dp[i + B * 100], dp[i])
    if dp[i] >= 0 and i + C <= F and (dp[i] + C) * (100 + E) <= (i + C) * E:
        dp[i + C] = max(dp[i + C], dp[i] + C)
    if dp[i] >= 0 and i + D <= F and (dp[i] + D) * (100 + E) <= (i + D) * E:
        dp[i + D] = max(dp[i + D], dp[i] + D)

x, y = A * 100, 0
for i in range(F + 1):
    if x <= 0 or x * dp[i] > y * i:
        x, y = i, dp[i]

print(x, y)

Measured memory_bytes: 3680
// A - 753
// https://atcoder.jp/contests/abc114/tasks/abc114_a
// +build ignore

package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)
	switch x {
	case 7:
		fmt.Println("YES")
	case 5:
		fmt.Println("YES")
	case 3:
		fmt.Println("YES")
	default:
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
/*Rabbi Zidni Ilma*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define mod 1000000007
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)

int main()
{
   ll len,i;
   string s;
   cin >> s;
   len=s.length();
   if(s[len-1]=='s')
   {
   	s.pb('e');
   	s.pb('s');
   }
   else
   s.pb('s');
   cout << s << "\n";
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	ll t1,t2,a,b,a2,b2;
	cin>>t1>>t2>>a>>b>>a2>>b2;
	a-=a2;b-=b2;
	if(a<0){
		a=-a;b=-b;
	}
	b=-b;
	if(a*t1==b*t2){
		cout<<"infinity"<<endl;
		return 0;
	}
	a*=t1;b*=t2;
	if(a-b>0){
		cout<<0<<endl;
		return 0;
	}

	else {
		ll cur = a;
		if(cur % (b-a)==0){
			cout<<cur/(b-a)*2<<endl;
		}
		else {
			cout<<cur/(b-a)*2+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string S;
  cin >> S;
  int count;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<4;j++){
      if(S[i]==S[j]){count++;}
    }
  }
  if(count==2){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func asub(x, y int) int {
	if x > y {
		return x - y
	}
	return y - x
}

func solve(a []int, start, N int) int {
	l := list.New()
	if start == 0 {
		l.PushBack(a[0])
		a = a[1:]
	} else {
		l.PushBack(a[N-1])
		a = a[:N-1]
	}
	ans := 0
	fpos := 0
	bpos := len(a) - 1
	for i := 0; i < len(a); i++ {
		f := l.Front().Value.(int)
		b := l.Back().Value.(int)
		diff := [4]int{
			asub(f, a[fpos]),
			asub(f, a[bpos]),
			asub(b, a[fpos]),
			asub(b, a[bpos]),
		}
		//out(f, b, a[fpos], a[bpos], diff)
		sel := 0
		for j := 0; j < 4; j++ {
			if diff[sel] < diff[j] {
				sel = j
			}
		}
		switch sel {
		case 0:
			l.PushFront(a[fpos])
			fpos++
		case 1:
			l.PushFront(a[bpos])
			bpos--
		case 2:
			l.PushBack(a[fpos])
			fpos++
		case 3:
			l.PushBack(a[bpos])
			bpos--
		}
		ans += diff[sel]
	}

	return (ans)
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}
	sort.Ints(a)

	r0 := solve(a, 0, N)
	//	r1 := solve(a, 1, N)
	ans := r0
	out(ans)
}


Measured memory_bytes: 8468
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    N, C, K = readi(3)
    ts = sorted(readi(N))
    ans = 1
    diff = 0
    c = 1
    for i in range(N - 1):
        diff += ts[i + 1] - ts[i]
        dbg(i=i, diff=diff, c=c)
        if diff > K or c == C:
            dbg(ii=i)
            ans += 1
            diff = 0
            c = 1
        else:
            c += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8896
import datetime
import calendar

m1,d1 = map(int,input().split())
m2,d2 = map(int,input().split())

day1 = datetime.date(2019, m1, d1)
day2 = datetime.date(2019, m1, calendar.monthrange(2019, m1)[1])

if day1 == day2:
    print("1")
else:
    print("0")

Measured memory_bytes: 4336
H, N = map(int, input().split())
l = []
for i in range(N):
  l.append(list(map(int, input().split())))
  
dp = [0] * 20000
for i in range(1, 20001):
  dp[i] = min(dp[i-a]+b for a, b in l)
  if i == H:
    break
print(dp[H])

Measured memory_bytes: 9516
fun main(args: Array<String>) {

    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val an = readLine()!!.split(" ").map(String::toInt)
        .groupBy { it }
        .mapValues { it.value.size }
        .toList()
        .sortedByDescending { it.second }

    an.drop(k).sumBy { it.second }.let(::println)
}




Measured memory_bytes: 109420
#include <bits/stdc++.h>
using namespace std;
const int mod  = 1e9+7;
int dp[1001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int h,w;
  cin >> h >> w;
  h--; w--;
  for(int i=0;i<=1000;i++)
      dp[i] = 0;
  dp[1] = 1;
  string grid;
  for(int row=0;row<=h;row++) {
    cin >> grid;
    for(int col = 1;col<=w+1;col++) {
      if (grid[col-1] == '.') {
        dp[col] = (dp[col] + dp[col-1])%mod;
      } 
      else if (grid[col-1] == '#')
        dp[col] = 0;  
    }
  }
  cout << dp[w+1];
  return 0;
}

Measured memory_bytes: 384
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
H = inintl()

h = H[0]

for i in range(1,n):
    if H[i]+1 < h:
        print("No")
        exit()
    if H[i] > h:
        h = H[i]

print("Yes")


Measured memory_bytes: 83732
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


S = str(input())
flag = 2
ans = 0

for i in range(3):
    if(S[i]=="R"):
        if(flag==1):
            ans +=1
        elif(ans == 0):
            ans = 1
        flag = 1
    else:
        flag = 0

print(ans)


Measured memory_bytes: 68704