akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
  args = input.split('\n')
  const square = []
  for(var i = 0; i < 3; i++){
    square[i] = args[i].split(' ')
  }
  
  const count = args[3]
  const nums = []
  for(var i = 0; i < count; i++){
    nums.push(args[i + 4])
  }
  
  // 印をつける
  const results = []
  for(var i = 0; i < 3; i++){
    results.push([0, 0, 0])
  }
  for(var i = 0; i < 3; i++){
    for(var j = 0; j < 3; j++){
      for(var k = 0; k < nums.length; k++){
        if(square[i][j] === nums[k]) {
          results[i][j] = 1
        }
      }
    }
  }
  
  // ビンゴかどうかをチェック
  var bingoCount = 0
  var checkedCountAngleRight = 0
  var checkedCountAngleLeft = 0
  for(var i = 0; i < 3; i++) {
    var checkedCountHorizontal = 0
    var checkedCountVertical = 0
    for(var j = 0; j < 3; j++) {
      // ヨコ
      if(results[i][j]) checkedCountHorizontal++
      // タテ
      if(results[j][i]) checkedCountVertical++
    }
    // 右ナナメ
    if(results[i][i]) {
      checkedCountAngleRight++
    }
    // 左ナナメ
    if(results[i][2-i]) {
      checkedCountAngleLeft++
    }
    
    if(checkedCountHorizontal === 3) {
      bingoCount++
    }
    if(checkedCountVertical === 3) {
      bingoCount++
    }
  }
  if(checkedCountAngleRight === 3) {
    bingoCount++
  }
  if(checkedCountAngleLeft === 3) {
    bingoCount++
  }
  if(bingoCount) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

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


Measured memory_bytes: 26052
function find_sum_of_digits(n::Int)
    sum = 0
    while n > 0
        sum += n % 10
        
        n -= n % 10
        n /= 10
    end

    return sum
end

function main()
    (N, A, B) = map(x -> parse(Int, x), split(readline()))

    total = 0
    for i = 1:N
        sum = find_sum_of_digits(i)
        if A <= sum <= B
            total += i
        end
    end

    println(total)
end

main()

Measured memory_bytes: 114072
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#define INF 100000000000000
using namespace std;

typedef struct _FLOOR{
    long long room[10];
}FLOOR;

int main() {
    long long n;
    long long b,f,r,v;
    FLOOR A[4][3];
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                A[i][j].room[k] = 0;
            }
        }
    }
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> b >> f >> r >> v;
        A[b-1][f-1].room[r-1] += v;
    }
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<9; k++){
                cout << " "<< A[i][j].room[k];
            }
            cout << " " << A[i][j].room[9] << endl;
        }
        if(i<=2){
            cout << "####################" << endl;
        }
    }
}


Measured memory_bytes: 3104
#include<stdio.h>
#define MAX 100
#define INF 1e8
#define WHITE 0
#define GRAY  1
#define BLACK 2

int n,M[MAX][MAX];

void dijkstra(){
  int color[MAX],d[MAX],p[MAX],min,u;
  int i,j,v;

  for(i=0;i<n;i++){
    color[i] = WHITE;
    d[i] = INF;
  }
  d[0] = 0;
  p[0] = -1;

  while(1){
    min = INF;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<min){
	min = d[i];
	u = i;
      }
    }

    if(min == INF) break;
    color[u] = BLACK;

    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INF){
	if(d[u]+M[u][v] < d[v]){
	  d[v] = d[u] + M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    } 
  }

  for(i=0;i<n;i++) printf("%d %d\n",i,(d[i]==INF ? -1: d[i]));
}

int main(){
  int u,k,v,c;
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++) for(j=0;j<n;j++) M[i][j]=INF;
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      scanf("%d",&M[u][v]);
    }
  }
  dijkstra();
  
  return 0;
}



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

int main(){

  int N;
  int i = 0;
  cin >> N;
  string color;

  while (i < N){
    cin >> color;
    if (color == "Y"){
      cout << "Four" << endl;
      break;
    }
    i++;
    
    if (i == N){
      cout << "Three"<< endl;
    }
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    //sort(v.begin(),v.end());
    int ans = 0;
    FOR(i,0,n){
        FOR(j,i + 1,n){
            FOR(k,j + 1,n){
                if(v[i] != v[j] && v[j] != v[k] && v[i] != v[k]){
                    vector<ll> check;
                    check.push_back(v[i]);
                    check.push_back(v[j]);
                    check.push_back(v[k]);
                    sort(check.begin(),check.end());
                    if(check[0] + check[1] > check[2] ){
                        // cout << i + 1 << " " << j + 1 << " " << k + 1 << endl;
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>     
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int H,W,K;
ll Ans=0;

int gcd(int a,int b){
	if(!b)return a;
	return gcd(b,a%b);
}

inline void solve(){
	for(int s=0;s<=min(H-2,2*K+W-2);++s)
	    for(int x=1;x<W&&x*s<=2*K+W-2;++x){
	    	int R=2*K+gcd(s,W)-s*x-2;
	    	int tmp=min(R/W,H-s-1);
	    	if(tmp>0){
	    		if(s==0)Ans+=2ll*tmp;
	    		else Ans+=4ll*tmp;
			}
	    	int yy=(R/W)+1;
	    	if(yy>=H-s)continue;
	    	if(1ll*W*yy-gcd(x,yy)-gcd(W-x,yy+s)<=R){
	    		if(s==0)Ans+=2;
	    		else Ans+=4;
			}
		}
}

inline void rd(int &x){
	x=0;char ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
}

int main(){
	rd(W);rd(H);rd(K);
	solve();
	swap(W,H);
	solve();
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

const ll K = 40;
ll a, b;

ll f(ll k) {
	ll ret = ((k/2)%2 ? 1 : 0);
	ll m = 2;
	for(int i=0; i<K; ++i) {
		ll p = k / m;
		ll q = k % m;
		if(p % 2 && q % 2) {
			ret += m;
		}
		m = m*2;
	}
	return ret;
}


int main(void) {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("in.txt", "r", stdin);
	ll a, b;
	cin >> a >> b;
	cout << (f(b+1)^f(a)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int a, b, x;
  cin >> a >> b>> x;
  if(a <= x && x <= a + b )cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
from bisect import bisect_right
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(m)]
l2 = sorted(l,key = lambda x:(x[0],x[1]))
t = [[] for _ in range(n)]

for p,y in l2:
    t[p-1].append(y)
    
for i in l:
    order = bisect_right(t[i[0]-1],i[1])
    print(str(i[0]).zfill(6)+str(order).zfill(6))


Measured memory_bytes: 35212
#include <iostream>

using namespace std;
int selectionSort(int a[], int n){
    int s, m, flag;
    s = 0;
    for (int i = 0; i < n; i++){
        m = a[i];
        flag = i;
        for (int j = i+1; j < n; ++j){
            if (a[j] < m){
                m = a[j];
                flag = j;
            }
        }
        if (i != flag){
            swap(a[i], a[flag]);
            s++;
        }
    }
    return s;
}
int main()
{
    int n;
    int a[100];
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    int s = selectionSort(a, n);
    for (int i = 0; i < n; ++i){
        if (i != n-1)
            cout << a[i] << " ";
        else
            cout << a[i] << endl;
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 3092
/**
 *    author:  FromDihPout
 *    created: 2020-05-30
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long n;
    cin >> n;
    if (n & 1) {
        cout << 0 << '\n';
    }
    else {
        long long cnt = 0, denom = 10;
        while (denom <= n) {
            cnt += n / denom;
            denom *= 5;
        }
        cout << cnt << '\n';
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define N               100005
#define ff              first
#define ss              second
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void fio(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

ll dp[405][405], a[405], sum[405][405];

void cSum(ll n){

    for(ll x=1;x<=n;x++){
        ll s = 0;
        for(ll y=x;y<=n;y++){
            s += a[y];
            sum[x][y] = s;
        }
    }

}

ll f(ll i, ll j){

    if(i == j) return 0;

    if(dp[i][j] != -1) return dp[i][j];

    dp[i][j] = inf;
    for(ll k=i;k<j;k++){
        dp[i][j] = min(dp[i][j], f(i,k) + f(k+1,j) + sum[i][k] + sum[k+1][j]);
    }

    return dp[i][j];
}

int main(){
    fio();

    ll n;
    cin>>n;

    for(ll z=1;z<=n;z++) cin>>a[z];

    memset(dp, -1, sizeof dp);
    cSum(n);
    cout<<f(1,n);

    return 0;
}

Measured memory_bytes: 6168
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var str = lines[0];
 str = str.replace(/[^ACGT]+/g, '-');
 var max = [];
 var a = str.split('-');
 for(i=0; i<a.length; i++){
   max.push(a[i].length);
 }
  console.log(Math.max(...max));
});

Measured memory_bytes: 7756
#include <iostream>
#include <cstdio>
#include <cctype> // for isdigit
#include <string>
using namespace std;
// ?§?????§£??????????????°????????§?????¢??°???????????????????????£?¨????????????¨
int exp(string s, int &i);
int term(string s, int &i);
int factor(string s, int &i);
int number(string s, int &i);
int exp(string s, int &i)
{
  int val = term(s, i);
  while(s[i] == '+' || s[i] == '-'){ // 0 ?????\?????°?????????????????¨???????????????
    char op = s[i];
    i++;
    int val2 = term(s, i);
    if(op == '+') val += val2;
    else val -= val2;
  }
  return val;
}
int term(string s, int &i)
{
  int val = factor(s, i);
  while(s[i] == '*' || s[i] == '/'){ // 0 ?????\?????°?????????????????¨???????????????
    char op = s[i];
    i++;
    int val2 = factor(s, i);
    if(op == '*') val *= val2;
    else val /= val2;
  }
  return val;
}
int factor(string s, int &i)
{
  // ??????????????????????????°????????´???
  // isdigit ?????¢??????????????\????¬????????????????????????§???????????¨
  if(isdigit(s[i]))
    return number(s, i);
  // ??°?????§???????????´??????????????§?§?????????£???????????°???????????????'(' ??¨??????
  i++; // '(' ??????????£???°???
  int val = exp(s, i);
  i++; // ')' ??????????£???°???
  return val;
}
int number(string s, int &i)
{
  // ??°??????1 ????????¨???
  int n = s[i] - '0';
  i++;
  // ??°??????2 ?????\????????¨???
  while(isdigit(s[i])){
    n = n * 10 + (s[i] - '0');
    i++;
  }
  return n;
}
int main()
{
  int n;
  cin >> n;
  for(int j = 0; j < n; ++j){
    string s;
    cin >> s;
    int i = 0;
    cout << exp(s, i) << endl;
  }
}

Measured memory_bytes: 1216
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        s: Chars,
    }
    let mut r = 0;
    let mut g = 0;
    let mut b = 0;
    for c in s.iter() {
        match c {
            'R' => r += 1,
            'G' => g += 1,
            'B' => b += 1,
            _ => (),
        }
    }

    let mut cnt: usize = r * g * b;
    for l in 1..n {
        for i in 0..n {
            let j = i + l;
            let k = i + l * 2;
            if k > n - 1 {
                break;
            }

            if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] {
                cnt -= 1;
            }
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 2204
n=int(input())
S=list(input())
W,B=[0]*(n+1),[0]*(n+1)
for i in range(n):
    if S[i]=='.':
        W[i+1]=W[i]+1
        B[i+1]=B[i]
    else:
        W[i+1]=W[i]
        B[i+1]=B[i]+1
ans=float('inf')
for i in range(n+1):
    w=W[i]
    b=B[-1]-B[i]
    tmp=n-w-b
    ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 14180
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll a, b, c;
    cin >> a >> b >> c;

    bool ans(false);
    for (int i=1; i<100; i++)
    {
        ll res = a*i % b;
        ans = (res == c);
        if (ans) break;
    }

    if (ans)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque
S = deque(str(input()))
Q = int(input())
count = 0
for i in range(Q):
    tmp = list(input().split())
    if tmp[0]=="1":
        count += 1
    else:
        if tmp[1]=="1" and count%2==0 or tmp[1]=="2" and count%2==1:
            S.appendleft(tmp[2])
        elif tmp[1]=="2" and count%2==0 or tmp[1]=="1" and count%2==1:
            S.append(tmp[2])
if count%2==0:
    ans = "".join(S)
    print(ans)
else: 
    S.reverse()
    ans = "".join(S)
    print(ans)

Measured memory_bytes: 8692
N, Y = gets.chomp.split.map(&:to_i)

a, b, c = -1, -1, -1

(N+1).times do |i|
  (N+1).times do |j|
    if 10000*i + 5000*j + (N-i-j)*1000 == Y && N-i-j >= 0
      a, b, c = i, j, (N-i-j)
    end
  end
end

puts "#{a} #{b} #{c}"


Measured memory_bytes: 1788
#include<cstdio>
int n,m,c,a[25],b[25],res;
int main(){
	scanf("%d%d%d",&n,&m,&c);
	for(int i=1;i<=m;++i)scanf("%d",b+i);
	for(int j=1;j<=n;++j){
		for(int i=1;i<=m;++i)scanf("%d",a+i);
		int ans=c;
		for(int i=1;i<=m;++i)ans+=a[i]*b[i];
		if(ans>0)++res;
	}
	printf("%d\n",res);
	return 0; 
}

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

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

    int n; cin >> n;
    unordered_map<int, int> um;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        um[a]++;
    }

    int res = 0;
    for (auto item : um) {
        if (item.second % 2 != 0) {
            ++res;
        }
    }

    cout << res << endl;

}

Measured memory_bytes: 4388
#include <iostream>
#include <utility>

int main()
{
	int a, b, c, x;
	std::cin >> a >> b >> c >> x;
	
	int comb = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (i * 500 + j * 100 + k * 50 == x) {
					comb++;
				}
			}
		}
	}
	
	std::cout << comb << std::endl;
	
	return 0;
}


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

typedef long long int llint;

int main(){
	int N,D;
	cin >> N >> D;
	int X[N][D];
	for(int i=0;i<N;i++){
		for(int k=0;k<D;k++){
			cin >> X[i][k];
		}
	}
	
	int cnt=0;
	for(int i=0;i<N-1;i++){
		for(int k=i+1;k<N;k++){
			double dist=0;
			for(int d=0;d<D;d++){
				dist+=pow(X[i][d]-X[k][d],2);
			}
			dist=sqrt(dist);
			if(floor(dist)==dist){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        int K = sc.nextInt();
        System.out.println(Integer.toString(N, K).length());
    }

    public static void main(String[] args) {
        new Main();
    }
}


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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, k, cnt = 0;
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for(int i = 1; i <= n; i++) {
    cnt += max(i - k, (ll)0) * (n / i);
    cnt += max((ll)0, n % i - k + 1);
  }
  cout << cnt << endl;
	return 0;
}

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

int main() {
    int r, D, x; cin >> r >> D >> x;

    for(int i=0; i<10; i++){
        x = r*x - D;
        cout << x << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int w,d;
int hf[100],hs[100];


int main(){   

    while(1){
        scanf("%d%d",&w,&d);
        if(w == 0 && d == 0)
            break;

        for(int i = 0;i < w;i++)
            scanf("%d",&hf[i]);
        for(int i = 0;i < d;i++)
            scanf("%d",&hs[i]);

        bool usef[100],uses[100];

        for(int i = 0;i < 100;i++)
            usef[i] = uses[i] = true;

        int ans = 0;
        for(int i = 0;i < w;i++)
            ans += hf[i];
        for(int i = 0;i < d;i++)
            ans += hs[i];

        for(int i = 0;i < w;i++){
            for(int j = 0;j < d;j++){
                if(hf[i] == hs[j] && usef[i] && uses[j]){
                    ans -= hf[i];
                    usef[i] = uses[j] = false;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 3180
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())
    if (A < B) or (D < B):
        print('No')
        continue
    elif (C+1 >= B):
        print('Yes')
        continue
    else:
        s_res = A % B
        s_k = int((C + 1 - s_res - 0.1) // B + 1)
        X = gcd(B, (D%B))
        if X == 1:
            print('No')
            continue
        else:
            s_0 = s_k * B + s_res
            if (s_0 - (C+1)) % X > (B-C-2):
                print('Yes')
            else:
                print('No')



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

int main() {
  int N;
  string str;
  cin >> N >> str;
  int x = 0;
  int maxX = 0; 
  for (int i = 0; i < N; i ++){
    if (str[i] == 'I'){
      x ++;
      maxX = max (maxX, x);
    } else {
      x --;
      maxX = max (maxX, x);
    }
  }
  cout << maxX << '\n';
}

Measured memory_bytes: 3108
N, M = map(int, input().split())
a = [False] * (N+1)
for i in range(M):
    a[int(input())] = True
 
memo = [None] * (N+1)
memo[0] = 1 #0番目にたどり着く方法は1通りと定義する。
memo[1] = 1 if not a[1] else 0
 
for i in range(2, N+1):
    memo[i] = memo[i-1] + memo[i-2] if not a[i] else 0
 
print(memo[N] % 1000000007)

Measured memory_bytes: 460788
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define LL  long long 
#define Pi 3.14159265358979;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	vector<char> t;
	int a, b;
	int d=0,i = 0, j = 0, run=0;
	int ans;
	
	cin >> a >> b;
	
	ans = a * b;

	cout << ans <<"\n";
	
}


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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int a, b; cin >> a >> b;

    if(a <= 0 && 0 <= b){
        cout << "Zero" << endl;
    }
    else if (0 < a){
        cout << "Positive" << endl;
    }
    else {
        int num = b - a + 1;
        if (num % 2 == 0) {
            cout << "Positive" << endl;
        }
        else{
            cout << "Negative" << endl;
        }
    }

    return 0;
}


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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));
void recursive_comb(int *indexes, int s, int rest,
                    std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

vector<int> vec;

int ans = 0;

int nn;

int main() {
  cin >> nn;

  int buf;
  rep(i, nn) {
    cin >> buf;
    vec.push_back(buf);
  }

  foreach_comb(nn, 3, [](int *indexes) {
    int a = vec[indexes[0]];
    int b = vec[indexes[1]];
    int c = vec[indexes[2]];
    if (a != b && b != c && c != a && a + b > c && b + c > a && c + a > b) {
      //cout << "A" << endl;
      ans++;
    }
    // std::cout << indexes[0] << ',' << indexes[1] << ',' << indexes[2] <<
    // std::endl;
  });

  cout << ans;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
using namespace std;
#define NIL -2000000001
#define MAX 10000000

int main() {
  long long n;
  scanf("%lld", &n);
  long long oldn= n;
  long long a[1000];
  long long count=0, div=-2;
  for (; n!=0; count++) {
    if (n%div == 0) {
      a[count] = 0;
    } else {
      a[count] = 1;
    }
    n -= (div)/(-2)*a[count];
    div *= -2;
  }
  bool flag = true;
  for (long long i=0; i<=count; i++) {
    if (oldn != 0 && flag && a[count-i] == 0) {
      continue;
    }
    flag = false;
    if (a[count-i] == 0) {
      printf("0");
    } else {
      printf("1");
    }
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ld double
#define ll long long
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
#define fi first
#define se second
#define sync  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf (ll)1e16

const ld pi=(4.0*atan(1));

int main() {
    
    sync
    ll tt=1;
    //cin>>tt;
    cout<<fixed<<setprecision(12);
    for (ll tc=1;tc<=tt;tc++){
        ll a,b,h,m;
        cin>>a>>b>>h>>m;
        
        ld hr=(ld)a,mn=(ld)b;
        
        ld w1=0.5,w2=6.0;
        ld ti=(h*60+m),deg1=(ti*w1),deg2=(ld)(((ll)ti*(ll)w2)%360);
        ld rad;
        
        if (deg1==deg2){
            cout<<abs(hr-mn)<<"\n";
        }
        else if (abs(deg1-deg2)==180.0){
            cout<<hr+mn<<"\n";
        }
        else{
            rad=(pi*(360.0-abs(deg2-deg1)))/180.0;
            
            ld dis=0.0;
            ld per=min(hr,mn)*sin(rad),par=max(hr,mn)-min(hr,mn)*cos(rad);
            dis=sqrt(per*per+par*par);
            cout<<dis<<"\n";
        }
        
    }
    
	return 0;
}

Measured memory_bytes: 4112
import java.util.Scanner;
public 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();
		int d = sc.nextInt();
		int sumL, sumR;
		sumL = a + b;
		sumR = c + d;
		if(sumL > sumR) {
			System.out.println("Left");
		}else if(sumL < sumR) {
			System.out.println("Right");
		}else {
			System.out.println("Balanced");
		}
	}
}


Measured memory_bytes: 23764
s = input()
s_X = list(s.replace("BC", "X"))

A_count = 0
ans = 0
for i in range(len(s_X)):
    if s_X[i] == "A":
        A_count += 1
    elif s_X[i] == "X":
        ans += A_count
    else:
        A_count = 0

print(ans)


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

int main()
{
    int n,id=1,ans[100];
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>ans[i];
        if(abs(ans[i])>abs(ans[id])) id=i;
    }
    cout<<2*n-1<<endl;
    for(int i=1;i<=n;i++) cout<<id<<" "<<i<<endl;
    if(ans[id]>0) for(int i=1;i<n;i++) cout<<i<<" "<<i+1<<endl;
    else for(int i=n;i>1;i--) cout<<i<<" "<<i-1<<endl;
    return 0;
}


Measured memory_bytes: 256
A = list(input())
B = list(input())
C = [a for a in input()]

x = A.pop(0) 
while True:  
  if x == "a":
    if len(A) == 0:      
      print("A")
      exit()
    x = A.pop(0)    
  elif x == "b":
    if len(B) == 0:
      print("B")
      exit()      
    x = B.pop(0)    
  elif x == "c":
    if len(C) == 0:
      print("C")
      exit()   
    x = C.pop(0)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;++i)cin>>a[i];
  vector<int> sum(n+1);
  sum[0]=0;
  for(int i=0;i<n;++i)sum[i+1]=sum[i]+a[i];
  sort(sum.begin(),sum.end());
  int ans=0,cnt=1;
  for(int i=0;i<=n;++i){
    if(sum[i]==sum[i-1])cnt++;
    else{
      ans+=cnt*(cnt-1)/2;
      cnt=1;
    }
  }
  ans+=cnt*(cnt-1)/2;
  cout<<ans<<endl;
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define bzero(p, n) memset(p, 0, n)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N, M; cin >>N>>M;

    int t = 1900 * M + 100 * (N-M);
    int X = t * powi(2, M);

    cout << X << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int main(void) {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep (i, h) cin >> s[i];

    vector<vector<int>> grid(h, vector<int>(w, INF));

    if (s[0][0] == '.') grid[0][0] = 0;
    else grid[0][0] = 1;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            rep (k, 2) {
                int y = i + dy[k];
                int x = j + dx[k];
                if (0 <= x && x < w && 0 <= y && y < h) {
                    if (s[i][j] == s[y][x] || s[i][j] == '.') chmin(grid[i][j], grid[y][x]);
                    else chmin(grid[i][j], grid[y][x] + 1);
                }
            }
        }
    }

    //cout << grid[0][0] << endl;
    cout << grid[h - 1][w - 1] << endl;
    /*
    rep (i, h) {
        rep (j, w) cout << grid[i][j] << " ";
        cout << endl;
    }
    */
    
    return 0;
}


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

void main_()
{
    string S;
    cin >> S;
    ll K;
    cin >> K;

    if (S.find_first_not_of(S.front()) == string::npos) {
        // 1種しか文字が無い場合
        cout << S.size() * K / 2 << "\n";
        return;
    }

    ll ans = 0;
    ll same = 1;
    for (ll i = 1; i <= (ll)S.size(); ++i) {
        if (i < S.size() && S[i] == S[i - 1]) {
            same++;
        } else {
            // same文字連続を異なるようにする
            // (連続してない(same=1)のときはansは増えない)
            ans += (same / 2);
            same = 1;
        }
    }

    // K回繰り返し
    ans *= K;

    if (S.front() == S.back()) {
        // 先頭と末尾が同じ文字で連続する場合、上で計算された先頭と末尾の連続分を引いた後、つなげた長さで足す
        auto first_same = S.find_first_not_of(S.front());
        auto last_same = S.size() - S.find_last_not_of(S.back()) - 1;
        ans -= (K - 1) * (first_same / 2);
        ans -= (K - 1) * (last_same / 2);
        ans += (K - 1) * ((first_same + last_same) / 2);
    }

    cout << ans << "\n";
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

using namespace std;

#define MAX_V 114
#define INF 1e9

int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];
int V;

int prim(){
  for(int i = 0 ; i < V ; i++){
    mincost[i] = INF;
    used[i] = false;
  }
  mincost[0] = 0;
  int res = 0;
  
  while(true){
    int v = -1;
  
    for(int u = 0 ; u < V ; u++){
      if(!used[u] && (v == -1 || mincost[u] < mincost[v])){
        v = u;
      }
    }
    if(v == -1){ break; }
    used[v] = true;        
    res += mincost[v];     

    for(int u = 0 ; u < V ; u++){
      mincost[u] = min(mincost[u],cost[v][u]);
    }
  }
  return res;
}

int main(){
  int E,s,t,w;
  while(cin >> V >> E,V){
    for(int i = 0 ; i < V ; i++){
      for(int j = 0 ; j < V ; j++){
        cost[i][j] = INF;
      }
    }
    for(int i = 0 ; i < E ; i++){
      cin >> s >> t >> w;
      cost[s][t] = cost[t][s] = w;
    }
    cout << prim() << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 998244353LL;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    V<int> c(n);
    for (int i = 1; i < n; i++) {
        int a;
        cin >> a;
        --a;
        c[a]++;
    }
    for (int i = 0; i < n; i++) {
        cout << c[i] << '\n';
    }
}

Measured memory_bytes: 3980
from itertools import permutations as perm
n = int(input())
cities = [list(map(int, input().split())) for _ in range(n)]
perms = list(range(n))
res=[]
for p in perm(perms):
    tmp=0
    for i in range(1,n):
       tmp+=((cities[p[i]][0]-cities[p[i-1]][0])**2+(cities[p[i]][1]-cities[p[i-1]][1])**2)**(1/2)
    res.append(tmp)
print(sum(res)/len(res))

Measured memory_bytes: 10720
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        while(r>=g) {
            g*=2;
            k--;
        }
        while(g>=b) {
            b*=2;
            k--;
        }
        if(k>=0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }



}

Measured memory_bytes: 35660
#include<bits/stdc++.h>
using namespace std;
vector<pair<int ,int> >v;
int main()
{
    long long t,k,n,c,x,p,in,fn,flag;
    string s;
    cin>>n>>k;
    cin>>s;
    in=0;
    flag=0;
    //n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1')
        {
            flag=1;
            if(i==n-1)
            {
                //cout<<in<<" "<<i<<endl;
            v.push_back({in,i});

            }
            continue;
        }
        else
        {
            if(!flag)

            {
                in=i+1;
                continue;
            }
            else{
                //cout<<in<<" "<<i-1<<endl;
            v.push_back({in,i-1});
            flag=0;
            in=i+1;
            }

        }
    }
    long long  ip,next,sz=v.size(),ans=INT_MIN;
    if(sz==0)
    {
        cout<<n;
        return 0;
    }

    if(count(s.begin(),s.end(),'1')==n)
    {
        cout<<n;
        return 0;
    }
    if(v[0].first!=0)
    {

        fn=v[k-1].second;
        ans=fn+1;
        //cout<<0<<" "<<fn<<" "<<ans<<endl;
    }

    for(int i=0;i<sz-k;i++)
    {
        in=v[i].first;
        fn=v[i+k].second;
        //cout<<in<<" "<<fn<<" "<<fn-in<<endl;
        ans=max(ans,(fn-in+1));
    }
    if(v[sz-1].second!=n-1)
    {
        in=v[sz-k].first;
        fn=n;
        //cout<<in<<" "<<fn<<" "<<fn-in<<endl;
        ans=max(ans,(fn-in));
    }

    if(k>sz )
    {
        cout<<n;
        return 0;
    }



    cout<<ans;



}




Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll n;cin >> n;
    ll m=0;
    while(m*(m-1)/2<n) m++;
    if(m*(m-1)/2!=n){
        cout << "No" << endl;
        return 0;
    }
    vl ans[m+1];
    ll num=1;
    for(int i=1;i<=m;i++){
        for(int j=i+1;j<=m;j++){
            ans[i].push_back(num);
            ans[j].push_back(num);
            num++;
        }
    }
    cout << "Yes" << endl;
    cout << m << endl;
    for(int i=1;i<=m;i++){
        cout << (int)ans[i].size() << " ";
        for(auto x: ans[i]){
            cout << x << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		List<P> list = new ArrayList<P>();	
		for (int i=0; i<N; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (2<=a-1 && a-1<H && 2<=b-1 && b-1<W) list.add(new P(a-1, b-1));
			if (2<=a   && a  <H && 2<=b-1 && b-1<W) list.add(new P(a  , b-1));
			if (2<=a+1 && a+1<H && 2<=b-1 && b-1<W) list.add(new P(a+1, b-1));
			if (2<=a-1 && a-1<H && 2<=b   && b  <W) list.add(new P(a-1, b  ));
			if (2<=a   && a  <H && 2<=b   && b  <W) list.add(new P(a  , b  ));
			if (2<=a+1 && a+1<H && 2<=b   && b  <W) list.add(new P(a+1, b  ));
			if (2<=a-1 && a-1<H && 2<=b+1 && b+1<W) list.add(new P(a-1, b+1));
			if (2<=a   && a  <H && 2<=b+1 && b+1<W) list.add(new P(a  , b+1));
			if (2<=a+1 && a+1<H && 2<=b+1 && b+1<W) list.add(new P(a+1, b+1));
		}
		Collections.sort(list);
		//
		int[] cnt = new int[10];
		int c = 0;
		P q = null;
		for (P p: list) {
			if (c==0) {
				c++;
				q = p;
				continue;
			}
			if (p.equals(q)) {
				c++;
			} else {
				cnt[c]++;
				c = 1;
				q = p;
			}
		}
		if (c!=0) cnt[c]++;
		System.out.println(((long)H-2)*((long)W-2)-array_sum(cnt));
		for (int i=1; i<10; i++) {
			System.out.println(cnt[i]);
		}
		//
		sc.close();
	}
	
	private static long array_sum(int[] array) {
		int sum = 0;
		for (int a: array) sum+=a;
		return sum;
	}

	private static class P implements Comparable<P> {
		private final int v1;
		private final int v2;
		public P(int v1, int v2) {
			this.v1 = v1;
			this.v2 = v2;
		}
		public int x() { return v1; }
		public int y() { return v2; }
		@Override public int compareTo(P o) {
			if (v1!=o.v1) return Integer.compare(v1, o.v1);
			return Integer.compare(v2, o.v2);
		}
		@Override public int hashCode() {
			int result = 17;
			result += 31*result + v1;
			result += 31*result + v2;
			return result;
		}
		@Override public boolean equals(Object o) {
			if (!(o instanceof P)) return false;
			P p = (P)o;
			if (v1!=p.v1) return false;
			if (v2!=p.v2) return false;
			return true;
		}
		@Override public String toString() {
			return String.format("{%d, %d}", v1, v2);
		}
	}

	
}


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

int main() {
    // freopen("number.in", "r", stdin);
    // freopen("number.out", "w", stdout);
    int sum = 0;
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int x;
        cin >> x;
        sum += x;
    }
    cout << max(n - sum, -1) << endl; 
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

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

	int a, b;
	cin >> a >> b;
	if (a == 2 || b == 2)
		cout << "No\n";
	else
		cout << "Yes\n";

	return 0;
}

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORD(i, m, n) for (int i = m; i >= n; i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 0; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	double n;
	cin>>n;
	int ans=n*100/108;
	while (ans<=n)
	{
		if(ans*108/100==n){
			cout<<ans<<endl;
			exit(0);
		}
		ans++;
	}
	cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 3724
#include <stdio.h>

int main(void)
{
  int x, y, i, j;
  int hanako[101],taro[101],hsum,tsum, min = 1000, anstaro, anshanako;

  while(1){
    scanf("%d %d",&x, &y);
    hsum = 0;
    tsum = 0;
    min = 1000;
    if(x == 0 && y == 0){
      break;
    }
    tsum = 0;
    for(i = 0 ; i < x ; i++){
      scanf("%d",&taro[i]);
      tsum += taro[i];
    }
    for(i = 0 ; i < y ; i++){
      scanf("%d",&hanako[i]);
      hsum += hanako[i];
    }

    for(i = 0 ; i < x ; i++){
      for(j = 0 ; j < y ; j++){
	if(tsum - taro[i] + hanako[j] == hsum - hanako[j] + taro[i]){
	  if(taro[i]+hanako[j] < min){
	    min = taro[i] + hanako[j];
	    anstaro = taro[i];
	    anshanako = hanako[j];
	  }
	}
      }
    }
    if(min == 1000){
      printf("-1\n");
    }
    else{
      printf("%d %d\n",anstaro,anshanako);
    }
  }
  return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include<string>
using namespace std;
#define REP(i,n) for(int i=2;i<n;i++)
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	
	string s;
	cin>>s;
	int y=100000;
	REP(i,s.size()){
	int x=s[i]-48;
	int k=s[i-1]-48;
	int v=s[i-2]-48;
	int t=v*100+k*10+x;
		t=abs(753-t);
		y=min(y,t);
	}
	cout<<y<<endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
# encoding: utf-8

# ABC 109 B Shiritori
# input
n = gets.to_i
w = Array.new(n,"")
(0..n-1).each do |i|
  w[i] = gets.chomp
end

# true:"Yes",false:"No"
ans = true

(1..n-1).each do |i|
  if w[i][0] != w[i-1][-1]
    puts "No"
    exit
  end
end

(0..n).each do |i|
  (0..i-1).each do |j|
    if w[i] == w[j]
      puts "No"
      exit
    end
  end
end

puts "Yes"


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
    const int mod=1000000007;
    int n,k;
    cin>>n>>k;
    int a[n-1],b[n-1];
    vector<vector<int>>pas(n);
    for(int i=0;i<n-1;i++){
        cin>>a[i]>>b[i];
        pas[a[i]-1].push_back(b[i]-1);
        pas[b[i]-1].push_back(a[i]-1);
    }
    long long x=k;
    k--;
    queue<int>q;
    int check[n]={};
    check[0]=1;
    for(int i=0;i<pas[0].size();i++){
        q.push(pas[0][i]);
        check[pas[0][i]]=1;
        x*=(k-i);
        if(x<=0){
            cout<<"0"<<endl;
            return 0;
        }
        x%=mod;
    }
    k--;
    while(q.size()){
        int f=q.front();
        q.pop();
        for(int i=0;i<pas[f].size();i++){
            if(check[pas[f][i]]==0){
                check[pas[f][i]]=1;
                q.push(pas[f][i]);
            }
        }
        for(int i=0;i<pas[f].size()-1;i++){
            x*=(k-i);
            if(x<0){
                cout<<"0"<<endl;
                return 0;
            }
            x%=mod;
        }
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 7672
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

ll XOR(ll x){
    if(x % 4 == 3)return 0;
    ll temp = (x/4)*4;
    ll res = 0;
    rep(i,(x-temp+1)) res ^= (temp+i);
    return res;
}

int main(){
    // cout << XOR(14) << endl;
    ll a,b; cin >> a >> b;
    cout << (XOR(a-1) ^ XOR(b)) << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n,k = map(int,input().split())
    e = [[0]*(2*k+1) for i in range(2*k+1)]
    mod = 2*k
    for i in range(n):
        x,y,c = input().split()
        if c == "W":
            x = int(x)%mod
            y = (int(y)+k)%mod
        else:
            x = int(x)%mod
            y = int(y)%mod
        e[x+1][y+1] += 1
    
    for i in range(mod):
        for j in range(mod):
            e[i+1][j+1] += e[i][j+1]+e[i+1][j]-e[i][j]
    
    def count(ax,ay,bx,by):
        return e[ax][ay] +e[bx][by] - e[ax][by]-e[bx][ay]
    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            c = count(2*k,2*k,i+k,j+k)+count(2*k,j,i+k,0)+count(i,2*k,0,j+k)+count(i,j,0,0)+count(i+k,j+k,i,j)
            ans = max(ans,c,n-c)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 79196
#include <iostream>
#include <bits/stdc++.h>
#define inf 1000000007
using namespace std;

void func(vector<long> v1, vector<long> v2){
    long max1 = INT_MIN,max2 = INT_MIN,min1 = INT_MAX,min2 = INT_MAX;
    for(int i = 0; i < v1.size(); i++){
        min1 = min(min1,v1[i]);
        min2 = min(min2,v2[i]);
        max1 = max(max1,v1[i]);
        max2 = max(max2,v2[i]);
    }
    long temp = abs(max2 - min2);
    long temp2 = abs(max1 - min1);
    cout << max(temp,temp2) << endl;
}

int main() {
	int n,i,j,t;
    cin >> n;
    vector<long> v1,v2;
    for(i = 0; i < n; i++){
        cin >> j >> t;
        v1.push_back(j+t);
        v2.push_back(j-t);
    }
    func(v1,v2);
    return 0;
}


Measured memory_bytes: 9484