akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1e9
 
int t,ans,size,diff;
vector<int> a,path;
map<int,int> mp;
 
int calc(int idx,int N){
    int res = 0, p = 1;
    for(int i = N-1 ; i >= idx ; i--){
	res += a[i]*p;
	p *= 10;
    }
    return res;
}
 
void solve(int idx,int val,vector<int> &v){
    if(idx == size){
	if(val > t) return;
	if(t-val <= diff){
	    diff = t-val;
	    ans = val; mp[ans]++;
	    path = v;
	}
	return;
    }
 
    for(int i = 1 ; i <= size ; i++){
	if(idx + i > size) continue;
	int c = calc(idx,idx+i);
	v.push_back(c);
	solve(idx+i,val+c,v);
	v.pop_back();
    }
}
 
int main(){
    int num;
    while(cin >> t >> num, (t | num)){
	mp.clear(); a.clear(); 
	diff = ans = INF;
	for(int i = 0 ; ; i++){
	    if(num == 0) break;
	    a.push_back(num%10);
	    num /= 10;
	}
	reverse(a.begin(),a.end());
	size = a.size();
	vector<int> v;
	solve(0,0,v);
	if(diff == INF){
	    cout << "error" << endl;
	}else{
	    if(mp[ans] != 1){
		cout << "rejected" << endl;
	    }else{
		cout << ans;
		for(int i = 0 ; i < (int)path.size() ; i++){
		    cout << " " << path[i];
		}
		cout << endl;
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 2928
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;


const long long int mod=1000000007;
int main(){
	cout << fixed << setprecision(18);
	string str;
	char ch;
	long long int n,a[200005],num[128]={},res=0;
	cin>>str;
	for(int i=0;i<=str.length();i++)
	{
		num[str[i]]++;
	}
	res=str.length()*(str.length()+1)/2+1;
	for(int i='a';i<='z';i++)
	{
		res-=num[i]*(num[i]+1)/2;
	}
	cout<<res<<endl;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  //
  string s;
  cin >> s;

  int cur = 0, ans = 0;
  while (cur < s.size()) {
    if (s[cur] != 'R') {
      cur++;
      continue;
    }

    int cur2 = cur;
    while (cur2 < s.size() && s[cur2] == 'R') {
      cur2++;
    }

    ans = max(ans, cur2 - cur);
    cur = cur2;
  }

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

Measured memory_bytes: 3628
N,M,*L = map(int, open(0).read().split())
S = L[:N]
T = L[N:]
MOD = 10**9+7
dp = [[0]*(M+1) for i in range(N+1)]
for i in range(N+1):
  dp[i][0] = 1
for j in range(M+1):
  dp[0][j] = 1
for i in range(1,N+1):
  for j in range(1,M+1):
    if S[i-1]==T[j-1]:
      dp[i][j] += dp[i][j-1]+dp[i-1][j]
    else:
      dp[i][j] += dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]
    dp[i][j] %= MOD
print(dp[N][M])

Measured memory_bytes: 72924
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    string k;
    rep(i,n){
        k.push_back(s[i]);
        k.push_back(t[i]);
    }
    cout << k << endl;
}


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

struct vertex {
    lint counter = 0;
    lint plus = 0;
    vector<lint> edge;
};

lint n, q;
vector<vertex> g;

void dfs(lint node) {
    g[node].counter += g[node].plus;
    for(auto e : g[node].edge) {
        g[e].plus += g[node].plus;
        dfs(e);
    }
}

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

    g.resize(n);
    for(lint i = 0; i < n-1; i++) {
        lint a, b;
        cin >> a >> b;
        a--; b--;
        g[a].edge.push_back(b);
    }

    for(lint i = 0; i < q; i++) {
        lint p, x;
        cin >> p >> x;
        p--;
        g[p].plus += x;
    }

    dfs(0);

    for(lint i = 0; i < n; i++) {
        cout << g[i].counter << " \n"[i == n-1];
    }
}

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

int main()
{
  std::string str;
  std::cin >> str;

  std::vector<int> childs(str.length(), 0);
  for(int i=0; i<str.size(); i++)
  {
    if(str[i]=='R')
    {
      int endR;
      for(endR=i; endR<str.size(); endR++) { if(str[endR]!='R') {endR-=1; break;} }
      int lengthR = endR - i + 1;
      childs[endR]   += lengthR / 2 + lengthR % 2;
      childs[endR+1] += lengthR / 2;
      i=endR;
    }
    else
    {
      int endL;
      for(endL=i; endL<str.size(); endL++) { if(str[endL]=='R') {endL-=1; break;} }
      if( endL==str.size() ) { endL -= 1;}
      int lengthL = endL - i + 1;
      childs[i]   += lengthL / 2 + lengthL % 2;
      childs[i-1] += lengthL / 2;
      i=endL;
    }
  }

  for(const auto& e: childs) { std::cout << e << " "; }
}


Measured memory_bytes: 1024
import sys
import itertools
input = sys.stdin.readline


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


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]

    
def main():
    N, K = read_values()
    R, S, P = read_values()
    T = input().strip()

    res = 0
    F = [True] * N
    for i, t in enumerate(T):
        if i >= K:
            if T[i - K] == T[i] and F[i - K]:
                F[i] = False
                continue
        
        if t == "r":
            res += P
        elif t == "s":
            res += R
        elif t == "p":
            res += S
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4084
#include <iostream>

using namespace std;

int main() {
  while(true) {
    int H, W;
    cin >> H >> W;

    if (H == 0 && W == 0) {
      break;
    }

    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}
map<ll,ll> prime_factor(ll x){
    map<ll,ll> m;
    ll sq=(ll)sqrt(x) + 1;
    vector<ll> v_prime=vectorprime(sq);
    
    ll tmp=x;
    rep(i,sz(v_prime)){
        ll count=0;
        while(tmp % v_prime[i] == 0){
            tmp /= v_prime[i];
            count++;
        }
        if(count != 0) m[v_prime[i]]=count;
        if(tmp==1) break;
    }
    
    if(tmp != 1) m[tmp]=1;
    return m;
}

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll H,W; cin>>H>>W;
    vector<ll> N(26,0);
    rep(i,H){
        string t; cin>>t;
        rep(j,W) N[(ll)(t[j]-'a')]++;
    }
    
    //1あまり許容
    ll rem1 = (H%2)*(W%2);
    ll tmp1=0;
    rep(i,26){
        if(N[i]%2==1) tmp1++;
    }
    
    if(rem1<tmp1) cout<<"No";
    else{
        ll rem2 = (H/2)*(W%2)+(W/2)*(H%2);
        ll tmp2=0;
        rep(i,26){
            tmp2+=(N[i]%4)/2;
        }
        if(rem2<tmp2) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}



Measured memory_bytes: 3728
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int dp[50][100001];

struct Elem {
    int sum, mod;
    bool operator<(const Elem &a) const {
        return dp[sum][mod] > dp[a.sum][a.mod];
    }
};

signed main() {
    int K; cin >> K;
    rep(i,0,50) rep(j,0,100001) dp[i][j] = INF;
    dp[0][0] = 0;

    // sum, mod
    priority_queue<Elem> q;
    q.push(Elem{0, 0});
    while(!q.empty()) {
        Elem cur = q.top(); q.pop();
        rep(x,0,10) {
            int nsum = cur.sum + x;
            int nmod = (cur.mod * 10 + x) % K;
            if(nsum > 45) continue;
            if(dp[nsum][nmod] > dp[cur.sum][cur.mod] + 1) {
                dp[nsum][nmod] = dp[cur.sum][cur.mod] + 1;
                q.push(Elem{nsum, nmod});
            }
        }
    }
    rep(i,1,50) {
        if(dp[i][0] != INF) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

int main(){
    string s;
    cin >> s;

    int t = 0;
    char c = s[0];
    for(int i = 1; i < s.size(); ++i){
        if(s[i] == c) continue;
        else{
            c = s[i];
            t++;
        }
    }

    cout << t << endl;

    return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define sp std::fixed<<std::setprecision
#define MOD 1000000007
#define MAX 1e18
#define N 1000005
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll l , r , mn = MAX;
    cin >> l >> r;
    if( ( r - l ) >= 2019 )
    {
        cout << 0 << endl;
        return 0;
    }
    l = ( l % 2019 );
    r = ( r % 2019 );
    for( int i = l ; i < r ; i++ )
    {
        for( int j = i + 1 ; j <= r ; j++ )
        {
            if( ( i % 2019 * j % 2019 ) % 2019 < mn )
                mn = ( i % 2019 * j % 2019 ) % 2019;
        }
    }
    cout << mn << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
ll N , K , loop_start;
vector<ll>A;
vector<bool>visited;
vector<bool>neo_visited;
vector<ll>k,loops;

void dfs(ll now){
  if(visited[now-1]){
    loop_start = now;
    return;
  }  
  visited[now-1] = true;
  k.pb(now);
  dfs(A[now-1]);
  return;
}

void neo_dfs(ll now){
  if(neo_visited[now-1]){
    return;
  }
  loops.pb(now);
  neo_visited[now-1] = true;
  neo_dfs(A[now-1]);
}

int main(){
  cin >> N >> K;
  A.resize(N);
  visited.resize(N,false);
  neo_visited.resize(N,false);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  dfs(1);
  neo_dfs(loop_start);
  if(K < (k.size()-loops.size())){
    cout << k[K] << endl;
  }else{
    K -= (k.size() - loops.size());
    cout << loops[K%loops.size()] << endl;
  }
}


Measured memory_bytes: 15184
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    int N;
    cin >> N;
    vector<vector<char>> s(N);
    REP(i,N){
        REP(j,10){
            char c;
            cin>>c;
            s[i].push_back(c);
        }
    }
    REP(i,N){
        sort(s[i].begin(),s[i].end());
    }
    sort(s.begin(),s.end());
    vector<ll> same;
    ll cnt=1;
    REP(i,N){
        if(s[i]==s[i+1]){
            cnt++;
        }else{
            same.push_back(cnt);
            cnt=1;
        }
    }
    ll ans=0;
    REP(i,same.size()){
        ans+=same[i]*(same[i]-1)/2;
    }
    printAns(ans);
}


Measured memory_bytes: 6904
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
using ll = long long;
int main(void){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    string ans;
    for(int i=0;i<n;i++){
        ans+=s[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Stream;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        Prim p = new Prim(n);
        
        int[][] xa = new int[n][];
        int[][] ya = new int[n][];
        
        for(int i=0; i<n; i++){
            xa[i] = new int[]{sc.nextInt(), i};
            ya[i] = new int[]{sc.nextInt(), i};
        }
        
        Arrays.sort(xa, Comparator.comparingInt(o->o[0]));
        Arrays.sort(ya, Comparator.comparingInt(o->o[0]));
        
        
        for(int i=0; i<n-1; i++){
            addEdge(p, xa, i);
            addEdge(p, ya, i);
        }
        
        System.out.println(p.prim());
    }
    
    public static void addEdge(Prim p, int[][] za, int i){
        int from = za[i][1];
        int to = za[i+1][1];
        int cost = za[i+1][0] - za[i][0];
        p.addEdge(from, to, cost);
    }
    
}

class Prim{
    
    public static int n;
    private static List<Edge>[] edge;
    
    public static final int inf = (int)10e9;
    
    public Prim(int n){
        this.n = n;
        
        edge = new List[n];
        for(int i=0; i<n; i++){
            edge[i] = new ArrayList<>();
        }
    }
    
    public long prim(){
        boolean[] check = new boolean[n];
        Queue<Edge> q = new PriorityQueue<>();
        q.add(new Edge(0,0,0));//だみー
        
        long res = 0;
        
        while(!q.isEmpty()){
            Edge e = q.poll();
            if(check[e.to]){
                continue;
            }
            
            check[e.to] = true;
            res += e.cost;
            
            q.addAll(edge[e.to]);
        }
        
        return res;
    }
    
    public void addEdge(int from, int to, int cost){
        edge[from].add(new Edge(from, to, cost));
        edge[to].add(new Edge(to, from, cost));
    }
    
    class Edge implements Comparable<Edge>{
        public int from = 0;
        public int to = 0;
        public int cost = 0;
        
        public Edge(int from, int to, int cost) {
            this.from = from;
            this.to = to;
            this.cost = cost;
        }
        
        @Override
        public int compareTo(Edge o) {
            return this.cost - o.cost;
        }
    }
}

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

bool exists(int a, int e, int k)
{
  if (e - a > k) {
    return true;
  } else {
    return false;
  }
}

int main(int argc, char **argv)
{
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if (exists(a,e,k)) {
    cout << ":(";
  } else {
    cout << "Yay!";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll N;
vector<vector<ll>> bit(26);

ll sum(ll ind, ll i)
{
  ll s = 0;
  while (i > 0)
  {
    s += bit.at(ind).at(i);
    i -= i & -i;
  }
  return s;
}

void add(ll ind, ll i, ll x)
{
  while (i <= N)
  {
    bit.at(ind).at(i) += x;
    i += i & -i;
  }
}

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

  for (ll i = 0; i < 26; i++)
  {
    bit.at(i) = vector<ll>(N + 1, 0);
    for (ll j = 1; j <= N; j++)
    {
      add(i, j, (S.at(j - 1) - 'a' == i));
    }
  }

  ll Q;
  cin >> Q;
  for (ll q = 0; q < Q; q++)
  {
    ll qt;
    cin >> qt;
    if (qt == 1)
    {
      ll i;
      char c;
      cin >> i >> c;

      add(S.at(i - 1) - 'a', i, -1);
      S.at(i - 1) = c;
      add(c - 'a', i, 1);
    }
    else
    {
      ll l, r;
      cin >> l >> r;
      ll ans = 0;
      for (ll i = 0; i < 26; i++)
      {
        ans += (sum(i, r) - sum(i, l - 1) >= 1);
      }

      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 102528
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<int> p(n);
  unordered_map<int,int> mp;
  for (int i = 0; i < n; ++i)
  {
    int tmp;
    cin>>tmp;
    mp[tmp]=i;
  }
  int cnt=1, ans=0;
  for (int i = 0; i < n-1; ++i)
  {
    if (mp[i+1]<mp[i+2]) {
      cnt++;
    } else {
      ans = max(ans,cnt);
      cnt = 1;
    }
  }
  ans = max(ans,cnt);
  cout<<n-ans<<endl;
}

Measured memory_bytes: 12244
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();

		if (a[0] == 'H' && b[0] == 'H') {
			pr.println('H');
		} else if (a[0] == 'D' && b[0] == 'H') {
			pr.println('D');
		} else if (a[0] == 'H' && b[0] == 'D') {
			pr.println('D');
		} else if (a[0] == 'D' && b[0] == 'D') {
			pr.println('H');
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


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


int main(){
  int X;
  cin >> X;
  
  X = X/100;
  if (4<= X && X<=5){
    cout << 8;
  return 0;
  }
    if (6<= X && X<=7){
    cout << 7;
  return 0;
  }
    if (8<= X &&X<=9){
    cout << 6;
  return 0;
  }
    if (10<= X && X<=11){
    cout << 5;
  return 0;
  }
    if (12<= X && X<=13){
    cout << 4;
  return 0;
  }
    if (14<= X && X<=15){
    cout << 3;
  return 0;
  }
    if (16<= X && X<=17){
    cout << 2;
  return 0;
  }
    if (18<= X && X<=19){
    cout << 1;
  return 0;
  }
  return 0;

}

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

int main() {
    int N;
    string S;
    int K;

    // in
    cin >> N;
    cin >> S;
    cin >> K;

    // calc
    char c = S[K-1];
    for(int i=0; i<N; i++){
        if (S[i]!=c) S[i]='*';
    }

    // out
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#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>;
 
 
int main() {
    string s;
    cin >> s;
    vector<char> ss(s.size()+1);
    ss.at(4)=' ';
    rep(i,4)ss.at(i)=s.at(i);
    for(int i=5;i<s.size()+1;i++){
        ss.at(i)=s.at(i-1);
    }
    rep(i,s.size()+1){
        cout << ss.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const ll LL_MAX=9223372036854775807;
ll sum;
ll s,x1,x2,Y1,y2,z1,z2,res;
ll a,b,c,d;
ll gcd(ll a,ll b)
{
   return b==0?a:gcd(b,a%b);
}
int main()
{
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    s=d/gcd(c,d)*c;
    x1=(a-1)/c;
    Y1=(a-1)/d;
    z1=(a-1)/s;
    x2=b/c;
    y2=b/d;
    z2=b/s;
    res=b-(x2+y2-z2)-(a-1-(x1+Y1-z1));
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 256
import numpy as np

posi_list = []
for _ in range(5):
  posi_list.append(int(input()))
k = int(input())

flag=True
for i in range(5):
  temp_posi_list = posi_list.copy()
  posi = temp_posi_list[i]
  del temp_posi_list[i]
  temp_posi_list = np.array(temp_posi_list)
  max_dist = max(np.abs(temp_posi_list - posi))
  if max_dist > k:
    flag=False
    break
if flag:
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 12408
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vector<int>>;

int main(){
    int l; cin>>l;
    double V_L = pow(l,3)/27;

    cout << fixed << setprecision(12) << V_L << endl;
}


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

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)


int main() {
	string s,t;
	cin >> s >> t;
	int count = 0;
	rep(i, s.size()) {
		if (s[i] != t[i]) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3376
*D, = open(0)
n = int(D[0])
 
edge = [[] for _ in range(n+1)]
v_val = [0 for _ in range(n+1)]
 
dist = {}
 
for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a)
c = list(map(int, D[n].split()))
 
c = sorted(c, reverse=True)
 
# 木の端を求める
def findLeaf(edge, start=1):
    visited = [False for _ in range(len(edge))]
    next_v = edge[start]
    visited[start] = True
    count = 0
    
    while len(next_v) > 0:
        new_v = []
        for it in next_v:
    #         print(it)
            leaf = it
            for v in edge[it]:
                if not visited[v]:
                    new_v.append(v)
            visited[it] = True
        next_v = new_v
        count += 1
 
    return leaf, count
 
 
# 木の直径を求める
def findD(edge):
    leaf, _ = findLeaf(edge, 1)
    leaf, count = findLeaf(edge, leaf)
    return count
 
# 木の中心を求める
def findCenter(edge):
    leaf, _ = findLeaf(edge, 1)
    leaf, d = findLeaf(edge, leaf)
    r = d//2
 
    visited = [False for _ in range(len(edge))]
    start = leaf
    next_v = edge[start]
    # print(next_v, leaf)
    visited[start] = True
    count = 0
 
    while not r == count+1:
        new_v = []
        for it in next_v:
    #         print(it)
            leaf = it
            for v in edge[it]:
                if not visited[v]:
                    new_v.append(v)
            visited[it] = True
        next_v = new_v
        count += 1
        
    center = []
    for it in next_v:
        if len(edge[it]) > 1:
            center.append(it)
    return center
 
 
def calcCost(D, v_val):
    total = 0
    
    n = int(D[0])
    for i in range(1, n):
        a, b = map(int, D[i].split())
        total += min(v_val[a], v_val[b])
        
    return total
 
 
max_val = 0
max_v = 0
l, _ = findLeaf(edge)
for center in [l]:
    order = []
    start = center
    visited = [False for _ in range(len(edge))]
    next_v = edge[start]
    visited[start] = True
    order.append(center)
 
    # Get order from center
    while len(next_v) > 0:
        new_v = []
        for it in next_v:
    #         print(it)
            leaf = it
            for v in edge[it]:
                if not visited[v]:
                    new_v.append(v)
            visited[it] = True
            order.append(it)
        next_v = new_v
        
    # calculate cost
    v_val = [0 for _ in range(len(c)+1)]
    for i, it in enumerate(order):
        v_val[it] = c[i]
 
    val = calcCost(D, v_val)
    if val > max_val:
        max_val = val
        max_v = v_val
 
        
print(max_val)
print(' '.join(map(str, max_v[1:])))

Measured memory_bytes: 7112
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
template <typename T>
T gcd(T a,T b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
template <typename T>
T lcm(T a,T b){
  return a/gcd(a,b)*b;
}
int dp[200][200];
struct z{
	int a,b,c;
};
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
	int n;cin>>n;
	vector<int> A(n);
	for(int i = 0; n > i; i++){
		cin>>A[i];
	}
	sort(A.begin(),A.end());
	vector<int> Y;
	for(int i = 1; A[n-1] >= i*i; i++){
		if(!(A[n-1]%i)){
			Y.push_back(i);
			if(i*i!=A[n-1])Y.push_back(A[n-1]/i);
		}
	}
	sort(Y.begin(),Y.end());
	int ans = 0;
	for(int i = 0; n > i; i++){
		ans += *lower_bound(Y.begin(),Y.end(),A[i])-A[i];
	}
	cout << ans << endl;

}



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

int main(){
	string s,r;
  	cin >> s >> r;
  	
  	int res = 0;
  	for(int i=0;i<s.size();i++){
    	if(s.at(i) != r.at(i)) res++;
    }
  	cout << res << endl;
}

Measured memory_bytes: 3924
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

//snuke
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    //エラトステネスの篩
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        //最小素因数がかかれるようにしている
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  //素因数列挙
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  //頻度を集計したもの
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      //小さい順に出てくるので前回と同じなら足す作業でmapが作れる
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main(){
  Sieve sieve(300);
  ll N;cin>>N;
  ll ans = 0;

  for(ll i = 1; i <= N; i+=2){
    ll tmp = 1;
    auto f = sieve.factor(i);
    for(auto p:f){
      tmp *= p.second + 1;
    }
    if(tmp == 8) ans++;
  }
  cout<<ans<<endl;
}


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

using namespace std;

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

  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++)
	cin >> A[i];

  for(int i=1; i<N; i++){
	int key = A[i];
	int j=i-1;
	for(int i=0; i<N-1; i++)
	  cout << A[i] << " ";
	cout << A[N-1] << endl;
		
	while(j >= 0 && A[j] > key){
	  A[j+1] = A[j];
	  j--;
	}
	A[j+1] = key;
  }
  for(int i=0; i<N-1; i++)
	cout << A[i] << " ";
  cout << A[N-1] << endl;
  
  return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int main() {
	LL h, w;
	cin >> h >> w;
	
	LL ans = h * w;
	LL x[3];
	incII(i, 0, h) {
		x[0] = w * i;
		x[1] = w * ((h - i) / 2);
		x[2] = h * w - (x[0] + x[1]);
		sort(x, x + 3);
		setmin(ans, x[2] - x[0]);
		
		x[0] = w * i;
		x[1] = (w / 2) * (h - i);
		x[2] = h * w - (x[0] + x[1]);
		sort(x, x + 3);
		setmin(ans, x[2] - x[0]);
	}
	incII(i, 0, w) {
		x[0] = h * i;
		x[1] = h * ((w - i) / 2);
		x[2] = h * w - (x[0] + x[1]);
		sort(x, x + 3);
		setmin(ans, x[2] - x[0]);
		
		x[0] = h * i;
		x[1] = (h / 2) * (w - i);
		x[2] = h * w - (x[0] + x[1]);
		sort(x, x + 3);
		setmin(ans, x[2] - x[0]);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

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

int H, W;
char s[55][55];

int ans = 0;

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

    memset(s,'#',sizeof(s));
    cin >> H >> W;
    REP(h,1,H+1) REP(w,1,W+1) {
        cin >> s[h][w];
        if(s[h][w] == '.') ans++;
    }

    queue<Tiii> q; q.push(mt(1,1,1));
    int dist = -1;
    V<V<bool>> closed = V<V<bool>>(H+1, V<bool>(W+1, false));
    while(!q.empty()) {
        int y, x, t; tie(y,x,t) = q.front(); q.pop();
        if(closed[y][x]) continue;
        if(y==H && x==W) {
            dist = t;
            break;
        }
        closed[y][x] = true;
        rep(i,4) {
            int n_y = y +dy[i], n_x = x +dx[i];
            if(s[n_y][n_x]!='#' && !closed[n_y][n_x]) q.push(mt(n_y,n_x,t+1));
        }
    }

    if(dist == -1) {
        cout << -1 << endl;
    } else {
        cout << ans - dist << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 1;; i++) {
            int x = sc.nextInt();
            if(x == 0){
                break;
            }
            System.out.println("Case "+ i + ": " + x);
        }
        sc.close();
    }
   
}



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


int main(){
  string w;
  cin >> w;
  map<char,int> mp;
  for(int i=0;i<w.size();++i){
    mp[w[i]]++;
  }
  bool ha=true;
  for(auto p : mp){
    if(p.second%2!=0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define maxn 100005
#define maxm 205
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}

int n, m, ans;
char s[maxn]; 
int main(){
	int i, j, x, u, v;
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for(i = 1;i <= n;i += 2) ans -= s[i] == 'p';
	for(i = 2;i <= n;i += 2) ans += s[i] == 'g';
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3936
#include <iostream>
 
using namespace std;
 
int main() {
  unsigned long sum = 0ul;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0) {
      continue;
    } else {
      sum += i;
    }
  }
  
  cout << sum;
  
  return 0;
}

Measured memory_bytes: 3128
// 1.初始化相?数?
// 2.?取?入
// 3.遍?整个数?，判断?当前位置有没有?行?通性?理
//     1.如果已??理?，接着遍?
//     2.如果没有?理?，使用dfs???型做?通性?理，??通数加一
// 4.?出
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAXN 105
int H,W;//行数和列数
int fruit[MAXN][MAXN];//水果的布局
#define STAR 0 //星号*
#define POUND 1 //井号#
#define AT 2 //符号@
int connect[MAXN][MAXN];//是否???通性?理

void init() {
    memset(fruit,0,sizeof(fruit));
    memset(connect,0,sizeof(connect));
}
void getInput() {
    char c;
    for(int i=0;i<H;i++) {
        c=getc(stdin);
        if(c=='\r') getc(stdin);
        for(int j=0;j<W;j++) {
            c=getc(stdin);
            if(c=='*') fruit[i][j]=STAR;
            else if(c=='#') fruit[i][j]=POUND;
            else if(c=='@') fruit[i][j]=AT;
        }
    }
}

void checkInput() {
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            if(fruit[i][j]==STAR) printf("*");
            else if(fruit[i][j]==POUND) printf("#");
            else if(fruit[i][j]==AT) printf("@"); 
        }
        printf("\n");
    }
}

void dfs(int row,int col,int type) {
    if(row>0 && fruit[row-1][col]==type && connect[row-1][col]==0) {
        connect[row-1][col]=1;
        dfs(row-1,col,type);
    }
    if(col>0 && fruit[row][col-1]==type && connect[row][col-1]==0) {
        connect[row][col-1]=1;
        dfs(row,col-1,type);
    }
    if(row<H-1 && fruit[row+1][col]==type && connect[row+1][col]==0) {
        connect[row+1][col]=1;
        dfs(row+1,col,type);
    }
    if(col<W-1 && fruit[row][col+1]==type && connect[row][col+1]==0) {
        connect[row][col+1]=1;
        dfs(row,col+1,type);
    }
}

int main() {
#ifdef debug
    freopen("in.txt","r",stdin);
#endif
    while(scanf("%d %d",&H,&W)) {
        if(H==0 && W==0) break;
        init();
        getInput();
    #ifdef debug   
        // checkInput();
    #endif
        int num=0;
        for(int i=0;i<H;i++) {
            for(int j=0;j<W;j++) {
                if(connect[i][j]==0) {
                    connect[i][j]=1;
                    dfs(i,j,fruit[i][j]);
                    num++;
                }
            }
        }
        printf("%d\n",num);
    }
}

Measured memory_bytes: 3292
N, M = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
def func(M):
  res = []
  i = 2
  while i * i <= M:
    c=0
    while M % i == 0:
      M /= i
      c += 1
    if c > 0:
      res.append(c)
    i += 1
  if M > 1:
    res.append(1)
  return res

def conb(n, r):
  N, R = n, r
  for i in range(1, r):
    N *= n-i
    R *= r-i
  return N // R

res = func(M)
ans = 1
for i in res:
  ans = (ans * conb(i+N-1, i)) % mod
print(ans)

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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") 

using namespace std;
typedef long long lint;
typedef long double ldb;
typedef unsigned long long uli;

#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define Df(i, l, r) for(auto i = l; i != r; i--)
#define I(i, a) for(auto i : a)
#define pb push_back
#define rs resize
#define mk make_pair
#define asg assign
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define era erase
#define fi0(x) memset(x, 0, sizeof(x))
#define finf(x) memset(x, 127, sizeof(x))
#define acpy(y, x) memcpy(y, x, sizeof(y))
#define y1 adjf
#define tm dhgdg

struct node{
	node *l = NULL, *r = NULL;
	int sz;
	bool pu = false;
	lint a = 0;
	lint d = 0;
};

void push(node * v){
	if(!v || !v->pu)ret;
	if(!v->l)ret;
	v->l->a += v->a;
	v->l->d += v->d;
	v->r->a += v->a + v->d * 1ll * v->l->sz;
	v->r->d += v->d;
	v->l->pu = v->r->pu = true;
	v->a = 0; v->d = 0; v->pu = false;
}

node * build(int l, int r){
	node * v = new node;
	v->sz = r - l + 1;
	if(l == r)ret v;
	int mid = (l + r) >> 1;
	v->l = build(l, mid);
	v->r = build(mid + 1, r);
	ret v;
}

void upd(node * v, int l, int r, int ul, int ur, lint a, lint d){
	if(ul > ur)ret;
	push(v);
	if(l == ul && r == ur){
		v->pu = true;
		if(v->a == -1)v->a = 0;
		v->a += a; v->d += d;
		ret;
	}
	int mid = (l + r) >> 1;
	upd(v->l, l, mid, ul, min(ur, mid), a, d);
	upd(v->r, mid + 1, r, max(ul, mid + 1), ur, a + d * max(0, mid - ul + 1), d);
}

lint calc(node * v, int l, int r){
	if(l == r)ret v->a;
	push(v);
	int mid = (l + r) >> 1;
	ret min(calc(v->l, l, mid), calc(v->r, mid + 1, r));
}

const int MAXN = 1e5 + 5;

int n, m;
int a[MAXN];
node * root;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	scanf("%d%d", &n, &m);
	F(i, 0, n)scanf("%d", &a[i]);
	root = build(1, m);
	F(i, 0, n - 1){
		int l = a[i], r = a[i + 1];
		if(l < r){
			upd(root, 1, m, l + 1, r, r - l, -1);
			upd(root, 1, m, 1, l, r - l, 0);
			upd(root, 1, m, r + 1, m, r - l, 0);
		}
		else{
			int len = m - l + r;
			upd(root, 1, m, r + 1, l, len, 0);
			upd(root, 1, m, l + 1, m, len, -1);
			upd(root, 1, m, 1, r, len - (m-l), -1);
		}
	}
	printf("%lld", calc(root, 1, m));
	ret 0;
}



Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int64 a, b, k;
    cin >> a >> b >> k;
    int64 x = min(a, k);
    a -= x;
    k -= x;
    b -= min(b, k);
    cout << a << ' ' << b; 
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
 //f(x) = 0 + |x-4| + |x-1| -6
 //4 2
 
//4
//1 4 2
//2
//1 1 -8
//2


//4 2
//1 -3

//low {1}
//high {4}

multiset<ll> low,high;
ll low_sum, high_sum;

void balance(){
	while(1){
		int ls = low.size(), hs = high.size();
		if(ls == hs || ls == hs + 1) break;
		if(ls < hs){
			auto v = high.begin();
			low.insert(*v);
			low_sum += *v;
			high_sum -= *v;
			high.erase(v);
		} else{
			auto v = low.end();
			--v;
			high.insert(*v);
			high_sum += *v;
			low_sum -= *v;
			low.erase(v);
		}
	}
}


void solve(){
	ll q; cin >> q;
	ll b_sum = 0;
	FOR(q){
		int n; cin >> n;
		if(n==1){
			ll a,b; cin >> a >> b;
			b_sum += b;
			
			if(low.empty()){
				low.insert(a);
				low_sum += a;
			} else{
				auto itr = low.end();
				--itr;
				int prev_med = *itr;
				if(prev_med >= a){
					low.insert(a);
					low_sum += a;
				} else{
					high.insert(a);
					high_sum += a;
				}
			}
			balance();
		} else{
			auto itr = low.end();
			--itr;
			ll median = *itr;
			ll ans = b_sum + median*low.size() - low_sum + high_sum - median*high.size();
			cout << median << " " << ans << '\n';
		}
	}
}

//6  high = 7,8,9,

//7-6+8-6+9-6  = (7 + 8 + 9 - 6 - 6 - 6)

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


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

int main()
{
	int n, flag = 1, minj;
	char c[36][5], alt[36][3] = { }, tmp;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> c[i];
		alt[i][0] = c[i][0];
		alt[i][1] = c[i][1];
	}
	for (int i = 0; i < n; i++)
		for (int j = n - 1; j > i; j--)
			if (alt[j - 1][1] > alt[j][1])
			{
				tmp = alt[j - 1][1];
				alt[j - 1][1] = alt[j][1];
				alt[j][1] = tmp;
				tmp = alt[j - 1][0];
				alt[j - 1][0] = alt[j][0];
				alt[j][0] = tmp;
			}
	for (int i = 0; i < n; i++)
	{
		if (i)
			cout << " ";
		cout << alt[i];
	}
	cout << endl << "Stable" << endl;

	for (int i = 0; i < n; i++)
	{
		minj = i;
		for (int j = i; j < n; j++)
			if (c[minj][1] > c[j][1])
				minj = j;
		for (int j = i + 1; j < minj; j++)
			if (c[j][1] == c[i][1])
				flag = 0;
		tmp = c[minj][0];
		c[minj][0] = c[i][0];
		c[i][0] = tmp;
		tmp = c[minj][1];
		c[minj][1] = c[i][1];
		c[i][1] = tmp;
	}
	for (int i = 0; i < n; i++)
	{
		if (i)
			cout << " ";
		cout << c[i];
	}
	if (flag)
		cout << endl << "Stable" << endl;
	else
		cout << endl << "Not stable" << endl;

	return 0;
}


Measured memory_bytes: 3096
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

long long gcd(long long a, long long b) {
  return (b ? gcd(b, a % b) : a);
}

long long a, b, c, d;

int read() {
  if (scanf("%lld%lld%lld%lld", &a, &b, &c, &d) < 4) {
    return false;
  }
  return true;
}

void solve() {
  if (a < b || d < b) {
    printf("No\n");
    return;
  }
  long long g = gcd(b, d);
  long long k = (b - (a % b) + g - 1) / g - 1;
  long long x = (a % b) + k * g;
  if (x > c) {
    printf("No\n");
    return;
  }
  printf("Yes\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  int t;
  scanf("%d", &t);
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256