akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
vi lcms(1000020,0);
void prime_factor(int n){
    map<int,int> res;
    for(int i=2; i*i<=n; i++){
        while(n%i==0){
            ++res[i];
            n /= i;
        }
        chmax(lcms.at(i),res[i]);
    }
    if(n != 1) res[n]=1;
    chmax(lcms.at(n),res[n]);
    return;
}
ll pow(ll x,ll y,ll m){
    if(y==0) return 1;
    if(y&1) return x*pow(x,y-1,m)%m;
    ll p=pow(x,y/2,m);
    return p*p%m;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    
    ll n;
    cin >> n;
    vi a(n);
    rp(i,n) {
        cin >> a.at(i);
        prime_factor(a.at(i));
    }
    ll l_c_m=1;
    for(int i=2; i<=1000000; i++){
        l_c_m *= pow(i,lcms.at(i),Mod);
        l_c_m %= Mod;
    }
    ll ans=0;
    rp(i,n){
        ans += l_c_m*pow(a.at(i),Mod-2,Mod)%Mod;
        ans %= Mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
 
 
long mod = 1000000007;
 
//aのp乗を求めるアルゴリズム
//p=62の時、pの変化は、62->31->30->15->14->7->6->3->2->1->0
//と、半分半分になっていく
//よって、計算量はO(logp)になる
long modpow(long a, int p) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		//pが偶数の時
		int halfP = p / 2;
		long half = modpow(a, halfP);
		//a^(p/2) をhalfとして、half*halfを計算
		return half * half % mod;
	}
	else {
		//pが奇数の時は、
		//pを偶数にするために1減らす
		return a * modpow(a, p - 1) % mod;
	}
}
 
 
//(10*9*8)/(3*2*1);
//10*9*8 -> ansMul
//3*2*1 -> ansDiv
long calcComb(int a, int b) {
	if (b > a - b) return calcComb(a, a - b);
 
 
	long ansMul = 1;
	long ansDiv = 1;
	for (int i = 0; i < b; i++)
	{
		ansMul *= (a - i);
		ansDiv *= (i + 1);
		ansMul %= mod;
		ansDiv %= mod;
	}
	//ansMul / ansDivをやりたい
	//ansDivの逆元を使って求めよう！
 
	long ans = ansMul * modpow(ansDiv, mod - 2) % mod;
	return ans;
}
 
 
int main() {
	int N, M;
	cin >> N >> M;
 
	int MNokori = M;
	long ans = 1;
	for (int i = 2; i * i <= MNokori; i++)
	{
		if (MNokori % i == 0) {
			int cnt = 0;
			while (MNokori % i == 0) {
				cnt++; MNokori /= i;
			}
			//cntが2^Xとか3^XのXの部分
			ans *= calcComb(N + cnt - 1, N - 1); //N-1はcntと同じ
			ans %= mod;
		}
	}
	if (MNokori != 1) {
		//最後に素数が残ってる分を処理する
		ans *= calcComb(N + 1 - 1, N - 1); //N-1はcntと同じ
		ans %= mod;
	}
 
	cout << ans << endl;
}

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

int main(){
    string s;
    cin>>s;
    int cnt=0;
    int z,a;
    for(int i=s.size();i>0;i--){
        if(s[i]=='Z'){
            z=i;
            break;
        }
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    cout<<z-a+1<<endl;
    return 0;
}

Measured memory_bytes: 3760
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

const MOD: u64 = 1_000_000_007;

fn modpow(a: u64, b: u64) -> u64 {
    let mut a = a;
    let mut b = b;
    let mut res = 1;
    while b != 0 {
        if b & 1 != 0 {
            res = res * a % MOD;
        }
        a = a * a % MOD;
        b /= 2;
    }
    res
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let n = sc.read();
        let a: Vec<usize> = sc.vec(n);
        let mut cnt = vec![0u32; n];
        for &x in a.iter() {
            cnt[x] += 1;
        }

        let mut ok = true;
        for i in 0..n {
            if n % 2 == 0 {
                if i % 2 == 0 {
                    ok &= cnt[i] == 0;
                } else {
                    ok &= cnt[i] == 2;
                }
            } else {
                if i == 0 {
                    ok &= cnt[i] == 1;
                } else if i % 2 == 0 {
                    ok &= cnt[i] == 2;
                } else {
                    ok &= cnt[i] == 0;
                }
            }
        }

        let ans = if ok {
            modpow(2, (n / 2) as u64)
        } else {
            0
        };
        println!("{}", ans);
    }
}


Measured memory_bytes: 8572
import itertools

n, m = map(int, input().split())

path = [[False] * n for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True

ans = 0

# 頂点を並び替える順列を生成してループ
for i in itertools.permutations(range(n), n):
    # 頂点1が始点
    if i[0] == 0:
        # 生成した順列の中をさらにループ
        for j in range(n):
            # n - 1 まで続いたら条件を満たすパスが存在する
            if j == n - 1:
                ans += 1
                break
            # i[j] から i[j + 1] に行くパスがなければ終了
            if not path[i[j]][i[j + 1]]:
                break

print(ans)

Measured memory_bytes: 40048
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
    return 0;
}

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

int main(){
	double d,r,n=90,x=0,y=0;
	char k;//????????????????????????
	while(1){
		cin>>d>>k>>r;
		if(d==0&&r==0) break;
		x+=d*cos(M_PI*n/180);
		y+=d*sin(M_PI*n/180);
		n-=r;
	}
	cout<<(int)x<<endl<<(int)y<<endl;
}

Measured memory_bytes: 1228
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int dp[45][500][500];
int main(){
    int n, a, b;
    int x, y, z;
    scanf("%d%d%d",&n,&a,&b);
    memset(dp,0x7f,sizeof(dp));
    dp[0][0][0] = 0;
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&x,&y,&z);
        for(int j=0;j<=400;j++)
        for(int k=0;k<=400;k++){
            if(dp[i-1][j][k] != 0x7f7f7f7f){
                dp[i][j][k] = min(dp[i-1][j][k],dp[i][j][k]);
                dp[i][j+x][k+y] = min(dp[i][j+x][k+y],dp[i-1][j][k] + z);

            }
        }
    }

    int ans = 0x7f7f7f7f;
    for(int i=a,j=b;i<=400&&j<=400;i+=a,j+=b){
            ans = min(ans,dp[n][i][j]);
    }
    printf("%d\n",ans!=0x7f7f7f7f?ans:-1);
    return 0;
}


Measured memory_bytes: 44160
<?php
	$s = trim(fgets(STDIN));
	$s = explode(' ', $s);
	$n = $s[0];
	$x = $s[1];
	$s = trim(fgets(STDIN));
	$a = explode(' ', $s);
	$ans = 0;
	
	if($a[0] > $x){
		$ans += $a[0] - $x;
		$a[0] = $x;
	}
	for($i = 1; $i < count($a); $i++){
		if($a[$i] > $x){
			$ans += $a[$i] - $x;
			$a[$i] = $x;
		}
		if($a[$i] + $a[$i - 1] > $x){
			$ans += $a[$i] + $a[$i - 1] - $x;
			$a[$i] = $x - $a[$i - 1];
		}
	}
	
	echo $ans."\n";
?>

Measured memory_bytes: 22080
import java.io.*;
import java.util.*;
public class Main
{
    public static void main(String args[]) throws Exception
    { new Main();}
  
    static int MAX = 9999;
    
    Main(){
    	Scanner cin = new Scanner(System.in);
    	int i,j,k,num;
    	while(true){
    		int n;
    		n = cin.nextInt();
    		if(n==0) break;
    		int input[] = new int[n];
    		for(i=0;i<n;i++){
    			input[i] = 0;
    			for(j=0;j<n;j++){
    				if(cin.nextInt()!=0) input[i] += 1<<j;
    			}
    		}
    		
    		num = n*(n+1)/2;
    		int range[] = new int[num];
    		int count = 0;
    		for(i=0;i<=n;i++){
    			for(j=i+1;j<=n;j++){
    				range[count++] = (1<<j)- (1<<i);
    			}
    		}
    		int memo[] = new int[1<<num];
    		int plus[] = new int[1<<num];
    		for(i=0;i<(1<<num);i++){
    			memo[i] = 0;
    			plus[i] = 0;
    			for(j=0;j<num;j++){
    				if(((1<<j)&i)!=0){
    					memo[i] ^= range[j];
    					plus[i]++;
    				}
    			}
    		}
    		ArrayList<LinkedList<Integer> > list = new ArrayList<LinkedList<Integer> >(0);
    		for(i=0;i<(1<<n);i++) list.add(new LinkedList<Integer>());
    		for(i=0;i<(1<<num);i++){
    			list.get(memo[i]).add(i);
    		}
    		int dp[] = new int[1<<num];
    		for(j=0;j<(1<<num);j++) dp[j] = MAX;
    		dp[0] = 0;
    		for(i=0;i<n;i++){
    			int newdp[] = new int[1<<num];
    			for(j=0;j<(1<<num);j++) newdp[j] = MAX;
    			for(j=0;j<(1<<num);j++){
    				if(dp[j]==MAX) continue;
    				int need = memo[j] ^ input[i];
    				for(int l : list.get(need)){
    					newdp[j ^ l] = Math.min(newdp[j ^ l], dp[j]+plus[l]);
    				}
    			}
    			dp = newdp.clone();
    		}
    		int res = MAX;
    		for(j=0;j<(1<<num);j++) res = Math.min(res, dp[j]+Integer.bitCount(j));
    		for(j=0;j<res/2;j++) System.out.print("myon");
    		System.out.println();
    	}
    }
}

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

int main() {
  
  int N,A,B;
  cin >> N;
  
  B = N;

  for (int i = 0; i < 9; i++) {
    A += N % 10;
    N = N / 10;
  }

 if (B % A == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <tuple>
using namespace std;
using ll = long long;

int main()
{
  pair<int, int> s, t;
  cin >> s.first >> s.second >> t.first >> t.second;
  for (int i = 0; i < 2; ++i)
  {
    if (i == 0)
      cout << "L";
    else
      cout << "R";
    for (int j = 0; j < t.second - s.second + 1; ++j)
    {
      if (i == 0)
        cout << "U";
      else
        cout << "D";
    }
    for (int j = 0; j < t.first - s.first + 1; ++j)
    {
      if (i == 0)
        cout << "R";
      else
        cout << "L";
    }
    if (i == 0)
      cout << "D";
    else
      cout << "U";
  }
  for (int i = 0; i < 2; ++i)
  {
    for (int j = 0; j < t.second - s.second; ++j)
    {
      if (i == 0)
        cout << "U";
      else
        cout << "D";
    }
    for (int j = 0; j < t.first - s.first; ++j)
    {
      if (i == 0)
        cout << "R";
      else
        cout << "L";
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int n,m;
    cin >> n >> m;
    int b[10] = {0,0,0,0,0,0,0,0,0,0};
    int c[10] = {0,2,5,5,4,5,6,3,7,6};
    rep(i,m){
        int a;
        cin >> a;
        b[a] = 1;
    }
    pair<int,int> dp[10101];
    rep(i,n+1)dp[i].first = -1e9;
    dp[0].first = 0;
    for(int i = 1;i < 10101;i++){
        for(int j = 1;j < 10;j++){
            if(b[j] == 1){
                if(i-c[j] >= 0 && dp[i-c[j]].first != -1e9){
                    dp[i] = max(dp[i],{dp[i-c[j]].first+1,j});
                }
            }
        }
    }
    int match = n;
    while(match > 0){
        cout << dp[match].second;
        match -= c[dp[match].second];
    }
    cout << endl;
}

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


Measured memory_bytes: 384
from numba import njit
@njit(cache=True)
def f(k):
    a = 7%k
    for i in range(k):
        if a == 0:
            print(i+1)
            break
        a = (a*10+7)%k
    else:
        print(-1)
k = int(input())
f(k)

Measured memory_bytes: 109396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  long long H1,M1,H2,M2,K,ans;
	cin>>H1>>M1>>H2>>M2>>K;
	ans=60*H2+M2-K-60*H1-M1;
	cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long l;
int main()
{
    int n;
    cin>>n;
    int res,rem;
    rem = n/1000;
    if(n%1000 != 0)
        res = ((rem+1)*1000) - n;
    else
        res = 0;
    cout<<res;
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String linr = br.readLine();
		int ans = 0;

		for (int i = 0; i < linr.length(); i++) {
			if (linr.charAt(i) == '+') {
				ans++;
			} else {

				ans--;
			}
		}
		System.out.println(ans);
	}

}


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

int main(){
  int n;
  cin >> n;
  vector<int>vec(n);
  rep(i,n){
    cin >> vec.at(i);
    vec.at(i)--;
  }
  int x = 0;
  rep(i, n){
    if(vec.at(x) == 1){
      cout  << i + 1 << endl;
      return 0;
    }
    x = vec.at(x);
  }
  cout << -1 << endl;


}



Measured memory_bytes: 3772
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, 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;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b; cin >> a >> b;
	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  string s,t;
  cin>>s>>t;
  cout<<t+s<<endl;
}

Measured memory_bytes: 3548
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	r := getNextInt(scanner)
	c := getNextInt(scanner)
	maze := make([][]byte, r)
	steps := make([][]int, r)
	n := r * c
	queue := make([][]int, n)
	ql := 0
	qr := 0
	for y := 0; y < r; y++ {
		maze[y] = make([]byte, c)
		steps[y] = make([]int, c)
		s := getNextString(scanner)
		for x := 0; x < c; x++ {
			maze[y][x] = s[x]
			if s[x] == '.' {
				continue
			}
			steps[y][x] = 1
			queue[qr] = []int{
				y, x, 0,
			}
			qr++
		}
	}

	dy := [4]int{-1, 0, 0, 1}
	dx := [4]int{0, -1, 1, 0}
	ans := -1
	for qr-ql > 0 {
		p := queue[ql]
		ql++
		ans = p[2]
		for i := 0; i < 4; i++ {
			yy := p[0] + dy[i]
			xx := p[1] + dx[i]
			if yy < 0 || yy >= r {
				continue
			}
			if xx < 0 || xx >= c {
				continue
			}
			if maze[yy][xx] == '#' {
				continue
			}
			if steps[yy][xx] > 0 {
				continue
			}
			steps[yy][xx] = 1
			queue[qr%n] = []int{
				yy,
				xx,
				p[2] + 1,
			}
			qr++
		}
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}


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

int main(){
  int count=0;
  int A,B,K;
  cin>>A>>B>>K;
  for(int i=min(A,B);i>=1;--i){
    if(A%i  == 0 && B%i == 0){
    --K; 
      if(K==0){
      cout<<i;
      return 0;
    }
    }
  }
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------

ll n,k;
ll t[100010];
ll a,b;

int main(){
    
    cin>>n>>k;
    REP(i,n){
        cin>>a>>b;
        t[a]+=b;
    }
    
    ll cnt=k;
    ll ans;
    REP(i,100005){
        cnt-=t[i];
        if(cnt<=0){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    int a[101];
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> a[i];
    cout << a[n-1];
    for(int i=1; i<n; i++)
        cout <<" "<< a[n-i-1];
    cout << endl;
    return 0;
}



Measured memory_bytes: 3076
n = int(input())
p = list(map(int, input().split())) 
count=0
for i in range(len(p)-2):
    if(p[i+1]>p[i] and p[i+1]<p[i+2]):
        count+=1
    elif(p[i+1]<p[i] and p[i+1]>p[i+2]):
        count+=1
       
print(count)
    

Measured memory_bytes: 3060
using System;

namespace ABC123A
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            var d = int.Parse(Console.ReadLine());
            var e = int.Parse(Console.ReadLine());
            var k = int.Parse(Console.ReadLine());

            int flag = 0;

            if(b-a > k)
            {
                flag = 1;
            }
            else if(c - a > k)
            {
                flag = 1;
            }
            else if(d - a > k)
            {
                flag = 1;
            }
            else if(e - a > k)
            {
                flag = 1;
            }
            else if(c - b > k)
            {
                flag = 1;
            }
            else if(d - b > k)
            {
                flag = 1;
            }
            else if(e - b > k)
            {
                flag = 1;
            }
            else if(d- c > k)
            {
                flag = 1;
            }
            else if(e - c > k)
            {
                flag = 1;
            }
            else if(e - d > k)
            {
                flag = 1;
            }

            if(flag == 0)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}


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

#define    int               long long int
 #define    bp(x)         __builtin_popcount(x)
#define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
#define  mod  1000000007
#define  endl  "\n"
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int t[800099];
int query(int node,int l,int r,int s,int e)
{
    if(l>e || r<s)   
        return 0;
    if(l<=s && e<=r)
        return t[node];
    int mid=(s+e)>>1;
    return max(query(2*node,l,r,s,mid) , query(2*node +1,l,r,mid+1,e));
}
void update(int node,int idx,int s,int e,int val)
{
    if(s==e)
        t[node]=val;
    else{
        int mid=(s+e)>>1;;
        if(s<= idx && idx<=mid)
            update(2*node,idx,s,mid,val);
        else
            update(2*node +1,idx,mid+1,e,val);
        t[node]=max(t[2*node] , t[2*node +1]);
    }
}


int32_t main()
{
    fast
    int n,ans=0;  cin>>n;
    int a[n+1],h[n+1];
    f(i,1,n)    cin>>h[i];
    f(i,1,n)    cin>>a[i];
    update(1,h[1],1,n,a[1]);
    ans=a[1];
    f(i,2,n){
        int x=query(1,1,h[i],1,n);
        update(1,h[i],1,n,a[i]+x);
        ans=max(ans,x+a[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 10840
import java.util.*

fun main(args: Array<String>) {
  val s = StringBuilder(readLine()!!)
  val t = StringBuilder()
  val q = readLine()!!.toInt()
  var r = 0
  repeat(q) {
    val query = readLine()!!
    if (query[0] == '1') {
      r++
    } else {
      val a = query[2] == '1'
      val b = r % 2 == 0
      if ((a && b) || (!a && !b)) {
        t.append(query[4])
      } else {
        s.append(query[4])
      }
    }
  }
  if (r % 2 == 0) {
    println(t.reverse().append(s))
  } else {
    println(s.reverse().append(t))
  }
}


Measured memory_bytes: 41824
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;



int main() {
    int n=read(), m=read();
    ll sum=0;
    for(int i=1; i<=m; ++i) sum+=read();
    if(n<sum) printf("-1\n");
    else printf("%lld\n", n-sum);
}

Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int write_move(char c, int dist) {
  REP(i, dist) {
    cout << c;
  }
}

int sign(int x) {
  return (x>0)-(x<0);
}

int main(){
  int N, M;
  cin >> N >> M;
  int dist[100][100];
  REP(i, N) {
    REP(j, N) {
      dist[i][j] = i == j ? 0 : 999999;
    }
  }
  vector<tuple<int,int,int>> v;
  REP(i, M) {
    int A, B, C;
    cin >> A >> B >> C;
    A--; B--;
    dist[A][B] = C;
    dist[B][A] = C;
    v.push_back(make_tuple(A, B, C));
  }
  REP(k, N) {
    REP(i, N) {
      REP(j, N) {
        int ndist = dist[k][i] + dist[k][j];
        if(dist[i][j] > ndist) {
          dist[i][j] = ndist;
          dist[j][i] = ndist;
        }
      }
    }
  }
  int ret = 0;
  for(auto itr = v.begin(); itr != v.end(); ++itr) {
    int A = get<0>(*itr), B = get<1>(*itr), C = get<2>(*itr);
    if(dist[A][B] < C) {
      ++ret;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        int sum = 0;
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }
        if (n < sum) {
            System.out.println(-1);
            return;
        }
        System.out.println(n - sum);
    }

}


Measured memory_bytes: 46352
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	boolean f = false;
	for(int i = 1; i <= b; i++) {
		if((a * i) % b == c) {
			f = true;
			break;
		}
	}
	if(f == false) {
		System.out.println("NO");
	} else {
		System.out.println("YES");
	}
}
}

Measured memory_bytes: 21844
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 2000 + 20 , inf = 1e9 + 20 ;
int n , k , q , a[N] , ans = inf ;
bool mark[N] ;
vector <pii> vals ;

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

	cin >> n >> k >> q ;

	for (int i = 0 ; i < n ; i ++) cin >> a[i] , vals.push_back({a[i] , i}) ;

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

	for (pii p : vals) {
		vector <int> tmp , vec ;

		for (int i = 0 ; i <= n ; i ++) {
			if (i == n || mark[i]) {
				sort(tmp.begin() , tmp.end()) ;
				for (int j = 0 ; j < _sz(tmp) - k + 1 ; j ++) vec.push_back(tmp[j]) ;
				tmp.clear() ;
			}
			else tmp.push_back(a[i]) ;
		}

		sort(vec.begin() , vec.end()) ;
		if (_sz(vec) >= q) ans = min(ans , vec[q - 1] - vec[0]) ;

		mark[p.S] = 1 ;
	}

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


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    n,k = map(int,input().split())
    if k%2 == 0:
        x = n//k
        k //= 2
        y = n//k
        ans = x*x*x - (x - y)*(x - y)*(x - y)
        print(ans)
    else:
        x = n//k
        print(x*x*x)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
double n,m,d,p,ans;
scanf("%lf%lf%lf",&n,&m,&d);
p=2*(n-d)/n;
if(d==0)
p=1;
ans=p*(m-1)/n;
printf("%.10lf\n",ans);
return 0;
}


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

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


int main(){

  ll n; cin >> n;
  map<string, int> mp;

  string tmp;
  rep(i,n){
    cin >> tmp;
    mp[tmp] ++;
  }

  ll ans = 0;
  for(auto itr : mp){
    ans++;
  }
  cout << ans << endl;

  return 0;
}



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

int main() {
	int a;
	while (cin >> a, a) {
		int s = 0;
		for (int b = 0; b < a / 4; b++) {
			int c;
			cin >> c;
			s += c;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 3004
#include <stdio.h>
int dx[4]={-1,0,0,1};
int dy[4]={0,1,-1,0};
int w,h,wsum,bsum,wnum=0,bnum=0,kari;
char sima[51][51];

int dfs(int y,int x){
    int res=1,i;
    if(y<0||y>=h||x<0||x>=w)
        return 0;
    
    if(sima[y][x]!='.'){
        if(sima[y][x]=='W')wnum++;
        if(sima[y][x]=='B')bnum++;
        return 0;
    }
    sima[y][x]='X';
    
    for(i=0;i<4;i++){
        int nx=x+dx[i];
        int ny=y+dy[i];
        res+=dfs(ny, nx);
    }
    return res;
}

int main(void){
    int i,j;
    while(1){
    scanf("%d %d",&w,&h);
        if(w==0)
            break;
    for(i=0;i<h;i++)
        scanf("%s",sima[i]);
    
    wsum=bsum=0;
    for(i=0;i<h;i++)
        for(j=0;j<w;j++){
            wnum=bnum=0;
            if(sima[i][j]!='.')
                continue;
            kari=dfs(i,j);
            if(wnum!=0&&bnum==0)
                wsum+=kari;
            
            if(wnum==0&&bnum!=0)
                bsum+=kari;
            
        }
    printf("%d %d\n",bsum,wsum);
    }
    return 0;
    
}

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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> data(N);
  for(int i=0;i<M;i++){
    int T1,T2;
    cin>>T1>>T2;
    data.at(T1-1)++;
    data.at(T2-1)++;
  }
  for(int i=0;i<N;i++){
    cout<<data.at(i)<<endl;
  }
}


Measured memory_bytes: 3508
#include <cstdio>
#include <map>

int main()
{
    int n;
    scanf("%d", &n);
    std::map<int, int> m;
    for (int i = 0; i < n; ++ i) {
        int a;
        scanf("%d", &a);
        m[a] ++;
    }
    long long result = 0;
    int last = 0;
    for (auto iterator : m) {
        if (iterator.second >= 2) {
            result = std::max(result, (long long)last * iterator.first);
            last = iterator.first;
        }
        if (iterator.second >= 4) {
            result = std::max(result, (long long)iterator.first * iterator.first);
        }
    }
    printf("%lld\n", result);
}

Measured memory_bytes: 4864
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))


for i, l in enumerate(itertools.permutations(range(1, n + 1))):
    if list(l) == p:
        a = i
    if list(l) == q:
        b = i
print(abs(a - b))


Measured memory_bytes: 74012
#include <iostream>
#include <string>
#include<bits/stdc++.h>
bool a[105][105];
using namespace std;
int main(){
	string s,ss;
	int i,j,k,n,m;
	cin>>n>>m;
	char tql;
	memset(a,0,sizeof(a));
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++) {
			cin>>tql;
			if(tql=='#') a[i][j]=1;
		}
	}
/*	for(i=1;i<=n;i++){
		cout<<endl;
		for(j=1;j<=m;j++)
	//		cout<<a[i][j];
			cout<<a[i+1][j+1]+a[i+1][j-1]+a[i+1][j]+a[i][j+1]+a[i][j-1]+a[i-1][j+1]+a[i-1][j]+a[i-1][j-1];
	}*/
		for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(a[i][j]==1) printf("#"); 
            else
            {
                printf("%d",a[i+1][j+1]+a[i+1][j-1]+a[i+1][j]+a[i][j+1]+a[i][j-1]+a[i-1][j+1]+a[i-1][j]+a[i-1][j-1]);
		
		}
		
		}cout<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){

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

    int count, divisiors;
    count = a;
    divisiors = 0;

    while(count < b+1){
        if(c % count == 0) {
            divisiors++;
            count++;
        }
        else if(c % count != 0) {
            count++;
        }
    }

    cout << divisiors << endl;

    return 0;

}


Measured memory_bytes: 3116
#include<stdio.h>
int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12)
    {
        if(y==1||y==3||y==5||y==7||y==8||y==10||y==12)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    else if(x==4||x==6||x==9||x==11)
    {
        if(y==4||y==6||y==9||y==11)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    else if(x==2 && y==2)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

/*<ここから>***********************************************************/


int main()
{
	string S;
	cin >> S;
	int ans = 700;
	for (int i = 0; i < 3; i++) {
		if (S[i] == 'o') ans += 100;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 1005;
const int MOD = 1e9+7;
int main() {
  ios_base::sync_with_stdio(false);
  int n; cin >> n;
  vector < double > v(n + 5), dp(n + 5, 0);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  dp[0] = 1;
  // dp[i] --> probabilitatea sa intoarcem i capuri
  for (int i = 1; i <= n; i++) {
    double tail = 1 - v[i];
    for (int heads_already = n; heads_already >= 0; heads_already--) {
      if (heads_already == 0) {
        dp[heads_already] = dp[heads_already] * tail;
        continue;
      }
      dp[heads_already] = dp[heads_already] * tail + dp[heads_already - 1] * v[i];
    }
  }
  double ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i > n - i) {
      ans += dp[i];
    }
  }
  cout << fixed << setprecision(10) << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 1e5+5;
int A[maxn];

int main()
{
    int n,k;
    while (cin >> n >> k) {
        FOR(i,0,n)
            cin >> A[i];
        int ans = inf;
        for (int i = 0; i < n; i++) {
            if (i+k <= n) {
                const int a = A[i];
                const int b = A[i+k-1];
                if (b < 0) {
                    ans = min(ans,abs(a));
                }
                else if (a < 0 && b > 0) {
                    const int x = 2*abs(a) + b;
                    const int y = abs(a) + 2*b;
                    ans = min(ans,min(x,y));
                }
                else {
                    ans = min(ans,b);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
def d_atcoder_express_2(N, M, Q, Train, Query):
    x = [[0] * (N + 1) for _ in range(N + 1)]
    for l, r in Train:
        x[l][r] += 1
    # 2次元累積和
    for r in range(1, N + 1):
        for c in range(1, N + 1):
            x[r][c] += x[r - 1][c] + x[r][c - 1] - x[r - 1][c - 1]

    tmp = []
    for p, q in Query:
        # 包除原理的
        tmp.append(str(x[q][q] - x[p - 1][q] - x[q][p - 1] + x[p - 1][p - 1]))
    ans = '\n'.join(tmp)
    return ans

N, M, Q = [int(i) for i in input().split()]
Train = [[int(i) for i in input().split()] for j in range(M)]
Query = [[int(i) for i in input().split()] for j in range(Q)]
print(d_atcoder_express_2(N, M, Q, Train, Query))

Measured memory_bytes: 64668
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
lint gcd(lint a,lint b){
    if(b==0)return a;
    return gcd(b,a%b);
}
bool solve(){
    lint a,b,c,d;cin>>a>>b>>c>>d;
    lint x=(a-c-1)/b+1;
    if(d<b)return false;
    if(gcd(b,d)==1){
        lint mn=min(a,c+1);
        return mn>=b;
    }
    else{
        lint buf=a-x*b;
        if(buf<0)return false;
        lint y=(c-buf)/gcd(b,d)+1;
        lint mn=min(a,buf+y*gcd(b,d));
        return mn>=b;
    }
}
signed main(){  
  int t;cin>>t;
  vector<bool> res(t);
  rep(i,t){
      res[i]=solve();
  }
  rep(i,t){
      	if(res[i]){
              cout<<"Yes"<<endl;
          }
          else{
              cout<<"No"<<endl;
          } 
  }
  return 0;
}

Measured memory_bytes: 3516
#include<stdio.h>

int main(){
    int n, a, b, ii, temp=0;
    long long int sum=0;
    scanf("%d %d %d", &n, &a, &b);
    for (int i=1 ; i<=n ; i++){
        ii=i;
        temp=0;
        while(ii>0){
            temp+=ii%10;
            ii/=10;
        }
        if(temp>=a && temp<=b){
            sum+=i;
        }
    }
    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define mod 1000000007

using namespace std;
int arr[20];
struct algo{
	int cst;
	int al[20];
};

ll getval(vector<algo> v,int n,int m,int x){
	bool ans = true;
	for(int i=0;i<m;i++){
		if(arr[i] < x){
			ans =false;
			break;
		}
	}
	if(ans) return 0;
	if(n == 0){
		return INT_MAX;
	}
	ll ans1 = getval(v,n-1,m,x);
	for(int i=0;i<m;i++){
		arr[i] += v[n-1].al[i];
	}	
	ll ans2 = v[n-1].cst + getval(v,n-1,m,x);
	for(int i=0;i<m;i++){
		arr[i] -= v[n-1].al[i];
	}
	return min(ans1,ans2);
}

int solve(){
	int n,m,x;
	cin>>n>>m>>x;
	vector<algo> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i].cst;
		for(int j=0;j<m;j++){
			cin>>v[i].al[j];
			arr[i]=0;
		}
	}

	ll answ =  getval(v,n,m,x);
	if(answ == INT_MAX) return -1;
	return answ;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	std::ios::sync_with_stdio(false);
	cout<<solve();
	return 0;
}

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

class Cube
{
  public:
	  int f[6];
	  Cube (){}
	  void roll_z()
	  {
		  roll(1, 2, 4, 3);
	  }
	  void roll_y()
	  {
		  roll(0, 2, 5, 3);
	  }
	  void roll_x()
	  {
		  roll(0, 1, 5, 4);
	  }
	  void roll(int i, int j, int k, int l)
	  {
		  int t = f[i];
		  f[i] = f[j];
		  f[j] = f[k];
		  f[k] = f[l];
		  f[l] = t;
	  }
};

bool eq( Cube c1, Cube c2 )
{
	for ( int i = 0; i < 6; i++)
	{
		if ( c1.f[i] != c2.f[i] )
		{
			return false;
		}
	}
	return true;
}

bool equal( Cube c1, Cube c2 )
{
	for ( int i = 0; i < 6; i++)
	{
		for ( int j = 0; j < 4; j++)
		{
			if ( eq(c1, c2) )
			{
				return true;
			}
			else 
			{
			c1.roll_z();
			}
		}
		if ( i % 2 == 0 )
		{
			c1.roll_y();
		}
		else
		{
			c1.roll_x();
		}
	}
		return false;
	}

int main()
{
    Cube c1;
	Cube c2;
	
	for ( int i = 0; i < 6; i++ )
	{
		cin >> c1.f[i];
	}

	for ( int i = 0; i < 6; i++ )
	{
		cin >> c2.f[i];
	}

	if ( equal(c1,c2) )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3136
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
    	FastScanner sc = new FastScanner(System.in);
    	int N = sc.nextInt();
    	int M = sc.nextInt();
    	String[] matrix = new String[N];
    	for(int i = 0; i < N; ++i)
    		matrix[i] = sc.nextString();
    	boolean[] row = new boolean[N];
    	boolean[] col = new boolean[M];
    	for(int i = 0; i < N; ++i) {
    		for(int j = 0; j < M; ++j) {
    			if(matrix[i].charAt(j) == '#') {
    				row[i] = col[j] = true;
    			}
    		}
    	}
    	for(int i = 0; i < N; ++i) {
    		if(!row[i])
    			continue;
    		for(int j = 0; j < M; ++j) {
    			if(col[j])
    				System.out.print(matrix[i].charAt(j));
    		}
    		System.out.print('\n');
    	}
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;
    boolean hasNext;

    public FastScanner(InputStream is) {
        br = new BufferedReader(new InputStreamReader(is));
        hasNext = true;
    }

    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                hasNext = false;
                return "##";
            }
        }
        return st.nextToken();
    }

    String next = null;
    public boolean hasNext(){
        next = nextToken();
        return hasNext;
    }

    public int nextInt() {
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return Integer.parseInt(more);
    }

    public long nextLong() {
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return Long.parseLong(more);
    }

    public double nextDouble() {
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return Double.parseDouble(more);
    }

    public String nextString(){
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return more;
    }

    public char nextChar(){
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return more.charAt(0);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
#define EPS 1e-5
#define all(a) (a).begin(),(a).end()
#define INTCEIL(a, b) ((a + (b - 1)) / b)
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;


int main() {
	cin >> N >> K;
	N %= K;
	cout << min(N, K - N) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int>S(m);
  vector<int>C(m);
  for (int i=0; i<m; i++) cin>>S[i]>>C[i];
  for (int i=0; i<1000; i++){
    bool jud = true;
    string st = to_string(i);
    if (st.size() != n)  jud = false;
    for (int j=0; j<m; j++){
      //cout << st[S[j]-1] <<","<< c << endl;
      if (st[S[j]-1] != (char)(C[j]+'0')) jud = false;
    }
    if (jud){
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}

Measured memory_bytes: 3696