akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;

	if(N == 0) {
		cout << 0 << endl;
		return 0;
	}
	string rsl = "";
	while(N != 0) {
		if(N % (-2) == 0) {
			rsl = '0' + rsl;
			N /= (-2);
		} else {
			rsl = '1' + rsl;
			(N -= 1) /= -2;
		}
	}

	cout << rsl << endl;
				


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
array<int, 101> factoring(int x) {
    array<int, 101> ret{};
    for (int i = 2; x >= i * i; i++) {
        while (x % i == 0) {
            ret[i]++;
            x /= i;
        }
    }
    if (x > 1) ret[x]++;
    return ret;
}

signed main() {
    int n, q;
    cin >> n >> q;
    vector<stack<int>> st(n);
    REP(i, q) {
        int a, t, x;
        cin >> a >> t;
        if (a == 0) {
            cin >> x;
            st[t].push(x);
        } else if (a == 1 && st[t].size() != 0) {
            cout << st[t].top() << endl;
        } else if (st[t].size() != 0) {
            st[t].pop();
        }
    }
}


Measured memory_bytes: 4416
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Pine1999
 */

#include <bits/stdc++.h>

using namespace std;

class ATakoyaki {
public:
    void solve(istream& in, ostream& out) {
        int n, x, t;
        in >> n >> x >> t;
        out << (n + x - 1) / x * t << '\n';
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ATakoyaki solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc115/abc115_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int D;
  cin >> D;

  string ans;
  if (D == 25) {
    ans = "Christmas";
  } else if (D == 24) {
    ans = "Christmas Eve";
  } else if (D == 23) {
    ans = "Christmas Eve Eve";
  } else if (D == 22) {
    ans = "Christmas Eve Eve Eve";
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)((n) - 1); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF = 1e9;
#define debug(x) cout << #x << ":" << x << endl
using namespace std;
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main(){
    string s;
    cin >> s;
    deque<char> d;
    rep(i,s.length()){
        d.push_back(s[i]);
    }
    intl q;
    cin >> q;
    intl r = 0;
    rep(i,q){
        intl a;
        cin >> a;
        if(a == 1){
            r++;
        }
        else {
            intl b;
            cin >> b;
            char t;
            cin >> t;
            if(b == 1){
                if(!(r % 2))d.push_front(t);
                else d.push_back(t);
            }
            else {
                if(!(r % 2))d.push_back(t);
                else d.push_front(t);
            }
        }
    }
    if(r % 2)reverse(d.begin(),d.end());
    rep(i,d.size()){
        cout << d[i];
    }
    return 0;
}

Measured memory_bytes: 896
N = int(input())
l = list(map(int,input().split()))

dp = [0]*N
dp[1] = abs(l[0]-l[1])

for i in range(N-2):
    dp[i+2] = min(dp[i]+abs(l[i+2]-l[i]),dp[i+1]+abs(l[i+2]-l[i+1]))

print(dp[N-1])

Measured memory_bytes: 13980
#include<iostream>
using namespace std;
 
int main(){
  int n, tmp, h=0, ans=0;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> tmp;
    if(tmp>h){
      ans += tmp - h;
    }
    h = tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;
const int SIZE=5+2*1e5;
const LL INF=1<<30;
int x[SIZE];
int conv[SIZE];
int N;
int NG;
int solve(int f){
	REP(i,NG) conv[i]=x[i]-f;
	REP(i,NG) if(conv[i]!=0) conv[i]/=abs(conv[i]);
	int now=N-1;
	int s=0,e=NG-1;
	FOR(i,now,NG-1) 
		if(conv[i]==conv[i+1]) {e=i;break;} 
	for(int i=now;i>0;i--)
		if(conv[i]==conv[i-1]) {s=i;break;}
	int ns=conv[s],ne=conv[e];
	for(int i=s+2;i<NG;i+=2)
		if(conv[i]==conv[i-2]) s++;
		else break;
	for(int i=e-2;i>0;i-=2)
		if(conv[i]==conv[i+2]) e--;
		else break;
	
	if(now<=s) return ns;
	else if(e<=now) return ne;
	return 0;
}
int main(){
	cin >> N;
	NG=N*2-1;
	REP(i,N*2-1){
		cin >> x[i];
	}
	int s=1,e=2*N-1;
	while(s<=e){
		int f=(s+e)/2;
		int ans=solve(f);
		if(ans>=0) s=f+1;
		else  e=f-1;
	}
	cout << e << endl;
	return 0;
}

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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

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

int main() {
  cout << setprecision(18);
  u64 X;
  cin >> X;
  u64 Yen = 100;
  u64 res = 0;
  while (Yen < X) {
    Yen *= 1.01;
    ++res;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
const ll MOD=1e9+7;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    ll a,b;
    cin>>a>>b;
    ll g=__gcd(a,b);
    cout<<(a*b)/g;
}


Measured memory_bytes: 256
# problem C
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
if x < num_list[0]:
    count = num_list[0] - x
    num_list[0] = x
else:
    count = 0

for i in range(N-1):
    n = num_list[i] + num_list[i+1]
    if x < n:
        num_list[i+1] = x - num_list[i]
        count += n - x
    else:
        pass
print(count)

Measured memory_bytes: 14668
#include<stdio.h>
#include<stdlib.h>
 
#define MAX 45
 
void Fibonacci(int);
 
int main(void){
  int n;
 
  scanf("%d", &n);
  Fibonacci(n);
 
  return 0;
}
 
void Fibonacci(int n){
  int i, fib[MAX];
 
  fib[0] = 1;
  fib[1] = 1;
 
  for(i=2; i<MAX; i++) fib[i] = fib[i-2] + fib[i-1];
  printf("%d\n", fib[n]);
 
  return;
}

Measured memory_bytes: 596
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.6
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.6
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Measured memory_bytes: 130040
#include<stdio.h>
#define H 500000

int h;

void maxheapify(int A[],int i){
  int l,r,largest,tmp;

  l=2*i;
  r=2*i+1;

  if(l<=h && A[l]>A[i]) largest = l;
  else largest = i;

  if(r<=h && A[r]>A[largest]) largest = r;

  if(largest != i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;

    maxheapify(A,largest);
  }
}

void makeMaxheap(int A[]){
  int i;
  for(i=h/2;i>0;i--) maxheapify(A,i);
}

int main(){

  int i,j,A[H];

  scanf("%d",&h);

  for(i=1;i<=h;i++) scanf("%d",&A[i]);

  makeMaxheap(A);

  for(i=1;i<=h;i++) printf(" %d",A[i]);

  printf("\n");

  return 0;
}



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

using namespace std;

const int N = 1e5 + 1;
int dp[N], h[N];

int solve(int i) {
    if (i == 1) {
        return 0;
    }
    int& res = dp[i];
    if (res != -1) {
        return res;
    }
    if (i == 2) {
        res = solve(i - 1) + abs(h[i] - h[i - 1]);
    } else {
        res = min(solve(i - 1) + abs(h[i] - h[i - 1]), solve(i - 2) + abs(h[i] - h[i - 2]));
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    memset(dp, -1, sizeof dp);
    cout << solve(n);
    return 0;
}


Measured memory_bytes: 2560
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 k = sc.nextInt();

		int hPtn = (int) Math.pow(2, h);
		int wPtn = (int) Math.pow(2, w);

		String[] hSelect = new String[hPtn];
		String[] wSelect = new String[wPtn];

		for (int i=0; i<hPtn; i++){
			hSelect[i] = String.format("%" + h + "s", Integer.toBinaryString(i)).replace(" ", "0");
		}

		for (int i=0; i<wPtn; i++){
			wSelect[i] = String.format("%" + w + "s", Integer.toBinaryString(i)).replace(" ", "0");
		}


		char[][] mas = new char[h][w];

		int black = 0;
		for (int i=0; i<h; i++){
			String s = sc.next();
			for (int j=0; j<w; j++){
				mas[i][j] = s.charAt(j);
				if (mas[i][j] == '#'){
					black++;
				}
			}
		}

		int remain = black - k;
		long ans = 0;
		for (int i=0; i<hSelect.length; i++){
			for (int j=0; j<wSelect.length; j++){
				int paint = 0;
				for (int l = 0; l < h; l++){
					for (int m=0; m < w; m++){
						if (mas[l][m] == '#'){
							if (hSelect[i].charAt(l) == '1' || wSelect[j].charAt(m) == '1'){
								paint ++;
							}
						}
					}
				}
				if (remain == paint){
					ans++;
				}
			}
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 38924
#include <iostream>
using namespace std;
char a[300010];
int N;
int  k[300010];
int main(){
		cin >> N;
		cin >> a;
		int c = 0;
		for(int i = 0;i < N;i++){
			if(a[i] == 'W')c++;
			k[i+1] +=c;
		}
		c = 0;
		for(int i = N-1;i > 0;i--){
				if(a[i] == 'E')c++;
				k[i-1]+=c;
		}

		int min = 300000;
		for(int i = 0;i < N;i++){
				if(min > k[i])min = k[i];
		}

		cout << min << endl;
}


Measured memory_bytes: 1664
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	int[][] cost;
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int m = scan.nextInt();
			cost = new int[n][n];
			for(int i = 0;i < n;i++){
				Arrays.fill(cost[i],-1);
			}
			for(int i = 0;i < n;i++){
				cost[i][i] = 0;
			}
			for(int i = 0;i < m;i++){
				cost[scan.nextInt()][scan.nextInt()] = scan.nextInt();
			}
			for(int i = 0;i < n;i++){
				for(int j = 0;j < n;j++){
					for(int k = 0;k < n;k++){
						if(!(cost[i][k] < 0 || cost[j][i] < 0)){
							cost[j][k] = Math.max(cost[j][k],cost[j][i] + cost[i][k]);
						}
					}
				}
			}
			System.out.println(cost[0][n-1]);
		}
	}
}

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

int main() {
  int h, w;
  while (cin >> h >> w) {
    if (h == 0 && w == 0) continue;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (i % 2 == 0) {
          if (j % 2 == 0) {
            cout << '#';
          } else {
            cout << '.';
          }
        } else {
          if (j % 2 == 0) {
            cout << '.';
          } else {
            cout << '#';
          }
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
  int n;
  cin>>n;
  if(n==1){
    cout<<"Yes"<<endl;
 return 0;
}    
  
  int val[n];
  rep(i, n){
    cin>>val[i];
}    
  
  int max=0;
  rep(i, n){
    if(max<=val[i]){
      max=val[i];
}      
    if(val[i]+1<max){
      cout<<"No"<<endl;
      return 0;
}      
}    
    cout<<"Yes"<<endl;
  
  
  
  
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ABC147D();

#if 1
int main()
{
	ABC147D();
	fflush(stdout);
	return 0;
}
#endif

static void ABC147D()
{
	int N;
	getint(N);

	std::vector<LLONG> an(N, 0);
	for (int i = 0; i < N; i++) {
		getint(an[i]);
	}

	LLONG ans = 0;
	LLONG bit = 1, two_factor = 1;
	for (int shift = 0; shift < 60; shift++) {
		bit = 1LL << shift;
		LLONG one = 0, zero = 0;
		for (int i = 0; i < N; i++) {
			if (an[i] & bit) {
				one++;
			}
			else {
				zero++;
			}
		}
		ans = (ans + ((one * zero % MOD_NUM) * two_factor) % MOD_NUM) % MOD_NUM;
		two_factor = (two_factor * 2LL) % MOD_NUM;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 2560
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> parse(string str) {
	vector<int> ret; int t = 0; str += ' ';
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == ' ') ret.push_back(t), t = 0;
		else t = t * 10 + str[i] - 48;
	}
	return ret;
}
int bitcount(int x) {
	int ret = 0;
	for (int i = 0; i < 31; i++) {
		if (x & (1 << i)) ret++;
	}
	return ret;
}
string s; long double dp[65536][16];
int main() {
	while (s = "", getline(cin, s)) {
		vector<int> u = parse(s);
		vector<int> v(u.begin() + 1, u.end());
		int n = v.size();
		for (int i = 0; i < (1 << n); i++) {
			for (int j = 0; j < n; j++) dp[i][j] = 999999999.9L;
		}
		for (int i = 0; i < n; i++) dp[1 << i][i] = v[i];
		for (int i = 1; i < (1 << n); i++) {
			if (bitcount(i) <= 1) continue;
			for (int j = 0; j < n; j++) {
				if (!(i & (1 << j))) continue;
				dp[i][j] = 999999999.9L;
				for (int k = 0; k < n; k++) {
					if ((i & (1 << k)) && (j != k)) {
						long double d1 = v[j] + v[k], d2 = abs(v[j] - v[k]);
						dp[i][j] = min(dp[i][j], dp[i - (1 << j)][k] + sqrtl(d1 * d1 - d2 * d2));
					}
				}
			}
		}
		long double ret = 999999999.9L;
		for (int i = 0; i < n; i++) ret = min(ret, dp[(1 << n) - 1][i] + v[i]);
		cout << (ret <= u[0] + 1e-10 ? "OK" : "NA") << endl;
	}
}

Measured memory_bytes: 4148
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
f=0
for i in [a,b,c,d,e]:
  for j in [a,b,c,d,e]:
    if abs(i-j)>k:
      f=f+1
      
if f>0:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 8956
package main

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

const max = 100000000000

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var a, b, q int
	fmt.Scan(&a, &b, &q)

	sc := bufio.NewScanner(os.Stdin)
	s := make([]int, a+2)
	s[0], s[len(s)-1] = -max, max
	for i := 1; i < len(s)-1; i++ {
		sc.Scan()
		s[i], _ = strconv.Atoi(sc.Text())
	}
	t := make([]int, b+2)
	t[0], t[len(t)-1] = -max, max
	for i := 1; i < len(t)-1; i++ {
		sc.Scan()
		t[i], _ = strconv.Atoi(sc.Text())
	}
	x := make([]int, q)
	for i := range x {
		sc.Scan()
		x[i], _ = strconv.Atoi(sc.Text())
	}

	for _, vx := range x {
		ss := sort.SearchInts(s, vx)
		st := sort.SearchInts(t, vx)
		ans := max * 2
		for _, vs := range s[ss-1 : ss+1] {
			for _, vt := range t[st-1 : st+1] {
				if d := abs(vx-vs) + abs(vs-vt); d < ans {
					ans = d
				}
				if d := abs(vx-vt) + abs(vs-vt); d < ans {
					ans = d
				}
			}
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 6784
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}

void testcase(){
	int n,cnt = 0;
	cin >> n;
	bool flag = false;
	while(n--){
		int a,b;cin >> a >> b;
		if(a == b)cnt++;
		else cnt = 0;
		if(cnt >= 3)flag = true;
	}
	if(flag)cout << "Yes";
	else cout << "No";
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


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

int main() {
	
	typedef std::multiset<int> MySet;
	MySet heightSet;
	
	for(int i = 0; i < 10; ++i)
	{
		int val;
		cin >> val;
		heightSet.insert(val);
	}
	
	MySet::reverse_iterator rit = heightSet.rbegin();
	for(int i = 0; i < 3; ++i)
	{
		cout << *rit << endl;
		++rit;
	}
	
	return 0;
}

Measured memory_bytes: 1196
//now 2.060s
#include<map>
#include<algorithm>
#include<iostream>
using namespace std;
#define N 211
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

int table[5][N];
char res[5][32];
int cnt=0;
int bit[20];

class state{
public:
  int t[5];
  int now,size;
  void set_data(int n,int num){
    size=n;now=num;
  }
  
  bool operator<(const state & a)const{
    if (now !=a.now)return now < a.now;
    
    if ( t[0] != a.t[0])return t[0]<a.t[0];
    if ( t[1] != a.t[1])return t[1]<a.t[1];
    if ( t[2] != a.t[2])return t[2]<a.t[2];
    if ( t[3] != a.t[3])return t[3]<a.t[3];
    if ( t[4] != a.t[4])return t[4]<a.t[4];
    return false;
  };
};

void fill_table(int x,int n,int now,bool flag,state &ins){
  rep(i,5){
    ins.t[i]=0;
    rep(j,n){
      if ( flag == false){
	if (table[i][x+j]!=-1)ins.t[i]|=bit[j];
	if( res[i][j] =='X')table[i][x+j]=now;
      }
      if (flag == true &&table[i][x+j]==now)table[i][x+j]=-1;
    }
  }
}

bool can_do(int x,int n){
  rep(i,5){
    rep(j,n){
      if ( res[i][j] == '.')continue;
      else if ( table[i][x+j]!= -1)return false;
    }
  }
  return true;
}


int node=0;


int solve(int n,int last,int now,map<state,int>&M,state &ins){

  if (M.find(ins) != M.end())return M[ins];

  if (now == 10){
    return n;
  }

  state next;next.set_data(n,now);    
  int res=N;
  int lim=n+1;
  REP(i,1,lim){
    if  (can_do(last+i,n)){
      fill_table(last+i,n,now,false,next);
      res=min(res,i+solve(n,last+i,now+1,M,next));
      fill_table(last+i,n,now,true,next);
    }
  }  
  

  return M[ins]=res;
}

main(){
  int n;
  rep(i,20)bit[i]=(1<<i);

  while(scanf("%d\n",&n) && n){
    int lim=11*n+1;
    rep(i,5){
      rep(j,lim)table[i][j]=-1;
    }
    //    rep(i,5)scanf("%s",res[i]);//rep(j,n)cin>>res[i][j];
    rep(i,5)fgets(res[i],n+3,stdin);
    node=0;
    cnt=N;
    state ins;
    map<state,int> M;

    rep(i,5){
      rep(j,n)if (res[i][j]=='X')table[i][j]=0;
    }

    //    cout << solve(n,0,1,M,ins) << endl;
    printf("%d\n",solve(n,0,1,M,ins));
    //cout <<"state "<< node << endl;
  }
  return false;
}

Measured memory_bytes: 0
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let k: usize = scan(tokens);
    let s: String = scan(tokens);
    let s = s.into_bytes();
    let mut cnt = 0;
    for i in 0..n - 1 {
        if s[i] == s[i + 1] {
            cnt += 1;
        }
    }
    println!("{}", std::cmp::min(n - 1, cnt + 2 * k));
}


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

using namespace std;

#define int 	long long
#define endl	"\n"
#define mod		1000000007
#define IOS		ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int32_t main(){

	IOS
	int s ,w;
	cin >> s >> w;

	if(s > w)
		cout<<"safe";
	else
		cout<<"unsafe";

	return 0;
}

Measured memory_bytes: 3652
import scala.io.StdIn.{readLine, readInt}

object Main {

  def factorize(p:Long,d:Long,l:Set[Long]):Set[Long] = {
    if(d >= Math.sqrt(p)+1) {
      if(p != 1) l+p else l
    } else {
      if(p%d == 0)
        factorize(p/d,d,l+d)
      else if(d==2)
        factorize(p,d+1,l)
      else
        factorize(p,d+2,l)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    val l = factorize(n,2,Set())
    var pi = n.toLong
    for(i <- l) {
      pi = (pi*(i-1))/i
    }
    println(pi)
  }
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int a, b, c, d, e;
    int s[5];
    int mark, min=10000;
    for(int i=0; i<5; i++) cin >> s[i];
    for(int i=0; i<5; i++){
        if(s[i]%10!=0){
            int tmp = s[i]%10;
            if(min>tmp){
                mark = i;
                min = tmp;
            }
        }
    }
    int sum = 0;
    for(int i=0; i<5; i++){
        if(i==mark){
            sum+=s[i];
        }else if(s[i]%10!=0){
            int diff = 10-s[i]%10;
            sum+=diff+s[i];
        }else{
            sum+=s[i];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(sc.next());
        }
        int ans = 0;
        for(int i = 1; i < n - 1; i++) {
            if((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1])) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
N = int(input())
X = input()
val = int(X,2)
C = X.count("1")

if C==1:
  for i in range(N):
    if X[i]=='1':
      print(0)
    elif i==N-1:
      print(2)
    else:
      print(1)
  exit()

# xをpopcountで割ったあまりに置き換える
def f(x):
  if x==0: return 0
  return 1 + f(x % bin(x).count("1"))

# 初回のpopcountでの割り方は、(C+1) or (C-1)
Y = val%(C+1)
if C-1 != 0:
  Z = val%(C-1)
else:
  Z = 0

for i in range(N):
  if X[i] == "1":
    if Z - 1 == 0:
      print(0)
      continue
    k = (Z - pow(2,N-i-1,C-1)) % (C-1)
  else:
    k = (Y + pow(2,N-i-1,C+1)) % (C+1)
  print(f(k)+1)

Measured memory_bytes: 76024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define endl "\n"
template <typename T>
void printvec(vector<T> &v, int n, int start = 0)
{
    //cout << "\nprinting vector\n";
    for (int i = start; i < n; i++)
    {
        cout << v[i] << " ";
    }
    cout << "done printing";
    cout << endl;
}
const int mod = 1e9 + 7;
const int BIG = 1e7 + 7;
inline void swap(int &a, int &b)
{
    int t = a;
    a = b;
    b = t;
}

void solve()
{  
    int n;
    map<pair<int,int>,int> mp;
    cin>>n;
    int d1,d2;
    int cnt = 0;
    bool flag = false;
    for(int i=0;i<n;i++)
    {
        cin>>d1>>d2;
        if(d1 == d2)
        {
            cnt++;
            if(cnt == 3)
            {
                flag = true;
            }
        }
        else
        {
            cnt = 0;
        }
    }    
    if(flag)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>

int main(){
    int n;
    scanf("%d", &n);
    int c[10][10];
    memset(c, 0, sizeof(c));
    for(int i = 1; i <= n; ++i){
        int x = i;
        int res = x % 10;
        while(x >= 10) x /= 10;
        c[res][x]++;
    }
    int ans = 0;
    for(int i = 0; i < 10; ++i){
        for(int j = 0; j < 10; ++j){
            ans += c[i][j] * c[j][i];
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1692
#include <vector>
#include <iostream>
#include <map>

class DisjointSet {
 public:
  std::vector<unsigned> parent;
  std::vector<unsigned> rank;
  DisjointSet(unsigned size)
      : parent(size),
        rank(size, 0u) {
    for (unsigned i = 0; i < size; ++i) { parent[i] = i; }
  }
  unsigned find(unsigned index) {
    if (parent[index] != index) { return parent[index] = find(parent[index]); }
    else { return index; }
  }
  void merge(unsigned index_a, unsigned index_b) {
    auto parent_a = find(index_a);
    auto parent_b = find(index_b);
    if (parent_a == parent_b) { return; }
    if (rank[parent_a] < rank[parent_b]) { parent[parent_a] = parent_b; }
    else if (rank[parent_b] < rank[parent_b]) { parent[parent_b] = parent_a; }
    else {
      ++rank[parent_a];
      parent[parent_b] = parent_a;
    }
  }
};

int main() {
  unsigned N, K, L;
  std::cin >> N >> K >> L;
  DisjointSet road(N);
  DisjointSet train(N);
  for (unsigned i = 0; i < K; ++i) {
    unsigned a, b;
    std::cin >> a >> b;
    road.merge(a - 1, b - 1);
  }
  for (unsigned i = 0; i < L; ++i) {
    unsigned a, b;
    std::cin >> a >> b;
    train.merge(a - 1, b - 1);
  }
  std::map<std::pair<unsigned, unsigned>, unsigned> cnt;
  for (unsigned i = 0; i < N; ++i) {
    auto a = road.find(i);
    auto b = train.find(i);
    auto x = cnt.find(std::make_pair(a, b));
    if (x == cnt.end()) {
      cnt.insert(std::make_pair(std::make_pair(a, b), 1));
    } else {
      ++x->second;
    }
  }
  for (unsigned i = 0; i < N; ++i) {
    auto a = road.find(i);
    auto b = train.find(i);
    std::cout << cnt.find(std::make_pair(a, b))->second << " ";
  }
  return 0;
}

Measured memory_bytes: 15104
/**
	������������ Author : Avi J Patel ������������
	������������ University : DA-IICT ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define large 10000000000000001

#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

/*bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} */
/*void calc()
{
	for(int i=0;i<2005;i++)
	{
		a[i][0]=1;
		a[i][i]=1;
		for(int j=1;j<i;j++)
		{
			a[i][j]=(a[i-1][j-1]+a[i-1][j])%MOD;	
		}
	}
}*/
int main()
{
	int n;
	cin>>n;
	vector<string> s(n);
	unordered_map<string,ll> a;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
		a[s[i]]++;
	}
	ll ans=0;
	for(auto x:a)
	{
		ans+=(x.ss*(x.ss-1))/2;
	}
	cout<<ans;
	return 0;
}











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

typedef long long LL;
int n,K;
LL ans;

int main(){
	scanf("%d%d",&n,&K);
	if(K==0){
		printf("%lld\n",1LL*n*n);
		return 0;
	}
	for(int i=K+1;i<=n;i++){//this is b
		int cnt=n/i;
		int r=n%i;
		ans+=1LL*cnt*(i-1-K+1);
		if(r>=K)
			ans+=r-K+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#-*-coding:utf-8-*-

def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    cumsum = []
    for i in range(n):
        if len(cumsum) == 0:
            cumsum.append(a_list[i])
        else:
            cumsum.append(cumsum[i - 1] + a_list[i])
    cumsum_reverce = []
    a_list.reverse()
    for i in range(n):
        if len(cumsum_reverce) == 0:
            cumsum_reverce.append(a_list[i])
        else:
            cumsum_reverce.append(cumsum_reverce[i - 1] + a_list[i])
    cumsum_reverce.reverse()

    ans = []
    for i in range(1, n):
        ans.append(abs(cumsum_reverce[i] - cumsum[i - 1]))
    print(min(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 37704
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
 
using namespace std;
 
bool sagyou(vector<int> &w, int &k, int &P)
{
    int sum = 0;
    int n = w.size();
    int j = 0;
     
     
    for(int i=0; i<n; i++){
        if(P < w[i]){
            return false;
        }
        if(P < sum + w[i]){
            j++;
            if(j == k){
            return false;
            }   
            sum = 0;
        }
        sum += w[i];
         
    }
    return true;
}
 
int allocation(vector<int> &w, int &k)
{
    int ave =  accumulate(w.begin(), w.end(), 0) / k;
    int max = *max_element(w.begin(),w.end());
    int P = std::max(ave,max);
    while(sagyou(w,k,P)==false){
        P++;
    }
     
    return P;
}
 
int main()
{
    int n,k;
    vector<int> w;
 
    cin >> n >> k;
     
    w.resize(n);
     
    for(int i=0; i<n; i++){
        cin >> w[i];
    }
     
    cout << allocation(w,k) << endl;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            final int n = Integer.parseInt(br.readLine());
            if (n == 0) { break; }
             
            Map<String, Long> data = new HashMap<>(n);
            List<String> out = new ArrayList<>();
            for (int i=1; i <= n; i++) {
                StringTokenizer st = new StringTokenizer(br.readLine());
                String e = st.nextToken();
                Long p = Long.parseLong(st.nextToken());
                Long q = Long.parseLong(st.nextToken());
                Long total = data.getOrDefault(e, 0L) + p * q;
                data.put(e, total);
                if (total >= 1_000_000L) {
                    if (out.contains(e) == false) {
                        System.out.println(e);
                        out.add(e);
                    }
                }
            }
            if (out.isEmpty()) {
                System.out.println("NA");
            }
        }
    }
}

Measured memory_bytes: 26740
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 5e3 + 5;
const double eps = 1e-9;
char str[MAXN];

int main() {
	int n, k; scanf("%d %d", &n, &k);
	scanf("%s", str);
	vector<string> v;
	for (int i = 0; i < n; i++) {
		string cur = "";
		for (int j = i; j < n; j++)
			cur += str[j];
		for (int j = 0; j < i; j++)
			cur += str[n-j-1];
		v.pb(cur);
	}
	sort(v.begin(),v.end());
	string ans = v[0];
	k = min(k-1, 15);
	while (k--) {
		int j = 0;
		string tmp = ""; tmp += ans[0];
		while (j + 1 < n && ans[j] == ans[j+1]) {
			tmp += ans[j+1];
			j++;
		}
		for (int i = j+1; i < n; i++)
			tmp += ans[i-j-1];
		ans = tmp;
	}
	printf("%s\n", ans.c_str());
	return 0;
}


Measured memory_bytes: 40192
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;

int main() {
	int n;
	cin >> n;
	string ans = "No";
	rep(i, 25) {
		rep(j, 15) {
			if (4 * i + 7 * j == n) {
				ans = "Yes";
			}
		}
	}
	cout << ans << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include"cstdio"
#include"algorithm"
using namespace std;
bool cmp(int a,int b)
{
 return a>b;
}
int main(){
	int n;
	scanf("%d",&n);
	int b[100005];
	int i=0,j=0,max=0,min=0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&b[i]);
	}	
	long long sum=1;
	int t=0;
	sort(b,b+n,cmp);
	for(i=1;i<n;i++)
	{
		if(b[i]==b[i-1])
		{
			sum=sum*b[i];
			i++;
			t++;
		}
		if(t==2)
			break;		
	}
	if(sum==1&&t!=2)
		sum=0;
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

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

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  qsort(a,n,sizeof(int),cmp);
  int64 sum=0;
  for(i=0;i<n;i++){
    sum+=a[i];
    int j=i+1;
    while(j<n && 2*sum>=a[j]) sum+=a[j++];
    if(j==n) break;
    i=j-1;
  }
  printf("%d\n",n-i);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

//最大公約数
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}

//最小公倍数
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

//素因数分解
map<int,int> prime_factor(ll n,map<int,int> &res){
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            res[i]++;
            n/=i;
        }
    }
    if(n!=1){
        if(res[n]==0){
            res[n]=1;
        }else{
            res[n]++;
        }
    }
    return res;
}

//約数列挙
vector<ll> divisor(ll n){
    vector<ll> a;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            a.push_back(i);
            if(i*i!=n){
                a.push_back(n/i);
            }
        }
    }
    SORT(a);
    return a;
}

//拡張ユークリッドの互除法
int extgcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }else{
        int d=extgcd(b,a%b,y,x);
        y-=a/b*x;
        return d;
    }
}

//素数判定
void sieve(int n,vector<bool> &is_prime) {
	is_prime[0]=false;
	is_prime[1]=false;
	for (int i = 2; i * i <= n; i++) {
		if (is_prime[i]) {
			for (int j = i * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return;
}

//繰り返し2乗法
ll mod_pow(ll x,ll n,ll mod){
    x%=mod;
    ll res=1;
    while(n>0){
        if(n&1){
            res=res*x%mod;
        }
        x=x*x%mod;
        n>>=1;
    }
    return res;
}

//mod　m での a の逆元
int mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

vector<ll> factrial, inverse;

//nCkの前計算
void init(ll n,ll m){
    factrial.resize(n+1);
    inverse.resize(n+1);
    factrial[0]=1;
    inverse[0]=1;
    for(ll i=1;i<=n;i++){
        factrial[i]=factrial[i-1]*i%m;
        inverse[i]=mod_inverse(factrial[i],m);
    }
}

//nCk
ll nCk(ll n,ll k,ll m){
    if(n<0||k<0||n<k){
        return 0;
    }
    return factrial[n]*inverse[k]%m*inverse[n-k]%m;
}

int mod=1e9+7;
vector<ll> a,b;

int main(){
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(w>v){
        cout<<"NO"<<endl;
    }else if(abs(a-b)<=t*abs(v-w)){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int A[N]; rep(i,N) cin >> A[i];

  map<int, int> num; rep(i,N) num[A[i]]++;
  bool ok = true;
  if (N%2==0) { rep(i, N/2) if (num[2*i+1]!=2) ok = false; }
  else {
    rep(i,(N+1)/2) {
      if (i==0) { if (num[2*i]!=1) ok = false; }
      else if (num[2*i]!=2) ok = false;
    }
  }

  ll result = 0;
  if (ok) {result=1; rep(i,N/2) result = (result*2)%MOD; }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define SIZE 1000001
#define pib pair<int,bool>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	vector<int> num(n);
	for(int i=0;i<n;i++){
		cin>>num[i];
	}
	if(n == 1){
		cout<<1;
		return 0;
	}

	sort(num.begin(), num.end());
	if(num[0] == 1){
		cout<<(num[0] == num[1] ? 0 : 1);
		return 0;
	}
	vector<bool> isPrime(SIZE, true);
	vector<pib> ans;

	for(int i=0;i<n;i++){
		bool curCheck = true;
		int sqrtn = (int)sqrt(num[i]);
		for(int j=2;j<=sqrtn;j++){
			if(!(num[i] % j)){
				if(!isPrime[j] || !isPrime[num[i] / j]){
					curCheck = false;
					break;
				}
			}
		}
		if(curCheck){
			if(ans.size() && ans.back().first == num[i]){
				ans.back().second = true;
			}else{
				ans.push_back(make_pair(num[i], false));
			}
		}
		isPrime[num[i]] = false;
	}
	
	int val = 0;
	for(int i=0;i<ans.size();i++){
		if(!ans[i].second) val++;
	}
	cout<<val;
}

Measured memory_bytes: 5680
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int cnt[30];
const int INF=1e9;
const double eps=1e-9;
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
int main(){
	int i,j,k,m,n;
	n=read();m=read();
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++){
			char ch=getchar();
			while(ch<'a' || ch>'z')ch=getchar();
			cnt[ch-'a']++;
		}
	if(n%2==0 && m%2==0){
		for(i=0;i<=25;i++)
			if(cnt[i]%4!=0){
				puts("No");
				return 0;
			}
		puts("Yes");
		return 0;
	}
	else if(n%2==0 || m%2==0){
		int num=0;
		for(i=0;i<=25;i++){
			if(cnt[i]%2!=0){
				puts("No");
				return 0;
			}
			if(cnt[i]%4!=0)num++;
		}
		if(n%2==0)
			if(num>n/2 || (num-n/2)%2!=0)puts("No");
			else puts("Yes");
		else
			if(num>m/2 || (num-m/2)%2!=0)puts("No");
			else puts("Yes");
		return 0;
	}
	else{
		int num1=0,num2=0,sum=(n+m-2)/2;
		for(i=0;i<=25;i++){
			if(cnt[i]%2!=0)num1++,sum-=((cnt[i]-1)%4)/2;
			if(num1>=2){
				puts("No");
				return 0;
			}
			if(cnt[i]%2==0 && cnt[i]%4!=0)num2++;
		}
		if(num2>sum || (num2-sum)%2!=0)puts("No");
		else puts("Yes");
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

// "static void main" must be defined in a public class.
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String input = sc.nextLine();
        boolean a = false;
        boolean b = false;
        for (char c : input.toCharArray()) {
            if (c == 'A') a = true;
            if (c == 'B') b = true;
        }

        if(a && b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

public class Main {

	void solve() {
		int n = in.nextInt();
		long[][] a=  new long[n][n];
		long INF = Long.MAX_VALUE / 3;
		long result = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				a[i][j] = in.nextLong();
				result += a[i][j];
			}
		}
		result /= 2;
		
		long[][] b = new long[n][n];
		for (int i = 0; i < n; i++) {
			b[i] = a[i].clone();
		}
		
		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (i != j && i != k && k != j && b[i][j] == b[i][k] + b[k][j]) {
						result -= b[i][j];
						b[i][j] = b[j][i] = INF;
					}
				}
			}
		}
		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					b[i][j] = Math.min(b[i][j], b[i][k] + b[k][j]);
				}
			}
		}
		for (int i = 0; i < n; i++){ 
			if (!Arrays.equals(a[i], b[i])) {
				out.println(-1);
				return;
			}
		}
		out.println(result);
		
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

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

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

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

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

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


Measured memory_bytes: 36636
N = int(input())
d = list(map(int, input().split()))

d.sort()
#print(d)

d_len = len(d)

if d_len % 2 == 0:
    up = int(d_len/2)
    down = int(d_len/2) - 1
    if up == down:
        print('0')
    else:
        print(d[up]-d[down])
            
        

else:
    print('0')

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

using namespace std;

int main()
{
    int t, n, a[] = {6000, 4000, 3000, 2000};
    for (int i = 0; i < 4; i++) {
        cin >> t >> n;
        cout << a[t-1] * n << endl;
    }

    return 0;
}

Measured memory_bytes: 3092
R, G, B, N = map(int, input().split())
counter = 0
r_max = N//R+1
for r in range(r_max+1):
  temp = N - R*r
  for g in range(temp//G+1):
    now = temp - G*g
    if now% B == 0 and now//B >= 0:
      counter +=1
print(counter)

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

using namespace std;

typedef long long ll;

#define FOR(_i, _a, _b) for (int _i=_a; _i<_b; ++_i)

const int INF = 1e9+7;

int main()
{
    int N;
    ll max_pr = 0;
    ll W;
    cin >> N >> W;
    vector <ll> price(N+1, 0);
    vector <ll> weight(N+1, 0);


    FOR(i, 1, N+1)
    {
        cin >> weight[i] >> price[i];
        max_pr = max(max_pr, price[i]);
    }

    vector <vector <ll>> dp(N+1, vector <ll> (max_pr*N+1, INF));
    dp[0][0] = 0;
    FOR(k, 1, N+1)
    {
        FOR(pr, 0, max_pr*N+1)
        {
            dp[k][pr] = dp[k-1][pr];
            if (pr >= price[k])
                dp[k][pr] = min(dp[k][pr], dp[k-1][pr-price[k]] + weight[k]);
        }
    }

    ll ans = 0;
    FOR(pr, 0, max_pr*N+1)
        if (dp[N][pr] <= W && pr > ans)
            ans = pr;

    cout << ans;
    return 0;
}


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

using namespace std;

int main() {
  long long a, b, x, cnt = 0;
  scanf("%lld %lld %lld", &a, &b, &x);
  printf("%lld\n", (b / x) - (a % x ? a / x : a / x - 1));
  return 0;
}

Measured memory_bytes: 256