akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll a, b, c, k; cin >> a >> b >> c >> k;
    
    ll cnt = 0;
    while(a >= b){
        b *= 2;
        cnt++;
    }

    while(b >= c){
        c *= 2;
        cnt++;
    }

    print((cnt <= k)? "Yes" : "No")
    
    return 0;
}

Measured memory_bytes: 3596
N, K = [int(_) for _ in input().split()]
S = input()
now = ''
ans = 0
block = 0
for s in S:
    if now == s:
        ans += 1
    else:
        now = s
        block += 1
block = max(block - 2 * K, 1)
print(N - 1 - (block - 1))


Measured memory_bytes: 3316
import sys

h, w, d = map(int, input().split())
f = [list(map(int, input().split())) for _ in range(h)]

c_map = [0] * (h * w)
for i in range(h):
    for j in range(w):
        c_map[f[i][j] - 1] = (i, j)

d_map = [0] * (h * w)
for l in range(h * w - d - 1, -1, -1):
    i, j = c_map[l]
    i2, j2 = c_map[l + d]
    d_map[l] = d_map[l + d] + abs(i - i2) + abs(j - j2)

buf = []
q = int(input())
for line in sys.stdin.readlines():
    l, r = map(int, line.split())
    buf.append(d_map[l - 1] - d_map[r - 1])

print('\n'.join(map(str, buf)))


Measured memory_bytes: 88284
N, K, C = map(int, input().split())
S = input()
mae = [0] * (2 * N)
ato = [0] * (2 * N)

cnt = 0
n = 0 - N - 100

for i in range(N):
    if i - n <= C:
        continue

    if S[i] == 'o':
        mae[cnt] = i
        cnt += 1
        n = i

cnt = K - 1
n = 2 * N + 100

for i in range(N-1, -1, -1):
    if n - i <= C:
        continue

    if S[i] == 'o':
        ato[cnt] = i
        cnt -= 1
        n = i

for i in range(K):
    if mae[i] == ato[i]:
        print(mae[i]+1)


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
#define neig(a, u, e, v) for(int v, e = (a).head[u] ; ~e and (v = (a).to[e], 1) ; e = (a).nxt[e])

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 1e5 + 9, M = 1e6 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


struct Adj {
	int head[N], nxt[M], to[M], ne, n;
	void init(int n) {
		memset(head, -1, n * sizeof(head[0]));
		ne = 0;
		this->n = n;
	}
	void addEdge(int f, int t) {
		nxt[ne] = head[f];
		to[ne] = t;
		head[f] = ne++;
	}
	void addBiEdge(int f, int t) {
		addEdge(f, t);
		addEdge(t, f);
	}
	int addNode() {
		head[++n] = 0;
		return n;
	}
} adj;

int vis[N];

void bfs(int src){
    queue<int> q;
    q.push(src);
    vis[0] = 0;
    while(q.size()){
        int u = q.front();  q.pop();
        neig(adj, u, e, v){
            if(vis[v] != -1)    continue;
            vis[v] = u;
            q.push(v);
        }
    }
}

int n, m, u, v;

int main(){
    init();


    memset(vis, -1, sizeof vis);

    cin >> n >> m;
    adj.init(n);
    for(int i = 0;i < m;i++){
        cin >> u >> v;  u--, v--;
        adj.addBiEdge(u, v);
    }

    bfs(0);

    for(int i = 0;i < n;i++)    if(vis[i] == -1) return cout << "No", 0;

    cout << "Yes\n";
    for(int i = 1;i < n;i++)
        cout << vis[i] + 1 << '\n';
}

Measured memory_bytes: 7644
def main():
  n, m, x = map(int, input().split())

  books = []

  for _ in range(n):
    tpl = tuple(map(int, input().split()))
    books.append((tpl[0], tpl[1:]))

  dp = []

  for c, A in books:
    new_dp = [(c, A)]
    for total_cost, total_amount_list in dp:
      next_list = [A[i] + total_amount_list[i] for i in range(m)]
      new_dp.append((c + total_cost, next_list))

    dp.extend(new_dp)

  ans = tuple(filter(lambda tpl: min(tpl[1]) >= x, dp))
  if len(ans) == 0:
    print(-1)
  else:
    ans = sorted(ans, key=lambda tpl: tpl[0])[0]
    print(ans[0])


main()


Measured memory_bytes: 11812
N = int(input())
W = list(map(int, input().split()))
ans = sum(W)
for i in range(N):
    S1 = sum(W[:i+1])
    S2 = sum(W[i+1:])
    ans1 = abs(S1-S2)
    if ans1 < ans:
        ans = ans1
    else:
        break
print(ans)

Measured memory_bytes: 3060
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
  
#define int long long int 
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

double EPS = 1e-9; 
int INF = 1000000005; 
long long INFF = 1000000000000000005LL;
const int mod = 1e9 + 7; 

//#define CI cpp_int
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << " " ;
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define setBits(n) __builtin_popcountll(n)
#define MX *max_element
#define MN *min_element
#define TC int t; cin >> t; while (t--) 

void Panda() {
    int a, b;
    cin >> a >> b;
    cout << (2 * b > a ? 0 : a - (2 * b)) << endl;
}
  
int32_t main() {
 
    FAST;

    
    
    Panda();

    return 0; 
} 

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

int digits(ll n){
  ll SUM=0;
  while(n!=0){
    SUM+=n%10;
    n=n/10;
  }
  return SUM;
}
bool compare(ll x,ll y){
  return digits(y)*x<=y*digits(x);
}

int main(){
  ll k;cin>>k;
  ll d=1,Current=0;
  rep(i,k){
    ll x=Current+d,y=Current+d*10;
    if(compare(x,y)){
      Current=x;
    }else{
      Current=y;
      d*=10;
    }
    cout<<Current<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
n, x = map(int,input().split())
slimes = list(map(int,input().split()))
p = slimes[:]
ans = 5000000000000000

for i in range(n):
    for j in range(n):
        if p[j] > slimes[j-i]:
            p[j] = slimes[j-i]
    ans = min(ans, sum(p) + i * x)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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 = 1000100100;

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

    bool ans = false;
    ll cnt = 0;
    REP(i, N) {
        ll D1, D2;
        cin >> D1 >> D2;

        if(D1 == D2) {
            ++cnt;
            if(cnt >= 3) {
                ans = true;
            }
        } else {
            cnt = 0;
        }
    }

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

    return 0;
}

Measured memory_bytes: 3632
n = int(input())
A = sorted(map(int, input().split()))
U = A[-1]
line = [1]*(U+1)
ans = set()
depricated = set()
for a in A:
    if a in ans:
        depricated.add(a)
        continue
    if line[a]:
        ans.add(a)
        for p in range(2*a, U+1, a):
            line[p] = 0
print(len(ans-depricated))

Measured memory_bytes: 43404
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    string S;
    cin >> S;

    set<char> s;
    REP(i, S.length()) {
        s.emplace(S[i]);
    }

    for (char i = 'a'; i <= 'z'; i++) {
        if (s.find(i) == s.end()) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

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

    const int MAX = 3500;
    for (int x = 1; x <= MAX; x++) {
        for (int y = 1; y <= MAX; y++) {
            //double z1 = ((double)N * x * y);
            //double z2 = (4.0 * x * y - (double)N * y - (double)N * x);

            ll z1 = ((double)N * x * y);
            ll z2 = (4.0 * x * y - (double)N * y - (double)N * x);

            if (z2 > 0 && z1 % z2 == 0) {
                cout << x << " " << y << " " << z1 / z2 << endl;
                return 0;
            }

        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct{

  char name[10];
  int time;
}Process;

Process queue[100000];
int eqp = 0;
int ebp = 0;
void enqueue(Process q){
  if(eqp == 100000)
   eqp = 0;

  queue[eqp] = q;
  eqp++;

}
Process dequeue(){
  if(ebp == 100000)
   ebp = 0;

  ebp += 1;
  return queue[ebp-1];
}


int main(){
int n, q, i, sum = 0;

Process pro;
scanf("%d", &n);
scanf("%d", &q);

 for(i = 0; i < n; i++){
  scanf("%s", pro.name);
  scanf("%d", &pro.time);
  enqueue(pro);
 }

 while(ebp != eqp){

  pro = dequeue();
   if(pro.time <= q){
     sum += pro.time;
     printf("%s %d\n", pro.name, sum);

   }
   else{
    sum += q;
    pro.time -= q;
    enqueue(pro);
   }
}




 return 0;
}

Measured memory_bytes: 2160
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll alp[26];
    ll count[26];
    rep(i, 26){
        alp[i] = 0;
        count[i] = 0;
    }

    string S;
    cin >> S;
    rep(i, S.size()){
        alp[S[i] - 'a']++;
    }

    ll bothExist = 0;
    ll ans = 0;
    rep(i, S.size()){
        count[S[i] - 'a']++;
        if(count[S[i] - 'a'] == 1){
            bothExist++;
        }
        if(count[S[i] - 'a'] == alp[S[i] - 'a']){
            bothExist--;
        }
        ans = max(ans, bothExist);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
#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 ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = 998244353;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

#define No -1
#define Done -2

int n, m, k, w, req;
vector<int> g[MX];
vector<int> stk, rec(MX, No), color(MX);

void dfs(int x, int par, int c){
	color[x] = c;
	if(c == 0) w++;
	for(auto &y : g[x]){
		if(y == par) continue;
		dfs(y, x, c ^ 1);
	}
}

int main(){

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

	int x, y;
	cin >> x >> y;

	for(int i = 0; i <= x; ++i){
		int j = x - i;
		if(i * 2 + j * 4 == y) return puts("Yes"), 0;
	}

	puts("No");

	return 0;
}

Measured memory_bytes: 6280
#include<stdio.h>
#include<ctype.h>
int main(){
	
	char m;
	while(1){
		scanf("%c",&m);
		
		if(islower(m)){
			printf("%c",toupper(m));
		}else {
			printf("%c",tolower(m));
		}
		
		if(m=='\n'){
		break;
		}
	}
	
	
	
return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int k;
    cin >> k;
    int ans = 0;
    for (int i=1; i<=k; i+=2) for (int j=2; j<=k; j+=2) ++ans;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
//
//  main.cpp
//  MST2ND
//
//  Created by Dong Truong on 7/13/19.
//  Copyright © 2019 Dong Truong. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
#define long long long

const long maxn = 1e6+2 , cm=1e9+7 , ba=31;
struct elem
{
    long id,gt;
};

long n,q,gt[maxn];
vector <long> g[maxn];

void nhap()
{
    cin>>n>>q;
    for (int i=1;i<n;++i)
    {
        long x,y;cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for (int i=1;i<=q;++i)
    {
        long p,x;
        cin>>p>>x;
        gt[p]+=x;
    }
}
void dfs(long u,long par)
{
    for (int i=0;i<g[u].size();++i)
    {
        long v=g[u][i];
        if (v==par) continue;
        gt[v]+=gt[u];
        dfs(v,u);
    }
}
int main(int argc, const char * argv[]) {
   // freopen("a.inp","r",stdin);
    nhap();
    dfs(1,-1);
    for (int i=1;i<=n;++i) cout<<gt[i]<<" ";
    return 0;
}


Measured memory_bytes: 44672
#include<iostream>
#include<cstdio>
using namespace std;
main(){int a,b,c,d;
while(cin>>a>>b>>c){d=a*10000+b*100+c;
if(d<18680908){printf("pre-meiji\n");continue;}
if(d<19120730){printf("meiji %d %d %d\n",a-1867,b,c);continue;}
if(d<19261225){printf("taisho %d %d %d\n",a-1911,b,c);continue;}
if(d<19890108){printf("showa %d %d %d\n",a-1925,b,c);continue;}
printf("heisei %d %d %d\n",a-1988,b,c);}}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath> 
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main()
{
	int n;
	while(cin>>n)
	{
		vector < ll > v;
		for(int i=0;i<n;i++)
		{
			ll a;
			cin>>a;
			if(a>=0) v.push_back(a);
			else v.push_back(abs(a));
		}
//		cout<<v.size()<<"size"<<endl;
		vector < ll >::iterator it;
		ll mmax=-INF,mmin=INF;
		for(it=v.begin();it!=v.end();it++)
		{
			if(*it>mmax) mmax=*it;
			if(*it<mmin) mmin=*it;
		} 
		cout<<mmax-mmin<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 123123
int arr[MAX],N;

int main(){
  long long int X,Y;
  cin >> X >> Y;
  int count=1;
  X=X*2;
  while(X<=Y){
    X=X*2;
    count++;
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	char masu[7] ={};
	
	for(int i=0;i<7;i++){
		scanf("%c",&masu[i]);
	}
	
	if(masu[0]==masu[6]&&masu[1]==masu[5]&&masu[2]==masu[4])	printf("YES");
	else printf("NO");
		
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
void print(char c, int x) {
    rep(i, x) cout << c;
}
int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    //1-forward
    print('U', ty-sy);
    print('R', tx-sx);
    //1-back
    print('D', ty-sy);
    print('L', tx-sx);
    //2-forward
    print('L', 1);
    print('U', ty-sy+1);
    print('R', tx-sx+1);
    print('D', 1);
    //2-back
    print('R', 1);
    print('D', ty-sy+1);
    print('L', tx-sx+1);
    print('U', 1);
    puts("");
    //puts("UURDDLLUUURRDRDDDLLU");
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>

using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rer(i,l,r) for(int(i)=(l); (i)<(r); ++(i))
#define rep(i,n) rer(i,0,n)
#define gnr(i,l,r) for(int (i)=(r)-1; (i)>=(l); --(i))
#define pri(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<(p).fi<<' '<<(p).se<<'\n'
#define priend(a) {cout<<(a)<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

int main(){
  cin.tie(nullptr); ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);
  
  cin>>n>>m;  V(int)a(n+1,0); rep(i,n){cin>>x; a[x]++;} sort(ALL(a));
  int ans=0,id=1; rep(i,n+1)q+=min(1,a[i]); q=q-m;
  while(q>0){
    if(!a[id]){id++; continue;}
    ans+=a[id]; id++; q--;
  }
  END
}

Measured memory_bytes: 3968
#include<iostream>
#include<string>
using namespace std;
int a, b, c;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s.at(i) == 'a') {
			a++;
		}
		else if (s.at(i) == 'b') {
			b++;
		}
		else c++;
	}
	if (a == 1 && b == 1) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fname "E"
#define bug(x) cerr << (#x) << " = " << (x) << '\n'
#define ll long long
#define ld long double
#define ull unsigned long long
#define ui unsigned int
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define ARR0(a, n) {cerr <<(#a)<< ": ["; REP0(i, n) cerr<< ' ' << a[i] <<','; cerr<<"]\n";}
#define ARR1(a, n) {cerr <<(#a)<< ": ["; REP1(i, n) cerr<< ' ' << a[i] <<','; cerr<<"]\n";}
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ins insert
#define ers erase
#define LB lower_bound
#define UB upper_bound
#define X first
#define Y second

using namespace std;
template<typename T, typename V>
inline void bugp(const pair<T, V> &x) {cerr << '{' << x.X << ", " << x.Y << "}\n";}
template<typename T, typename U, typename V>
inline void bugpp(const pair<T, pair<U, V> > &x) {cerr << '{' << x.X << ", {" << x.Y.X << ", " << x.Y.Y << "}}\n";}
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<float, float> ff;
typedef pair<int, ii> iii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll, ii> lii;
const int N = 101, T = 100001;
int n, w, dp[N][T], max_t = 0;
ii item[N];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> w;
    REP1(i, n) {
        cin >> item[i].X >> item[i].Y;
        max_t += item[i].Y;
    }
    fill(&dp[0][0], &dp[0][0] + sizeof(dp)/sizeof(int), 1e9+5);
    REP0(i, n+1) dp[i][0] = 0;
    REP1(i, n) {
        REP1(t, max_t) {
            dp[i][t] = dp[i - 1][t];
            if(item[i].Y <= t)
                dp[i][t] = min(dp[i][t], dp[i - 1][t - item[i].Y] + item[i].X);
        }
    }
    REPB0(t, max_t+1) {
        if(dp[n][t] <= w) {
            cout << t;
            break;
        }
    }
	return 0;
}


Measured memory_bytes: 39680
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
//careful not to convert INF to int type.
typedef pair<int, int> P;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rep0(i,n) for(int i=0;i<n;i++)
#define per0(i,n) for(int i=n;i>0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
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; }
 

void solve() {
    int n; cin >> n;
    vector<vector<int> > abc(n+1);
    abc[0].push_back(0);
    abc[0].push_back(0);
    abc[0].push_back(0);

    rep(i,1,n+1){
        int a, b, c; cin >> a >> b >> c;
        abc[i].push_back(a);
        abc[i].push_back(b);
        abc[i].push_back(c);
    }
    int dp[3][n+10];
    dp[0][0] = 0;
    dp[1][0] = 0;
    dp[2][0] = 0;
    rep(i, 1, n+1){
        dp[0][i] = max(dp[1][i-1] + abc[i][1], dp[2][i-1] + abc[i][2]);
        dp[1][i] = max(dp[0][i-1] + abc[i][0], dp[2][i-1] + abc[i][2]);
        dp[2][i] = max(dp[1][i-1] + abc[i][1], dp[0][i-1] + abc[i][0]);
    }
    int ans = max(dp[0][n], max(dp[1][n], dp[2][n]));
    cout << ans;

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


Measured memory_bytes: 6912
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

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

int main(){

    int n;
    long long int m;
    cin >> n >> m;

    long long int a[n];
    int s=0;
    for(int i=0;i<n;i++){
      cin >> a[i];
      a[i]/=2;
    }

    long long int l=1;
    for(int i=0;i<n;i++){
        l=l/gcd(l,a[i])*a[i];
    }

    for(int i=0;i<n;i++)if((l/a[i])%2==0)s++;

    if(s>0 )cout << 0 << endl;
    else cout << m/(2*l) +(m%(2*l))/l<< endl;


    

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999
#define P(x)           printf("%d\n", (x));

typedef long long ll;

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

	vector<int> A(N);
	map<int, int> M;

	for(int &a : A){
		cin >> a;
		M[a]++;
	}
	
	VSORT(A);
	VREV(A);
	
	int ans = 0;
	for(int a : A){
		if(M[a]){
			M[a]--;
			for(int k = 30; (1L << k) > a; k--){
				if(M[(1L << k) - a]){
					M[(1L << k) - a]--;
					ans++;
					break;
				}
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 29824
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }



void solve() {
    ll n;
    cin >> n;
    vll L;
    L.pb(2);
    L.pb(1);
    rng(i,2,n+1){
        L.pb(L[i-1]+L[i-2]);
    }
    print(L[n]);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void)
{
    int year, month, day, sum;
    while(scanf("%d %d %d", &year, &month, &day) != EOF) {
	sum = 10000 * year+ 100 * month + day;
	if (sum < 18680907) {
	    printf("pre-meiji\n");
	} else if (sum < 19120730) {
	    printf("meiji %d %d %d\n", year - 1867, month, day);
	} else if (sum < 19261225) {
	    printf("taisho %d %d %d\n", year - 1911, month, day);
	} else if (sum < 19890108) {
	    printf("showa %d %d %d\n", year - 1925, month, day);
	} else {
	    printf("heisei %d %d %d\n", year - 1988, month, day);
	}
    }
    return 0;
}

Measured memory_bytes: 1036
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n) :
    if i==0 or i==n-1 : continue
    if a[i-1]>a[i] and a[i]>a[i+1] or a[i-1]<a[i] and a[i]<a[i+1] : ans+=1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m;
string s;

int main(){
	cin >> s;
	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]){
		cout << "Bad" << endl;
	}
	else{
		cout << "Good" << endl;
	}
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/03  Problem: ABC 048 B / Link: http://abc048.contest.atcoder.jp/tasks/abc048_b  ----- */


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

	LL A, B, X; cin >> A >> B >> X;
	auto f = [&X](LL n) {
		if (n >= 0)return n / X + 1;
		else return 0LL;
	};
	LL ans = f(B) - f(A - 1);


	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
using namespace std;

int K, X;
void solve() {
	cin >> K >> X;
	for (int x = X - K + 1; x <= X + K - 1; x++)cout << x << endl;
	return;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  xs <- getc solve
  mapM_ putStrLn xs

solve :: String -> String
solve  = decode "" . encodes

encodec :: Char -> String
encodec c
  | c == 'A'  = "00000"
  | c == 'B'  = "00001"
  | c == 'C'  = "00010"
  | c == 'D'  = "00011"
  | c == 'E'  = "00100"
  | c == 'F'  = "00101"
  | c == 'G'  = "00110"
  | c == 'H'  = "00111"
  | c == 'I'  = "01000"
  | c == 'J'  = "01001"
  | c == 'K'  = "01010"
  | c == 'L'  = "01011"
  | c == 'M'  = "01100"
  | c == 'N'  = "01101"
  | c == 'O'  = "01110"
  | c == 'P'  = "01111"
  | c == 'Q'  = "10000"
  | c == 'R'  = "10001"
  | c == 'S'  = "10010"
  | c == 'T'  = "10011"
  | c == 'U'  = "10100"
  | c == 'V'  = "10101"
  | c == 'W'  = "10110"
  | c == 'X'  = "10111"
  | c == 'Y'  = "11000"
  | c == 'Z'  = "11001"
  | c == ' '  = "11010"
  | c == '.'  = "11011"
  | c == ','  = "11100"
  | c == '-'  = "11101"
  | c == '\'' = "11110"
  | c == '?'  = "11111"

encodes :: String -> String
encodes s = concatMap encodec s

decode :: String -> String -> String
decode acc s
  | take 3 s == "101" = decode (' ' : acc) (drop 3 s)
  | take 3 s == "110" = decode ('E' : acc) (drop 3 s)
  | take 3 s == "111" = decode ('P' : acc) (drop 3 s)
  | take 4 s == "0001" = decode ('D' : acc) (drop 4 s)
  | take 4 s == "0101" = decode ('C' : acc) (drop 4 s)
  | take 4 s == "0111" = decode ('I' : acc) (drop 4 s)
  | take 4 s == "0110" = decode ('K' : acc) (drop 4 s)
  | take 4 s == "1000" = decode ('R' : acc) (drop 4 s)
  | take 5 s == "00100" = decode ('L' : acc) (drop 5 s)
  | take 5 s == "00101" = decode ('O' : acc) (drop 5 s)
  | take 5 s == "00110" = decode ('S' : acc) (drop 5 s)
  | take 5 s == "00111" = decode ('T' : acc) (drop 5 s)
  | take 5 s == "01001" = decode ('F' : acc) (drop 5 s)
  | take 6 s == "000000" = decode ('\'' : acc) (drop 6 s)
  | take 6 s == "000001" = decode ('?' : acc) (drop 6 s)
  | take 6 s == "000010" = decode ('W' : acc) (drop 6 s)
  | take 6 s == "000011" = decode (',' : acc) (drop 6 s)
  | take 6 s == "010001" = decode ('.' : acc) (drop 6 s)
  | take 6 s == "010000" = decode ('H' : acc) (drop 6 s)
  | take 6 s == "100101" = decode ('A' : acc) (drop 6 s)
  | take 8 s == "10010000" = decode ('Z' : acc) (drop 8 s)
  | take 8 s == "10010001" = decode ('-' : acc) (drop 8 s)
  | take 8 s == "10010010" = decode ('X' : acc) (drop 8 s)
  | take 8 s == "10010011" = decode ('Y' : acc) (drop 8 s)
  | take 8 s == "10011000" = decode ('J' : acc) (drop 8 s)
  | take 8 s == "10011001" = decode ('M' : acc) (drop 8 s)
  | take 8 s == "10011010" = decode ('B' : acc) (drop 8 s)
  | take 8 s == "10011011" = decode ('G' : acc) (drop 8 s)
  | take 8 s == "10011100" = decode ('U' : acc) (drop 8 s)
  | take 8 s == "10011101" = decode ('V' : acc) (drop 8 s)
  | take 8 s == "10011110" = decode ('N' : acc) (drop 8 s)
  | take 8 s == "10011111" = decode ('Q' : acc) (drop 8 s)
  | otherwise = reverse acc

toInt :: String -> Int
toInt s = read s

getc :: (String -> a) -> IO [a]
getc f = map f . lines <$> getContents

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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int m,c[4],r[4];
  int d[4] = {10,50,100,500};
  bool firstline = true;
  while(cin>>m,m){
    if(!firstline) cout<<endl;
    else firstline = false;
     
    int sum = 0;
    REP(i,4){
      cin>>c[i];
      sum += d[i]*c[i];
      r[i] = 0;
    }
    sum -=m;
    REP(i,4){
      r[3-i] = sum/d[3-i];
      sum %= d[3-i];
    }
    REP(i,4){
      int x = c[i] - r[i];
      if(x>0){
        cout<<d[i]<<" "<<x<<endl;
      }
    }
  }
  return 0;
}

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

int main() {
  int N,A, B;
  cin >>N;
  A=N%1000;
  B=N-(N%10);
  if(A%111==0||B%111==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		String[] data = new String[num * 2];
		for(int i = 0; i < num * 2; i++) {
			data[i] = in.next();
			data[i + 1] = in.next();
			i++;
		}
		for(int i = 0; i < data.length; i++) {
			System.out.println(solve(data[i], data[i+1]));
			i++;
		}
	}
	
	public static int solve(String a, String b) {
		int[][] arr = new int[a.length() + 1][b.length() + 1];
		for(int i = 1; i <= a.length(); i++) {
			for(int j = 1; j <= b.length(); j++) {
				if(!a.substring(i-1, i).equals(b.substring(j-1, j))) {
					arr[i][j] = Math.max(arr[i-1][j], arr[i][j-1]);
				} else {
					arr[i][j] = 1 + arr[i-1][j-1];
				}
			}
		}
		
		return arr[a.length()][b.length()];
	}
	
}


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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    string s;
    cin >> s;
    int q;
    cin >> q;
    int hanten = 0;
    vector<vector<char>> vsc(2);
    REP(i, q)
    {
        int a;
        cin >> a;
        if (a == 1)
            hanten = (hanten + 1) % 2;
        if (a == 2) {
            int b;
            char c;
            cin >> b >> c;
            vsc[(b - 1 + hanten) % 2].push_back(c);
        }
    }
    if (hanten == 0) {
        REP(i,vsc[0].size()){
            cout<<vsc[0][vsc[0].size()-1-i];
        }
        cout<<s;
        REP(i,vsc[1].size()){
            cout<<vsc[1][i];
        }
    } else {
        REP(i,vsc[1].size()){
            cout<<vsc[1][vsc[1].size()-1-i];
        }
        REP(i,s.length())
        cout<<s[s.length()-1-i];
        REP(i,vsc[0].size()){
            cout<<vsc[0][i];
        }
    }
    cout<<endl;
}

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

int main() {
    long long int x; cin >> x;
    if (x <= 6) {
        cout << 1 << endl;
    }
    else {
        long long t = x/11;
        int t2 = x%11;

        int c = 0;
        if (t2 > 0 && t2 < 7) c=1;
        else if (t2 && t2 >= 7) c=2;

        cout << t*2+c << endl;
    }
}


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

using namespace std;

int main()
{
    int h, r;   cin >> h >> r;
    if (h < 0) {
        if (0 - h == r) {
            cout << '0' << endl;
        } else {
            cout << "-1" << endl;
        }
    } else {
        cout << '1' << endl;
    }
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

cat gcd(cat a, cat b) {
	if(a > b) swap(a, b);
	return (a == 0) ? b : gcd(b%a, a);
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int T;
	cin >> T;
	while(T--) {
		cat A, B, C, D;
		cin >> A >> B >> C >> D;
		if(B > D || B > A) {
			cout << "No\n";
			continue;
		}
		if(C >= B-1) {
			cout << "Yes\n";
			continue;
		}
		cat G = gcd(B, D);
		if(A%G <= C%G) A /= G, C /= G;
		else A /= G, C = C/G-1;
		B /= G, D /= G;
		if(C < 0) {
			cout << "No\n";
			continue;
		}
		if(D == B) {
			cout << "Yes\n";
			continue;
		}
		// > C, < B zakazane
		D %= B;
		D += B;
		A %= B;
		if(C >= B-1) {
			cout << "Yes\n";
			continue;
		}
		// cout << B << " " << D << " " << A << " " << C << " ";
		cout << "No\n";
	}
	return 0;
}

// look at my code
// my code is amazing


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

using S = vector<int>;
using Rule = pair<S, int>;

vector<vector<vector<bool>>> table(S s, auto R) {
  auto n = s.size() - 1;
  auto h = s.size() / 2;

  vector<vector<vector<bool>>> res(n, vector<vector<bool>>(n, vector<bool>(30)));
  for(auto i = 0; i < n; ++i) res[i][i][s[i]] = true;

  bool dp[50][50][60][10] = {};
  for(auto i = 0; i < n; ++i) for(auto r = 0; r < R.size(); ++r) if(R[r].first.front() == s[i]) dp[i][i][r][0] = true;

  for(auto w = 0; w < h; ++w) {
    for(auto i = 0; i + w < n; ++i) {
      auto j = i + w;

      for(auto x = i; x < j; ++x) for(auto r = 0; r < R.size(); ++r) for(auto k = 1; k < R[r].first.size(); ++k) {
        if(dp[i][x][r][k-1] && res[x+1][j][R[r].first[k]]) dp[i][j][r][k] = true;
      }

      for(auto r = 0; r < R.size(); ++r) if(dp[i][j][r][R[r].first.size()-1]) res[i][j][R[r].second] = true;
      for(auto r = 0; r < R.size(); ++r) if(res[i][j][R[r].first[0]]) dp[i][j][r][0] = true;
    }
  }

  return res;
}

int solve(auto dpA, auto dpB) {
  auto nA = dpA.size(), hA = (dpA.size() + 1) / 2;
  auto nB = dpB.size(), hB = (dpB.size() + 1) / 2;

  int res = 0;

  for(auto a = 0; a < hA; ++a) for(auto b = 0; b < hB; ++b) {
    int dp[25][25];
    for(auto i = 0; i < hA; ++i) for(auto j = 0; j < hB; ++j) dp[i][j] = -1;

    for(auto i = 0; i < hA; ++i) for(auto j = 0; j < hB; ++j) if(a + i < nA && b + j < nB) {
      for(auto c = 0; c < 30; ++c)
        if(dpA[a][a+i][c] && dpB[b][b+j][c])
          dp[i][j] = 1;
    }

    for(auto i = 0; i < hA; ++i) for(auto j = 0; j < hB; ++j) if(dp[i][j] != -1) {
      for(auto x = 1; i + x < hA; ++x)
        for(auto y = 1; j + y < hB; ++y)
          for(auto c = 0; c < 30; ++c)
            if(dpA[a+i+1][a+i+x][c] && dpB[b+j+1][b+j+y][c])
              dp[i+x][j+y] = max(dp[i+x][j+y], dp[i][j] + 1);

      res = max(res, dp[hA-1][hB-1]);
    }
  }

  return res ? res : -1;
}

int main() {
  int n, m, r;
  while(cin >> n >> m >> r, n | m | r) {
    S A(n), B(m);
    for(auto& i: A) cin >> i, --i;
    for(auto& i: B) cin >> i, --i;

    vector<Rule> R(r);
    for(auto& i: R) {
      int k;
      cin >> k;
      i.first = S(k);
      for(auto& j: i.first) cin >> j, --j;
      cin >> i.second;
      --i.second;
    }

    A.insert(end(A), begin(A), end(A));
    B.insert(end(B), begin(B), end(B));
    auto dpA = table(A, R);
    auto dpB = table(B, R);

    cout << solve(dpA, dpB) << endl;
  }
}

Measured memory_bytes: 5312
#0:09
"""
ABC数
遷移を考える問題
dp[どこまでみたか][その時の状態] = になりうる場合の数
"""
S = input()
n = len(S)

dp = [[0]*3 for i in range(n+1)]
cnt = 0 #はてなの数
#初期は後で構築
mod = 10**9 + 7 

X = 1
for i in range(n):
    if S[i] == "A":
        dp[i+1][0] = dp[i][0] + X
        dp[i+1][1] = dp[i][1]
        dp[i+1][2] = dp[i][2]
    elif S[i] == "B":
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod
        dp[i+1][2] = dp[i][2]
    elif S[i] == "C":
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = dp[i][1]
        dp[i+1][2] = (dp[i][1] + dp[i][2]) % mod
    elif S[i] == "?":
        dp[i+1][0] = (dp[i][0] * 3 + X) % mod
        dp[i+1][1] = (dp[i][1] * 3)%mod + (dp[i][0]) % mod
        dp[i+1][2] = (dp[i][2] * 3)%mod + (dp[i][1]) % mod        
        X = (X*3)%mod
print(dp[n][2]%mod)

Measured memory_bytes: 22796
using System;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var a = int.Parse(_[0]);
            var b = int.Parse(_[1]);

            var s = 0;
            for(var i = 1; i <= b - a; i++){
                s += i;
            }

            Console.WriteLine(s - b);
        }
    }
}


Measured memory_bytes: 11092
s = gets.chomp
l = 0
r = s.size-1
ans = 0
while l <= r
	if l == r || (l+1 == r && s[l] == s[r])
		break
	end
	if s[l] == s[r]
		l += 1
		r -= 1
	elsif s[l] == "x"
		ans += 1
		l += 1
	elsif s[r] == "x"
		ans += 1
		r -= 1
	else
		puts -1
		exit
	end
end
puts ans

Measured memory_bytes: 1916
n=int(input())
L=list(map(int,input().split()))

cnt=0
for i in range(1,n-1):        
    if ((L[i-1]<L[i] and L[i]<L[i+1]) or (L[i+1]<L[i] and L[i]<L[i-1])):
        cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}




int main(void) {

	string s;
	cin >> s;

	lli k;
	cin >> k;

	for (lli i = 0; i < k; i++) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}

	cout << '1' << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
text = ["AC", "WA", "TLE", "RE"]
count = [0,0,0,0]
for j in range(n):
  line = input()
  for i in range(4):
    if line == text[i]:
      count[i] += 1
      
for i in range(4):
  print(str(text[i]) + " x " + str(count[i]))

Measured memory_bytes: 9204
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define MOD (1e9+7)

int main(void){
	int n,i;
  	ll a[12345],b[12345],debt=0ll;
	bool flag = true;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	for(i=0; i<n; i++){
		cin >> b[i];
	}
	for(i=0; i<n; i++){
		if(a[i]>b[i]){
			debt += (a[i]-b[i])*2;
			b[i] = a[i];
		}
	}
	for(i=0; i<n; i++){
		debt -= ((b[i]-a[i])/2)*2;
	}
	cout << ((debt<=0)?"Yes":"No") << endl;
	return 0;
}


Measured memory_bytes: 384
package main

import(
      "fmt"
)

func main(){
  var n int
  ans := 0
  fmt.Scan(&n)
  for i:=0; i<n; i++ {
    var a int
    fmt.Scan(&a)
    cnt := 0
    for a%2==0 {
      a/=2
      cnt++;
    }
    ans+=cnt;
  }
  fmt.Println(ans)
}

//====  ↓↓↓ template functions ↓↓↓  ======================

func min(a, b int64) int64{
  if a < b {
    return a
  }
  return b
}

func max(a, b int64) int64{
  if a > b {
    return a
  }
  return b
}

func abs(x int64) int64{
  if x < 0 {
    return -x
  }
  return x
}

func gcd(a, b int64) int64{
  if b == 0 {
    return a
  }else{
    return gcd(b, a%b)
  }
}

func lcm(a, b int64) int64{
  return a*b/gcd(a, b);
}

Measured memory_bytes: 1280