akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <math.h>

#define MAX 10e5

using namespace std;

bool IsPrime(int num) {
	if (num < 2) return false;
	else if (num == 2)return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) {
			return false;
		}
	}
	return true;
}

int main() {
	int q;
	cin >> q;
	vector<int> l;
	vector<int> r;
	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		l.push_back(a);
		r.push_back(b);
	}

	vector<int> sum(MAX,0);
	vector<int> isPrime(MAX,0);

	for (int i = 3; i < MAX; i += 2) {
		if (IsPrime(i))
			isPrime[i] = 1;
	}

	for (int i = 2; i < MAX / 2; i++) {
		if (isPrime[2 * i - 1] != 1)
			continue;
		if (IsPrime(i)) {
			//cout << 2 * i - 1 << "は素数" << endl;
			continue;
		}
		else {
			isPrime[2 * i - 1] = 0;
		}
	}

	sum[3] = 1;

	for (int i = 5; i < MAX; i += 2) {
		sum[i] = sum[i - 2] + isPrime[i];
	}

	for (int i = 0; i < q; i++) {
		int x = sum[r[i]] - sum[l[i]];
		if (isPrime[l[i]])
			x += 1;
		cout << x << endl;
		//cout << r[i] << " " << sum[r[i]] << endl << l[i] << " " << sum[l[i]] << endl;
	}

	for (int i = 0; i < q; i++) {
		//cout << sum[i] << endl;
	}


}

Measured memory_bytes: 9460
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()

    def primes(n):
        is_prime = [True] * (n + 1)
        is_prime[0] = False
        is_prime[1] = False
        for i in range(2, int(n**0.5) + 1):
            if not is_prime[i]:
                continue
            for j in range(i * 2, n + 1, i):
                is_prime[j] = False
        return [i for i in range(n + 1) if is_prime[i]]

    p = primes(55555)
    ans = []
    i = 0

    for prime in p:
        if prime % 5 == 1:
            ans.append(prime)
            i += 1
        if i == n:
            break

    print(*ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 4288
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

int main() {
	int n, d; cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	int cnt = 0;
	double temp=0;
	

	for (int i = 0; i < n; i++){
		for (int k = i+1; k < n; k++){
			temp = 0;
			for (int j = 0; j < d; j++) {
				temp += pow(x[i][j] - x[k][j], 2);
			}
			if (integer(sqrt(temp))) cnt++;
			//cout << i<<" "<<k<<" "<<temp << endl;
		}
	}
	cout << cnt;



	cout << endl;
	return 0;
}

Measured memory_bytes: 256
def find(arr):

	n = len(arr)
	arr.sort()
	count = 0
	for i in range(0,n-2):

		k = i + 2

		for j in range(i+1,n):
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j):
				count += k - j - 1

	return count

n=int(input())
a=list(map(int,input().split()))


print(find(a))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> A(n), B(n);
    for(int i = 0; i < n; i++){
        cin >> A[i] >> B[i];
    }
    int dp[20010];
    for(int j = 0; j < 20010; j++){
        dp[j] = INF;
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 20010; j++){
            if (j - A[i] >= 0) chmin(dp[j], dp[j - A[i]] + B[i]);
        }
    }
    int ans = INF;
    for(int i = h; i < 20010; i++) chmin(ans, dp[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    if((b-a-1) % 2 == 0) {
        cout << "Borys";
    }else {
        cout << "Alice";
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 200005
#define INF 1000005
#define endl "\n"
int arr[MAX];
int f[INF];
bool p[INF];
bool flag[MAX];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for(lli i = 2; i<=INF; i++){
		if(!p[i]){
			for(lli j = i*i; j<=INF; j+=i){
				p[j] = true;
 			}
		}
	}
	int n;
	cin>>n;
	for(int i = 0; i<n; i++){
		cin>>arr[i];
		f[arr[i]]++;
	}
	int c = 0;
	bool flag = false;
	for(lli i = 0; i<n; i++){
		flag = false;
		f[arr[i]]--;
		if(!p[arr[i]]){
			if(f[1] || f[arr[i]]){
			}
			else{
				c++;
			}
			f[arr[i]]++;
			continue;
		}
		for(int j = 1; j*j <= arr[i]; j++){
			if(arr[i]%j == 0){
				if(f[j] || f[arr[i]/j]){
					flag = true;
					break;
				}
			}
		}
		if(!flag){
			c++;
		}
		f[arr[i]]++;
	}
	cout<<c<<endl;
	
}

Measured memory_bytes: 9200
'use strict'

var generatePermutation = function(perm, pre, post, n) {
  var elem, i, rest, len;
  if (n > 0)
    for (i = 0, len = post.length; i < len; ++i) {
      rest = post.slice(0);
      elem = rest.splice(i, 1);
      generatePermutation(perm, pre.concat(elem), rest, n - 1);
    }
  else
    perm.push(pre);
};

Array.prototype.permutation = function(n) {
  if (n == null) n = this.length;
  var perm = [];
  generatePermutation(perm, [], this, n);
  return perm;
};

function Main(input) {

  input = input.trim().split('\n')
  const N = parseInt(input[0])
  let P = input[1].split(' ').map(s => parseInt(s))
  let Q = input[2].split(' ').map(s => parseInt(s))

  const a = []
  for(let i = 0; i < N; ++i){ 
    a.push(i + 1)
  }

  const results = a.permutation()

  const strP = P.join('')
  const strQ = Q.join('')

  let indexP = 0
  let indexQ = 0

  results.forEach((d, index) => {
    const s = d.join('')
    if(strP === s) indexP = index
    if(strQ === s) indexQ = index
  })
  console.log(Math.abs(indexP - indexQ));

  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 27980
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
			sc.close();

			if(X<A){
				System.out.println("0");
			}
			else{
				System.out.println("10");
			}

	}
}


Measured memory_bytes: 22100
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<char>C(N);
    set<char>A;
    rep(i, N) {
        cin >> C[i];
        A.insert(C[i]);
    }
    cout << (A.size() == 3 ? "Three":"Four") << endl;
}

Measured memory_bytes: 3552
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<cmath>
using namespace std;
char s[15];
int n;
long long int sum=0,op,p,q;
int main()
{
	int i,j,k;
	//freopen("we.in","r",stdin);
	//freopen("we.out","w",stdout);
	scanf("%s",s+1);
	n=strlen(s+1);
	for(i=1;i<=n;i++)
	s[i]-=48;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			op=0;
			for(k=i;k<=j;k++)
            op=op*10+s[k];
			if(i==1)
			p=1;
			else p=pow(2,i-2);
			if(j==n)
			q=1;
			else q=pow(2,n-j-1);
			sum+=p*q*op;
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

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

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

const int MOD = 1e9 + 7;

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

    int a, b;
    cin >> a >> b;

    int ans = a * b - a - b + 1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << a*b/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
ll ncd(ll n,ll d){
    ll x = 1,y=1;
    for(int i=0;i<d;i++){
        x = x*(n-i)%mod;
        y = y*(i+1)%mod;
    }
    return x*modpow(y,mod-2,mod)%mod;
}
int main() {    
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll>a(n),b(m);
    for(int i=0;i<n;i++)cin >> a.at(i);
    for(int j=0;j<m;j++)cin>> b.at(j);
    vector<ll>ra(n+1,0),rb(m+1,0);
    for(int i=0;i<n;i++)ra.at(i+1)=ra.at(i)+a.at(i);
    for(int i=0;i<m;i++)rb.at(i+1)=rb.at(i)+b.at(i);
    ll ans = 0; ll d = m;
    for(int i=0;i<=n;i++){;
        ll che = k-ra.at(i);
        for(int j=d;j>=0;j--){
            if(rb.at(j)<=che){
                d = j;
                ans = max(ans,i+d);
                break;
            }
        }
    }
    cout<<ans<<endl;
}
    



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

// 0:eÈµ
// 1:eª é
// 2:øÎ
char map[8][8];
int sx, sy;

void bomb( int x, int y )
{
	// c
	for ( int i = -3; i <= 3; i++ )
	{
		int ny = y + i;
		if ( ny < 0 || ny >= 8 )
			continue;
		if ( map[ny][x] == '1' )
			map[ny][x] = '2';
	}
	// ¡
	for ( int i = -3; i <= 3; i++ )
	{
		int nx = x + i;
		if ( nx < 0 || nx >= 8 )
			continue;
		if ( map[y][nx] == '1' )
			map[y][nx] = '2';
	}
	// c
	for ( int i = -3; i <= 3; i++ )
	{
		int ny = y + i;
		if ( ny < 0 || ny >= 8 )
			continue;
		if ( map[ny][x] == '2' )
		{
			map[ny][x] = '0';
			bomb( x, ny );
		}
	}
	// ¡
	for ( int i = -3; i <= 3; i++ )
	{
		int nx = x + i;
		if ( nx < 0 || nx >= 8 )
			continue;
		if ( map[y][nx] == '2' )
		{
			map[y][nx] = '0';
			bomb( nx, y );
		}
	}
}

int main( void )
{
	char c;
	int n;
	cin >> n;
	for ( int lpc = 0; lpc < n; lpc++ )
	{
		for ( int i = 0; i < 8; i++ )
			for ( int j = 0; j < 8; j++ )
				map[i][j] = '0';

		for ( int i = 0; i < 8; i++ )
		{
			for ( int j = 0; j < 8; j++ )
			{
				cin >> map[i][j];
			}
		}

		cin >> sx;
		cin >> sy;

		sx--;
		sy--;

		map[sy][sx] = '0';

		bomb( sx, sy );

		cout << "Data " << lpc + 1 << ":" << endl;
		for ( int i = 0; i < 8; i++ )
		{
			for ( int j = 0; j < 8; j++ )
				cout << map[i][j];
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

string s;

void _main() {
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else if (s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

void chain(vector<pll> &v){
  bool f = true;
  while(1){
    f = true;
    for(auto it = v.begin(); it != v.end();){
      if((it+1) != v.end() && it->fi == (it+1)->fi && it->se + (it+1)->se > 3){
        f = false;
        it = v.erase(it);
        it = v.erase(it);
      }
      else if(it->se > 3){
        f = false;
        it = v.erase(it);
      }
      else
        ++it;
    }
    if(f) break;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n && n){
    vector<ll> v(n);
    vector<pair<ll,ll>> v2;
    ll a = inf,cnt = 0;
    rep(i,n){
      cin >> v[i];
      if(a == inf){
        a = v[i];
        ++cnt;
      }
      else{
        if(v[i] != a){
          v2.push_back(make_pair(a,cnt));
          a = v[i];
          cnt = 1;
        }
        else
          ++cnt;
      }
    }
    v2.push_back(make_pair(a,cnt));
    ll si = v2.size(),ans = inf,sum;
    v2.push_back(make_pair(inf,0));
    auto v3 = v2;
    auto it = v2.begin();
    rep(j,v2.size()){
      sum += v2[j].se;
    }
    REP(i,0,si){
      sum = 0;
      v2[i+1].se++;
      v2[i].se--;
      if(v2[i].se == 0)
        v2.erase(it + i);
      chain(v2);
      rep(j,v2.size()){
        sum += v2[j].se;
      }
      ans = min(ans,sum);
      v2 = v3;
      sum = 0;
      if(i>1){
        v2[i-1].se++;
        v2[i].se--;
        if(v2[i].se == 0)
          v2.erase(it + i);
        chain(v2);
        rep(j,v2.size()){
          sum += v2[j].se;
        }
        ans = min(ans,sum);
      }
      v2 = v3;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  A=A+B;
  C=C+D;
  if(A<C) {cout<<"Right"<<endl;}
  else if(A>C){cout<<"Left"<<endl;}
  else{cout<<"Balanced"<<endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;

const int N = 35;

pii a[200010];
long long dp[200010][40];
long long sum[200010];

bool cmp(pii a, pii b) {
	return (long double)a.fi / (a.se + 1) > (long double)b.fi / (b.se + 1);
}

int main () {
	int n, T; scanf("%d%d", &n, &T);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i].fi, &a[i].se);
	}
	sort(a, a + n, cmp);
	int mid = 0;
	while (mid < n && a[mid].fi != 0) mid++;
	sort(a + mid, a + n);
	for (int i = mid; i < n; i++) {
		sum[i] = a[i].se + 1;
		if (i != mid) sum[i] += sum[i - 1];
	}
	for (int i = 0; i <= N; i++) {
		dp[0][i] = 0x3f3f3f3f;
	}
	dp[0][0] = 0;
	int ans = 0;
	for (int i = 0; i < mid; i++) {
		for (int j = N; j >= 1; j--) {
			long long tmp = dp[i][j - 1];
			tmp++, tmp += tmp * a[i].fi + a[i].se;
			tmp = min(tmp, (long long)T + 1);
			dp[i + 1][j] = min(dp[i][j], tmp);
			int pos = upper_bound(sum + mid, sum + n, T - dp[i][j]) - sum;
			if (dp[i][j] <= T) ans = max(ans, j + pos - mid);
		}
	}
	for (int j = 0; j <= N; j++) {
		long long minj = 0x3f3f3f3f;
		for (int i = 0; i <= mid; i++) {
			minj = min(minj, dp[i][j]);
		}
		int pos = upper_bound(sum + mid, sum + n, T - minj) - sum;
		if (minj <= T) ans = max(ans, j + pos - mid);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 64384
n,k = map(lambda x: int(x),input().split())
p = list(map(lambda x: (int(x) + 1)/2,input().split()))
ruiseki = [0]
max = 0
for i in range(n) :
    ruiseki.append(ruiseki[i]+p[i])

for j in range(n - k + 1):
    if max < (ruiseki[j+k] - ruiseki[j]) :
        max = (ruiseki[j+k] - ruiseki[j])


print(max)


Measured memory_bytes: 23524
from collections import deque

N, K = map(int,input().split())
monsters = list(map(int, input().split()))
monsters.sort(reverse=True)
monsters = deque(monsters)
count = 0

while K > count:
  count += 1
  try:
    monsters.popleft()
  except IndexError:
    pass

print(sum(monsters))

Measured memory_bytes: 27660
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>
#include <math.h>
#include <time.h>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,pair<int, int>>
#define N 200005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

int main()
{
	int n, m, a[N], l, r;
	cin >> n >> m;
	memset(a, 0, sizeof(a));
	for (int i = 0; i < m; ++i)
	{
		cin >> l >> r;
		a[l] += 1;
		a[r + 1] -= 1;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		a[i] += a[i - 1];
		if(a[i] == m)
			ans++;
	}
	cout << ans;
}

Measured memory_bytes: 1024
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N;
  cin >> N;
  string S;
  map<string, ll> m;
  REP(i, N) {
    cin >> S;
    m[S]++;
  }
  const auto vmax = max_element(ALL(m), [](const auto &lhs, const auto &rhs) {
                      return lhs.second < rhs.second;
                    })->second;
  for (const auto &[k, v] : m) {
    if (v == vmax) {
      cout << k << endl;
    }
  }
  return 0;
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using ql = priority_queue<ll>;

int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  ql qa;
  ql qb;
  ql qc;
  for(ll i = 0LL; i < A; i++){
    ll x;
    cin >> x;
    qa.push(x);
  }
  for(ll i = 0LL; i < B; i++){
    ll x;
    cin >> x;
    qb.push(x);
  }
  for(ll i = 0LL; i < C; i++){
    ll x;
    cin >> x;
    qc.push(x);
  }
  vector<ll> v;
  for(ll i = 0LL; i < X; i++) {
    v.push_back(qa.top());
    qa.pop();
  }
  for(ll i = 0LL; i < Y; i++) {
    v.push_back(qb.top());
    qb.pop();
  }
  sort(v.begin(), v.end());
  ll i = 0LL;
  while(qc.top() > v.at(i) && i < C && i < X+Y){
    v.at(i) = qc.top();
    i++;
    qc.pop();
  }
  ll ans = 0LL;
  for(ll j:v) ans += j;
  cout << ans << endl;
}
    
        

Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  
  vector<int>p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }
   
  sort(p.begin(),p.end());
  
  int sum=0;
  for(int i=0;i<K;i++){
    sum+=p.at(i);
  }
  
  cout<<sum<<endl;
}
    

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<ll, ll>P;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
struct edge1 { ll from, to, cost; };
double pai = 3.141592653589793;
std::vector<P>v[100010];

int main() {
	int n, a[4][10000], ans = 0;
	std::cin >> n;
	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < n;j++) {
			std::cin >> a[i][j];
		}
	}
	for (int i = 0;i < n;i++) {
		int sum =0;
		for (int j = 0;j <= i;j++) sum += a[0][j];
		for (int j = i;j < n;j++)sum += a[1][j];
		ans = std::max(sum, ans);
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 2e5 + 5;
int k, a, b;

int32_t main() 
{
	ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
	cin >> k >> a >> b;
	int q = a / k;
	if((k * q >= a and k * q <= b) or (k * (q + 1) >= a and k * (q + 1) <= b))
		cout << "OK";
	else	cout << "NG";
    	return 0;
}

Measured memory_bytes: 3612
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', function (line) {
  var rad,a,S,L,h;
  var e = line.split(' ');
  var b = Number(e[0]);
  var c = Number(e[1]);
  var d = Number(e[2]);
  rad = d / 180 * Math.PI;
  a = Math.sqrt(b*b+c*c-2*b*c*Math.cos(rad));
  S = (b*c*Math.sin(rad))/2;
  L = a+b+c;
  h = (b*c*Math.sin(rad))/b;
  console.log(S.toFixed(8));
  console.log(L.toFixed(8));
  console.log(h.toFixed(8));
  process.exit();
});
process.stdin.on('end', function () {
});

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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> C(N);
    for (int i = 1; i < N; i++) {
        int a;
        cin >> a;
        C.at(a - 1).push_back(i);
    }

    for (int i = 0; i < N; i++) {
        cout << C.at(i).size() << endl;
    }
}

Measured memory_bytes: 14348
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;
int main(){
 double a,b;cin>>a>>b;
 int digit=0;
 digit = log10(b)+1;
 double tmp = a * pow(10,digit) + b;
 double root = 0;
 root = (int)sqrt((double)tmp);
 if (pow(root,2)==tmp){
     cout << "Yes" << endl;
 }  else {
     cout << "No" << endl;
 }
 //cout << tmp <<"," << root <<","<<digit <<endl;
}

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

int main(){
    uint_fast64_t N;
    unordered_map<uint_fast64_t, uint_fast64_t> m;
    scanf("%llu", &N);
    for(int_fast64_t i = 0, a; i < N; ++i){
        scanf("%llu", &a);
        ++m[a];
    }
    uint_fast64_t ans(0);
    for(auto i : m)ans += (i.second >= i.first) ? i.second - i.first : i.second;
    printf("%llu\n", ans);
    return 0;
}


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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;

int n,k,l;
int sz = 1,sz1 = 1;
int u[N],us[N];

vector <int> g[N],d[N];
map<pair<int,int>,int> mp;

void dfs(int v) {
        u[v] = sz;

        for (auto to : g[v]) {
                if (u[to] == 0)
                        dfs(to);
        }
}
void dfs1(int v) {
        us[v] = sz1;

        for (auto i : d[v]) {
                if (us[i] == 0)
                        dfs1(i);
        }
}
int main () {
        cin >> n >> k >> l;

        for (int i = 1; i <= k; i ++) {
                int x,y;
                scanf("%d%d", &x,&y);

                g[x].pb(y);
                g[y].pb(x);
        }
        for (int i = 1; i <= l; i ++) {
                int x,y;
                scanf("%d%d", &x,&y);

                d[x].pb(y);
                d[y].pb(x);
        }

        for (int i = 1; i <= n; i ++) {
                if (u[i] == 0)
                        dfs(i),sz ++;

                if (us[i] == 0)
                        dfs1(i),sz1 ++;

                mp[{u[i],us[i]}] ++;
        }

        for (int i = 1; i <= n; i ++) {
                cout << mp[{u[i],us[i]}] << " ";
        }
}


Measured memory_bytes: 27904
h, w = map(int, input().split())
c = [0]*10
for i in range(10):
  c[i] = [int(x) for x in input().split()]


for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min([c[i][j], c[i][k]+c[k][j]])

ans = 0
for i in range(h):
  a = [int(x) for x in input().split()]
  for j in range(w):
    if a[j] == -1:
      continue
    else:
      ans += c[a[j]][1]

print(ans)




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

int main()
{
	 int n;
	 cin>>n;
	 int a[n];
	 int ans=0;
	 for(int i=0;i<n;i++){
        cin>>a[i];
        if(i>1&&((a[i]>a[i-1]&&a[i-1]>a[i-2])||(a[i]<a[i-1]&&a[i-1]<a[i-2]))){
            ans++;
        }
	 }
	 cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    long K = scanner.nextLong();
    int[] A = new int[N];
    boolean[] D = new boolean[N];
    for(int i = 0; i < N; i++) {
      A[i] = scanner.nextInt();
      D[i] = false;
    }
    int C = 0;
    do {
      D[C] = true;
      C = A[C] - 1;
    } while(!D[C]);
    int count = 0;
    int start = C;
    do {
      C = A[C] - 1;
      count++;
    } while(C != start);
    C = 0;
    int offset = 0;
    do {
      C = A[C] - 1;
      offset++;
    } while(C != start);
    C = 0;
    long move = K > offset ? ((K - offset) % count) + offset : K;
    for(int i = 0; i < move; i++) C = A[C] - 1;
    System.out.println(C + 1);
  }
}

Measured memory_bytes: 60400
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

ll memo[300][300];

int gcd(int x, int y) {
  if (memo[x][y] != 0) return memo[x][y];
  if (y == 0) {
    memo[x][y] = x;
    return x;
  }
  memo[x][y] = gcd(y, x % y);
  return memo[x][y];
}

int main() {
  int k;
  cin >> k;
  ll ans = 0;
  for (int i = k; i >= 1; i--) {
    for (int j = k; j >= 1; j--) {
      for (int l = k; l >= 1; l--) {
        ans += gcd(i, gcd(j, l));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4092
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, t) for(ll i = 0; i < t; i++)

using namespace std;
using ll = long long;
using P = std::pair<ll, ll>;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    
    auto Max = max(max(a, b), c);
    auto Min = min(min(a, b), c);
    cout << Max - Min << endl;
}



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

int main(){
    int n;
    cin >> n;
    vector<P> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i].second >> v[i].first;
    }

    sort(v.begin(), v.end());

    ll t = 0;
    bool flag = true;
    for(int i=0; i<n; i++){
        t += v[i].second;
        if(t > v[i].first) flag = false;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3456
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {

	int a, max1=0,b[101] = {};

	while (cin>> a) {
		b[a]++;
		max1 = max(b[a], max1);
	}

	for (int i = 0; i < 101; i++) {
		if (b[i] == max1)cout<< i <<endl;
	}

	return 0;
}

Measured memory_bytes: 3092
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

int main() {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a > k) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
}


Measured memory_bytes: 256
//Author- Vaibhav Singh


#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
*/
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */
  
  ll powerm(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
  long long lcm(long long a, long long b){//最小公倍数を求める
   return a * b / gcd(a, b);
}

/*
ll po(ll z,ll z1)
{
    ll rer=0;
    rer=     ((z*(z-1))/2+(z1*(z1-1))/2);
    return rer;

}
*/
/*
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
*/
/*
bool is_prime(ll n){
    for(ll i = 2;i*i<=n;i++){
        if(n%i == 0) return false;
    }
    return true;
}
*/
int inv(int a){
    return powerm(a,mod-2,mod);
}

ll const N=1e5;
ll fact[N], invfact[N];
 
void precompute(){
    fact[0] = 1;
    for(int i=1;i<N;i++) fact[i] = (fact[i-1]*i)%mod;
    invfact[N-1] = inv(fact[N-1])%mod;
    for(int i=N-2;i>=0;i--) invfact[i] = (invfact[i+1]*(i+1))%mod;
}
 
ll ncr(ll n, ll r){
    if(n<r) return 0;
    return (((fact[n]*invfact[r])%mod)*invfact[n-r])%mod;
}

//*88888*********5555555555555555******88888888$$$$$$$$$$******!!!!!!!!!!

       int main()
       {
           //プログラムの開始
    fast

      ll n,k;
      cin>>n;
      ll s=1,h=1;
      n/=2;
       while(n>0)
       {
           h*=2;
           s+=h;
           n/=2;
       }
        o(s)


//プログラムの終わり
re}

Measured memory_bytes: 3660
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(int i = a; i < n; ++i)
#define pb push_back
#define mp make_pair
//#define f first
//#define sex second

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <set>
#include <ostream>
#include <queue>
#include <functional>
#include <sstream>
#include <map>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#pragma comment(linker, "/STACK:228228000")
const ll mod = 998244353228;

ll n, res, t;

ll eu(ll a, ll b)
{
	if (a == 0)
		return b;
	return eu(b%a, a);
}


int main()
{
	/*

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	*/




	cin >> t;
	
	forn(i, 0, t)
	{
		ll a, b, c, d;
		cin >> a >> b >> c >> d;

		ll nod = eu(b, d);
		if (a < b || d < b)
		{
			cout << "No" << endl;
			continue;
		}
		if (c >= b && d >= b)
		{
			cout << "Yes" << endl;
			continue;
		}
		a %= b;
		if (a > c)
		{
			cout << "No" << endl;
			continue;
		}
		c -= a;
		b -= a;
		a = (c / nod)*nod + nod;
		if (a < b)
		{
			cout << "No" << endl;
			continue;
		}
		else
		{
			cout << "Yes" << endl;
			continue;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
void bubble_sort(int C[], int value[], int length) {
  int i,j,tmp;
  for(i = 1; i <= length; ++i) {
    for(j = length; j >= i+1; --j) {
      if(value[C[j]] < value[C[j-1]]) {
        tmp = C[j];
        C[j] = C[j-1];
        C[j-1] = tmp;
      }
    }
  }
}

void select_sort(int C[], int value[], int length) {
  int i,j,mini,tmp;
  for(i = 1; i <= length; ++i) {
    mini = i;
    for(j = i; j <= length; ++j) {
      if(value[C[j]] < value[C[mini]] ){
        mini = j;
      }
    }
    tmp = C[i];
    C[i] = C[mini];
    C[mini] = tmp;
  }
}

void show(int C[], int value[], char mark[], int length, int isStable) {
  int i;
  for(i = 1; i <= length; ++i) {
    if(i != 1) printf(" ");
    printf("%c%d", mark[C[i]], value[C[i]]);
  }
  printf("\n");
  printf("%s\n",isStable?"Stable":"Not stable");
}

int isStable(int C[], int D[], int value[], char mark[], int length) {
  int i,j,s,t;
  for(i = 1; i+1 <= length; ++i) {
    if(value[D[i]] == value[D[i+1]]) {
      for(j = 1; j <= length; ++j) {
        if(value[C[j]] == value[D[i]] && mark[C[j]] == mark[D[i]])
          s = C[j];
        if(value[C[j]] == value[D[i+1]] && mark[C[j]] == mark[D[i+1]])
          t = C[j];
      }
      if(s > t) return 0;
    }
  }
  return 1;
}

int main() {
  int length;
  int value[37];
  char mark[37];
  int C[37],C1[37],C2[37];
  int isS1, isS2;

  int i,j,k;

  scanf("%d", &length);
  for(i = 1; i <= length; ++i)
    scanf(" %c%d", &mark[i], &value[i]);
  for(i = 1; i <= length; ++i)
    C[i] = C1[i] = C2[i] = i;

  bubble_sort(C1,value,length);
  select_sort(C2,value,length);

  isS1 = isStable(C,C1,value,mark,length);
  isS2 = isStable(C,C2,value,mark,length);

  show(C1,value,mark,length,isS1);
  show(C2,value,mark,length,isS2);
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}
const int mod = 1e9 + 7;
const int Max_N = 1e5 + 1;
int vis[Max_N];

void div(int x) {
  for (int i = 2; i * i <= x; i++){
    while (x % i == 0) {
      vis[i]++;
      x /= i;
    }
  }
  if (x > 1) vis[x]++;
}

bool isPrime(int n){
  for(int i = 2; i <= sqrt(n); i++)
    if (n % i == 0)
      return false;
  return true;
}
ll cnt[Max_N];
signed main (){
  int N;
  cin >> N;

  rep2(i,2,N + 1) div(i);
  ll ans = 1;
  rep2(i,2,1e3+1){
    if(vis[i]>0){
      ans *= (vis[i] + 1);
      ans %= mod;
    }
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 256
// Code for E - Red Scarf
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)

#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

  REP(i, N) {
    cin >> a[i];
  }

  int s = a[0];
  REP(i, N - 1) {
    s = s ^ a[i + 1];
  }

  REP(i, N) {
    int x = s ^ a[i];
    cout << x << " ";
  }

  return 0;
}


Measured memory_bytes: 3944
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   vi a(n);
   rep(i,0,n)cin>>a[i];
   int money=1000;
   for(int i=1;i<n;i++)
   {
       if(a[i]>a[i-1])
       {
           int stocks=(money/a[i-1]);
           money=(money%a[i-1] + stocks*a[i]);
       }
   }
   cout<<money<<endl;
}


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

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


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

int main(){
  stack<int> S1;
  stack<pair<int,int> > S2;
  char ch;
  int sum = 0;
  int i,j,a;
  for( i = 0; cin >> ch ; i++){
    if(ch == '\\'){
      S1.push(i);
    }
    else if( ch == '/' && S1.size() > 0){
      j = S1.top();
      S1.pop();
      sum += i - j;
      a = i - j;
      while(S2.size() > 0 && S2.top().first > j){
        a += S2.top().second;
        S2.pop();
      }
      S2.push( make_pair(j,a) );
    }
  }

  vector<int> ans;
  int t = 0;
  while(S2.size() > 0){
    ans.push_back( S2.top().second );
    S2.pop();
  }
  reverse( ans.begin(), ans.end() );
  cout << sum << endl;
  cout << ans.size();
  for( i = 0; i < ans.size(); i++){
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3236
package main

import "fmt"

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_A>
 */

func init() {
}

func main() {
	var n int
	fmt.Scanf("%d",&n)
	a := make([]int,n)
	for i:= 0; i < n;i++{
		fmt.Scanf("%d",&a[i])
	}
	for i:= n-1; i>=0;i--{
		fmt.Printf("%d",a[i])
		if i != 0{
			fmt.Print(" ")
		}
	}
	fmt.Println("")
}

Measured memory_bytes: 1140
#include<iostream>
#include<algorithm>
using namespace std;
int cmp(const void* a,const void* b){
	return *(const int*)a-*(const int*)b;
}
int main(){
	int n=0;
	cin>>n;
	int *a=new int[n];
    int count=0;
    int i=0;
	while(i<n){
	cin>>a[i++];
	}
	qsort(a,n,sizeof(int),cmp); 
	for(int i=0;i<n;i++){
		int temp=1;
		while(i<(n-1)&&a[i]==a[i+1]){
		   temp++;
		   i++;
	    }
		if(temp&0x01)count+=1 ;
	}
	cout<<count;
}

Measured memory_bytes: 1020