akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const unsigned int BIT_FLAG_0 = (1 << 0);  // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1);  // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2);  // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3);  // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4);  // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5);  // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6);  // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7);  // 0000 0000 1000 0000

const double PI = 3.14159265358979323846;

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

#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7
const ll mod = 1000000007;

int main() {
    int N = 5, a;
    rep(i, N) {
        cin >> a;
        if (a == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vs s(n);
    cin >> s;
    map<vector<int>, int> m;
    for (str it : s)
    {
        vi cnt(26);
        for (char c : it)
            cnt[c - 'a']++;
        m[cnt]++;
    }
    int res = 0;
    for (auto it : m)
        res += it.se * (it.se - 1) / 2;
    cout << res << endl;
    GAME_OVER;
}

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

int main() {
  int N, K, x;
  cin >> N >> K;
  x = 1;
  for (int i = 0; i < N; i++) {
    int A, B;
    A = x * 2;
    B = x + K;
    if (A <= B) {
      x *=2;
    }
    else {
      x += K;
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 3592
N, A, B = list(map(int, input().split()))

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

ans = 0

for i in range(N):
    dsum = digitSum(i + 1)
    if A <= dsum <= B:
        ans += (i + 1)

print(ans)

Measured memory_bytes: 3060
def main():
    s = input()

    st = [s]
    while st:
        x = st.pop()
        if x == '':
            print('YES')
            return

        for w in ('dream', 'dreamer', 'erase', 'eraser'):
            if x.endswith(w):
                st.append(x[:-len(w)])

    print('NO')


if __name__ == '__main__':
    main()


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

#define endl '\n'

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

    int n; cin >> n;
    int a[n];
    int mini = 1e6, ans=0;
    for (int i=0; i<n; i++){
        cin >> a[i];
        if (a[i] < mini) ans++;
        mini = min(mini, a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let L: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let R = L - 1;
    let N = 20;
    let mut edges = (2..N).map(|i| (i, i + 1, 1 << (N - i - 1)))
        .chain((2..N).map(|i| (i, i + 1, 0)))
        .collect::<Vec<_>>();
    if (R >> (N - 1)) & 1 == 1 {
        edges.push((1, 2, 0));
        edges.push((1, 2, 1 << (N - 2)));
    }
    let mut s = R & (1 << (N - 1));
    for i in 2..(N + 1) {
        if (R >> (N - i)) & 1 == 1 {
            edges.push((1, i, s));
        }
        s += R & (1 << (N - i));
    }
    edges.push((1, N, s));

    let ans = format!("{} {}\n{}",
        N,
        edges.len(),
        edges.iter()
            .map(|&(i, j, w)| format!("{} {} {}", i, j, w))
            .collect::<Vec<_>>()
            .join("\n")
    );

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

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <map>
using namespace std;

const unsigned long long BASE = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    map<string, int> table;
    int maxCount = 0;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        map<string, int>::iterator pFind = table.find(s);
        if (pFind == table.end())
        {
            table.insert(pair<string, int>(s, 1));
            maxCount = maxCount > 1 ? maxCount : 1;
        }
        else
        {
            pFind->second++;
            maxCount = maxCount > pFind->second ? maxCount : pFind->second;
        }
    }
    for (map<string, int>::iterator pIter = table.begin(); pIter != table.end(); pIter++)
    {
        if (pIter->second == maxCount)
        {
            cout << pIter->first << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 19224
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include <math.h>
#include <string>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
typedef long long int ll;
const ll INF =1LL << 62;
using namespace std;
int MAX_E=1000010;
ll dp[1000010];
int main(){
    while(1){
        int e; cin >>e;
        if(e==0) break;
        int ans=1e9;
        for(int i=0;i*i*i<=e;i++){
            for(int j=0;j*j<=e-i*i*i;j++){
                ans=min(ans,i+j+(e-i*i*i-j*j));
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2988
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int X, K, Q, v[100009], t[100009], a[100009], ans[100009]; vector<int> g[100009];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> X >> K; K++;
	for (int i = 1; i < K; i++) cin >> v[i];
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> t[i] >> a[i];
		g[lower_bound(v, v + K, t[i] + 1) - v - 1].push_back(i);
	}
	int l = 0, r = X, e = 0;
	for (int i = 0; i < K; i++) {
		for (int j : g[i]) {
			int val = (a[j] < l ? e : (a[j] > r ? e + r - l : e + a[j] - l));
			ans[j] = (i & 1 ? min(X, val + t[j] - v[i]) : max(0, val - t[j] + v[i]));
		}
		if (i & 1) {
			e += v[i + 1] - v[i];
			if (e + r - l > X) {
				r -= e + r - l - X;
				if (r < l) r = l;
				e = X - r + l;
			}
		}
		else {
			e -= v[i + 1] - v[i];
			if (e < 0) {
				l -= e; e = 0;
				if (l > r) l = r;
			}
		}
	}
	for (int i = 0; i < Q; i++) cout << ans[i] << '\n';
	return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
   cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n;
  ll pre1=2;
  ll pre2=1;
  ll now=0;
  for(int i=2;i<=n;i++){
   now=pre1+pre2;
   pre1=pre2;
   pre2=now;
  }
  if(n==0){
   cout<<2<<endl;
  }else if(n==1){
   cout<<1<<endl;
  }else cout<<now<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
// long long -> lint
using lint = long long;
// fast cin and cout from hitonanode-san's code
// w/o 71 ms -> w/ 18 ms (tested on ABC148-D with C++14(GCC 5.4.1))
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

int main(){
    // input
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    for( int i=0 ; i<N; i++ ) cin >> P[i];
    for( int i=0 ; i<N; i++ ) cin >> Q[i];

    // calc
    vector<int> perm(N);
    for( int i=0 ; i<N; i++ ) perm[i] = i + 1;
    int a, b;
    int count = 0;
    do{
        bool check_a = true;
        bool check_b = true;
        for( int i=0 ; i<N; i++ ){
            if( P[i] != perm[i] ) check_a = false;
            if( Q[i] != perm[i] ) check_b = false;
        }
        if( check_a ) a=count;
        if( check_b ) b=count;
        count++;
    } while (next_permutation(perm.begin(), perm.end()));

    // out
    cout << abs( a-b ) << endl;
} 

Measured memory_bytes: 256
use std::io::Read;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let mut result = String::new();

    let mut heap: BinaryHeap<isize> = BinaryHeap::new();

    loop {
        let command = iterator.next().unwrap();
        if command == "insert" {
            let key: isize = iterator.next().unwrap().parse().unwrap();
            heap.push(key);
        } else if command == "extract" {
            let key = heap.pop().unwrap();
            result.push_str(&format!("{}\n", key));
        } else {
            break;
        }
    }

    return result.trim().to_string();
}



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

int main() {

    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    int target = 1;
    int cnt = 0;
    bool can = false;
    while (true) {
        target = a[target - 1];
        cnt++;
        if (target == 2) {
            can = true;
            break;
        }
        if (cnt == n) {
            break;
        }
    }

    if (can) cout << cnt << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
# include <map>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9+7;

int main()
{
    int n;
    scanf("%d",&n);
    int  a[100010];
    int b[100010]={0};

    for(int i = 0;i < n;i++){
        scanf("%d",&a[i]);
        b[a[i]]++;
    }

    int flag = 0;
    if(n%2==1)//奇数
    {
        if(b[0] != 1)
			flag = 1;
        for(int i = 2;i < n;i+=2)
        {
            if(b[i] != 2)
            {
                flag = 1;
            }
        }
    }else{  //偶数
        for(int i = 1;i < n;i+=2)
        {
            if(b[i] != 2)
            {
                flag = 1;
            }
        }
    }
    long long sum=1;

    for(int i=0;i<floor(n/2);i++)
    {
        sum=(sum*2)%mod;
    }
    if(flag)
        printf("0\n");
    else
        printf("%lld\n",sum);


return 0;
 }

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fast ios::sync_with_stdio(0),cin.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define ls (rt<<1)
#define rs (rt<<1|1)
#define All(a) (a).begin(),(a).end()
#define clr(a) memset((a),0,sizeof(a))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,a,b) for(int i=(a);i>=(b);--i)
#define FOR_edge(i,u)  for(int i=hd[u];i;i=e[i].nxt)
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,-1,1};

inline char in() {
	static char buf[10001],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,10000,stdin),p1==p2)?EOF:*p1++;
}
template <class Tp> inline void read(register Tp &s) {
	s=0;
	register bool neg=0;
	register char c;
	while(!isdigit(c=in())) if(c=='-') neg=1;
	while(s=(s<<3)+(s<<1)+c-48,isdigit(c=in()));
	s=(neg?-s:s);
}
template <class Tp> inline void write(register Tp x) {
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
template <class Tp> inline void print(const Tp &x,const char &end) {write(x); putchar(end);}
template <class Tp> inline Tp pow(register Tp x,register Tp p,const Tp &mod) {
	register Tp res=1;
	for(;p;p>>=1,x=(x*x)%mod) if(p&1) res=(res*x)%mod;
	return res;
}
inline int comp(const double &x,const double &y) {
	const double d=x-y,eps=1e-8;
	return (d<=eps&&d>=-eps)?0:(d>eps?1:-1);
}
template <class Tp> inline Tp sqr(const Tp &x) {return x*x;}
template <class Tp> inline Tp gcd(const Tp &x,const Tp &y) {return(y==0?x:gcd(y,x%y));}
template <class Tp> inline Tp inv(const Tp &x,const Tp &MOD) {return POW(x,MOD-2,MOD);}
template <class Tp> inline Tp lowbit(const Tp &x) {return x&-x;}

#define fail return puts("WA"),0
char s[15];
int main() {
	cin>>(s+1);
	int n=strlen(s+1);
	if(s[1]!='A') fail;
	if(s[2]=='C'||s[n]=='C') fail;
	int cnt=0;
	FOR(i,3,n-1) {
		if(s[i]=='C') cnt++;
		if(cnt>1) fail;
	}
	if(!cnt) fail;
	for(int i=1;i<=n;++i) {
		if(s[i]!='A'&&s[i]!='C'&&s[i]>='A'&&s[i]<='Z') fail;
	}
	puts("AC");
	return 0;
}

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();
    int ans = 0;
    for (char c : S.toCharArray()) {
      if (c == '+') {
        ans++;
      } else {
        ans--;
      }
    }
    System.out.println(ans);
  }
}

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

int main(void){
    int n,k;
    unsigned long long ans = 0;
    cin >> n >> k;
    unsigned long long memo = n/k;
    unsigned long long memo2 = (n-(k/2))/k+1;
    if(n*2<k)memo2 = 0;
    if (k%2 == 0)ans= pow(memo,3)+pow(memo2,3);
    else ans= pow(memo,3);
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  int K;
  int x;
  int a = 0;;
  cin >> N >> K;
  for (int i=0; i<N; i++) {
    cin >> x;
    if (x > K - x) {
      a += (K - x) * 2;
    }
    else {
      a += x * 2;
    }
  }
  cout << a << endl;
}

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

long long a1,b1,a2,b2,a3,b3,l[4][4],a,b,c,d;
string ss;
int main(){
    cin>>a1>>b1;
    if (a1==1){
        a++;
    }
    else if(a1==2){
        b++;
    }
    else if (a1==3){
        c++;
    }
    else{
        d++;
    }
    if (b1==1){
        a++;
    }
    else if(b1==2){
        b++;
    }
    else if (b1==3){
        c++;
    }
    else{
        d++;
    }
    cin>>a1>>b1;
    if (a1==1){
        a++;
    }
    else if(a1==2){
        b++;
    }
    else if (a1==3){
        c++;
    }
    else{
        d++;
    }
    if (b1==1){
        a++;
    }
    else if(b1==2){
        b++;
    }
    else if (b1==3){
        c++;
    }
    else{
        d++;
    }
    cin>>a1>>b1;
    if (a1==1){
        a++;
    }
    else if(a1==2){
        b++;
    }
    else if (a1==3){
        c++;
    }
    else{
        d++;
    }
    if (b1==1){
        a++;
    }
    else if(b1==2){
        b++;
    }
    else if (b1==3){
        c++;
    }
    else{
        d++;
    }
    if (a>2 or b>2 or c>2 or d>2){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
}


Measured memory_bytes: 256
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
v = [[0]*3 for i in range(n)]
for i in range(n):
    v[i][0] = ab[i][0]+ab[i][1]
    v[i][1] = ab[i][0]
    v[i][2] = ab[i][1]
v.sort()
v.reverse()
ans=0
for i in range(n):
    ans += v[i][1] if i%2==0 else -v[i][2]
print(ans)

Measured memory_bytes: 38168
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

int solve()
{
    int n,k;
    cin>>n >>k;
    ll arr[n];
    rep(i,n)
    {
        cin>>arr[i];
    }
    ll dp[n];
    memset(dp,1000001,sizeof(dp));
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    rep_a(i,2,n)
    for (int j = 1 ;j<=k;j++)
    {
        if(i-j>=0)
        dp[i] = min(dp[i-j] + abs(arr[ i - j] - arr[i]),dp[i]) ;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}
int main()
{
    /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
    #endif */
    solve();
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC<<" Sec\n";
    #endif */

    return 0;
} 

Measured memory_bytes: 1792
#include<iostream>
#include<unordered_set>
#include<climits>
using namespace std;

int main(){
	int a, b, c, d, e, f;
	unordered_set<int> x;
	unordered_set<int> y;
	double max_n = -1;
	double ne;
	int max_x = INT_MIN;
	int max_y = INT_MIN;
	cin >> a >> b >> c >> d >> e >> f;
	ne = (double)e * 100 / (100+e);
	for(int i=0; i<=f/a/100; i++){
		for(int j=0; j<=f/b/100; j++){
			if(i*a*100+j*b*100 <= f) {
				x.insert(i*a*100+j*b*100);
			}
		}
	}
	for(int i=0; i<=f/c; i++){
		for(int j=0; j<=f/d; j++){
			if(i*c+j*d <= f) {
				y.insert(i*c+j*d);
			}
		}
	}
	for(auto i: x){
		for(auto j: y){
			if(i+j){
				double n = (double)j * 100 / (i+j);
				if(i + j <= f && n <= ne && n > max_n) {
					max_n = n;
					max_x = i;
					max_y = j;
				}
			}
		}
	}
	cout << max_x + max_y << " " << max_y;
}



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

typedef struct {
	char word[21];
	int count;
} WORD;

int main(void)
{
	int n;
	char in[1030];
	char word[21];
	char k;
	WORD words[1024];
	WORD tmp;
	int word_n;
	int i, j;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		word_n = 0;
		fgets(in, 1030, stdin);
		for (i = 0; i < n; i++){
			fgets(in, 1030, stdin);
			j = 0;
			while (sscanf(&in[j], "%s", word) > 0){
				j += (strlen(word) + 1);
				for (k = 0; k < word_n; k++){
					if (strcmp(words[k].word, word) == 0){
						words[k].count++;
						break;
					}
				}
				if (k == word_n){
					strcpy(words[word_n].word, word);
					words[word_n].count = 1;
					word_n++;
				}
			}
//for (j = 0; j < word_n; j++){
//	printf("[%s]=%d\n", words[j].word, words[j].count);
//}
		}
		
		for (i = 0; i < word_n; i++){
			for (j = 0; j < word_n - 1; j++){
				if ((words[j].count < words[j + 1].count) ||
				    ((words[j].count == words[j + 1].count) && 
				     (strcmp(words[j].word, words[j + 1].word)) > 0)){
					 	
					tmp = words[j];
					words[j] = words[j + 1];
					words[j + 1] = tmp;
				}
			}
		}
		
//for (j = 0; j < word_n; j++){
//	printf("(%s)=%d\n", words[j].word, words[j].count);
//}
		
		scanf("%c", &k);

		j = 0;
		for (i = 0; i < word_n; i++){
			if (words[i].word[0] == k){
				if (j != 0){
					printf(" ");
				}
				printf("%s", words[i].word);
				j++;
				if (j == 5){
					break;
				}
			}
		}
		if (j == 0){
			printf("NA");
		}
		printf("\n");

	}
	return (0);
}

Measured memory_bytes: 648
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

string S;

signed main(){
    cin >> S;
    int ans = S.size()/2*2 + (S.size()-S.size()/2);
    rep(i, S.size()){
        if(S[i] == 'g') ans -= 1;
        else ans -= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3728
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    double a[n];
    double ans=0;
    REP(i,n){
        cin >> a[i];
        ans += 1/a[i];
    }

    printf("%.6f\n",1/ans);

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;

void solve() {
  int N, M, Q; cin >> N >> M >> Q;
  vector<ll> a(M), q(Q), prev(N), next(N), flag(N);
  rep(i, M) cin >> a[i];
  rep(i, Q) cin >> q[i];
  rep(i, N) {
    flag[i] = 1;
    prev[i] = (i - 1 + N) % N;
    next[i] = (i + 1) % N;
  }

  ll p = 0;
  rep(i, M) {
    if (a[i] % 2 == 0)
      rep(j, a[i]) p = next[p];
    else
      rep(j, a[i]) p = prev[p];

    // 列から抜ける
    flag[p] = 0;

    // 自身が抜けた分のポインタを付け替える
    prev[next[p]] = prev[p];
    next[prev[p]] = next[p];

    // 時計回りで次の人にバトンを渡す
    p = next[p];
  }
  rep(i, Q) outl(flag[q[i]]);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}



Measured memory_bytes: 9068
n,k=map(int,input().split())
s=input()
t=1
l=[0]
for i in s:
  i=int(i)
  if i==t: l[-1]+=1
  else: l+=[1]; t=i
if t<1: l+=[0]
s=[0]
for i in l: s+=[s[-1]+i]
a=0
for i in range(0,len(l),2):
  if i<2*k: a=max(a,s[i+1])
  else: a=max(a,s[i+1]-s[i-k*2])
print(a)

Measured memory_bytes: 7832
from collections import deque

s = list(input())
q = int(input())
s = deque(s)

flg = "order"
for i in range(q):
    t, *f = map(str, input().split())
    if t == "1":
        if flg == "order":
            flg = "reverse"
        else:
            flg = "order"
    else:
        if f[0] == "1":
            if flg == "order":
                s.appendleft(f[1])
            else:
                s.append(f[1])
        else:
            if flg == "order":
                s.append(f[1])
            else:
                s.appendleft(f[1])

if flg == "order":
    print("".join(s))
else:
    s.reverse()
    print("".join(s))

Measured memory_bytes: 74856
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    import numpy as np
    import sys
    n = int(input())
    arr = factorization(n)
    ans = 0
    for fact,num in arr:
        if fact == 1:
            print(0)
            exit(0)
        ans += int((np.sqrt(1+8*num) - 1)/2)  
    print(ans)


if __name__ == '__main__':
    main()

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, K;
    cin >> N >> K;
    vector<Pll> sushis(N);
    for (ll i = 0; i < N; i++) {
        cin >> sushis[i].second >> sushis[i].first;
    }
    sort(sushis.begin(), sushis.end(), greater<Pll>());
    ll pdeli = 0;
    stack<ll> dups;
    unordered_set<ll> st;
    for (ll i = 0; i < K; i++) {
        ll t, d;
        tie(d, t) = sushis[i];
        if (st.find(t) != st.end()) {
            dups.emplace(d);
        }
        pdeli += d;
        st.emplace(t);
    }

    ll nk = (ll)st.size();
    ll ans = pdeli + nk * nk;

    for (ll i = K; i < N; i++) {
        ll t, d;
        tie(d, t) = sushis[i];
        if (st.find(t) != st.end()) continue;
        if (dups.empty()) break;
        pdeli -= dups.top();
        dups.pop();
        pdeli += d;
        st.emplace(t);
        nk = (ll)st.size();
        ans = max(ans, pdeli + nk * nk);
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 5516
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FASTIO cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define ll long long int
#define F first
#define S second
#define pll pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vpii vector<pair<int,int> >
#define vvpii vector<vpii >
#define vpll vector<pair<ll,ll> >
#define vvpll vector<vpll >
#define pb push_back
#define MOD 1000000007
#define brk cout<<"\n"

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

struct compare {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		if ((a.S - a.F) != (b.S - b.F)) return ((a.S - a.F) > (b.S - b.F));
		else return (a.F < b.F);
	}
};

const int mx = 1e5 + 5;
ll n;
vvl edges(mx);
vvl dp(mx, vl(2, 1));
vector<bool> visited(mx);

// void mult_self(ll &a, ll b) {
// 	a += b;
// 	if (a >= MOD)a -= MOD;
// }

void calc(ll vertex) {
	visited[vertex] = true;
	for (auto i : edges[vertex]) {
		if (!visited[i]) {
			calc(i);
			dp[vertex][1] = (dp[vertex][1] * dp[i][0]) % MOD;
			dp[vertex][0] = (dp[vertex][0] * ((dp[i][0] + dp[i][1]) % MOD)) % MOD;
		}

	}
}

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	FASTIO;
	cin >> n;
	for (ll i = 0; i < n - 1; i++) {
		ll u, v; cin >> u >> v;
		edges[u].pb(v);
		edges[v].pb(u);
	}
	calc(1);
	ll ans = (dp[1][0] + dp[1][1]) % MOD;
	cout << ans; brk;
}

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

using namespace std;

const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  int cnt = 0;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') cnt++;
    }
  }
  vector<vector<int>> D(H, vector<int>(W, -1));
  D[0][0] = 1;
  queue<pair<int, int>> que;
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    auto q = que.front();
    que.pop();
    int y = q.first, x = q.second;
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
      if (D[ny][nx] != -1 || S[ny][nx] == '#') continue;
      D[ny][nx] = D[y][x] + 1;
      que.push(make_pair(ny, nx));
    }
  }
  cout << (D[H - 1][W - 1] == -1 ? -1 : H * W - cnt - D[H - 1][W - 1]) << '\n';
  return 0;
}


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

int main() {
  int d, n;
  cin >> d >> n;
  int ans = 0;
  if (d == 0) {
    if (n == 100) {
      cout << 101;
      return 0;
    } else {
      cout << n;
      return 0;
    }

  } else if (d == 1) {
    if (n == 100) {
      cout << 10100;
      return 0;
    } else {
      cout << 100 * d * n;
      return 0;
    }
  } else {
    if (n == 100) {
      cout << 1010000;
    } else {
      cout << 100 * 100 * n;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >>s;
    bool t=true;
    int n=s.size();
    if (s[0]!='1' || s[n-1]!='0') t=false;
    rep(i,0,n-1){
        if (s[i]!=s[n-2-i]) t=false;
    }
    if (!t) cout <<-1 << "\n";
    else{
        int a=1;
        rep(i,0,n-1){
            cout << a <<" "<<i+2<<"\n";
            if(s[i]=='1') a=i+2;
        }
    }
}


Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M; cin >> N >> M; 
	for(int i = 1; i < (1 << N); i++){
		int a; 
		for(int t = 0; t < 100; t++){
			if((i >> t) & 1){
				a = t; break; 
			}
		}
		for(int j = 1; j < (1 << M); j++){
			int b; 
			for(int t = 0; t < 100; t++){
				if((j >> t) & 1){
					b = t; break; 
				}
			}
			cout << (a == b ? 1 : 0); 
		}
		cout << endl; 
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(a >= k){
        cout << k << endl;
    }
    else {
        if(a+b >= k){
            cout << a << endl;
        }
        else{
            cout << 2*a+b-k << endl;
        }
    }
}


Measured memory_bytes: 3596
// ABC 112 C
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

struct info{
    int x,y,h;
};

int main(){
    int n; cin >> n;
    info I[n];
    for(int i = 0; i < n; i++){
        int x,y,h;
        cin >> x >> y >> h;
        I[i].x = x; I[i].y = y; I[i].h = h; 
    }

    for(int cx = 0; cx <= 100; cx++){
        for(int cy = 0; cy <= 100; cy++){
            bool f = true;
            int H = -1;
            vector<info> zeros;
            for(int i = 0; i < n; i++){
                if(I[i].h == 0) {
                    zeros.push_back(I[i]);
                    continue;
                }
                int w = I[i].h + abs(I[i].x-cx) + abs(I[i].y-cy);
                if(H == -1) H = w;
                else{
                    if(H == w) continue;
                    else {f = false; break;}
                }
            }
            if(f){
                for(auto it: zeros){
                    if(max(H-abs(it.x-cx)-abs(it.y-cy),0) != it.h) {
                        f = false; break;
                    }
                }
            }
            if(f) {cout << cx << " " << cy << " " << H << endl; return 0;}
        }
    }

    return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0; i<n; i++)
		cin >> v[i];
	vector<int> dp(n);
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	for(int i=2; i<n; i++){
		dp[i]=min(dp[i-2]+abs(v[i]-v[i-2]), dp[i-1]+abs(v[i]-v[i-1]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
//created by pyoxiao on 2020/05/02
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
int k, a, b;
void solve() {
    scanf("%d %d %d", &k, &a, &b);
    for(int i = a; i <= b; i ++) {
        if(i % k == 0) {
            puts("OK");
            return;
        }
    }
    puts("NG");
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 3764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
    int n, k, s; cin >> n >> k >> s;
    vector<int> ans(n);
    if (s == 1000000000) {
        for (int i = 0; i < k; i++) {
            ans[i] = 1000000000;
        }
        for (int i = k; i < n; i++) {
            ans[i] = 1;
        }
    }
    else {
        for (int i = 0; i < k; i++) {
            ans[i] = s;
        }
        for (int i = k; i < n; i++) {
            ans[i] = s + 1;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#define endl '\n'
#include <algorithm>
using namespace std;
const int MAXN=1e5+200;
int L[MAXN], R[MAXN], A[MAXN];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int N;
    cin >> N;
    cin >> A[0];
    L[0] = A[0];
    for (int i = 1; i < N; ++i) {
        cin >> A[i];
        L[i] = __gcd(L[i-1], A[i]);
    }
    R[N-1] = A[N-1];
    for (int i = N-2; i>=0; --i) {
        R[i] = __gcd(A[i], R[i+1]);
    }
    int ans = 0;
    ans = max(R[1], L[N-2]);
    for (int i = 1; i < N-1; ++i) {
        ans = max(ans, __gcd(L[i-1], R[i+1]));
    }
    cout << ans << endl;
    return 0;
}


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


static const string t = "01235789";

string	 to(int n){
	string ans;
	while(n) ans += t[n%8] , n/=8;
	reverse(ans.begin(),ans.end());
	return ans;
}

int main(){
	int n;
	while(cin >> n , n){
		cout << to(n) << endl;
	}
}

Measured memory_bytes: 904
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string N; cin >> N;
	ll x = 0, y = N[0] - '0' - 1 + (N.size() - 1) * 9;
	rep(i, 0, N.size()) {
		x += N[i] - '0';
	}
	cout << max(x, y) << "\n";

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            final int R = fs.nextInt();
            final int G = fs.nextInt();

            System.out.println(2 * G - R);
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22484
#include <cstdio>

using namespace std;

int a, b, c, d;

void solve() {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    for (int i=0; 0<a && 0<c; i++) {
        if (i%2) a -= d;
        else c -= b;
    }
    if (0>=a) printf("No\n");
    else printf("Yes\n");
}

int main() {
    solve();

    return 0;
}

Measured memory_bytes: 1636
n,k=map(int,input().split())
A=list(map(int,input().split()))

ng=0
ok=max(A)


while abs(ok-ng)>1:
    mid=(ok+ng)//2
    
    now=0
    for i in A:
        now+= i//mid-1 if i%mid==0 else i//mid
    if now> k :
        ng=mid
    else:
        ok=mid

print(ok)

Measured memory_bytes: 30824
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define vll vector<ll>
#define sz size()
#define pb emplace_back
#define mp make_pair
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL))
const int N = 100005;

int main()
{
	ll n;
	cin>>n;
	for(ll i=1;i<=9;i++)
	{
	   ll b=n/i;
	   ll a=n%i;
	   if(a==0 && b>=1 && b<=9)
	   {
	     cout<<"Yes";
	     return 0;
	   }
	}
	
	   cout<<"No";
}

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

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


using LP = pair<ll, int>;
string zeronumber(int x){
	string num = to_string(x);
	string zero = "";
	for(int i=6; i>(int)num.size(); i--) zero.push_back('0');
	return zero+num;
}
int main(){
	int N, M;
	cin >> N >> M;
	vector<LP> YP;
	for(int i=0; i<M; i++){
		int p; ll y;
		cin >> p >> y;
		p--;
		YP.emplace_back(y, p);
	}
	//sort(YP.begin(), YP.end());
	vector<vector<ll>> id(N, vector<ll>());//id[i][j]: 県iのj番目にできた年
	for(int i=0; i<M; i++){
		id[YP[i].second].push_back(YP[i].first);
	}
	// cout << " id: "; print_vec2(id);
	for(int i=0; i<N; i++){
		sort(id[i].begin(), id[i].end());
	}
	// cout << " id: "; print_vec2(id);
	for(int i=0; i<M; i++){
		int y = YP[i].first;
		int p = YP[i].second;
		string ue6 = zeronumber(p+1);
		
		auto iter = lower_bound(id[p].begin(), id[p].end(), y);
		auto index = iter - id[p].begin();
		string sita6 = zeronumber((int)index+1);
		cout << ue6 + sita6 << endl;
	}

	return 0;
}



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    string s;
    cin >> s;

    rep(i, s.size()){
        if(s[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
typedef long long ll;

int bucket[100000];
int main()
{
	memset(bucket, 0, sizeof(bucket));

	int N, Q;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		++bucket[A[i]];
	}
	cin >> Q;
	vector<ll> B(Q), C(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> B[i] >> C[i];
	}

	ll sum = 0;
	for (int i = 0; i < N; ++i) {
		sum += A[i];
	}
	for (int q = 0; q < Q; ++q) {
		sum = sum + (C[q] - B[q]) * bucket[B[q]];
		bucket[C[q]] += bucket[B[q]];
		bucket[B[q]] = 0;
		cout << sum << endl;
	}
}



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

int T,A,B,L,R,n,m,ans,l,r,mid,len,cA,cB;

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d%d%d%d",&A,&B,&L,&R);
		n=max(A,B),m=min(A,B);
		len=n/(m+1)+(n%(m+1)!=0);
		l=1,r=A+B,ans=0;
		while (l<=r)
		{
			mid=(l+r)>>1,cB=mid/(len+1),cA=mid-cB;
			if (cB<=B&&cA<=A&&B-cB<=1ll*(A-cA+1)*len-(mid%(len+1)==0)) ans=mid,l=mid+1; else r=mid-1;
		}
		if (ans%(len+1)==0&&ans>0) ans--;
		cB=ans/(len+1),cA=ans-cB;
		l=B-cB-(A-cA)*len;
		if (R<=ans) 
		{
			for (int i=L; i<=R; i++) putchar(i%(len+1)==0?'B':'A');
			puts("");
		} else
		if (L>ans)
		{
			for (int i=L; i<=R; i++) 
			{
				if (i<=ans+l) putchar('B'); else
				putchar((i-ans-l)%(len+1)==1?'A':'B');
			}
			puts("");
		} else
		{
			for (int i=L; i<=ans; i++) putchar(i%(len+1)==0?'B':'A');
			for (int i=ans+1; i<=R; i++) 
			{
				if (i<=ans+l) putchar('B'); else
				putchar((i-ans-l)%(len+1)==1?'A':'B');
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    int n,a;cin>>n>>a;
    cout<<(n%500<=a?"Yes":"No")<<endl;
    return 0;
}


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

vector<long> a(50);
vector<long> b(50);
vector<long> c(50);
vector<long> d(50);

long N,M,Q;
long A[10];
long idx=0;
long ans=0;
void dfs(int j, int dpth){
  if(dpth==N){
    long tmp=0;
    for(int i=0;i<Q;i++){
      if(A[b[i]-1]-A[a[i]-1]==c[i]) tmp+=d[i];
    }
    ans=max(tmp,ans);
    idx++;
  }
  else{
    for(int i=j;i<=M;i++){
      A[dpth]=i;
      dfs(i, dpth+1);
    }
  }
}

int main() {


cin>>N>>M>>Q;
//cout<<N;
for(int i=0;i<Q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];

dfs(1,0);

cout<<ans<<endl;
}


Measured memory_bytes: 3632