akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N, W;
    cin >> N >> W;

    vector<ll> V0;
    vector<ll> V1;
    vector<ll> V2;
    vector<ll> V3;

    ll w1 = -1;
    FOR(i, 0, N){
        ll w, v;
        cin >> w >> v;
        
        if(w1==-1){
            w1 = w;
        }

        ll diff = w - w1;
        switch(diff){
            case 0:
                V0.push_back(v);
                break;
            case 1:
                V1.push_back(v);
                break;
            case 2:
                V2.push_back(v);
                break;
            case 3:
                V3.push_back(v);
                break;
        }
    }

    sort(ALL(V0), greater<ll>());
    sort(ALL(V1), greater<ll>());
    sort(ALL(V2), greater<ll>());
    sort(ALL(V3), greater<ll>());

    ll n0 = V0.size();
    ll n1 = V1.size();
    ll n2 = V2.size();
    ll n3 = V3.size();

    // 価値の累積和
    ll Ac0[n0];
    ll Ac1[n1];
    ll Ac2[n2];
    ll Ac3[n3];

    if(n0>0) Ac0[0] = V0[0];
    FOR(i, 1, n0){
        Ac0[i] = Ac0[i-1] + V0[i];
    }

    if(n1>0) Ac1[0] = V1[0];
    FOR(i, 1, n1){
        Ac1[i] = Ac1[i-1] + V1[i];
    }

    if(n2>0) Ac2[0] = V2[0];
    FOR(i, 1, n2){
        Ac2[i] = Ac2[i-1] + V2[i];
    }

    if(n3>0) Ac3[0] = V3[0];
    FOR(i, 1, n3){
        Ac3[i] = Ac3[i-1] + V3[i];
    }

    ll value_max = 0;
    FOR(i, 0, n0+1){
        FOR(j, 0, n1+1){
            FOR(k, 0, n2+1){
                FOR(l, 0, n3+1){

                    ll value = 0;
                    ll weight = 0;

                    if(i>0){
                        value += Ac0[i-1];
                        weight += i * w1;
                    }
                    if(j>0){
                        value += Ac1[j-1];
                        weight += j * (w1+1);
                    }
                    if(k>0){
                        value += Ac2[k-1];
                        weight += k * (w1+2);
                    }
                    if(l>0){
                        value += Ac3[l-1];
                        weight += l * (w1+3);
                    }
                    
                    if(weight <= W){
                        value_max = max(value_max, value);
                    }
                }
            }
        }
    }

    p(value_max);
    
    return 0;
}

Measured memory_bytes: 256
def inputs(): return (int(x) for x in input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N,M,K = inputs()
uf = UnionFind(N+1)
f = {i:[] for i in range(N)}
b = {i:[] for i in range(N)}
ans = [0]*(N)
for _ in range(M):
    x,y = [int(x) for x in input().split()]
    f[x-1].append(y-1)
    f[y-1].append(x-1)
    uf.union(x-1,y-1)
for _ in range(K):
    x,y = inputs()
    if uf.same(x-1,y-1):
        b[x-1].append(y-1)
        b[y-1].append(x-1)
for i in range(N):
    ans[i]+=uf.size(i)-len(f[i])-len(b[i])-1
print(*ans)

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int N = 101;

vector<bool> isNorth;

double dir(int s){
    if(isNorth.size() - 1 == s){
        if(isNorth[s]) return 0.;
        else return 90.;
    }
    
    double d = 90. / (2 * (1 << (isNorth.size() - s - 2)));
    if(isNorth[s]) return dir(s + 1) - d;
    else return dir(s + 1) + d;
}

int main(void){
    for(string in; cin >> in, in != "#";){
        isNorth = vector<bool>();
        rep(i, in.size()){
            if(in[i] == 'n'){
                isNorth.pb(true);
                i += 4;
            }
            else{
                isNorth.pb(false);
                i += 3;
            }
        }

        double p = dir(0), q = 1;
        while(p != (int)p){
            p *= 2;
            q *= 2;
        }
        p /= __gcd((int)p, (int)q);
        q /= __gcd((int)p, (int)q);

        cout << (int)p;
        if(q != 1.) cout << "/" << (int)q;
        cout << endl;
    }

	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N; 
ll K, Bit[40], A[int(1e5+5)], B[int(1e5+5)];
bool k[40];
ll DP[40], ans[40];

int main(){
  cin >> N >> K;
  Bit[39] = 1;
  for (int i = 38; i >= 0; i--) Bit[i] = Bit[i+1] * 2;

  ll num = K;
  for (int i = 39; i >= 0; i--){
    if (num % 2 != 0) k[i] = true;
    num /= 2;
  }

  for (int i = 0; i < 40; i++){
    ll now = 0;
    for (int j = 0; j < i; j++){
      if (k[j]) now += Bit[j];
    }
    for (int j = i + 1; j < 40; j++){
      now += Bit[j];
    }
    DP[i] = now;
  }

  for (int i = 0; i < N; i++){
    cin >> A[i] >> B[i];
    for (int j = 0; j < 40; j++){
      if ((A[i] | DP[j]) <= K) ans[j] += B[i];
    }
  }

  sort(ans, ans + 40, greater<ll>());
  cout << ans[0] << endl;

  return 0;
}


Measured memory_bytes: 5196
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>

typedef long long LL;
using namespace std;

#define MAXN 200005

char s[MAXN];
int persum = 0;
LL ans = 0;

signed main() {
	scanf("%s", s);
	for (int i = 0; s[i] != '\0'; i++) {
		if (s[i] == 'B') {
			if (s[i + 1] == 'C') {
				ans += persum;
			}
			else {
				persum = 0;
			}
		}
		if (s[i] == 'C') {
			if (i == 0) continue;
			else {
				if (s[i - 1] != 'B') {
					persum = 0;
				}
			}
		}
		if (s[i] == 'A') persum++;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[n][3];
    int dp[n][3];
    for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
    for(int i=1;i<n;i++){
        dp[i][0]=a[i][0] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2] + max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 2560
N, K = map(int, input().split())
c = 0
a = []

while 1:
    if K==1:
        print(0)
        break
    if N==0:
        print(0)
        break
    if N==1:
        print(1)
        break
    
    for i in range(2):
        if i==0:
            N = N-((N//K)*K)
        N = abs(N-K)
        a.append(N)
    b = min(a)
    print(b)  
    break

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    int c = 0;
    int n; cin >> n;
    vll a(n);
    rep(i,0,n) cin >> a[i];

    /*sort(all(a));
    a.resize(unique(all(a)) - a.begin());
    n = sz(a);
    rep(i,0,n) {
        rep(j,i+1,n) {
            rep(k,j+1,n) {
                if(a[i] + a[j] > a[k]) c++;
            }
        }
    }*/


    rep(i,0,n) {
        rep(j,i + 1,n) {
            rep(k, j + 1, n) {
                ll x = a[i];
                ll y = a[j];
                ll z = a[k];
                if(x == y || x == z || z == y) continue;
                vll xz = {x,y,z};
                sort(all(xz));
                if(xz[0] + xz[1] > xz[2]) c++;
            }
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

int main(int argc, char const *argv[]) {
  int n,num,i,j;
  int r[4][13]={0};
  char ch;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf(" %c %d", &ch, &num);
    switch (ch)  {
      case 'S':
        r[0][num-1]=num;
        break;
      case 'H':
        r[1][num-1]=num;
        break;
      case 'C':
        r[2][num-1]=num;
        break;
      case 'D':
        r[3][num-1]=num;
        break;
      default:
        break;
    }
  }
  //printf("\n");
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 13; j++) {
      if (r[i][j]==0) {
        switch (i)  {
          case 0:
            printf("S %d\n", j+1);
            break;
          case 1:
            printf("H %d\n", j+1);
            break;
          case 2:
            printf("C %d\n", j+1);
            break;
          case 3:
            printf("D %d\n", j+1);
            break;
          default:
            break;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 596
// OURL: https://atcoder.jp/contests/abc132/tasks/abc132_e
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

inline int toidx(int v) {
  return (v-1)*3;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin >> N >> M;
  N = N*3;

  auto edge = make_v<set<int>>(N);
  REP(i,M) {
    int u1, u2;
    cin >> u1 >> u2;
    u1 = toidx(u1);
    u2 = toidx(u2);
    edge[u1].insert(u2+1);
    edge[u1+1].insert(u2+2);
    edge[u1+2].insert(u2);
  }
  int S,T;
  cin >> S >> T;
  S = toidx(S); T = toidx(T);
  // debug(S,T);
  auto min_cnt = make_v<int>(N);
  fill_v(min_cnt, INT_MAX);
  min_cnt[S] = 0;

  auto done = make_v<bool>(N);
  done[S] = true;

  deque<int> que;
  que.push_back(S);

  bool fin = false;
  while (que.size() > 0) {
    int v = que.front();que.pop_front();
    for (auto &vv : edge[v]) {
      if (!done[vv]){
        que.push_back(vv);
        min_cnt[vv] = min(min_cnt[vv], min_cnt[v]+1);
        if (vv == T) {
          fin = true;
          break;
        }
        done[vv] = true;
      }
    }
    if (fin) break;
  }

  // debug(min_cnt);
  if (fin) {
    cout << min_cnt[T] / 3 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in(),Q=in();
	map<int,list<int>> S;
	REP(i,Q){
		int q=in();
		if(!q){
			int t=in();
			S[t].push_back(in());
		}
		else if(q==1){
			int t=in();
			auto neitr=S[t].end();
			if(!S[t].empty()) advance(neitr,-1);
			for(auto itr=S[t].begin(),eitr=S[t].end();itr!=eitr;++itr){
				cout << *itr;
				if(itr!=neitr) cout << ' ';
			}
			cout << endl;
		}
		else{
			int s=in();
			int t=in();
			S[t].splice(S[t].end(),S[s]);
			S[s].clear();
		}
	}

	return 0;
}


Measured memory_bytes: 18652
#pragma warning(disable:4996)
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
using mint = boost::multiprecision::cpp_int; //int1024_t etc...
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;

TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value, void>::type fill(vector<V>& _v, const T &_t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value, void>::type fill(vector<V>& _v, const T &_t) { for (auto &_e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

int main(void) {
	int A, B, C;
	cin >> A >> B >> C;
	string ans = "No";
	if (A < C && C < B) {
		ans = "Yes";
	}
	if (B < C && C < A) {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
{-
G - Longest Path

問題文

N頂点 M 辺の有向グラフ G があります。頂点には 1,2,…,N と番号が振られています。
各 i (1≤i≤M) について、i 番目の有向辺は頂点 xi から yi へ張られています。
Gは有向閉路を含みません。

Gの有向パスのうち、最長のものの長さを求めてください。
ただし、有向パスの長さとは、有向パスに含まれる辺の本数のことです。

制約
    入力はすべて整数である。
    2≤ N≤ 10^5
    1≤ M ≤10^5
    1 ≤ xi,yi ≤ N
    ペア (xi,yi)はすべて相異なる。
    Gは有向閉路を含まない。

入力
入力は以下の形式で標準入力から与えられる。

N M
x1 y1
x2 y2
:
xM yM

出力

Gの有向パスのうち、最長のものの長さを出力せよ
-}
{-# LANGUAGE BangPatterns #-}

import Control.Monad.Trans.State.Lazy
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Vector as V

rint :: StateT B.ByteString Maybe Int
rint = StateT $ B.readInt.B.dropWhile(<'!')
rint2 = (,) <$> ((+(-1))<$>rint) <*> ((+(-1))<$>rint)
rvn ps n = V.replicateM n ps

parse = do
    n <- rint
    m <- rint
    xs <- rvn rint2 m
    return (n,xs)

main=print.f =<< fromJust.evalStateT parse <$> B.getContents

f :: (Int, V.Vector (Int,Int)) -> Int
f (n,xs) = V.maximum v
    where
        cods = V.accumulate  (flip (:))  (V.replicate n []) xs
        v = V.generate n m
        m i = (+1) $ maximum $ ((-1):) $ map (\j->v V.! j) $ cods V.! i

Measured memory_bytes: 56700
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>*/
#include <bits/stdc++.h>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int main() {
	string s; int N; cin >> N >> s;
	
	int cur = 0;
	F0R(i,N) {
	    if (s[i] == '(') cur ++; else cur --;
	}
	
	if (cur>0) F0R(i,cur) s += ')';
	else if (cur<0) F0R(i,-cur) s = '('+s;
	
	int c1 = 0, mn = 0;
	F0R(i,s.length()) {
	    if (s[i] == '(') c1++; 
	    else c1--;
	    mn = min(mn,c1);
	}
	F0R(i,-mn) s = '('+s+')';
	cout << s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<20;



int main(){
    int a,b,q;cin >> a >> b >> q;
    vector<LL> s(a),ss,tt,t(b);
    for (int i = 0; i < a; i++) {
        cin >> s[i];
        s.pb(-s[i]);
    }
    s.pb(LINF);
    s.pb(-LINF);
    t.pb(LINF);
    t.pb(-LINF);
    for (int i = 0; i < b; i++) {
        cin >> t[i];
        t.pb(-t[i]);
    }
    sort(ALL(s));
    sort(ALL(t));
    for (int i = 0; i < q; i++) {
        LL x;cin >> x;
        LL ans=LINF;
        LL xa=-*lower_bound(ALL(s),-x);
        LL tmp=abs(xa-x);
        ans=min(ans,tmp+min(abs(xa+*lower_bound(ALL(t),-xa)),abs(*lower_bound(ALL(t),xa)-xa)));

        xa=*lower_bound(ALL(s),x);
        tmp=abs(xa-x);
        ans=min(ans,tmp+min(abs(xa+*lower_bound(ALL(t),-xa)),abs(*lower_bound(ALL(t),xa)-xa)));
        xa=-*lower_bound(ALL(t),-x);
        tmp=abs(xa-x);
        ans=min(ans,tmp+min(abs(xa+*lower_bound(ALL(s),-xa)),abs(*lower_bound(ALL(s),xa)-xa)));

        xa=*lower_bound(ALL(t),x);
        tmp=abs(xa-x);
        ans=min(ans,tmp+min(abs(xa+*lower_bound(ALL(s),-xa)),abs(*lower_bound(ALL(s),xa)-xa)));
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
    vector<int> a(5);
    int min = 10, sum = 0, tmp = 0;
    for (int i = 0; i < 5; i++) {
        cin >> a.at(i);
        if (a.at(i) % 10 < min && a.at(i) % 10 != 0) min = a.at(i) % 10;
        if (a.at(i) % 10 == 0) {
            sum += a.at(i);
        } else {
            sum += a.at(i) + 10 - (a.at(i) % 10);
        }
    }

    if (min >= 10) {
        cout << sum << endl;
    } else {
        cout << sum - (10 - min) << endl;
    }

    return 0;
}


Measured memory_bytes: 3592
import collections

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

s = {i:[] for i in range(n+1)}
for i in range(m):
    a,b = map(int,input().split())
    s[a].append(b)
    s[b].append(a)

bfs = [0]*(n+1)
try:
    bfs[1] = s[1][0]
except IndexError:
    print("No")
    exit()
q = collections.deque()
q.append({1:s[1]})

while  q:
    tmp = q.popleft()#現在地点からたどり着ける部屋の辞書
    for k,v in tmp.items():
        for room in v:
            if bfs[room] == 0:
                bfs[room] = k
                q.append({room:s[room]})

if bfs.count(0) <= 1:
    print("Yes")
    for i in bfs[2:]:
        print(i)
else:
    print("No")
   

Measured memory_bytes: 62912
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  ll N;
  cin>>N;
  int X=sqrt(N);
  rep(i,X+1){
    if(N%(X-i)==0&&X-i){
      cout<<X-i+N/(X-i)-2;
      break;
    }
  }
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc159/tasks/abc159_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

bool is_kaibun(string s) {
  ll n = s.size();

  rep(i, n) {
    unless(i < n - 1 - i) break;
    unless(s[i] == s[n - 1 - i]) return false;
  }

  return true;
}

void solve() {
  string S;
  cin >> S;
  ll N = S.size();

  ll f_from = 0;
  ll f_to = (N - 1) / 2 - 1;

  ll s_from = (N + 3) / 2 - 1;
  ll s_to = N - 1;

  bool res = is_kaibun(S) && is_kaibun(S.substr(f_from, f_to - (f_from - 1))) &&
             is_kaibun(S.substr(s_from, s_to - (s_from - 1)));

  if (res) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                                                                                                                     
using namespace std;
int main()
{
  int N,i=0,bob=0,alice=0;
  cin >> N;
  vector<int> a(N);
  for(i=0; i<N; i++)
    cin >> a.at(i);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(i=0; i<N; i+=2){
    alice+=a.at(i);
    if(i+1==N)
      break;
    bob+=a.at(i+1);
  }
  cout << alice-bob << endl;
}


Measured memory_bytes: 256
class Dice(object):
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom
    def rollN(self):
        prevN = self.north
        prevB = self.bottom
        prevS = self.south
        self.north = self.top
        self.bottom = prevN
        self.south = prevB
        self.top = prevS
    def rollS(self):
        prevS = self.south
        prevB = self.bottom
        prevN = self.north
        self.south = self.top
        self.bottom = prevS
        self.north = prevB
        self.top = prevN
    def rollE(self):
        prevE = self.east
        prevB = self.bottom
        prevW = self.west
        self.east = self.top
        self.bottom = prevE
        self.west = prevB
        self.top = prevW
    def rollW(self):
        prevW = self.west
        prevB = self.bottom
        prevE = self.east
        self.west = self.top
        self.bottom = prevW
        self.east = prevB
        self.top = prevE

diceInit = [int(n) for n in raw_input().split()][:6:]
instruction = raw_input()

diceI = Dice(diceInit[0], diceInit[1], diceInit[2], diceInit[3], diceInit[4], diceInit[5])

for item in instruction:
    if item == 'N':
        diceI.rollN()
    elif item == 'E':
        diceI.rollE()
    elif item == 'W':
        diceI.rollW()
    elif item == 'S':
        diceI.rollS()

print diceI.top

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

int main() {
  long long N;
  cin >> N;
  long long ans=0;
  long long fizz=0, buzz=0, fizzbuzz=0;
  
  fizz = N/3;
  buzz = N/5;
  fizzbuzz = N/15;
//  printf("fizz:%lld, buzz:%lld, fizzbuzz: %lld\n", fizz, buzz, fizzbuzz);
  N = N*(N+1)/2;
  fizz =  3*fizz*(fizz+1)/2;
  buzz =  5*buzz*(buzz+1)/2;
  fizzbuzz = 15*fizzbuzz*(fizzbuzz+1)/2;
//  cout << N << endl;
//  cout << fizz << endl;
//  cout << buzz << endl;
//  cout << fizzbuzz << endl;
  cout << N - fizz - buzz + fizzbuzz << endl;
}



Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
void kansu(vector<char>& in,int x){
  in[x]='!';
  //cout<<"!"<<endl;
  vector<char>t;
  loop(i,x+1,in.size()){
    if(in[i]=='['){kansu(in,i);i--;}
    else if(in[i]==']'){
      reverse(all(t));
      rep(j,t.size())
	in[j+x+1]=t[j];
      in[i]='!';
      //rep(i,t.size())cout<<t[i]<<" ";
      //cout<<endl;
      break;
    }else{
      t.pb(in[i]);
    }
  } 
}
int main(){
  string s;
  while(cin>>s,s.size()!=1||s[0]!='.'){
    vector<char>in;
    for(int i=s.size()-1;i>=0;i--){
      if(s[i]=='+'||s[i]=='-'||s[i]=='?'){
	int tm=i;
	char tmp;
	if(s[i]=='?'){tmp=s[i];i--;}
	else tmp=s[i+1];
	while(s[i]=='+'||s[i]=='-'){
	  if(s[i]=='+')tmp++;
	  else tmp--;
	  if(tmp>'Z')tmp='A';
	  if(tmp<'A')tmp='Z';
	  i--;
	}
	i++;
	if(s[tm]=='?')tmp='A';
	in.pb(tmp);
      }else if(i==0||!isalpha(s[i])||(isalpha(s[i])&&(s[i-1]!='+'&&s[i-1]!='-')))in.pb(s[i]);
    }
    //rep(i,in.size())cout<<in[i]<<" ";
    //
    reverse(all(in));
    rep(i,in.size()){
      if(in[i]=='['){
	kansu(in,i);	
      }else if(in[i]!='!'&&in[i]!=']')cout<<in[i];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1200
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	Int M1, M2, D1, D2;
	cin >> M1 >> D1 >> M2 >> D2;

	if (M1+1==M2) {
		cout << 1 << "\n";
	}
	else {
		cout << 0 << "\n";
	}

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vl vector<ll>
using namespace std;
const int N=1e5+5;
ll n,m,x[N][3],ans;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
			cin>>x[i][j];
	for(int i=0;i<8;i++)
	{
		vl v;
		v.clear();
		for(int j=0;j<n;j++)
		{
			ll sum=0;
			if(i&1)
				sum+=x[j][0];
			else
				sum-=x[j][0];
			if(i&2)
				sum+=x[j][1];
			else
				sum-=x[j][1];
			if(i&4)
				sum+=x[j][2];
			else
				sum-=x[j][2];
			v.push_back(sum);
		}
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		ll sum=0;
		for(int j=0;j<m;j++)sum+=v[j];
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define N 200005
#define rank Rank
#define index Index
LL dp[25000005];
int main(){
    LL n;
    scanf("%lld",&n);
    pll p[4];
    scanf("%lld %lld %lld %lld %lld %lld",&p[0].x,&p[1].x,&p[2].x,&p[0].y,&p[1].y,&p[2].y);
    p[3]=mp(1,1);
    MEM(dp);
    for(int i =0;i<4;i++){
        for(int j =0;j<=n-p[i].x;j++){
            dp[j+p[i].x]=max(dp[j+p[i].x],dp[j]+p[i].y);
        }
        swap(p[i].x,p[i].y);
    }
    LL temp=0;
    for(int i = 0;i<=n;i++)
        temp=max(temp,dp[i]);
   // printf("%lld\n",temp);
    n=temp;
    MEM(dp);
    for(int i=0;i<4;i++){
        for(int j = 0;j<=n-p[i].x;j++){
            dp[j+p[i].x]=max(dp[j+p[i].x],dp[j]+p[i].y);
        }
       // printf("%d %d\n",p[i].x,p[i].y);
    }
    printf("%lld\n",dp[n]);
    return 0;
}

Measured memory_bytes: 195712
#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,r,c,m,top;
struct data
{
    int l,r;
    bool operator<(const data &t) const
    {
        return r<t.r;
    }
} a[100100],stk[100100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

int get()
{
    int x=getint(),y=getint();
    if (!x)
        return y;
    if (y==c)
        return x+c;
    if (x==r)
        return c+r+c-y;
    if (!y)
        return r+c+r+c-x;
    return -1;
}

int main()
{
    scanf("%d%d%d",&r,&c,&n);
    while (n--)
    {
        int x=get(),y=get();
        if (x>-1 && y>-1)
            a[++m]=(data){min(x,y),max(x,y)};
    }
    sort(a+1,a+1+m);
    repu(i,1,m)
    {
        while (top && stk[top].r>a[i].l)
            if (stk[top].l<a[i].l)
            {
                puts("NO");
                return 0;
            }
            else
                --top;
        stk[++top]=a[i];
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 1024
sx, sy, tx, ty = map(int, input().split())

h = ty - sy
w = tx - sx

ans = 'U'*h + 'R'*w + 'D'*h + 'L'*w + 'L' + 'U'*(h+1) + 'R'*(w+1) + 'D' + 'R' + 'D'*(h+1) + 'L'*(w+1) + 'U'

print(ans)


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

int main() {
  double a, b, c, d, e, f, x, y;
  while (cin >> a >> b >> c >> d >> e >> f) {
    y = (c * d - a * f) / (b * d - a * e);
    x = (c - b * y) / a;
    cout << fixed << setprecision(3) << x << " " << y << endl;
  }
  return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    unordered_map<string,int> mp;
    string s; int n;
    cin>>n>>s;
    vvll dp(n+1,vll(n+1,0));
    ll res=0;
    irep(i,0,n){
        irep(j,i+1,n){
            if(s[i]==s[j])chmax(dp[i][j],dp[i+1][j+1]+1);
            chmax(res,min(j-i,dp[i][j]));
        }
    }
    cout<<res<<endl;
    return 0;
}




Measured memory_bytes: 195840
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	string s,t;
	cin>>s>>t;
	int sum=0;
	rep(i,3){
		sum+=(s[i]==t[i]?1:0);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
    int h,w;
    cin >> h;
    cin >> w;
    vector< vector<char> > neko;
    vector<char> wl(w,0),hl(h,0);

    for(int y = 0; y < h; y++){
        vector<char> tmp;
        for(int x = 0; x < w; x++){
            char t;
            cin >> t;
            tmp.push_back(t);
            if(t != '.'){
                hl[y]++;
                wl[x]++;
            }
        }
        neko.push_back(tmp);
    }

    for(int y = 0; y < h; y++){
        
        if(hl[y] != 0){
            for(int x = 0; x < w; x++){
                if(wl[x] != 0){
                    cout << neko[y][x];
                }
            }
            cout << endl;
        }
    }
}   

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

using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    int x = 0, y = 0;
    for (int i = N - 1; i > 0; i--) {
        if (A[i] == A[i - 1]) {
            if (x == 0) {
                x = A[i];
            } else {
                y = A[i];
                break;
            }
            i--;
        }
    }
    cout << 1LL * x * y << "\n";
    //cout << x << " " << y << "\n";
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int N,i,tmp;
    int A[200001];
    int buka[200001];

    scanf("%d",&N);
    
    for(i=0; i<N; i++){
        buka[i]=0;
    }
    for(i=0; i<N-1; i++){
        scanf("%d",&tmp);
        buka[tmp-1]++;
    }

    for(i=0; i<N; i++){
        printf("%d\n",buka[i]);
    }
    
    return 0;
}

Measured memory_bytes: 2488
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define scn(n) scanf("%d",&n)
using namespace std;
const int N= 5e5+4;
struct mo{
    int left;
    int right;
    int ind;
    int ans;
};

int block;

bool comp(mo a,mo b){
    
    int a_block = a.left/block;
    int b_block = b.left/block;
    
    if(a_block!=b_block)
    return a.left<b.left;
    
    return a.right<b.right;
}


bool comp1(mo a,mo b)
{
    return a.ind<b.ind;
}
int main() {
	
	int n,q;
	scn(n);
	scn(q);
	block = (int)sqrt(n);
	
	int col[n+5];
	for(int i=1;i<=n;i++)
	scn(col[i]);
	
	mo qry[q+5];
	
	for(int i=0;i<q;i++)
	{
	   int x,y;
	   scn(x);
	   scn(y);
	   
	   qry[i].left=x;
	   qry[i].right=y;
	   qry[i].ind=i;
	}
	
	sort(qry,qry+q,comp);
	col[0]=5e4+2;
	int fre[N];
	memset(fre,0,sizeof(fre));
	int le=1,rt=0;
	
	int var=0;
	for(int i=0;i<q;i++)
	{
	    int L=qry[i].left;
	    int R=qry[i].right;
	    while(le<L)
	    {
	        fre[col[le]]--;
	        if(fre[col[le]]==0)
	        var--;
	        le++;
	    }
	    while(le>L)
	    {
	        le--;
	        fre[col[le]]++;
	        if(fre[col[le]]==1)
	        var++;
	    }
	    while(rt<R)
	    {
	        rt++;
	        fre[col[rt]]++;
	        if(fre[col[rt]]==1)
	        var++;
	    }
	    while(rt>R)
	    {
	        fre[col[rt]]--;
	        if(fre[col[rt]]==0)
	        var--;
	        rt--;
	    }
	    
	    qry[i].ans=var;
	}
	
	sort(qry,qry+q,comp1);
	
	
	for(int i=0;i<q;i++)
	printf("%d\n",qry[i].ans);
	return 0;
}

Measured memory_bytes: 15476
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  ll cnt=0;
  for(auto c:s){
    if(c=='o')cnt++;
  }
  if(cnt+15-s.length()>=8)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
a,b,c,d = map(int, list(input()))

for op1 in ["+","-"]:
    for op2 in ["+","-"]:
        for op3 in ["+","-"]:
            res = 0
            if op1=="+":
                res += a+b
            else:
                res += a-b
            if op2=="+":
                res += c
            else:
                res -= c
            if op3=="+":
                res += d
            else:
                res -= d
            if res==7:
                print("".join([str(a),op1,str(b),op2,str(c),op3,str(d),"=7"]))
                exit()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s, ss;
    cin >> s >> ss;
    if(s.size() == ss.size())
    {
        if(s.compare(ss) < 0 ) puts("LESS");
        else if(s.compare(ss) > 0) puts("GREATER");
        else puts("EQUAL");
    }
    else{
        if(s.size() > ss.size()) puts("GREATER");
        else puts("LESS");
    }
}


Measured memory_bytes: 256
def side(p1, p2, p3):
    return (p3[1]-p1[1])*(p2[0]-p1[0])-(p2[1]-p1[1])*(p3[0]-p1[0])>0

while True:
    try:
        x = map(float, raw_input().split())
        p1 = x[0:2]
        p2 = x[2:4]
        p3 = x[4:6]
        p0 = x[6:]
        if (side(p1, p2, p0)==side(p2, p3, p0) and side(p2, p3, p0)==side(p3, p1, p0)):
            print "YES"
        else:
            print "NO"
    except:
        break

Measured memory_bytes: 4260
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second

int main()
{
    int n;
    cin >> n;
    int x = n % 10;
    vector<int> hon = {2, 4, 5, 7, 9};
    vector<int> pon = {0, 1, 6, 8};

    if (count(hon.begin(), hon.end(), x) == 1)
    {
        cout << "hon" << endl;
    }
    else if (count(pon.begin(), pon.end(), x) == 1)
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "bon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
n, k = map(int, input().split())
a = [int(i) - 1 for i in input().split()]
if k <= n:
  p = 0
  for i in range(k):
    p = a[p]
  print(p + 1)
  exit()
p = 0
t = [-1]*n
t[0] = 0
for i in range(1, n):
  p = a[p]
  if t[p] != -1:
    break
  t[p] = i
d = i - t[p]
k -= i
k %= d
for i in range(k):
  p = a[p]
print(p + 1)

Measured memory_bytes: 32264
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

bool check(int n, int i)
{
	if(i == 1)
		return 0;
	while(n % i == 0)
		n /= i;
	n %= i;
	return n == 1;
}

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	set<int> s;
	int x = n - 1;
	for(int i = 2; i * i <= x; i++)
	{
		if(x % i == 0)
		{
			s.insert(i);
			s.insert(x / i);
		}
	}
	s.insert(x);
	for(int i = 1; i * i <= n; i++)
	{
		if(n % i == 0)
		{
			if(check(n, i))
				s.insert(i);
			if(check(n, n / i))
				s.insert(n / i);
		}
	}
	s.erase(1);
	cout << s.size();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<functional>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define int long long
#define inf 1145141919810931
typedef pair<int, int> P;
struct edge { int to, cost; };
vector<edge>G[114514];
int d[114514];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>Q;
	fill(d, d + 114014, inf);
	d[s] = 0;
	Q.push(P(0, s));
	while (Q.size()) {
		P p = Q.top();
		Q.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				Q.push(P(d[e.to], e.to));
			}
		}
	}
}
signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		G[a - 1].push_back({ b - 1,c });
		G[b - 1].push_back({ a - 1,c });
	}
	int q, k;
	cin >> q >> k;
	dijkstra(k - 1);
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		cout << d[x - 1] + d[y - 1] << endl;
	}
}

Measured memory_bytes: 11632
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    int h,w;
    string s;
    cin>>h;
    vector<string> v(h);
    cin>>v;
    unordered_map<string ,ll> m;
    rep(i, h){
        sort(ALL(v[i]));
        m[v[i]]++;
    }
    ll sum=0;
    for(auto it:m){
        if(it.second !=1) sum+=((it.second -1)*it.second)/2;
    }
    pr(sum);
    return 0;
}


Measured memory_bytes: 17700
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]
Rsub = [0]
L = 0
R = 0


for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    L += 1
  Lsub.append(L)

for j in range(0,N-1)[::-1]:
  if S[j] == "A" and S[j+1] == "C":
    R += 1
  Rsub.append(R)


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[N-1] - Lsub[L-1] - Rsub[N-R])

Measured memory_bytes: 9256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
#define MOD (ll)(1e9+7)
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

struct edge{
    ll to,k;
    edge(ll to,ll k):to(to),k(k){};
};

signed main(){
    ll n,k;
    string s;
    cin >> n >> k >> s;

    ll cnt = 1;
    rep(i,0,n-1){
        if(s[i] != s[i+1]) cnt++;
    }
    cout << (ll)min(n - max((cnt-2*k),0LL),n-1LL) << endl;
    return 0;
}


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

int cnt[2010];

int main(){
    int n,x,y;
    cin>>n>>x>>y;

    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int tmp=min(j-i,abs(x-i)+1+abs(y-j));
            cnt[tmp]++;
        }
    }

    for(int i=1;i<n;i++){
        cout<<cnt[i]<<endl;
    }
}



Measured memory_bytes: 3588