akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}

int main() {
	string a;
	cin >> a;
	char b = a.at(0);
	char c = a.at(1);
	char d = a.at(2);
	char e = a.at(3);
	if (b == c && c == d && d == e) { cout << "No" << endl; }
	else if ((b == c && d == e) || (b == d && c == e) || (b == e && c == d)) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
int N;
scanf("%d",&N);
string A,B,C,D;
cin >> A;
cin >> B;
cin >> C;
int ans=0;
for(int i=0;i<N;i++){
  if(A[i]==B[i]){
    if(A[i]==C[i]){

    }else{
      ans=ans+1;
    }
  }else if(A[i]==C[i]){

        ans=ans+1;
      }else if(B[i]==C[i]){
      ans=ans+1;
    }else{ans=ans+2;};

}
cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <functional>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define inf 0x3f7f7f7f

using namespace std;

int dp[11][11];

int main()
{
	int t, i, j, k, x, y, z, n, MIN, sum[11];
	while (scanf("%d", &t) && t)
	{
		for (i = n = 0; i < 11; i++)
			for (j = 0; j < 11; j++)
				dp[i][j] = inf;
		while (t--)
		{
			scanf("%d%d%d", &x, &y, &z);
			dp[x][y] = dp[y][x] = z;
			n = max(n, max(x + 1, y + 1));
		}
		for (k = 0; k < n; k++)
			for (i = 0; i < n; i++)
				for (j = 0; j < n; j++)
					dp[i][j] = min(dp[i][k] + dp[k][j], dp[i][j]);
		for (i = 0, MIN = 0; i < n; i++)
		{
			for (j = sum[i] = 0; j < n; j++)
				if (i != j)
					sum[i] += dp[i][j];
			if (sum[MIN] > sum[i])
				MIN = i;
		}
		printf("%d %d\n", MIN, sum[MIN]);
	}	
	return 0;
}

Measured memory_bytes: 1188
S = input()

match = "keyence"
check = ""
revcheck = ""

flag = False

for x in range(len(S)):
    if x == len(match):
        break
    if match[x] == S[x]:
        check += S[x]
    else:
        flag = True
        break

if flag:
    remainFlag = False
    remain = match[x:]
    revS = "".join(reversed(S))
    revMatch = "".join(reversed(remain))
    for y in range(len(revS)):
        # print(revS[y])
        if y == len(revMatch):
            remainFlag = True
            break
        if revMatch[y] == revS[y]:
            revcheck += revS[y]
        else:
            break
    if remainFlag:
        print("YES")
    else:
        print("NO")
elif check == match:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 38256
data Arrange = Twin | Single deriving (Show, Eq)

prime = 1000000007 :: Integer

abbr :: String -> [Arrange] -> [Arrange]
abbr [] xs = xs
abbr [_] xs = Single:xs
abbr (x:y:ys) xs
  | x == y = abbr ys (Twin:xs)
  | x /= y = abbr (y:ys) (Single:xs) 

(*->) :: Arrange -> Arrange -> Integer
pre *-> cur
  | pre == Twin && cur == Twin = 3
  | pre == Twin && cur == Single = 1
  | pre == Single && cur == Twin = 2
  | otherwise = 2
infixl 7 *->

solve :: [Arrange] -> Arrange -> Integer
solve [] _ = 1
solve (cur:xs) pre = pre *-> cur * (solve xs cur) `mod` prime

main = do
  getLine
  getLine
  str <- getLine
  let (x:xs) = reverse $ abbr str []
  print $ (if x == Twin then 6 else 3) * solve xs x `mod` prime


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 4000


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

    auto get_cuml = [&](char c) {
        vector<i64> C(N + 1, 0);
        REP(i, N) {
            C[i + 1] = C[i] + (s[i] == c);
        }
        return C;
    };
    unordered_map<char, vector<i64>> cm;
    cm['R'] = get_cuml('R');
    cm['G'] = get_cuml('G');
    cm['B'] = get_cuml('B');

    i64 cnt = 0;
    REP(i, N - 2) {
        for (i64 j = i + 1; j < N - 1; j++) {
            if (s[i] == s[j]) continue;

            char kc;
            if (s[i] == 'R') {
                if (s[j] == 'G') kc = 'B';
                else kc = 'G';
            } else if (s[i] == 'G') {
                if (s[j] == 'R') kc = 'B';
                else kc = 'R';
            } else {
                if (s[j] == 'R') kc ='G';
                else kc = 'R';
            }
            assert(s[i] != kc && s[j] != kc);

            cnt += cm[kc][N] - cm[kc][j + 1];
            if (2 * j - i < N && s[2 * j - i] == kc) cnt--;
        }
    }
    cout << cnt << endl;

    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    double sum = 0;
    double dal = 1;
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        sum += (dal/a);
    }
    cout << fixed << setprecision(10) << dal/sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <cstdio>
#include <queue>
#define FOR(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define FORD(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define maxi 100000
typedef long long ll;
using namespace std;

int n, A[3*maxi+1];
ll sum[3*maxi+1],s1[3*maxi+1],s2[3*maxi+1],res;
priority_queue<int> Q,QQ;

int main(){
    scanf("%d",&n);
    FOR(i,1,3*n) {scanf("%d",&A[i]);} sum[0]=0;
    FOR(i,1,3*n) sum[i]=sum[i-1]+A[i];
    FOR(i,1,n) Q.push(-A[i]);
    s1[0]=s2[0]=0;
    FOR(i,n+1,2*n){
        Q.push(-A[i]);
        s1[i-n]=s1[i-n-1]-Q.top(); Q.pop();
    }

    FORD(i,3*n,2*n+1) {
        QQ.push(A[i]);
        //cout<<i<<"=>"<<A[i]<<'\n';
    }
    FORD(i,2*n,n){
        QQ.push(A[i]);
        //cout<<QQ.top()<<' ';
        s2[2*n+1-i]=s2[2*n-i]+QQ.top(); QQ.pop();
        //cout<<2*n-i<<' '<<s2[2*n-i]<<endl;
    }
    res=-1e18;
    FOR(i,n,2*n){
        ll ts1=sum[i],ts2=sum[3*n]-sum[i]; int len1=i-n,len2=2*n-i;
        //cout<<i<<' '<<ts1<<' '<<ts2<<' '<<s1[len1]<<' '<<s2[len2]<<endl;
        res=max(res,ts1-s1[len1]-ts2+s2[len2]);
    }
    printf("%lld",res);
    return 0;
}


Measured memory_bytes: 8056
#include <bits/stdc++.h>
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n;
    cin >> n;
    vector<lint> luca;
    luca.emplace_back(2);
    luca.emplace_back(1);
    repeat_from_to (i, 2, n) {
        luca.emplace_back(luca[i - 2] + luca[i - 1]);
        //vdump(luca);
    }
    cout << luca[n] << endl;
}


Measured memory_bytes: 256
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

class Main{
    public static void main(String[] a) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int top1 = 0, top2 = 0, top3 = 0;

        for (int i = 0; i < 10; i++) {
            int input = Integer.parseInt(br.readLine());
            int w;

            if (input > top1) {
		top3 = top2;
		top2 = top1;
		top1 = input;
            } else if (input > top2) {
		top3 = top2;
		top2 = input;
            } else if (input > top3) {
		top3 = input;
            }
        }

        System.out.println(top1 + "\n" + top2 + "\n" + top3);
    }
}

Measured memory_bytes: 9372
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int a[100010];
int b[100010]={0};
int main()
{
	long long i,n,count=1;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	i=1;
	while(a[i]!=2)
	{
		b[i]=1;
		i=a[i];
		count++;
		if(b[i]==1)
		{
			count=-1;
			break;
		}
	}
	cout<<count;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
#define all(c) (c).begin(), (c).end()
#define rep( i, a, n ) for( int i=a; i<n; i++ )
#define repp( i, a, n, p ) for( int i=a; i<n; i+=p )
#define per( i, a, n ) for( int i=n-1; i>=a; i--)

int main () {
    int n;
    cin >> n;
    ll sum =0;

    rep ( i, 1, n+1 ) {
        rep ( j, 1, n+1 ) {
            rep ( k, 1, n+1 ) {
                sum += gcd ( i, gcd ( k, j ) );
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

int main(){
	int n, m;
	cin >> n >> m;
	if(abs(n - m) > 1){
		cout << 0 << endl;
		return 0;
	}

	long long cnt = 1;
	if(n == m){
		cnt *= n + m;
	}else{
		if(n < m){
			swap(n, m);
		}
	}

	for(int i = 1; i <= n; i++){
		cnt = (cnt * i) % mod;
		if(i < n)cnt = (cnt * i) % mod;
	}
	cout << cnt << endl;
			


}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int dp[300][300];

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    int N; cin >> N;
    if (not N) break;
    vector<int> W(N); REP(i, N) cin >> W[i];
    memset(dp, 0, sizeof(dp));
    FOR(w, 2, N + 1) REP(left, N - w + 1) {
      // [left, right]
      int right = left + w - 1;
      if (dp[left + 1][right - 1] == w - 2 and abs(W[left] - W[right]) <= 1) {
        dp[left][right] = w;
      } else {
        FOR(mid, left, right) {
          dp[left][right] = max(dp[left][right], dp[left][mid] + dp[mid + 1][right]);
        }
      }
    }
    cout << dp[0][N - 1] << endl;
  }

  return 0;
}

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

int main(void) {
  int N, T;
  cin >> N >> T;
  vector<int> t(N);
  for (int i = 0; i < N; i++) {
    cin >> t[i];
  }

  long long now = 0;
  for (int i = 0; i < N - 1; i++) {
    if (t[i] + T > t[i+1]) {
      now += t[i+1] - t[i];
    } else {
      now += T;
    }
  }
  cout << now + T << endl;

  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int nums[] = new int[in.nextInt()];
        for (int i = 0; i < nums.length; i++)
            nums[i] = in.nextInt();
        int numx[] = new int[in.nextInt()];
        for (int i = 0; i < numx.length; i++)
            numx[i] = in.nextInt();
        in.close();

        int low = 0;
        int high = nums.length - 1;
        int counter = 0;

        for (int x = 0; x < numx.length; x++)
            counter += binarySearch(nums, low, high, numx[x]);
        System.out.println(counter);
    }
        public static int binarySearch(int arr[], int low, int high, int x) {
            int mid = low + (high - low) / 2;
            if (high < low)
                return 0;
            if (x == arr[mid])
                return 1;
            if (x < arr[mid])
                return binarySearch(arr, low, mid - 1, x);
            return binarySearch(arr, mid + 1, high, x);
        }
}



Measured memory_bytes: 68852
# -*- coding: utf-8 -*-
'import sys'
c={
    'S':[0]*13,
    'H':[0]*13,
    'C':[0]*13,
    'D':[0]*13
}
n=int(input())
for i in range(n):
    s,num=input().split()
    c[s][int(num)-1]=1
for i in["S","H","C","D"]:
    for j in range(13):
        if c[i][j]==0:
            print(i,j+1)

Measured memory_bytes: 5600
program ABC072B
    implicit none
    integer(8)::i
    integer(8)::t_len=1
    character(100000)::s,t
    read(5,*)s

    do i=1,len_trim(s)
        if(mod(i,2)==1)then
            t(t_len:t_len)=s(i:i)
            t_len=t_len+1
        end if
    end do

    print'(A)',t(1:t_len-1)
end program ABC072B

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

int main() {
    vector<int> A;
    vector<int> B;
    vector<int> C;
    int num;
    int N;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> num;
        A.push_back(num);
    }
     for(int i=0;i<N;i++){
        cin >> num;
        B.push_back(num);
    }
     for(int i=0;i<N;i++){
        cin >> num;
        C.push_back(num);
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    long long sum=0;
    long long b;
    for(int i=0;i<N;i++){
        auto t=lower_bound(A.begin(),A.end(),B[i]);
        b=(int)(t-A.begin());
        auto l=upper_bound(C.begin(),C.end(),B[i]);
        sum+=b*(long long)(C.end()-l);
    }
    cout << sum << endl;
}

Measured memory_bytes: 1912
import bisect

n = int(input())
A = [int(input()) for _ in range(n)]

que = [A[0]]

for a in A[1:]:
    if a > que[-1]:
        que.append(a)
    else:
        idx = bisect.bisect_left(que, a)
        que[idx] = a

print(len(que))


Measured memory_bytes: 11144
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
double dist(double x, double y){
 	return sqrt(x*x + y*y); 
}

int main() {
 	ios::sync_with_stdio(false);
  	cin.tie(0);
  
  	unsigned N;
  	cin >> N;
  	vector<int> cumul(N, 0);
  	int nr = 0;
  	int nw = 0;
  	char c;
  	for(int i = 0; i < N; i++){
      	cin >> c;
  		if(c == 'W') nw++;
  		else nr++;
    	cumul[i] = nw - nr;
    }
  	cout << min(nw, (cumul[nr-1] + nr)/2);
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};


int main(){
    string S;
    cin >> S;
    int N = S.length();
    ll ans = 0;
    ll tmp = 0;
    REP(i, N - 2){
        string target = S.substr(i, 3);
        if(target == "ABC"){
            S[i + 2] = 'A';
            ans += tmp + 1;
            i++;
        }else if(target[0] == 'A') tmp++;
        else tmp = 0;
    }
    print(ans);
    return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  int d = n % 10;
  if (d == 3) {
    cout << "bon" << endl;
  } else if (d == 0 || d == 1 || d == 6 || d == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int n, a[1000005], cnt[1000005];

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin >> n;
    int d = 0;
    bool ok = true, one = true;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        d = __gcd(d, a[i]);
        cnt[a[i]]++;
        if (a[i] != 1) one = false;
        if (cnt[a[i]] > 1 && a[i] > 1) ok = false;
    }

    if (one) {
        cout << "pairwise coprime\n";
        return 0;
    }

    for (int i = 2; i <= maxn && ok; i++) {
        int tmp = 0;
        for (int j = i; j <= maxn && ok; j += i) {
            if (cnt[j]) tmp++;
            if (tmp >= 2) ok = false;
        }
    }

    if (ok) {
        cout << "pairwise coprime\n";
        return 0;
    }

    if (d == 1) cout << "setwise coprime\n";
    else cout << "not coprime\n";

    return 0;
}


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

//const int Nmax=200010;
const ll Nmax=3000010;
int main() {
	int N,A[Nmax]={0};
	char S[Nmax];
	cin >> N;
	for(int i=0;i < N;i++){
		cin >> S[i];
		if(S[i]=='E') A[i] = 1;
		else A[i] = 2;
	}
	int S1[Nmax]={},S2[Nmax]={},mac=Nmax;
	if(A[0] == 2) S1[0]=1;
	if(A[N-1] == 1) S2[N-1]=1;
	for(int i=1;i < N;i++){
		if(A[i] == 2) S1[i]=S1[i-1]+1;
      else S1[i]=S1[i-1];
	}
	for(int i=N-2;i >=0;i--){
		if(A[i] == 1) S2[i]=S2[i+1]+1;
      else S2[i]=S2[i+1];
	}
  	mac = S2[0];
	for(int i=1;i < N-1;i++){
		mac = min(mac,S1[i-1]+S2[i+1]);
	}
  	mac = min(S1[N-1],mac);
	cout << mac << endl;
	return 0;
}

Measured memory_bytes: 37376
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
#define ll long long

int main(){
    std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int blood=c,cnt=0;
    while(1){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            break;
        }
        a-=d;
        if(a<=0){
            cout <<"No"<<endl;
            break;
        }
    }
}

Measured memory_bytes: 3612
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
struct SGT{
	#define SIZE 524288
	int f[SIZE<<1];
	SGT(){memset(f,-1,sizeof f);}
	void set(int x,int v){
		x+=SIZE;f[x]=v;
		while(x!=1){
			x>>=1;f[x]=max(f[x<<1],f[x<<1|1]);
		}
	}
	void get(int l,int r,int k,vector<int>&vv,int &cur,const int &ql,const int &qr){
		if(f[k]<=cur)return;
		if(r<ql||qr<l)return;
		if(ql<=l&&r<=qr){
			if(l==r){
				vv.push_back(l);cur=f[k];
				return;
			}else{
				if(cur<f[k<<1])get(l,(l+r)/2,k<<1,vv,cur,ql,qr);
				if(cur<f[k<<1|1])get((l+r)/2+1,r,k<<1|1,vv,cur,ql,qr);
			}
		}
		get(l,(l+r)/2,k<<1,vv,cur,l,r);
		get((l+r)/2+1,r,k<<1|1,vv,cur,l,r);
	}
	int Get(int l,int r,vector<int>&vv){
		int cur=-1;get(0,SIZE-1,1,vv,cur,l,r);
	}
}T;
int ls[2000005],rs[2000005],tot,root[2000005],val[2000005],size[2000005],rnd[2000005];
void init(){
	memset(root,0,sizeof root);tot=0;size[0]=0;
}
int new_node(int v){
	++tot;val[tot]=v;rnd[tot]=Rand();size[tot]=1;return tot;
}
void update(int x){
	size[x]=1+size[ls[x]]+size[rs[x]];
}
void split(int &rt1,int &rt2,int rt,int x){
	if(!rt){rt1=rt2=0;return;}
	if(val[rt]<x){
		rt1=rt;split(rs[rt1],rt2,rs[rt1],x);
	}else{
		rt2=rt;split(rt1,ls[rt2],ls[rt2],x);
	}
	update(rt);
}
int merge(int x,int y){
	if(!x||!y)return x|y;
	if(rnd[x]>rnd[y]){
		rs[x]=merge(rs[x],y);
		update(x);return x;
	}else{
		ls[y]=merge(x,ls[y]);
		update(y);return y;
	}
}
int n,ans;
int a[200005],mx[400005];
int get_max(int x){
	while(rs[x])x=rs[x];
	return val[x];
}
int get_min(int x){
	while(ls[x])x=ls[x];
	return val[x];
}
int main(){
	init();
	cin>>n;
	memset(mx,-1,sizeof mx);
	for(int i=1;i<=n;i++){
		cin>>a[i];T.set(i,a[i]);
		root[i]=new_node(a[i]);
		mx[i]=a[i];
	}
	for(int i=n+1;i<=n+n;i++){
		vector<int>got;
		T.Get(1,i,got);
		int lst=-1;
		for(auto x:got){
			int l=0,r=0;
			split(l,r,root[x],lst);
			lst=mx[x];root[x]=l;
			if(l)mx[x]=get_max(l);
			else mx[x]=-1;
			T.set(x,mx[x]);
			root[i]=merge(root[i],r);
		}
		if(size[root[i]]==n){
			cout<<i-n-1<<endl;
			return 0;
		}
		mx[i]=lst;
		T.set(i,mx[i]);
	}
	return 0;
}

Measured memory_bytes: 29940
n,m = map(int,input().split())
dp=[1 for _ in range(n+1)]
for i in range(m):
    a = int(input())
    dp[a] = 0
for i in range(2,n+1):
    if dp[i]==0:
        continue
    else:
        dp[i] = dp[i-1]+dp[i-2]
print(dp[n]%(10**9+7))

Measured memory_bytes: 469940
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define SORT(x) sort(all(x))
#define RSORT(x) sort(all(x),greater<ll>())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){

  int N;
  cin >> N;
  print(180*(N-2));

 return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
// clang-format on
 
main {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int p = 0, q = accumulate(all(a), 0LL);
  int mini = INF;
  rep(i, n - 1) {
    p += a[i];
    q -= a[i];
    cmin(mini, abs(p - q));
  }
  cout << mini << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  map<string, long> mp;
  string S;
  for(int i = 0; i < N; i++){
    cin >> S;
    mp[S]++;
  }
  cout << mp.size() << endl;
  return 0;
}

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

struct Node {
    int parent = -1, left = -1, right = -1;
};

int sibling(int node_id, vector<Node> &nodes) {
    Node node = nodes.at(node_id);

    if (node.parent == -1) {
        return -1;
    }
    else
    {
        Node parent = nodes.at(node.parent);
        if (parent.left == node_id)
            return parent.right;
        else
            return parent.left;
    }
}

void set_depth(int node_id, int p, vector<int> &D, vector<Node> &nodes) {
    Node node = nodes.at(node_id);
    D.at(node_id) = p;

    if (node.left != -1) {
        set_depth(node.left, p + 1, D, nodes);
    }

    if (node.right != -1) {
        set_depth(node.right, p + 1, D, nodes);
    }
}

int set_height(int node_id, vector<int> &H, vector<Node> &nodes) {
    Node node = nodes.at(node_id);
    int h_left = 0, h_right = 0;

    if (node.left != -1) {
        h_left = set_height(node.left, H, nodes) + 1;
    }

    if (node.right != -1) {
        h_right = set_height(node.right, H, nodes) + 1;
    }

    int h = max(h_left, h_right);
    H.at(node_id) = h;
    return h;
}

int degree(int node_id, vector<Node> &nodes) {
    Node node = nodes.at(node_id);
    int c = 0;
    // if (node.parent != -1) {
    //     c += 1;
    // }
    if (node.left != -1) {
        c += 1;
    }
    if (node.right != -1) {
        c += 1;
    }
    return c;
}

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

    vector<Node> nodes(N);
    vector<int> D(N), H(N);

    // cout << N << endl;
    for (int i = 0; i < N; i++) {
        int node_id, left_c, right_c;
        cin >> node_id >> left_c >> right_c;
        // cout << node_id << " " << left_c << " " << right_c << endl;

        // nodes.at(i) = node;
        nodes.at(node_id).left = left_c;
        nodes.at(node_id).right = right_c;

        if (left_c != -1)
            nodes.at(left_c).parent = node_id;
        if (right_c != -1)
            nodes.at(right_c).parent = node_id;
    }

    int root;
    for (int i = 0; i < N; i++)
    {
        if (nodes.at(i).parent == -1)
            root = i;
    }
    set_depth(root, 0, D, nodes);
    int h = set_height(root, H, nodes);

    // output
    for (int i = 0; i < N; i++) {
        Node node = nodes.at(i);

        // node id
        cout << "node " << i << ": ";

        // parent
        cout << "parent = " << node.parent << ", ";

        // sibling
        cout << "sibling = " << sibling(i, nodes) << ", ";

        // degree
        cout << "degree = " << degree(i, nodes) << ", ";

        // depth
        cout << "depth = " << D.at(i) << ", ";

        // height
        cout << "height = " << H.at(i) << ", ";

        // type
        string type;
        if (node.parent == -1) {
            type = "root";
        }
        else if (node.left != -1 || node.right != -1)
        {
            type = "internal node";
        }
        else {
            type = "leaf";
        }
        cout << type;

        cout << endl;
    }
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;
 
const int Inf = 1000000007;
//const int mod = 998244353;//1000000007;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int k, a, b;
 
void Solve()
{
	cin >> k >> a >> b;
	for(int i = a; i <= b; i++)
	{
		if(i % k == 0)
		{
			cout << "OK";
			return;
		}
	}
	cout << "NG";
}
 
int main()
{
	Fastio();
	Solve();
}

Measured memory_bytes: 3648
function Main(input) {
  input = input.split(' ');
  const takahashi = {
    strength: parseInt(input[0]),
    attack: parseInt(input[1])
  };
  const aoki = {
    strength: parseInt(input[2]),
    attack: parseInt(input[3])
  };

  while(takahashi.strength > 0 && aoki.strength > 0) {
    aoki.strength -= takahashi.attack;
    if (aoki.strength <= 0) {
      console.log('%s', 'Yes');
      break;
    }
    takahashi.strength -= aoki.attack;
    if (takahashi.strength <= 0) console.log('%s', 'No');
  }
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30136
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

ll fact(ll x){
	if(x<=1) return 1;
	ll y = 1;
	for(ll i = 2; i <= x; i++) (y*=i)%=mod;
	return y;
}

int main(){
	ll n;
	cin>>n;
	vector<ll> x(n);
	rep(i, n) cin>>x[i];
	ll res = 1, cnt = 0;
	rep(i, n){
		if(i+1-cnt>(x[i]+1)/2){
			(res *= i+1-cnt)%=mod;
			cnt++;
		}
	}
	(res*=fact(n-cnt))%=mod;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1024
from collections import deque
 
n,p=map(int ,input().split())
que=deque([])
 
for i in range(n):
    name,time=input().split()
    time=int(time)
    que.append([name,time])
 
t=0
while len(que)>0:
    atop=que.popleft()
    spend=min(atop[1],p)
    atop[1]-=spend
    t+=spend
    if(atop[1]==0):
        print(atop[0],t)
    else:
        que.append(atop)


Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ieps 5*30000
#define eps (int)  1e9
#define pii pair<int,int>
#define endl '\n'



int32_t main(){
	int n;
	cin>>n;
	set<int> v;
	for(int i = 1;i<=n;i++){
		v.insert(abs((i - 1) - (n - (i - 1) - 1)));
	}
	map<int,int> c;
	for(int i = 0;i<n;i++){
		int x;
		cin>>x;
		c[x]++;
	}
	int q = 1LL;
	int mod = 1000000007;
	for(auto p : v){
		if(p == 0LL){
			if(n%2){
				if(c[p] == 1) continue;
				else q*=0LL;
			}
			else{
				q*=0LL;
			}
			continue;
		}
		if(c[p] != 2) q*=0;
		else q*=2, q%=mod;
	}
	cout<<q%mod<<endl;
}

Measured memory_bytes: 7680
function main(arg){
  arg = arg.trim().split('\n');
  //投票用紙枚数
  var n = Number(arg[0]),
      //回答内容
      s = arg.slice(1, n + 1).sort(),
      //回答内容カウント用のリスト
      ary = {},
      cnt = 0;
  for (var i = 0; i < n; i++) {
    //要素
    var index = s[i];
    //同一要素をカウントしていく
    ary[index] = (ary[index])? ary[index] + 1: 1;
    //カウント数が増えた場合最多数更新
    if (cnt < ary[index]) {
    	cnt = ary[index];
    }
  }
  var out = Object.keys(ary);
  //重複の最多数の要素の出力
  out = out.filter((out) => ary[out] == cnt)
  	console.log(out.join('\n'));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 115664
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a1 = in.nextInt();
            int a2 = in.nextInt();

            if (a2 % 2 == 0 && (a2 / 2 - a1 >= 0) && 2 * a1 - a2 / 2 >= 0) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 33936
mod = 10**9+7
N, A, B, C = map(int, input().split())
def make_fact(n):#0~nの階乗を求める
    fact = [1]*(n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1]*i%mod
    return fact
fact = make_fact(N*2) #＠
def make_fact_inv(n):#0~nの階乗のmodに関する逆元を求める
    fact_inv = [1]*(n+1)
    fact_inv[n] = pow(fact[n], mod-2, mod)#フェルマーの小定理
    for i in range(n, 0, -1):
        fact_inv[i-1] = fact_inv[i]*i%mod
    return fact_inv
fact_inv = make_fact_inv(N*2)#＠
def comb(n, k):#nCk
    return fact[n]*fact_inv[k]*fact_inv[n-k]%mod
res = 0
AB_inv = pow(A+B, mod-2, mod)
for m in range(N, N*2):
    res+=comb(m-1, N-1)*pow(A, N, mod)*pow(B, m-N, mod)*pow(AB_inv, m, mod)*m
    res+=comb(m-1, N-1)*pow(B, N, mod)*pow(A, m-N, mod)*pow(AB_inv, m, mod)*m
    res%=mod
res*=100*pow(100-C, mod-2, mod)
res%=mod
print(res)




Measured memory_bytes: 44520
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main()
{
    int n;
    int p[100001];
    
    cin >> n;

    REP(i,n) cin >> p[i];

    int m[100001];
    REP(i,n) m[i] = 0;
    REP(i,n){
        if(i+1 == p[i]){
            m[i] = 1;
        }
    }
    int cnt = 0;
    REP(i,n){
        if(m[i] == 1){
            swap(p[i],p[i+1]);
            cnt++;
        }
        if(p[i] == i+1) m[i] = 1;
        else m[i] = 0;
        if(p[i+1] == i+2) m[i+1] = 1;
        else m[i+1] = 0;
    }

    /*int cnt = 0;
    for(int i = 0; i < n; i+=2){
        if(p[i] == p[i+1] && m[i] == 1){
            cnt += 2;
        }
        else if(m[i] == 1 && m[i+1] == 1){
            cnt++;
        }
        else if(m[i] == 1 && m[i+1] == 0){ 
            cnt++;
        }
    }*/

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin >>N >>S;
  if (N%2 == 0){
    string a =S.substr(0,N/2);
    string b =S.substr(N/2,N/2);
    if (a==b){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n, m = map(int, input().split())

students = []
for i in range(n):
    axis = [int(x) for x in input().split()]
    students.append(axis)

checkpoints = []
for i in range(m):
    axis = [int(x) for x in input().split()]
    checkpoints.append(axis)

ans = []
for s_x, s_y in students:
    distances = []
    for c_x, c_y in checkpoints:
        distances.append(abs(s_x - c_x) + abs(s_y - c_y))
    i_c = 0
    i_d = 4 * 10 ** 8 + 1
    for cnt, distance in enumerate(distances, 1):
        if i_d > distance:
            i_d = distance
            i_c = cnt
        else:
            pass
    ans.append(i_c)

for i in ans:
    print(i)

Measured memory_bytes: 3064
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x << endl , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

ll a , b , c , d;
int q;

int solve(){
    if(b > min(a,d))
        dokme("No")
    ll gc = __gcd(b , d);
    a%=gc;
    if(c - b + 1 >= 0)
        dokme("Yes");
    if(b + a > c + gc)
        dokme("No");
    dokme("Yes");
}

int32_t main(){
    migmig
    cin >> q;
    while(q -- ){
        cin >> a >> b >> c >> d;
        solve();
    }
    return(0);
}

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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;

void printLCS(vector<vector<int>> &d, string &s, int i, int j)
{
	if(i==0|| j==0)
	{
		//cout << s[i-1];
		return;
	}
	
	if(d[i][j] == 3)
	{
		printLCS(d, s, i-1, j-1);
		cout << s[i-1];
	
	}else if(d[i][j] == 2)
	{
		
		printLCS(d, s, i-1, j);
		
	}else
	{
		printLCS(d, s, i, j-1);
	}
}
	

int main(void)
{
	FAST
	
	
	string s, t; cin >> s >> t;
	
	int n = s.length(), m = t.length();
	
	vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
	vector<vector<int>> direction(n+1, vector<int>(m+1, 0));
	
	// 3: diag, 2: up, 1: left
	
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			if(s[i] == t[j])
			{
				dp[i+1][j+1] = dp[i][j]+1;
				direction[i+1][j+1] = 3;
				
			}else if(dp[i][j+1] >= dp[i+1][j])
			{
				dp[i+1][j+1] = dp[i][j+1];
				direction[i+1][j+1] = 2;
			}
			else
			{
				dp[i+1][j+1] = dp[i+1][j];
				direction[i+1][j+1] = 1;
			}
		}
	}

	printLCS(direction, s, n, m);
	
	return 0;
}


Measured memory_bytes: 71040
fun main(args: Array<String>) {
    val inputs = readInputLine().split(" ").map { Integer.parseInt(it) }
    
    val n = inputs[0]
    val l = inputs[1]
    
    val list = (l until l + n).toList()
    
    if (list.contains(0)) {
        println("${list.sum()}")
    } else if (list[0] > 0) {
        println("${list.sum() - list[0]}")
    } else {
        println("${list.sum() - list[list.size - 1]}")
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37864
#include <bits/stdc++.h>
using namespace std;
int main(){
    int y,m,d;
    char a,b;

    cin>>y>>a>>m>>b>>d;

    if(m<5){
        cout<<"Heisei"<<endl;
    }
    else {
        cout<<"TBD"<<endl;
    }
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Rahul Raj
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String input = in.next();
            int len = input.length();
            int count = 0;
            for (int i = 0; i < len; i++) {
                if (input.charAt(i) == '1') {
                    count++;
                }
            }
            out.println(count);
        }

    }
}



Measured memory_bytes: 21716
#include <iostream>
using namespace std;
int F[1001];
int P[10010];
void init(int n) {
 for (int i=0; i<n; ++i) { P[i] = i; }
}
int root(int a) {
 if (P[a] == a) return a;
 return (P[a] = root(P[a]));
}
bool is_same_set(int a, int b) {
 return root(a) == root(b);
}
void unite(int a, int b) {
 P[root(a)] = root(b);
}

int main() {
 F[0]=1;
 F[1]=2;
 for (int i=2; i<1001; ++i) {
  F[i]=(F[i-1]+F[i-2]) % 1001;
 }
 int V, D;
 while (cin >> V >> D) {
  init(V+1);
  for (int i=1; i<=V; ++i) {
   for (int j=i+1; j<=V; ++j) {
    if(F[j]-F[i]<D && -D<F[j]-F[i]) { unite(i, j); }
   }
  }
  int ans = 0;
  for (int i=1; i<=V; ++i) {
   if (root(i) == i) { ans++; }
  }
  cout << ans << endl;
 }
}


Measured memory_bytes: 1176
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a=2000000000,b=2000000000,e=0;
  for(int i=0;i<n;i++){
    int c,d;
    cin>>c>>d;
    a=min(a,c);
    b=min(b,d);
    e=max(e,c);
  }
  cout<<b+a+(e-a)<<endl;
  return 0;
}


Measured memory_bytes: 256
/*
*/

#define _CRT_SECURE_NO_WARNINGS

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-6
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 337

using namespace std;

const int INF = 1e9;
const int N = 201231;

int n, m;
long long dp[305][305][305];
int ans;
vector<int> g[500];
int used[500];

void dfs(int v)
{
	used[v] = 1;
	for (int i = 0; i < g[v].size(); i++)
	{
		int to = g[v][i];
		if (used[to])
			continue;
		dfs(to);
	}
}

bool valid(int v)
{
	for (int i = 1; i <= n; i++)
		used[i] = 0;
	dfs(v);
	return (used[1] == 1);
}

bool check()
{
	for (int i = 1; i <= n; i++)
	{
		if (!valid(i))
			return false;
	}
	return true;
}

vector<int> path;

void generate(int dep,int cur)
{
	if (dep == m)
	{
		if (check())
		{
			++ans;
			/*for (int i = 0; i < path.size(); i++)
			{
				cout << path[i] << " ";
			}
			cout << endl;*/
		}
		return;
	}
	for (int i = 1; i <= n; i++)
	{
		g[cur].push_back(i);
		path.push_back(i);
		generate(dep + 1, i);
		g[cur].pop_back();
		path.pop_back();
	}
}

int brute(int m, int n)
{
	ans = 0;
	for (int i = 1; i <= n; i++)
	{
		g[i].clear();
	}
	path.push_back(1);
	generate(0,1);
	path.pop_back();
	return ans;
}

int main(){
	//freopen("fabro.in","r",stdin);
	//freopen("fabro.out","w",stdout);
	//freopen("F:/input.txt", "r", stdin);
	//freopen("F:/output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin >> n >> m;

	dp[0][1][0] = 1;
	for (int i = 0; i <m; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			for (int q = 0; q <= n; q++)
			{
			//	cout << i << " " << j << " " << q << " " << dp[i][j][q] << endl;

				dp[i + 1][j][q + 1] += dp[i][j][q] * (n - j - q) % bs;// new vertex
				dp[i + 1][j + q][0]+=dp[i][j][q] * j%bs;
				dp[i + 1][j][q] += dp[i][j][q] * q%bs;
				dp[i + 1][j][q + 1] %= bs;
				dp[i + 1][j + q][0] %= bs;
				dp[i+1][j][q + 1] %= bs;
			}
		}
	}

	cout << dp[m][n][0] << endl;

//	cout << brute(m, n) << endl;

	cin.get(); cin.get();
	return 0;
}

Measured memory_bytes: 219008
#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define LL long long
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define sz(v) ((int)sizeof(v))
#define N 200005

int main()
{
    int a,b,ans;
    while(~scanf("%d%d",&a,&b)){
    if(b>0){
        if(a>=0){
            if(a>b){
                ans=a-b+2;
            }
            else{
                ans=b-a;
            }
        }
        else{
            ans=abs(b-abs(a))+1;
        }
    }
    else{
        if(a>=0){
            if(abs(b)<a){
                ans=abs(abs(b)-abs(a))+1;
            }
            else{
                ans=abs(abs(b)-abs(a))+1;
            }
        }
        else{
            if(abs(a)<abs(b)){
                ans=abs(abs(b)-abs(a))+2;
            }
            else{
                ans=abs(abs(b)-abs(a));
            }
        }
    }
    printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256