akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define MAX 10000
#define NIL -1

struct Node{
  int p, l, r;
};

struct Node T[MAX];

int n,D[MAX],H[MAX];

int getdepth(int u){
  int d = 0;
  while(1){
    
    u = T[u].p;
    
    if( u == NIL ){
      break;
    }
    
    d++;
  }
  
  return d;
}

int getsibling(int u){
  
  if( T[u].p == NIL ) {
    return NIL;
  }
  
  if( T[T[u].p].l != u && T[T[u].p].l != NIL ) {
    return T[T[u].p].l;
  }
  
  if( T[T[u].p].r != u && T[T[u].p].r != NIL ){
    return T[T[u].p].r;
  }
  
  return NIL;
}

void print(int u){

  int d = 0;
  
  printf("node %d: parent = %d, sibling = %d,",u,T[u].p,getsibling(u));
  
  if( T[u].l != NIL ){
    d++;
  }
  
  if( T[u].r != NIL ) {
    d++;
  }
  
  printf(" degree = %d, depth = %d, height = %d, ", d,D[u],H[u]);

  if( T[u].p == NIL ){
    printf("root\n");
  }
  
  else if( T[u].l == NIL && T[u].r == NIL){
    printf("leaf\n");
  }
  
  else{
    printf("internal node\n");
  }
  
}

int main(){
  
  int i, v, l, r;
  
  scanf("%d", &n);

  for(i=0;i<n;i++){
    T[i].p = NIL;
  }

  for(i=0;i<n;i++){
    
    scanf("%d%d%d",&v,&l,&r);

    T[v].l = l;
    

    T[v].r = r;
    if(l!=NIL){
      T[l].p = v;
    }
    
    if(r != NIL){
      T[r].p = v;
    }
  }

  for (i=0;i<n;i++){
    
    D[i] = getdepth(i);
    H[i] = 0;
    
  }

  for (i=0;i<n;i++){
    if(T[i].l == NIL && T[i].r == NIL){
      
      H[i] = 0;
      
      int p = T[i].p;
      int count = 1;
      
      while(1){
	
	if(p == NIL){
	  break;
	}
	
	if(H[p] < count){
	  H[p] = count;
	}
	
	count++;
	p = T[p].p;
      }
    }
  }

  for (i=0;i<n;i++){
    print(i);
  }
  
  return 0;
}



Measured memory_bytes: 2100
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] a = new long[3 * N];
    for(int i = 0; i < 3 * N; i++) {
      a[i] = sc.nextLong();
    }
    PriorityQueue<Long> pq = new PriorityQueue<Long>();
    long[] max = new long[N + 1];
    for(int i = 0; i < N; i++) {
      pq.add(a[i]);
      max[0] += a[i];
    }
    for(int i = 1; i < N + 1; i++) {
      pq.add(a[N + i - 1]);
      long m = pq.poll();
      max[i] = max[i - 1] + a[N + i - 1] - m;
    }
 
    PriorityQueue<Long> pq2 = new PriorityQueue<>(N, Collections.reverseOrder());
    long[] min = new long[N + 1];
    for(int i = 3 * N - 1; i > 2 * N - 1; i--) {
      pq2.add(a[i]);
      min[0] += a[i];
    }
    for(int i = 1; i < N + 1; i++) {
      pq2.add(a[2 * N - i]);
      long m = pq2.poll();
      min[i] = min[i - 1] + a[2 * N - i] - m;
    }
    long ans = -1000000000000000000l;
    for(int i = 0; i < N + 1; i++) {
      ans = Math.max(ans, max[i] - min[N - i]);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 100384
N = int(input())
As = input().split()

c_even = 0
c_odd = 0

for A in As:
  if int(A)%2 == 0:
    c_even += 1
  else:
    c_odd += 1

if c_even != 0 and c_odd%2 != 0:
  print("NO")
  exit(0)
print("YES")

Measured memory_bytes: 85328
from copy import copy

N = int(input())
D = []
for _ in range(N):
    D.append(int(input()))

DD = copy(D)
v1 = max(D)
m1 = D.index(v1)

del D[m1]
v2 = max(D)

[print(v2) if i == v1 else print(v1) for i in DD]

Measured memory_bytes: 82264
n, m = [int(n) for n in input().split(' ')]

s, c = [], []
for i in range(m):
    si, ci = [int(n) for n in input().split(' ')]
    s.append(si-1)
    c.append(ci)

ans = -1
for nn in range(1000):
    sn = str(nn)

    found = True
    if len(sn) == n:
        for si, ci in zip(s, c):
            if int(sn[si]) != ci:
                found = False
                break
    else:
        found = False

    if found:
        ans = nn
        break

print(ans)


Measured memory_bytes: 3064
A, B = list(map(int, input().split()))
S = input()

ans = 'Yes'

if S[A] != '-':
    ans = 'No'

if len(S) != A + B + 1:
    ans = 'No'

for i in range(len(S)):
    if i != A:
        if S[i] == '-':
            ans = 'No'

print(ans)

Measured memory_bytes: 3060
N, M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

cnt = 0
tmp = []
for a in A:
  for b in B:
    if(tmp != B):
      if(b in a):
        tmp.append(b)
    else:
      break
if(tmp == B):
  print("Yes")
else:
  print("No")


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

int main() {
	int n, h[50], cnt=0;
	cin>>n;
	int mx=0;
	for(int i=0; i<n; i++)
	{
        cin>>h[i];
        mx=max(mx, h[i]);
        if(h[i]>=mx) cnt++;
	}
	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

vector<int> as;

void f(const int N) {
    vector<int> ops(N + 1, 0);
    for (int i = 0; i < N; i++) {
        ops[max(0, i - as[i])]++;
        ops[min(N, i + as[i] + 1)]--;
    }

    int light = 0;
    for (int i = 0; i < N; i++) {
        light += ops[i];
        as[i] = light;
    }
}

void solve(const int N, const int K) {
    for (int i = 0; i < K; i++) {
        f(N);

        bool ok = true;
        for (int i = 0; i < N; i++) {
            if (as[i] < N) {
                ok = false;
                break;
            }
        }
        if (ok) {
            break;
        }
    }
}

int main(void) {
    int N, K;
    cin >> N >> K;

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

    solve(N, K);

    cout << as[0];
    for (int i = 1; i < N; i++) {
        cout << " " << as[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
	let (a,b,n): (u64,u64,u64) = (read(),read(),read());
	let ans = if n < b { (a*n/b)-a*(n/b) } else { (a*(b-1)/b)-a*((b-1)/b) };
	println!("{}", ans);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 2172
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  while (getline(cin, s), s != ".") {
    stack<char> t;
    rep(i, s.size()) {
      if (s[i] == '[' || s[i] == '(') t.push(s[i]);
      if (s[i] == ')') {
        if (t.size() && t.top() == '(') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
      if (s[i] == ']') {
        if (t.size() && t.top() == '[') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
    }
    cout << (t.size() ? "no" : "yes") << endl;
  next:;
  }
}

Measured memory_bytes: 2976
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define timer_start()                            \
    chrono::system_clock::time_point start, end; \
    start = chrono::system_clock::now();
#define timer_wrap()                                                       \
    end = chrono::system_clock::now();                                     \
    double time = static_cast<double>(                                     \
        chrono::duration_cast<chrono::microseconds>(end - start).count() / \
        1000.0);                                                           \
    printf("%lf[ms]\n", time);                                             \
    start = end;
#define optimize_cin() \
    cin.tie(0);        \
    ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
#define INF 1000000000    // 10^9
#define INFINF LLONG_MAX  // 2^63-1
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
// ########## template end ##########

#ifdef DEBUG_ON
void test_all();
#endif

const int N = 10000001;
vector<bool> is_prime(N, true);
vector<bool> forans(N, false);
vector<int> pr;

void prime_table() {
    is_prime.at(0) = false;
    is_prime.at(1) = false;
    for (int i = 0; i < N; i++) {
        if (!is_prime.at(i)) {
            continue;
        }
        for (int j = i + i; j < N; j += i) {
            is_prime.at(j) = false;
        }
    }
}
void build_ans() {
    ll tmp = 0;
    for (int i = 2; i < N / 2; i++) {
        if (!is_prime[i]) {
            continue;
        }
        for (int j = 1; j < N; j++) {
            tmp = pow(i, j);
            if (tmp > N && tmp > 0) {
                break;
            }
            forans[tmp] = true;
        }
    }
}
bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;  // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
void resolve() {
    prime_table();
    build_ans();
    ll n;
    cin >> n;
    ll ans = 0;
    if (isPrime(n)) {
        cout << 1 << endl;
        return;
    }
    for (ll i = 2; i < N; i++) {
        if (!forans[i]) {
            continue;
        }
        if (i > n) {
            break;
        }
        if (n % i == 0) {
            ans++;
            n = n / i;
        }
    }
    if (n > N) {
        ans++;
    }
    cout << ans << endl;
}

int main() {
#ifdef DEBUG_ON
    test_all();
#else
    resolve();
#endif
    return 0;
}


Measured memory_bytes: 5476
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline int read()
{
	int x=0;
	bool pos=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar())
		if(ch=='-')
			pos=0;
	for(;isdigit(ch);ch=getchar())
		x=x*10+ch-'0';
	return pos?x:-x;
}
char buf[4];
double x,ans=0;
int main()
{
	int n=read();
	for(int i=1;i<=n;++i)
		{
			scanf("%lf%s",&x,&buf);
			if(buf[0]=='J')
				ans+=x;
			else
				ans+=380000.0*x;
		}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
s = list(input())
yn = 0

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == 'L':
            yn = 1
    
    else:
        if s[i] == 'R':
            yn = 1

if yn == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int m,d; cin >> m >> d;

  int cnt = 0;
  for(int i = 1; i <= m; i++){
    for(int j = 11; j <= d; j++){
      int a = j%10;
      int b = j/10;
      if(a < 2 || b < 2) continue;
      if(a * b == i){
        cnt++;
        //cout << i << " " << j << " " << b << " " << a << endl;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#  B
R, G, B, N = [int(x) for x in input().split()]
RGB = [R, G, B]

cnt = 0
for i in range(N//R+1):
    g_range = (N - RGB[0]*i)//RGB[1]
    for j in range((N-R*i)//G+1):
        rem = N - R*i - G*j
        if rem % B == 0: 
            cnt += 1
print(cnt)

Measured memory_bytes: 3060
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (a, b, x) = read!(i64, i64, i64);

    let n = if a == 0 {
        b / x + 1
    } else {
        b / x - (a - 1) / x
    };

    println!("{}", n)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define LL long long
#define dl double
template <class T>
void rd(T &x){
  x=0;T f=1;char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  while(ch<='9' && ch>='0')x=x*10+ch-'0',ch=getchar();x*=f;
}
using namespace std;
int cnt[4];
char s[4][10]={"AC","WA","TLE","RE"};
int n;
int main(){
 // freopen("in.txt","r",stdin);
 // freopen("o.txt","w",stdout);
 rd(n);
 for(int i=1;i<=n;i++){
  char t[10];
  scanf("%s",t);
  if(t[0]=='A')cnt[0]++;
  if(t[0]=='W')cnt[1]++;
  if(t[0]=='T')cnt[2]++;
  if(t[0]=='R')cnt[3]++;
 }
 for(int i=0;i<4;i++)printf("%s x %d\n",s[i],cnt[i]);
 return 0;
}
/**/

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

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    uf.unite(a,b);
  }

  int ans = 0;
  rep(i,n) ans = max(ans, uf.size(i));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4028
N,A,B,C,D=map(int,input().split())
if N%A==0:
    X=int(N/A)*B
else:
    X=int(N/A+1)*B

if N%C==0:
    Y=int(N/C)*D
else:
    Y=int(N/C+1)*D
    
if X<Y:
    print(X)
else:
    print(Y)


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

int a, b;
int main() {
  cin >> a >> b;
  if (a <= 0 && b >= 0) {
    cout << "Zero\n";
  }
  else if (a >= 0) {
    cout << "Positive\n";
  }
  else {
    int d = b - a;
    if (d % 2 == 0) cout << "Negative\n";
    else            cout << "Positive\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> xm,xp;
    rep(i,N){
        ll x;
        cin >> x;
        if(x<0){
            xm.push_back(x);
        }else{
            xp.push_back(x);
        }
    }
    ll sz = xm.size();
    if(sz==0){
        cout << xp[K-1] << endl;
        return 0;
    }
    ll lim = min(K,sz);
    ll ans = INF;
    sort(xm.rbegin(),xm.rend());
    for(int i=0;i<lim;i++){
        if(xp.size()<=K-i-2) continue;
        ans = min(ans,2*abs(xm[i])+xp[K-i-2]);
        ans = min(ans,abs(xm[i])+2*xp[K-i-2]);
    }
    if(xp.size()>=K) ans = min(ans,xp[K-1]);
    if(sz>=K) ans = min(ans,abs(xm[K-1]));
    cout << ans << endl;
    return 0;
}

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

int main() {
  int K,A,B;
  cin>>K>>A>>B;
  for(int i=0;i<10000;i++){
    if(A<=K*i&&K*i<=B){
      cout<<"OK"<< endl;
      return 0;
    }
  }
  cout<<"NG"<< endl;
  
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> Qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> Qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ll n,a,b;
  cin >> n >> a;
  REP(i,4) {
    cin >> b;
    a=min(a,b);
  }
  ll ans=n/a+5;
  if(n%a==0)ans--;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

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

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

	sort(all(a), greater<int>());
	int ans1;
	ans1 = a[0];
	a.erase(a.begin());
	vector<int> b = a;

	for (int i = 0; i < N-1; i++) {
		int tmp = ans1 - a[i];
		a[i] = min(tmp, a[i]);
	}
	int index = 0;
	for (int i = 0; i < N; i++) {
		if(a[index]<a[i]){
			index = i;
		}
	}

	cout << ans1 << " " << b[index] << endl;

	return 0;
}

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

using namespace std;

int main () {
    int a, b, ans;
    char op;

    cin >> a >> op >> b;

    if(op == '+') {
        ans = a + b;
    } else if(op == '-') {
        ans = a - b;
    }

    cout << ans << endl;
}


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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

bool pal(string s, int l, int r) {
    while (l < r) {
        if (s[l] != s[r]) {
            return 0;
        }
        l++, r--;
    }
    return 1;
}

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

    string s;
    cin >> s;
    int n = s.size();
    if (n%2 == 1 and pal(s, 0, n-1) and pal(s, 0, (n-1)/2-1) and pal(s, (n+3)/2-1, n-1)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    cout << 24 + (24 - M) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long int
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 1e9+7
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp);
void ipgraph(int m);
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const int mod = 1e9 + 7;
const int N = 2e5+5, M = N;
//=========================================


int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    int a[n + 1];
    for(int i = 1; i <= n; ++i)
        cin >> a[i];

    int dp[n + 1][k + 1];
    dp[0][0] = 1;

    for(int i = 1; i <= k; ++i)
        dp[0][i] = 0;

    for(int i = 1; i <= n; ++i){
        vector<int> sum(k + 1);
        sum[0] = dp[i - 1][0];

        for(int j = 1; j <= k; ++j)
            sum[j] = (sum[j - 1] % mod + dp[i - 1][j] % mod) % mod;

        for(int j = 0; j <= k; ++j){
            int tmp = sum[j];
            int unreachable = j - a[i] - 1;

            if(unreachable >= 0)
                tmp = (tmp - sum[unreachable] + mod) % mod;

            dp[i][j] = tmp;
        }
    }

    cout << dp[n][k] << endl;

    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,k; cin>>n>>k;
	//for(int i=0;i<n;++i){int g;cin>>g;}
	cout<<(n-2)/(k-1)+1<<"\n"s;
}

Measured memory_bytes: 256
# EASY!数値をintでリスト化する方法を学んだ

n = int(input())
l = list(map(int,list(str(n))))
#print(l)
x = int(str(l[0])+str(l[0])+str(l[0]))
y = int(str(l[0]+1)+str(l[0]+1)+str(l[0]+1))

if n <= x:
    print(x)
else:
    print(y)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N, A, B; cin >> N >> A >> B;
    int ans = 0;
    while (N--) {
        int t; cin >> t;
        if (A > t || t >= B) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,c=map(int,input().split())\n"
"r=[[0,0]for _ in range(c)]\n"
"for s,t,c in sorted(list(map(int,input().split()))for _ in range(n)):\n"
"    for m in r:\n"
"        if m[0]<s-0.5or m[1]==c and m[0]<=s:\n"
"            m[0],m[1]=t,c\n"
"            break\n"
"print(len(list(filter(lambda x:x!=[0,0],r))))\n"
"\"";
  system(s);
  return 0;
}            

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

using namespace std;

int main(){
	//~ freopen("input.txt", "r", stdin);
	//~ freopen("output.txt", "w", stdout);
	int a;
	cin >> a;
	int ans = a + a * a + a * a * a;
	cout << ans << '\n';
	return 0;
}


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

#define _USE_MATH_DEFINES
#define reb(i,b,n)         for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n)           reb(i,0,n)
#define each(it,v)         for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v)        for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vsort(v)           sort((x).begin(), (x).end()
#define rvsort(v)          sort((x).rbegin(), (x).rend()
#define mp(a, b)           make_pair(a, b)
#define fi                 first
#define se                 second
#define pb                 push_back
#define dbg(x)             cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;
#define dbgArr(table, n)   rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define dbg2Arr(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}

using namespace std; using std::stringstream;

typedef long long       ll; typedef unsigned long long ull; typedef long double     ld;
typedef pair <int, int> P;  typedef pair <int, P>      PP;
typedef vector<int>     vi; typedef vector<vi>         vvi; typedef vector<ll>      vl;
typedef vector<P >      vP; typedef vector<char>       vc;  typedef vector<string>  vs;

static const int    INF  = 0x3f3f3f3f;
static const ll     INFL = 0x3f3f3f3f3f3f3f3fLL;
static const double EPS  = 1e-9;
static const ll     MOD  = 1000000007LL;

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

int main(int argc, char *argv[])
{
    int x;
    int cnt=0;
    rep(i, 5) {
        cnt++;
        cin >> x;
        if (x == 0) {
            cout << cnt << endl;
        }
    }

    return 0;
}


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

long long H, W, D;
long long A[305][305];
long long L[100005];
long long R[100005];
map<long long, pair<long long, long long> >posmap;
long long d[90010];

int main(){
	cin >> H >> W >> D;
	for(long long i = 0; i < H; i++){
		for(long long j = 0; j < W; j++){
			cin >> A[i][j];
			A[i][j]--;
			posmap[A[i][j]] = make_pair(i, j);
		}
	}
	long long Q;
	cin >> Q;
	for(long long i = 0; i < Q; i++){
		cin >> L[i] >> R[i];
		L[i]--;R[i]--;
	}

	for(long long i = D; i < H * W; i++)
		d[i] = d[i-D] + abs(posmap[i].first - posmap[i-D].first)
			      +	abs(posmap[i].second - posmap[i-D].second);

	for(long long i = 0; i < Q; i++){
		cout << d[R[i]] - d[L[i]] << endl;
	}
}

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

int a,b,c,d,S,T;

int main(){
    scanf("%d%d%d%d",&a,&b,&c,&d);
    S=a+b+c+d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    T=a+b+c+d;
    printf("%d\n",max(S,T));                                                                                                                                                                              
}       

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <complex>
using namespace std;

int main(void){
	double x,y;
	int q;
	cin>>x>>y;
	complex<double> p1(x,y);
	cin>>x>>y;
	complex<double> p2(x,y);
	cin>>q;
	while(q--){
		cin>>x>>y;
		complex<double> p(x,y);
		complex<double> p1p=p-p1;
		complex<double> p1p2=p2-p1;
		double r=abs(p1p);
		double t=arg(p1p)-arg(p1p2);
		r*=cos(t);
		complex<double> res=polar(r,arg(p2-p1))+p1;
		printf("%.8lf %.8lf\n",real(res),imag(res));
	}
	return 0;
}

Measured memory_bytes: 3692
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		for(;;){
			int n = sc.nextInt();
			
			if(n==0){
				break;
			}
			n = 1000 -n;
			int count = 0;
			int a[]= {500,100,50,10,5,1};
			for(int i =0 ;i < 6;i++){
 			count += n/a[i];
			n = n%a[i];
			}
			System.out.println(count);
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

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

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

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

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N; cin >> N;
    vec a(N), b(N), c(N);
    REP(i, N) cin >> a[i] >> b[i] >> c[i];
    mat dp(N, vec(3, -INF));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    FOR(i, 1, N){
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2]));
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main() {
    int w,h,n; cin >> w >> h >> n;
    int l = 0,r = w,u = h,d = 0;
    rep(i,n){
        int x,y,a; cin >> x >> y >> a;
        if(a == 1) l = max(l,x);
        if(a == 2) r = min(r,x);
        if(a == 3) d = max(d,y);
        if(a == 4) u = min(u,y);
    }
    if(l < r && d < u) cout << (r-l)*(u-d) << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(B<=C || D<A){cout<<0<<endl;}
    else{cout<<min({abs(A-D),abs(B-C),abs(A-B),abs(C-D)})<<endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long p(long long a,long long b){
    int res=1;
    while(b>0) {
        if(b&1) res=res*a %mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
int main() {
    long long n;
    scanf("%lld",&n);
    long long ans=p(10,n)-2*p(9,n)+p(8,n); 
	ans%=mod; 
	ans=(ans+mod)%mod;
    printf("%lld",ans);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int x = 1; x < 10000; x++)
    {
        if (x * x > n)
            break;
        for (int y = 1; y < 10000; y++)
        {
            if (y * y > n)
                break;
            for (int z = 1; z < 10000; z++)
            {
                if (z * z > n)
                    break;
                if (x * x + y * y + z * z + x * y + y * z + z * x <= n)
                    a[x * x + y * y + z * z + x * y + y * z + z * x - 1]++;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3608
using System;
class p
{
  static void Main()
  {
    string s = Console.ReadLine();
    int N = int.Parse(s);
    int n = 0;
    for (int i = 0; i < s.Length; i++) {
      n += int.Parse(s[i].ToString());
    }
    Console.WriteLine((N%n==0) ? "Yes" : "No");
  }
}

Measured memory_bytes: 13140
#include<stdio.h>


int main(void)
 {
     int x, y, z = 0;
     scanf("%d %d", &x, &y);
     while(1){
         if((x == 0) && (y == 0)){
             break;
         }
         if(x > y){
             z = x;
             x = y;
             y = z;
         }
         printf("%d %d\n", x, y);
         scanf("%d %d", &x, &y);
     }
     return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
double n, m, i, j, k, t, a, b, c, d, f, w, s, wt, st;
double pt, p, e;
set<double> water;
set<double> sugar;
set<double>::iterator it1;
set<double>::iterator it2;
int main(){
	cin>>a>>b>>c>>d>>e>>f;
	p=0;
	s=0;
	w=a;
	for(i=0;i<=30;i++){
		for(j=0;j<=30;j++){
			if(a*i+b*j<=30) water.insert(a*i+b*j);
		}
	}
	for(i=0;i<=1500;i++){
		for(j=0;j<=1500;j++){
			if(c*i+d*j<=1500) sugar.insert(c*i+d*j);
		}
	}
//	cout<<"Hi 1"<<endl;
	for(it1=water.begin();it1!=water.end();it1++){
		if(*it1==0) continue;
		for(it2=sugar.begin();it2!=sugar.end();it2++){
			//cout<<"Hi 3"<<endl;
			wt=(*(it1));
		//	cout<<"Hi 5"<<endl;
			st=(*(it2));
			pt=(double)st/(double)wt;
			//cout<<"Hi 4"<<endl;
			if(wt*100+st<=f&&pt>p&&pt<=e){
			//	cout<<"Hi 2 ";
			//	cout<<*it1<<*it2<<endl;
				p=pt;
				w=wt;
				s=st;
			}
		}
	}
	cout<<w*100+s<<" "<<s;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

// belik's shit
ll const mod = 1e9 + 7;
namespace {
	ll mult(ll& a, ll& b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) {
			val += mod;
		}
		if (val >= mod) {
			val -= mod;
		}
		return val;
	}
	ll poww(ll a, ll b)
	{
		ll val = 1;
		a %= mod;
		while (b > 0){
			if (b % 2) val = mult(a, val);
			a = mult(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

vector<ll>g[maxn];
bool used[maxn];
vector<ll>topsort;

void dfs(ll u) {
	used[u] = 1;
	for (ll v : g[u]) {
		if (!used[v])dfs(v);
	}
	topsort.push_back(u);
}
ll num[maxn], dp[maxn];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, m; cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll a, b; cin >> a >> b;
		g[a].push_back(b);
	}
	for (ll i = 1; i <= n; i++) {
		if (!used[i]) dfs(i);
	}
	reverse(all(topsort));
	for (ll i = 0; i < topsort.size(); i++) {
		num[topsort[i]] = i;
	}
	for (ll i = 0; i < topsort.size(); i++) {
		for (ll j : g[topsort[i]]) {
			dp[num[j]] = max(dp[i] + 1, dp[num[j]]);
		}
	}
	cout << *max_element(dp, dp + maxn);

	return 0;
}
/*

*/

Measured memory_bytes: 17140
def gcd(a,b):
 if b==0:
  return a
 return gcd(b,a%b)

while True:
 try:
  a,b=[int(i) for i in input().split()]
  print(gcd(a,b),(a*b)//gcd(a,b))
 except EOFError:
  break
  

Measured memory_bytes: 7680
let n = Int(readLine()!)!
let a = readLine()!.split(separator: " ").lazy.map(String.init).map { Int($0)! }

var acc = 0
var min = 0

for num in a {
  if min > num {
    acc = acc &+ (min - num)
  } else {
    min = num
  }
}

print(acc)


Measured memory_bytes: 21356
#include<stdio.h>
int main(void)
{
	int a,b,c,i,j,k;
	while(1)
	{
		scanf("%d %d", &a, &b);
		if(a==0&&b==0)
		break;
		c=0;
		for(i=1; i<a-1; i++)
		{
			for(j=i+1; j<a; j++)
			{
				for(k=j+1; k<=a; k++)
				{
					if(i+j+k==b)
					c++;
				}
			}
		}
		printf("%d\n", c);
	}
	
	return 0;
}


Measured memory_bytes: 2072
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int fg=0;
	while(n){
		if(n%10==7)
		fg=1;
		n/=10;
	} 
	if(fg)
	cout << "Yes" <<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3628
N = int(input())
X = list(map(int, input().split()))
Y = X.copy()
Y.sort()
for i in range(N):
	if X[i] < Y[int(N / 2)]:
		print(Y[int(N / 2)] )
	else:
		print(Y[int(N / 2 - 1)])

Measured memory_bytes: 25220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end() 
#define SZ(x) (int)x.size()
#define f first
#define s second
const int MAXN=7;
const int MAXK=18;
const int INF = 1e9;
const ll MOD = 998244353;

ll N,R,C;
ll A[MAXN][MAXN];
string S;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>R>>C>>N;
	for(int i=0;i<R;++i){
		cin>>S;
		for(int j=0;j<C;++j)if(S[j]=='#')A[i][j]=1;
	}
	ll ans=0;
	for(int i=0;i<(1<<R);++i){
		for(int j=0;j<(1<<C);++j){
			ll r=0;
			for(int k=0;k<R;++k)if((1<<k)&i){
				for(int l=0;l<C;++l)if((1<<l)&j){
					r+=A[k][l];
				}
			}
			if(r==N)++ans;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<time.h>
#include<assert.h>
#include<iostream>
using namespace std;
typedef long long LL;
typedef pair<int,int>pi;
int W,H;
int f[200020];
int find(int x){return x==f[x]?(x):(f[x]=find(f[x]));}
int main(){
	scanf("%d%d",&W,&H);
	vector<pi>V;
	for(int i=1;i<=W+H+2;i++)f[i]=i;
	for(int i=1;i<=W;i++){
		int x;scanf("%d",&x);
		V.push_back(pi(x,i));
	}
	for(int i=1;i<=H;i++){
		int x;scanf("%d",&x);
		V.push_back(pi(x,-i));
	}
	sort(V.begin(),V.end());
	LL ans=0;
	int cnt[2];
	cnt[0]=W+1,cnt[1]=H+1;
	for(int i=0;i<V.size();i++){
		int id=V[i].second,val=V[i].first;
		if(id>0){
			int u=find(id),v=find(id+1);
			if(u!=v){
				cnt[0]--;
				f[u]=v;
				ans+=1LL*val*(cnt[1]);
			}
		}
		else{
			id=-id;
			int u=find(id+W+1),v=find(id+W+2);
			if(u!=v){
				cnt[1]--;
				f[u]=v;
				ans+=1LL*val*(cnt[0]);
			}
		}
		//printf("ans=%lld id=%d\n",ans,id);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3188
import sys
input=sys.stdin.readline
x=int(input())
for a in range(101):
    for b in range(101):
        if a**5+b**5==x:
            print(a,-b)
            sys.exit()
for a in range(150):
    for b in range(150):
        if a**5-b**5==x:
            print(a,b)
            sys.exit()


Measured memory_bytes: 64920
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define RG register
#define LL long long
using namespace std;
const int N=2e6+10;
struct node{ int a,b; LL c; }pt[N];
int n,m,cnt,tot,fa[N];
LL minn[N],ans;
inline bool cmp(node a,node b){return a.c<b.c;}
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	return x*f;}
inline LL mi(LL a,LL b){return a<b ? a : b;}
inline int f(int son){return fa[son]= fa[son]==son ? son : f(fa[son]);}
int main()
{
	//freopen("Zigzag MST.in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(); m=read();
	memset(minn,0x3f,sizeof minn);
	for(int i=0;i<n;i++) fa[i]=i;
	for(int i=1,a,b,c;i<=m;i++)
	{
		a=read()%n; b=read()%n; c=read();
		pt[++cnt]={a,b,c};
		minn[a]=mi(minn[a],c+1);
		minn[b]=mi(minn[b],c+2);
	}
	for(int i=1;i<2*n;i++) minn[i%n]=mi(minn[i%n],minn[(i-1)%n]+2);
	for(int i=0;i<n;i++) pt[++cnt]=(node){i%n,(i+1)%n,minn[i]};
	sort(pt+1,pt+1+cnt,cmp);
	for(int i=1;i<=cnt;i++)
	{
		int fx=f(pt[i].a), fy=f(pt[i].b);
		if(fx==fy) continue;
		fa[fx]=fy;
		ans+=pt[i].c;
		if(++tot==n-1) return printf("%lld\n",ans), 0;
	}
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 27008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<62;

int main() {
  ll h,w,y,x;
  cin >> h >> w >> y >> x;
  if(h%y==0&&w%x==0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if(w%x) {
    vec s(w+1);
    for(ll i=w;i>=0;i--) {
      if(w-i<x) {
        s[i]=1;
      }
      else {
        s[i]=s[i+x]+1;
      }
    }
    s[0]=0;
    for(ll i=x;i<w;i+=x) {
      s[i]=s[i-x]-1;
    }
    vec a(w);
    for(ll i=0;i<w;i++) {
      a[i]=s[i+1]-s[i];
    }
    for(ll i=0;i<h;i++) {
      for(ll j=0;j<w;j++) {
        if(j) cout << " ";
        cout << a[j];
      }
      cout << endl;
    }
  }
  else {
    vec s(h+1);
    for(ll i=h;i>=0;i--) {
      if(h-i<y) {
        s[i]=1;
      }
      else {
        s[i]=s[i+y]+1;
      }
    }
    s[0]=0;
    for(ll i=y;i<h;i+=y) {
      s[i]=s[i-y]-1;
    }
    vec a(h);
    for(ll i=0;i<h;i++) {
      a[i]=s[i+1]-s[i];
    }
    for(ll i=0;i<h;i++) {
      for(ll j=0;j<w;j++) {
        if(j) cout << " ";
        cout << a[i];
      }
      cout << endl;
    }
  }
}

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

#define all(x) x.begin(),x.end()
#define pb push_back
#define ss second
#define ff first

int main(){
	int n, cnt=0;	cin>>n;
	vector<int>A(n);	for(int i=0;i<n;i++)	cin>>A[i];
	sort(all(A));
	for(int c=n-1;c>=2;c--){
		int a=0,b=c-1;
		while(a<b){
			if(A[a]+A[b] > A[c]){
				cnt+=(b-a);
				b--;
			}
			else
				a++;
		}
	}
	cout<<cnt<<endl;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if ((i + 1) % 2 && a[i] % 2) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
typedef long long int ll;
using namespace std;

int main(){
    int N,K;
    char kirai[10];
    cin >> N >> K;
    for(int k=0;k<K;k++){
        cin >> kirai[k];
    }
    bool flag=false;
    while(!flag){
        string str = to_string(N);
        int check=0;
        for(int i=0;i<str.size();i++){
            for(int k=0;k<K;k++){
                char s = str[i];
                char kk = kirai[k];
                if(s==kk) check=1;
            }
        }
        if(check==1){
            N++;
        }else{
            flag=true;
            cout << N << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
N = [0 for i in range(2*(10**5)+3)]
b = a.copy()
b.sort()
sum = 0
count = 1
for i in range(1,n):
    if b[i] != b[i-1]:
        sum += count*(count-1)//2
        N[b[i-1]]=count
        count=1
    else:
        count+=1
N[b[n-1]] = count
sum += count*(count-1)//2
for i in range(n):
    print(sum + (N[a[i]]-1) * (N[a[i]]-2) // 2 - N[a[i]] * (N[a[i]]-1)//2)

Measured memory_bytes: 26140
#include<bits/stdc++.h>
using namespace std;
int n;
bool p[5001][5001];
bool c(int a){return 0<=a&&a<=5000;}
int main(){
  while(cin>>n&&n){
    int x[5001],y[5001],an=0;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i],p[x[i]][y[i]]=1;
    for(int i=0;i<n;i++)
      for(int j=i;j<n;j++){
    int dx=x[i]-x[j],dy=y[i]-y[j];
    int x1=x[i]-dy,y1=y[i]+dx,x2=x[j]-dy,y2=y[j]+dx;
    int x3=x[i]-dy,y3=y[i]+dx,x4=x[j]+dy,y4=y[j]-dx;
    if(c(x1)&&c(y1)&&p[x1][y1]&&c(x2)&&c(y2)&&p[x2][y2])
      an=max(an,dx*dx+dy*dy);
    if(c(x3)&&c(y3)&&p[x3][y3]&&c(x4)&&c(y4)&&p[x4][y4])
      an=max(an,dx*dx+dy*dy);
      }
    cout<<an<<endl;
  }
  return 0;
}

Measured memory_bytes: 25004
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int) n;++i)
int main(){
  int x, n, m=1000, record;
  cin >> x >> n;
  vector<int> vec(n);
  vector<int> v(1000);
  if(n==0) {
    cout << x << endl;
    return 0;
  }
  rep(i,n) cin >> vec.at(i);
  rep(i, 102){
    rep(j,n){
      if(i==vec.at(j)){
        v.at(i)=1;
      }
    }
    if(v.at(i)==1) continue;
    int a=abs(x-i);
    if(a<m){
          record=i;
          m=min(m,a);
    }
  }
  cout << record << endl;
  //rep(i, 101-n) cout << S.at(i) << endl;
}
        


Measured memory_bytes: 3592
#include <stdio.h>
#include <assert.h>

#define MOD 1000000007

int dp[2][101][100001];

int isqrt(long long int x) {
	long long int a = x, b = (x+1)/2;
	while (a > b) {
		a = b;
		b = (a + x/a)/2;
	}
	return a;
}

int main(void) {
	long long int n;
	int k;
	scanf("%lld%d", &n, &k);

	int sqrt = isqrt(n)+1;

	dp[0][0][1] = 1;
	for (int i = 0; i < k; i++) {
		for (int j = 1; j < sqrt; j++) {
			dp[0][i][j] += dp[0][i][j-1];
			dp[0][i][j] %= MOD;
		}
		for (int j = 1; j < sqrt-1; j++) {
			dp[1][i][sqrt-j-1] += dp[1][i][sqrt-j];
			dp[1][i][sqrt-j-1] %= MOD;
		}

		for (int j = 1; j < sqrt; j++) {
			dp[0][i+1][j] = dp[0][i][sqrt-1] + dp[1][i][j];
			dp[0][i+1][j] %= MOD;

			if (n/j != j) {
				dp[1][i+1][j] = ((long long int) dp[0][i][j] * (n/j - n/(j+1))) % MOD;
			}
		}

	}

	int ans = 0;
	for (int i = 0; i < sqrt; i++) {
		ans = (ans + dp[0][k][i]) % MOD;
		ans = (ans + dp[1][k][i]) % MOD;
	}

	printf("%d\n", ans);
}


Measured memory_bytes: 76928
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    
    string S;
    ll K;
    cin >> S;
    cin >> K;
    
    ll n = 0;
    int a;
    
    rep(i,int(S.length())){
        if(S[i]-'0' == 1) n+=1;
        else{
            a = S[i]-'0';
            break;
        }
    }
    if(n>=K) cout << 1 << endl;
    else cout << a << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int A,B;
  scanf ("%d %d",&A,&B);
  if (A+B<A*B&&A-B<A*B) { 
      printf ("%d",A*B);
  } else {
        if (A+B<A-B&&A*B<A-B) {
            printf ("%d",A-B);
        } else {
            printf ("%d",A+B);
          }
         }  
  return 0;     
}


Measured memory_bytes: 1704
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static void Main()
    {
        var s = Console.ReadLine();
        if (s.StartsWith("YAKI"))
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a[11] = {0};
	rep (i, 3){
		int in; cin >> in;
		++a[in];
	} // end rep

	cout << (a[5] == 2 && a[7] == 1 ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256