akhauriyash/Code-Regression huggingface dataset:
class SegmentTree():
  def __init__(self, n, oper, e):
    self.n = n
    self.oper = oper
    self.e = e
    self.log = (n - 1).bit_length()
    self.size = 1 << self.log
    self.data = [e] * (2 * self.size)

  def update(self, k):
    self.data[k] = self.oper(self.data[2 * k], self.data[2 * k + 1])

  def build(self, arr):
    #assert len(arr) <= self.n
    for i in range(self.n):
      self.data[self.size + i] = arr[i]
    for i in range(self.size-1,0,-1):
      self.update(i)

  def set(self, p, x):
    #assert 0 <= p < self.n
    p += self.size
    self.data[p] = x
    for i in range(self.log):
      p >>= 1
      self.update(p)

  def get(self, p):
    #assert 0 <= p < self.n
    return self.data[p + self.size]

  def prod(self, l, r):
    #assert 0 <= l <= r <= self.n
    sml = smr = self.e
    l += self.size
    r += self.size
    while l < r:
      if l & 1:
        sml = self.oper(sml, self.data[l])
        l += 1
      if r & 1:
        r -= 1
        smr = self.oper(self.data[r], smr)
      l >>= 1
      r >>= 1
    return self.oper(sml, smr)

  def all_prod(self):
    return self.data[1]

  def max_right(self, l, f):
    #assert 0 <= l <= self.n
    #assert f(self.)
    if l == self.n: return self.n
    l += self.size
    sm = self.e
    while True:
      while l % 2 == 0: l >>= 1
      if not f(self.oper(sm, self.data[l])):
        while l < self.size:
          l = 2 * l
          if f(self.oper(sm, self.data[l])):
            sm = self.oper(sm, self.data[l])
            l += 1
        return l - self.size
      sm = self.oper(sm, self.data[l])
      l += 1
      if (l & -l) == l: break
    return self.n

  def min_left(self, r, f):
    #assert 0 <= r <= self.n
    #assert f(self.)
    if r == 0: return 0
    r += self.size
    sm = self.e
    while True:
      r -= 1
      while r > 1 and (r % 2): r >>= 1
      if not f(self.oper(self.data[r], sm)):
        while r < self.size:
          r = 2 * r + 1
          if f(self.oper(self.data[r], sm)):
            sm = self.oper(self.data[r], sm)
            r -= 1
        return r + 1 - self.size
      sm = self.oper(self.data[r], sm)
      if (r & -r) == r: break
    return 0

import sys
input = sys.stdin.readline

from math import gcd

e = 0

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

st = SegmentTree(N,gcd,e)
st.build(A)

ans = max(st.prod(1,N),st.prod(0,N-1))
for i in range(1,N-1):
  ans = max(ans, gcd(st.prod(0,i),st.prod(i+1,N)))
print(ans)

Measured memory_bytes: 85296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main(){
    ll A, B, C, D; cin >> A >> B >> C >> D;
    if(A+B < C+D) cout << "Right" << endl;
    else if(A+B>C+D) cout << "Left" << endl;
    else cout << "Balanced" << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long a = sc.nextInt();
		long b = sc.nextInt();
		long sum = 0;
		long pre = sc.nextInt();
		for (int i = 0; i < n - 1; i++) {
			long cur = sc.nextInt();
			sum += Math.min(a * (cur - pre), b);
			pre = cur;
		}
		System.out.println(sum);
	}

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


Measured memory_bytes: 30252
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "d.cpp"

int main() {
  ll n;
  cin >> n;
  vl a(n);
  cin >> a;
  ll q;
  cin >> q;

  vl cnt(1e5+1);
  ll sum = 0;
  rep(i, n) {
    cnt[a[i]]++;
    sum += a[i];
  }

  rep(i, q) {
    ll b, c;
    cin >> b >> c;
    sum -= cnt[b]*b;
    sum += cnt[b]*c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << el;
  }
}


Measured memory_bytes: 4788
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
int ans[100500],sz[100500];
int main(){
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    rep(i,1,n) sz[i]=1;
    ans[1]=1;
    rep(i,2,n) ans[i]=0;
    rep(i,1,m){
        scanf("%d%d",&x,&y);
        sz[x]--;
        sz[y]++;
        if (ans[x]) ans[y]=1;
        if (sz[x]==0&&ans[x]) ans[x]=0;
    }
    int cnt=0;
    rep(i,1,n) if (ans[i]) cnt++;
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	vector<int> a(n);
	for(int& x:a) cin>>x;
	sort(a.begin(),a.end());
	int mid1=a[n-1]/2,mid2=(a[n-1]+1)/2,best=2*a[n-1],res;
	for(int i=0;i<n-1;++i)
		if(a[i]<=mid1){
			if(mid1-a[i]<best){
				best=mid1-a[i];
				res=a[i];
			}
		}
		else if(a[i]>=mid2){
			if(a[i]-mid2<best){
				best=a[i]-mid2;
				res=a[i];
			}
		}
	cout<<a[n-1]<<' '<<res<<'\n';
}




Measured memory_bytes: 3612
#include<stdio.h>
int main(){
int i,n,c=1,m;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
scanf("%d",&a[i]);}
m=a[0];
for(i=1;i<n;i++){
if(a[i]<=m){c++;m=a[i];}}
printf("%d\n",c);
}

Measured memory_bytes: 2512
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::collections::HashSet;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
	let cin = stdin();
	let cin = cin.lock();
	let mut sc = Scanner::new(cin);
	let n : usize = sc.read();
    for _ in 0..n {
        let s : String = sc.read();
        let mut col = HashSet::new();
        for i in 1..s.len() {
            let mut f : String = s.chars().collect();
            let r : String = f.split_off(i).chars().collect();
            //println!("{} / {} ", f, r);
            col.insert(f.chars().collect::<String>()+r.as_str());
            col.insert(f.chars().rev().collect::<String>()+r.chars().rev().collect::<String>().as_str());
            col.insert(f.chars().collect::<String>()+r.chars().rev().collect::<String>().as_str());
            col.insert(f.chars().rev().collect::<String>() + r.as_str());
            col.insert(r.chars().collect::<String>()+f.as_str());
            col.insert(r.chars().rev().collect::<String>()+f.chars().rev().collect::<String>().as_str());
            col.insert(r.chars().collect::<String>()+f.chars().rev().collect::<String>().as_str());
            col.insert(r.chars().rev().collect::<String>() + f.as_str());
            
        }
        //col.iter().for_each(|x| println!("{}", x));
        println!("{}", col.len());
    }
}




Measured memory_bytes: 5060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    ll ans = 0;
    rep(i, b, w+1) {
        ans += COM(h-a-1+i, i) * COM(a+w-2-i, a-1) % MOD; 
    }
    ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 12160
from collections import deque

n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
p = 0
b = 0

qp = deque([])
qn = deque([])

for i in range(n):
    b += abs(a[i])
    if a[i] < 0:
        qn.append(a[i])
        p += 1
    else:
        qp.append(a[i])
if p != 0 and p != n:
    print(b)
    for i in range(n-2):
        if len(qp) >= 2:
            x = qn.popleft()
            y = qp.popleft()
            print(x,y)
            qn.append(x-y)
        else:
            x = qn.popleft()
            y = qp.popleft()
            print(y,x)
            qp.append(y-x)
    if len(qn) == 1 and len(qp) == 1:
        x = qn.popleft()
        y = qp.popleft()
        print(y,x)
    
elif p == 0:
    print(b-2*a[0])
    x = qp.popleft()
    y = qp.pop()
    print(x,y)
    qn.append(x-y)
    for i in range(n-3):
        x = qn.popleft()
        y = qp.popleft()
        print(x,y)
        qn.append(x-y)
    if len(qp) == 1 and len(qn) == 1:
        x = qn.popleft()
        y = qp.popleft()
        print(y,x)
    
else:
    print(b-2*abs(a[-1]))
    x = qn.popleft()
    y = qn.pop()
    print(y,x)
    qp.append(y-x)
    for i in range(n-3):
        x = qn.popleft()
        y = qp.popleft()
        print(y,x)
        qp.append(y-x)
    if len(qn) == 1 and len(qp) == 1:
        x = qn.popleft()
        y = qp.popleft()
        print(y,x)

Measured memory_bytes: 21284
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		boolean flag = false;
		int res = sc.nextInt();
		if( res < 0 || res > 100) {
			System.err.println("res is not in [0,100]");
			System.exit(1);
		}
		for( int j = 1 ; j <= 9 ; j++) {
			for(int k = 1 ; k <= 9 ; k++) {
				if( (j * k) == res) {
					flag = true;
					break;
				}
			}
		}
		if( flag ) {
			System.out.println( "Yes" );
		}
		else {
			System.out.println("No");
		}
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll X,Y;

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

  cin>>X>>Y;
  ll res=0;
  if(X==1&&Y==1){
    res+=400000;
  }
  if(X<=3)res+=100000*(4-X);
  if(Y<=3)res+=100000*(4-Y);
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 764
w, a, b = gets.split.map(&:to_i)

c = w + a
d = w + b

if c <= b
  if c == b
    puts 0
  else
    puts b - c
  end
elsif d <= a
  if d == a
    puts 0
  else 
    puts a - d
  end
else
  puts 0
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int a[MAXn],b[MAXn];
int main(){
  IOS();
  int n;
  cin>>n;
  REP(i,n) cin>>a[i];
  REP(i,n) cin>>b[i];
  int ans = 0;
  REP(i,n){
    int tmp = 0;
    REP(j,i+1) tmp+=a[j];
    for(int j=i;j<n;j++) tmp+=b[j];
    chkmax(ans,tmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		int ans = b;

		if (n * a < b) {
			ans = n * a;
		}

		System.out.println(ans);

	}

}


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

int main() {
  string s;
  cin >> s;
  int gx, gy;
  cin >> gx >> gy;

  // ヨコ移動とタテ移動に分ける
  int xx, mode = 0, count = 0, tokubetu = 1;
  vector<int> idox, idoy;
  for (int i = 0; i <= s.size(); i++) {
    if (s[i] == 'T' || i == s.size()) {
      if (tokubetu)
        xx = count, tokubetu = 0;
      else if (mode == 0)
        idox.push_back(count);
      else
        idoy.push_back(count);
      mode ^= 1;
      count = 0;
    } else {
      count++;
    }
  }

  set<int> cangox = {0}, cangoy = {0};

  // ヨコ移動について
  for (auto sa : idox) {
    set<int> res(cangox);
    cangox.clear();
    for (auto x : res) {
      cangox.insert(x + sa);
      cangox.insert(x - sa);
    }
  }

  // タテ移動について
  for (auto sa : idoy) {
    set<int> res(cangoy);
    cangoy.clear();
    for (auto y : res) {
      cangoy.insert(y + sa);
      cangoy.insert(y - sa);
    }
  }

  if (cangox.count(gx - xx) && cangoy.count(gy))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 768
import std.stdio;
import std.string;
import std.conv;

void main() {
    
    int[100] n;
    
    // input
    for(int i=0; ; ++i) {
        auto temp = readln().chomp;
        n[i] = to!int(temp);
        
        if(n[i] == 0) {
            break;
        }
    }
    
    for(int i=0; ; ++i) {
        
        if(n[i] == 0) {
            break;
        }
        
        int num;
        int devide = 5;
        
        for(int j=0;; ++j) {
            int delta = n[i] / devide;
            if(delta == 0) {
                break;
            }
            
            num += delta;
            devide *= 5;
        }
        
        writefln("%d", num);
    }
    
}

Measured memory_bytes: 2392
#include<stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x+r<=W&&y+r<=H&&x-r>=0&&y-r>=0){
        printf("Yes\n");
    }else printf("No\n");
    return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

signed main(){
	int N, T;
	cin >> N >> T;
	vector<int> A(N + 1), B(N + 1);
	A[0] = B[0] = (int)1e18;
	for(int i = 1; i <= N; ++i) {
		cin >> A[i];
		B[i] = min(A[i], B[i-1]);
	}
	int d = 0;
	for(int i = 1; i <= N; ++i) {
		d = max(d, A[i] - B[i - 1]);
	}
	int res = 0, u = A[N], ucnt = 0, lcnt = 0;
	for(int i = N; i >= 0; --i) {
		if(A[i] > u) {
			if(ucnt > 0 && lcnt > 0) {
				res += min(ucnt, lcnt);
			}
			ucnt = 1;
			lcnt = 0;
			u = A[i];
		} else if(A[i] == u) {
			++ucnt;
		} else if(A[i] == u - d) {
			++lcnt;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
N,W=map(int,input().split())

jwels=[]

for _ in range(N):
    jwels.append(list(map(int,input().split())))

dp=[10**10]*(10**5+1)
dp[0]=0

for w,v in jwels:
    for i in range(10**5+1)[::-1]:
        if dp[i]!=10**10 and i+v<=10**5:
            dp[i+v]=min(dp[i]+w,dp[i+v])

#print(dp[:100])

for i in range(10**5+1)[::-1]:
    if dp[i]<=W:
        print(i)
        break




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

int main(){
    string a, b;
    cin >> a >> b;
    string num = a+b;
    int numm = stoi(num);
    bool bo = false;
    for(int i = 4; i <= 1000; i++){
        if(i*i == numm)bo = true;
    }
    if(bo){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int a,b,c;
int tot;
int main(){
	cin >> a >> b >> c;
	int minn = min(a,b);
	for(int i = minn; i > 0; i--){
		if(a % i == 0 && b % i == 0) tot++;
		if(tot == c){
			cout << i;
			return 0;
		}
	}
}
 

Measured memory_bytes: 256
// ref: https://atcoder.jp/contests/abc054/submissions/8585283
#include <bits/stdc++.h>
using namespace std;

void search(int& sum, const vector<vector<int>>& mat, vector<int>& vecIsUsed, int r, int steps){
    if(steps == mat.size()-1){ ++sum; return; }
    
    for(int i=1; i<mat.size(); ++i){
        if(mat[r][i]==0 || vecIsUsed[i]==1){ continue; }
        vecIsUsed[i] = 1;
        search(sum, mat, vecIsUsed, i, steps+1);
        vecIsUsed[i] = 0;
    }
    return;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, M;
    cin >> N >> M;
    vector<vector<int>> mat(N, vector<int>(N, 0));
    
//    for(int i=0; i<N; ++i){
    for(int i=0; i<M; ++i){
        int a; cin >> a; --a;
        int b; cin >> b; --b;
        mat[a][b] = 1;
        mat[b][a] = 1;
    }
    
    vector<int> vecIsUsed(N, 0);
    int sum=0;
    search(sum, mat, vecIsUsed, 0, 0);
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
/* ex3_2
   key_tree */

#include <stdio.h>

int main(void){
  int N;
  //　入力の受け取り
  scanf("%d\n", &N);
  // 1の位を考えるので10で割った余りを用いる
  int mod = N % 10;
  //　あとは条件分岐
  if(mod == 3){
    printf("bon\n");
  }
  else if(mod == 0||mod == 1||mod == 6||mod == 8){
    printf("pon\n");
  }
  else{
    printf("hon");
  } 
  return 0;
    
  }

Measured memory_bytes: 1728
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  3005

string s;
string t;
ll n,m;
ll dp[N][N];
pii bt[N][N];

ll solve(ll i, ll j){
	if(i<0 or j<0)return 0;
	if(dp[i][j]!=-1){
		return dp[i][j];
	}
	if(s[i]==t[j]){
		bt[i][j]={i-1,j-1};
		return dp[i][j]=solve(i-1,j-1)+1;
	}
	else{
		ll a=solve(i-1,j);
		ll b = solve(i-1,j-1);
		ll c= solve(i,j-1);
		if(a>b){
			if(a>c){
				bt[i][j]={i-1,j};
			}
			else{
				bt[i][j]={i,j-1};
			}
		}
		else{
			if(b>c){
				bt[i][j]={i-1,j-1};
			}
			else{
				bt[i][j]={i,j-1};
			}
		}
		return dp[i][j]=max(a,max(b,c));
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	rep(i,0,N)rep(j,0,N)dp[i][j]=-1;
	while(TESTS--)
	{
		cin>>s>>t;
		n=sz(s);
		m=sz(t);
		solve(n-1,m-1);
		ll i=n-1,j=m-1;
		vector<char> v;
		while(i>=0 and j>=0){
			if(s[i]==t[j])v.pb(s[i]);
			pii temp = bt[i][j];
			i=temp.F;
			j=temp.S;
		}
		reverse(all(v));
		for(auto i:v)cout<<i;
		cout<<endl;
	}
	return 0;
}

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

int main(){
  int N, D;
  cin >> N >> D;
  int X[N][D];
  for(int i=0; i<N; i++){
    for(int j=0; j<D; j++) cin >> X[i][j];
  }
  int ans=0, cal=0;
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      cal=0;
      for(int k=0; k<D; k++){
        cal += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
      }
      ans += (float)(sqrt(cal)) == (int)(sqrt(cal));
    }
  }
        
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    L, *A = map(int, open(0))

    D = [(2, 1), (1, 0), (0, 1)]

    s0 = s1 = s2 = s3 = s4 = 0

    for a in A:
        e, o = D[(a - 1) % 2 + 1 if a else 0]

        s0 += a
        s1 = min(s0, s1 + e)
        s2 = min(s1, s2 + o)
        s3 = min(s2, s3 + e)
        s4 = min(s3, s4 + a)

    print(min(s0, s1, s2, s3, s4))


if __name__ == '__main__':
    main()

Measured memory_bytes: 11036
S = str(input())
T = str(input()) 
s = list(S)
t = list(T)
p = 1
for i in range(len(s)):
    if s == t:
        p = p*0
    else:
        p = p*1
    s.insert(0,s[len(s)-1])
    del s[len(s)-1]
if p == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;


int main(void)
{
	//変数の宣言
	char s[100010];
	int n;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	int ok,ng;
	int r;


	//データの読み込み

/*
//	scanf("%d %d",&n,&m);
	scanf_s("%d %d",&n,&m);

	for(i=0;i<m;i++){
//		scanf("%d %d",&a[i],&b[i]);
		scanf_s("%d %d",&a[i],&b[i]);
		graph[a[i]].push_back(b[i]);
		graph[b[i]].push_back(a[i]);
	}
	*/

	scanf("%s",s);
//	scanf_s("%s",s,100010);

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	n=strlen(s);

	if(s[0]!='1'||s[n-2]!='1'||s[n-1]!='0'){
		printf("-1");
		return 0;
	}

	for(i=1;i<n-2;i++){
		if(s[i]!=s[n-i-2]){
			printf("-1");
			return 0;
		}
	}

	temp1=1;
	temp2=2;
	for(i=0;i<=n-2;i++){
		if(s[i]=='1'){
			printf("%d %d\n",temp1,temp2);
			temp1=temp2;
			temp2++;
		}else{
			printf("%d %d\n",temp1,temp2);
			temp2++;
		}
	}

	//	printf("計算部分終了\n");

	//出力

	


	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 1536
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = ~~arg[0];
    const b = arg[1].split(" ").map(n=>~~n);
    
    const minusCnt = b.filter(n=>n<0).length;
    
    
    if(minusCnt % 2 === 0) {
        console.log(b.map(n=>Math.abs(n)).reduce((m,n)=>m+n));
    } else {
        console.log(b.map(n=>Math.abs(n)).reduce((m,n)=>m+n) - (b.map(n=>Math.abs(n)).sort((a,b)=>a-b)[0] * 2));
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30052
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int len = (a-b)-1;
    if(len % 2 == 0) cout << "Borys" << endl;
    else cout << "Alice" << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

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

int m,d;

int main(){
	
	while(cin>>m>>d,!(m==0&&d==0)){
		if(m==2){
			d+=31;
		}
		if(m==3){
			d+=60;
		}
		if(m==4){
			d+=91;
		}
		if(m==5){
			d+=121;
		}
		if(m==6){
			d+=152;
		}
		if(m==7){
			d+=182;
		}
		if(m==8){
			d+=213;
		}
		if(m==9){
			d+=244;
		}
		if(m==10){
			d+=274;
		}
		if(m==11){
			d+=305;
		}
		if(m==12){
			d+=335;
		}
		d = d%7;
		if(d==0) cout<<"Wednesday\n";
		if(d==1) cout<<"Thursday\n";
		if(d==2) cout<<"Friday\n";
		if(d==3) cout<<"Saturday\n";
		if(d==4) cout<<"Sunday\n";
		if(d==5) cout<<"Monday\n";
		if(d==6) cout<<"Tuesday\n";
	}
	return 0;
	
}

Measured memory_bytes: 1120
#include "bits/stdc++.h"

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int a, b;
  cin >> a >> b;
  if (a * b % 2 == 1) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n = int(open(0).read())
from math import ceil
m = ceil((2*n)**0.5)

from collections import defaultdict

c = defaultdict(int)

for k in range(m):
    for i in range(1,k):
        for j in range(1,k-i):
            x,y,z=i,j,k-i-j
            if z>0:
                val = x**2+y**2+z**2+x*y+y*z+z*x
#                 print(x,y,z,val)
                c[val] += 1

for i in range(1,n+1):
    print(c[i])

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

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;

  vector<int> b(m);
  rep(i, m) cin >> b.at(i);

  int count = 0;
  rep(i, n) {
    int sum = 0;
    int a;
    rep(j, m) {
      cin >> a;
      sum += a * b.at(j);
    }
    if (0 < sum + c) count++;
  }
  cout << count << endl;
}


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

int main()
{
    string str;
 
    while (1) {
        cin >> str;

        if (str == "0") break;
    
        long sum = 0;
    
        for (int i = 0; i < str.length(); i++) {
            char ch = str.at(i);
            if (isdigit(static_cast<unsigned char>(ch))) {
                sum += ch - '0';
            }
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 3176
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int main() {
	double a, b, c;
	char n, m;
	while (cin >> a >> n >> b >> m >> c) {
		if (b / (c*c) >= 25) { cout << a << endl; }
	}
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N,K;
  cin>>N>>K;
  if(2*K-1<=N){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 3616
#include<stdio.h>
int main(void){
    int H,M,i,j;
    while(1){
        scanf("%d %d",&H,&M);
        if(H==0&&M==0)break;
        for(i=0;i<H;i++){
            for(j=0;j<M;j++){
                if(i%2==0){
                    if(j%2==0){
                        printf("#");
                    }
                    else{
                        printf(".");
                    }
                }
                    else if(i%2==1){
                            if(j%2==1){
                        printf("#");
                            }
                            else{
                                printf(".");
                            }
                    }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
package main

import (
  "fmt"
)

func main() {
  var n, x int
  fmt.Scan(&n, &x)
  l := make([]int, n)
  for i := 0; i < n; i++ {fmt.Scan(&l[i])}
  d := 0
  for i := 0; i < n; i++ {
    d += l[i]
    if d > x {
      fmt.Println(i + 1)
      return
    }
  }
  fmt.Println(n + 1)
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

ll pow_mod(ll a, ll b, ll m = mod){
    ll ret = 1;
    while (b > 0) {
        if (b & 1) {
            ret = ret * a % m;
        }
        a = a * a % m;
        b >>= 1;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    vector<ll> A(K + 1);
    for(ll d = K; d >= 1; d--) {
        ll cnt = pow_mod((K / d), N);
        for(ll e = 2; e * d <= K; e++) {
            cnt -= A[e * d];
            cnt += mod;
            cnt %= mod;
        }
        A[d] = cnt;
        ans += A[d] * d;
        ans %= mod;
    }
    
    output(ans);
    
    return 0;
}


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

int main()
{
	int n, r;
	cin >> n >> r;
	if (r == 10) {
		cout<<((int)log10(n) + 1);
	}
	else {
		cout<<((int)(log10(n)/log10(r))+1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
set<char>st;
int main()
{
   int n=D();
   for(int i=0;i<n;++i){
    char c;
    cin>>c;
    st.insert(c);
   }
   if(st.size()==4)
    cout<<"Four"<<endl;
   else
    cout<<"Three"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define mod 1000000007
#define wi while
#define vtr vector<ll>
#define endl "\n"
#define BLOCK 500
//a = 2,b = 3, c = 5, d=+-1
ll N,A,B,C,D;
ll INF = 5e18;
void min_self(ll &a,ll b)
{
	a = min(a,b);
}
map<ll,ll> mapka;
ll f(ll goal)
{
	if(goal==0)
	return 0;
	if(goal==1)
	return D;
	if(mapka.count(goal))
	{
		return mapka[goal];
	}
	ll best = INF;
	if(D < INF/goal)
	{
		min_self(best,D * goal);
	}

	for(int i = 0; i< 3;i++)
	{
		int mul = vector<int>{2,3,5}[i];
		ll cost = vector<ll> {A,B,C}[i];
		if(goal % mul==0)
		{
			min_self(best,cost+f(goal/mul));
		}
		else
		{
			ll down = goal/mul * mul;
			min_self(best,cost+D*(goal-down) + f(goal/mul));
			ll up = down + mul;
			min_self(best,cost+D*(up-goal)+f(goal/mul+1));
		}
	}
	return mapka[goal] = best;

}
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--)
	{
		mapka.clear();
		cin>>N>>A>>B>>C>>D;
		cout<<f(N)<<endl;

	}

	return 0;
}


Measured memory_bytes: 4380
N, A = gets.split(/ /).collect{|i| i.to_i}


list_s = []
count_j = 0
list_l = []

gets.split(/ /).collect{|x|
	x = x.to_i
	if x == A
		count_j += 1
	elsif x < A
		list_s << (A - x)
	elsif
		list_l << (x - A)
	end
}

def make_patterns(list)
	results = {0 => 1}
	
	list.each{|x|
		new_results = {}
		results.each{|sum, count|
			if new_results[sum]
				new_results[sum] += count
			else
				new_results[sum] = count
			end
			
			new_sum = sum + x
			if new_results[new_sum]
				new_results[new_sum] += count
			else
				new_results[new_sum] = count
			end
		}
		results = new_results
	}
	
	results
end

results_s = make_patterns(list_s)
results_l = make_patterns(list_l)

pattern_count_j = 2 ** count_j
count = pattern_count_j - 1
results_s.each{|sum_s, count_s|
	if sum_s > 0 && count_l = results_l[sum_s]
		count += count_s * count_l * pattern_count_j
	end
}

p count




Measured memory_bytes: 2812
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()

    def step(i: Int, cnt: Int, pre: Option[Int]): Int = {
      if (i == N) cnt
      else {
        val a = sc.nextInt()
        pre match {
          case None => step(i + 1, cnt, Some(a))
          case Some(b) if a == b => step(i + 1, cnt + 1, None)
          case Some(b) if a != b => step(i + 1, cnt, Some(a))
        }
      }
    }

    val ans = step(0, 0, None)

    out.println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) { f(i); i += 1 }
  }
  def rep_r(n: Int)(f: Int => Unit): Unit = {
    var i = n - 1
    while(i >= 0) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 27212
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+50;
int n,a[N],mn=1e5,mx,nn;
void fail(){puts("No");exit(0);}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),mn=min(mn,a[i]),mx=max(mx,a[i]);
	if(mx-mn>1)fail();
	if(mx>mn){
		for(int i=1;i<=n;i++)if(a[i]==mn)nn++;
		if(nn+1>mx||nn==n-1)fail();
		nn+=(n-nn)/2;if(nn<mx)fail();
		puts("Yes");
	}
	else{
		if(mx!=n-1&&n/2<mx)fail();
		puts("Yes");
	}
	return 0;
}

Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;
 
    UnionFind (int n = 1 ) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n); siz.resize(n);
        for (int i = 0; i < n; i++) par[i] = i, rank[i] = 0, siz[i] = 1;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool same(int x, int y) {
        return root(x) == root(y);
    }
 
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
 
        if (rank[x] < rank[y]) {
            par[x] = y;
            siz[y] += siz[x];
        }
        else {
            par[y] = x;
            siz[x] += siz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
 
    int size(int x) {
        return siz[root(x)];
    }
};

//--------------------------- Solve ---------------------------//

void solve() {
    int N, M; cin >> N >> M;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i], p[i]--;

    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int x, y; cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (uf.same(i, p[i])) ans++;
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 4752
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  int32_t sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  cout << string(tx - sx, 'R') << string(ty - sy, 'U');
  cout << string(tx - sx, 'L') << string(ty - sy, 'D');

  cout << string(1, 'D') << string(tx + 1 - sx, 'R') << string(ty + 1 - sy, 'U') << string(1, 'L');
  cout << string(1, 'U') << string(tx + 1 - sx, 'L') << string(ty + 1 - sy, 'D') << string(1, 'R');

  cout << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
ans = [0] * 4
m = {'AC': 0, 'WA': 1, 'TLE': 2, 'RE': 3}
for _ in range(N):
    k = input()
    ans[m[k]] += 1
for key in ['AC', 'WA', 'TLE', 'RE']:
    print(key, 'x', ans[m[key]])


Measured memory_bytes: 69884
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds; 
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order() - 0 indexing
// order_of_key() - number of elements strictly smaller
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
//---------------------------------------GL HF------------------------------------------------------
// -------------------------------------ManavJ07----------------------------------------------------
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll X;
        cin>>X;
        if(X>=30){
            cout<<"Yes"<<endl;
        }
        else
            cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3644
#include<cstdio>
#include<algorithm>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 100003;
int n, m, cnt[N], fa[N], ans;
LL sum[N];
struct Edge {
	int u, v, w;
	inline bool operator < (const Edge &o) const {return w < o.w;}
} e[N];
inline int getfa(int x){
	return x == fa[x] ? x : fa[x] = getfa(fa[x]);
}
int main(){
	scanf("%d%d", &n, &m);
	for(Rint i = 1;i <= n;i ++){
		scanf("%lld", sum + i);
		fa[i] = i;
	}
	for(Rint i = 1;i <= m;i ++) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
	sort(e + 1, e + m + 1);
	for(Rint i = 1;i <= m;i ++){
		int fa1 = getfa(e[i].u), fa2 = getfa(e[i].v);
		if(fa1 == fa2) ++ cnt[fa1];
		else {
			cnt[fa1] += cnt[fa2] + 1;
			sum[fa1] += sum[fa2];
			cnt[fa2] = sum[fa2] = 0;
			fa[fa2] = fa1;
		}
		if(sum[fa1] >= e[i].w){
			ans += cnt[fa1];
			cnt[fa1] = 0;
		}
	}
	printf("%d\n", m - ans);
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N, K; cin >> N >> K;
    vector<double> A(N);
    rep(i, N) cin >> A[i];
    double ruiseki[1001] = {};
    for(int i = 1; i <= 1000; i++) ruiseki[i] = ruiseki[i-1] + i;

    int idx = 0;
    double mx = 0.0;
    rep(i, K) mx += A[i];
    double temp = mx;
    for(int i = K; i < N; i++){
        temp += A[i] - A[i-K];
        if(temp > mx){
            idx = i-(K-1);
            mx = temp;
        }
    }

    double acc = 0.0;
    for(int i = idx; i < idx+K; i++) acc += ruiseki[(int) A[i]]/A[i];
    printf("%.10f\n", acc);

    return 0;
}

Measured memory_bytes: 1792
/******************************************************************************

                         بسم الله الرحمن الرحيم
                     Author: Mst: Mhamuda Khatun
                               RUCSE27

*******************************************************************************/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define OrderSetTree tree<ll,null_type/*mapped_type*/,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define MAX 1000000000000
#define N 305

int main()
{
    fastio;
    //OrderSetTree ost;
    ll i,t,a,b;
    bool flag=false;
    vector<ll>cnt(105);
    cin>>t;

    for(i=1;i<=t;i++)
    {
        cin>>a>>b;

        if(a==b)
            cnt[i]++;
    }
    for(i=3;i<=100;i++)
    {
        if((cnt[i-2]+cnt[i-1]+cnt[i])==3)
        {
            flag=true;
            break;
        }
    }
    if(flag)
        cout<<"Yes";
    else
        cout<<"No";

    cout<<"\n";
    return 0;   //:D
}




Measured memory_bytes: 3644
w, h, n = map(int, input().split())
minx, maxx, miny, maxy = 0, w, 0, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        minx = max(minx, x)
    if a == 2:
        maxx = min(maxx, x)
    if a == 3:
        miny = max(miny, y)
    if a == 4:
        maxy = min(maxy, y)
print(max(0, maxx - minx) * max(0, maxy - miny))


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

using namespace std;


int main() {
    long long n, p;
    cin >> n >> p;
    long long ans = 1;
    map<long long, long long> mp;
    auto prime_factor = [&]() {
        for(long long i = 2; i * i <= p; i++) {
            while(p % i == 0) {
                mp[i]++;
                p /= i;
            }
        }
        if(p != 1) {
            mp[p]++;
        }
    };
    prime_factor();
    for(auto c : mp) {
        ans *= pow(c.first, c.second / n);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3844