akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll N, K;
vector<ll>A;
int check(ll x) {
	ll cnt = 0;
	for (int i = 0; i < N-1; i++) {
		if (A[i] < 0) {
			if (A[i] * A[N - 1] > x)continue;
			int ok = N-1,ng = i;
			while (ok - ng > 1) {
				int mid = (ok + ng) / 2;
				if (A[i] * A[mid] <= x)ok = mid;
				else ng = mid;
			}
			cnt += N-ok;
		}
		else if (A[i] > 0) {
			if (A[i] * A[i + 1] > x)continue;
			int ok = i + 1, ng = N;
			while (ng - ok > 1) {
				int mid = (ng + ok) / 2;
				if (A[i] * A[mid] <= x)ok = mid;
				else ng = mid;
			}
			cnt += ok-i;
		}else{
			if (x >= 0)cnt += N - i - 1;
		}
	}
	return cnt >= K;
}

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

	
	cin >> N >> K;
	A.resize(N);
	for (int i = 0; i < N; i++)cin >> A[i];
	sort(all(A));

	ll ok = inf, ng = -inf;
	while (ok - ng > 1) {
		ll mid = (ok+ng)/2LL;
		if (check(mid))ok = mid;
		else ng = mid;
	}
	puts(ok);

	

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int mod = 1000000007;

inline LL qpow(LL a, LL b)
{
	LL res = 1;
	while (b)
	{
		if (b & 1) res = (res * a) % mod;
		a = a * a % mod, b >>= 1;
	}
	return res % mod;
}

const int M=1e9+7;
int n,m;
LL ans=1,f[1000005]={1},g[1000005]={1};
LL ksm(LL x,LL y)
{
    LL s=1;
    while(y)
	{
        if(y&1)s=(s*x)%M;
        x=(x*x)%M;
        y>>=1;
    }
    return s;
}
LL work(int x,int y)
{
    return f[x]%M*g[y]%M*g[x-y]%M;
}
int main(){
	cin >> n >> m;
    for(int i=1;i<=n;i++)
{
        f[i]=f[i-1]*i%M;
        g[i]=ksm(f[i],M-2);
    }
    int k=min(n-1,m);
    for(int i=1;i<=k;i++)
{
        LL x=work(n,i);
        LL y=work(n-1,i);
        ans=(ans+x*y%M)%M;
    }
    cout<<ans<<endl;
	return 0;
}


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

int main(void){
  string s;cin >> s;s[-1] = '0';
  for(int i=1;i<s.length();++i){
    int a = 0;
    if(s[i-2] == s[i-1]||s[i-1] == s[i]||s[i-2] == s[i])a = 1;
    if(a == 1 && i-1 > 0){printf("%d %d\n",i-1,i+1);return 0;}
    else if(a == 1){printf("%d %d\n",i,i+1);return 0;}
  }
  printf("-1 -1\n");
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
bool lun(string n){
    int len = n.length();
    for(int i=1;i<len;i++){
        if(abs(n[i]-n[i-1]) > 1) return false;
    }
    return true;
}
string nxt(string n){
    int len = n.length();
    for(int i=len-2;i>=0;i--){
        if(n[i]+1 != n[i+1] && n[i+1] != '9'){
            n[i+1] += 1;
            for(int j=i+2;j<len;j++){
                if(n[j-1] == '0') n[j] = '0';
                else n[j] = n[j-1]-1;
            }
            return n;
        }
    }
    if(n[0] == '9') n = '1' + string(len, '0');
    else{
        n[0]++;
        for(int i=1;i<len;i++){
            if(n[i-1] == '0') n[i] = '0';
            else n[i] = n[i-1]-1;
        }
    }
    return n;
}
int main(void){
    int k;
    string n = "10";
    cin >> k;
    if(k <= 10){
        cout << k << endl;
        return 0;
    }
    for(int i=10;i<k;i++){
        // cout << n << endl;
        n = nxt(n);
    }
    cout << n << endl;
}


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

int main(){
    int h, w, dp[51][51];
    string s[51];
    
    cin >> h >> w;
    for(int i=0 ; i < h ; i++ ){
        cin >> s[i];
    }
    for(int y=0 ; y < h ; y++ ){
        for(int x=0 ; x < w ; x++ ){
            dp[y][x] = 10000;
        }
    }
    dp[0][0] = 0;
    for(int y=0 ; y < h ; y++ ){
        for(int x=0 ; x < w ; x++ ){
            if( y != 0 ){
                dp[y][x] = min( dp[y][x] , dp[y-1][x] + (s[y][x]-'0') );
            }
            if( x != 0 ){
                dp[y][x] = min( dp[y][x] , dp[y][x-1] + (s[y][x]-'0') );
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 1220
#include <iostream>

int GetRateModifier(int joinCount)
{
    if (joinCount >= 10)
    {
        return 0;
    }

    return 100 * (10 - joinCount);
}

int main()
{
    int joinCount = 0;
    std::cin >> joinCount;

    int dispRate = 0;
    std::cin >> dispRate;

    std::cout << dispRate + GetRateModifier(joinCount);
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	x, _ := sc.NextInt()
	y, _ := sc.NextInt()
	ans := solve(x, y)
	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func solve(x, y int) bool {
	i := sort.Search(x+1, func(i int) bool { return 4*i+2*(x-i) >= y })
	return i < x+1 && 4*i+2*(x-i) == y
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}


Measured memory_bytes: 1756
direction = input()

def next(direction, current):
	output = [0] * len(current)

	for i in range(len(direction)):
		if direction[i] == 'R':
			output[i+1] += current[i]
		if direction[i] == 'L':
			output[i-1] += current[i]

	return output

def s(inp):
	r = len([x for x in inp if x == 'R'])
	l = len([x for x in inp if x == 'L'])

	R = L = 0
	for i in range(0, r, 2):
		R += 1
	for i in range(1, r, 2):
		L += 1
	for i in range(0, l, 2):
		L += 1
	for i in range(1, l, 2):
		R += 1
	
	output = [0 for _ in range(len(inp))]
	output[r-1] = R
	output[r] = L
	return output

def solve(inp):
	r = len([x for x in inp if x == 'R'])
	l = len([x for x in inp if x == 'L'])

	output = [0] * len(inp)
	if r == l:
		output[r-1] = output[r] = r
	else:
		m = max(l-1, r-1)
		if m % 2 == 1:
			output[r-1] = r
			output[r] = l
		else:
			output[r-1] = l
			output[r] = r
		


def solve(direction, start, end, output):
	original = [1] * (end-start)

	sub_direction = direction[start:end]

	prev2 = next(sub_direction, original)
	prev1 = next(sub_direction, prev2)

	count = 2

	output.append(s(direction[start:end]))

	# while True:
	# 	next_state = next(sub_direction, prev1)
	# 	count += 1
	# 	if next_state == prev2:
	# 		if count % 2 == 0:
	# 			output.append(prev2)
	# 			# print(' '.join(map(str, prev2)))
	# 			return
	# 		else:
	# 			output.append(prev1)
	# 			# print(' '.join(map(str, prev1)))
	# 			return
	# 	prev2 = prev1
	# 	prev1 = next_state

# direction = 'RRRLLRLLRRRLLLLL'
parts = []
prev = 0
for i in range(len(direction)-1):
	if direction[i] == 'L' and direction[i+1] == 'R':
		parts.append((prev,i+1))
		prev = i+1

parts.append((prev,len(direction)))

# print(parts)
output = []
for start,end in parts:
	solve(direction, start, end, output)

# print(output)
final = [x for  y in output for x in y]
print(' '.join(map(str, final)))


# print(solve('RRLRL'))
# print(solve('RRLLLLRLRRLL'))

Measured memory_bytes: 23164
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if(w >= v ){
        cout << "NO" << endl;
    }else{
        if( (v -w)*t >= abs( a - b ) ){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cstdio>
#include <cmath>
#include <deque>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

ll dp[100];

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	dp[0] = 2; dp[1] = 1;
	REP(i, n){
		dp[i + 2] = dp[i + 1] + dp[i];
	}
	cout << dp[n];
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
  int n,m;
  cin >> n >> m;
  int a[n];
  int e = 0;
  for (int i = 0 ; i < n; i++){
    cin >> a[i];
    e += a[i];
  }
  
  sort (a, a + n);
  if (a[n-m]* 4* m >= e) {
    cout << "Yes";}
  else {
    cout << "No";} }
    

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
ll INF = (1LL << 60) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N*3);
    rep(i,0,N*3)cin >> V[i];
    vector<ll> A(N+1),B(N+1);
    priority_queue<int, vector<int>, greater<int>> que;
    ll sum = 0;
    rep(i,0,N){
        sum += V[i];
        que.push(V[i]);
    }
    rep(i,0,N+1){
        A[i] = sum;
        //cout << A[i] << endl;
        que.push(V[N+i]);
        sum = sum - que.top() + V[N+i];
        que.pop();
    }
    priority_queue<int> que2;
    sum = 0;
    for(int i = N*3-1;i >= N*2;i--){
        sum += V[i];
        que2.push(V[i]);
    }
    for(int i = N;i >= 0;i--){
        B[i] = sum;
        que2.push(V[N + i - 1]);
        //cout << B[i] << " " << V[N + i - 1] << " " << que2.top() << endl;
        sum = sum - que2.top() + V[N + i - 1];
        que2.pop();
    }
    ll maxi = -INF;
    rep(i,0,N+1)maxi = max(maxi, A[i] - B[i]);
    cout << maxi << endl;
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int sum=0;
    for (int i = 1; i <= n; i++) {
        int s=0;
        if (i < 10) s = i;
        else {
            int aa = i;
            while (aa >= 10) {
                s += aa%10;
                aa /= 10;
            }
            s += aa;
        }
        if (a<=s && s<=b) {
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#D
N, X = [int(x) for x in input().split()]

def make(lv):
    if lv==0: return 'P'
    else: return 'B' + make(lv-1) + 'P' + make(lv-1) + 'B'

def countBurg(lv):
    if lv==0: return 1, 1
    else: #return 'B' + make(lv-1) + 'P' + make(lv-1) + 'B'
        c1 = countBurg(lv-1)
        return 1+c1[0]+1+c1[0]+1, c1[1]+1+c1[1]

def countBurg2(lv):
    count = [(1,1) for i in range(lv+1)]
    for i in range(1,lv+1):
        count[i] = count[i-1][0]*2+3, count[i-1][1]*2+1
    return count

BurgCount = countBurg2(50) #[(bc, pc),...]

def countPate(lv, x):
    #print(lv, x) #
    if lv<=0: return 1

    ec = 1 # Eat Count   B
    epc = 0 # Eat Pate Count
    #print(ec, epc) #
    if ec>=x: return epc
    
    if ec+BurgCount[lv-1][0]>x:
        epc += countPate(lv-1, x-ec)
        ec = x #lv-1
    else:
        ec += BurgCount[lv-1][0]#lv-1
        epc += BurgCount[lv-1][1]
    #print(ec, epc) #
    if ec>=x: return epc
    
    ec += 1 #P
    epc += 1 
    #print(ec, epc) #
    if ec>=x: return epc
    
    if ec+BurgCount[lv-1][0]>x:
        epc += countPate(lv-1, x-ec)
        ec = x #lv-1
    else:
        ec += BurgCount[lv-1][0]#lv-1
        epc += BurgCount[lv-1][1]
    #print(ec, epc) #
    if ec>=x: return epc
    
    ec += 1 #B
    #print(ec, epc) #
    return epc
            
#burg = make(N)
#print(burg)#
#for i in range(X):
#    if burg[i]=='P': count += 1

#print(BCount)#

print(countPate(N,X))



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n;string s,t;cin>>n>>s>>t;
  rep(i,n){
    cout<<s[i]<<t[i];
  }
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        ss: [String; h],
    }
    let s = ss
        .iter()
        .map(|s| s.chars().collect::<Vec<_>>())
        .collect::<Vec<_>>();
    for y in 0..h {
        for x in 0..w {
            if s[y][x] == '#' {
                if y > 0 {
                    if s[y - 1][x] == '#' {
                        continue;
                    }
                }
                if y < h - 1 {
                    if s[y + 1][x] == '#' {
                        continue;
                    }
                }
                if x > 0 {
                    if s[y][x - 1] == '#' {
                        continue;
                    }
                }
                if x < w - 1 {
                    if s[y][x + 1] == '#' {
                        continue;
                    }
                }
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
n = int(input())

lastch = ''
answer = 'Yes'
words = []

for i in range(n):
    word = input()
    words.append(word)
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(words) != len(set(words)):
    answer = 'No'

print(answer)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
const double EPS = 1e-4;
typedef long long ll;
typedef complex<double> Point;
typedef vector<Point> VP;
#define X real()
#define Y imag()

double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

namespace std {
  bool operator<(const Point a, const Point b) {
    return a.Y != b.Y ? a.Y < b.Y : a.X < b.X;
  }
}

// ??????
VP convexHull(VP ps) {  // ????????????????????????????????????????????????VP&???
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  VP ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;  // ????¨?????????????????????? == -1 ??¨??????
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;
  ch.resize(k-1);
  return ch;
}

int main(void){
    int n;
    double x,y;
    cin>>n;
    VP ps(n);
    rep(i,n){
        cin>>x>>y;
        ps[i] = {x,y};
    }

    ps = convexHull(ps);
    n = ps.size();
    cout<<n<<endl;
    rep(i,n){
        printf("%.0f %.0f\n",ps[i].X,ps[i].Y);
    }
    return 0;
}

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

int main (){

    int N,O=1;
    cin >> N;
    
    for(int i = 0; i < N; i++) {
        O *= 2;
        if(O > N) {
            break;
        }
    }

    cout << O / 2 << endl;
    return 0;
}


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

using namespace std;
typedef long long nagai;

vector<vector<pair<int, nagai>>> g;
vector<nagai> d;


void dfs(int u, int p, nagai d1)
{
	d[u] = d1;
	for (auto v : g[u])
		if (v.first != p)
			dfs(v.first, u, d[u] + v.second);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	d.resize(n);
	g.resize(n);
	for (int i = 0; i < n - 1; ++i)
	{
		int a, b;
		nagai c;
		cin >> a >> b >> c;
		--a, --b;
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}
	int q, k;
	cin >> q >> k;
	--k;
	dfs(k, -1, 0);
	for (int i = 0; i < q; ++i)
	{
		 int a, b;
		 cin >> a >> b;
		 --a, --b;
		 cout << d[a] + d[b] << '\n';
	}
	
}


Measured memory_bytes: 14336
import sys
sys.setrecursionlimit(100000)
 

N,K = list(map(int,input().split()))

tree = [[] for _ in range(N+10)]

for i in range(N-1):
    a,b = list(map(int,input().split()))
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

ans = []
def wfs(now,back):
    if now != 0:
        cnt = K - 2 #まず一個上のを引く。
    else:
        cnt = K - 1
    for nxt in tree[now]:
        if nxt != back:
            ans.append(cnt)
            cnt = cnt - 1
            wfs(nxt,now)

ans.append(K)
wfs(0,-1)

ans2 = 1
for j in range(len(ans)):
    ans2 = (ans2 * ans[j]) % (10**9+7)
print(ans2)

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

using namespace std;

int main()
{
    while (true) {
        int n, p;
        cin >> n >> p;
        if (n == -1 and p == -1) {
            break;
        }
        p--;
        int prime[100];
        int num = max(2, n + 1);
        for (int i = 0; i < 100; i++) {
            while (true) {
                bool isp = true;
                for (int j = 2; j * j <= num; j++) {
                    if (num % j == 0) {
                        isp = false;
                        break;
                    }
                }
                if (isp) {
                    prime[i] = num;
                    num++;
                    break;
                } else {
                    num++;
                }
            }
        }
        vector<int> sum;
        for (int i = 0; i < 100; i++) {
            for (int j = i; j < 100; j++) {
                sum.push_back(prime[i] + prime[j]);
            }
        }
        sort(sum.begin(), sum.end());
        cout << sum[p] << endl;
    }
    return 0;
}

Measured memory_bytes: 3004
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	k := scanInt()
	a := make(map[int][]int, n)
	for i := 0; i < n; i++ {
		t, d := scanInt(), scanInt()
		a[t] = append(a[t], d)
	}

	ans := 0
	b := piis{}
	c := piis{}
	for i, e := range a {
		sort.Ints(e)
		b = append(b, pii{i, e[len(e)-1]})
		for j := 0; j < len(e)-1; j++ {
			c = append(c, pii{i, e[j]})
		}
	}

	used := piis{}
	cnt := map[int]int{}
	sort.Sort(b)
	sort.Sort(c)

	for i := 0; i < len(b); i++ {
		ans += b[i].d
		used = append(used, b[i])
		cnt[b[i].t]++
		k--
		if k == 0 {
			break
		}
	}
	if k != 0 {
		for k > 0 {
			ans += c[0].d
			used = append(used, c[0])
			cnt[c[0].t]++
			c = c[1:]
			k--
		}
	}

	sort.Sort(used)
	num := len(cnt)
	for i := 0; i < len(c); i++ {
		u := used[len(used)-1]
		if cnt[u.t] > 1 {
			break
		}
		if ans+num*num < ans-u.d+c[i].d+(num-1)*(num-1) {
			ans += c[i].d - u.d
			used = used[:len(used)-1]
			num--
		} else {
			break
		}
	}

	fmt.Fprintln(wr, ans+num*num)

}

type pii struct{ t, d int }

type piis []pii

func (a piis) Len() int           { return len(a) }
func (a piis) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a piis) Less(i, j int) bool { return a[i].d > a[j].d }


Measured memory_bytes: 22528
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define pb push_back
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
    ll n, x, m;
    cin >> n >> x >> m;
    Graph G(m);
    ll tmp = x;
    ll cnt = 0;
    vector<ll> v;
    while(1){
        //cout << x << endl;
        G[x].push_back(x * x % m);
        if(G[x].size() == 2)break;
      	cnt++;
      	v.pb(x);
        x = x * x % m;
    }
    //cはしっぽの長さ,lはループの長さ
    ll c = 0, l;
    x = tmp;
    while(1){
        if(G[x].size() == 2)break;
        c++;
        x = x * x % m;
    }
    l = cnt - c;
    ll res = 0;
    x = tmp;
  	//rep(i, cnt)cout << v[i] << " ";
  	//cout << l << endl;return 0;
    if(n <= cnt){
        rep(i, n)res += v[i];
    }
    else {
        rep(i, cnt)res += v[i];
        n -= cnt;
      	//ループ何回するか
        REP(i, c, cnt - 1){
            res += (v[i] * (n / l));
        }
        n %= l;
        rep(i, n)res += v[c + i];
    }
    cout << res << endl;
}



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

int main(){
    int K, X;
    int p;

    cin >> K >> X;

    p = X - K;

    for(int i; i < 2 * K - 1; i++){
        cout << X - K + 1 + i << ' ';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
    x, y, z = [int(_) for _ in input().split()]
    c.append(x)
    s.append(y)
    f.append(z)

for j in range(n-1):
    t = 0
    for i in range(j, n-1):
        if t < s[i]:
            t = s[i]
        elif (t - s[i]) % f[i] != 0:
            t += f[i] - (t - s[i]) % f[i]
        t += c[i]
    print(t)
print(0)


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <array>
#include <climits>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

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

int main() {
    string s;
    cin >> s;
    cout << "ABC" << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define mp make_pair
#define P pair<int,int>
#define ri register int
#define rb register bool
#define rc register char
#define t(i) edge[i].to
#define w(i) edge[i].wei
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define e(i,x) for(ri i=head[x];i;i=edge[i].nxt)

const int N=2*1e5+10;
int w[N],d[N],cnt[20],res,n,st,sxr[N];
bool book[N];

il int read()
{
	rc ch=gc;ri x=0;rb y=1;
	while(ch!='-' && (ch<'0' || ch>'9'))ch=gc;
	if(ch=='-')ch=gc,y=0;
	while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
	return y?x:-x;
}

int main()
{
	n=read();rp(i,1,n-1){ri u=read()+1,v=read()+1,va=read();w[u]^=va;w[v]^=va;}rp(i,1,n)cnt[w[i]]++;
	rp(i,1,15)res+=cnt[i]/2,st|=(cnt[i]&1)<<(i-1);
	n=1<<15;
	rp(i,1,n-1)d[i]=d[i>>1]+(i&1);rp(i,1,n-1)d[i]-=1;
	rp(i,1,n-1){rp(j,0,14)if((i>>j)&1)sxr[i]^=(j+1);}
	rp(i,1,n-1)
	{
		if(sxr[i]!=0)continue;
		for(int k=(i-1)&i;k;k=(k-1)&i)if(!sxr[k])d[i]=min(d[i],d[k]+d[i^k]);
	}
	printf("%d",res+d[st]);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::string s;
  std::cin >> s;
  char c = s.back();
  if (c == '2' || c == '4' || c == '5' || c == '7' || c == '9') {
    std::cout << "hon";
  } else if (c == '0' || c == '1' || c == '6' || c == '8') {
    std::cout << "pon";
  } else {
    std::cout << "bon";
  }
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<string> th;
    for(int i=0;i<n;++i){
      string s;cin>>s;
      th.push_back(s);
    }

    for(int i=1;i<n;++i)
      for(int j=0;j+1<n;++j)
	if(th[i][j]=='.' && th[i][j+1]!='.'){
	  th[i][j]='+';
	  break;
	}

    for(int i=0;i<n;++i) for(int j=0;j<th[i].length();++j) if(th[i][j]=='.') th[i][j]=' ';

    for(int i=n-1;i>=0;--i){
      for(int j=0;j<th[i].length();++j){
	if(th[i][j]=='+'){
	  int k = i-1;
	  while(k>=0 && th[k][j]==' ') th[k--][j]='|';
	}
      }
    }

    for(int i=0;i<n;++i) cout << th[i] << endl;
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int answer = 0;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == '1'){
      answer++;
    }else{
      continue;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define P pair<int , int>

using namespace std;

int main(){
  int n, C;
  vector<P> v[31];
  cin >> n >> C;
  for(int i=0;i<n;i++){
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    v[c].push_back(P(s, t));
  };
  priority_queue<P, vector<P>, greater<P> > q1;
  priority_queue<int , vector<int>, greater<int> > q2;
  for(int i=0;i<C;i++){
    sort(v[i].begin(), v[i].end());
    int s=-1, t=-1;
    for(int j=0;j<v[i].size();j++){
      if(s==-1){
        s = v[i][j].first;
        t = v[i][j].second;
      }
      else if(v[i][j].first==t){
        t = v[i][j].second;
      }
      else if(v[i][j].first!=t){
        q1.push(P(s, t));
        s = v[i][j].first;
        t = v[i][j].second;
      }
      if(j==v[i].size()-1){
        q1.push(P(s, t));
      }
    }
  }
  int ans=0;
  while(!q1.empty()){
    while(!q2.empty() && q1.top().first>q2.top())q2.pop();
    q2.push(q1.top().second);q1.pop();
    ans = max(ans, (int)q2.size());
  }
  cout << ans << endl;
}



Measured memory_bytes: 5528
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var s = Console.ReadLine();

        Console.WriteLine(
            Regex.IsMatch(s, "^.*keyence$") ||
            Regex.IsMatch(s, "^k.*eyence$") ||
            Regex.IsMatch(s, "^ke.*yence$") ||
            Regex.IsMatch(s, "^key.*ence$") ||
            Regex.IsMatch(s, "^keye.*nce$") ||
            Regex.IsMatch(s, "^keyen.*ce$") ||
            Regex.IsMatch(s, "^keyenc.*e$") ||
            Regex.IsMatch(s, "^keyence.*$") ? "YES" : "NO");
    }
}


Measured memory_bytes: 16064
fun main(args: Array<String>) {
  val (n, k) = readLine()!!.split(" ").map { it.toInt() }
  val d = readLine()!!.split(" ").map { it.toInt() }
  for (i in n..100000) {
    if (d.all { !i.toString().contains(it.toString()) }) {
      println(i)
      return
    }
  }
}


Measured memory_bytes: 40808
N, Y = map(int, input().split())
flg = False
for x in range(N+1):
    for y in range(N+1):
        if ((10000*x + 5000*y + (N-x-y)*1000)==Y) & (x+y<=N):
            print(x,y,(N-x-y))
            flg = True
            break
    if flg:
        break
else:
    print(-1,-1,-1)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	string s;
	cin>>s;
	LL ans=0;
	LL now=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='A'){
			ans+=now;
		}else{
			if(i==0)break;
			if(s[i]=='C'&&s[i-1]=='B'){
				i--;
				now++;
			}else{
				now=0;
			}
		}
	}
	
	
	cout<<ans<<endl;
}

Measured memory_bytes: 640
$S=<>;
$S=~/(..)(..)/;
$f=2    if($1>0&&$1<13);
$f+=1   if($2>0&&$2<13);
print "AMBIGUOUS" if($f==3);
print "MMYY" if($f==2);
print "YYMM" if($f==1);
print "NA" if($f==0);

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
#define int long
  int N;cin>>N;
  vector<vector<pair<int,int> > >A(N);
  for(int i=0;i<N-1;i++){
    int a,b,c;cin>>a>>b>>c;
    A[a-1].push_back(pair<int,int>(b-1,c));
    A[b-1].push_back(pair<int,int>(a-1,c));
  }
  int Q,K;cin>>Q>>K;
  vector<int>d(N,-1);
  queue<int>q;q.push(K-1);d[K-1]=0;
  while(q.size()){
    int f=q.front();q.pop();
    for(auto n:A[f]){
      if(d[n.first]==-1){
        d[n.first]=d[f]+n.second;
        q.push(n.first);
      }
    }
  }
  for(int i=0;i<Q;i++){
    int x,y;cin>>x>>y;
    cout<<d[x-1]+d[y-1]<<endl;
  }
}

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

int main(){
	int n,k,q; cin >>n>>k>>q;
	vector<ll> p(n,k-q); 
	for(int i=0; i<q; i++){
		int a; cin>>a;
		p.at(--a)++;
	}
	for(auto i:p) cout <<(i>0?"Yes":"No") << endl;
}

Measured memory_bytes: 1408
import math
n=int(input())
mod=10**9+7
ans=1
cnt=[0]*1000
for i in range(2,n+1):
    x=i
    for j in range(2,int(math.sqrt(n))+1):
        while x%j==0:
            cnt[j]+=1
            x/=j
    if x!=1:
        cnt[int(x)]+=1
for i in cnt:
    if i!=0:
        ans*=(i+1)
        ans%=mod
print(int(ans))

Measured memory_bytes: 9196
#include "stdio.h"


int main()
{
	int A,B,C,D;
	do{
		scanf("%d%d%d%d",&A,&B,&C,&D);
	}while((A<1&&A>100)&&(B<1&&B>100)&&(C<1&&C>100)&&(D<1&&D>100));
	
	while(A>=0)
	{
		C-=B;
		if(C<=0)
			break;
		A-=D;
	}
	if(A<=0)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1664
#BFS
from collections import deque
def bfs(i):
    q=deque()
    q.append((0, 0))

    d = ((1, 0), (0, 1), (-1, 0), (0, -1))
    log = [[0] * w for i in range(h)]
    log[0][0] = 1

    while q:
        #qの先頭を取り出す
        x, y=q.popleft()
        for dx, dy in d:
            nx = x + dx
            ny = y + dy
            if not(0 <= nx < h and 0 <= ny <w):continue
            if s[nx][ny] == '#':continue
            if log[nx][ny] != 0:continue
            log[nx][ny] = log[x][y] + 1
            if (nx + 1, ny + 1) == (h, w):
                return h * w - i - log[nx][ny]

            q.append((nx, ny))

    return -1

h, w = map(int,input().split())
s = [list(input()) for i in range(h)]

cnt = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':cnt += 1
ans = bfs(cnt)
print(ans)

Measured memory_bytes: 3316
def main():
    n = input()
    a = b = ab = s = 0
    for _ in xrange(n):
        st = raw_input()
        s += st.count('AB')
        if st.endswith('A'):
            if st.startswith('B'):
                ab += 1
            else:
                a += 1
        elif st.startswith('B'):
            b += 1
    if ab > 1:
        s += ab - 1
        ab = 1
    if ab and a:
        s += 1
        a -= 1
    if ab and b:
        s += 1
        b -= 1
    print s + min(a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33388
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n,x,t; cin>>n>>x>>t;
  int cou = (n+(x-1))/x;
  cout << cou*t << endl;
}

Measured memory_bytes: 3544
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0

for ai in range(a+1):
    diff = x - 500 * ai
    if diff < 0:
        break
    for bi in range(b+1):
        diff = x - 500 * ai - 100 * bi
        if diff < 0:
            break
        # for ci in range(c+1):
        #     diff = x - 500 * ai - 100 * bi - 50 * ci
        #     if diff == 0:
        #         cnt += 1
        if diff % 50 == 0 and int(diff / 50) <= c:
            cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>

using namespace std;

int main() {
    long long int N, tmp = -1, count = 0, ans = 0;
    cin >> N;

    vector<long long int>A(N);

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

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

    for (int i = 0; i < N; i++) {
        if (A[i] != tmp) {
            ans += count % 2;
            tmp = A[i];
            count = 1;
        }
        else {
            count++;
        }
    }
    
    ans += count % 2;

    cout << ans;

    return 0;
}


Measured memory_bytes: 4048
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int n;
    cin >> n;
    vs s(n);
    rep(i, n)
    {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    map<string, int> memo;
    rep(i, n)
    {
        memo[s[i]]++;
    }
    ll result = 0;
    rep(i, n)
    {
        result += memo[s[i]] - 1;
    }
    cout << result / 2 << endl;
}

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

int main(){
	long long a,b,k;
	
	cin>>a>>b>>k;
  
	if(a > 0){
      	long long l = a;
		a = a - k;
		k = k - l;
		if(a < 0){
			a = 0;
		}
      	if(k < 0){
        	k = 0;
        }
	}
	if (b > 0){
		b = b - k;
		//k = k - b;
		if(b < 0){
			b = 0;
		}
	}
	cout<<a<<" "<<b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

ll Max(ll a,ll b,ll c){
    if(a<0){
        a=-inf;
    }
    if(b<0){
        b=-inf;
    }
    if(c<0){
        c=-inf;
    }
    ll ans=max(max(a,b),c);
    if(ans<0) return -2;
    return ans;
}

int main(){
    string s,t;cin>>s>>t;
    int dp[s.size()+1][t.size()+1];
    rep(i,0,s.size()){
        dp[i][0]=i;
    }
    rep(i,0,t.size()){
        dp[0][i]=i;
    }
    rep(i,0,s.size()-1){
        rep(j,0,t.size()-1){
            if(s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j];
            }else{
                dp[i+1][j+1]=min(min(dp[i][j+1],dp[i+1][j]),dp[i][j])+1;
            }
            //cout<<dp[i+1][j+1]<<' ';
        }
        //cout<<endl;
    }
    cout<<dp[s.size()][t.size()]<<endl;
    
    return 0;
}




Measured memory_bytes: 7100
li = list(map(int, input().split()))
count5 = count7 = 0
for l in li:
    if l == 5:
        count5 += 1
    elif l == 7:
        count7 += 1
    else:
        print("NO")
        exit()
if count5 == 2 and count7 == 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9060
#include <vector>
#include <iostream>
using namespace std;
int n, m, q, x, y; int group[100000]; vector<int> f[100000];
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++) group[i] = i, f[i].push_back(i);
	for(int i = 0; i < m; i++) {
		scanf("%d%d", &x, &y);
		if(group[x] == group[y]) continue;
		x = group[x], y = group[y];
		if(f[y].size() > f[x].size()) swap(x, y);
		for(int j = f[y].size() - 1; j >= 0; j--) {
			group[f[y][j]] = group[x];
			f[x].push_back(f[y][j]);
			f[y].pop_back();
		}
	}
	scanf("%d", &q);
	for(int i = 0; i < q; i++) {
		scanf("%d%d", &x, &y);
		printf("%s\n", group[x] == group[y] ? "yes" : "no");
	}
	return 0;
}

Measured memory_bytes: 9636
W,H,N = map(int,input().split())

Ws = [x for x in range(W + 1)]
Hs = [x for x in range(H + 1)]

for i in range(N):
    x_i,y_i,a = map(int,input().split())

    if a == 1:
        Ws = list(filter(lambda x: x >= x_i,Ws))
    if a == 2:
        Ws = list(filter(lambda x: x <= x_i,Ws))
    if a == 3:
        Hs = list(filter(lambda y: y >= y_i,Hs))
    if a == 4:
        Hs = list(filter(lambda y: y <= y_i,Hs))

if len(Ws) == 0 or len(Hs) == 0:
    print(0)
else:
    print((Ws[-1] - Ws[0]) * (Hs[-1] - Hs[0]))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int N;
int A[20];
int x[20][20];
int y[20][20];
 
int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}
 
void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for(int i = 1; i <= N; i++) {
            if(!(bits & (1 << (i-1)))) continue;
            for(int j = 1; j <= A[i]; j++) {
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
def solve():
    N, M, X, Y = map(int, input().split())
    x = list(map(int, input().split()))
    x.append(X)
    y = list(map(int, input().split()))
    y.append(Y)

    if max(x) < min(y):
        print('No War')
    else:
        print('War')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9088
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    if(n==2){
        cout << 1 << endl;
        return 0;
    }
    ll ans = 2;
    for(ll i=2;i*i<=n;++i){
        ll t = n;
        if(t%i==0){
            while(t%i==0){
                t/=i;
            }
            if(t%i==1){
                ans++;
            }
        }else if((t-1)%i==0){
            ll j = (t-1)/i;
            if(i==j){
                ans++;
            }else{
                ans+=2;
            }
        }
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i=0;i<7;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(Math.abs(a-b));
		}
	}

}

Measured memory_bytes: 17188
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1000000007;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

combination table(2e6);

int main(){
    int X, Y;
    cin >> X >> Y;
    if((X + Y) % 3){
        cout << 0 << endl;
        return 0;
    }
    int cnt = (X + Y) / 3;
    if(X < cnt || Y < cnt){
        cout << 0 << endl;
        return 0;
    }
    X -= cnt, Y -= cnt;
    cout << table.C(X + Y, X) << endl;
}


Measured memory_bytes: 31488
//
//  main.cpp

#include <iostream>
using namespace std;


int main(){
	int a,b,c,d,A,B,C,D;
	cin >> a >> b >> c >> d >> A >> B >> C >> D;
	cout << max(a+b+c+d,A+B+C+D) << endl;
	
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <iomanip>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n, k, s;
    cin >> n >> k >> s;
    for(ll i = 0; i < n; i++){
        if(i < k)
            cout << s << " ";
        else if(i>=k && s<1e+9)
            cout << s+1 << " ";
        else if(i>=k && s==1e+9)
            cout << 1 << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
    #include <iostream>
    #include <string>
    using namespace std;
     
    int main() {
        int A,B;
        cin>>A>>B;
        char S;
        for(int i=0;i<A+B+1;i++){
            cin>>S;
            if(i!=A){
                if(S<48 || S>57){
    	            cout<<"No"<<endl;
    	            return 0;
    	        }
            }
            else if(i==A){
                if(S!='-'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
        cout<<"Yes"<<endl;
    }


Measured memory_bytes: 256
"use strict";

const main = (input) => {
  const N = input.split('\n')[0]-0;
  const S = input.split('\n')[1].split("");
  let wmap = {};
  
  S.forEach(function(w){
    wmap[w] = wmap[w]?wmap[w]+1:1;
  });
  
  let ans = 1;
  Object.keys(wmap).forEach((w)=>{
    ans *= wmap[w]+1;
    ans = ans%1000000007;
  });

  console.log(ans-1);
}

const pow = (a,b) => {
  var ans = 1;
  for(var i=0;i<b;i++){
    ans=ans*a;
    if(ans>=1000000007){
      ans = ans%1000000007;
    }
  }
  return ans;
};

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 8644
while True:
    try:
        line = input()
    except:
        break
    a,b,c,d,e,f = map(int, line.strip().split())
    z = a * e - b * d
    x = c * e - b * f
    if x: x = x / z
    y = a * f - c * d
    if y: y = y / z
    print('{:.3f} {:.3f}'.format(x, y))

Measured memory_bytes: 6744