akhauriyash/Code-Regression huggingface dataset:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

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


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


friend_checker = UnionFind(N)
direct_friends = [0 for _ in range(N)]

for _ in range(M):
    A, B = map(int, input().split())
    friend_checker.union(A - 1, B - 1)
    direct_friends[A - 1] += 1
    direct_friends[B - 1] += 1

block = [[] for _ in range(N)]
for _ in range(K):
    C, D = map(int, input().split())
    block[C - 1].append(D - 1)
    block[D - 1].append(C - 1)

for i in range(N):
    ans = friend_checker.size(i) - direct_friends[i] - 1
    for l in block[i]:
        if friend_checker.same(i, l):
            ans -= 1
    print(ans)


Measured memory_bytes: 28728
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010

int A[maxn], B[maxn], n;

int main(){
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i]>>B[i];
	long long int ans= 0LL, cur=0LL;
	for (int i=n; i>=1; i--){
		long long int x= A[i]+cur;
		long long int rem= B[i]-x%B[i];
		if (x%B[i]==0) rem=0;
		ans+=rem;
		cur+=rem; 
	}	
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        for( ; ; ){
            String x = sc.next();
            if(x.equals("-")){
                 break;
            }
            for(int n = sc.nextInt() ; n > 0; n--){
                int a = sc.nextInt();
                x = x.substring(a) + x.substring(0,a);
            }
            System.out.println(x);
        }
        sc.close();
    }
}


Measured memory_bytes: 26164
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	M = 1;
	while (M*(M - 1) / 2 < N)M++;
	if (M*(M - 1) / 2 != N) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	L = 0;
	R = 1;
	vector<vector<int>>v(M);
	for (int i = 1; i <= N; i++) {
		v[L].push_back(i);
		v[R].push_back(i);
		R++;
		if (R == M) {
			L++;
			R = L + 1;
		}
	}
	cout << M << endl;
	for (auto i : v) {
		cout << i.size();
		for (auto j : i)cout << " " << j;
		cout << endl;
	}
	return 0;

}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i > b; i--)
#define repll(i, a, b) for (ll i = a; i < b; i++)

#define PI 3.14159

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

  int r;
  cin >> r;
  cout << 2 * PI * r << endl;

  return 0;
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n), f(n);
  rep(i,n)
    cin >> a[i];
  rep(i,n)
    cin >> f[i];
  sort(a.begin(), a.end(), greater<ll>());
  sort(f.begin(), f.end());

  ll l = 0, r = 1e12 + 1, mid, sum, ans;
  while (l <= r) {
    mid = (l + r) / 2;
    sum = k;
    rep(i,n)
      if (mid / f[i] < a[i])
        sum -= a[i] - mid / f[i];
    if (sum < 0) {
      l = mid + 1;
    } else {
      ans = mid;
      r = mid - 1;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
struct node{ll i, j, dis;};
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, m, sx, sy;
    cin >> h >> w >> m;
    string s[h];

    for(int i=0;i<h;i++){
    	cin >> s[i];
    	for(int j=0;j<w;j++){
    		if(s[i][j] == 'S') sx = j, sy = i;
    	}
    }

    ll dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
    ll ans = 1e9;

    queue<node> q;
    q.push({sy, sx, 0});
    bool used[h][w];
    memset(used,0,sizeof(used));
    used[sy][sx] = true;
    while(!q.empty()){
    	node now = q.front(); q.pop();
    	ans = min({ans, now.i, now.j, w - now.j - 1, h - now.i - 1});
    	if(now.dis == m) continue;
    	for(int k=0;k<4;k++){
    		ll y = now.i + dy[k];
    		ll x = now.j + dx[k];
    		if(x < 0 || y < 0 || x >= w || y >= h || s[y][x] == '#' || used[y][x]) continue;
    		used[y][x] = true;
    		q.push({y, x, now.dis + 1});
    	}
    }
    cout << (ans + m * 2 - 1) / m << endl;
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define M 200005
using namespace std;
struct node{
	int a,b;
	bool operator <(const node _)const{
		return b<_.b;
	} 
}t[M];
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&t[i].a,&t[i].b);
	sort(t+1,t+n+1);
	long long res=0;
	for(int i=1;i<=n;i++){
		res+=t[i].a;
		if(res>t[i].b){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}


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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

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

int main() {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}


Measured memory_bytes: 3576
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	string s;
	LL k;
	cin >> s >> k;
	int n = s.size();
	vint a(n);
	for(int i = 0; i < n; ++i){
		a[i] = s[i] - 'a';
	}
	for(int i = 0; i < n; ++i){
		if(a[i] && 26 - a[i] <= k){
			k -= 26 - a[i];
			a[i] = 0;
		}
	}
	a.back() = (a.back() + k) % 26;
	string t(n, '_');
	for(int i = 0; i < n; ++i){
		t[i] = a[i] + 'a';
	}
	cout << t << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, C;
	cin >> A >> B >> C;
	cout << min(A + B, min(B + C, C + A)) << endl;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


X, Y = map(int, input().split())

n = (X + Y) // 3
x = (2 * X - Y) // 3
y = (-X + 2 * Y) // 3
if (X + Y) % 3 or x < 0 or y < 0:
    print(0)
    exit()


def mod_com(n, r):
    MOD = 1000000007
    r = min(r, n - r)
    numer = denom = 1
    for i in range(1, r + 1):
        numer = numer * (n - r + i) % MOD
        denom = denom * i % MOD
    return numer * pow(denom, MOD - 2, MOD) % MOD


print(mod_com(n, x))


Measured memory_bytes: 39732
def GCD(m, n)
	return 0 if m == 0 || n == 0
	while m != 0 && n != 0
		if m > n then
			m %= n
		else
			n %= m
		end
	end
	return [m, n].max
end

def LCM(m, n)
	return 0 if m == 0 || n == 0
	return m * n / GCD(m, n)
end

a, v = gets.chomp.split.map(&:to_i)
b, w = gets.chomp.split.map(&:to_i)
t = gets.chomp.to_i

if v <= w then
	puts "NO"
	exit
end

kyori = v - w
puts (a-b).abs <= kyori * t  ? "YES" : "NO"
	



Measured memory_bytes: 14304
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstdint>
using namespace std;

const uint64_t kMax = UINT64_MAX;

bool isSq(uint64_t n) {
  for (uint64_t i = 0; i * i <= n; ++i) {
    if (i * i == n) {
      return true;
    }
  }
  return false;
}


int main()
{
  uint64_t n, d;
  vector<vector<int64_t> > v;

  cin >> n >> d;
  v.resize(n);
  for (uint64_t i = 0; i < n; ++i) {
    v[i].resize(d);
    for (uint64_t j = 0; j < d; ++j) {
      cin >> v[i][j];
    }
  }
  uint64_t count = 0;
  for (uint64_t i = 0; i < n; ++i) {
    for (uint64_t k = i + 1; k < n; ++k) {
      uint64_t sum = 0;
      for (uint64_t j = 0; j < d; ++j) {
        sum += (v[i][j] - v[k][j]) * (v[i][j] - v[k][j]);
      }
      count += isSq(sum);
    }
  }
  cout << count;

  return 0;
}





Measured memory_bytes: 256
#![allow(unused_imports, non_snake_case, dead_code)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

struct FenwikTree {
    size: usize,
    depth: usize,
    tree: Vec<i64>,
}
impl FenwikTree {
    fn new(n: usize) -> Self {
        let size = n;
        let mut v = size;
        let mut tmp = 0;
        while v > 0 {
            tmp += 1;
            v >>= 1
        }
        let depth = tmp;
        let tree = vec![0; size + 1];
        FenwikTree { size, depth, tree }
    }
    fn _bitsum(&self, mut i: usize) -> i64 {
        let mut ret = 0;
        while i > 0 {
            ret += self.tree[i];
            i ^= i & (1 + !i);
        }
        ret
    }
    fn bitsum(&self, l: usize, r: usize) -> i64 {
        self._bitsum(r) - self._bitsum(l)
    }
    fn bitadd(&mut self, mut i: usize, x: i64) {
        i += 1;
        while i <= self.size {
            self.tree[i] += x;
            i += i & (1 + !i);
        }
    }
    fn lower_bound(&self, x: i64) -> usize {
        let mut _sum: i64 = 0;
        let mut pos: usize = 0;
        let mut v: usize = 1 << self.depth;
        for _ in (0..self.depth).rev() {
            let k = pos + v;
            if k <= self.size && _sum + self.tree[k] < x {
                _sum += self.tree[k];
                pos = k;
            }
            v >>= 1;
        }
        pos + 1
    }
}

#[fastout]
fn main() {
    input! {
        N: usize, Q: usize,
        a: [i64; N],
        l: [(usize, usize, usize); Q]
    }
    let mut bit = FenwikTree::new(N);
    for i in 0..N {
        bit.bitadd(i, a[i]);
    }
    for &(t, x, y) in &l {
        if t > 0 {
            println!("{}", bit.bitsum(x, y));
        } else {
            bit.bitadd(x, y as i64);
        }
    }
    // println!("{}", N);
}

Measured memory_bytes: 37128
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

using namespace std;

int main() {
    int x , a;
    cin >> x >> a;
    if (x < a) {
        cout << 0 << endl;
    } else {
        cout << 10 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
    int ty[4] = {};
    int n;
    char s[3];
    while(scanf("%d,%s",&n,s)!=EOF){
        string str=s;
        if(str=="A"){
            ty[0]++;
        }else if(str=="B"){
            ty[1]++;
        }else if(str=="AB"){
            ty[2]++;
        }else if(str=="O"){
            ty[3]++;
        }
    }
    for(int i=0;i<4;i++){
        cout << ty[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

struct Node* treeMinimum(struct Node *x){
  while(x -> left != NIL) x = x -> left;
  return x;
}

struct Node* find(struct Node *u,int k){
  while(u != NIL && k != u -> key){
    if(k < u -> key) u = u -> left;
    else u = u -> right;
  }
  return u;
}

struct Node* treeSuccessor(struct Node *x){
  struct Node *y;
  if(x -> right != NIL) return treeMinimum(x -> right);
  y = x -> parent;
  while(y != NIL && x == y -> right){
    x = y;
    y = y -> parent;
  }
  return y;
}

void treeDelete(struct Node *z){
  struct Node *y;
  struct Node *x;

  if(z -> left == NIL || z -> right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y -> left != NIL){
    x = y -> left;
  } else{
    x = y -> right;
  }

  if(x != NIL){
    x -> parent = y -> parent;
  }

  if(y -> parent == NIL){
    root = x;
  } else{
    if(y == y -> parent -> left){
      y -> parent -> left = x;
    } else{
      y -> parent -> right = x;
    }
  }

  if(y != z){
    z -> key = y -> key;
  }

  free(y);
}

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node*)malloc(sizeof(struct Node));
  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;

  while(x != NIL){
    y = x;
    if(z -> key < x -> key){
      x = x -> left;
    } else{
      x = x -> right;
    }
  }
  z -> parent = y;
  if(y == NIL){
    root= z;
  } else{
    if(z -> key < y -> key){
      y -> left = z;
    } else{
      y -> right = z;
    }
  }
}

void inorder(struct Node *u){
  if(u == NIL) return ;
  inorder(u -> left);
  printf(" %d",u -> key);
  inorder(u -> right);
}

void preorder(struct Node *u){
  if(u == NIL) return ;
  printf(" %d",u -> key);
  preorder(u -> left);
  preorder(u -> right);
}

int main(){
  int n,i,x;
  char str[7];
  struct Node *t;
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s",str);
    if(strcmp(str,"find") == 0){
      scanf("%d",&x);
      t = find(root,x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(str,"insert") == 0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(str,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(strcmp(str,"delete") == 0){
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }
  return 0;
}

Measured memory_bytes: 19360
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

#define pb push_back
#define ll long long

using namespace std;

int A[200001], nums[200000];

int main() {
    int n;
    cin >> n;
    for(int i=0;i<n;i++) {
        int x;
        cin >> x;
        A[x]++;
        nums[i] = x;
    }
    ll total = 0;
    for(int i=1;i<=n;i++) {
        ll val = A[i];
        total += val*(val-1);
    }
    total /= 2;
    for(int i=0;i<n;i++) {
        int rem = A[nums[i]];
        if (rem==0) rem = 0;
        else rem--;
        cout << (total - rem) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3712
n = input()

def nine(s):
    st = ""
    for _ in range(s):
        st += "9"
    return st

if len(n) == 1:
    print(n)
    exit()

if int(n[0]) == 1:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 1)
        exit()
    else:
        print(9*(len(n) -1))
        exit()

if int(n[0]) == 2:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 2)
        exit()
    else:
        print(9*(len(n) -1) + 1)
        exit()

if int(n[0]) == 3:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 3)
        exit()
    else:
        print(9*(len(n) -1) + 2)
        exit()

if int(n[0]) == 4:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 4)
        exit()
    else:
        print(9*(len(n) -1) + 3)
        exit()

if int(n[0]) == 5:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 5)
        exit()
    else:
        print(9*(len(n) -1) + 4)
        exit()

if int(n[0]) == 6:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 6)
        exit()
    else:
        print(9*(len(n) -1) + 5)
        exit()

if int(n[0]) == 7:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 7)
        exit()
    else:
        print(9*(len(n) -1) + 6)
        exit()

if int(n[0]) == 8:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 8)
        exit()
    else:
        print(9*(len(n) -1) + 7)
        exit()

if int(n[0]) == 9:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 9)
        exit()
    else:
        print(9*(len(n) -1) + 8)
        exit()

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

//最大公約数GCD
ll gcd_ori(ll a, ll b){
    if(b == 0){
        return a;
    }

    return gcd_ori(b, a % b);
}

int main() {
    ll a, b; cin >> a >> b;

    if(a<b){
        int tmp=a;
        a = b;
        b = tmp;
    }

    ll c=a*b;
    c /= gcd_ori(a,b);

    cout << c << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <cassert>
#include <vector>
using namespace std;

struct point {
    double x, y;
    point() {}
    point(double x, double y): x(x), y(y) {}

    point operator + (const point& o) const { return point(x+o.x, y+o.y); }
    point operator - (const point& o) const { return point(x-o.x, y-o.y); }
    point operator * (const double a) const { return point(x*a, y*a); }
    bool operator < (const point& o) const { return x == o.x ? y < o.y : x < o.x; }
};

double abs(point p) {
    return sqrt(p.x*p.x + p.y*p.y);
}

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

bool has_intersect(point l1a, point l1b, point l2a, point l2b) {
    double c1a = cross(l1b - l1a, l2a - l1a), c1b = cross(l1b - l1a, l2b - l1a);
    double c2a = cross(l2b - l2a, l1a - l2a), c2b = cross(l2b - l2a, l1b - l2a);

    return c1a * c1b < 0 && c2a * c2b < 0;
}

point intersect(point l1a, point l1b, point l2a, point l2b) {
    assert(has_intersect(l1a, l1b, l2a, l2b));

    double c1 = abs(cross(l2b - l2a, l1a - l2a));
    double c2 = abs(cross(l2b - l2a, l1b - l2a));

    return l1a + (l1b - l1a) * (c1 / (c1 + c2));
}

struct railroad {
    point a, b;
    int owner;
    int loc;
    railroad() {}
};

int N;
railroad W;
vector<railroad> Ls;

int solve() {
    vector<pair<point, int>> ps;
    for (int i = 0; i < N; ++i) {
        if (has_intersect(W.a, W.b, Ls[i].a, Ls[i].b))
            ps.emplace_back(intersect(W.a, W.b, Ls[i].a, Ls[i].b), i);
    }

    if (ps.size() == 0) return 0;

    sort(begin(ps), end(ps));

    int h = (Ls[ps[0].second].owner == 1) ? Ls[ps[0].second].loc : (1 - Ls[ps[0].second].loc);
    int ans = 0;
    for (auto pr : ps) {
        railroad r = Ls[pr.second];
        if (h != (r.owner == 1 ? r.loc : 1 - r.loc)) {
            ++ans;
            h = 1 - h;
        }
    }

    return ans;
}

int main() {
    int T; cin >> T;
    W.owner = 1;
    for (int i = 0; i < T; ++i) {
        cin >> W.a.x >> W.a.y >> W.b.x >> W.b.y >> N;
        Ls.resize(N);
        for (int j = 0; j < N; ++j)
            cin >> Ls[j].a.x >> Ls[j].a.y >> Ls[j].b.x >> Ls[j].b.y
                >> Ls[j].owner >> Ls[j].loc;

        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll pr[mx],ar[mx],br[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
int main()
{
    faster();
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll sum=0;
    sum+=min(a,k);
    k-=a;
    if(k>0)
        k-=b;
    if(k>0)
        sum+=(-1*k);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3620
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var k = cin.nextInt();            
            Console.WriteLine(k%2==0? (k/2)*(k/2) : (k / 2) * (k / 2 +1));
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
x,k,d = map(int, input().split())

n = abs(x)//d
sign_x = 1 if x>0 else -1

if n>=k:  
  x -= sign_x*k*d
  print(abs(x))
else:
  cand = [x-sign_x*n*d, x-sign_x*(n+1)*d]
  rest_n = k-n
  if rest_n%2:
    print(abs(cand[1]))
  else:
    print(abs(cand[0]))

Measured memory_bytes: 9188
// Problem : D - Two Sequences
// Contest : AtCoder Regular Contest 092
// URL : https://atcoder.jp/contests/arc092/tasks/arc092_b
// Memory Limit : 256 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define temptts template <class T, class... Ts>

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n, ans = 0, a[N], b[N], cnt[N];

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	for (int k = 28; k >= 0; k--) {
		int x = 1 << k;
		for (int i = 1; i <= n; i++) {
			a[i] %= x << 1;
			b[i] %= x << 1;
		}
		sort(b + 1, b + n + 1);
		int cnt = 0;
		for (int i = 1, l, r; i <= n; i++) {
			r = lower_bound(b + 1, b + n + 1, 2 * x - a[i]) - b;
			l = lower_bound(b + 1, b + n + 1, x - a[i]) - b;
			cnt += r - l;
			r = lower_bound(b + 1, b + n + 1, 4 * x - a[i]) - b;
			l = lower_bound(b + 1, b + n + 1, 3 * x - a[i]) - b;
			cnt += r - l;
		}
		if (cnt & 1) {
			ans += x;
		}
	}
	cout << ans;
}


Measured memory_bytes: 8448
N, A, B, C, D = map(int, input().split())

def isOk():
    M = B - A
    R = D - C

    for k in range(N):
        Z = M - (N - 1 - 2 * k) * C
        if -R * k <= Z <= R * (N - 1 - k):
            return True
    return False

print('YES' if isOk() else 'NO')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v.begin(),v.end())
#define ff first
#define ss second
const ll maxn=2e5+10;
const ll mod=1e9+7;
 
int main() {
  	fast;
  	
  	ll r;
  	cin>>r;
  	double ans=2*( 3.14159265358979323846 )*r;
  	cout<<fixed<<setprecision(10)<<ans;
  	
}

Measured memory_bytes: 3800
a, b, c= input().split()
a, b, c = int(a), int(b), int(c)

if a>b and a>c:
  print(int((1/2 * b * c)))
  
if b>a and b>c:
  print(int((1/2 * a * c)))
  
else:
  print(int((1/2 * a *b)))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
//#include <array>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <stack>
//#include <queue>
using ll = long long;
using namespace std;

int main() {
	int N, T;
	cin >> N >> T;
	const int INF = 10000;
	int c_min = INF;
	for (int i = 0; i < N; i++)
	{
		int c, t;
		cin >> c >> t;
		if (t <= T) {
			c_min = min(c_min, c);
		}
	}
	if (c_min != INF) {
		cout << c_min << endl;
	}
	else {
		cout << "TLE" << endl;
	}
	return 0;
}


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

int main() {
   int n,k;
   cin>>n>>k;
   int arr[n];
   for(int i=0;i<n;i++){
       cin>>arr[i];
   }
   int dp[k+1]={0};
   dp[0]=0;
   for(int i=1;i<=k;i++){
       for(int j=0;j<n;j++){
           if(i-arr[j]<0)continue;
           if(dp[i-arr[j]]== 0)dp[i]=1;
       }
   }
   if(dp[k]==0)cout<<"Second";
   else cout<<"First";
}


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

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i, n){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll ans=0;
    ans += a[0];
    for(int i=1;i<=(n-1)/2;i++){
        ans += a[i]*2;
    }
    if(n%2==1) ans -= a[n/2];
    cout << ans << endl;
}

Measured memory_bytes: 4820
#include<iostream>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<string>
    #include<functional>
    using namespace std;
     
    #define INF (1<<21)
    #define MOD 1000000007

    int r[35][1000005];
   
    int main() {
        int N,C;
        int ans=0;
        cin>>N>>C;
        int s,t,c;
        
        for(int i=0;i<N;i++){
            cin>>s>>t>>c;
            s*=10;
            t*=10;
            s-=5;
            r[c][s]=1;
            r[c][t+1]=-1;
        }

        for(int i=1;i<=C;i++){
            for(int j=1;j<1000005;j++){
                r[i][j]+=r[i][j-1];
            }

        }

        int cnt;
        for(int i=0;i<1000005;i++){
            cnt=0;
            for(int j=1;j<=C;j++){
                if(r[j][i])cnt++;
            }
            ans=max(cnt,ans);
        }
        cout<<ans<<endl;
        return 0;

    }

Measured memory_bytes: 121088
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef vector <int> vi;
vi SIEVES;
vi sieve(int n){
    vi s;
    int i,j,m,x,h;
    for (i=1;i<n+2;i+=2) s.push_back(i);
    m=pow(n,0.5)+1;
	h=s.size();
    s[0]=0;
    for (i=0;i<h;i++){
        x=s[i];
        if (x>m) break;
        if (x&&x+i<h)
            for (j=i+x;j<h;j+=x) s[j]=0;
    }
	s[0]=2;
	return s;
}
int main(void){
	int m=105000,n,s,c,i;
	SIEVES=sieve(m);
	while (true){
		cin>>n;
		if (n==0) break;
		s=0;
		c=0;
		for(i=0;i<m;i++)
			if(SIEVES[i]!=0){
				s+=SIEVES[i];
				if(++c==n) break;
			}
		cout<<s<<"\n";
	}
} 

Measured memory_bytes: 1592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;
vector<pair<ll, ll>> prime_fact(ll n) {
    vector<pair<ll, ll>> v;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0)
            continue;
        ll cnt = 0;
        while (n % i == 0) {
            cnt++;
            n /= i;
        }
        v.emplace_back(i, cnt);
    }
    if (n != 1)
        v.emplace_back(n, 1);
    return v;
}
int main(){
    ll N, P;
    cin >> N >> P;
    const auto& v = prime_fact(P);
    ll ans = 1;
    for (auto x : v) {
        if (x.second >= N)
            ans *= pow(x.first, x.second / N);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4108
#include<iostream>

using namespace std;

long long GCD(long long a,long long b);
int main(){
    long long a,b;
    cin>>a>>b;
    cout<<GCD(a,b)<<endl;
}
long long GCD(long long a,long long b){
    while(b!=0){
        long long r=a%b;
        a=b;
        b=r;
    }
    return(a);
}


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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		String s = br.readLine();
		int len = s.length();
		 s = s.substring(0,len-8);
		System.out.println(s);
	}
}

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

int main() {
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def maxof(x, y):
    if x > y:
        return x
    return y

n=int(input())
a = list(map(int, input().strip().split()))
total=0
max_num=0
for i in range(len(a)):
    max_num=maxof(max_num,a[i])
    total=total+max_num-a[i]
print(total)


Measured memory_bytes: 32220
# coding: utf-8
n, t = map(int,input().split())
T = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    if T[i+1] - T[i] >= t:
        ans += t
    else:
        ans += T[i+1] - T[i]
print(ans+t)

Measured memory_bytes: 103980
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    if(N % 2) {
        cout << 0 << endl;
    } else {
        ll res = 0;
        ll cnt = 1;
        ll mul = 10;
        while(N / mul > 0) {
            res += N / mul;
            mul *= 5;
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
public class Program
{
    public static void Main(string[] args)
    {
        var xy = Console.ReadLine().Split(' ');
        var x = int.Parse(xy[1]);  //x,y なのか y,xなのか注意
        var y = int.Parse(xy[0]);
		if((x*y)%2==0)
        {
          Console.WriteLine("Even");
        }
      	else
        {
          Console.WriteLine("Odd");
        }
	}
}

Measured memory_bytes: 13140
#include<stdio.h>
#define N 1001
static int INFTY = (1<<21);

int n, G[N][N];
int color[N], b[N], f[N], tt;
int P[N*2], head, tail;

void init(){
  head = tail = 1;
}

void enqueue(int x){
  P[tail++] = x;
}

int empty(){
  return head == tail;
}

int dequeue(){
  int x = P[head++];
  return x;
}

void bfs(int s){
  int i, u, v;
  init();
  enqueue(s);
  for ( i = 0; i < n; i++ )b[i] = INFTY;
  b[s] = 0;
  while(!empty()){
    u = dequeue();
    for ( v = 0; v < n; v++ ){
      if ( G[u][v] == 0 ) continue;
      if ( b[v] != INFTY ) continue;
      b[v] = b[u] + 1;
      enqueue(v);
    }
  }
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i+1,((b[i]==INFTY)?(-1):b[i]));
  }
}

int main(){
  int  u, k, v, i, j; 
  scanf("%d", &n);
  for ( i = 0; i <n; i++ ){
    for ( j = 0; j <n; j++ ) G[i][j] = 0;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    u--;
    for ( j = 0; j < k; j++ ){
      scanf("%d", &v);
      v--;
      G[u][v] = 1;
    }
  }
  
  bfs(0);

  return 0;
}


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

using namespace std;
typedef  long long ll;
typedef unsigned long long ull;
const int inf_int=1e8;
const ll inf_ll=1e16;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double dbl;
#define pb push_back
const double pi=3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;

const int MAXN = 3e5+10;
const int LOG = 20;
const int mod =998244353;



int L[MAXN],R[MAXN];
ll get(int n){
    dout <<"start "<<endl;
    set<pii> l;
    set<pii> r;
    for(int i=1;i<=n;++i){
        r.insert({R[i],i});
        l.insert({L[i],i});
    }

    int cur  =0;
    ll ans =0;
    for(int i=1;i<=n;++i){
        int nxt = -1;
        if(i&1){
            nxt = l.rbegin()->se;
            if(L[nxt] < cur){
                break;
            }
            ans+=abs(L[nxt] - cur);
            cur = L[nxt];
        } else{
            nxt = r.begin()->se;
            if(R[nxt]>cur)
                break;
            ans+=abs(R[nxt] - cur);
            cur = R[nxt];
        }
      //  cout << cur<<" "<<ans<<endl;
        l.erase({L[nxt],nxt});
        r.erase({R[nxt],nxt});
    }
    ans+=abs(cur);
    dout <<"ans "<<ans<<endl;
    return ans;

}
void solve(){
    int n;
    cin >> n;
    for(int i=1;i<=n;++i){
        cin >> L[i] >> R[i];
    }
    ll ans = get(n);
    for(int i=1;i<=n;++i){
        L[i]=-L[i];
        R[i]=-R[i];
        if(L[i]>R[i])
            swap(L[i],R[i]);
    }
    ans = max(ans, get(n));

    cout << ans<<"\n";


}

signed main()
{
        #ifdef taow
           freopen("input.txt","r",stdin);
         //   freopen("output.txt","w",stdout);
        #else
        #endif // taow
        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        cout.setf(ios::fixed);
        cout.precision(20);



        int t = 1;
        while(t--)
            solve();
}


Measured memory_bytes: 10368
def read():
    board = []
    for _ in range(3):
        board.append([int(num) for num in input().split()])
    return board

board = read()
N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if board[i][j] == b:
                board[i][j] = True

good = False

for i in range(3):
    if board[i][0] == board[i][1] == board[i][2] == True:
        good = True
    if board[0][i] == board[1][i] == board[2][i] == True:
        good = True

if board[0][0] == board[1][1] == board[2][2] == True:
    good = True
if board[0][2] == board[1][1] == board[2][0] == True:
    good = True

if good:
    print("Yes")
else:
    print("No")


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


int main() {

	int N, Y;
	cin >> N >> Y;

	bool can = false;
	int ans_0=-1, ans_1=-1, ans_2=-1;
	for (int i = 0;i <= N;i++) {
		for (int j = 0;j <= N - i;j++) {
			if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
				can = true;
				ans_0 = i, ans_1 = j, ans_2 = N - i - j;
				break;
			}
		}
		if (can)
			break;
	}

		cout << ans_0 << " " << ans_1 << " " << ans_2;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# Rectangle
#	Write a program which calculates the area and perimeter of a given rectangle.

# Input
#	The length a and breadth b of the rectangle are given in a line separated by a single space.

# Output
#	Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.

# Constraints
#	1 ≤ a, b ≤ 100
# Sample Input 1
#	3 5
# Sample Output 1
#	15 16

a, b = (int(x) for x in input().split())
print(a * b, (a + b) * 2)



Measured memory_bytes: 5596
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	cout << (N - 1) / 2 << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
constexpr long long int mod = 1000000007, MOD = 998244353;
constexpr double PI = 3.14159265358979323846;

int main() {
	int X, N;
	cin >> X >> N;
	set<int> U;
	for (size_t i = 0; i < N; i++)
	{
		int z;
		cin >> z;
		U.insert(z);
	}
	for (size_t i = 0;true ; i++)
	{
		auto it = U.find(X - i);
		auto is= U.find(X + i);
		if (it == U.end()) { cout << X - i; return 0; }
		if (is == U.end()) { cout << X + i; return 0; }
	}
}

Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()


template <typename T>
void cout_vector(vector<T> A){
    for (T a : A) cout << a << " ";
cout << endl;
}

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(N);
    vector<int> B(M);
    rep(i, N) cin >> A[i];
    rep(j, M) cin >> B[j];
    vector<int> C;
    vector<int> D;
    C.push_back(0);
    D.push_back(0);

    for (int i = 1; i <= N; i++){
        if (C[i - 1] + A[i - 1] > K) break;
        C.push_back(C[i - 1] + A[i - 1]);
    }

    for (int j = 1; j <= M; j++){
        if (D[j - 1] + B[j - 1] > K) break;
        D.push_back(D[j - 1] + B[j - 1]);
    }


    int max_ans = -1;
    for (int i = 0; i < C.size() ; i++){
        int d = K - C[i];
        int left = -1;
        int right = D.size();
        while (abs(right - left) > 1){
            int mid = (left + right) / 2;
            if (D[mid] > d) right = mid;
            else left = mid;
        }
        int ans = i + left;
        max_ans = max(max_ans, ans);
    }
    cout << max_ans << endl;
}

Measured memory_bytes: 7068
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define eps 1e-14
#define m0(x) memset(x, 0, sizeof(x))

using namespace std;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int a, b, c;
  cin >> a >> b >> c;
  int tmp = a;
  int mod = 0;
  bool flag[101];
  
  fill(flag, flag+100, false);
  
  mod = tmp % b;
  do{
    flag[mod] = true;
    if(mod == c){
      cout << "YES" << endl;
      exit(0);
    }
    tmp += a;
    mod = tmp % b;
  }while(!flag[mod]);
  
  cout << "NO" << endl;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

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

    int n;
    cin >> n;

    vi a(n);
    rep(i, 0, n) { cin >> a[i]; }

    vi L(n);
    L[0] = a[0];
    rep(i, 1, n) { L[i] = gcd(L[i - 1], a[i]); }

    vi R(n);
    R[n - 1] = a[n - 1];
    rrep(i, 0, n - 1) { R[i] = gcd(R[i + 1], a[i]); }

    int ans = 0;
    rep(i, 0, n) {
        if (i == 0) {
            ans = max(ans, R[1]);
        } else if (i == n - 1) {
            ans = max(ans, L[n - 2]);
        } else {
            ans = max(ans, gcd(L[i - 1], R[i + 1]));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1536
import heapq
H = []
heapq.heapify(H)
while True:
    tmp = input().split()
    if tmp[0] == "end":
        break
    if tmp[0] == "insert":
        heapq.heappush(H, -int(tmp[1]))
    elif tmp[0] == "extract":
        ret = heapq.heappop(H)
        print(-ret)



Measured memory_bytes: 45308
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


ll a,b,c,d[100005] = {},n,m;
string s,t;

int main(){


    /*   cin >>  a >> b;

    b += a*3;

    P(b/2);
    */
    cin >> n;

    pair<string,pair<int,int>> p[n];

    rep(i,0,n){
	cin >> s >> a;
	p[i] = make_pair(s,make_pair(-a,i+1));
    }

    sort(p,p+n);

  
    rep(i,0,n){
	//PS(pp[i].ft);P(pp[i].sd);
	P(p[i].sd.sd);
    }
    return  0;
}


Measured memory_bytes: 256
loop do
  n = gets.to_i
  break if n==0

  map = [[0,0]]
  (n-1).times do
    a,b = gets.split.map(&:to_i)

    case b
    when 0
      map << [map[a][0]-1,map[a][1]]
    when 1
      map << [map[a][0],map[a][1]-1]
    when 2
      map << [map[a][0]+1,map[a][1]]
    when 3
      map << [map[a][0],map[a][1]+1]
    end
  end
  w,h = 0,0
  map.map{|x,y|x}.minmax.tap{|mi,ma| w = ma - mi}
  map.map{|x,y|y}.minmax.tap{|mi,ma| h = ma - mi}
  puts [w+1,h+1].join(" ")
end

Measured memory_bytes: 8756
#include <cstdio>
#include <queue>
#include <functional>
using namespace std;
using ll = long long;

int main(){
	int N;
	scanf("%d", &N);
	int a[N*3];
	for (int i = 0; i < N*3; ++i) scanf("%d", a + i);
	ll sum1 = 0, sum2 = 0;
	priority_queue<int, vector<int>, greater<int>> PQ1;
	priority_queue<int> PQ2;
	for (int i = 0; i < N; ++i){
		sum1 += a[i];
		PQ1.push(a[i]);
		sum2 += a[N*3 - 1 - i];
		PQ2.push(a[N*3 - 1 - i]);
	}
	ll former[N + 1], latter[N + 1];
	former[0] = sum1, latter[N] = sum2;
	for (int i = N; i < N*2; ++i){
		PQ1.push(a[i]);
		(sum1 += a[i]) -= PQ1.top();
		PQ1.pop();
		former[i - N + 1] = sum1;
		PQ2.push(a[N*3 - 1 - i]);
		(sum2 += a[N*3 - 1 - i]) -= PQ2.top();
		PQ2.pop();
		latter[N*2 - i - 1] = sum2;
	}
	ll answer = former[N] - latter[N];
	for (int i = 0; i < N; ++i) if(former[i] - latter[i] > answer) answer = former[i] - latter[i];
	printf("%lld\n", answer);
	return 0;
}

Measured memory_bytes: 3956