akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

string hands( const vector<int>& c ) {
	int n = (int)c.size();

	int p1 = 0;
	int c3 = 0;

	for( int i = 0; i < n; ++i ) {
		if( c[i] == 4 ) {
			return "four card";
		}
		else if( c[i] == 3 ) { c3 += 1; }
		else if( c[i] == 2 ) { p1 += 1; }
	}

	if( c3 > 0 && p1 > 0 ) {
		return "full house";
	}
	else if( c3 > 0 ) {
		return "three card";
	}
	else if( p1 == 2 ) {
		return "two pair";
	}
	else if( p1 == 1 ) {
		return "one pair";
	}

	int x = 0;
	for( int i = 0; i <= n; ++i ) {
		x = (c[i%n] == 1) ? (x+1) : 0;

		if( x == 5 ) { break; }
	}

	return x == 5 ? "straight" : "null";
}

int main() {
	ios_base::sync_with_stdio( false );

	string line;
	while( getline( cin, line ) ) {
		replace( line.begin(), line.end(), ',', ' ' );

		istringstream iss( line );
		vector<int> cnt( 13 );
		int cd;
		while( iss >> cd ) { cnt[cd-1] += 1; }

		cout << hands( cnt ) << '\n';
	}

	return 0;
}



Measured memory_bytes: 3184
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[110][100010];
int w[110];
int v[110];

int main(){
    int n,W;
    cin>>n>>W;
    rep(i,n)
        cin>>w[i]>>v[i];
    rep(i,n){
        for(int w_max=0;w_max<=W;w_max++){
            if(w_max-w[i]>=0)
            chmax(dp[i+1][w_max],dp[i][w_max-w[i]]+v[i]);
            chmax(dp[i+1][w_max],dp[i][w_max]);
        }
    }
    cout<<dp[n][W]<<endl;
    return 0; 
}



Measured memory_bytes: 79360
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;

//
int dx8[8] = { -1,-1,-1, 0, 1, 1, 1, 0 };
int dy8[8] = { -1, 0, 1, 1, 1, 0,-1,-1 };
//6:28
vector<vector<int>>as;
void check(int y, int x) {
	for (int i = 0; i < 8; ++i) {
		int nx = x + dx8[i];
		int ny = y + dy8[i];
		if (as[ny][nx]) {
			as[ny][nx] = 0;
			check(ny, nx);
		}
	}
}
int main() {
	while (1) {
		as.clear();
		int w, h; cin >> w >> h;
		if (!w)break;
		as.resize(h+2);
		for (int i = 0; i <= h+1; ++i) {
			as[i].emplace_back(0);
			if (i != 0 && i != h + 1) {
				for (int j = 0; j < w; ++j) {
					int c; cin >> c;
					as[i ].emplace_back(c);
				}
			}
			else {
				for (int j = 0; j < w; ++j) {
					as[i].emplace_back(0);
				}
			}
			
			as[i].emplace_back(0);
		}
		int ans = 0;
		for (int i = 1; i <= h; ++i) {
			for (int j = 1; j <= w; ++j) {
				if (as[i][j]) {
					ans++;
					check(i, j);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
# 長方形の中の円

# 長方形の中に円が含まれるかを判定するプログラムを作成してください。
# 長方形は左下の頂点を原点とし、右上の頂点の座標 (W,H) が与えられます。
# また、円はその中心の座標 (x,y) と半径 r で与えられます。
# (少しでもはみ出ていたら x )

# Input
# 5つの整数 W、H、x、y、r が空白区切りで1行に与えられます。

def inout (place, line, r)
	flag = true
	# 座標の左or下
	place_min = place - r
	if place_min < 0
		flag = false
	end
	
	# 座標の右o上
	place_max = place + r
	if place_max > line
		flag = false
	end
	return flag
end

# input
nyuryoku= gets.chomp.split("\s")

W = nyuryoku[0].to_i	#この辺修正したい…
H = nyuryoku[1].to_i
x = nyuryoku[2].to_i
y = nyuryoku[3].to_i
r = nyuryoku[4].to_i

if inout(x, W, r)
	if inout(y, H, r)
		puts "Yes"
	else
		puts "No"
	end
	
else
	puts "No"
end

Measured memory_bytes: 6104
#include <stdio.h>
#include <iostream>
using namespace std;

int  main(){
	int N[6];
	int n;
	for(int i=0;i<6;i++){
		cin>>N[i];
	}
	cin>>n;
	int a[n][2];
	for(int i=0;i<n;i++){
		cin>>a[i][0];
		cin>>a[i][1];
	}
	for(int i=0;i<n;i++){
		if(a[i][0]==N[0]&&a[i][1]==N[1])
			cout<<N[2]<<endl;
		if(a[i][0]==N[0]&&a[i][1]==N[2])
			cout<<N[4]<<endl;
		if(a[i][0]==N[0]&&a[i][1]==N[3])
			cout<<N[1]<<endl;
		if(a[i][0]==N[0]&&a[i][1]==N[4])
			cout<<N[3]<<endl;
		if(a[i][0]==N[1]&&a[i][1]==N[2])
			cout<<N[0]<<endl;
		if(a[i][0]==N[1]&&a[i][1]==N[3])
			cout<<N[5]<<endl;
		if(a[i][0]==N[1]&&a[i][1]==N[5])
			cout<<N[2]<<endl;
		if(a[i][0]==N[2]&&a[i][1]==N[4])
			cout<<N[0]<<endl;
		if(a[i][0]==N[2]&&a[i][1]==N[5])
			cout<<N[4]<<endl;
		if(a[i][0]==N[3]&&a[i][1]==N[4])
			cout<<N[5]<<endl;
		if(a[i][0]==N[3]&&a[i][1]==N[5])
			cout<<N[1]<<endl;
		if(a[i][0]==N[4]&&a[i][1]==N[5])
			cout<<N[3]<<endl;
			
				
		if(a[i][0]==N[1]&&a[i][1]==N[0])
			cout<<N[3]<<endl;
		if(a[i][0]==N[2]&&a[i][1]==N[0])
			cout<<N[1]<<endl;
		if(a[i][0]==N[3]&&a[i][1]==N[0])
			cout<<N[4]<<endl;
		if(a[i][0]==N[4]&&a[i][1]==N[0])
			cout<<N[2]<<endl;
		if(a[i][0]==N[2]&&a[i][1]==N[1])
			cout<<N[5]<<endl;
		if(a[i][0]==N[3]&&a[i][1]==N[1])
			cout<<N[0]<<endl;
		if(a[i][0]==N[5]&&a[i][1]==N[1])
			cout<<N[3]<<endl;
		if(a[i][0]==N[4]&&a[i][1]==N[2])
			cout<<N[5]<<endl;
		if(a[i][0]==N[5]&&a[i][1]==N[2])
			cout<<N[1]<<endl;
		if(a[i][0]==N[4]&&a[i][1]==N[3])
			cout<<N[0]<<endl;
		if(a[i][0]==N[5]&&a[i][1]==N[3])
			cout<<N[4]<<endl;
		if(a[i][0]==N[5]&&a[i][1]==N[4])
			cout<<N[2]<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long ans = N - 1;
  long long sq  = floor(sqrt(N));
  for (long long i = sq; i >= 1; i--) {
	  if (N % i == 0) {
		  ans = (i - 1) + (N / i - 1);
		  break;
		}
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007


int main() {
	int n;
	cin >> n;
	VI a(n + 1),sa(n);
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
	}

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

	for (int i = 0; i <n; i++) {
		sa[i] = a[i + 1] - a[i];
	}
	sort(sa.begin(), sa.end());

	int ans = sa[0];
	for (int i = 0; i < n; i++) {
		ans = __gcd(sa[i], ans);
	}
	cout << ans << endl;
	return 0;
	
}


Measured memory_bytes: 1024
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;

void main()
{
  auto n = readln.chomp.to!size_t;

  auto gij = new int[][](n, n);
  foreach (i; n.iota)
    gij[i] = readln.split.to!(int[]);

  edge[] ei;
  foreach (i; 0..n-1)
    foreach (j; i+1..n)
      if (gij[i][j] >= 0)
        ei ~= edge(i, j, gij[i][j]);
  ei.sort!("a.w < b.w");

  auto r = 0;
  auto uf = new UnionFind!size_t(n);
  foreach (e; ei) {
    if (uf.find(e.u) != uf.find(e.v)) {
      uf.unite(e.u, e.v);
      r += e.w;
    }
  }

  writeln(r);
}

alias Tuple!(size_t, "u", size_t, "v", int, "w") edge;

class UnionFind(T)
{
  T[] p; // parent
  T s; // sentinel

  this(T n) {
    p = new T[](n);
    s = n + 1;
    p[] = s;
  }

  T find(T i) {
    if (p[i] == s) {
      return i;
    } else {
      p[i] = find(p[i]);
      return p[i];
    }
  }

  void unite(T i, T j) {
    auto pi = find(i), pj = find(j);
    if (pi != pj) p[pj] = pi;
  }
}

Measured memory_bytes: 3020
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<int> p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> v(n);
    iota(ALL(v), 1);
    int a = 0, b = 0;
    int now = 0;
    do{
        now++;
        if(v == p) a = now;
        if(v == q) b = now;
    } while(next_permutation(ALL(v)));
    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
package main

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

//scanで一行づつ読み込む
var sc = bufio.NewScanner(os.Stdin)
var wtr = bufio.NewWriter(os.Stdout)

//sort
// array := []int{5, 1, 4, 2, 3}
// sort.Sort(sort.IntSlice(array))

func main() {
	// a := make([]int, n)
	// A := strings.Split(nextLine(), " ")

	X := strings.Split(nextLine(), " ")

	// Z := strings.Split(nextLine(), " ")

	// n, _ := strconv.Atoi(input[0])

	// memo = make([]bool, n+1, n+2)

	K, _ := strconv.Atoi(X[0])
	A, _ := strconv.Atoi(X[1])
	B, _ := strconv.Atoi(X[2])

	// ans := K+1
	buiscket := int64(K + 1)
	tmp := int64(1)
	money := int64(0)

	for i := 0; i < K; i++ {

		if money < 1 {

			if i >= K-1 {
				tmp++
			} else if tmp < int64(A) {
				tmp++
			} else {
				tmp, money = exchangeToYen(tmp, int64(A))
			}
		} else {
			tmp, money = exchangeToBuiscket(money, tmp, int64(B))
		}
		// fmt.Printf("tmp: %d , money: %d \n", tmp, money)
	}

	buiscket = max(buiscket, tmp)

	fmt.Fprintln(wtr, buiscket)

	_ = wtr.Flush()
}

func addBuiscket(b int64) int64 {
	return b + 1
}
func exchangeToYen(b int64, rate int64) (rest int64, money int64) {
	return b - rate, 1
}
func exchangeToBuiscket(mone int64, buis int64, rate int64) (b int64, money int64) {
	return buis + rate, mone - 1
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func com(a, b int) int {

	if a > b {
		return 0
	}
	return abs(a - b)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

type dishh struct {
	first  int
	second int
}

type dish []dishh

func (p dish) Len() int {
	return len(p)
}

func (p dish) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p dish) Less(i, j int) bool {

	return p[i].first+p[i].second > p[j].first+p[j].second
}


Measured memory_bytes: 640
n = gets.to_i
nums = []
max = 0
second_max = 0

n.times do |i|
    num = gets.to_i
    nums << num
    if num > max
        second_max = max
        max = num
    elsif num > second_max
        second_max = num
    end
end

# puts "max: #{max}"
# puts "second_max: #{second_max}"


n.times do |i|
    res = max
    if nums[i] == max
        res = second_max
    end
    puts res
end



Measured memory_bytes: 5172
#include <iostream>
using namespace std;
int main() {
    int N;
    cin >> N;
    int numbers[N];
    for (int i = 0; i < N; ++i) {
        cin >> numbers[i];
    }
    int counter = 0;
    for (int i = 0; i < N; ++i) {
        int first = numbers[i];
        for (int j = i+1; j < N; ++j) {
            int second = numbers[j];
            if(second==first){
                continue;
            }
            for (int k = j+1; k < N; ++k) {
                int third = numbers[k];
                if(third==second||third==first){
                    continue;
                }
                if(first+second>third&&first+third>second&&second+third>first&&first-second<third&&second-first<third&&first-third<second&&third-first<second&&second-third<first&&third-second<first){
                    counter++;
                }
            }
        }
    }
    cout << counter << endl;
    return 0;
}


Measured memory_bytes: 3224
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    print('Yes' if N==M else 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38452
S = input()
T = input()

a = 0
ans = len(T)
c = len(T)


for i in range(len(S)-len(T)+1):
    b = 0
    c = len(T)
    for j in T:
        if S[i+b] == j:
            c -= 1
        b += 1
    else:
        if ans > c:
            ans = c
        
print(ans)
        

Measured memory_bytes: 9048
N = int(input())
A = list(map(int, input().split()))


def bubble_sort(A, N):
    cnt = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if(A[i-1] > A[i]):
                A[i-1], A[i] = A[i], A[i-1]
                cnt += 1
                flag = True

    print(" ".join(list(map(str, A))))
    print(cnt)

bubble_sort(A, N)

Measured memory_bytes: 7708
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pll, int> plp;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const bool debug = 0;
//--------------------------------//

int N;
int c[100];
bool dp[100][101];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", c + i);
	
	REP(i, N - 1) if (c[i] == c[i + 1]) dp[i][i + 2] = true;
	
	FOR(s, 2, N + 1) {
		REP(l, N - s + 1) {
			int r = l + s;
			
			FOR(k, l + 1, r) {
				dp[l][r] |= dp[l][k] & dp[k][r]; // xx
				
				if (c[l] == c[r - 1]) {
					dp[l][r] |= dp[l + 1][r - 1]; // 1x1
					if (c[l] == c[k]) dp[l][r] |= dp[l + 1][k] & dp[k + 1][r - 1]; // 1x1x1
				}
			}
			
			if (c[l] && c[r - 1]) {
				if (l > 0 && c[l - 1] == c[l]) dp[l - 1][r] |= dp[l][r];
				if (r < N && c[r - 1] == c[r]) dp[l][r + 1] |= dp[l][r];
			}
		}
	}
	
	puts(dp[0][N] ? "yes" : "no");
	return 0;
}

Measured memory_bytes: 3164
def solve(n, a):
    l = [0] * n
    r = [0] * n
    v = 0
    for i in range(n):
        l[i] = v
        v = max(v, a[i])
    v = 0
    for i in range(n-1, -1, -1):
        r[i] = v
        v = max(v, a[i])
    for i in range(n):
        print(max(l[i], r[i]))

n = int(input())
a = [int(input()) for i in range(n)]
solve(n, a)

Measured memory_bytes: 15632
S = input()
Q = int(input())
b = "" #reversed
a = ""
f = 0
for i in range(Q):
  q = input()
  if q == "1":
    f+=1
  else:
    _,F,C = q.split()
    if (f+int(F))%2==1:
      b+=C
    else:
      a+=C
if f%2==0:
  print(b[::-1]+S+a)
else:
  print(a[::-1]+S[::-1]+b)

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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
	if(l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m+1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());
	for(int i = 0; i < n; i++) {
		if(i) cout << " ";
		cout << post[i]; 
	}
	cout << endl;
}

int main() {
	int k;
	cin >> n;
	
	for(int i = 0; i < n; i++) {
		cin >> k;
		pre.push_back(k);
	}
	
	for(int i = 0; i < n; i++) {
		cin >> k;
		in.push_back(k);
	}
	
	solve();
    
	return 0;	
}

Measured memory_bytes: 3140
loop do
  tmp = gets.chomp.split(" ")
  a = tmp[0].to_i
  b = tmp[2].to_i
  op = tmp[1]
  break if op == "?"
  puts case op
    when "+" then a + b
    when "-" then a - b
    when "*" then a * b
    when "/" then a / b
    end
end

Measured memory_bytes: 8604
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    vector<pair<ll,ll>> bc(m);
    REP(i, m) cin >> bc[i].first >> bc[i].second;

    sort(ALL_OF(a));
    sort(ALL_OF(bc), [](auto &bci, auto &bcj) -> bool {
        if (bci.second != bcj.second)
            return bci.second > bcj.second;
        else
            return bci.first > bcj.first;
    });

    ll unchanged = 0;
    REP(i, m) {
        ll lb = lower_bound(a.begin() + unchanged, a.end(), bc[i].second) - a.begin();
        ll en = unchanged + min(bc[i].first, lb - unchanged);
        RANGE(j, unchanged, en-1) {
            a[j] = bc[i].second;
        }
        unchanged = en;
    }

    cout << accumulate(ALL_OF(a), 0LL) << endl;
    
}

Measured memory_bytes: 2560
a = input()
b = input()
c = input()
turn = 'a'
for i in range(500):
	if turn == 'a':
		if int(len(a)) == 0:
			print("A")
			break
		else:
			turn = a[0]
			a = a[1:]
	if turn == 'b':
		if int(len(b)) == 0:
			print('B')
			break
		else:
			turn = b[0]
			b = b[1:]
	if turn == 'c':
		if int(len(c)) == 0:
			print('C')
			break
		else:
			turn = c[0]
			c = c[1:]

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using i64=long long int;

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

    cout << "Christmas";
    
    while (N++ < 25) cout << " Eve";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <cmath>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;

ll gcd(ll x, ll y){ return y==0? x: gcd(y, x%y); }




int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI t(n), a(n);
	rep(i,n) cin >>t[i] >>a[i];
	
	ll ts=1, as=1;
	
	rep(i,n){
	
		ll k = max((ts + t[i] -1)/t[i] , (as + a[i] -1)/a[i]) ;
		ts = k*t[i];
		as = k*a[i];
	}
	
	
	cout << ts + as <<endl;
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#define MAX 100000
main(){
  int n, i;
  int A[MAX+1];
  scanf("%d", &n);
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);

  for ( i = 1; i <= n; i++ ) {
    printf("node %d: key = %d, ", i, A[i]);
    if ( i / 2 >= 1 )printf("parent key = %d, ", A[i/2]);
    if ( i*2 <= n ) printf("left key = %d, ", A[i*2]);
    if ( i*2+1 <= n ) printf("right key = %d, ", A[i*2+1]);
    printf("\n");
  }
  
  return 0;
}


Measured memory_bytes: 2084
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

int dp[1 << 26];

int main() {
	string s;
	cin >> s;
	LL bit = 0;
	cin >> s;
	for (int i = 0; i < (1 << 26); i++)dp[i] = INF;
	dp[0] = 0;
	for (int i = 0; i < s.size(); i++) {
		bit ^= 1 << (s[i] - 'a');
		for (int j = 0; j < 26; j++) {
			dp[bit] = min(dp[bit], dp[bit ^ (1 << j)] + 1);
		}
	}
	cout << max(1, dp[bit]) << endl;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int dx[] = {-1, 0, 1, 0, 0, 0};
int dy[] = {0, -1, 0, 1, 0, 0};
int dz[] = {0, 0, 0, 0, -1, 1};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int A, B, C, N;
  cin >> A >> B >> C >> N;
  vector<tuple<int, int, int> > ps;
  rep(i, N) {
    int x, y, z;
    cin >> x >> y >> z;
    ps.emplace_back(x, y, z);
  }

  map<tuple<int, int, int>, int> mp;
  int ans = 2 * (A*B + B*C + C*A);
  for(auto p : ps) {
    int x, y, z;
    tie(x, y, z) = p;
    mp[p] = 1;
    rep(i, 6) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      int nz = z + dz[i];
      if(nx < 0 || A <= nx|| ny < 0 || B <= ny|| nz < 0 || C <= nz) ans--;
      else if(mp.count(make_tuple(nx, ny, nz))) ans--;
      else ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main()
{
    string S;
    cin >> S;

    if(S == "Sunny") cout << "Cloudy" << endl;
    else if(S == "Rainy") cout << "Sunny" << endl;
    else if(S == "Cloudy") cout << "Rainy" << endl;

    return 0;
}

Measured memory_bytes: 256
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max

local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end


local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if(allnums[i]) then
      table.insert(primes, i)
      local lim = mfl(x / i)
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while(primepos <= prime_num and dv <= lim) do
    if(x % dv == 0) then
      local asdf = {}
      asdf.p = dv
      asdf.cnt = 1
      x = x / dv
      while(x % dv == 0) do
        x = x / dv
        asdf.cnt = asdf.cnt + 1
      end
      table.insert(tmp, asdf)
      lim = mce(msq(x))
    end
    if(primepos == prime_num) then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if(x ~= 1) then
    local asdf = {}
    asdf.p, asdf.cnt = x, 1
    table.insert(tmp, asdf)
  end
  return tmp
end

local function getdivisor(divisorparts)
  local t = {}
  local pat = 1
  local len = #divisorparts
  local allpat = 1
  for i = 1, len do
    allpat = allpat * (1 + divisorparts[i].cnt)
  end
  for t_i_pat = 0, allpat - 1 do
    local div = allpat
    local i_pat = t_i_pat
    local ret = 1
    for i = 1, len do
      div = mfl(div / (divisorparts[i].cnt + 1))
      local mul = mfl(i_pat / div)
      i_pat = i_pat % div
      for j = 1, mul do
        ret = ret * divisorparts[i].p
      end
    end
    table.insert(t, ret)
  end
  -- table.sort(t)
  return t
end

local a, b = io.read("*n", "*n")
local gcd = getgcd(a, b)
local primes = getprimes(mce(msq(gcd)))
local divps = getdivisorparts(gcd, primes)
local ret = 1 + #divps
print(ret)


Measured memory_bytes: 9728
def count(s):
    w = s.count('.')
    candidate = w
    for i in range(len(s)):
        if s[i] == '#':
            w += 1
        else:
            w -= 1
        candidate = min(candidate, w)

    return candidate


def main():
    _ = int(input())
    s = input()  # '#.#' -> '###'

    print(count(s))


main()

Measured memory_bytes: 3500
#include"bits/stdc++.h"
using namespace std;

int main() {
	vector<int> v;
	for (int i = 0; i < 4; i++) {
		int a;
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	if (v[0] == 1 && v[1] == 4 && v[2]==7 && v[3] == 9) {
		puts("YES");
	}
	else {
		puts("NO");
	}
	return 0;
}

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

ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))

cd=[]
for j in range(m):
    cd.append(list(map(int,input().split())))

for i in range(n):
    far=float("inf")
    number=0
    for j in range(len(cd)):
        ans0=abs(ab[i][0]-cd[j][0])
        ans1=abs(ab[i][1]-cd[j][1])
        ans=ans0+ans1
        if far>ans:
            far=ans
            number=j+1
    print(number)


Measured memory_bytes: 3064
N = int(input())

a = [0 for i in range(N)]
b = [0 for i in range(N)]

for i in range(N):
  x, y = list(map(int, input().split()))
  a[i] = x + y
  b[i] = x - y

a = sorted(a)
b = sorted(b)
print(max(a[N-1]-a[0], b[N-1]-b[0]))

Measured memory_bytes: 94140
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

A, B, C, D = read_int()

def lcm(a, b):
    pa, pb = a, b
    if a > b:
        a, b = b, a
    while b % a != 0:
        a, b = b % a, a
    return pa * pb // a

def divi(a, b, m):
    ans = 0
    former = a // m
    latter = b // m
    ans = latter - former
    if a % m == 0:
        ans += 1
    return ans

def solve():
    return (B - A + 1) - (divi(A, B, C) + divi(A, B, D) - divi(A, B, lcm(C, D)))

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 3768
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
    public static void process()throws IOException
    {
        long a=nl();
        long b=nl();
        long h=nl();
        long m=nl();
        double min=(6.0*m)%360;
        double hour=(30.0*h)%360+(min/12);
        double angle=Math.abs(min-hour);
        if(angle>180)
            angle=360-angle;
        double length=Math.sqrt((a*a)+(b*b)-(2*a*b*Math.cos(angle*Math.PI/180)));
        pn(length);
    }

    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        boolean oj=true;
        //oj = System.getProperty("ONLINE_JUDGE") != null;
        if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
        else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
        int t=1;
        // t=ni();
        while(t-->0) {process();}
        out.flush();out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Measured memory_bytes: 33368
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    
    int cnt1, cnt2, cnt3;
    cnt1 = cnt2 = cnt3 = 0;
    rep(i, n){
        int p;
        cin >> p;
        if(p<=a)cnt1++;
        else if(p<=b)cnt2++;
        else cnt3++;
    }
    cout << min(cnt1, min(cnt2, cnt3)) << endl;
}

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

int main() {
  int a=0,b=0,c=0,d=0;
  cin >> a >> b >> c;
  if(a<b && b<c){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  //cout << << endl;
  return 0;
}


Measured memory_bytes: 3052
# -*- coding: utf-8 -*-
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy > 0:
        out = str(X_dumy % n)+out
        X_dumy = X_dumy//n
    return out


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

print(len(Base_10_to_n(n, k)))


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

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

    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int i;
    cin >> i;
    cout << a[i - 1] << '\n';

    return 0;
}

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

using namespace std;

using int64 = long long;

int main() {

  int Q;
  cin >> Q;
  while(Q--) {
    int64 A, B;
    cin >> A >> B;

    if(A == 1 && B == 1) {
      cout << 0 << endl;
      continue;
    }
    int64 sum = A * B;

    int64 ok = 0, ng = 1LL << 60;

    auto check = [&](int64 mid) {
      int64 vv = mid / 2;
      for(int64 j = max(vv - 5, 1LL); j <= min(vv + 5, mid); j++) {
        if(j == A || mid - j + 1 == B) continue;
        if((__int128_t) j * (mid - j + 1) >= sum) return false;
      }
      return true;
    };

    while(ng - ok > 1) {
      int64 mid = (ok + ng) / 2;
      if(check(mid)) ok = mid;
      else ng = mid;
    }

    int64 ret = 0;
    for(int64 i = ok; i <= ok + 10; i++) {
      if(check(i)) ret = max(ret, i);
    }
    cout << ret - 1 << endl;
  }
}


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

int main(){
    ll a;
    cin >> a;
  	
  	ll ans = 0;
    rep(i,a+1){
      if(i % 2 == 1) ans++;
    }
    cout << (double)ans/(double)a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 998244353;

struct mint {
    ll x;
    mint(ll x=0):x(x%MOD){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
};

int main() {
    int n;
    cin >> n;
    vint d(n);
    rep(i, n) cin >> d[i];

    if (d[0] != 0) {
        puts("0");
        return 0;
    }
    if (n == 1) {
        puts("1");
        return 0;
    }
    sort(all(d));
    if (d[1] == 0) {
        puts("0");
        return 0;
    }
    vpair rl;
    rl.emplace_back(d[0], 1);
    srep(i, n, 1) {
        if (rl.back().fi == d[i]) rl.back().se++;
        else if (rl.back().fi + 1 != d[i]) {
            puts("0");
            return 0;
        }
        else {
            rl.emplace_back(d[i], 1);
        }
    }

    mint ans = 1;
    ll pre = 1;
    for (auto x : rl) {
        rep(i, x.se) ans *= pre;
        pre = x.se;
    }

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

Measured memory_bytes: 1784
while True:
  h,w = map(int, input().split())
  if h == 0 and w == 0:
    break
  else:
    for j in range(h):
      for i in range(w):
        if i == 0 or i == w-1 or j == 0 or j == h-1:
          print("#", end="")
        else:
          print(".", end="")
      print()
    print()


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 2e3 + 100;
pii p[N];
int n;

bool cmp(pii a, pii b) {
    return a.first > b.first;
}

ll dp[N][N];

ll clac(int cnt, int l, int r) {
    if (l > r)return 0;
    if (~dp[l][r])return dp[l][r];
    ll ans = 1ll * p[cnt].first * abs(p[cnt].second - l) + clac(cnt + 1, l + 1, r);
    ans = max(ans, 1ll * p[cnt].first * abs(p[cnt].second - r) + clac(cnt + 1, l, r - 1));
    return dp[l][r] = ans;
}

int main() {
    scanf("%d", &n);
    for (int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        p[i] = {x, i};
    }
    sort(p + 1, p + n + 1, cmp);
    memset(dp, -1, sizeof(dp));
    printf("%lld\n", clac(1, 1, n));
    return 0;
}


Measured memory_bytes: 38364
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    double ans = 0;
    int n; cin >> n;
    rep(i,n){
        double x; cin >> x;
        ans += 1/x;
    }
    ans = 1/ans;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main()

{

char a[3][3];

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

for(int i=0;i<3;i++){
    cout<<a[i][i];
}


return 0;

}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin >> d.at(i); 
  }
  sort(d.begin(),d.end());
  int ans=1;
  for(int i=0;i<N-1;i++){
    if(d.at(i)!=d.at(i+1)){
      ans++;
    }
  }
  cout << ans << endl;


}


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

int main(){
    ll a,b,m;
    cin >> a >> b >> m;
    ll ans;
    vector<ll> A(a);
    vector<ll> B(b);
    rep(i,a){
        cin >> A[i];
    }
    rep(i,b){
        cin >> B[i];
    }
    ll amin=A[0];
    ll bmin=B[0];
    rep(i,a){
        amin=min(amin,A[i]);
    }
    rep(i,b){
        bmin=min(bmin,B[i]);
    }
    ans=amin+bmin;
    for(ll i=0;i<m;i++){
        ll x,y;
        cin >> x >> y;
        ll sa;
        cin >> sa;
        ans=min(ans,A[x-1]+B[y-1]-sa);
    }
    
    cout << ans << endl;

    return 0;
}








Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n+1];
        int[] x = new int[n+1];
        int[] y = new int[n+1];

        // 初期化
        t[0] = 0;
        x[0] = 0;
        y[0] = 0;

        for (int i = 1; i <= n; i++) {
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        boolean canTravel = true;
        for (int i = 0; i <= n; i++) {
            if (n < i+1) break;

            int dist = t[i+1] - t[i];
            int distAbs = Math.abs(x[i+1] - x[i]) + Math.abs(y[i+1] - y[i]);

            // 移動する時間が足りない
            if (dist < distAbs) {
                canTravel = false;
                break;
            }

            if (dist % 2 != distAbs % 2) {
                canTravel = false;
                break;
            }
        }

        System.out.println(canTravel ? "Yes" : "No");
    }
}


Measured memory_bytes: 92256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> cA;
  rep (i, N) cin >> A[i];
  rep (i, N) {
    if (i == 0) cA.push_back(A[i]);
    else {
      if (A[i] == cA.back()) continue;
      cA.push_back(A[i]);
    }
  }

  int cnt = 0;
  for (int i = 0; i < cA.size(); i++) {
    if (i == cA.size() - 1) {
      cnt++;
      break;
    }
    if (cA[i] < cA[i + 1]) {
      while (i < N - 1 && cA[i] < cA[i + 1]) i++;
      cnt++;
    } else {
      while (i < N - 1 && cA[i] > cA[i + 1]) i++;
      cnt++;
    }
  }

  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 4324
N = int(input())

total = N*(N+1)//2
fizz_n = N//3
fizz_total = 3*fizz_n*(fizz_n+1)//2
buzz_n = N//5
buzz_total = 5*buzz_n*(buzz_n+1)//2
fizzbuzz_n = N//15
fizzbuzz_total = 15*fizzbuzz_n*(fizzbuzz_n+1)//2

print(total - fizz_total - buzz_total + fizzbuzz_total)

Measured memory_bytes: 61592
import java.util.*;
import java.io.*;
import java.lang.*;

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();

        System.out.println((a-c)*(b-d));
    }
}


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

int main(){
	int n, count = 0;
	vector<int> p(20);
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> p[i];
	}
	for(int i = 1; i < n-1; ++i){
		if(p[i-1] <= p[i]){
			if(p[i+1] >= p[i])count += 1;
		}else if(p[i+1] <= p[i]){
			count += 1;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>
#include <climits>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream& operator<<(ostream& out, vector<T> &v){
  for (int i = 0; i < (int)v.size(); i++) {
    out<<v[i]<<' ';
  }
  return out;
}

int main(){
  int n; cin >> n;
  if(n >= 30){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int N, m, M, t;
	long int s; 
	cin >> N;
	m = 1000000;
	M = -1000000;
	s = 0;
	for(int i = 0; i < N; i++){
		cin >> t;
		m = min(m,t);
		M = max(M,t);
		s += t;
	}
	cout << m << " " << M << " " << s << endl;
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
    cin >> N;
    vector<int> p(N);
    int count = 0;
    for(int i = 0; i < N; ++i) {
        cin >> p.at(i);
        if(p.at(i) != i+1) {
            count++;
        }
    }

    if(count <= 2) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
}

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

template <int64_t N>
class modint {
    int64_t x;

public:
    modint(int64_t x = 0) : x((x % N + N) % N) {}
    modint operator-() const { return modint(-x); }
    modint& operator+=(const modint& a) {
        if ((x += a.x) >= N) x -= N;
        return *this;
    }
    modint& operator-=(const modint& a) {
        if ((x += N - a.x) >= N) x -= N;
        return *this;
    }
    modint& operator*=(const modint& a) {
        (x *= a.x) %= N;
        return *this;
    }
    modint operator+(const modint& a) const {
        return modint(*this) += a;
    }
    modint operator-(const modint& a) const {
        return modint(*this) -= a;
    }
    modint operator*(const modint& a) const {
        return modint(*this) *= a;
    }
    modint pow(int64_t t) const {
        if (not t) return 1;
        modint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    modint inv() const { return pow(N - 2); }
    modint& operator/=(const modint& a) {
        return (*this) *= a.inv();
    }
    modint operator/(const modint& a) const {
        return modint(*this) /= a;
    }
    friend ostream& operator<<(ostream& os,
                               const modint& m) {
        os << m.x;
        return os;
    }
};
const int64_t mod = 1e9 + 7;
using mint = modint<mod>;
int main() {
    int n;
    cin >> n;
    vector<mint> m(3, 0);
    for (auto i = 0; i < 3; i++) {
        m[i] = i + 8;
        m[i] = m[i].pow(n);
    }
    mint ans = m[2] - m[1] * 2 + m[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
import sys

def solve():
      input = sys.stdin.readline
      N, K = map(int, input().split())
      A = [int(a) for a in input().split()]
      Ans = ["No"] * (N - K)
      for i in range(K, N):
            if A[i] > A[i - K]:
                  Ans[i - K] = "Yes"
      print(*Ans, sep = "\n")

      return 0

if __name__ == "__main__":
      solve()

Measured memory_bytes: 31292
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>

using namespace std;

int main()
{
	int N, M, X;
	cin >> N >> M >> X;

	int r1 = 0;
	int r2 = 0;
	int ans;
	for (int i = 0; i < M; i++)
	{
		int t;
		cin >> t;

		if (t < X)
			r1++;
		else if (t > X)
			r2++;

		ans = min(r1, r2);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc078
// status:

#define SUBMIT
//#define DEBUG

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <queue>
#include <numeric>
#include <limits>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    auto program_input = std::string(R"(64145 123 456
)");
    stringstream stream(program_input);
#endif
    int X, Y, Z;
    stream >> X >> Y >> Z;

    // ans = aとすると以下を満たす最大のaを求めれば良い
    // aY + (a + 1)Z <= X
    // a <= (X - Z) / (Y + Z)

    auto ans = (X - Z) / (Y + Z);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N; cin >> N;
    vec A(N); readv(A);

    int ans = 0, tmp = 0;
    REP(i, N){
        tmp += A[i];
        if(A[i] == 0 || i == N - 1){
            ans += tmp / 2;
            tmp = 0;
        }
    }
    
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 1024